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
13 changes: 10 additions & 3 deletions tests/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,19 +429,26 @@
},
{"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",
Expand Down
57 changes: 50 additions & 7 deletions tests/routers/test_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ def test_create_experiment_that_keyword_gene_ontology_has_valid_code(client, set
"keywords": [
{
"keyword": {
"key": "Phenotypic Assay Mechanism",
"label": "Label",
"key": "Molecular Mechanism Assessed",
"label": "Sodium channel activity",
"code": "GO:1234567",
"special": False,
"description": "Description",
Expand All @@ -541,8 +541,8 @@ def test_create_experiment_that_keyword_gene_ontology_has_valid_code(client, set
response = client.post("/api/v1/experiments/", json=experiment)
assert response.status_code == 200
response_data = response.json()
assert response_data["keywords"][0]["keyword"]["key"] == "Phenotypic Assay Mechanism"
assert response_data["keywords"][0]["keyword"]["label"] == "Label"
assert response_data["keywords"][0]["keyword"]["key"] == "Molecular Mechanism Assessed"
assert response_data["keywords"][0]["keyword"]["label"] == "Sodium channel activity"
assert response_data["keywords"][0]["keyword"]["code"] == "GO:1234567"


Expand All @@ -551,7 +551,7 @@ def test_create_experiment_that_keyword_gene_ontology_is_other_without_code(clie
"keywords": [
{
"keyword": {
"key": "Phenotypic Assay Mechanism",
"key": "Molecular Mechanism Assessed",
"label": "Other",
"code": None,
"description": "Description",
Expand All @@ -564,17 +564,60 @@ def test_create_experiment_that_keyword_gene_ontology_is_other_without_code(clie
response = client.post("/api/v1/experiments/", json=experiment)
assert response.status_code == 200
response_data = response.json()
assert response_data["keywords"][0]["keyword"]["key"] == "Phenotypic Assay Mechanism"
assert response_data["keywords"][0]["keyword"]["key"] == "Molecular Mechanism Assessed"
assert response_data["keywords"][0]["keyword"]["label"] == "Other"


def test_create_experiment_that_keywords_has_multiple_molecular_mechanism_assessed_labels(client, setup_router_db):
valid_keywords = {
"keywords": [
{
"keyword": {
"key": "Molecular Mechanism Assessed",
"label": "Sodium channel activity",
"code": "GO:1234567",
"special": False,
"description": "Description",
},
},
{
"keyword": {
"key": "Molecular Mechanism Assessed",
"label": "Calcium-mediated signaling",
"code": "GO:1134567",
"special": False,
"description": "Description",
},
}
],
}
experiment = {**TEST_MINIMAL_EXPERIMENT, **valid_keywords}
response = client.post("/api/v1/experiments/", json=experiment)
assert response.status_code == 200
response_data = response.json()
assert len(response_data["keywords"]) == 2
labels = {kw["keyword"]["label"] for kw in response_data["keywords"]}
codes = {kw["keyword"]["code"] for kw in response_data["keywords"]}
keys = {kw["keyword"]["key"] for kw in response_data["keywords"]}

assert keys == {"Molecular Mechanism Assessed"}
assert labels == {
"Sodium channel activity",
"Calcium-mediated signaling",
}
assert codes == {
"GO:1234567",
"GO:1134567",
}


# TODO(#511) Re-enable the Gene Ontology code requirement.
# def test_cannot_create_experiment_that_keyword_has_an_invalid_code(client, setup_router_db):
# invalid_keyword = {
# "keywords": [
# {
# "keyword": {
# "key": "Phenotypic Assay Mechanism",
# "key": "Molecular Mechanism Assessed",
# "label": "Label",
# "code": "invalid",
# "description": "Description",
Expand Down