Exemple #1
0
 def test_Transcoder(self):
     dna = sequence.DNA(name='test', seq='AAAGTGAGCCCC')
     dna.ftable.add_feature(Feature(dna, 1, 3, '+', 'GEN'))
     dna.ftable.add_feature(Feature(dna, 4, 9, '+', 'DON'))
     dna.ftable.add_feature(Feature(dna, 10, 12, '+', 'GEN'))
     tc = hmm.Transcoder(model=self.hmm, dna=dna)
     self.assertAlmostEqual(tc.score, 1.250948871669515)
Exemple #2
0
 def test_StochasticViterbi_and_Parse(self):
     dna = sequence.DNA(name='test', seq='TTTTTGTAAGTAAGTTTTT')
     v = hmm.StochasticViterbi(model=self.hmm, dna=dna, seed=1)
     ps = v.generate_paths(1000)
     self.assertIsInstance(ps[0], hmm.Parse)
     self.assertAlmostEqual(ps[0].score, 4.600333948735676)
     self.assertAlmostEqual(ps[0].freq, 0.459)
Exemple #3
0
 def test_Viterbi_logspace(self):
     dna = sequence.DNA(name='test', seq='AAAAGTAAGTTTTT')
     m = copy.deepcopy(self.hmm)
     m.convert2log()
     v = hmm.Viterbi(model=m, dna=dna)
     p = v.generate_path()
     self.assertAlmostEqual(p.score, 1.5763805776787159)
Exemple #4
0
 def test_StochasticViterbi_logspace(self):
     dna = sequence.DNA(name='test', seq='TTTTTGTAAGTAAGTTTTT')
     m = copy.deepcopy(self.hmm)
     m.convert2log()
     v = hmm.StochasticViterbi(model=m, dna=dna, seed=1)
     ps = v.generate_paths(1000)
     self.assertAlmostEqual(ps[0].score, 1.5261288984112191)
     self.assertAlmostEqual(ps[0].freq, 0.459)
Exemple #5
0
 def test_Viterbi_and_Parse(self):
     dna = sequence.DNA(name='test', seq='AAAAGTAAGTTTTT')
     v = hmm.Viterbi(model=self.hmm, dna=dna)
     p = v.generate_path()
     self.assertIsInstance(p, hmm.Parse)
     self.assertEqual(p.freq, None)
     self.assertEqual(p.path[0], 'GEN')
     self.assertAlmostEqual(p.score, 4.837415437963225)
     ft = p.features()
     self.assertEqual(ft[1].type, 'DON')
     self.assertEqual(ft[1].beg, 5)
Exemple #6
0
    def test_DNA(self):
        s = sequence.DNA(seq='CATGCCAACAATGCNCAY')
        self.assertIsInstance(s, sequence.DNA)
        try:
            s.check_alphabet()
        except sequence.SequenceError:
            self.fail('DNA object failed check_alphabet()')
        p = s.translate()
        self.assertIsInstance(p, sequence.Protein)
        self.assertEqual(p.seq, 'HANNAH')
        s.revcomp()
        self.assertIsInstance(s, sequence.DNA)
        self.assertEqual(s.seq, 'RTGNGCATTGTTGGCATG')

        s2 = sequence.DNA(seq='CATGCCAACAATGCNCAQ')
        with self.assertRaises(sequence.SequenceError):
            s2.check_alphabet()
        with self.assertRaises(sequence.SequenceError):
            p2 = s2.translate()
        with self.assertRaises(sequence.SequenceError):
            s2.revcomp()
Exemple #7
0
 def test_ForwardBackward(self):
     dna = sequence.DNA(name='test', seq='AGT')
     p = hmm.ForwardBackward(model=self.hmm, dna=dna)
     self.assertAlmostEqual(p.posterior(state_name='GEN', i=0),
                            0.021213450734526202,
                            places=8)
     self.assertAlmostEqual(p.posterior(state_name='DON-1', i=2),
                            0.0031969999999999998,
                            places=8)
     self.assertAlmostEqual(p.posterior(state_name='DON-0', i=1),
                            0.0031969999999999998,
                            places=8)
     self.assertAlmostEqual(p.posterior(state_name='GEN', i=2),
                            0.0180164507345262,
                            places=8)
Exemple #8
0
              arg.gff3 + ' ' + '--model ' + 'mRNA2' + ' ' + '--hmm ' +
              arg.mRNA2 + ' ' + '--source ' + arg.work +
              'C.elegans.mRNA2.source' + ' ' + '--u5_ctx ' + '5 ' +
              '--u3_ctx ' + '5 ' + '--koz_ctx ' + '1 ' + '--atg_ctx ' + '2 ' +
              '--stop_ctx ' + '2 ' + '--cds_ctx ' + '2')
    print('Forge Completed')

fasta = toolbox.FASTA_stream(filename=arg.work +
                             'C.elegans.mRNA1.source.fasta')
gff = toolbox.GFF_file(filename=arg.work + 'C.elegans.mRNA1.source.gff')

#Extract from GFF3
GFF3_genes = {}
dnas = []
for entry in fasta:
    dna = sequence.DNA(seq=entry.seq, name=entry.id)
    dnas.append(dna)
    gffs = gff.get(chrom=dna.name)
    for g in gffs:
        if g.type == 'ATG':
            GFF3_genes.update({entry.id: g.beg})

#mRNA1 model
mRNA1_genes = {}
mRNA1_hmm = hmm.HMM.read(arg.work + 'C.elegans.mRNA1.hmm')
mRNA1_hmm.convert2log()
for dna in dnas:
    mRNA1 = decode.Viterbi(model=mRNA1_hmm, dna=dna)
    path = mRNA1.generate_path()
    features = path.features()
    for f in features: