我正在尝试使用该程序使用pyseqlogo在python中绘制序列徽标。该程序打开用户输入的文件,通过seqLength矩阵创建矩阵4,并输入for循环中发生的任何核苷酸量。 由于某些原因,我收到“如果line [i] ==“ A”:“行超出范围的错误。
import pyseqlogo
count=0.0
seqLength=0.0
file=input("Input file name: \n")#user input file name
seqfile= open(file,'r')#opens file
seqLength= len(seqfile.readline())-1 #Reads line from openend file
NT_c = [0]*4 #Creates slots for base nucleotide A,C,G,U
for i in range(4):
NT_c[i] = [0]*seqLength #Uses seqlength to make an "i" length for each NT_C
#Counting nucleotides from file lines
for line in seqfile: #For loop that will read line by line in file
line = line.upper() #Makes all input uppercase
for i in range(seqLength): #for loop to input data in matrix
if line[i]== "A":
NT_c[0][i] =NT_c[0][i]+1 #possition i will add one for each A in line
elif line[i]=="G":
NT_c[1][i]=NT_c[1][i]+1 #possition 1i adds a 1
elif line[i]=="C":
NT_c[2][i]=NT_c[2][i]+1
elif line[i]=="U":
NT_c[3][i]=NT_c[3][i]+1
elif line[i]=="-":
continue #skips positions with - value
else:
print("Error\n") #If none of these,there's a mistake
count=count+1