-
Notifications
You must be signed in to change notification settings - Fork 0
/
emblebi_ena_report_download.py
executable file
·65 lines (53 loc) · 2.63 KB
/
emblebi_ena_report_download.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/env python
__author__ = 'Paul Sarando'
import config.emblebi_ena_submit_properties
from argparse import ArgumentParser
from subprocess import call
class BioProjectReportDownloader:
def __init__(self, ascp_cmd, private_key_path, ncbi_user, ncbi_host, ncbi_sumbit_path):
self.ascp_cmd = ascp_cmd
self.private_key_path = private_key_path
self.report_src = '{0}@{1}:{2}'.format(ncbi_user, ncbi_host, ncbi_sumbit_path)
def download_report(self, sumbit_dir, download_dest):
report_xml = '{0}/{1}/report.xml'.format(self.report_src, sumbit_dir)
ascp_cmd = self.ascp_cmd + [
"-i", self.private_key_path,
report_xml,
download_dest
]
try:
retcode = call(ascp_cmd)
if retcode != 0:
raise Exception("Download error: {0}".format(-retcode))
except OSError as e:
raise Exception("Aspera Connect download failed", e)
usage = """
ncbi_sra_report_download.py [-i <PRIVATE_KEY_PATH>] -s <SRC_SUBMIT_DIR> -d <DOWNLOAD_OUTPUT_DIR>
"""
desc = """
Downloads a report.xml file from the NCBI Sequence Read Archive (SRA).
"""
# Parse the command-line options.
parser = ArgumentParser(usage = usage, description = desc, add_help = False)
parser.add_argument('-i', '--private-key', dest = 'private_key_path',
default = config.ncbi_sra_submit_properties.private_key_path,
help = '(optional) specify an alternative path to the id_rsa'
' private-key file.')
parser.add_argument('-s', '--submit-dir', dest = 'submit_dir',
required = True,
help = 'specify the name of the BioProject SRA submission'
' folder where the report.xml file is located.')
parser.add_argument('-d', '--output-dir', dest = 'output_dir',
default = ".",
help = 'specify the path to the output directory where the SRA'
' report.xml file will be downloaded.')
parser.add_argument('-?', '--help', action = 'help')
args = parser.parse_args()
# Define the objects we need.
downloader = BioProjectReportDownloader(config.ncbi_sra_submit_properties.ascp_cmd,
args.private_key_path,
config.ncbi_sra_submit_properties.ncbi_user,
config.ncbi_sra_submit_properties.ncbi_host,
config.ncbi_sra_submit_properties.ncbi_sumbit_path)
# Download the SRA report
downloader.download_report(args.submit_dir, args.output_dir)