Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mavedb/lib/validation/constants/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
variant_count_data = "count_data"
required_score_column = "score"

multi_value_keys = ["molecular mechanism assessed"]
valid_dataset_columns = [score_columns, count_columns]
valid_variant_columns = [variant_score_data, variant_count_data]

Expand Down
12 changes: 8 additions & 4 deletions src/mavedb/lib/validation/keywords.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from typing import Optional

from mavedb.lib.validation.constants.general import multi_value_keys
from mavedb.lib.validation.exceptions import ValidationError
from mavedb.lib.validation.utilities import is_null


def validate_code(key: str, label: str, code: Optional[str]):
# TODO(#511) Re-enable the Gene Ontology code requirement.
pass
# if key.lower() == "phenotypic assay mechanism" and label.lower() != "other":
# if key.lower() == "molecular mechanism assessed" and label.lower() != "other":
# # The Gene Ontology accession is a unique seven digit identifier prefixed by GO:.
# # e.g. GO:0005739, GO:1904659, or GO:0016597.
# if code is None or not re.match(r"^GO:\d{7}$", code):
Expand All @@ -26,9 +27,12 @@ def validate_duplicates(keywords: list):
keys = []
labels = []
for k in keywords:
keys.append(k.keyword.key.lower()) # k: ExperimentControlledKeywordCreate object
if k.keyword.label.lower() != "other":
labels.append(k.keyword.label.lower())
key = k.keyword.key.lower()
label = k.keyword.label.lower()
if key not in multi_value_keys:
keys.append(key)
if label != "other":
labels.append(label)

keys_set = set(keys)
labels_set = set(labels)
Expand Down
17 changes: 13 additions & 4 deletions src/mavedb/routers/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ async def update_experiment(
item.raw_read_identifiers = raw_read_identifiers

if item_update.keywords:
keywords: list[ExperimentControlledKeywordAssociation] = []
all_labels_none = all(k.keyword.label is None for k in item_update.keywords)
if all_labels_none is False:
# Users may choose part of keywords from dropdown menu. Remove not chosen keywords from the list.
Expand All @@ -467,10 +468,18 @@ async def update_experiment(
validate_keyword_list(filtered_keywords)
except ValidationError as e:
raise HTTPException(status_code=422, detail=str(e))
try:
await item.set_keywords(db, filtered_keywords)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Invalid keywords: {str(e)}")
for upload_keyword in filtered_keywords:
try:
description = upload_keyword.description
controlled_keyword = search_keyword(db, upload_keyword.keyword.key, upload_keyword.keyword.label)
experiment_controlled_keyword = ExperimentControlledKeywordAssociation(
controlled_keyword=controlled_keyword,
description=description,
)
keywords.append(experiment_controlled_keyword)
except ValueError as e:
raise HTTPException(status_code=422, detail=str(e))
item.keyword_objs = keywords

item.modified_by = user_data.user

Expand Down
75 changes: 67 additions & 8 deletions tests/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,21 +427,35 @@
"special": False,
"description": "Description",
},
{"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
{"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
{
"key": "Phenotypic Assay Mechanism",
"key": "Molecular Mechanism Assessed",
"label": "Other",
"code": None,
"special": False,
"description": "Description",
},
{
"key": "Phenotypic Assay Mechanism",
"label": "Label",
"key": "Molecular Mechanism Assessed",
"label": "Sodium channel activity",
"code": "GO:1234567",
"special": False,
"description": "Description",
},
{
"key": "Molecular Mechanism Assessed",
"label": "Calcium-mediated signaling",
"code": "GO:1134567",
"special": False,
"description": "Description",
},
{
"key": "Phenotypic Assay Profiling Strategy",
"label": "Shotgun sequencing",
"code": None,
"special": False,
"description": "Description",
},
]

TEST_KEYWORDS = [
Expand Down Expand Up @@ -470,7 +484,7 @@
},
},
{
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
"description": "Details of delivery method",
},
]
Expand All @@ -492,7 +506,7 @@
"methodText": "Methods",
"keywords": [
{
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
"description": "Details of delivery method",
},
],
Expand Down Expand Up @@ -572,7 +586,7 @@
"keywords": [
{
"recordType": "ExperimentControlledKeyword",
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
"description": "Details of delivery method",
},
],
Expand All @@ -587,6 +601,51 @@
"numScoreSets": 0, # NOTE: This is context-dependent and may need overriding per test
}

TEST_EXPERIMENT_WITH_UPDATE_KEYWORD_RESPONSE = {
"recordType": "Experiment",
"title": "Test Experiment Title",
"shortDescription": "Test experiment",
"abstractText": "Abstract",
"methodText": "Methods",
"createdBy": {
"recordType": "User",
"firstName": TEST_USER["first_name"],
"lastName": TEST_USER["last_name"],
"orcidId": TEST_USER["username"],
},
"modifiedBy": {
"recordType": "User",
"firstName": TEST_USER["first_name"],
"lastName": TEST_USER["last_name"],
"orcidId": TEST_USER["username"],
},
"creationDate": date.today().isoformat(),
"modificationDate": date.today().isoformat(),
"scoreSetUrns": [],
"contributors": [],
"keywords": [
{
"recordType": "ExperimentControlledKeyword",
"keyword": {
"key": "Phenotypic Assay Profiling Strategy",
"label": "Shotgun sequencing",
"special": False,
"description": "Description"
},
"description": "Details of phenotypic assay profiling strategy",
},
],
"doiIdentifiers": [],
"primaryPublicationIdentifiers": [],
"secondaryPublicationIdentifiers": [],
"rawReadIdentifiers": [],
# keys to be set after receiving response
"urn": None,
"experimentSetUrn": None,
"officialCollections": [],
"numScoreSets": 0, # NOTE: This is context-dependent and may need overriding per test
}

TEST_EXPERIMENT_WITH_KEYWORD_HAS_DUPLICATE_OTHERS_RESPONSE = {
"recordType": "Experiment",
"title": "Test Experiment Title",
Expand Down Expand Up @@ -622,7 +681,7 @@
},
{
"recordType": "ExperimentControlledKeyword",
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
"description": "Description",
},
],
Expand Down
Loading