Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add raredisease config #2725

Merged
merged 190 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 174 commits
Commits
Show all changes
190 commits
Select commit Hold shift + click to select a range
fb15cb7
add raredisease config
peterpru Dec 1, 2023
33f51de
typo
peterpru Dec 1, 2023
d0ea695
add samplesheet and pipeline parameters
peterpru Dec 1, 2023
fff1463
update config case function
rannick Dec 7, 2023
55a35c7
update config case function
rannick Dec 7, 2023
3800350
update config case function
rannick Dec 7, 2023
09dac81
reach case_sample
rannick Dec 7, 2023
d1e6014
reach case_sample
rannick Dec 7, 2023
f59b8e4
bug fixing
rannick Dec 7, 2023
30fe9b0
bug fixing
rannick Dec 7, 2023
2a05912
bug fixing
rannick Dec 7, 2023
74c840f
bug fixing
rannick Dec 7, 2023
9d586eb
bug fixing
rannick Dec 7, 2023
48eac02
bug fixing
rannick Dec 7, 2023
01e5def
bug fixing
rannick Dec 7, 2023
10918a6
bug fixing
rannick Dec 7, 2023
aefa3f2
bug fixing
rannick Dec 7, 2023
5f8540e
bug fixing
rannick Dec 7, 2023
ebca9bf
bug fixing
rannick Dec 7, 2023
02397ce
bug fixing
rannick Dec 7, 2023
a50b4a6
bug fixing
rannick Dec 7, 2023
65a0499
bug fixing
rannick Dec 7, 2023
0bca8c1
bug fixing
rannick Dec 7, 2023
021dca8
bug fixing
rannick Dec 7, 2023
9b093a3
bug fixing
rannick Dec 7, 2023
fcd6463
bug fixing
rannick Dec 7, 2023
987a573
bug fixing
rannick Dec 7, 2023
ae6826c
bug fixing
rannick Dec 7, 2023
79e770d
bug fixing
rannick Dec 7, 2023
606066b
bug fixing
rannick Dec 7, 2023
a40d1c9
fix samplesheet creation
rannick Dec 7, 2023
462f950
fix samplesheet creation
rannick Dec 7, 2023
1d24f42
fix samplesheet creation
rannick Dec 7, 2023
a8dff75
start plan for raredisease parameters
rannick Dec 11, 2023
f4c6523
Merge branch 'master' into add-raredisease-config-case
peterpru Jan 9, 2024
447078d
fix linting
peterpru Jan 9, 2024
0e57efd
use general tower binary path
peterpru Jan 11, 2024
91b8043
change to staticmethod and clean up sonarcloud issue
peterpru Jan 11, 2024
ab826e0
start preparing test for cg workflow raredisease config-case
peterpru Jan 11, 2024
3cb91ad
comment out part of the test
peterpru Jan 16, 2024
65594d6
move option_from_start to common
rannick Jan 22, 2024
230ba24
move option_from_start to common
rannick Jan 22, 2024
6fc27b5
move option_from_start to common
rannick Jan 22, 2024
e8f0ed7
add config manipulation
rannick Jan 22, 2024
fac4402
merge
rannick Jan 22, 2024
a6c43d1
black
rannick Jan 22, 2024
30043e1
fix path
rannick Jan 22, 2024
c977bf3
add on-the-fly parameters
rannick Jan 22, 2024
00356d3
add on-the-fly parameters, fix typo
rannick Jan 22, 2024
aead555
add on-the-fly parameters, fix typo
rannick Jan 22, 2024
ad73ca9
fix PipelineParameters
rannick Jan 24, 2024
70d1006
config: write to stdout
rannick Jan 24, 2024
8dd3bb2
config: write to stdout
rannick Jan 24, 2024
648574f
add newline
rannick Jan 24, 2024
1333786
add newline
rannick Jan 24, 2024
ee960d7
black
rannick Jan 24, 2024
22d4ace
black
rannick Jan 24, 2024
5452641
fix some code smells
rannick Jan 24, 2024
ee1d788
black
rannick Jan 24, 2024
a553cb7
keep using RnafusionParameters
rannick Jan 24, 2024
36cf1bf
black
rannick Jan 24, 2024
3c08001
change type
rannick Jan 24, 2024
8855132
update docstring
rannick Jan 24, 2024
10b0fc3
Merge branch 'master' into add-raredisease-config-case
rannick Jan 24, 2024
deeec2f
uncomment tests
rannick Jan 24, 2024
5ddaff8
adapt server fixture
rannick Jan 24, 2024
9cf6877
get parameters info in dry-run
rannick Jan 24, 2024
f029153
remove binary path from raredisease server fixture
rannick Jan 24, 2024
3a709c5
add outdir
rannick Jan 24, 2024
e323bbc
add all pipeline parameter to teh string
rannick Jan 24, 2024
217022d
Merge branch 'master' into add-raredisease-config-case
rannick Feb 5, 2024
a5689b8
fix issues
rannick Feb 5, 2024
5d45e4d
black
rannick Feb 5, 2024
2787ba6
Update cg/cli/workflow/nf_analysis.py
rannick Feb 12, 2024
4842cfc
add config file extension and use
rannick Feb 12, 2024
02c8b52
add config file extension and use
rannick Feb 12, 2024
5df6471
remove config read/write/concat that can be in txt io
rannick Feb 12, 2024
b2bd759
Update cg/meta/workflow/raredisease.py
rannick Feb 12, 2024
941bfb9
Update cg/meta/workflow/raredisease.py
rannick Feb 12, 2024
23f4375
Update cg/meta/workflow/raredisease.py
rannick Feb 12, 2024
7eddb2a
rename function config_case in RarediseaseApi
rannick Feb 12, 2024
64f2382
Merge branch 'add-raredisease-config-case' of https://github.com/Clin…
rannick Feb 12, 2024
ac10dd9
Update cg/meta/workflow/raredisease.py
rannick Feb 12, 2024
20b5784
Update cg/meta/workflow/raredisease.py
rannick Feb 12, 2024
46c102f
use named arguments
rannick Feb 12, 2024
ac2ee07
Merge branch 'add-raredisease-config-case' of https://github.com/Clin…
rannick Feb 12, 2024
642f71f
types and named args
rannick Feb 12, 2024
16e0b8c
use constant for empty string and double quote
rannick Feb 12, 2024
9cf7e7c
use PlinkPhenotypeStatus + update docstring
rannick Feb 16, 2024
811f159
use params instead of config, and overwrite nf-analysis in rarediseas…
rannick Feb 16, 2024
dc3e551
clarify docstring
rannick Feb 16, 2024
81a49ef
Update cg/models/raredisease/raredisease.py
rannick Feb 16, 2024
091dc62
use Sex class constants
rannick Feb 16, 2024
438dce6
move getting the parental id to StatusDB API
rannick Feb 16, 2024
16a6496
Merge branch 'add-raredisease-config-case' of https://github.com/Clin…
rannick Feb 16, 2024
1b99df6
move Pipeline to Workflow
rannick Feb 16, 2024
e2e3892
create RarediseaseSampleSheetHeaders class, similar to Fluffy
rannick Feb 16, 2024
94a2783
add test raredisease config case
rannick Feb 16, 2024
62b0bcf
rename reformat function to clarify
rannick Feb 16, 2024
70472d3
Update cg/meta/workflow/raredisease.py
rannick Feb 16, 2024
1e95376
Update cg/meta/workflow/raredisease.py
rannick Feb 16, 2024
69a6777
update docstring
rannick Feb 16, 2024
269f293
Merge branch 'add-raredisease-config-case' of https://github.com/Clin…
rannick Feb 16, 2024
a679f0e
samplesheet to sample sheet
rannick Feb 16, 2024
3c03eaa
fix dependencies
rannick Feb 16, 2024
520ff4b
Merge branch 'master' into add-raredisease-config-case
rannick Feb 16, 2024
d8cc2fc
fix dependencies
rannick Feb 16, 2024
5851f83
Merge branch 'add-raredisease-config-case' of https://github.com/Clin…
rannick Feb 16, 2024
43348c3
workflow
rannick Feb 16, 2024
e7e245e
workflow
rannick Feb 16, 2024
44b25ea
fix dependencies
rannick Feb 16, 2024
7f3b45d
adapt concat
rannick Feb 16, 2024
011b198
black
rannick Feb 29, 2024
cdd7021
Merge branch 'master' into add-raredisease-config-case
rannick Feb 29, 2024
d97956b
update dry-run message in tests
rannick Feb 29, 2024
414df0a
Merge branch 'add-raredisease-config-case' of https://github.com/Clin…
rannick Feb 29, 2024
253f5a8
black
rannick Feb 29, 2024
dc72d77
debugging
rannick Feb 29, 2024
cc629e3
debugging
rannick Feb 29, 2024
abc900e
debugging
rannick Feb 29, 2024
8612c4a
debugging
rannick Feb 29, 2024
bf81651
black
rannick Feb 29, 2024
af70527
black
rannick Feb 29, 2024
d1a69ef
debugging
rannick Feb 29, 2024
7d98f47
Merge branch 'master' into add-raredisease-config-case
rannick Feb 29, 2024
2d58207
add test for concat
rannick Feb 29, 2024
4e42083
Merge branch 'add-raredisease-config-case' of https://github.com/Clin…
rannick Feb 29, 2024
730e782
continue addind concat tests
rannick Feb 29, 2024
f03b940
continue addind concat tests
rannick Feb 29, 2024
def61d0
fix typo
rannick Feb 29, 2024
8ed4a1e
fix tests
rannick Feb 29, 2024
a4df746
fix tests
rannick Feb 29, 2024
e5e3071
fix tests
rannick Feb 29, 2024
2f15ab9
Merge branch 'master' into add-raredisease-config-case
rannick Feb 29, 2024
78108dc
fix tests
rannick Feb 29, 2024
b686381
fix tests
rannick Feb 29, 2024
6098dd3
fix tests
rannick Feb 29, 2024
2140909
fix tests
rannick Feb 29, 2024
107ee86
fix tests
rannick Feb 29, 2024
4461b4f
fix tests
rannick Feb 29, 2024
1e590c3
fix tests
rannick Feb 29, 2024
47b2bb0
fix tests
rannick Feb 29, 2024
dedde02
fix tests
rannick Feb 29, 2024
b5d76e0
fix tests
rannick Feb 29, 2024
faa8559
fix tests
rannick Feb 29, 2024
e6fa5ef
fix tests
rannick Feb 29, 2024
d986097
Merge branch 'master' into add-raredisease-config-case
rannick Feb 29, 2024
37f5aaa
black
rannick Feb 29, 2024
d324b8b
Merge branch 'add-raredisease-config-case' of https://github.com/Clin…
rannick Feb 29, 2024
df16baa
add test for sample sheet creation
rannick Feb 29, 2024
eccae2d
add test for sample sheet creation
rannick Feb 29, 2024
cd751a0
test writing
rannick Mar 1, 2024
70a9092
test writing
rannick Mar 1, 2024
d29170c
test writing
rannick Mar 1, 2024
2bc92cc
test writing
rannick Mar 1, 2024
8431435
test for writing config file
rannick Mar 1, 2024
28d019d
black
rannick Mar 1, 2024
fd794c3
test for writing config file
rannick Mar 1, 2024
708ba30
type for raredisease config to str
rannick Mar 1, 2024
d14a3ac
test for writing config file
rannick Mar 1, 2024
fbdbcb3
black
rannick Mar 1, 2024
45a90a4
black
rannick Mar 1, 2024
261cae7
test for writing config file
rannick Mar 1, 2024
860551a
test for writing config file
rannick Mar 1, 2024
2eed8a0
test for writing config file
rannick Mar 1, 2024
e2aa94a
test for writing config file
rannick Mar 4, 2024
5dd1671
black
rannick Mar 4, 2024
a329f86
test for writing config file
rannick Mar 4, 2024
d07447b
test for writing config file
rannick Mar 4, 2024
7b13a6d
black
rannick Mar 4, 2024
577d550
make reformat_sample_content a property
rannick Mar 4, 2024
d40108c
Merge branch 'master' into add-raredisease-config-case
rannick Mar 4, 2024
2e505ae
fix error
rannick Mar 4, 2024
70d7a3b
Merge branch 'add-raredisease-config-case' of https://github.com/Clin…
rannick Mar 4, 2024
7922ba5
Update cg/io/config.py
rannick Mar 4, 2024
33f70a3
Update cg/meta/workflow/raredisease.py
rannick Mar 4, 2024
b0525fe
Merge branch 'master' into add-raredisease-config-case
rannick Mar 4, 2024
5aaf75a
key to parameters
rannick Mar 4, 2024
5b776bc
merge
rannick Mar 4, 2024
5ec203a
Update cg/io/txt.py
rannick Mar 4, 2024
3b43816
Update cg/store/models.py
rannick Mar 4, 2024
0cc4d74
black
rannick Mar 4, 2024
fb7400c
Merge branch 'add-raredisease-config-case' of https://github.com/Clin…
rannick Mar 4, 2024
46240b2
parental id as property
rannick Mar 4, 2024
c4ddd17
parental id as property
rannick Mar 4, 2024
6c90f43
parental id as property
rannick Mar 4, 2024
7f97fc6
parental id as property
rannick Mar 4, 2024
e912d29
black
rannick Mar 4, 2024
fafc34a
black
rannick Mar 4, 2024
db93365
paternal/maternal ids cannot be None, should return empty string
rannick Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cg/cli/workflow/nf_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@
default=None,
help="NF-Tower ID of run to relaunch. If not provided the latest NF-Tower ID for a case will be used.",
)
OPTION_FROM_START = click.option(
"--from-start",
is_flag=True,
default=False,
show_default=True,
help="Start workflow from start without resuming execution",
)


@click.command("metrics-deliver")
Expand Down
21 changes: 20 additions & 1 deletion cg/cli/workflow/raredisease/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import logging

import click
from pydantic.v1 import ValidationError

from cg.cli.utils import echo_lines
from cg.cli.workflow.commands import ARGUMENT_CASE_ID, OPTION_DRY
from cg.constants.constants import MetaApis
from cg.constants.constants import DRY_RUN, MetaApis
from cg.meta.workflow.analysis import AnalysisAPI
from cg.meta.workflow.raredisease import RarediseaseAnalysisAPI
from cg.models.cg_config import CGConfig
from cg.exc import CgError


LOG = logging.getLogger(__name__)

Expand All @@ -22,6 +25,22 @@ def raredisease(context: click.Context) -> None:
context.obj.meta_apis[MetaApis.ANALYSIS_API] = RarediseaseAnalysisAPI(config=context.obj)


@raredisease.command("config-case")
@ARGUMENT_CASE_ID
@DRY_RUN
@click.pass_obj
def config_case(context: CGConfig, case_id: str, dry_run: bool) -> None:
"""Create sample sheet file and params file for a given case."""
analysis_api: RarediseaseAnalysisAPI = context.meta_apis[MetaApis.ANALYSIS_API]
LOG.info(f"Creating config files for {case_id}.")
try:
analysis_api.status_db.verify_case_exists(case_internal_id=case_id)
analysis_api.write_config_case(case_id=case_id, dry_run=dry_run)
except (CgError, ValidationError) as error:
LOG.error(f"Could not create config files for {case_id}: {error}")
raise click.Abort() from error


@raredisease.command("panel")
@OPTION_DRY
@ARGUMENT_CASE_ID
Expand Down
2 changes: 1 addition & 1 deletion cg/cli/workflow/rnafusion/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from cg.cli.workflow.nf_analysis import (
OPTION_COMPUTE_ENV,
OPTION_CONFIG,
OPTION_FROM_START,
OPTION_LOG,
OPTION_PARAMS_FILE,
OPTION_PROFILE,
Expand All @@ -22,7 +23,6 @@
report_deliver,
)
from cg.cli.workflow.rnafusion.options import (
OPTION_FROM_START,
OPTION_REFERENCES,
OPTION_STRANDEDNESS,
)
Expand Down
8 changes: 0 additions & 8 deletions cg/cli/workflow/rnafusion/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

from cg.constants.constants import Strandedness

OPTION_FROM_START = click.option(
"--from-start",
is_flag=True,
default=False,
show_default=True,
help="Start workflow from start without resuming execution",
)

OPTION_STRANDEDNESS = click.option(
"--strandedness",
type=str,
Expand Down
5 changes: 4 additions & 1 deletion cg/cli/workflow/taxprofiler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from cg.cli.workflow.nf_analysis import (
OPTION_COMPUTE_ENV,
OPTION_CONFIG,
OPTION_FROM_START,
OPTION_LOG,
OPTION_PARAMS_FILE,
OPTION_PROFILE,
Expand All @@ -19,7 +20,9 @@
metrics_deliver,
report_deliver,
)
from cg.cli.workflow.taxprofiler.options import OPTION_FROM_START, OPTION_INSTRUMENT_PLATFORM
from cg.cli.workflow.taxprofiler.options import (
OPTION_INSTRUMENT_PLATFORM,
)
from cg.constants import EXIT_FAIL, EXIT_SUCCESS
from cg.constants.constants import DRY_RUN, CaseActions, MetaApis
from cg.constants.nf_analysis import NfTowerStatus
Expand Down
8 changes: 0 additions & 8 deletions cg/cli/workflow/taxprofiler/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

from cg.constants.sequencing import SequencingPlatform

OPTION_FROM_START = click.option(
"--from-start",
is_flag=True,
default=False,
show_default=True,
help="Start workflow from the start",
)

OPTION_INSTRUMENT_PLATFORM = click.option(
"--instrument-platform",
show_default=True,
Expand Down
1 change: 1 addition & 0 deletions cg/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class HastaSlurmPartitions(StrEnum):
class FileExtensions(StrEnum):
BED: str = ".bed"
COMPLETE: str = ".complete"
CONFIG: str = ".config"
CRAM: str = ".cram"
CSV: str = ".csv"
FASTQ: str = ".fastq"
Expand Down
17 changes: 17 additions & 0 deletions cg/io/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Module to read or write config files"""

from pathlib import Path
from typing import Any
from cg.constants.symbols import EMPTY_STRING


def write_config_nextflow_style(content: dict[str, Any] | None) -> str:
"""Write content to stream accepted by Nextflow config files with non-quoted booleans and quoted strings."""
string = EMPTY_STRING
double_quotes = '"'
rannick marked this conversation as resolved.
Show resolved Hide resolved
for key, value in content.items():
rannick marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(value, Path):
value: str = value.as_posix()
quotes = double_quotes if type(value) is str else EMPTY_STRING
string += f"params.{key} = {quotes}{value}{quotes}\n"
return string
19 changes: 18 additions & 1 deletion cg/io/txt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Module to read or write txt files."""

from pathlib import Path
from typing import Any
from typing import List, Optional
from cg.constants.symbols import EMPTY_STRING


def read_txt(file_path: Path, read_to_string: bool = False) -> list[str] | str:
Expand All @@ -19,3 +20,19 @@ def write_txt(content: list[str] | str, file_path: Path) -> None:
file.writelines(content)
else:
file.write(content)


def concat_txt(
file_paths: list[Path], target_file: Path, str_content: Optional[List[str]] = None
) -> None:
"""Concatenate files and eventual string content."""
content: str = EMPTY_STRING
if str_content:
for txt in str_content:
content += txt
content += "\n" # Add newline after each file content
for file_path in file_paths:
content += read_txt(file_path, read_to_string=True)
content += "\n" # Add newline after each file content

write_txt(content=content, file_path=target_file)
rannick marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions cg/meta/workflow/nf_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def get_workdir_path(self, case_id: str, work_dir: Path | None = None) -> Path:
return work_dir.absolute()
return Path(self.get_case_path(case_id), NFX_WORK_DIR)

def set_cluster_options(self, case_id: str) -> str:
return f'process.clusterOptions = "-A {self.account} --qos={self.get_slurm_qos_for_case(case_id=case_id)}"\n'

@staticmethod
def extract_read_files(
metadata: list[FastqFileMeta], forward_read: bool = False, reverse_read: bool = False
Expand Down
135 changes: 135 additions & 0 deletions cg/meta/workflow/raredisease.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
"""Module for Raredisease Analysis API."""

import logging
from typing import Any
from pathlib import Path

from cg.io.txt import concat_txt
from cg.io.config import write_config_nextflow_style
from cg.constants import GenePanelMasterList, Workflow
from cg.constants.constants import FileExtensions
from cg.constants.subject import PlinkPhenotypeStatus, PlinkSex
from cg.constants.gene_panel import GENOME_BUILD_37
from cg.meta.workflow.analysis import add_gene_panel_combo
from cg.meta.workflow.nf_analysis import NfAnalysisAPI
from cg.models.cg_config import CGConfig
from cg.models.fastq import FastqFileMeta
from cg.models.raredisease.raredisease import (
RarediseaseSampleSheetEntry,
RarediseaseSampleSheetHeaders,
)
from cg.models.nf_analysis import WorkflowParameters
from cg.store.models import Case, CaseSample


LOG = logging.getLogger(__name__)

Expand All @@ -22,6 +35,128 @@ def __init__(
workflow: Workflow = Workflow.RAREDISEASE,
):
super().__init__(config=config, workflow=workflow)
self.root_dir: str = config.raredisease.root
self.nfcore_workflow_path: str = config.raredisease.workflow_path
self.references: str = config.raredisease.references
self.profile: str = config.raredisease.profile
self.conda_env: str = config.raredisease.conda_env
self.conda_binary: str = config.raredisease.conda_binary
self.config_platform: str = config.raredisease.config_platform
self.config_params: str = config.raredisease.config_params
self.config_resources: str = config.raredisease.config_resources
self.tower_binary_path: str = config.tower_binary_path
self.tower_workflow: str = config.raredisease.tower_workflow
self.account: str = config.raredisease.slurm.account
self.compute_env: str = config.raredisease.compute_env
self.revision: str = config.raredisease.revision

def write_config_case(
self,
case_id: str,
dry_run: bool,
) -> None:
"""Create a parameter (.config) files and a Nextflow sample sheet input for Raredisease analysis."""
self.create_case_directory(case_id=case_id, dry_run=dry_run)
sample_sheet_content: list[list[Any]] = self.get_sample_sheet_content(case_id=case_id)
workflow_parameters: WorkflowParameters = self.get_workflow_parameters(case_id=case_id)
if dry_run:
LOG.info("Dry run: nextflow sample sheet and parameter file will not be written")
return
self.write_sample_sheet(
content=sample_sheet_content,
file_path=self.get_sample_sheet_path(case_id=case_id),
header=RarediseaseSampleSheetHeaders.headers(),
)
self.write_params_file(case_id=case_id, workflow_parameters=workflow_parameters.dict())

def get_sample_sheet_content_per_sample(
rannick marked this conversation as resolved.
Show resolved Hide resolved
self, case: Case = "", case_sample: CaseSample = ""
) -> list[list[str]]:
"""Get sample sheet content per sample."""
sample_metadata: list[FastqFileMeta] = self.gather_file_metadata_for_sample(
case_sample.sample
)
fastq_forward_read_paths: list[str] = self.extract_read_files(
metadata=sample_metadata, forward_read=True
)
fastq_reverse_read_paths: list[str] = self.extract_read_files(
metadata=sample_metadata, reverse_read=True
)
sample_sheet_entry = RarediseaseSampleSheetEntry(
name=case_sample.sample.internal_id,
fastq_forward_read_paths=fastq_forward_read_paths,
fastq_reverse_read_paths=fastq_reverse_read_paths,
sex=self.get_sex_code(case_sample.sample.sex),
phenotype=self.get_phenotype_code(case_sample.status),
paternal_id=CaseSample.get_paternal_id(case_sample.father),
maternal_id=CaseSample.get_maternal_id(case_sample.mother),
case_id=case.internal_id,
)
return sample_sheet_entry.reformat_sample_content

def get_sample_sheet_content(
self,
case_id: str,
) -> list[list[Any]]:
"""Return Raredisease nextflow sample sheet content for a case."""
case: Case = self.status_db.get_case_by_internal_id(internal_id=case_id)
sample_sheet_content = []
LOG.info("Getting sample sheet information")
LOG.info(f"Samples linked to case {case_id}: {len(case.links)}")
for link in case.links:
sample_sheet_content.extend(
self.get_sample_sheet_content_per_sample(case=case, case_sample=link)
)
return sample_sheet_content

def get_workflow_parameters(self, case_id: str) -> WorkflowParameters:
"""Return parameters."""
LOG.info("Getting parameters information")
return WorkflowParameters(
sample_sheet_path=self.get_sample_sheet_path(case_id=case_id),
outdir=self.get_case_path(case_id=case_id),
)

def get_params_file_path(self, case_id: str, params_file: Path | None = None) -> Path:
"""Return parameters file or a path where the default parameters file for a case id should be located."""
if params_file:
return Path(params_file).absolute()
return Path((self.get_case_path(case_id)), f"{case_id}_params_file{FileExtensions.CONFIG}")
rannick marked this conversation as resolved.
Show resolved Hide resolved
# This function should be moved to nf-analysis to replace the current one when all nextflow pipelines are using the same config files approach

def write_params_file(self, case_id: str, workflow_parameters: dict) -> None:
"""Write params-file for analysis."""
LOG.debug("Writing parameters file")
config_files_list = [self.config_platform, self.config_params, self.config_resources]
extra_parameters_str = [
write_config_nextflow_style(workflow_parameters),
self.set_cluster_options(case_id=case_id),
]
concat_txt(
file_paths=config_files_list,
target_file=self.get_params_file_path(case_id=case_id),
str_content=extra_parameters_str,
)

@staticmethod
def get_phenotype_code(phenotype: str) -> int:
"""Return Raredisease phenotype code."""
LOG.debug("Translate phenotype to integer code")
try:
code = PlinkPhenotypeStatus[phenotype.upper()]
except KeyError:
raise ValueError(f"{phenotype} is not a valid phenotype")
return code

@staticmethod
def get_sex_code(sex: str) -> int:
"""Return Raredisease sex code."""
LOG.debug("Translate sex to integer code")
try:
code = PlinkSex[sex.upper()]
except KeyError:
raise ValueError(f"{sex} is not a valid sex")
return code

@property
def root(self) -> str:
Expand Down
8 changes: 6 additions & 2 deletions cg/models/cg_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,14 @@ class MipConfig(BaseModel):
script: str


class RareDiseaseConfig(CommonAppConfig):
class RarediseaseConfig(CommonAppConfig):
rannick marked this conversation as resolved.
Show resolved Hide resolved
binary_path: str | None = None
compute_env: str
conda_binary: str | None = None
conda_env: str
config_platform: str
config_params: str
config_resources: str
launch_directory: str
workflow_path: str
profile: str
Expand Down Expand Up @@ -339,7 +343,7 @@ class CGConfig(BaseModel):
mip_rd_dna: MipConfig = Field(None, alias="mip-rd-dna")
mip_rd_rna: MipConfig = Field(None, alias="mip-rd-rna")
mutant: MutantConfig = None
raredisease: RareDiseaseConfig = Field(None, alias="raredisease")
raredisease: RarediseaseConfig = Field(None, alias="raredisease")
rnafusion: RnafusionConfig = Field(None, alias="rnafusion")
taxprofiler: TaxprofilerConfig = Field(None, alias="taxprofiler")

Expand Down
10 changes: 5 additions & 5 deletions cg/models/nf_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
from cg.exc import SampleSheetError


class PipelineParameters(BaseModel):
clusterOptions: str = Field(..., alias="cluster_options")
priority: str
class WorkflowParameters(BaseModel):
input: Path = Field(..., alias="sample_sheet_path")
outdir: Path = Field(..., alias="outdir")


class NextflowSampleSheetEntry(BaseModel):
"""Nextflow samplesheet model.
"""Nextflow sample sheet model.

Attributes:
name: sample name, corresponds to case_id
name: sample name, or case id
fastq_forward_read_paths: list of all fastq read1 file paths corresponding to sample
fastq_reverse_read_paths: list of all fastq read2 file paths corresponding to sample
"""
Expand Down
Loading
Loading