Example #1
0
    def test_no_collapse3(self):
        '''
            before
            L|=====|------|======|R
                     L|=|-|======|------|====|R
            after
            L|=====|------|======|R
                     L|=|-|======|------|====|R

        '''
        e1 = gimme.ExonObj('chr1', 2400, 2450)
        e1.terminal = 1
        self.align_db.exon_db[str(e1)] = e1

        e2 = gimme.ExonObj('chr1', 2500, 2600)
        e2.terminal = 2
        self.align_db.exon_db[str(e2)] = e2

        e3 = gimme.ExonObj('chr1', 2700, 2800)
        e3.terminal = 1
        self.align_db.exon_db[str(e3)] = e3

        self.exon_graph.add_edge(str(e1), str(e2))
        self.exon_graph.add_edge(str(e2), str(e3))

        self.assertEqual(len(self.exon_graph.nodes()), 8)
        self.assertEqual(len(self.exon_graph.edges()), 7)

        gimme.collapse_exon(self.exon_graph, self.align_db)

        self.assertEqual(len(self.exon_graph.nodes()), 8)
        self.assertEqual(len(self.exon_graph.edges()), 7)
Example #2
0
    def test_collapse_all(self):
        '''
            before
                            L|==|--------|====|R
            L|=====|------|=====|--------|======|-------|======|R

            after
            L|=====|------|=====|--------|======|-------|======|R

        '''

        e1 = gimme.ExonObj('chr1', 1350, 1400)
        e1.terminal = 1
        self.align_db.exon_db[str(e1)] = e1

        e2 = gimme.ExonObj('chr1', 1600, 1650)
        e2.terminal = 2
        self.align_db.exon_db[str(e2)] = e2

        self.exon_graph.add_edge(str(e1), str(e2))

        self.assertEqual(len(self.exon_graph.nodes()), 8)
        self.assertEqual(len(self.exon_graph.edges()), 6)

        gimme.collapse_exon(self.exon_graph, self.align_db)

        self.assertEqual(len(self.exon_graph.nodes()), 6)
        self.assertEqual(len(self.exon_graph.edges()), 5)
Example #3
0
    def test_collapse_right_utr_shorter_than_100(self):
        '''
            before
              L|===|------|=====|--------|=========|R
            L|=====|------|=====|--------|======|-------|======|R

            after
            L|=====|------|=====|--------|======|-------|======|R

        '''

        e1 = gimme.ExonObj('chr1', 1050, 1100)
        e1.terminal = 1
        self.align_db.exon_db[str(e1)] = e1

        e2 = gimme.ExonObj('chr1', 1300, 1400)
        self.align_db.exon_db[str(e2)] = e2

        e3 = gimme.ExonObj('chr1', 1600, 1750)
        e3.terminal = 2
        self.align_db.exon_db[str(e3)] = e3

        self.exon_graph.add_edge(str(e1), str(e2))
        self.exon_graph.add_edge(str(e2), str(e3))

        self.assertEqual(len(self.exon_graph.nodes()), 8)
        self.assertEqual(len(self.exon_graph.edges()), 7)

        gimme.collapse_exon(self.exon_graph, self.align_db)

        self.assertEqual(len(self.exon_graph.nodes()), 6)
        self.assertEqual(len(self.exon_graph.edges()), 5)
Example #4
0
    def test_collapse_left_terminal_exon_with_other_exons(self):
        '''
            before
                         |===|--------|======|R
            L|====|----|=====|R

            after
            L|====|----|=====|--------|======|R

        '''

        e1 = gimme.ExonObj('chr1', 700, 800)
        e1.terminal = 1
        self.align_db.exon_db[str(e1)] = e1

        e2 = gimme.ExonObj('chr1', 900, 1100)
        e2.terminal = 2
        self.align_db.exon_db[str(e2)] = e2
        self.exon_graph.add_edge(str(e1), str(e2))

        self.assertEqual(len(self.exon_graph.nodes()), 8)
        self.assertEqual(len(self.exon_graph.edges()), 6)

        gimme.collapse_exon(self.exon_graph, self.align_db)

        self.assertEqual(len(self.exon_graph.nodes()), 7)
        self.assertEqual(len(self.exon_graph.edges()), 6)

        self.assertItemsEqual(self.exon_graph.edges(),
                [('chr1:700-800', 'chr1:900-1100'),
                    ('chr1:900-1100', 'chr1:1300-1400'),
                    ('chr1:1300-1400', 'chr1:1600-1700'),
                    ('chr1:1600-1700', 'chr1:1900-2000'),
                    ('chr1:1900-2000', 'chr1:2200-2300'),
                    ('chr1:2200-2300', 'chr1:2500-2600')])
Example #5
0
    def test_collapse_right_terminal_exon_with_skipped_exon(self):
        '''
            before
            L|=====|------|=====|--------|======|R
            L|=====|---------------------|===|R

            after
            L|=====|------|=====|--------|======|R
            L|=====|---------------------|======|R

        '''

        e1 = gimme.ExonObj('chr1', 1900, 2000)
        e1.terminal = 1
        self.align_db.exon_db[str(e1)] = e1

        e2 = gimme.ExonObj('chr1', 2500, 2550)
        e2.terminal = 2
        self.align_db.exon_db[str(e2)] = e2
        self.exon_graph.add_edge(str(e1), str(e2))

        self.assertEqual(len(self.exon_graph.nodes()), 7)
        self.assertEqual(len(self.exon_graph.edges()), 6)

        gimme.collapse_exon(self.exon_graph, self.align_db)

        #print >> sys.stderr, self.exon_graph.edges()

        #nx.draw(self.exon_graph)
        #pyplot.show()
        #print >> sys.stderr, self.exon_graph.neighbors('chr1:1900-2000')

        self.assertEqual(len(self.exon_graph.nodes()), 6)
        self.assertEqual(len(self.exon_graph.edges()), 6)

        self.assertItemsEqual(self.exon_graph.edges(),
                [('chr1:1000-1100', 'chr1:1300-1400'),
                    ('chr1:1300-1400', 'chr1:1600-1700'),
                    ('chr1:1600-1700', 'chr1:1900-2000'),
                    ('chr1:1900-2000', 'chr1:2200-2300'),
                    ('chr1:1900-2000', 'chr1:2500-2600'),
                    ('chr1:2200-2300', 'chr1:2500-2600'),
                    ])
Example #6
0
    def test_collapse_right_utr_longer_than_100(self):
        '''
            before
              L|===|------|=====|--------|=========|R
            L|=====|------|=====|--------|======|-------|======|R

            after
            L|=====|------|=====|--------|=========|R
            L|=====|------|=====|--------|======|-------|======|R

        '''

        e1 = gimme.ExonObj('chr1', 1050, 1100)
        e1.terminal = 1
        self.align_db.exon_db[str(e1)] = e1

        e2 = gimme.ExonObj('chr1', 1300, 1400)
        self.align_db.exon_db[str(e2)] = e2

        e3 = gimme.ExonObj('chr1', 1600, 1850)
        e3.terminal = 2
        self.align_db.exon_db[str(e3)] = e3

        self.exon_graph.add_edge(str(e1), str(e2))
        self.exon_graph.add_edge(str(e2), str(e3))

        self.assertEqual(len(self.exon_graph.nodes()), 8)
        self.assertEqual(len(self.exon_graph.edges()), 7)

        gimme.collapse_exon(self.exon_graph, self.align_db)

        self.assertEqual(len(self.exon_graph.nodes()), 7)
        self.assertEqual(len(self.exon_graph.edges()), 6)

        self.assertItemsEqual(self.exon_graph.edges(),
                [('chr1:1000-1100', 'chr1:1300-1400'),
                    ('chr1:1300-1400', 'chr1:1600-1700'),
                    ('chr1:1300-1400', 'chr1:1600-1850'),
                    ('chr1:1600-1700', 'chr1:1900-2000'),
                    ('chr1:1900-2000', 'chr1:2200-2300'),
                    ('chr1:2200-2300', 'chr1:2500-2600'),
                    ])
Example #7
0
    def test_collapse_right_terminal_exon(self):
        '''
            before
            L----|=====|--------|======|R
            L----|=====|--------|===|R

            after
            L----|=====|--------|======|R

        '''

        e = gimme.ExonObj('chr1', 2500, 2550)
        e.terminal = 2
        self.align_db.exon_db[str(e)] = e
        self.exon_graph.add_edge('chr1:2200-2300', str(e))
        self.assertEqual(len(self.exon_graph.nodes()), 7)
        self.assertEqual(len(self.exon_graph.edges()), 6)

        gimme.collapse_exon(self.exon_graph, self.align_db)

        self.assertEqual(len(self.exon_graph.nodes()), 6)
        self.assertEqual(len(self.exon_graph.edges()), 5)
Example #8
0
    def test_collapse_left_terminal_exon(self):
        '''
            before
            L|=====|--------|======|-----R
               L|==|--------|======|-----R

            after
            L|=====|--------|======|-----R

        '''

        e = gimme.ExonObj('chr1', 1050, 1100)
        e.terminal = 1
        self.align_db.exon_db[str(e)] = e
        self.exon_graph.add_edge(str(e), 'chr1:1300-1400')
        self.assertEqual(len(self.exon_graph.nodes()), 7)
        self.assertEqual(len(self.exon_graph.edges()), 6)

        gimme.collapse_exon(self.exon_graph, self.align_db)

        self.assertEqual(len(self.exon_graph.nodes()), 6)
        self.assertEqual(len(self.exon_graph.edges()), 5)
Example #9
0
    def test_two_no_collapse_one_collapse(self):
        '''
            before
          L|=========|------|=====|R
            L|=|-|=|--------|=====|R
           L|========|------|=====|--------|======|-------|======|R

            after
            L|=|-|=|--------|=====|R
          L|=========|------|=====|--------|======|-------|======|R

        '''
        e1 = gimme.ExonObj('chr1', 990, 1010)
        e1.terminal = 1
        self.align_db.exon_db[str(e1)] = e1

        e2 = gimme.ExonObj('chr1', 1300, 1400)
        e2.terminal = 2
        self.align_db.exon_db[str(e2)] = e2

        e3 = gimme.ExonObj('chr1', 950, 1100)
        e3.terminal = 1
        self.align_db.exon_db[str(e3)] = e3

        e4 = gimme.ExonObj('chr1', 1030, 1040)
        self.align_db.exon_db[str(e4)] = e4

        self.exon_graph.add_edge(str(e1), str(e4))
        self.exon_graph.add_edge(str(e3), str(e2))
        self.exon_graph.add_edge(str(e4), str(e2))

        self.assertEqual(len(self.exon_graph.nodes()), 9)
        self.assertEqual(len(self.exon_graph.edges()), 8)

        gimme.collapse_exon(self.exon_graph, self.align_db)

        self.assertEqual(len(self.exon_graph.nodes()), 8)
        self.assertEqual(len(self.exon_graph.edges()), 7)