【发布时间】:2018-07-24 05:41:09
【问题描述】:
我有几个 fastq 文件,平均有 500.000.000 行(125.000.000 个序列)。有没有一种快速的方法可以更快地读取这些 fastq 文件。
我想做的是读取每个序列并将前 16 个序列用作条形码。然后统计每个文件中的条码数量。
这是我的脚本,需要几个小时:
import os, errno
from Bio import SeqIO
import gzip
files = os.listdir(".")
for file in files[:]:
if not file.endswith(".fastq.gz"):
files.remove(file)
maps = {}
for file in files:
print "Now Parsing file %s"%file
maps[file] = {}
with gzip.open(file,"r") as handle:
recs = SeqIO.parse(handle,"fastq")
for rec in recs:
tag = str(rec.seq)[0:16]
if tag not in map[file]:
maps[file][tag] = 1
else:
maps[file][tag] += 1
我有 250 GB RAM 和 20 个可用于多线程的 CPU ...
谢谢。
【问题讨论】:
-
您是否已经像 this question 那样对将 fastq 文件解析为 Pandas 进行了基准测试?如果这是可行的,那么我可以想出几种方法来简化这个过程。
标签: python multithreading multiprocessing fastq