Skip to content

Commit a4fc1b1

Browse files
committed
maybe?
1 parent de4d302 commit a4fc1b1

49 files changed

Lines changed: 2578 additions & 885 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

clinvar_api/client.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ class Config(BaseModel):
4747
class _SubmitData:
4848
"""Helper class to reduce redundancy betwee sync/async `sumbit_data`."""
4949

50-
def __init__(self, submission_container: models.SubmissionContainer, config: Config):
50+
def __init__(
51+
self, submission_container: models.SubmissionContainer, config: Config
52+
):
5153
self.submission_container = submission_container
5254
self.config = config
5355

5456
self.url: str = ""
5557
self.headers: typing.Dict[str, str] = {}
5658
self.post_data: typing.Dict[str, typing.Any] = {}
5759

58-
def before_post(self) -> typing.Tuple[str, typing.Dict[str, str], typing.Dict[str, typing.Any]]:
60+
def before_post(
61+
self,
62+
) -> typing.Tuple[str, typing.Dict[str, str], typing.Dict[str, typing.Any]]:
5963
logger.info("Submitting with config %s", self.config)
6064

6165
url_prefix = ENDPOINT_URL_TEST if self.config.use_testing else ENDPOINT_URL_PROD
@@ -69,7 +73,9 @@ def before_post(self) -> typing.Tuple[str, typing.Dict[str, str], typing.Dict[st
6973
payload = self.submission_container.to_msg().model_dump(mode="json")
7074
logger.debug("Payload data is %s", json.dumps(payload, indent=2))
7175
cleaned_payload = common.clean_for_json(payload)
72-
logger.debug("Cleaned payload data is %s", json.dumps(cleaned_payload, indent=2))
76+
logger.debug(
77+
"Cleaned payload data is %s", json.dumps(cleaned_payload, indent=2)
78+
)
7379
if self.config.presubmission_validation:
7480
logger.info("Validating payload...")
7581
schemas.validate_submission_payload(cleaned_payload)
@@ -79,7 +85,11 @@ def before_post(self) -> typing.Tuple[str, typing.Dict[str, str], typing.Dict[st
7985

8086
post_data = {
8187
"actions": [
82-
{"type": "AddData", "targetDb": "clinvar", "data": {"content": cleaned_payload}}
88+
{
89+
"type": "AddData",
90+
"targetDb": "clinvar",
91+
"data": {"content": cleaned_payload},
92+
}
8393
]
8494
}
8595
logger.debug("Overall POST payload is %s", post_data)
@@ -89,7 +99,9 @@ def after_post(self, response: httpx.Response):
8999
if httpx.codes.is_success(response.status_code):
90100
logger.info("API returned OK - %s", response.status_code)
91101
if response.status_code == 204: # no content, on dry-run
92-
logger.info("Server returned '204: No Content', constructing fake created message.")
102+
logger.info(
103+
"Server returned '204: No Content', constructing fake created message."
104+
)
93105
return models.Created(id="--NONE--dry-run-result--")
94106
else:
95107
created_msg = msg.Created.model_validate_json(response.content)
@@ -100,12 +112,18 @@ def after_post(self, response: httpx.Response):
100112
error_obj = models.Error.from_msg(error_msg)
101113
logger.debug("Full server response is %s", response.json())
102114
if hasattr(error_obj, "errors"):
103-
raise exceptions.SubmissionFailed(f"ClinVar submission failed: {error_obj.message}")
115+
raise exceptions.SubmissionFailed(
116+
f"ClinVar submission failed: {error_obj.message}"
117+
)
104118
else:
105-
raise exceptions.SubmissionFailed(f"ClinVar submission failed: {error_obj.message}")
119+
raise exceptions.SubmissionFailed(
120+
f"ClinVar submission failed: {error_obj.message}"
121+
)
106122

107123

108-
def submit_data(submission_container: models.SubmissionContainer, config: Config) -> models.Created:
124+
def submit_data(
125+
submission_container: models.SubmissionContainer, config: Config
126+
) -> models.Created:
109127
"""Submit new data to ClinVar API (sync).
110128
111129
:param submission_container: The submission data.
@@ -115,7 +133,9 @@ def submit_data(submission_container: models.SubmissionContainer, config: Config
115133
"""
116134
helper = _SubmitData(submission_container, config)
117135
url, headers, post_data = helper.before_post()
118-
response = httpx.post(url, headers=headers, json=post_data, verify=config.verify_ssl)
136+
response = httpx.post(
137+
url, headers=headers, json=post_data, verify=config.verify_ssl
138+
)
119139
return helper.after_post(response)
120140

121141

@@ -219,7 +239,9 @@ def after_first_get_success(
219239
return more_urls, status_obj
220240

221241
def after_get_more_urls(
222-
self, status_obj: models.SubmissionStatus, more_results: typing.Dict[str, httpx.Response]
242+
self,
243+
status_obj: models.SubmissionStatus,
244+
more_results: typing.Dict[str, httpx.Response],
223245
) -> RetrieveStatusResult:
224246
summaries = {}
225247
for url, response in more_results.items():
@@ -283,7 +305,9 @@ async def async_retrieve_status(
283305
)
284306
tasks[url] = client.get(url)
285307

286-
more_results = dict(zip(tasks.keys(), await asyncio.gather(*tasks.values())))
308+
more_results = dict(
309+
zip(tasks.keys(), await asyncio.gather(*tasks.values()))
310+
)
287311
return helper.after_get_more_urls(status_obj, more_results)
288312
else:
289313
return helper.after_first_get_failure(response)

clinvar_api/common.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33

44
def clean_for_json(
55
value: typing.Union[
6-
bool, int, float, typing.List[typing.Any], None, typing.Dict[str, typing.Any], str
6+
bool,
7+
int,
8+
float,
9+
typing.List[typing.Any],
10+
None,
11+
typing.Dict[str, typing.Any],
12+
str,
713
]
814
) -> typing.Union[
915
bool, int, float, typing.List[typing.Any], None, typing.Dict[str, typing.Any], str

clinvar_api/models/query_response.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ class SubmissionStatusActions(BaseModel):
116116
def from_msg(cls, other: msg.SubmissionStatusActions):
117117
return SubmissionStatusActions(
118118
id=other.id,
119-
responses=[SubmissionStatusResponse.from_msg(response) for response in other.responses],
119+
responses=[
120+
SubmissionStatusResponse.from_msg(response)
121+
for response in other.responses
122+
],
120123
status=other.status,
121124
target_db=other.targetDb,
122125
updated=other.updated,
@@ -134,5 +137,7 @@ class SubmissionStatus(BaseModel):
134137
@classmethod
135138
def from_msg(cls, other: msg.SubmissionStatus):
136139
return SubmissionStatus(
137-
actions=[SubmissionStatusActions.from_msg(action) for action in other.actions]
140+
actions=[
141+
SubmissionStatusActions.from_msg(action) for action in other.actions
142+
]
138143
)

clinvar_api/models/sub_payload.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ class SubmissionClinvarDeletion(BaseModel):
5454

5555
def to_msg(self) -> msg.SubmissionClinvarDeletion:
5656
return msg.SubmissionClinvarDeletion(
57-
accessionSet=[msg_accession_set.to_msg() for msg_accession_set in self.accession_set],
57+
accessionSet=[
58+
msg_accession_set.to_msg() for msg_accession_set in self.accession_set
59+
],
5860
)
5961

6062

@@ -378,7 +380,9 @@ def to_msg(self) -> msg.SubmissionConditionSetGermline:
378380
condition = [msg_condition.to_msg() for msg_condition in self.condition]
379381
drug_response = None
380382
if self.drug_response:
381-
drug_response = [msg_response.to_msg() for msg_response in self.drug_response]
383+
drug_response = [
384+
msg_response.to_msg() for msg_response in self.drug_response
385+
]
382386
return msg.SubmissionConditionSetGermline(
383387
condition=condition,
384388
drugResponse=drug_response,
@@ -397,7 +401,9 @@ def to_msg(self) -> msg.SubmissionConditionSetSomatic:
397401
condition = [msg_condition.to_msg() for msg_condition in self.condition]
398402
drug_response = None
399403
if self.drug_response:
400-
drug_response = [msg_response.to_msg() for msg_response in self.drug_response]
404+
drug_response = [
405+
msg_response.to_msg() for msg_response in self.drug_response
406+
]
401407
return msg.SubmissionConditionSetSomatic(
402408
condition=condition,
403409
drugResponse=drug_response,
@@ -520,7 +526,9 @@ def to_msg(self) -> msg.SubmissionClinvarSubmission:
520526
return msg.SubmissionClinvarSubmission(
521527
clinicalSignificance=self.clinical_significance.to_msg(),
522528
conditionSet=self.condition_set.to_msg(),
523-
observedIn=[msg_observed_in.to_msg() for msg_observed_in in self.observed_in],
529+
observedIn=[
530+
msg_observed_in.to_msg() for msg_observed_in in self.observed_in
531+
],
524532
recordStatus=self.record_status,
525533
clinvarAccession=self.clinvar_accession,
526534
compoundHeterozygoteSet=compound_heterozygote_set,
@@ -538,8 +546,12 @@ def to_msg(self) -> msg.SubmissionClinvarSubmission:
538546
class SomaticClinicalImpactClassification(_SubmissionClinicalSignificanceBase):
539547
"""Details of somatic clinical impact classification."""
540548

541-
clinical_impact_classification_description: SomaticClinicalImpactClassificationDescription
542-
assertion_type_for_clinical_impact: typing.Optional[SomaticClinicalImpactAssertionType] = None
549+
clinical_impact_classification_description: (
550+
SomaticClinicalImpactClassificationDescription
551+
)
552+
assertion_type_for_clinical_impact: typing.Optional[
553+
SomaticClinicalImpactAssertionType
554+
] = None
543555
drug_for_therapeutic_assertion: typing.Optional[str] = None
544556

545557
def to_msg(self) -> msg.SomaticClinicalImpactClassification:
@@ -591,7 +603,9 @@ def to_msg(self) -> msg.SubmissionClinicalImpactSubmission:
591603
return msg.SubmissionClinicalImpactSubmission(
592604
clinicalImpactClassification=self.clinical_impact_classification.to_msg(),
593605
conditionSet=self.condition_set.to_msg(),
594-
observedIn=[msg_observed_in.to_msg() for msg_observed_in in self.observed_in],
606+
observedIn=[
607+
msg_observed_in.to_msg() for msg_observed_in in self.observed_in
608+
],
595609
recordStatus=self.record_status,
596610
clinvarAccession=self.clinvar_accession,
597611
compoundHeterozygoteSet=compound_heterozygote_set,
@@ -659,7 +673,9 @@ def to_msg(self) -> msg.SubmissionOncogenicitySubmission:
659673
return msg.SubmissionOncogenicitySubmission(
660674
oncogenicityClassification=self.oncogenicity_classification.to_msg(),
661675
conditionSet=self.condition_set.to_msg(),
662-
observedIn=[msg_observed_in.to_msg() for msg_observed_in in self.observed_in],
676+
observedIn=[
677+
msg_observed_in.to_msg() for msg_observed_in in self.observed_in
678+
],
663679
recordStatus=self.record_status,
664680
clinvarAccession=self.clinvar_accession,
665681
compoundHeterozygoteSet=compound_heterozygote_set,
@@ -734,7 +750,9 @@ def to_msg(self) -> msg.SubmissionGermlineSubmission:
734750
return msg.SubmissionGermlineSubmission(
735751
germlineClassification=self.germline_classification.to_msg(),
736752
conditionSet=self.condition_set.to_msg(),
737-
observedIn=[msg_observed_in.to_msg() for msg_observed_in in self.observed_in],
753+
observedIn=[
754+
msg_observed_in.to_msg() for msg_observed_in in self.observed_in
755+
],
738756
recordStatus=self.record_status,
739757
clinvarAccession=self.clinvar_accession,
740758
compoundHeterozygoteSet=compound_heterozygote_set,
@@ -756,11 +774,15 @@ class SubmissionContainer(BaseModel):
756774
behalf_org_id: typing.Optional[int] = None
757775
clinvar_deletion: typing.Optional[SubmissionClinvarDeletion] = None
758776
clinvar_submission: typing.Optional[typing.List[SubmissionClinvarSubmission]] = None
759-
germline_submission: typing.Optional[typing.List[SubmissionGermlineSubmission]] = None
760-
oncogenicity_submission: typing.Optional[typing.List[SubmissionOncogenicitySubmission]] = None
761-
clinical_impact_submission: typing.Optional[typing.List[SubmissionClinicalImpactSubmission]] = (
777+
germline_submission: typing.Optional[typing.List[SubmissionGermlineSubmission]] = (
762778
None
763779
)
780+
oncogenicity_submission: typing.Optional[
781+
typing.List[SubmissionOncogenicitySubmission]
782+
] = None
783+
clinical_impact_submission: typing.Optional[
784+
typing.List[SubmissionClinicalImpactSubmission]
785+
] = None
764786
clinvar_submission_release_status: typing.Optional[ReleaseStatus] = None
765787
submission_name: typing.Optional[str] = None
766788

@@ -784,12 +806,14 @@ def to_msg(self) -> msg.SubmissionContainer:
784806
oncogenicity_submission = None
785807
if self.oncogenicity_submission:
786808
oncogenicity_submission = [
787-
msg_submission.to_msg() for msg_submission in self.oncogenicity_submission
809+
msg_submission.to_msg()
810+
for msg_submission in self.oncogenicity_submission
788811
]
789812
clinical_impact_submission = None
790813
if self.clinical_impact_submission:
791814
clinical_impact_submission = [
792-
msg_submission.to_msg() for msg_submission in self.clinical_impact_submission
815+
msg_submission.to_msg()
816+
for msg_submission in self.clinical_impact_submission
793817
]
794818
return msg.SubmissionContainer(
795819
assertionCriteria=assertion_criteria,

clinvar_api/models/sub_response.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class SummaryResponseErrorOutput(BaseModel):
7070
def from_msg(cls, other: msg.SummaryResponseErrorOutput):
7171
return SummaryResponseErrorOutput(
7272
errors=[
73-
SummaryResponseErrorOutputError.from_msg(msg_error) for msg_error in other.errors
73+
SummaryResponseErrorOutputError.from_msg(msg_error)
74+
for msg_error in other.errors
7475
]
7576
)
7677

@@ -84,7 +85,10 @@ class SummaryResponseError(BaseModel):
8485
@classmethod
8586
def from_msg(cls, other: msg.SummaryResponseError):
8687
return SummaryResponseError(
87-
input=[SummaryResponseErrorInput.from_msg(msg_input) for msg_input in other.input],
88+
input=[
89+
SummaryResponseErrorInput.from_msg(msg_input)
90+
for msg_input in other.input
91+
],
8892
output=SummaryResponseErrorOutput.from_msg(other.output),
8993
)
9094

@@ -116,7 +120,9 @@ class SummaryResponseDeletion(BaseModel):
116120
def from_msg(cls, other: msg.SummaryResponseDeletion):
117121
errors = None
118122
if other.errors:
119-
errors = [SummaryResponseError.from_msg(msg_error) for msg_error in other.errors]
123+
errors = [
124+
SummaryResponseError.from_msg(msg_error) for msg_error in other.errors
125+
]
120126
return SummaryResponseDeletion(
121127
identifiers=SummaryResponseDeletionIdentifier.from_msg(other.identifiers),
122128
processing_status=other.processingStatus,
@@ -158,7 +164,9 @@ class SummaryResponseSubmission(BaseModel):
158164
def from_msg(cls, other: msg.SummaryResponseSubmission):
159165
errors = None
160166
if other.errors:
161-
errors = [SummaryResponseError.from_msg(msg_error) for msg_error in other.errors]
167+
errors = [
168+
SummaryResponseError.from_msg(msg_error) for msg_error in other.errors
169+
]
162170
return SummaryResponseSubmission(
163171
identifiers=SummaryResponseSubmissionIdentifiers.from_msg(
164172
other.identifiers,
@@ -196,7 +204,8 @@ def from_msg(cls, other: msg.SummaryResponse):
196204
deletions = None
197205
if other.deletions:
198206
deletions = [
199-
SummaryResponseDeletion.from_msg(msg_deletion) for msg_deletion in other.deletions
207+
SummaryResponseDeletion.from_msg(msg_deletion)
208+
for msg_deletion in other.deletions
200209
]
201210
submissions = None
202211
if other.submissions:

clinvar_api/msg/sub_payload.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,12 @@ class SubmissionClinvarSubmission(_SubmissionClinvarSubmissionBase):
483483
class SomaticClinicalImpactClassification(_SubmissionClinicalSignificanceBase):
484484
"""Details of somatic clinical impact classification."""
485485

486-
clinicalImpactClassificationDescription: SomaticClinicalImpactClassificationDescription
487-
assertionTypeForClinicalImpact: typing.Optional[SomaticClinicalImpactAssertionType] = None
486+
clinicalImpactClassificationDescription: (
487+
SomaticClinicalImpactClassificationDescription
488+
)
489+
assertionTypeForClinicalImpact: typing.Optional[
490+
SomaticClinicalImpactAssertionType
491+
] = None
488492
drugForTherapeuticAssertion: typing.Optional[str] = None
489493

490494

@@ -540,12 +544,16 @@ class SubmissionContainer(BaseModel):
540544
#: "clinicalImpactSubmission", "oncogenicitySubmission", and "germlineSubmission".
541545
clinvarSubmission: typing.Optional[typing.List[SubmissionClinvarSubmission]] = None
542546
#: ClinVar Submission Set for germline variants
543-
germlineSubmission: typing.Optional[typing.List[SubmissionGermlineSubmission]] = None
544-
#: ClinVar Submission Set for somatic variants with oncogenicityClassification.
545-
oncogenicitySubmission: typing.Optional[typing.List[SubmissionOncogenicitySubmission]] = None
546-
#: ClinVar Submission Set for somatic variants with clinicalImpactClassification.
547-
clinicalImpactSubmission: typing.Optional[typing.List[SubmissionClinicalImpactSubmission]] = (
547+
germlineSubmission: typing.Optional[typing.List[SubmissionGermlineSubmission]] = (
548548
None
549549
)
550+
#: ClinVar Submission Set for somatic variants with oncogenicityClassification.
551+
oncogenicitySubmission: typing.Optional[
552+
typing.List[SubmissionOncogenicitySubmission]
553+
] = None
554+
#: ClinVar Submission Set for somatic variants with clinicalImpactClassification.
555+
clinicalImpactSubmission: typing.Optional[
556+
typing.List[SubmissionClinicalImpactSubmission]
557+
] = None
550558
clinvarSubmissionReleaseStatus: typing.Optional[ReleaseStatus] = None
551559
submissionName: typing.Optional[str] = None

0 commit comments

Comments
 (0)