我试图编写一个需要输出为矩阵的代码,但由于是新手,我没有正确理解它。基本上我想为每列的A,C,G,T生成一个计数矩阵。我能够做到这一点,但很难为其他专栏做。如何在python中填充矩阵
输入文件
>Rosalind_1
ATCCAGCT
>Rosalind_2
GGGCAACT
>Rosalind_3
ATGGATCT
>Rosalind_4
AAGCAACC
>Rosalind_5
TTGGAACT
>Rosalind_6
ATGCCATT
>Rosalind_7
ATGGCACT
到目前为止我的代码
fh_in = open("consensus_seq.txt", 'r')
A_count = 0
C_count = 0
G_count = 0
T_count = 0
result = []
for line in fh_in:
line = line.strip()
if not line.startswith(">"):
for nuc in line[0]:
if nuc == "A":
A_count += 1
if nuc == "C":
C_count += 1
if nuc == "G":
G_count += 1
if nuc == "T":
T_count += 1
result.append(A_count)
result.append(C_count)
result.append(G_count)
result.append(T_count)
print result
输出
[5, 0, 1, 1]
我想要的实际产量
A 5 1 0 0 5 5 0 0
C 0 0 1 4 2 0 6 1
G 1 1 6 3 0 1 0 0
T 1 5 0 0 0 1 1 6
任何帮助/提示表示赞赏。
这是如此简单。谢谢.... – upendra 2014-11-07 20:20:27