Skip to content

Commit

Permalink
Added endpoint to lookup samples based on sequencer run id search
Browse files Browse the repository at this point in the history
  • Loading branch information
BasMonkey committed May 31, 2024
1 parent 67b93d2 commit 15bbea3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
28 changes: 27 additions & 1 deletion ExonCov/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_sample_by_sample_name_api(sample_name):

@app.route('/api/samples/run/id/<int:run_id>')
@token_required
def get_summary_by_run_id_api(run_id):
def get_summary_by_run_db_id_api(run_id):
"""
Look up samples by its run database ID
Expand All @@ -160,3 +160,29 @@ def get_summary_by_run_id_api(run_id):
samples_list = generate_not_found_dict()

return jsonify(samples_list)


@app.route('/api/samples/run/seqid/<string:seq_run_id>')
@token_required
def get_summary_by_run_seq_id_api(seq_run_id):
"""
Look up samples by its sequencer run ID
Args:
run_id (str): run sequencer id
Returns:
A list of sample as a JSON object if there are any found in the database
"""
samples = get_sample_by_like_run_id(seq_run_id)
samples_list = []

for sample in samples:
sample = model_to_dict(sample)
sample.pop("import_command")
samples_list.append(sample)

if len(samples_list) == 0:
samples_list = generate_not_found_dict()

return jsonify(samples_list)
15 changes: 14 additions & 1 deletion ExonCov/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,20 @@ def get_sample_by_like_run_id(run_id):
.options(joinedload(Sample.project))
)

samples = samples.filter(SequencingRun.id.like('%{0}%'.format(run_id)))
samples = samples.filter(SequencingRun.platform_unit.like('%{0}%'.format(run_id)))
return samples


def get_sample_by_like_run_db_id(run_id):
samples = (
Sample.query
.order_by(Sample.import_date.desc())
.order_by(Sample.name.asc())
.options(joinedload(Sample.sequencing_runs))
.options(joinedload(Sample.project))
)

samples = samples.filter(SequencingRun.id == run_id)
return samples


Expand Down

0 comments on commit 15bbea3

Please sign in to comment.