From cdbe165dd5743d7b5fe41b01f9083b6c39f43490 Mon Sep 17 00:00:00 2001 From: Guillaume Poirier-Morency Date: Fri, 17 May 2024 12:43:05 -0700 Subject: [PATCH] Fix rename of GemmaTask to GemmaTaskMixin and GemmaCliTask --- rnaseq_pipeline/webviewer/__init__.py | 23 ++++++++++++++++++----- tests/test_gemma.py | 2 +- tests/test_tasks.py | 6 +++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/rnaseq_pipeline/webviewer/__init__.py b/rnaseq_pipeline/webviewer/__init__.py index a2701272..fda48d99 100644 --- a/rnaseq_pipeline/webviewer/__init__.py +++ b/rnaseq_pipeline/webviewer/__init__.py @@ -9,7 +9,7 @@ from rnaseq_pipeline.config import rnaseq_pipeline from rnaseq_pipeline.tasks import GenerateReportForExperiment, CountExperiment, ExtractGeoSeriesBatchInfo, SubmitExperimentDataToGemma, SubmitExperimentBatchInfoToGemma -from rnaseq_pipeline.gemma import GemmaTask +from rnaseq_pipeline.gemma import GemmaTaskMixin app = Flask('rnaseq_pipeline.webviewer') @@ -17,6 +17,9 @@ references = ['hg38_ncbi', 'mm10_ncbi', 'm6_ncbi'] +class FakeGemmaTask(GemmaTaskMixin, luigi.Task): + pass + @app.errorhandler(400) def bad_request(e): return render_template('400.html', e=e), 400 @@ -63,13 +66,18 @@ def experiment_batch_info(experiment_id): @app.route('/experiment//by-reference-id//quantifications/') def experiment_quantifications(experiment_id, mode, reference_id=None): if reference_id is None: - gemma_task = GemmaTask(experiment_id) + gemma_task = FakeGemmaTask(experiment_id) reference_id = gemma_task.reference_id + taxon = gemma_task.taxon + source = 'gemma' + else: + taxon = 'human' + source = 'local' try: mode_ix = ['counts', 'fpkm'].index(mode) except ValueError: abort(400, f'Unknown mode {mode} for quantifications, try either counts or fpkm.') - count_experiment_task = CountExperiment(experiment_id, reference_id=reference_id, taxon=None) + count_experiment_task = CountExperiment(experiment_id, reference_id=reference_id, taxon=taxon, source=source) if not count_experiment_task.complete(): abort(404, f'No quantifications available for {experiment_id} in {reference_id}.') file_path = count_experiment_task.output()[mode_ix].path @@ -79,9 +87,14 @@ def experiment_quantifications(experiment_id, mode, reference_id=None): @app.route('/experiment//by-reference-id//report') def experiment_report(experiment_id, reference_id=None): if reference_id is None: - gemma_task = GemmaTask(experiment_id) + gemma_task = FakeGemmaTask(experiment_id) reference_id = gemma_task.reference_id - generate_report_task = GenerateReportForExperiment(experiment_id, reference_id=reference_id, taxon=None) + taxon = gemma_task.taxon + source = 'gemma' + else: + taxon = 'human' + source = 'local' + generate_report_task = GenerateReportForExperiment(experiment_id, reference_id=reference_id, taxon=taxon, source=source) if not generate_report_task.complete(): abort(404, f'No report available for {experiment_id} in {reference_id}.') return send_file(generate_report_task.output().path) diff --git a/tests/test_gemma.py b/tests/test_gemma.py index 647d8ec7..00e11d0e 100644 --- a/tests/test_gemma.py +++ b/tests/test_gemma.py @@ -7,7 +7,7 @@ def test_gemma_api(): gemma_api.samples('GSE110256') def test_gemma_task(): - task = GemmaTask(experiment_id='GSE110256') + task = GemmaCliTask(experiment_id='GSE110256') env = task.program_environment() assert 'JAVA_OPTS' in env assert 'JAVA_HOME' in env diff --git a/tests/test_tasks.py b/tests/test_tasks.py index b2b2db07..2a11fe0a 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -1,6 +1,8 @@ import datetime import pytest +import luigi + from rnaseq_pipeline.config import rnaseq_pipeline from rnaseq_pipeline.tasks import * @@ -42,7 +44,9 @@ def test_align_sample_task(): assert task.output().path == join(cfg.OUTPUT_DIR, cfg.ALIGNDIR, 'hg38_ncbi', 'GSE', 'GSM.genes.results') assert task.walltime == datetime.timedelta(days=1) -def test_gemma_task(): +def test_gemma_task_mixin(): + class GemmaTask(GemmaTaskMixin, luigi.Task): + pass gemma_task = GemmaTask('GSE110256') assert gemma_task.taxon == 'mouse' assert gemma_task.accession == 'GSE110256'