Skip to content

Instantly share code, notes, and snippets.

@crazyhottommy
Forked from hiraksarkar/ebi_url_from_srr.py
Created February 22, 2018 17:04
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 crazyhottommy/7fb431a179a044dbd78077abef91ba58 to your computer and use it in GitHub Desktop.
Save crazyhottommy/7fb431a179a044dbd78077abef91ba58 to your computer and use it in GitHub Desktop.
#API created by @apfejes (Anthony Fejes) on top of my half-cooked script
#python ebi_url_from_srr.py --file srr_list.txt | xargs -I {} wget {}
import argparse
def prepareURL(srr_name, prefix="ftp://ftp.sra.ebi.ac.uk/vol1/fastq/"):
dir_1=srr_name[:6]
dir_2=""
url=""
num_digits=sum(s.isdigit() for s in srr_name)
if(num_digits == 6):
url=prefix+dir_1+"/"+srr_name+"/"
elif(num_digits == 7):
dir_2="00"+srr_name[-1]
url=prefix+dir_1+"/"+dir_2+"/"+srr_name+"/"
elif(num_digits == 8):
dir_2="0"+srr_name[-2:]
url=prefix+dir_1+"/"+dir_2+"/"+srr_name+"/"
elif(num_digits == 9):
dir_2=srr_name[-3:]
url=prefix+dir_1+"/"+dir_2+"/"+srr_name+"/"
return url
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--SRR', help='SRR name to be parsed')
parser.add_argument('--file', help='file containing SRR name to be parsed')
args = parser.parse_args()
if args.file:
with open(args.file) as srr_file:
for line in srr_file:
url = prepareURL(line.strip())
print("{}*.fastq.gz".format(url))
else:
url = prepareURL(args.SRR)
print("{}*.fastq.gz".format(url))
if __name__ == '__main__':
main()
@crazyhottommy
Copy link
Author

check this gist as well https://gist.github.com/crazyhottommy/b9f6ee0122538b69876fad090cb7211b to understand how the fastqs are organized in the portal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment