-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsra.py
25 lines (19 loc) · 866 Bytes
/
sra.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from pathlib import Path
import subprocess
class SequenceReadArchive:
def __init__(self, accession, outdir):
self.accession = accession
self.outdir = outdir
self.url = None
self.sra_file = Path(self.outdir, self.accession + '.sra')
def make_url(self):
url = 'ftp://ftp.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByRun/sra/{}/{}/{}/{}'.format(
self.accession[0:3], self.accession[0:6], self.accession, self.accession + '.sra')
self.url = url
def download(self):
subprocess.call(['wget', self.url, '-O', self.sra_file], stderr=subprocess.DEVNULL)
def split(self, fastq_dir):
cmd = ["fastq-dump", self.sra_file, '--outdir', fastq_dir, '--split-files', '--gzip']
subprocess.call(cmd, stdout=subprocess.DEVNULL)
def remove(self):
Path.unlink(self.sra_file)