Commit 9bc89054 authored by Thomas Van Parys's avatar Thomas Van Parys
Browse files

plaza api ftp returns latest version and adds version option (fixes #56)

parent 765b2492
......@@ -16,24 +16,33 @@ def get_plaza_data():
return j
def get_ftp_url(species, data_type):
def get_ftp_url(species, data_type, version=None):
Retrieves an FTP link from the Plaza API.
:param species: Plaza id
:param data_type: Which download link to return (annot/fasta/cds)
:param version: the version identifier of the genome (by default the latest one is selected)
:returns: A string with the FTP link or None if species not found.
j = get_plaza_data()
hit = None
for entry in j:
if entry['species'] == species:
if ((version is None
and (hit is None or int(entry['year']) > int(hit['year'])))
or (version == entry['version'])):
hit = entry
if hit is None:
return None
if data_type == 'annot':
return entry['csv'][0]['location']
return hit['csv'][0]['location']
if data_type == 'prot':
return entry['fasta']['proteome'][0]['location']
return hit['fasta']['proteome'][0]['location']
if data_type == 'cds':
return entry['fasta']['cds'][0]['location']
return None
return hit['fasta']['cds'][0]['location']
def find_species(needle, all=True):
......@@ -125,9 +134,14 @@ def list():
'--type', '-t', 'data_type',
help="Type of data we need the ftp link for (annot/prot/cds)"
help="Type of data we need the ftp link for (annot/prot/cds) (default: annot)"
'--version', '-v', 'version',
help="Genome version identifier"
def ftp(species, data_type):
def ftp(species, data_type, version):
Get Plaza FTP URLs for given species.
......@@ -137,7 +151,7 @@ def ftp(species, data_type):
ftp_url = get_ftp_url(species, data_type)
ftp_url = get_ftp_url(species, data_type, version)
if not ftp_url:
print("Error: Species abbrevation unknown: {}".format(species), file=sys.stderr)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment