Skip to content

Instantly share code, notes, and snippets.

@flashton2003
Created January 6, 2016 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flashton2003/336e67bbc513b0cf3f07 to your computer and use it in GitHub Desktop.
Save flashton2003/336e67bbc513b0cf3f07 to your computer and use it in GitHub Desktop.
import ftplib
# ftp://ftp.sra.ebi.ac.uk/vol1/fastq/ERR038/ERR038787/ERR038787_1.fastq.gz
todo_list = ['ERR024633'] # ERR accessions
target_dir = '/where/you/want/the/data'
def download_from_ena(todo_list, target_dir):
ftp = ftplib.FTP('ftp.sra.ebi.ac.uk')
ftp.login()
ftp.cwd('vol1')
ftp.cwd('fastq')
for each in todo_list:
initial = each[0:6]
ftp.cwd(initial)
ftp.cwd(each)
with open('%s/%s_1.fastq.gz' % (target_dir, each), 'wb') as f1:
with open('%s/%s_2.fastq.gz' % (target_dir, each), 'wb') as f2:
ftp.retrbinary('RETR %s_1.fastq.gz' % each, f1.write)
ftp.retrbinary('RETR %s_2.fastq.gz' % each, f2.write)
download_from_ena(todo_list, target_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment