class CTTVGeneticsEvidenceString(CTTVEvidenceString): """ Class for genetics evidence string specifically. Holds information required for Open Target's evidence strings for genetic information. """ with utilities.open_file( utilities.get_resource_file(__package__, config.GEN_EV_STRING_JSON), "rt") as gen_json_file: base_json = json.load(gen_json_file) def __init__(self, clinvar_record, clinvar_record_measure, report, trait, consequence_type): a_dictionary = copy.deepcopy(self.base_json) ref_list = list( set(clinvar_record.trait_refs_list[trait.trait_counter] + clinvar_record.observed_refs_list + clinvar_record_measure.refs_list)) ref_list.sort() super().__init__(a_dictionary, clinvar_record, ref_list, consequence_type.ensembl_gene_id, report, trait) variant_type = get_cttv_variant_type(clinvar_record_measure) self.add_unique_association_field('alleleOrigin', 'germline') if clinvar_record_measure.rs_id: self.set_variant( 'http://identifiers.org/dbsnp/' + clinvar_record_measure.rs_id, variant_type) self.add_unique_association_field('variant_id', clinvar_record_measure.rs_id) elif clinvar_record_measure.nsv_id: self.set_variant( 'http://identifiers.org/dbsnp/' + clinvar_record_measure.nsv_id, variant_type) self.add_unique_association_field('variant_id', clinvar_record_measure.nsv_id) else: self.set_variant( 'http://www.ncbi.nlm.nih.gov/clinvar/' + clinvar_record.accession, variant_type) self.add_unique_association_field('variant_id', clinvar_record.accession) self.date = clinvar_record.date self.db_xref_url = 'http://identifiers.org/clinvar.record/' + clinvar_record.accession self.url = 'http://www.ncbi.nlm.nih.gov/clinvar/' + clinvar_record.accession self.association = clinvar_record.clinical_significance not in \ ('non-pathogenic', 'probable-non-pathogenic', 'likely benign', 'benign') self.gene_2_var_ev_codes = [ 'http://identifiers.org/eco/cttv_mapping_pipeline' ] most_severe_so_term = consequence_type.so_term if most_severe_so_term.accession is None: self.gene_2_var_func_consequence = 'http://targetvalidation.org/sequence/' + \ most_severe_so_term.so_name else: self.gene_2_var_func_consequence = 'http://purl.obolibrary.org/obo/' + \ most_severe_so_term.accession.replace(':', '_') if len(ref_list) > 0: self.set_var_2_disease_literature(ref_list) # Arbitrarily select only one reference among all self.unique_reference = ref_list[0] if clinvar_record.clinical_significance: self.clinical_significance = clinvar_record.clinical_significance @property def db_xref_url(self): if self['evidence']['gene2variant']['provenance_type']['database']['dbxref']['url'] \ == self['evidence']['variant2disease']['provenance_type']['database']['dbxref']['url']: return \ self['evidence']['variant2disease']['provenance_type']['database']['dbxref']['url'] else: raise Exception("db_xref_url attributes different") @db_xref_url.setter def db_xref_url(self, url): self['evidence']['gene2variant']['provenance_type']['database'][ 'dbxref']['url'] = url self['evidence']['variant2disease']['provenance_type']['database'][ 'dbxref']['url'] = url @property def url(self): if self['evidence']['gene2variant']['urls'][0]['url'] \ == self['evidence']['variant2disease']['urls'][0]['url']: return self['evidence']['gene2variant']['urls'][0]['url'] else: raise Exception("url attributes different") @url.setter def url(self, url): self['evidence']['gene2variant']['urls'][0]['url'] = url self['evidence']['variant2disease']['urls'][0]['url'] = url @property def gene_2_var_ev_codes(self): return self['evidence']['gene2variant']['evidence_codes'] @gene_2_var_ev_codes.setter def gene_2_var_ev_codes(self, gene_2_var_ev_codes): self['evidence']['gene2variant'][ 'evidence_codes'] = gene_2_var_ev_codes @property def gene_2_var_func_consequence(self): return self['evidence']['gene2variant']['functional_consequence'] @gene_2_var_func_consequence.setter def gene_2_var_func_consequence(self, so_term): self['evidence']['gene2variant']['functional_consequence'] = so_term def set_var_2_disease_literature(self, ref_list): self['evidence']['variant2disease']['provenance_type']['literature'] = \ {'references': [{'lit_id': reference} for reference in ref_list]} @property def association(self): if self['evidence']['gene2variant']['is_associated'] \ == self['evidence']['variant2disease']['is_associated']: return self['evidence']['gene2variant']['is_associated'] else: raise Exception("association attributes different") @association.setter def association(self, is_associated): self['evidence']['gene2variant']['is_associated'] = is_associated self['evidence']['variant2disease']['is_associated'] = is_associated def _clear_variant(self): self['variant']['id'] = [] self['variant']['type'] = [] def set_variant(self, var_id, var_type): self['variant']['id'] = var_id self['variant']['type'] = var_type @property def unique_reference(self): return self['evidence']['variant2disease'][ 'unique_experiment_reference'] @unique_reference.setter def unique_reference(self, reference): self['evidence']['variant2disease'][ 'unique_experiment_reference'] = reference @property def date(self): if self['evidence']['gene2variant']['date_asserted'] == \ self['evidence']['variant2disease']['date_asserted']: return self['evidence']['gene2variant']['date_asserted'] else: raise Exception("date attributes have different values") @date.setter def date(self, date_string): self['evidence']['gene2variant']['date_asserted'] = date_string self['evidence']['variant2disease']['date_asserted'] = date_string @property def clinical_significance(self): return self['evidence']['variant2disease']['clinical_significance'] @clinical_significance.setter def clinical_significance(self, clinical_significance): self['evidence']['variant2disease'][ 'clinical_significance'] = clinical_significance
class CTTVSomaticEvidenceString(CTTVEvidenceString): """ Class for somatic evidence string specifically. Holds information required for Open Target's evidence strings for somatic information. """ with utilities.open_file( utilities.get_resource_file(__package__, config.SOM_EV_STRING_JSON), "rt") as som_json_file: base_json = json.load(som_json_file) def __init__(self, clinvar_record, clinvar_record_measure, report, trait, consequence_type): a_dictionary = copy.deepcopy(self.base_json) ref_list = list( set(clinvar_record.trait_refs_list[trait.trait_counter] + clinvar_record.observed_refs_list + clinvar_record_measure.refs_list)) ref_list.sort() super().__init__(a_dictionary, clinvar_record, ref_list, consequence_type.ensembl_gene_id, report, trait) self.add_unique_association_field('alleleOrigin', 'somatic') if clinvar_record_measure.rs_id: self.add_unique_association_field('variant_id', clinvar_record_measure.rs_id) elif clinvar_record_measure.nsv_id: self.add_unique_association_field('variant_id', clinvar_record_measure.nsv_id) else: self.add_unique_association_field('variant_id', clinvar_record.accession) self.date = clinvar_record.date self.db_xref_url = 'http://identifiers.org/clinvar.record/' + clinvar_record.accession self.url = 'http://www.ncbi.nlm.nih.gov/clinvar/' + clinvar_record.accession self.association = clinvar_record.clinical_significance not in \ ('non-pathogenic', 'probable-non-pathogenic', 'likely benign', 'benign') self.set_known_mutations(consequence_type.so_term) if len(ref_list) > 0: self.evidence_literature = ref_list if clinvar_record.clinical_significance: self.clinical_significance = clinvar_record.clinical_significance @property def db_xref_url(self): return self['evidence']['provenance_type']['database']['dbxref']['url'] @db_xref_url.setter def db_xref_url(self, url): self['evidence']['provenance_type']['database']['dbxref']['url'] = url @property def url(self): return self['evidence']['urls'][0]['url'] @url.setter def url(self, url): self['evidence']['urls'][0]['url'] = url @property def evidence_literature(self): return self['evidence']['provenance_type']['literature']['references'] @evidence_literature.setter def evidence_literature(self, ref_list): self['evidence']['provenance_type']['literature'] = \ {'references': [{'lit_id': reference} for reference in ref_list]} @property def association(self): return self['evidence']['is_associated'] @association.setter def association(self, is_associated): self['evidence']['is_associated'] = is_associated @property def date(self): return self['evidence']['date_asserted'] @date.setter def date(self, date_string): self['evidence']['date_asserted'] = date_string def _clear_known_mutations(self): self['evidence']['known_mutations'] = [] def add_known_mutation(self, new_functional_consequence, so_name): new_known_mutation = \ {'functional_consequence': new_functional_consequence, 'preferred_name': so_name} self['evidence']['known_mutations'].append(new_known_mutation) def set_known_mutations(self, so_term): if so_term.accession: new_functional_consequence = \ "http://purl.obolibrary.org/obo/" + so_term.accession.replace(':', '_') else: new_functional_consequence = \ 'http://targetvalidation.org/sequence/' + so_term.so_name self.add_known_mutation(new_functional_consequence, so_term.so_name) @property def clinical_significance(self): return self['evidence']['clinical_significance'] @clinical_significance.setter def clinical_significance(self, clinical_significance): self['evidence']['clinical_significance'] = clinical_significance
def test_get_resource_file_existent(self): self.assertTrue( utilities.get_resource_file("eva_cttv_pipeline", "resources/json_schema"))
def test_get_resource_file_nonexistent(self): self.assertEqual( utilities.get_resource_file("not_a_real_package_39146", "not_a_real_file"), None)
def test_get_resource_file_existent(self): self.assertTrue(utilities.get_resource_file("eva_cttv_pipeline", "resources/json_schema"))
def test_get_resource_file_nonexistent(self): self.assertEqual(utilities.get_resource_file("not_a_real_package_39146", "not_a_real_file"), None)
class CTTVSomaticEvidenceString(CTTVEvidenceString): """ Class for somatic evidence string specifically. Holds information required for Open Target's evidence strings for somatic information. """ with utilities.open_file( utilities.get_resource_file(__package__, config.SOM_EV_STRING_JSON), "rt") as som_json_file: base_json = json.load(som_json_file) def __init__(self, clinvar_record, clinvar_record_measure, report, trait, consequence_type): a_dictionary = copy.deepcopy(self.base_json) ref_list = list( set(clinvar_record.trait_refs_list[trait.trait_counter] + clinvar_record.observed_refs_list + clinvar_record_measure.refs_list)) ref_list.sort() super().__init__(a_dictionary, clinvar_record, ref_list, consequence_type.ensembl_gene_id, report, trait) self.add_unique_association_field('alleleOrigin', 'somatic') if clinvar_record_measure.rs_id: self.add_unique_association_field('variant_id', clinvar_record_measure.rs_id) elif clinvar_record_measure.nsv_id: self.add_unique_association_field('variant_id', clinvar_record_measure.nsv_id) else: self.add_unique_association_field('variant_id', clinvar_record.accession) self.date = clinvar_record.date self.last_evaluated_date = clinvar_record.last_evaluated_date self.db_xref_url = 'http://identifiers.org/clinvar.record/' + clinvar_record.accession self.url = 'http://www.ncbi.nlm.nih.gov/clinvar/' + clinvar_record.accession # See https://github.com/opentargets/platform/issues/1139#issuecomment-682592678 self.association = True self.set_known_mutations(consequence_type.so_term) if len(ref_list) > 0: self.evidence_literature = ref_list if clinvar_record.clinical_significance: self.clinical_significance = process_clinical_significance( clinvar_record.clinical_significance) # Populate star rating and review status star_rating, review_status = clinvar_record.score self.clinvar_rating = (star_rating, review_status) # Populate mode of inheritance (if present) self.mode_of_inheritance = clinvar_record.mode_of_inheritance @property def db_xref_url(self): return self['evidence']['provenance_type']['database']['dbxref']['url'] @db_xref_url.setter def db_xref_url(self, url): self['evidence']['provenance_type']['database']['dbxref']['url'] = url @property def url(self): return self['evidence']['urls'][0]['url'] @url.setter def url(self, url): self['evidence']['urls'][0]['url'] = url @property def evidence_literature(self): return self['evidence']['provenance_type']['literature']['references'] @evidence_literature.setter def evidence_literature(self, ref_list): self['evidence']['provenance_type']['literature'] = \ {'references': [{'lit_id': reference} for reference in ref_list]} @property def association(self): return self['evidence']['is_associated'] @association.setter def association(self, is_associated): self['evidence']['is_associated'] = is_associated @property def date(self): return self['evidence']['date_asserted'] @date.setter def date(self, date_string): self['evidence']['date_asserted'] = date_string @property def last_evaluated_date(self): return self['evidence']['last_evaluated_date'] @last_evaluated_date.setter def last_evaluated_date(self, clinvar_last_evaluated_date): if clinvar_last_evaluated_date: self['evidence'][ 'last_evaluated_date'] = clinvar_last_evaluated_date def _clear_known_mutations(self): self['evidence']['known_mutations'] = [] def add_known_mutation(self, new_functional_consequence, so_name): new_known_mutation = \ {'functional_consequence': new_functional_consequence, 'preferred_name': so_name} self['evidence']['known_mutations'].append(new_known_mutation) def set_known_mutations(self, so_term): if so_term.accession: new_functional_consequence = \ "http://purl.obolibrary.org/obo/" + so_term.accession.replace(':', '_') else: new_functional_consequence = \ 'http://targetvalidation.org/sequence/' + so_term.so_name self.add_known_mutation(new_functional_consequence, so_term.so_name) @property def clinical_significance(self): return self['evidence']['clinical_significance'] @clinical_significance.setter def clinical_significance(self, clinical_significance): self['evidence']['clinical_significance'] = clinical_significance @property def clinvar_rating(self): return self['evidence']['clinvar_rating'] @clinvar_rating.setter def clinvar_rating(self, clinvar_rating_data): star_rating, review_status = clinvar_rating_data self['evidence']['clinvar_rating'] = { 'star_rating': star_rating, 'review_status': review_status, } @property def mode_of_inheritance(self): return self['evidence'].get('mode_of_inheritance') @mode_of_inheritance.setter def mode_of_inheritance(self, mode_of_inheritance): if mode_of_inheritance: self['evidence']['mode_of_inheritance'] = mode_of_inheritance