update PROB
This commit is contained in:
parent
222e3ee447
commit
389773d411
@ -4,39 +4,44 @@ Solutions to the PROB Rosalind Problem - Introduction to Random Strings
|
|||||||
Author: Peter Vlasveld
|
Author: Peter Vlasveld
|
||||||
Date: 20190222
|
Date: 20190222
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
#Read in file content into list
|
# Read in file content into list
|
||||||
f1 = open("rosalind_prob.txt")
|
f1 = open("rosalind_prob.txt")
|
||||||
content = f1.readlines()
|
content = f1.readlines()
|
||||||
f1.close()
|
f1.close()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Function to calculate the probability of the exact sequence given the GC-content
|
Function to calculate the probability of the exact sequence given the
|
||||||
|
GC-content
|
||||||
@param gc - the GC-content given
|
@param gc - the GC-content given
|
||||||
@param seq - the sequence being studied
|
@param seq - the sequence being studied
|
||||||
|
|
||||||
@return - the raw probability value
|
@return - the raw probability value
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def calcProb(gc, seq):
|
def calcProb(gc, seq):
|
||||||
# get probability for just one nucleotide
|
# get probability for just one nucleotide
|
||||||
gchalf = gc/2.0
|
gchalf = gc / 2.0
|
||||||
athalf = (1.0-gc)/2.0
|
athalf = (1.0 - gc) / 2.0
|
||||||
|
|
||||||
# multiply all of the probability values for each letter in the sequence
|
# multiply all of the probability values for each letter in the sequence
|
||||||
prob = 1.0
|
prob = 1.0
|
||||||
for i in range(0, len(seq)):
|
for i in range(0, len(seq)):
|
||||||
if seq[i] == 'A' or seq[i] == 'T':
|
if seq[i] == "A" or seq[i] == "T":
|
||||||
prob *= athalf
|
prob *= athalf
|
||||||
elif seq[i] == 'G' or seq[i] == 'C':
|
elif seq[i] == "G" or seq[i] == "C":
|
||||||
prob *= gchalf
|
prob *= gchalf
|
||||||
|
|
||||||
# return the probability value
|
# return the probability value
|
||||||
return prob
|
return prob
|
||||||
|
|
||||||
|
|
||||||
# take the log of the probabilities returned by calcProb
|
# take the log of the probabilities returned by calcProb
|
||||||
# format them to 3 decimal places
|
# format them to 3 decimal places
|
||||||
gcCons = content[1].split( )
|
gcCons = content[1].split()
|
||||||
finalProbs = []
|
finalProbs = []
|
||||||
for i in gcCons:
|
for i in gcCons:
|
||||||
rawProb = calcProb(float(i), content[0])
|
rawProb = calcProb(float(i), content[0])
|
||||||
@ -44,3 +49,4 @@ for i in gcCons:
|
|||||||
|
|
||||||
# print the probabilities with spaces in between
|
# print the probabilities with spaces in between
|
||||||
print(" ".join(finalProbs))
|
print(" ".join(finalProbs))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user