Python: 如何根据得到的最大值输出变量?
Python: How to output the variable based on the maximum value obtained?
我有一个 DNA 序列列表,如下所示。我想获得在该特定位置获得的最高频率的共识序列。
test.txt
>human
ATCAATTGCT
>human
GCTAGCTAGC
>human
GCTAGCTAGC
>human
GCTGATCGGC
>human
GCTTACAACG
使用下面的代码,我从每个位置获得总的 A、C、G 和 T。
代码
from Bio import motifs
output=open("test_output.txt","a")
with open("test.txt") as handle:
motif = motifs.read(handle, 'sites')
output.write(str(motif.counts))
示例输出
0 1 2 3 4 5 6 7 8 9
A: 1.00 0.00 0.00 3.00 3.00 0.00 1.00 3.00 0.00 0.00
C: 0.00 4.00 1.00 0.00 0.00 3.00 1.00 0.00 2.00 3.00
G: 4.00 0.00 0.00 1.00 2.00 0.00 0.00 2.00 3.00 1.00
T: 0.00 1.00 4.00 1.00 0.00 2.00 3.00 0.00 0.00 1.00
如何获得最后一列中每个碱基的输出?
期望输出
0 1 2 3 4 5 6 7 8 9
A: 1.00 0.00 0.00 3.00 3.00 0.00 1.00 3.00 0.00 0.00
C: 0.00 4.00 1.00 0.00 0.00 3.00 1.00 0.00 2.00 3.00
G: 4.00 0.00 0.00 1.00 2.00 0.00 0.00 2.00 3.00 1.00
T: 0.00 1.00 4.00 1.00 0.00 2.00 3.00 0.00 0.00 1.00
G C T A A C T A G C
Motifs 有一个完全符合您要求的共识方法:
output.write("\t".join(list(motif.consensus)))
我有一个 DNA 序列列表,如下所示。我想获得在该特定位置获得的最高频率的共识序列。
test.txt
>human
ATCAATTGCT
>human
GCTAGCTAGC
>human
GCTAGCTAGC
>human
GCTGATCGGC
>human
GCTTACAACG
使用下面的代码,我从每个位置获得总的 A、C、G 和 T。
代码
from Bio import motifs
output=open("test_output.txt","a")
with open("test.txt") as handle:
motif = motifs.read(handle, 'sites')
output.write(str(motif.counts))
示例输出
0 1 2 3 4 5 6 7 8 9
A: 1.00 0.00 0.00 3.00 3.00 0.00 1.00 3.00 0.00 0.00
C: 0.00 4.00 1.00 0.00 0.00 3.00 1.00 0.00 2.00 3.00
G: 4.00 0.00 0.00 1.00 2.00 0.00 0.00 2.00 3.00 1.00
T: 0.00 1.00 4.00 1.00 0.00 2.00 3.00 0.00 0.00 1.00
如何获得最后一列中每个碱基的输出?
期望输出
0 1 2 3 4 5 6 7 8 9
A: 1.00 0.00 0.00 3.00 3.00 0.00 1.00 3.00 0.00 0.00
C: 0.00 4.00 1.00 0.00 0.00 3.00 1.00 0.00 2.00 3.00
G: 4.00 0.00 0.00 1.00 2.00 0.00 0.00 2.00 3.00 1.00
T: 0.00 1.00 4.00 1.00 0.00 2.00 3.00 0.00 0.00 1.00
G C T A A C T A G C
Motifs 有一个完全符合您要求的共识方法:
output.write("\t".join(list(motif.consensus)))