diff --git a/ExonCov/api_views.py b/ExonCov/api_views.py index 78bc76d..1daab29 100644 --- a/ExonCov/api_views.py +++ b/ExonCov/api_views.py @@ -138,7 +138,7 @@ def get_sample_by_sample_name_api(sample_name): @app.route('/api/samples/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 @@ -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/') +@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) diff --git a/ExonCov/services.py b/ExonCov/services.py index 4e363fd..687cd51 100644 --- a/ExonCov/services.py +++ b/ExonCov/services.py @@ -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