Skip to content

Commit

Permalink
opentargets filtering complete
Browse files Browse the repository at this point in the history
  • Loading branch information
techno-sam committed Jun 26, 2024
1 parent 6e43e47 commit b24c5f1
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 12 deletions.
12 changes: 8 additions & 4 deletions gget/gget_opentargets.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,14 @@ def f(
) -> bool:
for filter_id, filter_values in filters.items():
split_key = id_key[filter_id].split(".")
actual_value = row
actual_value: dict[str, ...] | list[dict[str, ...]] = row
for k in split_key:
if actual_value is None:
break
actual_value = actual_value[k]
if type(actual_value) is list:
actual_value = [v[k] for v in actual_value]
else:
actual_value = actual_value[k]

if mode == "and":
if type(actual_value) is list:
Expand Down Expand Up @@ -354,8 +357,6 @@ def fun(
)

if limit is None and limit_key is not None and is_rows_based_query:
# wait 1 second as a courtesy
time.sleep(1)
variables["pagination"] = limit_func(total_count, is_rows_based_query)

new_results = graphql_query(
Expand All @@ -382,6 +383,9 @@ def fun(
rows = [row for row in rows if filter_(row)]
converter(rows)

if actual_limit is not None: # just in case the converter changed the length
rows = rows[:actual_limit]

df = json_list_to_df(
rows,
df_schema,
Expand Down
260 changes: 252 additions & 8 deletions tests/fixtures/test_opentargets.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
},
"expected_result": "e6030c0f3da91f8176deaf29dcc08285"
},
"test_opentargets_no_limit_accurate_coverage": {
"type": "assert_equal_json_hash",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "diseases",
"verbose": false,
"wrap_text": true
},
"expected_result": "e6030c0f3da91f8176deaf29dcc08285"
},
"test_opentargets_no_specified_resource": {
"type": "assert_equal",
"args": {
Expand Down Expand Up @@ -146,6 +156,61 @@
},
"expected_result": "dcdd8421204bb3a273c8ca0b2de8d088"
},
"test_opentargets_drugs_filter": {
"type": "assert_equal",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "drugs",
"filters": {
"disease_id": "EFO_0000274"
},
"limit": 2
},
"expected_result": [
[
"CHEMBL1743081",
"TRALOKINUMAB",
"Antibody",
"Interleukin-13 inhibitor",
"Antibody drug with a maximum clinical trial phase of IV (across all indications) that was first approved in 2021 and is indicated for atopic eczema and eczematoid dermatitis and has 5 investigational indications.",
[
"CAT-354",
"Tralokinumab"
],
[
"Adbry",
"Adtralza"
],
"EFO_0000274",
"atopic eczema",
4,
[],
true
],
[
"CHEMBL1743081",
"TRALOKINUMAB",
"Antibody",
"Interleukin-13 inhibitor",
"Antibody drug with a maximum clinical trial phase of IV (across all indications) that was first approved in 2021 and is indicated for atopic eczema and eczematoid dermatitis and has 5 investigational indications.",
[
"CAT-354",
"Tralokinumab"
],
[
"Adbry",
"Adtralza"
],
"EFO_0000274",
"atopic eczema",
3,
[
"NCT03587805"
],
true
]
]
},


"test_opentargets_tractability": {
Expand Down Expand Up @@ -234,17 +299,113 @@
}
]
},
"test_pharmacogenetics_no_limit": {
"test_opentargets_pharmacogenetics_no_limit": {
"type": "assert_equal_json_hash_nested",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "pharmacogenetics"
},
"expected_result": "34e64088e72da5710cdacd522c5fbd67"
},
"test_opentargets_pharmacogenetics_filter": {
"type": "assert_equal_nested",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "pharmacogenetics",
"filters": {
"drug_id": "CHEMBL535"
}
},
"expected_result": [
{
"direct_target": false,
"drugs": [
{
"id": "CHEMBL535",
"name": "sunitinib"
}
],
"evidence_level": "3",
"genotype": "TT",
"genotype_annotation": "Patients with renal cell carcinoma and the TT genotype may have a decreased severity of drug-induced toxicity when administered sunitinib as compared to patients with the CC or CT genotypes. Other clinical and genetic factors may also influence severity of drug-induced toxicity in patients with renal cell carcinoma who are administered sunitinib.",
"genotype_id": "5_132657117_C_T,T",
"literature": [
"26387812",
"26387812"
],
"phenotype": "decreased severity of drug-induced toxicity",
"response_category": "toxicity",
"rs_id": "rs1800925",
"source": "pharmgkb",
"variant_consequence_id": "SO:0001631",
"variant_consequence_label": "upstream_gene_variant"
},
{
"direct_target": false,
"drugs": [
{
"id": "CHEMBL535",
"name": "sunitinib"
}
],
"evidence_level": "3",
"genotype": "CC",
"genotype_annotation": "Patients with renal cell carcinoma and the CC genotype may have a decreased severity of drug-induced toxicity when administered sunitinib as compared to patients with the TT genotype. Other clinical and genetic factors may also influence severity of drug-induced toxicity in patients with renal cell carcinoma who are administered sunitinib.",
"genotype_id": "5_132657117_C_C,C",
"literature": [
"26387812",
"26387812"
],
"phenotype": "decreased severity of drug-induced toxicity",
"response_category": "toxicity",
"rs_id": "rs1800925",
"source": "pharmgkb",
"variant_consequence_id": "SO:0002073",
"variant_consequence_label": "no_sequence_alteration"
},
{
"direct_target": false,
"drugs": [
{
"id": "CHEMBL535",
"name": "sunitinib"
}
],
"evidence_level": "3",
"genotype": "CT",
"genotype_annotation": "Patients with renal cell carcinoma and the CT genotype may have a decreased severity of drug-induced toxicity when administered sunitinib as compared to patients with the TT genotype. Other clinical and genetic factors may also influence severity of drug-induced toxicity in patients with renal cell carcinoma who are administered sunitinib.",
"genotype_id": "5_132657117_C_C,T",
"literature": [
"26387812",
"26387812"
],
"phenotype": "decreased severity of drug-induced toxicity",
"response_category": "toxicity",
"rs_id": "rs1800925",
"source": "pharmgkb",
"variant_consequence_id": "SO:0001631",
"variant_consequence_label": "upstream_gene_variant"
}
]
},
"test_opentargets_pharmacogenetics_filter_or": {
"type": "assert_equal_json_hash_nested",
"args": {
"ensembl_id": "ENSG00000130164",
"resource": "pharmacogenetics",
"filters": {
"drug_id": [
"CHEMBL1643",
"CHEMBL24"
]
},
"filter_mode": "or"
},
"expected_result": "870d20f5746e90144ff986e800767b87"
},


"test_expression": {
"test_opentargets_expression": {
"type": "assert_equal",
"args": {
"ensembl_id": "ENSG00000169194",
Expand Down Expand Up @@ -302,27 +463,86 @@
]
]
},
"test_expression_no_limit": {
"test_opentargets_expression_no_limit": {
"type": "assert_equal_json_hash",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "expression"
},
"expected_result": "192b5fceebfbb1cc7386cf319c264688"
},
"test_opentargets_expression_filter": {
"type": "assert_equal",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "expression",
"filters": {
"tissue_id": "UBERON_0000473",
"organ": "reproductive organ"
}
},
"expected_result": [
[
"UBERON_0000473",
"testis",
5,
1026,
"",
3,
[
"reproductive system"
],
[
"reproductive organ",
"reproductive structure"
]
]
]
},


"test_depmap": {
"test_opentargets_depmap": {
"type": "assert_equal_json_hash",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "depmap"
},
"expected_result": "83de5c6bfee6e796bd5d68af1af702fc"
},
"test_opentargets_depmap_filter": {
"type": "assert_equal",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "depmap",
"filters": {
"tissue_id": "UBERON_0002367"
},
"limit": 2
},
"expected_result": [
[
"ACH-000977",
-0.08063846,
"UBERON_0002367",
"prostate gland",
"LNCaP clone FGC",
"SIDM00683",
"Prostate Adenocarcinoma"
],
[
"ACH-000979",
-0.09671201,
"UBERON_0002367",
"prostate gland",
"DU 145",
"SIDM00120",
"Prostate Adenocarcinoma"
]
]
},


"test_interactions": {
"test_opentargets_interactions": {
"type": "assert_equal",
"args": {
"ensembl_id": "ENSG00000169194",
Expand Down Expand Up @@ -362,15 +582,15 @@
]
]
},
"test_interactions_no_limit": {
"test_opentargets_interactions_no_limit": {
"type": "assert_equal_json_hash",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "interactions"
},
"expected_result": "483362ee0e9454f16cde738a6dc4887c"
},
"test_interactions_simple_filter": {
"test_opentargets_interactions_simple_filter": {
"type": "assert_equal",
"args": {
"ensembl_id": "ENSG00000169194",
Expand Down Expand Up @@ -411,7 +631,7 @@
]
]
},
"test_interactions_complex_filter": {
"test_opentargets_interactions_complex_filter": {
"type": "assert_equal",
"args": {
"ensembl_id": "ENSG00000169194",
Expand Down Expand Up @@ -533,6 +753,30 @@
},
"expected_result": "ValueError"
},
"test_error_opentargets_diseases_filter": {
"type": "error",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "diseases",
"filters": {
"disease_id": "EFO_0000274"
}
},
"expected_result": "ValueError"
},


"test_error_opentargets_drugs_invalid_filter": {
"type": "error",
"args": {
"ensembl_id": "ENSG00000169194",
"resource": "drugs",
"filters": {
"organ": "brain"
}
},
"expected_result": "ValueError"
},


"test_error_opentargets_tractability_limit": {
Expand Down

0 comments on commit b24c5f1

Please sign in to comment.