• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Clinical-Genomics / cg / 9460843507

11 Jun 2024 06:42AM UTC coverage: 84.664%. First build
9460843507

Pull #3329

github

web-flow
Merge 768870696 into fa05c0cfe
Pull Request #3329: feature(downsample api parameters)

37 of 39 new or added lines in 4 files covered. (94.87%)

20376 of 24067 relevant lines covered (84.66%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.56
/cg/cli/downsample.py
1
"""cg module for downsampling reads in a sample."""
2

3
import logging
1✔
4
from pathlib import Path
1✔
5
from typing import Tuple
1✔
6

7
import click
1✔
8

9
from cg.apps.downsample.downsample import DownsampleAPI
1✔
10
from cg.apps.downsample.models import DownsampleInput
1✔
11
from cg.apps.downsample.utils import store_downsampled_sample_bundle
1✔
12
from cg.constants.constants import DRY_RUN
1✔
13
from cg.models.cg_config import CGConfig
1✔
14

15
LOG = logging.getLogger(__name__)
1✔
16

17

18
@click.group()
1✔
19
def downsample():
1✔
20
    """Downsample reads in a sample."""
21

22

23
@downsample.command(
1✔
24
    "samples",
25
    help="Downsample reads in one or multiple samples in a case. Usage: \n"
26
    "For a single sample: cg downsample samples -c supersonicturtle -cn new_case_name -i ACC1234 0.1\n"
27
    "For multiple samples:cg downsample samples -c supersonicturtle -cn new_case_name -i ACC1234 0.1 -i ACC12324 10",
28
)
29
@click.option(
1✔
30
    "-c",
31
    "--case-id",
32
    required=True,
33
    help="Case identifier used in statusdb, e.g. supersonicturtle. The case information wil be transferred to the downsampled case.",
34
)
35
@click.option(
1✔
36
    "-cn",
37
    "--case-name",
38
    required=True,
39
    help="Case name that is used as name for the downsampled case.",
40
)
41
@click.option(
1✔
42
    "-a",
43
    "--account",
44
    required=False,
45
    default=None,
46
    help="Please specify the account to use for the downsampling. Defaults to production (production) or development (stage) account if not specified.",
47
)
48
@click.option(
1✔
49
    "-i",
50
    "--input-data",
51
    required=True,
52
    nargs=2,
53
    multiple=True,
54
    help="Identifier used in statusdb, e.g. ACC1234567 and the number of reads to down sample to in millions separated by a space"
55
    " e.g. ACC1234567 30.0. Multiple inputs can be provided.",
56
)
57
@click.option(
1✔
58
    "--action",
59
    required=False,
60
    default=None,
61
    help="Set the action of the case in statusDB, e.g. HOLD. Default is to keep the action from the original case.",
62
)
63
@click.option(
1✔
64
    "--ticket",
65
    required=False,
66
    default=None,
67
    help="Set the ticket number for the case in statusDB. Default is to keep the ticket number from the original case.",
68
)
69
@click.option(
1✔
70
    "--customer-id",
71
    required=False,
72
    default=None,
73
    help="Set the customer for the case in statusDB, e.g. cust000. Default is to keep the customer from the original case.",
74
)
75
@click.option(
1✔
76
    "--data-analysis",
77
    required=False,
78
    default=None,
79
    help="Set the data analysis for the case in statusDB, e.g. MIP_DNA. Default is to keep the data analysis from the original case.",
80
)
81
@click.option(
1✔
82
    "--data-delivery",
83
    required=False,
84
    default=None,
85
    help="Set the data delivery for the case in statusDB, e.g. fastq. Default is to keep the data delivery from the original case.",
86
)
87
@DRY_RUN
1✔
88
@click.pass_obj
1✔
89
def downsample_sample(
1✔
90
    context: CGConfig,
91
    case_id: str,
92
    case_name: str,
93
    account: str | None,
94
    input_data: Tuple[str, float],
95
    action: str | None,
96
    ticket: str | None,
97
    customer_id: str | None,
98
    data_analysis: str | None,
99
    data_delivery: str | None,
100
    dry_run: bool,
101
):
102
    """Downsample reads in one or multiple samples."""
103
    downsample_api = DownsampleAPI(config=context, dry_run=dry_run)
×
104
    for sample_id, reads in input_data:
×
NEW
105
        downsample_input = DownsampleInput(
×
106
            case_id=case_id,
107
            sample_id=sample_id,
108
            number_of_reads=float(reads),
109
            case_name=case_name,
110
            account=account,
111
            action=action,
112
            ticket=ticket,
113
            customer_id=customer_id,
114
            data_analysis=data_analysis,
115
            data_delivery=data_delivery,
116
        )
117
        try:
×
NEW
118
            downsample_api.downsample_sample(downsample_input=downsample_input)
×
119
        except Exception as error:
×
120
            LOG.info(repr(error))
×
121
            continue
×
122

123

124
@downsample.command(
1✔
125
    "store",
126
    help="Store the downsampled fastq files in housekeeper.\n "
127
    "Make sure the downsample sbtach job has finished before using this command! \n"
128
    "Usage: cg downsample store ACC123145DS2C0M ACC1231DS30C0M",
129
)
130
@click.argument("sample_ids", type=str, nargs=-1)
1✔
131
@click.pass_obj
1✔
132
def store_downsampled_samples(context: CGConfig, sample_ids: list[str]):
1✔
133
    """Store fastq files for downsampled samples in Housekeeper."""
134
    for sample_id in sample_ids:
1✔
135
        downsample_dir: str = str(Path(context.downsample.downsample_dir, sample_id))
1✔
136
        LOG.debug(f"Searching for fastq files in : {downsample_dir}")
1✔
137
        try:
1✔
138
            store_downsampled_sample_bundle(
1✔
139
                housekeeper_api=context.housekeeper_api,
140
                sample_id=sample_id,
141
                fastq_file_output_directory=downsample_dir,
142
            )
143
        except Exception as error:
×
144
            LOG.info(repr(error))
×
145
            continue
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc