如何计算文件中的std dev

时间:2014-03-23 04:39:32

标签: python standard-deviation

我有这样的输入文件

@a
CTCTCTTTAGAACAATCATCACATACCCCTGGTT
+
1>1A>FDF3113B11BB1BAED1D11BAEE0ABG
@b
CAATGCAGCGAACAATGTTCTGGTGGTTGAATTT
+
111>1@11C?1AE?BFDGGGGGBGCCGGGGHHHH
....

我计算了此文件中的平均质量分数,但在计算标准时需要帮助 该分数的偏差

这里我做了什么

import sys,csv
import numpy as np
import math

r = open(sys.argv[1],"r")

length =200
a = np.zeros(length)
b = np.zeros(length)
av = np.zeros(length)

while True:
    id = reads.readline().rstrip()
    if id == "":
       break
    seq= r.readline().rstrip()
    p = r.readline().rstrip()
    qua = r.readline().rstrip()
    l= len(qua)
    q = [ord(character) - 33 for character in qua]
    for i in range(l):
        a[i] += q[i]
        b[i] += 1

for j in range(length):
     av[j] = float(a[j]) / b[j]
     s2 = sum((x - av[j])**2  for x in q[i])/b[j] # error in this
     standard_deviation = s2**0.5
     print standard_deviation

1 个答案:

答案 0 :(得分:0)

这个怎么样?

import sys,csv
import numpy as np
import math

r = open(sys.argv[1],"r")

while True:
    id = reads.readline().rstrip()
    if id == "":
       break
    seq= r.readline().rstrip()
    p = r.readline().rstrip()
    qua = r.readline().rstrip()
    q = [ord(character) - 33 for character in qua]

    mean = np.mean(q)
    standard_deviation = np.std(q)