Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Clinical-Genomics/hermes into add-gens
Browse files Browse the repository at this point in the history
  • Loading branch information
ivadym committed Jan 2, 2024
2 parents 730176c + d38db69 commit 6da33be
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.14.1
current_version = 1.14.3
commit = True
tag = True
tag_name = {new_version}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.12.0
hooks:
- id: black
args: ["--line-length", "100"]
Expand Down
24 changes: 18 additions & 6 deletions cg_hermes/config/rnafusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"used_by": ["deliver"],
},
frozenset({"arriba-visualisation", "arriba"}): {
"is_mandatory": True,
"is_mandatory": False,
"bundle_id": True,
"tags": ["arriba-visualisation", "visualization", "arriba", "research"],
"used_by": ["deliver", "scout"],
Expand All @@ -40,12 +40,12 @@
"used_by": ["deliver", "scout"],
},
frozenset({"fusioninspector", "report"}): {
"is_mandatory": True,
"is_mandatory": False,
"tags": ["fusioninspector"],
"used_by": ["deliver"],
},
frozenset({"fusioninspector-html", "report"}): {
"is_mandatory": True,
"is_mandatory": False,
"tags": ["fusioninspector-html", "research"],
"used_by": ["deliver", "scout"],
},
Expand All @@ -57,6 +57,16 @@
frozenset({"star-fusion-cram", "star-fusion"}): {
"is_mandatory": True,
"tags": ["cram"],
"used_by": ["deliver", "scout"],
},
frozenset({"star-fusion-cram-index", "star-fusion"}): {
"is_mandatory": True,
"tags": ["cram-index"],
"used_by": ["deliver", "scout"],
},
frozenset({"star-align-gene-counts", "star-align"}): {
"is_mandatory": True,
"tags": ["gene-counts"],
"used_by": ["deliver"],
},
frozenset({"multiqc-json"}): {
Expand All @@ -69,9 +79,11 @@
"tags": ["qc-metrics"],
"used_by": ["cg"],
},
frozenset({"vcf-fusion", "vcf-collect"}): {
"is_mandatory": False,
"tags": ["vcf-fusion"],
"used_by": ["deliver", "scout"],
},
}

NXF_RNAFUSION_COMMON_TAGS = {**RNAFUSION_COMMON_TAGS, **NEXTFLOW_COMMON_TAGS}


#
2 changes: 2 additions & 0 deletions cg_hermes/config/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"vcf-report": {"description": "Results and QC from variant calling"},
"cnv-report": {"description": "CNV variant calling report"},
"software-versions": {"description": "Versions of software used in analysis"},
"gene-counts": {"description": "STAR read counts output per gene"},
}

VALIDATIONS_COMMON = {
Expand Down Expand Up @@ -138,6 +139,7 @@
"umi-cram-index": {"description": "Index for the UMI consensus filtered cram file"},
"qc-cram": {"description": "QC alignment file in CRAM format"},
"qc-cram-index": {"description": "QC index file for alignment file in CRAM format"},
"vcf-fusion": {"description": "Converted RNA fusion file to SV VCF"},
}

TOOLS = {
Expand Down
54 changes: 27 additions & 27 deletions cg_hermes/deliverables.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Class to represent deliverables file"""
import copy
import logging
from typing import Dict, FrozenSet, List, Optional, Set
from typing import FrozenSet, Optional

from cg_hermes.config.balsamic import (
BALSAMIC_TAGS,
Expand All @@ -12,21 +12,21 @@
)
from cg_hermes.config.balsamic_qc import (
BALSAMIC_QC_TAGS,
QC_TUMOR_NORMAL_WGS_TAGS,
QC_TUMOR_NORMAL_PANEL_TAGS,
QC_TUMOR_NORMAL_WGS_TAGS,
)
from cg_hermes.config.balsamic_umi import (
BALSAMIC_UMI_TAGS,
UMI_TUMOR_ONLY_PANEL_TAGS,
UMI_TUMOR_NORMAL_PANEL_TAGS,
UMI_TUMOR_ONLY_PANEL_TAGS,
)
from cg_hermes.config.fluffy import FLUFFY_COMMON_TAGS
from cg_hermes.config.microsalt import MICROSALT_COMMON_TAGS
from cg_hermes.config.mip_dna import MIP_DNA_TAGS
from cg_hermes.config.mip_rna import MIP_RNA_TAGS
from cg_hermes.config.mutant import MUTANT_COMMON_TAGS
from cg_hermes.config.rnafusion import NXF_RNAFUSION_COMMON_TAGS
from cg_hermes.config.pipelines import AnalysisType, Pipeline
from cg_hermes.config.rnafusion import NXF_RNAFUSION_COMMON_TAGS
from cg_hermes.exceptions import MissingFileError
from cg_hermes.models import pipeline_deliverables
from cg_hermes.models.pipeline_deliverables import (
Expand All @@ -36,8 +36,8 @@
MicrosaltDeliverables,
MipDeliverables,
MutantDeliverables,
RnafusionDeliverables,
PipelineDeliverables,
RnafusionDeliverables,
TagBase,
)
from cg_hermes.models.tags import CGTag, TagMap
Expand All @@ -50,17 +50,17 @@ class Deliverables:

def __init__(
self,
deliverables: Dict[str, List[Dict[str, str]]],
deliverables: dict[str, list[dict[str, str]]],
pipeline: Pipeline,
analysis_type: Optional[AnalysisType] = None,
):
self.raw_deliverables = deliverables
self.pipeline = pipeline
self.analysis_type = analysis_type
self.bundle_id: Optional[str] = None
self.configs: Dict[FrozenSet[str], TagMap]
self.files: List[TagBase]
self.file_identifiers: Set[FrozenSet[str]]
self.configs: dict[FrozenSet[str], TagMap]
self.files: list[TagBase]
self.file_identifiers: set[FrozenSet[str]]
self.model: PipelineDeliverables
self.set_pipeline_specific_variables()
self.file_identifiers = {file_obj.tags for file_obj in self.files}
Expand Down Expand Up @@ -105,18 +105,18 @@ def set_pipeline_specific_variables(self):
)

@staticmethod
def build_internal_tag_map(tag_map: Dict[FrozenSet[str], dict]) -> Dict[FrozenSet[str], TagMap]:
def build_internal_tag_map(tag_map: dict[FrozenSet[str], dict]) -> dict[FrozenSet[str], TagMap]:
"""Convert and validate a tag map to TagMap objects"""
LOG.debug("Build internal tag map")
internal_tag_map: Dict[FrozenSet[str], TagMap] = dict()
internal_tag_map: dict[FrozenSet[str], TagMap] = dict()
for pipeline_tags in tag_map:
internal_tag_map[pipeline_tags] = TagMap.parse_obj(tag_map[pipeline_tags])
return internal_tag_map

@staticmethod
def convert_to_cg_tag(conversion_info: TagMap, subject_id: str, path: str) -> CGTag:
"""Convert tags from pipeline specific tags to CG tags"""
cg_tags: List[str] = copy.deepcopy(conversion_info.tags)
cg_tags: list[str] = copy.deepcopy(conversion_info.tags)
cg_tags.append(subject_id)
cg_tags.extend(
[tool for tool in conversion_info.used_by if tool not in ["cg", "audit", "store"]]
Expand All @@ -125,7 +125,7 @@ def convert_to_cg_tag(conversion_info: TagMap, subject_id: str, path: str) -> CG

def convert_to_cg_deliverables(self) -> CGDeliverables:
"""Convert pipeline specific information from deliverables file to CG formatted information"""
cg_files: List[CGTag] = []
cg_files: list[CGTag] = []
file_object: TagBase
for file_object in self.files:
pipeline_tags = file_object.tags
Expand Down Expand Up @@ -155,7 +155,7 @@ def convert_to_cg_deliverables(self) -> CGDeliverables:
pipeline=self.pipeline.value, files=cg_files, bundle_id=self.bundle_id
)

def get_balsamic_analysis_configs(self) -> Dict[FrozenSet[str], dict]:
def get_balsamic_analysis_configs(self) -> dict[FrozenSet[str], dict]:
"""Extracts all the BALSAMIC mandatory files depending on the analysis workflow and type executed"""

BALSAMIC_COMMON_TAGS = []
Expand Down Expand Up @@ -203,9 +203,9 @@ def validate_mandatory_files(self) -> None:
files=missing_mandatory_files, message="Deliverables is missing mandatory files"
)

def get_mip_files(self) -> List[TagBase]:
def get_mip_files(self) -> list[TagBase]:
file_obj: pipeline_deliverables.MipFile
files: List[TagBase] = []
files: list[TagBase] = []
for file_obj in self.model.files:
identifier = [file_obj.step]
if file_obj.tag:
Expand All @@ -220,9 +220,9 @@ def get_mip_files(self) -> List[TagBase]:
)
return files

def get_microsalt_files(self) -> List[TagBase]:
def get_microsalt_files(self) -> list[TagBase]:
file_obj: pipeline_deliverables.MicrosaltFile
files: List[TagBase] = []
files: list[TagBase] = []
for file_obj in self.model.files:
identifier = [file_obj.step]
if file_obj.tag:
Expand All @@ -236,9 +236,9 @@ def get_microsalt_files(self) -> List[TagBase]:
)
return files

def get_mutant_files(self) -> List[TagBase]:
def get_mutant_files(self) -> list[TagBase]:
file_obj: pipeline_deliverables.MutantFile
files: List[TagBase] = []
files: list[TagBase] = []
for file_obj in self.model.files:
identifier = [file_obj.step]
if file_obj.tag:
Expand All @@ -252,22 +252,22 @@ def get_mutant_files(self) -> List[TagBase]:
)
return files

def get_fluffy_files(self) -> List[TagBase]:
def get_fluffy_files(self) -> list[TagBase]:
file_obj: pipeline_deliverables.FileBase
files: List[TagBase] = []
files: list[TagBase] = []
for file_obj in self.model.files:
identifier = frozenset([file_obj.tag.lower()])
files.append(TagBase(tags=identifier, subject_id=file_obj.id, path=file_obj.path))
return files

def get_balsamic_files(self) -> List[TagBase]:
def get_balsamic_files(self) -> list[TagBase]:
file_obj: pipeline_deliverables.BalsamicFile
files: List[TagBase] = []
files: list[TagBase] = []
for file_obj in self.model.files:
sample_id: str = file_obj.id
tag_sample_id: str = sample_id.replace("_", "-")
# This is due to older balsamic format
split_id: List[str] = sample_id.split("_")
split_id: list[str] = sample_id.split("_")
if len(split_id) > 2:
sample_id = split_id[1]
tag_sample_id: str = "-".join(split_id)
Expand All @@ -277,9 +277,9 @@ def get_balsamic_files(self) -> List[TagBase]:
files.append(TagBase(tags=identifier, subject_id=sample_id, path=file_obj.path))
return files

def get_rnafusion_files(self) -> List[TagBase]:
def get_rnafusion_files(self) -> list[TagBase]:
file_obj: pipeline_deliverables.RnafusionFile
files: List[TagBase] = []
files: list[TagBase] = []
for file_obj in self.model.files:
identifier = [file_obj.step]
if file_obj.tag:
Expand Down
5 changes: 1 addition & 4 deletions cg_hermes/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from typing import List


class Error(Exception):
"""Base class for exceptions in this module."""

Expand All @@ -10,7 +7,7 @@ class Error(Exception):
class MissingFileError(Error):
"""Exception when mandatory file is missing."""

def __init__(self, files: List[str], message: str):
def __init__(self, files: list[str], message: str):
self.files = files
self.message = message

Expand Down
20 changes: 10 additions & 10 deletions cg_hermes/models/pipeline_deliverables.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import FrozenSet, List, Optional
from typing import FrozenSet, Optional

from pydantic import BaseModel, validator

Expand Down Expand Up @@ -49,7 +49,7 @@ class BalsamicFile(FileBase):
"""Definition of elements in balsamic deliverables"""

format: Optional[str]
tag: List[str]
tag: list[str]

@validator("tag", pre=True)
def split_str(cls, v):
Expand All @@ -64,51 +64,51 @@ def split_str(cls, v):
class PipelineDeliverables(BaseModel):
"""Specification for a general deliverables file"""

files: List[FileBase]
files: list[FileBase]


class MipDeliverables(PipelineDeliverables):
"""Specification for a MIP specific deliverables file"""

files: List[MipFile]
files: list[MipFile]


class MicrosaltDeliverables(PipelineDeliverables):
"""Specification for a MIP specific deliverables file"""

files: List[MicrosaltFile]
files: list[MicrosaltFile]


class BalsamicDeliverables(PipelineDeliverables):
"""Specification for a BALSAMIC specific deliverables file"""

files: List[BalsamicFile]
files: list[BalsamicFile]


class FluffyDeliverables(PipelineDeliverables):
"""Specification for a FLUFFY specific deliverables file"""

files: List[FileBase]
files: list[FileBase]


class MutantDeliverables(PipelineDeliverables):
"""Specification for a MUTANT specific deliverables file"""

files: List[MutantFile]
files: list[MutantFile]


class RnafusionDeliverables(PipelineDeliverables):
"""Specification for a RNAFUSION specific deliverables file"""

files: List[RnafusionFile]
files: list[RnafusionFile]


class CGDeliverables(PipelineDeliverables):
"""Class that specifies the output to CG"""

pipeline: str
bundle_id: str
files: List[CGTag]
files: list[CGTag]


class TagBase(BaseModel):
Expand Down
8 changes: 4 additions & 4 deletions cg_hermes/models/tags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import Optional

from pydantic import validator
from pydantic.main import BaseModel
Expand All @@ -7,9 +7,9 @@


class TagMap(BaseModel):
tags: List[str]
tags: list[str]
is_mandatory: bool
used_by: List[str]
used_by: list[str]
bundle_id: Optional[bool] = False

@validator("tags", each_item=True)
Expand All @@ -25,5 +25,5 @@ def check_usage(cls, usage):

class CGTag(BaseModel):
path: str
tags: List[str]
tags: list[str]
mandatory: bool
Loading

0 comments on commit 6da33be

Please sign in to comment.