2016-09-28 13 views
-1

私は長い文字列を持っている場合、その文字列内で与えられた長さの単語を見つける確率をどのように計算するのですか?文字列内の単語の確率を見つける

import math 
from scipy import stats 

alphabet = list("ATCG") # This is the alphabet I am working with 
string = "AATCAGTAGATCG" # Here are two example strings 
string2 = "TGTAAACCTTGGTTTATCG" 
word = "ATCG" # This is my word 

n_substrings = len(string) - len(word) # The number of possible substrings 
n_substrings2 = len(string2) - len(word) 

prob_match = math.pow(len(alphabet), - len(word)) # The probability of randomly choosing the word from the alphabet 

# Get the probability from a binomial test? 
print stats.binom_test(1, n_substrings, p=prob_match) # (Number of successes, number of trials, prob of success) 
print stats.binom_test(1, n_substrings2, p=prob_match) 

>>>0.0346119111615 
    0.0570183821615 

これは、これを行うためにまたは私は何かが足りないのです適切な方法です:

は、これまでのところ私はこれを持っていますか?

+0

なぜダウン投票してください! – kezzos

答えて

1

私は、あなたがすべきだと思う:5文字の文字列で

n_substrings = len(string) - len(word) +1 

を、あなたは2つのオプションを持っているサブストリング4文字で: ATCGAはATCGとTCGAを保持することができます

+0

ありがとう、それは基本的なエラーでした。 – kezzos

関連する問題