Demo entry 6328597

HMM

   

Submitted by Whyy on Nov 27, 2016 at 08:13
Language: Python. Code size: 791 Bytes.

with open('rosalind_ba10b.txt','r') as inFile:
    rawData = inFile.read()
data = rawData.replace('\t',' ')    
data = data.split('\n')

emissions = data[0]
emAlphabet = data[2].replace(' ','')
emDict = dict([(letter,i) for i, letter in enumerate(emAlphabet)])

states = data[4]
stAlphabet = data[6].replace(' ','')
stDict = dict([(letter,i) for i, letter in enumerate(stAlphabet)])

probMat = data[9:]
for letter in stAlphabet:
    probMat = [row.replace(letter,'') for row in probMat]
probMat = [row.split(' ') for row in probMat]
probMat = [[float(elem) for elem in row if len(elem) > 0] for row in probMat]

emissionProb = 1
for state,emission in zip(states, emissions):
    emissionProb = probMat[stDict[state]][emDict[emission]] * emissionProb
print(emissionProb)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).