Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace isort, black, pylint with ruff #246

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion clinvar_ingest/api/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async def dispatch(self, request: Request, call_next: Callable) -> Response:
response = await call_next(request)
elapsed_ms = int((time.time() - start_ms) * MS_PER_S)
logger.info(
f"{request.method} {request.url.path} id={request_id} elapsed_ms={elapsed_ms} status_code={response.status_code}"
f"{request.method} {request.url.path} id={request_id} "
f"elapsed_ms={elapsed_ms} status_code={response.status_code}"
)
return response
3 changes: 2 additions & 1 deletion clinvar_ingest/api/status_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def get_status_file(
blob: Blob = bucket.get_blob(f"{file_prefix}/{step}-{status}.json")
if blob is None:
raise ValueError(
f"Could not find status file for step {step} with status {status} in bucket {bucket} and file prefix {file_prefix}"
f"Could not find status file for step {step} with status {status} "
f"in bucket {bucket} and file prefix {file_prefix}"
)
content = blob.download_as_string()
return StatusValue(**json.loads(content))
6 changes: 2 additions & 4 deletions clinvar_ingest/model/trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,8 @@ def find_matching_trait(

# "XRef"
is_xref_match = mapping.mapping_type == "XRef" and any(
[
x.db == mapping.mapping_ref and x.id == mapping.mapping_value
for x in me.xrefs
]
x.db == mapping.mapping_ref and x.id == mapping.mapping_value
for x in me.xrefs
)
if is_xref_match:
_logger.debug("is_xref_match: %s", is_xref_match)
Expand Down
2 changes: 1 addition & 1 deletion clinvar_ingest/model/variation_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ def from_xml(inp: dict):
raw_classifications = extract(interp_record, "Classifications")
else:
raw_classifications = {}
raw_classification_types = set([r.value for r in StatementType]).intersection(
raw_classification_types = {r.value for r in StatementType}.intersection(
set(raw_classifications.keys())
)
raw_trait_sets = flatten1(
Expand Down
6 changes: 0 additions & 6 deletions lint
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ had_error=0

if [[ "$1" == "apply" ]]; then
# Uses each linter's option to apply the changes if it is supported
black clinvar_ingest test || had_error=1
isort clinvar_ingest test || had_error=1
ruff check --fix clinvar_ingest test || had_error=1
pylint --disable=C,R,W clinvar_ingest || had_error=1
else
# Check-only mode
black --check clinvar_ingest test || had_error=1
isort --check-only clinvar_ingest test || had_error=1
ruff check clinvar_ingest test || had_error=1
pylint --disable=C,R,W clinvar_ingest || had_error=1
fi

exit $had_error
26 changes: 21 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ dynamic = ["version"]
[project.optional-dependencies]
dev = [
"ipykernel",
"black~=23.9.1",
"isort~=5.13.2",
# "black~=23.9.1",
# "isort~=5.13.2",
"ruff~=0.6.3",
"pytest~=7.4.3",
"pylint~=3.2.6",
# "pylint~=3.2.6",
"httpx~=0.25.2",
]

Expand All @@ -45,5 +45,21 @@ include = ["clinvar_ingest*"]
"clinvar_ingest" = ["*.json", ".*.env"]
"clinvar_ingest.cloud.bigquery.bq_json_schemas" = ["*.json"]

[tool.isort]
profile = "black"
[tool.ruff]
line-length = 120
target-version = "py311"

[tool.ruff.lint]
select = [
"C",
"F",
"I",
"E",
"W"
]
fixable = ["ALL"]
ignore = ["C901"]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
2 changes: 1 addition & 1 deletion test/data/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-i clinvar-new/ClinVarVCVRelease_2024-08.xml.gz \
-o clinvar-new \
-v VCV000000002,VCV000000010,VCV000000032,VCV000000051,VCV000004897,VCV000040200,VCV000222476,VCV000406155,VCV000424711,VCV000634266,VCV001264328
"""
""" # noqa: E501

import argparse
import gzip
Expand Down
2 changes: 1 addition & 1 deletion test/data/filter_somatic-oncogenicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_classifications(variation_archive_elem: ET.Element) -> list[ET.Element]:
# classifications = variation_archive_elem.find("IncludedRecord/Classifications")
if classifications is None:
return []
types = set(o.value for o in StatementType)
types = {o.value for o in StatementType}
stmts = []
for statement_key in types:
statement = classifications.find(statement_key)
Expand Down
8 changes: 4 additions & 4 deletions test/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_read_original_clinvar_variation_2():
assert rcv.version == 5
assert (
rcv.title
== "NM_014855.3(AP5Z1):c.80_83delinsTGCTGTAAACTGTAACTGTAAA (p.Arg27_Ile28delinsLeuLeuTer) AND Hereditary spastic paraplegia 48"
== "NM_014855.3(AP5Z1):c.80_83delinsTGCTGTAAACTGTAACTGTAAA (p.Arg27_Ile28delinsLeuLeuTer) AND Hereditary spastic paraplegia 48" # noqa: E501
)
assert rcv.trait_set_id == "2"

Expand Down Expand Up @@ -189,7 +189,7 @@ def test_scv_9794255():
assert scv005045669.interpretation_description == "Tier I - Strong"
assert scv005045669.interpretation_comments == [
{
"text": "Combination treatment of BRAF inhibitor dabrafenib and MEK inhibitor trametinib is recommended for adjuvant treatment of stage III or recurrent melanoma with BRAF V600E mutation detected by the approved THxID kit, as well as first line treatment for metastatic melanoma. The treatments are FDA approved based on studies including the Phase III COMBI-V, COMBI-D and COMBI-AD Trials. Combination therapy is now recommended above BRAF inhibitor monotherapy. Cutaneous squamous-cell carcinoma and keratoacanthoma occur at lower rates with combination therapy than with BRAF inhibitor alone."
"text": "Combination treatment of BRAF inhibitor dabrafenib and MEK inhibitor trametinib is recommended for adjuvant treatment of stage III or recurrent melanoma with BRAF V600E mutation detected by the approved THxID kit, as well as first line treatment for metastatic melanoma. The treatments are FDA approved based on studies including the Phase III COMBI-V, COMBI-D and COMBI-AD Trials. Combination therapy is now recommended above BRAF inhibitor monotherapy. Cutaneous squamous-cell carcinoma and keratoacanthoma occur at lower rates with combination therapy than with BRAF inhibitor alone." # noqa: E501
}
]
assert scv005045669.submitter_id == "509553"
Expand Down Expand Up @@ -754,7 +754,7 @@ def test_read_original_clinvar_variation_10():
"""
Get trait set ids from the vcv
xq -x '//ClinVarVariationRelease/VariationArchive/InterpretedRecord/Interpretations/Interpretation/ConditionList/TraitSet/@ID' VCV000000010.xml
"""
""" # noqa: E501

clinical_assertion_traits = [
o for o in objects if isinstance(o, ClinicalAssertionTrait)
Expand Down Expand Up @@ -786,7 +786,7 @@ def test_read_original_clinvar_variation_10():
scv001251532 = scv[0]
assert len(scv001251532.interpretation_comments) == 1
assert scv001251532.interpretation_comments[0]["text"] == html.unescape(
"The HFE c.187C>G (p.H63D) variant is a pathogenic variant seen in 10.8% of the human population in gnomAD. Indviduals with the p.H63D variant are considered carriers of hemochromatosis, although this variant is associated with less severe iron overload and reduced penetrance compared to another pathogenic HFE variant, c.845G>A, p.C282Y (PMID: 19159930; 20301613)."
"The HFE c.187C>G (p.H63D) variant is a pathogenic variant seen in 10.8% of the human population in gnomAD. Indviduals with the p.H63D variant are considered carriers of hemochromatosis, although this variant is associated with less severe iron overload and reduced penetrance compared to another pathogenic HFE variant, c.845G>A, p.C282Y (PMID: 19159930; 20301613)." # noqa: E501
)
assert "type" not in scv001251532.interpretation_comments[0]

Expand Down
2 changes: 1 addition & 1 deletion test/test_parse_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_vcv_VCV000000002():
assert rcv.independent_observations is None
assert (
rcv.title
== "NM_014855.3(AP5Z1):c.80_83delinsTGCTGTAAACTGTAACTGTAAA (p.Arg27_Ile28delinsLeuLeuTer) AND Hereditary spastic paraplegia 48"
== "NM_014855.3(AP5Z1):c.80_83delinsTGCTGTAAACTGTAACTGTAAA (p.Arg27_Ile28delinsLeuLeuTer) AND Hereditary spastic paraplegia 48" # noqa: E501
)
assert rcv.trait_set_id == "2"
assert rcv.variation_archive_id == "VCV000000002"
Expand Down
6 changes: 3 additions & 3 deletions test/test_trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


def unordered_dict_list_equal(list1: list[dict], list2: list[dict]) -> bool:
set1 = set([tuple(elem.items()) for elem in list1])
set2 = set([tuple(elem.items()) for elem in list2])
set1 = {tuple(elem.items()) for elem in list1}
set2 = {tuple(elem.items()) for elem in list2}
return len(list1) == len(list2) and set1 == set2


Expand Down Expand Up @@ -267,7 +267,7 @@ def test_trait_from_xml_406155():
# And a public_definition (with xref)
assert (
trait.public_definition
== "The spectrum of MECP2-related phenotypes in females ranges from classic Rett syndrome to variant Rett syndrome with a broader clinical phenotype (either milder or more severe than classic Rett syndrome) to mild learning disabilities; the spectrum in males ranges from severe neonatal encephalopathy to pyramidal signs, parkinsonism, and macroorchidism (PPM-X) syndrome to severe syndromic/nonsyndromic intellectual disability. Females: Classic Rett syndrome, a progressive neurodevelopmental disorder primarily affecting girls, is characterized by apparently normal psychomotor development during the first six to 18 months of life, followed by a short period of developmental stagnation, then rapid regression in language and motor skills, followed by long-term stability. During the phase of rapid regression, repetitive, stereotypic hand movements replace purposeful hand use. Additional findings include fits of screaming and inconsolable crying, autistic features, panic-like attacks, bruxism, episodic apnea and/or hyperpnea, gait ataxia and apraxia, tremors, seizures, and acquired microcephaly. Males: Severe neonatal-onset encephalopathy, the most common phenotype in affected males, is characterized by a relentless clinical course that follows a metabolic-degenerative type of pattern, abnormal tone, involuntary movements, severe seizures, and breathing abnormalities. Death often occurs before age two years."
== "The spectrum of MECP2-related phenotypes in females ranges from classic Rett syndrome to variant Rett syndrome with a broader clinical phenotype (either milder or more severe than classic Rett syndrome) to mild learning disabilities; the spectrum in males ranges from severe neonatal encephalopathy to pyramidal signs, parkinsonism, and macroorchidism (PPM-X) syndrome to severe syndromic/nonsyndromic intellectual disability. Females: Classic Rett syndrome, a progressive neurodevelopmental disorder primarily affecting girls, is characterized by apparently normal psychomotor development during the first six to 18 months of life, followed by a short period of developmental stagnation, then rapid regression in language and motor skills, followed by long-term stability. During the phase of rapid regression, repetitive, stereotypic hand movements replace purposeful hand use. Additional findings include fits of screaming and inconsolable crying, autistic features, panic-like attacks, bruxism, episodic apnea and/or hyperpnea, gait ataxia and apraxia, tremors, seizures, and acquired microcephaly. Males: Severe neonatal-onset encephalopathy, the most common phenotype in affected males, is characterized by a relentless clinical course that follows a metabolic-degenerative type of pattern, abnormal tone, involuntary movements, severe seizures, and breathing abnormalities. Death often occurs before age two years." # noqa: E501
)
assert {
"db": "GeneReviews",
Expand Down
20 changes: 9 additions & 11 deletions test/test_variation.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,15 @@ def test_clinical_assertion_variation_descendants_genotype():
assert simplealleleBC.child_ids == []

# Check descendants
assert list(sorted(genotype.descendant_ids)) == list(
sorted(
[
haplotypeA.id,
simplealleleAA.id,
haplotypeB.id,
simplealleleBA.id,
simplealleleBB.id,
simplealleleBC.id,
]
)
assert sorted(genotype.descendant_ids) == sorted(
[
haplotypeA.id,
simplealleleAA.id,
haplotypeB.id,
simplealleleBA.id,
simplealleleBB.id,
simplealleleBC.id,
]
)
assert haplotypeA.descendant_ids == [simplealleleAA.id]
assert simplealleleAA.descendant_ids == []
Expand Down
Loading