diff --git a/CHANGELOG.md b/CHANGELOG.md index b7e8e54068..5c13641d7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ About changelog [here](https://keepachangelog.com/en/1.0.0/) - Variants pagination after pressing "Filter variants" or "Clinical filter" - Layout of buttons Matchmaker submission panel (case page) - Removing cases from Matchmaker (simplified code and fixed functionality) +- Reintroduce check for missing alignment files purged from server ## [4.53] ### Added diff --git a/scout/server/blueprints/variant/controllers.py b/scout/server/blueprints/variant/controllers.py index 8b34b3380e..a79bddb727 100644 --- a/scout/server/blueprints/variant/controllers.py +++ b/scout/server/blueprints/variant/controllers.py @@ -1,4 +1,5 @@ import logging +import os from base64 import b64encode from datetime import date @@ -132,8 +133,13 @@ def has_rna_tracks(case_obj): # Display junctions track if available for any of the individuals for ind in case_obj.get("individuals", []): # Track contains 2 files and they should both be present - if all([ind.get("splice_junctions_bed"), ind.get("rna_coverage_bigwig")]): - return True + splicej_bed = ind.get("splice_junctions_bed") + rna_cov_bw = ind.get("rna_coverage_bigwig") + if None in [splicej_bed, rna_cov_bw]: + continue + if False in [os.path.exists(splicej_bed), os.path.exists(rna_cov_bw)]: + continue + return True return False diff --git a/scout/server/utils.py b/scout/server/utils.py index 916aaa292c..50981992f7 100644 --- a/scout/server/utils.py +++ b/scout/server/utils.py @@ -181,7 +181,8 @@ def case_has_alignments(case_obj): """ case_obj["bam_files"] = False # Availability of alignments for autosomal chromosomes for ind in case_obj.get("individuals"): - if ind.get("bam_file") and ind.get("bam_file") != "": + bam_path = ind.get("bam_file") + if bam_path and os.path.exists(bam_path): case_obj["bam_files"] = True return @@ -194,7 +195,8 @@ def case_has_mt_alignments(case_obj): """ case_obj["mt_bams"] = False # Availability of alignments for MT chromosome for ind in case_obj.get("individuals"): - if ind.get("mt_bam") and ind.get("mt_bam") != "": + mt_bam_path = ind.get("mt_bam") + if mt_bam_path and os.path.exists(mt_bam_path): case_obj["mt_bams"] = True return diff --git a/tests/server/blueprints/variant/test_variant_controllers.py b/tests/server/blueprints/variant/test_variant_controllers.py index 18476723af..332efb939f 100644 --- a/tests/server/blueprints/variant/test_variant_controllers.py +++ b/tests/server/blueprints/variant/test_variant_controllers.py @@ -84,16 +84,23 @@ def test_tx_overview(app): assert key in tx -def test_has_rna_tracks(case_obj): +def test_has_rna_tracks(case_obj, tmpdir): """Test the function that returns True if any individual of a case has RNA tracks available""" - # GIVEN a case with an individual with RNA tracks: + # GIVEN an individual with splice junctions bed file and rna coverage track + splicej_bed = tmpdir.join("test.bed") + rna_cov_bw = tmpdir.join("test.BigWig") + splicej_bed.write("content") + rna_cov_bw.write("content") + for ind in case_obj["individuals"]: if ind["phenotype"] == 1: # Lets's assume only the affected individuals has RNA data continue - ind["splice_junctions_bed"] = "test.bed" - ind["rna_coverage_bigwig"] = "test.BigWig" + ind["splice_junctions_bed"] = str(splicej_bed) + ind["rna_coverage_bigwig"] = str(rna_cov_bw) + + # THEN case should result having RNA tracks assert has_rna_tracks(case_obj) is True