Skip to content
Draft
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
4 changes: 2 additions & 2 deletions civicpy/civic.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ def _is_valid_for_gks_json(cls, emit_warnings: bool = False) -> bool:
warnings.append(f"{prefix} does not have 'accepted' status. Skipping")

record_type = cls.evidence_type if isinstance(cls, Evidence) else cls.assertion_type
if record_type not in ("DIAGNOSTIC", "PREDICTIVE", "PROGNOSTIC"):
if record_type not in ("DIAGNOSTIC", "PREDICTIVE", "PROGNOSTIC", "ONCOGENIC"):
warnings.append(
f"{prefix} type is not one of: 'DIAGNOSTIC', 'PREDICTIVE', or 'PROGNOSTIC'. Skipping"
f"{prefix} type is not one of: 'DIAGNOSTIC', 'PREDICTIVE', 'PROGNOSTIC', or 'ONCOGENIC'. Skipping"
)

len_mp_variants = len(cls.molecular_profile.variants)
Expand Down
34 changes: 29 additions & 5 deletions civicpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
from civicpy import civic
from civicpy.__env__ import LOCAL_CACHE_PATH
from civicpy.exports.civic_gks_record import (
CivicGksClinSigAssertion,
CivicGksOncogenicAssertion,
CivicGksRecordError,
CivicGksAssertion
ClinVarSubmissionType,
create_gks_record_from_assertion,
)
from civicpy.exports.civic_gks_writer import CivicGksWriter, GksAssertionError
from civicpy.exports.civic_vcf_writer import CivicVcfWriter
Expand Down Expand Up @@ -71,6 +74,16 @@ def create_vcf(vcf_file_path, include_status):
help="The CIViC organization ID that approved the assertion(s) for submission to ClinVar.",
type=int,
)
@click.option(
"--submission-type",
type=click.Choice(
[s.value for s in ClinVarSubmissionType],
case_sensitive=True,
),
help="The ClinVar submission type to generate GKS JSON for.",
default=ClinVarSubmissionType.CLINICAL_IMPACT.value,
show_default=True,
)
@click.option(
"-o",
"--output-json",
Expand All @@ -83,13 +96,22 @@ def create_vcf(vcf_file_path, include_status):
path_type=Path,
),
)
def create_gks_json(organization_id: int, output_json: Path) -> None:
def create_gks_json(
organization_id: int, submission_type: ClinVarSubmissionType, output_json: Path
) -> None:
"""Create a JSON file for CIViC assertion records approved by a specific organization that are ready for ClinVar submission, represented as GKS objects.

For now, we will only support simple molecular profiles and diagnostic, prognostic,
or predictive assertions.
predictive, or oncogenic assertions.

ClinVar only supports submitting records of the same submission type for a given assertion criteria:
* Clinical Impact -> diagnostic, prognostic, or predictive assertion
* Oncogenicity -> oncogenic assertion
Therefore, you must create separate GKS JSON for each submission type

:param organization_id: The CIViC organization ID that approved the assertion(s) for submission to ClinVar
:param submission_type: The ClinVar submission type to generate GKS JSON for.
Defaults to clinical impact.
:param output_json: The output file path to write the JSON file to
"""
try:
Expand All @@ -98,7 +120,7 @@ def create_gks_json(organization_id: int, output_json: Path) -> None:
logging.exception("Error getting organization %i", organization_id)
return

records: list[CivicGksAssertion] = []
records: list[CivicGksClinSigAssertion] | list[CivicGksOncogenicAssertion] = []
errors: list[GksAssertionError] = []

for approval in civic.get_all_approvals_ready_for_clinvar_submission_for_org(
Expand All @@ -107,7 +129,9 @@ def create_gks_json(organization_id: int, output_json: Path) -> None:
assertion = approval.assertion
if assertion.is_valid_for_gks_json(emit_warnings=True):
try:
gks_record = CivicGksAssertion(assertion, approval=approval)
gks_record = create_gks_record_from_assertion(
assertion, approval=approval, submission_type_filter=submission_type
)
except (CivicGksRecordError, NotImplementedError) as e:
errors.append(
GksAssertionError(assertion_id=assertion.id, message=str(e))
Expand Down
Binary file modified civicpy/data/test_cache.pkl
Binary file not shown.
Loading
Loading