def test_draw_layout_single_genomic(self): d = DiagramSettings() d1 = protein.Domain('first', [(55, 61), (71, 73)]) d2 = protein.Domain('second', [(10, 20), (30, 34)]) g1 = genomic.Gene('1', 150, 1000, strand=STRAND.POS) g2 = genomic.Gene('1', 5000, 7500, strand=STRAND.POS) t1 = build_transcript( gene=g1, cds_start=50, cds_end=249, exons=[(200, 299), (400, 499), (700, 899)], domains=[d2, d1], ) t2 = build_transcript( gene=g2, cds_start=20, cds_end=500, exons=[(5100, 5299), (5800, 6199), (6500, 6549), (6700, 6799)], domains=[], ) b1 = Breakpoint('1', 350, orient=ORIENT.LEFT) b2 = Breakpoint('1', 6500, orient=ORIENT.RIGHT) bpp = BreakpointPair(b1, b2, opposing_strands=False, untemplated_seq='') ann = variant.Annotation(bpp, transcript1=t1, transcript2=t2, event_type=SVTYPE.DEL, protocol=PROTOCOL.GENOME) ann.add_gene(genomic.Gene('1', 1500, 1950, strand=STRAND.POS)) ann.add_gene(genomic.Gene('1', 3000, 3980, strand=STRAND.POS)) ann.add_gene(genomic.Gene('1', 3700, 4400, strand=STRAND.NEG)) reference_genome = {'1': MockObject(seq=MockString('A'))} ft = variant.FusionTranscript.build(ann, reference_genome) ann.fusion = ft self.assertEqual(t1.exons[0], ft.exon_mapping[ft.exons[0].position]) self.assertEqual(t2.exons[2], ft.exon_mapping[ft.exons[1].position]) self.assertEqual(t2.exons[3], ft.exon_mapping[ft.exons[2].position]) canvas, legend = draw_sv_summary_diagram(d, ann) self.assertEqual(5, len(canvas.elements)) # defs counts as element expected_height = (d.top_margin + d.bottom_margin + d.track_height + d.breakpoint_bottom_margin + d.breakpoint_top_margin + d.inner_margin + d.track_height + d.splice_height + d.breakpoint_bottom_margin + d.breakpoint_top_margin + d.padding + d.translation_track_height + d.padding * 2 + d.domain_track_height * 2 + d.inner_margin + d.track_height + d.splice_height) self.assertEqual(expected_height, canvas.attribs['height']) if OUTPUT_SVG: canvas.saveas('test_draw_layout_single_genomic.svg')
def test_draw_overlay(self): gene = genomic.Gene('12', 25357723, 25403870, strand=STRAND.NEG, name='KRAS') marker = BioInterval('12', 25403865, name='splice site mutation') t = build_transcript(cds_start=193, cds_end=759, exons=[(25403685, 25403865), (25398208, 25398329), (25380168, 25380346), (25378548, 25378707), (25357723, 25362845)], gene=gene, domains=[]) build_transcript(cds_start=198, cds_end=425, exons=[(25403685, 25403870), (25398208, 25398329), (25362102, 25362845)], gene=gene, domains=[]) build_transcript(cds_start=65, cds_end=634, exons=[(25403685, 25403737), (25398208, 25398329), (25380168, 25380346), (25378548, 25378707), (25368371, 25368494), (25362365, 25362845)], gene=gene, domains=[ protein.Domain('domain1', [(1, 10)]), protein.Domain('domain1', [(4, 10)]) ], is_best_transcript=True) build_transcript(cds_start=65, cds_end=634, exons=[(25403698, 25403863), (25398208, 25398329), (25386753, 25388160)], gene=gene, domains=[]) d = DiagramSettings() for i, t in enumerate(gene.transcripts): t.name = 'transcript {}'.format(i + 1) scatterx = [x + 100 for x in range(gene.start, gene.end + 1, 400)] scattery = [random.uniform(-0.2, 0.2) for x in scatterx] s = ScatterPlot(list(zip(scatterx, scattery)), 'cna', ymin=-1, ymax=1, yticks=[-1, 0, 1]) d.gene_min_buffer = 0 canvas = draw_multi_transcript_overlay(d, gene, vmarkers=[marker], plots=[s, s]) self.assertEqual(2, len(canvas.elements)) # defs counts as element if OUTPUT_SVG: canvas.saveas('test_draw_overlay.svg')
def test_draw_layout_translocation(self): d = DiagramSettings(domain_name_regex_filter=r'.*') d1 = protein.Domain('first', [(55, 61), (71, 73)]) d2 = protein.Domain('second', [(10, 20), (30, 34)]) g1 = genomic.Gene('1', 150, 1000, strand=STRAND.POS) g2 = genomic.Gene('2', 5000, 7500, strand=STRAND.NEG) t1 = build_transcript( gene=g1, cds_start=50, cds_end=249, exons=[(200, 299), (400, 499), (700, 899)], domains=[d2, d1], ) t2 = build_transcript( gene=g2, cds_start=120, cds_end=700, exons=[(5100, 5299), (5800, 6199), (6500, 6549), (6700, 6799)], domains=[], ) b1 = Breakpoint('1', 350, orient=ORIENT.LEFT) b2 = Breakpoint('2', 6520, orient=ORIENT.LEFT) bpp = BreakpointPair(b1, b2, opposing_strands=True, untemplated_seq='') ann = variant.Annotation(bpp, transcript1=t1, transcript2=t2, event_type=SVTYPE.ITRANS, protocol=PROTOCOL.GENOME) # genes 1 ann.add_gene(genomic.Gene('1', 1500, 1950, strand=STRAND.POS)) ann.add_gene(genomic.Gene('1', 3000, 3980, strand=STRAND.POS)) ann.add_gene(genomic.Gene('1', 3700, 4400, strand=STRAND.NEG)) # genes 2 ann.add_gene(genomic.Gene('2', 1500, 1950, strand=STRAND.NEG)) ann.add_gene(genomic.Gene('2', 5500, 9000, strand=STRAND.POS)) ann.add_gene(genomic.Gene('2', 3700, 4400, strand=STRAND.NEG)) reference_genome = { '1': MockObject(seq=MockString('A')), '2': MockObject(seq=MockString('A')), } ft = variant.FusionTranscript.build(ann, reference_genome) ann.fusion = ft canvas, legend = draw_sv_summary_diagram(d, ann) assert len(canvas.elements) == 6 # defs counts as element expected_height = ( d.top_margin + d.bottom_margin + d.track_height * 2 + d.padding + d.breakpoint_bottom_margin + d.breakpoint_top_margin + d.inner_margin + d.track_height + d.splice_height + d.breakpoint_bottom_margin + d.breakpoint_top_margin + d.padding + d.translation_track_height + d.padding * 2 + d.domain_track_height * 2 + d.inner_margin + d.track_height + d.splice_height) assert canvas.attribs['height'] == expected_height
def test_draw_ustranscript(self): d = DiagramSettings() # domains = [protein.Domain()] d1 = protein.Domain('first', [(55, 61), (71, 73)]) d2 = protein.Domain('second', [(10, 20), (30, 34)]) t = build_transcript( gene=None, cds_start=50, cds_end=249, exons=[(1, 99), (200, 299), (400, 499)], strand=STRAND.NEG, domains=[d2, d1], ) b = Breakpoint('1', 350, 410, orient=ORIENT.LEFT) g = draw_ustranscript(d, self.canvas, t, 500, colors={t.exons[1]: '#FFFF00'}, breakpoints=[b]) self.canvas.add(g) # self.canvas.saveas('test_draw_ustranscript.svg') self.assertEqual(2, len(self.canvas.elements)) self.assertEqual(3, len(g.elements)) for el, cls in zip(g.elements[0].elements, ['splicing', 'exon_track', 'protein']): self.assertEqual(cls, el.attribs.get('class', '')) for el, cls in zip(g.elements[0].elements[1].elements, ['scaffold', 'exon', 'exon', 'exon']): self.assertEqual(cls, el.attribs.get('class', '')) for el, cls in zip(g.elements[0].elements[2].elements, ['translation', 'domain', 'domain']): self.assertEqual(cls, el.attribs.get('class', '')) self.assertEqual( sum([ d.track_height, d.splice_height, 2 * d.padding, d.domain_track_height * 2, d.translation_track_height, d.padding, d.breakpoint_top_margin, d.breakpoint_bottom_margin, ]), g.height, ) self.assertEqual(d1.name, g.labels['D1']) self.assertEqual(d2.name, g.labels['D2'])
def test_draw_layout_single_transcript(self): d = DiagramSettings() d1 = protein.Domain('first', [(55, 61), (71, 73)]) d2 = protein.Domain('second', [(10, 20), (30, 34)]) g1 = genomic.Gene('1', 150, 1000, strand=STRAND.POS) t = build_transcript(g1, [(200, 299), (400, 499), (700, 899)], 50, 249, [d2, d1]) b1 = Breakpoint('1', 350, orient=ORIENT.RIGHT) b2 = Breakpoint('1', 600, orient=ORIENT.LEFT) bpp = BreakpointPair(b1, b2, opposing_strands=False, untemplated_seq='') ann = variant.Annotation(bpp, transcript1=t, transcript2=t, event_type=SVTYPE.DUP, protocol=PROTOCOL.GENOME) ann.add_gene(genomic.Gene('1', 1500, 1950, strand=STRAND.POS)) reference_genome = {'1': MockObject(seq=MockString('A'))} ft = variant.FusionTranscript.build(ann, reference_genome) ann.fusion = ft canvas, legend = draw_sv_summary_diagram(d, ann) self.assertEqual(4, len(canvas.elements)) # defs counts as element expected_height = (d.top_margin + d.bottom_margin + d.track_height + d.breakpoint_bottom_margin + d.breakpoint_top_margin + d.inner_margin + d.track_height + d.splice_height + d.padding + d.translation_track_height + d.padding * 2 + d.domain_track_height * 2 + d.inner_margin + d.track_height + d.breakpoint_bottom_margin + d.breakpoint_top_margin + d.splice_height) if OUTPUT_SVG: canvas.saveas('test_draw_layout_single_transcript.svg') self.assertEqual(expected_height, canvas.attribs['height'])
def test_draw_translocation_with_template(self): d = DiagramSettings() d1 = protein.Domain('PF0001', [(55, 61), (71, 73)]) d2 = protein.Domain('PF0002', [(10, 20), (30, 34)]) g1 = genomic.Gene(TEMPLATE_METADATA['1'], 150, 1000, strand=STRAND.POS, aliases=['HUGO2']) g2 = genomic.Gene(TEMPLATE_METADATA['X'], 5000, 7500, strand=STRAND.NEG, aliases=['HUGO3']) t1 = build_transcript( gene=g1, name='transcript1', cds_start=50, cds_end=249, exons=[(200, 299), (400, 499), (700, 899)], domains=[d2, d1], ) t2 = build_transcript( gene=g2, name='transcript2', cds_start=120, cds_end=700, exons=[(5100, 5299), (5800, 6199), (6500, 6549), (6700, 6799)], domains=[], ) b1 = Breakpoint('1', 350, orient=ORIENT.LEFT) b2 = Breakpoint('2', 6520, orient=ORIENT.LEFT) bpp = BreakpointPair(b1, b2, opposing_strands=True, untemplated_seq='') ann = variant.Annotation(bpp, transcript1=t1, transcript2=t2, event_type=SVTYPE.ITRANS, protocol=PROTOCOL.GENOME) # genes 1 ann.add_gene( genomic.Gene('1', 1500, 1950, strand=STRAND.POS, aliases=['HUGO5'])) ann.add_gene(genomic.Gene('1', 3000, 3980, strand=STRAND.POS)) ann.add_gene(genomic.Gene('1', 3700, 4400, strand=STRAND.NEG)) # genes 2 ann.add_gene(genomic.Gene('2', 1500, 1950, strand=STRAND.NEG)) ann.add_gene(genomic.Gene('2', 5500, 9000, strand=STRAND.POS)) ann.add_gene(genomic.Gene('2', 3700, 4400, strand=STRAND.NEG)) reference_genome = { '1': MockObject(seq=MockString('A')), '2': MockObject(seq=MockString('A')), } ft = variant.FusionTranscript.build(ann, reference_genome) ann.fusion = ft canvas, legend = draw_sv_summary_diagram(d, ann, draw_reference_templates=True, templates=TEMPLATE_METADATA) if OUTPUT_SVG: canvas.saveas('test_draw_translocation_with_template.svg') self.assertEqual(8, len(canvas.elements)) # defs counts as element expected_height = ( d.top_margin + d.bottom_margin + d.track_height * 2 + d.padding + d.breakpoint_bottom_margin + d.breakpoint_top_margin + d.inner_margin + d.track_height + d.splice_height + d.breakpoint_bottom_margin + d.breakpoint_top_margin + d.padding + d.translation_track_height + d.padding * 2 + d.domain_track_height * 2 + d.inner_margin * 2 + d.track_height + d.breakpoint_bottom_margin + d.breakpoint_top_margin + d.splice_height + d.template_track_height) self.assertAlmostEqual(expected_height, canvas.attribs['height'])