From af3a57886bc5e0d820ea45276953454cd76ebe9e Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Mon, 22 Feb 2016 01:01:07 +0100 Subject: [PATCH] Add transcript in getTranscriptsMapping output Previously the getTranscriptsMapping webservice method didn't return enough information to construct a complete transcript name. This is now reported in a new `transcript` field. --- mutalyzer/models.py | 1 + mutalyzer/services/rpc.py | 20 +++++++++++++++++--- tests/test_services_json.py | 3 +++ tests/test_services_soap.py | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/mutalyzer/models.py b/mutalyzer/models.py index 7ebade7f..133fc6d8 100644 --- a/mutalyzer/models.py +++ b/mutalyzer/models.py @@ -310,6 +310,7 @@ class TranscriptMappingInfo(ComplexModel): """ __namespace__ = SOAP_NAMESPACE + transcript = Mandatory.Unicode name = Mandatory.Unicode version = Mandatory.Integer gene = Mandatory.Unicode diff --git a/mutalyzer/services/rpc.py b/mutalyzer/services/rpc.py index ce2287a8..93ca0689 100644 --- a/mutalyzer/services/rpc.py +++ b/mutalyzer/services/rpc.py @@ -458,6 +458,7 @@ class MutalyzerService(ServiceBase): - 1 ; Return all hit transcripts. @return: Array of TranscriptMappingInfo objects with fields: + - transcript - name - version - gene @@ -526,9 +527,22 @@ class MutalyzerService(ServiceBase): for mapping in mappings: t = TranscriptMappingInfo() - # TODO: This doesn't work so well for mappings with select_transcript - # set, for example LRG and mtDNA mappings, but it's not so easy to - # fix in a backwards compatible way. + + if mapping.version: + accession = '%s.%i' % (mapping.accession, mapping.version) + else: + accession = mapping.accession + if mapping.select_transcript: + if mapping.reference_type == 'lrg': + selector = 't%d' % mapping.transcript + elif mapping.transcript: + selector = '(%s_v%.3i)' % (mapping.gene, mapping.transcript) + else: + selector = '(%s)' % mapping.gene + else: + selector = '' + t.transcript = '%s%s' % (accession, selector) + t.name = mapping.accession t.version = mapping.version t.gene = mapping.gene diff --git a/tests/test_services_json.py b/tests/test_services_json.py index e47e306e..76bcb8c4 100644 --- a/tests/test_services_json.py +++ b/tests/test_services_json.py @@ -220,6 +220,7 @@ def test_get_transcripts_mapping(api): r = api('getTranscriptsMapping', 'hg19', 'chr11', 111955524, 111966518) assert r == [{'cds_start': 111957492, 'cds_stop': 111956019, + 'transcript': 'NM_012459.2', 'name': 'NM_012459', 'stop': 111955524, 'start': 111957522, @@ -228,6 +229,7 @@ def test_get_transcripts_mapping(api): 'orientation': '-'}, {'cds_start': None, 'cds_stop': None, + 'transcript': 'NR_028383.1', 'name': 'NR_028383', 'stop': 111955524, 'start': 111957522, @@ -236,6 +238,7 @@ def test_get_transcripts_mapping(api): 'orientation': '-'}, {'cds_start': 111957632, 'cds_stop': 111965694, + 'transcript': 'NM_003002.2', 'name': 'NM_003002', 'stop': 111966518, 'start': 111957571, diff --git a/tests/test_services_soap.py b/tests/test_services_soap.py index a02146da..83792b7f 100644 --- a/tests/test_services_soap.py +++ b/tests/test_services_soap.py @@ -258,6 +258,22 @@ def test_gettranscriptsbygenename_invalid(api): assert not r +@pytest.mark.usefixtures('hg19_transcript_mappings') +def test_gettranscriptsmapping_mtdna(api): + """ + Running getTranscriptsMapping on mtDNA should give a list of transcripts + including their complete identification in the transcript attribute. + """ + r = api('getTranscriptsMapping', 'hg19', 'chrM', 10765, 10765, 1) + assert type(r.TranscriptMappingInfo) == list + assert len(r.TranscriptMappingInfo) == 1 + info = r.TranscriptMappingInfo[0] + assert 'NC_012920' == info.name + assert 1 == info.version + assert 'ND4' == info.gene + assert 'NC_012920.1(ND4_v001)' == info.transcript + + @with_references('AF230870.1') def test_gettranscriptsandinfo_valid(api): """ @@ -804,6 +820,7 @@ def test_get_transcripts_mapping(api): for t_real, t_expected in zip(r.TranscriptMappingInfo, [{'cds_start': 111957492, 'cds_stop': 111956019, + 'transcript': 'NM_012459.2', 'name': 'NM_012459', 'stop': 111955524, 'start': 111957522, @@ -812,6 +829,7 @@ def test_get_transcripts_mapping(api): 'orientation': '-'}, {'cds_start': None, 'cds_stop': None, + 'transcript': 'NR_028383.1', 'name': 'NR_028383', 'stop': 111955524, 'start': 111957522, @@ -820,6 +838,7 @@ def test_get_transcripts_mapping(api): 'orientation': '-'}, {'cds_start': 111957632, 'cds_stop': 111965694, + 'transcript': 'NM_003002.2', 'name': 'NM_003002', 'stop': 111966518, 'start': 111957571, -- GitLab