Example #1
0
    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), 2)
        self.assertEqual(seq.genes[0].mrnas, [test_mrna0])
        self.assertEqual(seq.genes[1].mrnas, [test_mrna1, test_mrna2])
Example #2
0
    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), 2)
        self.assertEqual(seq.genes[0].mrnas, [test_mrna0])
        self.assertEqual(seq.genes[1].mrnas, [test_mrna1, test_mrna2])
 def setup_seqs_and_genes(self):
     self.setup_seqs()
     gene1 = Mock()
     gene1.seq_name = "seq2"
     gene1.identifier = "gene1"
     self.ctrlr.add_gene(gene1)
     gene2 = Mock()
     gene2.seq_name = "seq2"
     gene2.identifier = "gene2"
     self.ctrlr.add_gene(gene2)
     gene3 = Mock()
     gene3.seq_name = "seq3"
     gene3.identifier = "gene3"
     self.ctrlr.add_gene(gene3)
Example #4
0
 def add_mock_gene_with_2_mrnas(self, name):
     mockgene = Mock()
     mockgene.indices = [20, 30]
     mockgene.identifier = name
     mockgene.death_flagged = False
     mockgene.mrnas = [Mock(), Mock()]
     mockgene.mrnas[0].identifier = name + "-RA"
     mockgene.mrnas[0].cds = None
     mockgene.mrnas[0].exon = None
     mockgene.mrnas[0].length = Mock(return_value=5)
     mockgene.mrnas[1].identifier = name + "-RB"
     mockgene.mrnas[1].cds = Mock()
     mockgene.mrnas[1].cds.identifier = [name + "-RB:CDS"]
     mockgene.mrnas[1].cds.length = Mock(return_value=3)
     mockgene.mrnas[1].exon = Mock()
     mockgene.mrnas[1].length = Mock(return_value=2)
     mockgene.get_valid_mrnas = Mock(return_value=mockgene.mrnas)
     mockgene.length = Mock(return_value=10)
     mockgene.get_partial_info.return_value = {
         "complete": 0,
         "start_no_stop": 1,
         "stop_no_start": 1,
         "no_stop_no_start": 1,
     }
     mockgene.get_num_exons.return_value = 4
     mockgene.get_num_introns.return_value = 3
     mockgene.get_longest_exon.return_value = 10
     mockgene.get_longest_intron.return_value = 10
     mockgene.get_shortest_exon.return_value = 5
     mockgene.get_shortest_intron.return_value = 5
     mockgene.get_total_exon_length.return_value = 25
     mockgene.get_total_intron_length.return_value = 25
     self.seq1.add_gene(mockgene)
Example #5
0
 def test_add_annotations_from_list_adds_to_gene(self):
     gene = Mock()
     self.seq1.genes = [gene]
     gene.identifier = "foo_gene"
     anno_list = [["foo_gene", "name", "ABC123"], ["bar_gene", "name", "XYZ789"]]
     self.seq1.add_annotations_from_list(anno_list)
     self.assertEquals("ABC123", gene.name)
Example #6
0
 def test_mrna_to_protein_fasta_reverse(self):
     mrna = Mock()
     mrna.identifier = "foo_mrna"
     mrna.cds = Mock()
     mrna.cds.indices = [[21, 27], [4, 10]]
     mrna.strand = "-"
     expected = ">foo_mrna protein\nCNL*\n"
     self.assertEquals(expected, self.helper.mrna_to_protein_fasta(mrna))
Example #7
0
 def test_mrna_to_cds_fasta(self):
     mrna = Mock()
     mrna.identifier = "foo_mrna"
     mrna.cds = Mock()
     mrna.cds.indices = [[4, 10], [21, 27]]
     mrna.strand = "-"
     expected = ">foo_mrna CDS\ntgtaatcTGTAATC\n"
     self.assertEquals(expected, self.helper.mrna_to_cds_fasta(mrna))
Example #8
0
 def test_mrna_to_fasta_reverse_strand(self):
     mrna = Mock()
     mrna.identifier = "foo_mrna"
     mrna.exon = Mock()
     mrna.exon.indices = [[4, 10], [21, 27]]
     mrna.strand = "-"
     expected = ">foo_mrna\ntgtaatcTGTAATC\n"
     self.assertEquals(expected, self.helper.mrna_to_fasta(mrna))
Example #9
0
 def test_mrna_to_fasta(self):
     mrna = Mock()
     mrna.identifier = "foo_mrna"
     mrna.exon = Mock()
     mrna.exon.indices = [[4, 10], [21, 27]]
     mrna.strand = "+"
     expected = ">foo_mrna\nGATTACAgattaca\n"
     self.assertEquals(expected, self.helper.mrna_to_fasta(mrna))
Example #10
0
 def test_add_annotations_from_list_adds_to_mrna(self):
     gene = Mock()
     mrna = Mock()
     self.seq1.genes = [gene]
     gene.mrnas = [mrna]
     gene.identifier = "foo_gene"
     gene.contains_mrna.return_value = True
     anno_list = [["foo_mrna", "Dbxref", "PFAM:0001"]]
     self.seq1.add_annotations_from_list(anno_list)
     gene.add_mrna_annotation.assert_called_with("foo_mrna", "Dbxref", "PFAM:0001")
Example #11
0
 def add_mock_gene(self, name="foo_gene"):
     mockgene = Mock()
     mockgene.identifier = name
     mockgene.indices = [2, 4]
     mockgene.death_flagged = False
     mockgene.to_mrna_fasta.return_value = "mockgene_to_mrna_fasta\n"
     mockgene.to_cds_fasta.return_value = "mockgene_to_cds_fasta\n"
     mockgene.to_protein_fasta.return_value = "mockgene_to_protein_fasta\n"
     mockgene.get_valid_mrnas = Mock(return_value=[])
     self.seq1.add_gene(mockgene)
Example #12
0
 def test_custom_date_field_widget(self):
     obj = Mock()
     obj.prefix = "objprefix"
     obj.identifier = "objident"
     obj.htmlAttributes = {}
     obj.valueType = "medium"
     request = TestRequest()
     form = Form(obj, request)
     form.prefix = "form.prefix"
     datefield = DateFieldWidget(obj, form, request)
     datum = datetime.date(2011, 01, 01)
Example #13
0
 def test_add_mrna_annotation(self):
     mrna = Mock()
     mrna.identifier = "foo_mrna"
     self.test_gene0.mrnas = [mrna]
     self.test_gene0.add_mrna_annotation("foo_mrna", "gag_flag", "awesome_anno")
     mrna.add_annotation.assert_called_with("gag_flag", "awesome_anno")