From 598c243d9aededce4c9e0a6456e673e571c1e5cd Mon Sep 17 00:00:00 2001 From: Colin Gross Date: Tue, 10 Oct 2023 12:21:52 -0400 Subject: [PATCH] Include handlers for data cached from s3 --- bravo_api/core/s3_cram_source.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bravo_api/core/s3_cram_source.py b/bravo_api/core/s3_cram_source.py index 011a88d..63676a5 100644 --- a/bravo_api/core/s3_cram_source.py +++ b/bravo_api/core/s3_cram_source.py @@ -161,6 +161,22 @@ def cache_combined_data(self, base_key: str, bam_data: dict) -> None: self.cache.set(f'{base_key}-bam', bam_data['bam']) self.cache.set(f'{base_key}-bai', bam_data['bai']) + def get_bam_data(self, cram_path, chrom, pos, ref, alt, sample_no, sample_het=None) -> bytes: + return(self.get_data('bam', cram_path, chrom, pos, ref, alt, sample_no, sample_het)) + + def get_bai_data(self, cram_path, chrom, pos, ref, alt, sample_no, sample_het=None) -> bytes: + return(self.get_data('bai', cram_path, chrom, pos, ref, alt, sample_no, sample_het)) + + def get_data(self, key_suffix, cram_path, chrom, pos, ref, alt, + sample_no, sample_het=None) -> bytes: + base_key = f'{chrom}-{pos}-{ref}-{alt}-{sample_het}-{sample_no}' + target_data = self.cache.get(f'{base_key}-{key_suffix}') + if target_data is None: + combined_data = S3CramSource.extract_bam_subset(cram_path, self.ref_path, chrom, pos) + self.cache_combined_data(base_key, combined_data) + target_data = combined_data[key_suffix] + return(target_data) + @staticmethod def extract_bam_subset(cram_url: str, ref_path: str, chrom: str, pos: str): window = 100