diff --git a/mutalyzer/mapping.py b/mutalyzer/mapping.py index d93ff17e791dc0163e72a7e6cfdcbf53d3e0eee8..4abd3edf6ba238bab7f033bd71ad45f530967c88 100644 --- a/mutalyzer/mapping.py +++ b/mutalyzer/mapping.py @@ -431,11 +431,16 @@ class Converter(object) : else : change = r_change - if M.start_g != M.end_g : - if self.dbFields["orientation"] == '+' : - var_in_g = "g.%s_%s%s" % (M.start_g, M.end_g, change) - else : - var_in_g = "g.%s_%s%s" % (M.end_g, M.start_g, change) + if M.start_g != M.end_g: + if self.dbFields["orientation"] == '-': + last_g, first_g = M.start_g, M.end_g + else: + first_g, last_g = M.start_g, M.end_g + if last_g < first_g: + self.__output.addMessage(__file__, 3, 'ERANGE', 'End position ' + 'is smaller than the begin position.') + return None + var_in_g = "g.%s_%s%s" % (first_g, last_g, change) #if else : var_in_g = "g.%s%s" % (M.start_g, change) @@ -556,6 +561,11 @@ class Converter(object) : else : loc2 = loc + if loc2 < loc: + self.__output.addMessage(__file__, 3, 'ERANGE', 'End position is ' + 'smaller than the begin position.') + return None + if gene: transcripts = self.__database.get_TranscriptsByGeneName(gene) else: diff --git a/tests/test_mapping.py b/tests/test_mapping.py index 12e5608431ff913e8e4f6a2a35e29678bbf07a04..aebb11a575101ecc402b0a984db2f29e502288be 100644 --- a/tests/test_mapping.py +++ b/tests/test_mapping.py @@ -94,3 +94,54 @@ class TestConverter(): assert 'NM_002241.3:c.-27340-7_-27332del16' not in coding assert 'NM_002241.4:c.1-7_9del16' in coding assert 'NM_002241.3:c.1-7_9del16' in coding + + def test_range_order_forward_correct(self): + """ + Just a normal position converter call, both directions. See Trac #95. + """ + converter = self._converter('hg19') + genomic = converter.c2chrom('NM_003002.2:c.-1_274del') + assert_equal(genomic, 'NC_000011.9:g.111957631_111959695del') + coding = converter.chrom2c(genomic, 'list') + assert 'NM_003002.2:c.-1_274del' in coding + + def test_range_order_forward_incorrect_c2chrom(self): + """ + Incorrect order of a range on the forward strand. See Trac #95. + """ + converter = self._converter('hg19') + genomic = converter.c2chrom('NM_003002.2:c.274_-1del') + assert_equal(genomic, None) + erange = self.output.getMessagesWithErrorCode('ERANGE') + assert_equal(len(erange), 1) + + def test_range_order_reverse_correct(self): + """ + Just a normal position converter call on the reverse strand, both + directions. See Trac #95. + """ + converter = self._converter('hg19') + genomic = converter.c2chrom('NM_001162505.1:c.-1_40del') + assert_equal(genomic, 'NC_000020.10:g.48770135_48770175del') + coding = converter.chrom2c(genomic, 'list') + assert 'NM_001162505.1:c.-1_40del' in coding + + def test_range_order_reverse_incorrect_c2chrom(self): + """ + Incorrect order of a range on the reverse strand. See Trac #95. + """ + converter = self._converter('hg19') + genomic = converter.c2chrom('NM_001162505.1:c.40_-1del') + assert_equal(genomic, None) + erange = self.output.getMessagesWithErrorCode('ERANGE') + assert_equal(len(erange), 1) + + def test_range_order_incorrect_chrom2c(self): + """ + Incorrect order of a chromosomal range. See Trac #95. + """ + converter = self._converter('hg19') + coding = converter.chrom2c('NC_000011.9:g.111959695_111957631del', 'list') + assert_equal(coding, None) + erange = self.output.getMessagesWithErrorCode('ERANGE') + assert_equal(len(erange), 1)