def test_to_hgvs_locations_simple(hgvs, hgvs_internal_indexing): r_model = generate_references({ "id": "t1", "type": "mRNA", "inverted": False, "exon": [(3, 6), (8, 13), (16, 21), (24, 26)], "cds": (10, 19), }) append_transcript( r_model, { "id": "t2", "type": "ncRNA", "inverted": False, "exon": [(3, 6), (8, 13), (16, 21), (24, 26)], }, ) model_internal_indexing = to_model(hgvs_internal_indexing) model_hgvs = to_model(hgvs) if model_hgvs["coordinate_system"] in ["c", "n"]: to_selector_id = model_hgvs["reference"]["selector"]["id"] else: to_selector_id = None hgvs_conversion = model_to_string( to_hgvs_locations( model=model_internal_indexing, references=r_model, to_coordinate_system=model_hgvs["coordinate_system"], to_selector_id=to_selector_id, degenerate=True, )) assert hgvs_conversion == hgvs
def test_outside_cds_description_model(): p_c = position_convert( description_model=to_model("NG_012337.1:27"), to_selector_id="NM_003002.2", ) assert model_to_string( p_c["converted_model"]) == "NG_012337.1(NM_003002.2):c.-5035"
def _convert_description_to_model(self): try: self.input_model = to_model(self.input_description) except UnexpectedCharacter as e: self._add_error(errors.syntax_uc(e)) except UnexpectedEnd as e: self._add_error(errors.syntax_ueof(e))
def test_to_internal_locations(description_in, description_expected, references): description_model = to_model(description_in) description_out = model_to_string( to_internal_indexing( to_internal_coordinates(description_model, references))) assert description_out == description_expected
def get(self, description): """Convert a variant description to its dictionary model.""" try: model = to_model(description) except Exception: model = {"errors": "Some unexpected parsing error occured."} return model
def _get_model_from_segmented_input(self): description_model = {"reference": {"id": self.reference_id}} if self.from_selector_id: description_model["reference"]["selector"] = { "id": self.from_selector_id } if (self.from_coordinate_system and self.from_coordinate_system.strip().lower() not in ["selector"]): description_model[ "coordinate_system"] = self.from_coordinate_system try: location_model = to_model(self.position, start_rule="location") description_model["variants"] = [{"location": location_model}] except UnexpectedCharacter as e: self.errors.append( errors.position_syntax("Unexpected character.", e)) except UnexpectedEnd as e: self.errors.append( errors.position_syntax("Unexpected end of input.", e)) self.input_model = description_model
def test_point_shift_from_positive_strand_ro_positive_strand(): model = to_model("NG_012337.1:1005") model["variants"][0]["location"]["shift"] = 4 p_c = position_convert( description_model=model, to_selector_id="NM_003002.2", ) assert model_to_string( p_c["converted_model"]) == "NG_012337.1(NM_003002.2):c.-4057"
def test_to_hgvs_locations(description_in, description_expected, references): model_internal_indexing = to_model(description_in) model_hgvs = to_model(description_expected) if model_hgvs["coordinate_system"] in ["c", "n"]: to_selector_id = model_hgvs["reference"]["selector"]["id"] else: to_selector_id = None hgvs_conversion = model_to_string( to_hgvs_locations( model=model_internal_indexing, references=references, to_coordinate_system=model_hgvs["coordinate_system"], to_selector_id=to_selector_id, degenerate=True, )) assert hgvs_conversion == description_expected
def test_point_shift_from_positive_strand_to_negative_strand(): """ NM_012459.2 is on the negative strand on NG_012337.1 """ model = to_model("NG_012337.1:1005") model["variants"][0]["location"]["shift"] = 4 p_c = position_convert( description_model=model, to_selector_id="NM_012459.2", ) assert model_to_string( p_c["converted_model"]) == "NG_012337.1(NM_012459.2):c.*2448"
def lovd_to_bed(input_handle, output_handle, ref, alt): dialect = Sniffer().sniff(input_handle.read(1024)) input_handle.seek(0) for record in DictReader(filter(lambda x: x[0] != '#', input_handle), dialect=dialect): chrom = 'chr{}'.format(record['{{chromosome}}']) try: model = to_model('{}:{}'.format( chrom, record['{{VariantOnGenome/DNA/hg38}}'])) except (UnexpectedCharacter, UnexpectedEnd): continue for variant in model['variants']: if (variant['type'] == 'substitution' and variant['deleted'][0]['sequence'] == ref and variant['inserted'][0]['sequence'] == alt): output_handle.write('{}\t{}\t{}\n'.format( chrom, variant['location']['position'] - 1, variant['location']['position']))
def test_to_internal_coordinates_simple(hgvs, hgvs_internal_indexing): d_m = to_model(hgvs) r_model = generate_references({ "id": "t1", "type": "mRNA", "inverted": False, "exon": [(3, 6), (8, 13), (16, 21), (24, 26)], "cds": (10, 19), }) append_transcript( r_model, { "id": "t2", "type": "ncRNA", "inverted": False, "exon": [(3, 6), (8, 13), (16, 21), (24, 26)], }, ) hgvs_internal_indexing_conversion = model_to_string( to_internal_indexing(to_internal_coordinates(d_m, r_model))) assert hgvs_internal_indexing_conversion == hgvs_internal_indexing
def test_hgvs_protein_convert(description): if TESTS.get(description): assert to_model(description) == TESTS[description]
def test_description_to_model_to_description(description): """ Check if the parsed model of a description is converted back to the initial description. """ assert model_to_string(to_model(description)) == description