Skip to content

Commit

Permalink
Added a couple of tests for the new _swap_transcript routine - just m…
Browse files Browse the repository at this point in the history
…aking sure that the swap actually changes the primary transcript and all the metrics (EI-CoreBioinformatics#137).
  • Loading branch information
lucventurini committed Nov 10, 2018
1 parent 92ada58 commit 51803fe
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Bugfixes and improvements:

# Version 1.2.4

Enhancement release. Following version 1.2.3, now Mikado can accept BED12 files as input for convert, compare and stats (see #122). This is becoming necessary as many long-reads alignment tools are preferentially outputting (or can be easily converted to) this format.
Enhancement release. Following version 1.2.3, now Mikado can accept BED12 files as input for convert, compare and stats (see [#122](https://github.com/EI-CoreBioinformatics/mikado/issues/122)). This is becoming necessary as many long-reads alignment tools are preferentially outputting (or can be easily converted to) this format.

# Version 1.2.3

Expand Down
59 changes: 59 additions & 0 deletions Mikado/tests/locus_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2594,6 +2594,65 @@ def test_edge_expansion(self):
(197652, 197987)]
)

def test_swap_single(self):

transcript = Transcript()
transcript.id, transcript.chrom, transcript.strand = "test", "Chr5", "+"
transcript.add_exons([(101, 1000)])
transcript.finalize()
new = transcript.deepcopy()

locus = Locus(transcript)
self.assertEqual(locus.primary_transcript, transcript)
self.assertEqual(len(locus.exons), 1)

new.unfinalize()
new.remove_exon((101, 1000))
new.start, new.end = 51, 1200
new.add_exons([(51, 200), (501, 1200)])
new.finalize()
self.assertEqual(transcript.id, new.id)

locus._swap_transcript(transcript, new)
self.assertEqual(len(locus.exons), 2)
self.assertEqual(locus.exons, set(new.exons))
self.assertEqual(locus.primary_transcript, new)

def test_swap_see_metrics(self):

transcript = Transcript()
transcript.id, transcript.chrom, transcript.strand = "test", "Chr5", "+"
transcript.add_exons([(101, 1000), (1201, 1500)])
transcript.finalize()
new = transcript.deepcopy()
locus = Locus(transcript)
locus.json_conf["pick"]["alternative_splicing"]["only_confirmed_introns"] = False
second = Transcript()
second.id, second.chrom, second.strand = "test2", "Chr5", "+"
second.add_exons([(101, 1000), (1301, 1600)])
second.finalize()
locus.add_transcript_to_locus(second)
self.assertEqual(len(locus.transcripts), 2)
locus.calculate_scores()
self.assertAlmostEqual(locus[second.id].exon_fraction, 2/3, places=3)
self.assertAlmostEqual(locus[transcript.id].exon_fraction, 2 / 3, places=3)
self.assertEqual(locus.primary_transcript, transcript)

new.unfinalize()
new.remove_exon((101, 1000))
new.start, new.end = 51, 1500
new.add_exons([(51, 200), (501, 1000)])
new.finalize()
self.assertEqual(transcript.id, new.id)
self.assertEqual(locus.primary_transcript_id, transcript.id)

locus._swap_transcript(transcript, new)
self.assertEqual(locus.primary_transcript, new)
self.assertEqual(locus.exons, {(51, 200), (501, 1000), (101, 1000), (1301, 1600), (1201, 1500)})
locus.calculate_scores()
self.assertAlmostEqual(locus[second.id].exon_fraction, 2 / 5, places=3)
self.assertAlmostEqual(locus[transcript.id].exon_fraction, 3 / 5, places=3)


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 51803fe

Please sign in to comment.