Skip to content

Commit 329d91d

Browse files
committed
Modify the Gene Ontology related validators and tests.
1 parent 3e8d901 commit 329d91d

File tree

4 files changed

+69
-14
lines changed

4 files changed

+69
-14
lines changed

src/mavedb/lib/validation/constants/general.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
variant_count_data = "count_data"
4545
required_score_column = "score"
4646

47+
multi_value_keys = ["molecular mechanism assessed"]
4748
valid_dataset_columns = [score_columns, count_columns]
4849
valid_variant_columns = [variant_score_data, variant_count_data]
4950

src/mavedb/lib/validation/keywords.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from typing import Optional
22

3+
from mavedb.lib.validation.constants.general import multi_value_keys
34
from mavedb.lib.validation.exceptions import ValidationError
45
from mavedb.lib.validation.utilities import is_null
56

67

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

3337
keys_set = set(keys)
3438
labels_set = set(labels)

tests/helpers/constants.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,19 +429,26 @@
429429
},
430430
{"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
431431
{
432-
"key": "Phenotypic Assay Mechanism",
432+
"key": "Molecular Mechanism Assessed",
433433
"label": "Other",
434434
"code": None,
435435
"special": False,
436436
"description": "Description",
437437
},
438438
{
439-
"key": "Phenotypic Assay Mechanism",
440-
"label": "Label",
439+
"key": "Molecular Mechanism Assessed",
440+
"label": "Sodium channel activity",
441441
"code": "GO:1234567",
442442
"special": False,
443443
"description": "Description",
444444
},
445+
{
446+
"key": "Molecular Mechanism Assessed",
447+
"label": "Calcium-mediated signaling",
448+
"code": "GO:1134567",
449+
"special": False,
450+
"description": "Description",
451+
},
445452
{
446453
"key": "Phenotypic Assay Profiling Strategy",
447454
"label": "Shotgun sequencing",

tests/routers/test_experiments.py

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ def test_create_experiment_that_keyword_gene_ontology_has_valid_code(client, set
528528
"keywords": [
529529
{
530530
"keyword": {
531-
"key": "Phenotypic Assay Mechanism",
532-
"label": "Label",
531+
"key": "Molecular Mechanism Assessed",
532+
"label": "Sodium channel activity",
533533
"code": "GO:1234567",
534534
"special": False,
535535
"description": "Description",
@@ -541,8 +541,8 @@ def test_create_experiment_that_keyword_gene_ontology_has_valid_code(client, set
541541
response = client.post("/api/v1/experiments/", json=experiment)
542542
assert response.status_code == 200
543543
response_data = response.json()
544-
assert response_data["keywords"][0]["keyword"]["key"] == "Phenotypic Assay Mechanism"
545-
assert response_data["keywords"][0]["keyword"]["label"] == "Label"
544+
assert response_data["keywords"][0]["keyword"]["key"] == "Molecular Mechanism Assessed"
545+
assert response_data["keywords"][0]["keyword"]["label"] == "Sodium channel activity"
546546
assert response_data["keywords"][0]["keyword"]["code"] == "GO:1234567"
547547

548548

@@ -551,7 +551,7 @@ def test_create_experiment_that_keyword_gene_ontology_is_other_without_code(clie
551551
"keywords": [
552552
{
553553
"keyword": {
554-
"key": "Phenotypic Assay Mechanism",
554+
"key": "Molecular Mechanism Assessed",
555555
"label": "Other",
556556
"code": None,
557557
"description": "Description",
@@ -564,17 +564,60 @@ def test_create_experiment_that_keyword_gene_ontology_is_other_without_code(clie
564564
response = client.post("/api/v1/experiments/", json=experiment)
565565
assert response.status_code == 200
566566
response_data = response.json()
567-
assert response_data["keywords"][0]["keyword"]["key"] == "Phenotypic Assay Mechanism"
567+
assert response_data["keywords"][0]["keyword"]["key"] == "Molecular Mechanism Assessed"
568568
assert response_data["keywords"][0]["keyword"]["label"] == "Other"
569569

570570

571+
def test_create_experiment_that_keywords_has_multiple_molecular_mechanism_assessed_labels(client, setup_router_db):
572+
valid_keywords = {
573+
"keywords": [
574+
{
575+
"keyword": {
576+
"key": "Molecular Mechanism Assessed",
577+
"label": "Sodium channel activity",
578+
"code": "GO:1234567",
579+
"special": False,
580+
"description": "Description",
581+
},
582+
},
583+
{
584+
"keyword": {
585+
"key": "Molecular Mechanism Assessed",
586+
"label": "Calcium-mediated signaling",
587+
"code": "GO:1134567",
588+
"special": False,
589+
"description": "Description",
590+
},
591+
}
592+
],
593+
}
594+
experiment = {**TEST_MINIMAL_EXPERIMENT, **valid_keywords}
595+
response = client.post("/api/v1/experiments/", json=experiment)
596+
assert response.status_code == 200
597+
response_data = response.json()
598+
assert len(response_data["keywords"]) == 2
599+
labels = {kw["keyword"]["label"] for kw in response_data["keywords"]}
600+
codes = {kw["keyword"]["code"] for kw in response_data["keywords"]}
601+
keys = {kw["keyword"]["key"] for kw in response_data["keywords"]}
602+
603+
assert keys == {"Molecular Mechanism Assessed"}
604+
assert labels == {
605+
"Sodium channel activity",
606+
"Calcium-mediated signaling",
607+
}
608+
assert codes == {
609+
"GO:1234567",
610+
"GO:1134567",
611+
}
612+
613+
571614
# TODO(#511) Re-enable the Gene Ontology code requirement.
572615
# def test_cannot_create_experiment_that_keyword_has_an_invalid_code(client, setup_router_db):
573616
# invalid_keyword = {
574617
# "keywords": [
575618
# {
576619
# "keyword": {
577-
# "key": "Phenotypic Assay Mechanism",
620+
# "key": "Molecular Mechanism Assessed",
578621
# "label": "Label",
579622
# "code": "invalid",
580623
# "description": "Description",

0 commit comments

Comments
 (0)