Skip to content

Commit

Permalink
* delete tmp files after copy
Browse files Browse the repository at this point in the history
* better detection of sra file args
  • Loading branch information
rvalieris committed Jan 13, 2020
1 parent fcddfa0 commit db06b67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Protips
* All extra arguments will be passed directly to ``fastq-dump``, ``--gzip``, ``--split-files`` and filters works as expected.
* This tool is **not** a replacement, you still need ``fastq-dump`` and ``sra-stat`` on your ``PATH`` for it to work properly.
* Speed improvements are better with bigger files, think at least 200k reads/pairs for each thread used.
* Mind the disk usage, you will need about double the space compared to a normal ``fastq-dump`` run.

Install
-------
Expand Down
15 changes: 11 additions & 4 deletions parallel-fastq-dump
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tempfile
import subprocess
import argparse

__version__ = "0.6.5"
__version__ = "0.6.6"

def pfd(args, srr_id, extra_args):
tmp_dir = tempfile.TemporaryDirectory(prefix="pfd_",dir=args.tmpdir)
Expand Down Expand Up @@ -43,6 +43,7 @@ def pfd(args, srr_id, extra_args):
wfd[fo] = open(os.path.join(args.outdir,fo), "wb")
with open(os.path.join(tmp_path,fo), "rb") as fd:
shutil.copyfileobj(fd, wfd[fo])
os.remove(os.path.join(tmp_path,fo))

def split_blocks(start, end, n_pieces):
total = (end-start+1)
Expand Down Expand Up @@ -73,6 +74,14 @@ def partition(f, l):
r[1].append(i)
return r

def is_sra_file(path):
f = os.path.basename(path)
if f.lower().endswith('.sra'): return True
if "SRR" in f.upper(): return True
if "ERR" in f.upper(): return True
if "DRR" in f.upper(): return True
return False

def main():
parser = argparse.ArgumentParser(description="parallel fastq-dump wrapper, extra args will be passed through")
parser.add_argument("-s","--sra-id", help="SRA id", action="append")
Expand All @@ -90,9 +99,7 @@ def main():
sys.exit(0)

elif args.sra_id:
extra_srrs, extra_args = partition(
lambda s: "SRR" in s.upper() or s.lower().endswith('.sra'),
extra)
extra_srrs, extra_args = partition(is_sra_file,extra)
args.sra_id.extend(extra_srrs)
sys.stderr.write("SRR ids: {}\n".format(args.sra_id))
sys.stderr.write("extra args: {}\n".format(extra_args))
Expand Down

0 comments on commit db06b67

Please sign in to comment.