有人能给我解释一些具体的行语法吗(不长,只有3行)对于这个,它是用来为字典创建一个定义,并使用namehold从包含fastas序列的文件中写入的:
我听不懂的台词是没有#
def getfasta(file): #creating the definition
nameHandle=open('fastas.txt,'r') #(this is for opening the file that we're gonna use)
fastas={} #I know it means my dictionnary name
for line in nameHandle: #I know what it means
if line [0]=='>': #(it's beacause each first line in a fasta seq starts with > )
header=line[1:] #(Starting this line I can't understand a thing)
fastas[header]=''
else:
fastas[header]+=line[:-1]
nameHandle.close() #closing the package
return(fastas) #gives us the dictionary with the keys and all of content
所以发生的是这样的:文件被逐行读取。我假设第一行以“>;”开头。该行的其余部分(我们称之为“第一个条目”)作为字典的键。然后将以下行附加到关联的值。当您到达以“>;”开头的另一行时,它作为一个新的键,下面的行附加在一个新的值中
使用以下示例:
由此产生的字典是:
相关问题 更多 >
编程相关推荐