除了代码中已有的之外,我还尝试使用 newString.strip('\n') ,但它没有做任何事情。我正在输入一个不应该有问题的 .fasta 文件。提前致谢。
def createLists(fil3):
f = open(fil3, "r")
text = f.read()
listOfSpecies = []
listOfSequences = []
i = 0
check = 0
while (check != -1):
startIndex = text.find(">",i)
endIndex = text.find("\n",i)
listOfSpecies.append(text[startIndex+1:endIndex])
if(text.find(">",endIndex) != -1):
i = text.find(">",endIndex)
newString = text[endIndex+1: i]
newString.strip()
newString.splitlines()
listOfSequences.append(newString)
else:
newString = text[endIndex+1:]
newString.strip()
newString.strip('\n')
listOfSequences.append(newString)
return (listOfSpecies,listOfSequences)
def cluster(fil3):
print createLists(fil3)
cluster("ProteinSequencesAligned.fasta")