Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
include location for public samples
Browse files Browse the repository at this point in the history
  • Loading branch information
rpetit3 committed Nov 8, 2017
1 parent 6799357 commit cd889d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions api/queries/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_samples_by_tag(tag_id):
return query_database(sql)


def get_public_samples(is_published=False):
def get_public_samples(is_published=False, include_location=False):
"""Return sample info associated with a tag."""
sql = None
if is_published:
Expand All @@ -84,7 +84,15 @@ def get_public_samples(is_published=False):
results[row['sample_tag']]['pmid'].append(int(row['pmid']))

return [vals for k, vals in results.items()]

elif include_location:
sql = """SELECT p.sample_id, is_paired, is_public, is_published,
sample_tag, st_original, st_stripped,
st_is_exact_match, pmid, location, region, country
FROM published_ena_samples AS p
LEFT JOIN sample_metadata AS m
ON p.sample_id=m.sample_id
WHERE m.location <> 'unknown/missing';"""
return query_database(sql)
else:
return query_database('SELECT * FROM public_ena_samples;')

Expand Down
7 changes: 5 additions & 2 deletions api/viewsets/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ def list(self, request):
@list_route(methods=['get'])
def public(self, request):
"""Return all public ENA samples."""
samples = get_public_samples()

samples = None
if 'include_location' in request.GET:
samples = get_public_samples(include_location=True)
else:
samples = get_public_samples()
return self.paginate(samples, page_size=500, is_serialized=True)

@list_route(methods=['get'])
Expand Down

0 comments on commit cd889d8

Please sign in to comment.