Skip to content

Commit

Permalink
linting - isort and black
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinbleile committed Jul 12, 2024
1 parent a15f56e commit 7e67692
Show file tree
Hide file tree
Showing 34 changed files with 1,787 additions and 1,350 deletions.
3 changes: 1 addition & 2 deletions pori_python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import ipr
from . import graphkb
from . import graphkb, ipr
2 changes: 1 addition & 1 deletion pori_python/graphkb/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def __getitem__(self, key):
}

# For match.type_screening() [KBDEV-1056]
DEFAULT_NON_STRUCTURAL_VARIANT_TYPE = 'mutation'
DEFAULT_NON_STRUCTURAL_VARIANT_TYPE = "mutation"
STRUCTURAL_VARIANT_SIZE_THRESHOLD = 48 # bp
STRUCTURAL_VARIANT_TYPES = [
"structural variant",
Expand Down
73 changes: 59 additions & 14 deletions pori_python/graphkb/genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@


def _get_tumourigenesis_genes_list(
conn: GraphKBConnection, relevance: str, sources: List[str], ignore_cache: bool = False
conn: GraphKBConnection,
relevance: str,
sources: List[str],
ignore_cache: bool = False,
) -> List[Ontology]:
statements = cast(
List[Statement],
Expand All @@ -34,10 +37,17 @@ def _get_tumourigenesis_genes_list(
"filters": {
"AND": [
{"source": {"target": "Source", "filters": {"name": sources}}},
{"relevance": {"target": "Vocabulary", "filters": {"name": relevance}}},
{
"relevance": {
"target": "Vocabulary",
"filters": {"name": relevance},
}
},
]
},
"returnProperties": [f"subject.{prop}" for prop in GENE_RETURN_PROPERTIES],
"returnProperties": [
f"subject.{prop}" for prop in GENE_RETURN_PROPERTIES
],
},
ignore_cache=ignore_cache,
),
Expand Down Expand Up @@ -74,7 +84,9 @@ def get_oncokb_tumour_supressors(conn: GraphKBConnection) -> List[Ontology]:
Returns:
gene (Feature) records
"""
return _get_tumourigenesis_genes_list(conn, TUMOUR_SUPPRESSIVE, [ONCOKB_SOURCE_NAME])
return _get_tumourigenesis_genes_list(
conn, TUMOUR_SUPPRESSIVE, [ONCOKB_SOURCE_NAME]
)


def get_cancer_genes(conn: GraphKBConnection) -> List[Ontology]:
Expand Down Expand Up @@ -147,7 +159,12 @@ def get_genes_from_variant_types(
filters: List[Dict[str, Any]] = []
if types:
filters.append(
{"type": {"target": "Vocabulary", "filters": {"name": types, "operator": "IN"}}}
{
"type": {
"target": "Vocabulary",
"filters": {"name": types, "operator": "IN"},
}
}
)

variants = cast(
Expand Down Expand Up @@ -177,7 +194,11 @@ def get_genes_from_variant_types(
result = cast(
List[Ontology],
conn.query(
{"target": list(genes), "returnProperties": GENE_RETURN_PROPERTIES, "filters": filters},
{
"target": list(genes),
"returnProperties": GENE_RETURN_PROPERTIES,
"filters": filters,
},
ignore_cache=ignore_cache,
),
)
Expand Down Expand Up @@ -273,7 +294,12 @@ def get_gene_linked_cancer_predisposition_info(
"filters": {"@rid": get_rid(conn, "Source", "CGL")},
}
},
{"relevance": {"target": "Vocabulary", "filters": {"@rid": relevance_rids}}},
{
"relevance": {
"target": "Vocabulary",
"filters": {"@rid": relevance_rids},
}
},
]
},
"returnProperties": [
Expand Down Expand Up @@ -307,7 +333,10 @@ def get_gene_linked_cancer_predisposition_info(
logger.error(
f"Non-gene cancer predisposition {biotype}: {name} for {condition['displayName']}"
)
variants[condition["@rid"]] = [condition["displayName"], assoc_gene_list]
variants[condition["@rid"]] = [
condition["displayName"],
assoc_gene_list,
]

for gene, name, biotype in infer_genes:
logger.debug(f"Found gene '{gene}' for '{name}' ({biotype})")
Expand Down Expand Up @@ -359,7 +388,12 @@ def get_gene_linked_pharmacogenomic_info(
{
"target": "Statement",
"filters": [
{"relevance": {"target": "Vocabulary", "filters": {"@rid": relevance_rids}}}
{
"relevance": {
"target": "Vocabulary",
"filters": {"@rid": relevance_rids},
}
}
],
"returnProperties": [
"conditions.@class",
Expand Down Expand Up @@ -397,7 +431,10 @@ def get_gene_linked_pharmacogenomic_info(
logger.error(
f"Non-gene pharmacogenomic {biotype}: {name} for {condition['displayName']}"
)
variants[condition["@rid"]] = [condition["displayName"], assoc_gene_list]
variants[condition["@rid"]] = [
condition["displayName"],
assoc_gene_list,
]
for gene, name, biotype in infer_genes:
logger.debug(f"Found gene '{gene}' for '{name}' ({biotype})")
genes.add(gene)
Expand Down Expand Up @@ -449,7 +486,9 @@ def get_gene_information(

gene_names = sorted(set(gene_names))
statements = graphkb_conn.query(body)
statements = [s for s in statements if s.get("reviewStatus") != FAILED_REVIEW_STATUS]
statements = [
s for s in statements if s.get("reviewStatus") != FAILED_REVIEW_STATUS
]

gene_flags: Dict[str, Set[str]] = {
"kbStatementRelated": set(),
Expand All @@ -472,9 +511,13 @@ def get_gene_information(
logger.info("fetching oncogenes list")
gene_flags["oncogene"] = convert_to_rid_set(get_oncokb_oncogenes(graphkb_conn))
logger.info("fetching tumour supressors list")
gene_flags["tumourSuppressor"] = convert_to_rid_set(get_oncokb_tumour_supressors(graphkb_conn))
gene_flags["tumourSuppressor"] = convert_to_rid_set(
get_oncokb_tumour_supressors(graphkb_conn)
)
logger.info("fetching cancerGeneListMatch list")
gene_flags["cancerGeneListMatch"] = convert_to_rid_set(get_cancer_genes(graphkb_conn))
gene_flags["cancerGeneListMatch"] = convert_to_rid_set(
get_cancer_genes(graphkb_conn)
)

logger.info("fetching therapeutic associated genes lists")
gene_flags["therapeuticAssociated"] = convert_to_rid_set(
Expand All @@ -484,7 +527,9 @@ def get_gene_information(
logger.info(f"Setting gene_info flags on {len(gene_names)} genes")
result = []
for gene_name in gene_names:
equivalent = convert_to_rid_set(get_equivalent_features(graphkb_conn, gene_name))
equivalent = convert_to_rid_set(
get_equivalent_features(graphkb_conn, gene_name)
)
row = {"name": gene_name}
flagged = False
for flag in gene_flags:
Expand Down
Loading

0 comments on commit 7e67692

Please sign in to comment.