def download_with_sra_prefetch(aspera_key, outdir, pickle_prefix, ena_id): command = ['prefetch', '', ena_id] if aspera_key is not None: _, ascp, _ = utils.run_command_popen_communicate(['which', 'ascp'], False, None, False) command[1] = '-a {ascp}|{aspera_key}'.format(ascp=ascp.splitlines()[0], aspera_key=aspera_key) run_successfully, stdout, stderr = utils.run_command_popen_communicate(command, False, 3600, True) if run_successfully: _, prefetch_outdir, _ = utils.run_command_popen_communicate(['echo', '$HOME/ncbi/public/sra'], True, None, False) try: os.rename(os.path.join(prefetch_outdir.splitlines()[0], ena_id + '.sra'), os.path.join(outdir, ena_id + '.sra')) except OSError as e: print('Found the following error:' '{}'.format(e)) from shutil import copy as shutil_copy shutil_copy(os.path.join(prefetch_outdir.splitlines()[0], ena_id + '.sra'), os.path.join(outdir, ena_id + '.sra')) os.remove(os.path.join(prefetch_outdir.splitlines()[0], ena_id + '.sra')) utils.save_variable_to_pickle(run_successfully, outdir, pickle_prefix + '.' + ena_id)
def gzip_files(file_2_compress, pickle_prefix, outdir): if file_2_compress.endswith('.temp'): out_file = os.path.splitext(file_2_compress)[0] else: out_file = file_2_compress command = ['gzip', '--stdout', '--best', file_2_compress, '>', str(out_file + '.gz')] run_successfully, stdout, stderr = utils.run_command_popen_communicate(command, True, None, True) if run_successfully: os.remove(file_2_compress) utils.save_variable_to_pickle(run_successfully, outdir, str(pickle_prefix + '.' + os.path.basename(file_2_compress)))
def download_with_aspera(aspera_file_path, aspera_key, outdir, pickle_prefix, sra, ena_id): command = ['ascp', '-QT', '-l', '300m', '', '-i', aspera_key, '', outdir] if not sra: command[4] = '-P33001' command[7] = str('era-fasp@' + aspera_file_path) pickle = pickle_prefix + '.' + aspera_file_path.rsplit('/', 1)[1] else: command[7] = '[email protected]:/sra/sra-instant/reads/ByRun/sra/{a}/{b}/{c}/{c}.sra'.format( a=ena_id[:3], b=ena_id[:6], c=ena_id) pickle = pickle_prefix + '.' + ena_id run_successfully, stdout, stderr = utils.run_command_popen_communicate(command, False, 3600, True) utils.save_variable_to_pickle(run_successfully, outdir, pickle)
def download_with_curl(ftp_file_path, outdir, pickle_prefix, sra, ena_id): command = ['curl', '--retry', '1', '', '-o', ''] if not sra: command[3] = ftp_file_path file_download = ftp_file_path.rsplit('/', 1)[1] command[5] = os.path.join(outdir, file_download) pickle = pickle_prefix + '.' + file_download else: command[3] = 'ftp://ftp-trace.ncbi.nih.gov/sra/sra-instant/reads/ByRun/sra/{a}/{b}/{c}/{c}.sra'.format( a=ena_id[:3], b=ena_id[:6], c=ena_id) command[5] = os.path.join(outdir, ena_id + '.sra') pickle = pickle_prefix + '.' + ena_id run_successfully, stdout, stderr = utils.run_command_popen_communicate(command, False, 3600, True) utils.save_variable_to_pickle(run_successfully, outdir, pickle)