Skip to content

Commit

Permalink
Add raredisease scout upload (#3591)(minor)
Browse files Browse the repository at this point in the history
## Description

### Added

- scout upload for raredisease

### Changed

- unified scout upload for balsamic, rnafusion, raredisease and mip-dna using inherited functions
  • Loading branch information
rannick authored Oct 21, 2024
1 parent e924df4 commit a1a3d44
Show file tree
Hide file tree
Showing 21 changed files with 928 additions and 360 deletions.
6 changes: 4 additions & 2 deletions cg/cli/upload/scout.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from cg.meta.workflow.balsamic_umi import BalsamicUmiAnalysisAPI
from cg.meta.workflow.mip_dna import MipDNAAnalysisAPI
from cg.meta.workflow.mip_rna import MipRNAAnalysisAPI
from cg.meta.workflow.raredisease import RarediseaseAnalysisAPI
from cg.meta.workflow.rnafusion import RnafusionAnalysisAPI
from cg.meta.workflow.tomte import TomteAnalysisAPI
from cg.models.cg_config import CGConfig
Expand Down Expand Up @@ -88,11 +89,11 @@ def create_scout_load_config(context: CGConfig, case_id: str, print_console: boo
except SyntaxError as error:
LOG.warning(repr(error))
raise click.Abort from error
LOG.info(f"Found load config {scout_load_config}")
LOG.info(f"Found load config: {scout_load_config}")

root_dir: str = context.meta_apis["upload_api"].analysis_api.root
LOG.info(f"Set root dir to {root_dir}")
file_path: Path = Path(root_dir, case_id, "scout_load.yaml")

if print_console:
click.echo(
WriteStream.write_stream_from_content(
Expand Down Expand Up @@ -315,6 +316,7 @@ def get_upload_api(case: Case, cg_config: CGConfig) -> UploadAPI:
Workflow.BALSAMIC_UMI: BalsamicUmiAnalysisAPI,
Workflow.MIP_RNA: MipRNAAnalysisAPI,
Workflow.MIP_DNA: MipDNAAnalysisAPI,
Workflow.RAREDISEASE: RarediseaseAnalysisAPI,
Workflow.RNAFUSION: RnafusionAnalysisAPI,
Workflow.TOMTE: TomteAnalysisAPI,
}
Expand Down
40 changes: 35 additions & 5 deletions cg/constants/scout.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ class ScoutUploadKey(StrEnum):


RAREDISEASE_CASE_TAGS = dict(
delivery_report={"delivery-report"},
multiqc={"multiqc-html"},
peddy_check={"ped-check", "peddy"},
peddy_ped={"ped", "peddy"},
peddy_sex={"sex-check", "peddy"},
smn_tsv={"smn-calling"},
vcf_mei={"mobile-elements", "clinical", "vcf"},
vcf_mei_research={"mobile-elements", "research", "vcf"},
vcf_snv_research={"vcf-snv-research"},
vcf_snv={"vcf-snv-clinical"},
vcf_snv_research_mt={"vcf-sv-research", "mitochondria"},
vcf_snv_mt={"vcf-sv-clinical", "mitochondria"},
str_catalog={"expansionhunter", "variant-catalog"},
vcf_sv_research={"vcf-sv-research"},
vcf_sv={"vcf-sv-clinical"},
vcf_str={"vcf-str"},
)

MIP_CASE_TAGS: dict[str, set[str]] = dict(
delivery_report={"delivery-report"},
multiqc_report={"multiqc-html"},
peddy_check={"ped-check", "peddy"},
Expand All @@ -57,8 +76,6 @@ class ScoutUploadKey(StrEnum):
vcf_str={"vcf-str"},
)

MIP_CASE_TAGS: dict[str, set[str]] = RAREDISEASE_CASE_TAGS

BALSAMIC_CASE_TAGS = dict(
sv_vcf={"vcf-sv-clinical"},
snv_vcf={"vcf-snv-clinical"},
Expand Down Expand Up @@ -87,7 +104,22 @@ class ScoutUploadKey(StrEnum):
vcf_fusion={"vcf-fusion"},
)

RAREDISEASE_SAMPLE_TAGS = dict(
RAREDISEASE_SAMPLE_TAGS: dict[str, set[str]] = dict(
alignment_file={AlignmentFileTag.CRAM},
vcf2cytosure={"vcf2cytosure"},
mt_bam={"bam-mt"},
eklipse_path={"eklipse-png"},
chromograph_autozyg={"chromograph", "autozyg"},
chromograph_coverage={"chromograph", "tcov"},
chromograph_regions={"chromograph", "regions"},
chromograph_sites={"chromograph", "sites"},
reviewer_alignment={"expansionhunter", "bam"},
reviewer_alignment_index={"expansionhunter", "bam-index"},
reviewer_vcf={"expansionhunter", "vcf-str"},
mitodel_file={"mitodel"},
)

MIP_SAMPLE_TAGS: dict[str, set[str]] = dict(
bam_file={"bam"},
alignment_file={"cram"},
vcf2cytosure={"vcf2cytosure"},
Expand All @@ -102,8 +134,6 @@ class ScoutUploadKey(StrEnum):
mitodel_file={"mitodel"},
)

MIP_SAMPLE_TAGS: dict[str, set[str]] = RAREDISEASE_SAMPLE_TAGS

BALSAMIC_SAMPLE_TAGS = dict(
bam_file={"bam"},
alignment_file={"cram"},
Expand Down
8 changes: 8 additions & 0 deletions cg/meta/upload/raredisease/raredisease.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ def upload(self, ctx: click.Context, case: Case, restart: bool) -> None:
ctx.invoke(upload_observations_to_loqusdb, case_id=case.internal_id)
ctx.invoke(upload_to_gens, case_id=case.internal_id)

# Delivery report generation
if case.data_delivery in REPORT_SUPPORTED_DATA_DELIVERY:
ctx.invoke(generate_delivery_report, case_id=case.internal_id)

# Clinical delivery upload
self.upload_files_to_customer_inbox(case)

# Scout specific upload
if DataDelivery.SCOUT in case.data_delivery:
ctx.invoke(upload_to_scout, case_id=case.internal_id, re_upload=restart)
LOG.info(
f"Upload of case {case.internal_id} was successful. Uploaded at {dt.datetime.now()} in StatusDB"
)
Expand Down
41 changes: 21 additions & 20 deletions cg/meta/upload/scout/balsamic_config_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cg.apps.lims import LimsAPI
from cg.constants.constants import SampleType
from cg.constants.housekeeper_tags import HK_DELIVERY_REPORT_TAG
from cg.constants.scout import BALSAMIC_CASE_TAGS, BALSAMIC_SAMPLE_TAGS, UploadTrack
from cg.constants.scout import BALSAMIC_CASE_TAGS, BALSAMIC_SAMPLE_TAGS, GenomeBuild, UploadTrack
from cg.constants.subject import PhenotypeStatus
from cg.meta.upload.scout.hk_tags import CaseTags, SampleTags
from cg.meta.upload.scout.scout_config_builder import ScoutConfigBuilder
Expand All @@ -19,25 +19,21 @@
class BalsamicConfigBuilder(ScoutConfigBuilder):
def __init__(self, hk_version_obj: Version, analysis_obj: Analysis, lims_api: LimsAPI):
super().__init__(
hk_version_obj=hk_version_obj, analysis_obj=analysis_obj, lims_api=lims_api
hk_version_obj=hk_version_obj,
analysis_obj=analysis_obj,
lims_api=lims_api,
)
self.case_tags: CaseTags = CaseTags(**BALSAMIC_CASE_TAGS)
self.sample_tags: SampleTags = SampleTags(**BALSAMIC_SAMPLE_TAGS)
self.load_config: BalsamicLoadConfig = BalsamicLoadConfig(
track=UploadTrack.CANCER.value,
delivery_report=self.get_file_from_hk({HK_DELIVERY_REPORT_TAG}),
)

def include_case_files(self):
def include_case_files(self, load_config: BalsamicLoadConfig) -> None:
LOG.info("Including BALSAMIC specific case level files")
self.load_config.vcf_cancer = self.get_file_from_hk(
hk_tags=self.case_tags.snv_vcf, latest=True
)
self.load_config.vcf_cancer_sv = self.get_file_from_hk(
load_config.vcf_cancer = self.get_file_from_hk(hk_tags=self.case_tags.snv_vcf, latest=True)
load_config.vcf_cancer_sv = self.get_file_from_hk(
hk_tags=self.case_tags.sv_vcf, latest=True
)
self.include_cnv_report()
self.include_multiqc_report()
self.include_cnv_report(load_config)
self.include_multiqc_report(load_config)

def include_sample_files(self, config_sample: ScoutCancerIndividual) -> None:
LOG.info("Including BALSAMIC specific sample level files.")
Expand Down Expand Up @@ -78,16 +74,21 @@ def get_balsamic_analysis_type(self, sample: Sample) -> str:

return analysis_type

def build_load_config(self) -> None:
def build_load_config(self) -> BalsamicLoadConfig:
LOG.info("Build load config for balsamic case")
self.add_common_info_to_load_config()
self.load_config.human_genome_build = "37"
self.load_config.rank_score_threshold = -100

self.include_case_files()
load_config: BalsamicLoadConfig = BalsamicLoadConfig(
track=UploadTrack.CANCER.value,
delivery_report=self.get_file_from_hk({HK_DELIVERY_REPORT_TAG}),
)
self.add_common_info_to_load_config(load_config)
load_config.human_genome_build = GenomeBuild.hg19
load_config.rank_score_threshold = -100
self.include_case_files(load_config)

LOG.info("Building samples")
db_sample: CaseSample

for db_sample in self.analysis_obj.case.links:
self.load_config.samples.append(self.build_config_sample(case_sample=db_sample))
load_config.samples.append(self.build_config_sample(case_sample=db_sample))

return load_config
30 changes: 26 additions & 4 deletions cg/meta/upload/scout/balsamic_umi_config_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,48 @@

from cg.apps.lims import LimsAPI
from cg.constants.housekeeper_tags import HK_DELIVERY_REPORT_TAG
from cg.constants.scout import BALSAMIC_UMI_CASE_TAGS, BALSAMIC_UMI_SAMPLE_TAGS, UploadTrack
from cg.constants.scout import (
BALSAMIC_UMI_CASE_TAGS,
BALSAMIC_UMI_SAMPLE_TAGS,
GenomeBuild,
UploadTrack,
)
from cg.meta.upload.scout.balsamic_config_builder import BalsamicConfigBuilder
from cg.meta.upload.scout.hk_tags import CaseTags, SampleTags
from cg.models.scout.scout_load_config import BalsamicUmiLoadConfig, ScoutCancerIndividual
from cg.store.models import Analysis, Sample
from cg.store.models import Analysis, CaseSample, Sample

LOG = logging.getLogger(__name__)


class BalsamicUmiConfigBuilder(BalsamicConfigBuilder):
def __init__(self, hk_version_obj: Version, analysis_obj: Analysis, lims_api: LimsAPI):
super().__init__(
hk_version_obj=hk_version_obj, analysis_obj=analysis_obj, lims_api=lims_api
hk_version_obj=hk_version_obj,
analysis_obj=analysis_obj,
lims_api=lims_api,
)
self.case_tags: CaseTags = CaseTags(**BALSAMIC_UMI_CASE_TAGS)
self.sample_tags: SampleTags = SampleTags(**BALSAMIC_UMI_SAMPLE_TAGS)
self.load_config: BalsamicUmiLoadConfig = BalsamicUmiLoadConfig(

def build_load_config(self) -> BalsamicUmiLoadConfig:
LOG.info("Build load config for balsamic case")
load_config: BalsamicUmiLoadConfig = BalsamicUmiLoadConfig(
track=UploadTrack.CANCER.value,
delivery_report=self.get_file_from_hk({HK_DELIVERY_REPORT_TAG}),
)
self.add_common_info_to_load_config(load_config)
load_config.human_genome_build = GenomeBuild.hg19
load_config.rank_score_threshold = -100
self.include_case_files(load_config)

LOG.info("Building samples")
db_sample: CaseSample

for db_sample in self.analysis_obj.case.links:
load_config.samples.append(self.build_config_sample(case_sample=db_sample))

return load_config

def include_sample_files(self, config_sample: ScoutCancerIndividual) -> None:
LOG.info("Including BALSAMIC specific sample level files")
Expand Down
16 changes: 16 additions & 0 deletions cg/meta/upload/scout/hk_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ class CaseTags(BaseModel):
None, description="vcf_cancer_sv for rare disease and vcf_sv_cancer for cancer"
)
sv_research_vcf: set[str] | None = Field(None, description="vcf_sv_research for rare disease")
vcf_snv: set[str] | None = Field(
None, description="vcf_snv for rare disease and vcf_cancer for cancer"
)
vcf_snv_research: set[str] | None = Field(None, description="vcf_snv_research for rare disease")
vcf_snv_mt: set[str] | None = Field(None, description="vcf_snv for rare disease, mitochondria")
vcf_snv_research_mt: set[str] | None = Field(
None, description="vcf_snv_research for rare disease, mitochondria"
)
vcf_sv: set[str] | None = Field(
None, description="vcf_cancer_sv for rare disease and vcf_sv_cancer for cancer"
)
vcf_sv_research: set[str] | None = Field(None, description="vcf_sv_research for rare disease")
vcf_str: set[str] = Field(
None, description="Short Tandem Repeat variants, only for rare disease"
)
Expand All @@ -21,6 +33,7 @@ class CaseTags(BaseModel):
peddy_sex: set[str] | None = Field(None, description="Peddy sex check, only for rare disease")
peddy_check: set[str] = Field(None, description="Peddy pedigree check, only for rare disease")
multiqc_report: set[str] | None = Field(None, description="MultiQC report")
multiqc: set[str] | None = Field(None, description="MultiQC report")
delivery_report: set[str] | None = Field(None, description="Delivery report")
str_catalog: set[str] | None = Field(
None, description="Variant catalog used with expansionhunter"
Expand Down Expand Up @@ -57,13 +70,16 @@ class SampleTags(BaseModel):
# If cram does not exist
bam_file: set[str] | None = None
alignment_file: set[str] | None = None
alignment_path: set[str] | None = None
vcf2cytosure: set[str] | None = None
eklipse_path: set[str] | None = None
mt_bam: set[str] | None = None
chromograph_autozyg: set[str] | None = None
chromograph_coverage: set[str] | None = None
chromograph_regions: set[str] | None = None
chromograph_sites: set[str] | None = None
reviewer_alignment: set[str] | None = None
reviewer_alignment_index: set[str] | None = None
reviewer_catalog: set[str] | None = None
reviewer_vcf: set[str] | None = None
mitodel_file: set[str] | None = None
Loading

0 comments on commit a1a3d44

Please sign in to comment.