Skip to content

Instantly share code, notes, and snippets.

@althonos
Created August 2, 2018 09:55
Show Gist options
  • Save althonos/0041c80f645f8a06b3cc6c6c5de14738 to your computer and use it in GitHub Desktop.
Save althonos/0041c80f645f8a06b3cc6c6c5de14738 to your computer and use it in GitHub Desktop.
MTBLS dump script through FTP
# coding: utf-8
from __future__ import unicode_literals
from __future__ import print_function
import io
import ftplib
import posixpath
ftp = ftplib.FTP("ftp.ebi.ac.uk")
ftp.connect()
ftp.login()
base = "/pub/databases/metabolights/studies/public/"
ftp.cwd(base)
studies = [x for x in ftp.nlst() if x.startswith('MTBLS')]
for i, study in enumerate(sorted(studies)):
print("Study:", "{}".format(study).rjust(8), "[{}/{}]".format(i+1, len(studies)), end=" ")
ftp.cwd(posixpath.join(base, study))
mzml_files = [x for x in ftp.nlst() if x.lower().endswith('.mzml')]
print(len(mzml_files), "mzML files")
if mzml_files:
with open(mzml_files[0], 'wb') as dst:
ftp.retrbinary("RETR {}".format(mzml_files[0]), dst.write)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment