def test_max_intron_length_filter(self): intron_length = MaxIntronLengthFilter(30) # Create a mock sequence seq = Sequence() # Give the sequence some genes seq.genes = [ Gene('foo_seq', 'geib_labs', [1, 2], '+', 'foo1'), Gene('foo_seq', 'geib_labs', [1, 2], '+', 'foo2'), Gene('foo_seq', 'geib_labs', [1, 2], '+', 'foo3') ] # Give the mock mrnas some exon's test_mrna0 = Mock() test_mrna0.identifier = 'foo1-RA' test_mrna0.death_flagged = False test_mrna0.exon = Mock() test_mrna0.get_shortest_intron = Mock(return_value=20) test_mrna0.get_longest_intron = Mock(return_value=20) test_mrna1 = Mock() test_mrna1.identifier = 'foo2-RA' test_mrna1.death_flagged = False test_mrna1.exon = Mock() test_mrna1.get_shortest_intron = Mock(return_value=30) test_mrna1.get_longest_intron = Mock(return_value=30) test_mrna2 = Mock() test_mrna2.identifier = 'foo2-RB' test_mrna2.death_flagged = False test_mrna2.exon = None test_mrna3 = Mock() test_mrna3.identifier = 'foo3-RA' test_mrna3.death_flagged = False test_mrna3.exon = Mock() test_mrna3.get_shortest_intron = Mock(return_value=40) test_mrna3.get_longest_intron = Mock(return_value=40) # Give the mock genes some mrnas seq.genes[0].mrnas = [test_mrna0] seq.genes[0].death_flagged = False seq.genes[1].mrnas = [test_mrna1, test_mrna2] seq.genes[1].death_flagged = False seq.genes[2].mrnas = [test_mrna3] seq.genes[2].death_flagged = False # Apply the filter intron_length.apply(seq) self.assertEqual(len(seq.genes), 3) self.assertEqual(seq.genes[0].mrnas, [test_mrna0]) self.assertEqual(seq.genes[1].mrnas, [test_mrna1, test_mrna2])
def test_max_cds_length_filter(self): cds_length = MaxCDSLengthFilter(100) # Create a mock sequence seq = Sequence() # Give the sequence some genes seq.genes = [ Gene('foo_seq', 'geib_labs', [1, 2], '+', 'foo1'), Gene('foo_seq', 'geib_labs', [1, 2], '+', 'foo2'), Gene('foo_seq', 'geib_labs', [1, 2], '+', 'foo3') ] # Give the mock mrnas some cds's test_mrna0 = Mock() test_mrna0.identifier = 'foo1-RA' test_mrna0.death_flagged = False test_mrna0.cds = Mock() test_mrna0.cds.length = Mock(return_value=90) test_mrna1 = Mock() test_mrna1.identifier = 'foo2-RA' test_mrna1.death_flagged = False test_mrna1.cds = None test_mrna2 = Mock() test_mrna2.identifier = 'foo2-RB' test_mrna2.death_flagged = False test_mrna2.cds = Mock() test_mrna2.cds.length = Mock(return_value=100) test_mrna3 = Mock() test_mrna3.identifier = 'foo3-RA' test_mrna3.death_flagged = False test_mrna3.cds = Mock() test_mrna3.cds.length = Mock(return_value=110) # Give the mock genes some mrnas seq.genes[0].mrnas = [test_mrna0] seq.genes[0].death_flagged = False seq.genes[1].mrnas = [test_mrna1, test_mrna2] seq.genes[1].death_flagged = False seq.genes[2].mrnas = [test_mrna3] seq.genes[2].death_flagged = False # Apply the filter cds_length.apply(seq) self.assertEqual(len(seq.genes), 3) self.assertEqual(seq.genes[0].mrnas, [test_mrna0]) self.assertEqual(seq.genes[1].mrnas, [test_mrna1, test_mrna2])
def process_gene_line(self, line): """Extracts arguments from a line and instantiates a Gene object.""" kwargs = self.extract_gene_args(line) if not kwargs: return gene_id = kwargs['identifier'] self.genes[gene_id] = Gene(**kwargs)
def test_gene_initialized_without_annotations(self): newgene = Gene(seq_name="seq1", source="maker", indices=[1, 50], strand="+", identifier="foo_gene_1") self.assertFalse(newgene.annotations) self.assertEquals(0, len(newgene.annotations.keys()))
def __init__(self, population_size, filename_of_genes, max_weight, logger): self.population_size = population_size self.genes = Gene(filename_of_genes, logger) self.max_weight = max_weight self.max_score_for_run = None self.logger = logger self.best_chromosome = np.array([0, 0]) return
def test_gene_initialized_with_annotations(self): newgene = Gene(seq_name="seq1", source="maker", indices=[1, 50], strand="+", identifier="foo_gene_1", annotations={"bar": ["cat"]}) self.assertTrue(newgene.annotations) self.assertEquals(1, len(newgene.annotations.keys()))
def test_to_tbl_negative(self): gene = Gene("seq1", "maker", [1, 50], "-", "foo_gene_1") mrna1 = Mock() mrna1.to_tbl.return_value = "mrna1_to_tbl...\n" mrna2 = Mock() mrna2.to_tbl.return_value = "mrna2_to_tbl...\n" gene.mrnas.append(mrna1) gene.mrnas.append(mrna2) expected = "50\t1\tgene\n\t\t\tlocus_tag\tfoo_gene_1\nmrna1_to_tbl...\nmrna2_to_tbl...\n" self.assertEquals(gene.to_tbl(), expected)
def process_gene_line(self, line, gene_type): """Extracts arguments from a line and instantiates a Gene object.""" kwargs = self.extract_gene_args(line) if not kwargs: return gene_id = kwargs['identifier'] gene = Gene(**kwargs) if gene_type == 'pseudogene': gene.pseudo = True self.genes[gene_id] = gene
def setUp(self): self.test_gene0 = Gene(seq_name="sctg_0080_0020", source="maker", indices=[3734, 7436], strand='+', identifier=1) self.test_gene1 = Gene(seq_name="sctg_0080_0020", source="maker", indices=[3734, 7436], strand='+', identifier=1) self.fake_mrna1 = Mock() self.fake_mrna1.identifier = "fake_mrna1" self.fake_mrna1.death_flagged = False self.fake_mrna2 = Mock() self.fake_mrna2.identifier = "fake_mrna2" self.fake_mrna2.death_flagged = False self.test_gene1.mrnas.append(self.fake_mrna1) self.test_gene1.mrnas.append(self.fake_mrna2)
def test_to_tbl_positive(self): gene = Gene(seq_name="seq1", source="maker", indices=[1, 50], strand="+", identifier="foo_gene_1") self.assertFalse(gene.annotations) gene.add_annotation('foo', 'dog') mrna1 = Mock() mrna1.to_tbl.return_value = "mrna1_to_tbl...\n" mrna2 = Mock() mrna2.to_tbl.return_value = "mrna2_to_tbl...\n" gene.mrnas.append(mrna1) gene.mrnas.append(mrna2) expected = "1\t50\tgene\n\t\t\tlocus_tag\tfoo_gene_1\nmrna1_to_tbl...\nmrna2_to_tbl...\n" self.assertEquals(gene.to_tbl(), expected)