我写了一段代码IDS.txt文件“是一个制表符删除的文本文件,它以下面给出的方式包含ID,其中第一列表示ID,第二列表示起始索引,第三列表示结束索引。你知道吗
IDs.txt-------
““完成.txt““
我所写的脚本给出了根据IDs.txt文件“它正在NOT
工作。请帮助我更正代码应该做什么更改
with open("\Users\Zebrafish\Desktop\IDs.txt") as f: # will get input from the text
for line in f:
c = line.split("\t")
for i, x in enumerate(c): #passing values to start and end variables
if i == 1:
start = x
elif i == 2:
end = x
elif i == 0:
gene_name = x
infile = open("/Users/Zebrafish/Desktop/complete.txt") #file to get large string data
for seq in infile:
seqnew = seq.split("\t") # get data as single line
retrived = seqnew[int(start):int(end)] #retrieve fragment
print retrived
3MB不是很大(在可以运行Windows的计算机上)。只需将第二个文件作为单个字符串加载到内存中,即可获得片段:
如果
complete.txt
文件不适合内存,可以使用mmap
以字节序列的形式访问其内容,而无需将整个文件加载到内存中:我不知道你为什么要在
\t
上拆分你的complete.txt
文件,下面是你的代码优化:删除行:
只要做:
会得到你想要的子串。你知道吗
然后你就可以:
相关问题 更多 >
编程相关推荐