Exemplo n.º 1
0
    def test_region_check(self):
        with self.assertRaises(genome_tools.BadRegionError):
            self.genome.check_region(genome_tools.Region('chr4',10,20))

        with self.assertRaises(genome_tools.BadRegionError):
            self.genome.check_region(genome_tools.Region('chr1',-1, 20))

        with self.assertRaises(genome_tools.BadRegionError):
            self.genome.check_region(genome_tools.Region('chr2', 300, 400))
Exemplo n.º 2
0
    def test_get_window_from_position(self):
        region, window_idx = self.genome.get_window_from_position('chr2', 250)
        self.assertTrue(
            region == genome_tools.Region('chr2', 200, 300)
        )

        next_region, next_window_idx = self.genome.get_next_window(region)
        self.assertTrue(
            next_region == genome_tools.Region('chr2',300,375)
        )

        self.assertTrue(
            window_idx == (next_window_idx - 1)
        )
Exemplo n.º 3
0
    def _check_region_specification(self, regions):

        invalid_chroms = Counter()
        valid_regions = []
        for i, region in enumerate(regions):
            assert(isinstance(region, (tuple, list)) and len(region) == 3), 'Error at region #{}: Each region passed must be in format (string \"chr\",int start, int end'\
                .format(str(i))

            try:
                new_region = genome_tools.Region(*region, annotation=i)
                self.data_interface.genome.check_region(new_region)
                valid_regions.append(new_region)
            except ValueError:
                raise AssertionError(
                    'Error at region #{}: Could not coerce positions into integers'
                    .format(str(i)))
            except genome_tools.NotInGenomeError as err:
                invalid_chroms[region[0]] += 1
                #raise AssertionError('Error at region #{}: '.format(str(i+1)) + str(err) + '\nOnly main chromosomes (chr[1-22,X,Y] for hg38, and chr[1-19,X,Y] for mm10) are permissible for LISA test.')
            except genome_tools.BadRegionError as err:
                raise AssertionError('Error at region #{}: '.format(str(i +
                                                                        1)) +
                                     str(err))

        if len(invalid_chroms) > 0:
            self.log.append(
                'WARNING: {} regions encounted from unknown chromsomes: {}'.
                format(str(sum(invalid_chroms.values())),
                       str(','.join(invalid_chroms.keys()))))

        return valid_regions
Exemplo n.º 4
0
    def test_get_window_idx(self):
        self.assertTrue(
            self.genome.get_region(0)[0] == genome_tools.Region('chr1', 0, 100)
        )

        self.assertTrue(
            self.genome.get_region(4)[0] == genome_tools.Region('chr1',400,450)
        )

        self.assertTrue(
            self.genome.get_region(5)[0] == genome_tools.Region('chr2',0,100)
        )

        self.assertTrue(
            self.genome.get_region(14)[0] == genome_tools.Region('chr3',500,600)
        )

        with self.assertRaises(AssertionError):
            self.genome.get_region(15)
Exemplo n.º 5
0
    def test_overlap_any(self):
        self.assertTrue(
            genome_tools.Region('chr1',5,10).overlaps(genome_tools.Region('chr1',8,15))
        )

        self.assertFalse(
            genome_tools.Region('chr1',1,11).overlaps(genome_tools.Region('chr1',9,15), min_overlap_proportion=0.4)
        )

        self.assertTrue(
            genome_tools.Region('chr1',1,11).overlaps(genome_tools.Region('chr1',6,15), min_overlap_proportion=0.4)
        )
Exemplo n.º 6
0
 def test_invalid_region(self):
     with self.assertRaises(AssertionError):
         genome_tools.Region('chr1',10, 5)
Exemplo n.º 7
0
 def test_regions_equal(self):
     self.assertTrue(
         genome_tools.Region('chr1',10,15) == genome_tools.Region('chr1', 10, 15)
     )
Exemplo n.º 8
0
 def test_distance_function(self):
     self.assertEqual(
         genome_tools.Region('chr1',20, 30).get_genomic_distance(genome_tools.Region('chr1', 120, 130)), 100)
Exemplo n.º 9
0
 def test_overlap_negative_abutted(self):
     self.assertFalse(
         genome_tools.Region('chr1',5,10).overlaps(genome_tools.Region('chr1',10,20))
     )
Exemplo n.º 10
0
 def test_overlap_negative(self):
     self.assertFalse(
         genome_tools.Region('chr1',5,10).overlaps(genome_tools.Region('chr1',20,25))
     )
Exemplo n.º 11
0
    def setUp(self):
        self.genome = genome_tools.Genome(['chr1','chr2','chr3'], [450, 375, 600], window_size=50)
        self.scrambled_genome = genome_tools.Genome(['chr1','chr3','chr2'], [450, 600, 375], window_size=50)

        self.regions1A = [
            genome_tools.Region('chr1',20,40),
            genome_tools.Region('chr1',30,60),
            genome_tools.Region('chr1',210,230),
            genome_tools.Region('chr2',100,150),
            genome_tools.Region('chr2',220,233),
            genome_tools.Region('chr3',430,450),
        ]
        self.regions1B = [
            genome_tools.Region('chr1',20,40),
            genome_tools.Region('chr1',30,60),
            genome_tools.Region('chr1',210,230),
            genome_tools.Region('chr2',100,150),
            genome_tools.Region('chr2',220,233),
            genome_tools.Region('chr3',430,450),
        ]

        self.auto_distancing_truth = np.array(
            [[0,15,0,0,0,0],
             [15,0,175,0,0,0],
             [0,175,0,0,0,0],
             [0,0,0,0,101,0],
             [0,0,0,101,0,0],
             [0,0,0,0,0,0]
            ]
        )

        self.m2m_map_truth = np.array([
            (0,0),
            (0,1),
            (1,1),
            (4,2),
            (11,3),
            (13,4),
            (25,5)
        ])
Exemplo n.º 12
0
 def test_overlap_different_chr(self):
     self.assertFalse(
         genome_tools.Region('chr1',5,10).overlaps(genome_tools.Region('chr2',5,10))
     )