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_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_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'])