|
18 | 18 | FlowCellSampleBcl2Fastq,
|
19 | 19 | FlowCellSampleBCLConvert,
|
20 | 20 | )
|
| 21 | +from cg.apps.downsample.downsample import DownSampleAPI |
21 | 22 | from cg.apps.gens import GensAPI
|
22 | 23 | from cg.apps.gt import GenotypeAPI
|
23 | 24 | from cg.apps.hermes.hermes_api import HermesApi
|
@@ -3259,3 +3260,113 @@ def flow_cell_encryption_api(
|
3259 | 3260 | )
|
3260 | 3261 | flow_cell_encryption_api.slurm_api.set_dry_run(dry_run=True)
|
3261 | 3262 | return flow_cell_encryption_api
|
| 3263 | + |
| 3264 | + |
| 3265 | +# Downsample |
| 3266 | +@pytest.fixture() |
| 3267 | +def store_with_case_and_sample_with_reads( |
| 3268 | + store: Store, |
| 3269 | + helpers: StoreHelpers, |
| 3270 | + downsample_case_internal_id: str, |
| 3271 | + downsample_sample_internal_id_1: str, |
| 3272 | + downsample_sample_internal_id_2: str, |
| 3273 | +) -> Store: |
| 3274 | + """Return a store with a case and a sample with reads.""" |
| 3275 | + case: Family = helpers.add_case(store=store, internal_id=downsample_case_internal_id) |
| 3276 | + |
| 3277 | + for sample_internal_id in [downsample_sample_internal_id_1, downsample_sample_internal_id_2]: |
| 3278 | + helpers.add_sample( |
| 3279 | + store=store, |
| 3280 | + internal_id=sample_internal_id, |
| 3281 | + customer_id=case.customer_id, |
| 3282 | + reads=100_000_000, |
| 3283 | + ) |
| 3284 | + sample: Sample = store.get_sample_by_internal_id(internal_id=sample_internal_id) |
| 3285 | + helpers.add_relationship(store=store, case=case, sample=sample) |
| 3286 | + |
| 3287 | + return store |
| 3288 | + |
| 3289 | + |
| 3290 | +@pytest.fixture() |
| 3291 | +def downsample_case_internal_id() -> str: |
| 3292 | + """Return a case internal id.""" |
| 3293 | + return "supersonicturtle" |
| 3294 | + |
| 3295 | + |
| 3296 | +@pytest.fixture() |
| 3297 | +def downsample_sample_internal_id_1() -> str: |
| 3298 | + """Return a sample internal id.""" |
| 3299 | + return "ACC12345675213" |
| 3300 | + |
| 3301 | + |
| 3302 | +@pytest.fixture() |
| 3303 | +def downsample_sample_internal_id_2() -> str: |
| 3304 | + """Return a sample internal id.""" |
| 3305 | + return "ACC12345684213" |
| 3306 | + |
| 3307 | + |
| 3308 | +@pytest.fixture() |
| 3309 | +def number_of_reads_in_millions() -> int: |
| 3310 | + """Return a number of reads in millions.""" |
| 3311 | + return 50 |
| 3312 | + |
| 3313 | + |
| 3314 | +@pytest.fixture() |
| 3315 | +def downsample_hk_api( |
| 3316 | + real_housekeeper_api: HousekeeperAPI, |
| 3317 | + fastq_file: Path, |
| 3318 | + downsample_sample_internal_id_1: str, |
| 3319 | + downsample_sample_internal_id_2: str, |
| 3320 | + timestamp_yesterday: str, |
| 3321 | + helpers: StoreHelpers, |
| 3322 | + tmp_path_factory, |
| 3323 | +) -> HousekeeperAPI: |
| 3324 | + """Return a Housekeeper API with a real database.""" |
| 3325 | + for sample_internal_id in [downsample_sample_internal_id_1, downsample_sample_internal_id_2]: |
| 3326 | + tmp_fastq_file = tmp_path_factory.mktemp(f"{sample_internal_id}.fastq.gz") |
| 3327 | + downsample_bundle: dict = { |
| 3328 | + "name": sample_internal_id, |
| 3329 | + "created": timestamp_yesterday, |
| 3330 | + "expires": timestamp_yesterday, |
| 3331 | + "files": [ |
| 3332 | + { |
| 3333 | + "path": tmp_fastq_file.as_posix(), |
| 3334 | + "archive": False, |
| 3335 | + "tags": [SequencingFileTag.FASTQ, sample_internal_id], |
| 3336 | + } |
| 3337 | + ], |
| 3338 | + } |
| 3339 | + helpers.ensure_hk_bundle(store=real_housekeeper_api, bundle_data=downsample_bundle) |
| 3340 | + return real_housekeeper_api |
| 3341 | + |
| 3342 | + |
| 3343 | +@pytest.fixture() |
| 3344 | +def downsample_context( |
| 3345 | + cg_context: CGConfig, |
| 3346 | + store_with_case_and_sample_with_reads: Store, |
| 3347 | + downsample_hk_api: HousekeeperAPI, |
| 3348 | +) -> CGConfig: |
| 3349 | + """Return cg context with added Store and Housekeeper API.""" |
| 3350 | + cg_context.status_db_ = store_with_case_and_sample_with_reads |
| 3351 | + cg_context.housekeeper_api_ = downsample_hk_api |
| 3352 | + return cg_context |
| 3353 | + |
| 3354 | + |
| 3355 | +@pytest.fixture() |
| 3356 | +def downsample_api( |
| 3357 | + downsample_context: CGConfig, |
| 3358 | + store_with_case_and_sample_with_reads: Store, |
| 3359 | + downsample_hk_api: HousekeeperAPI, |
| 3360 | + downsample_sample_internal_id_1: str, |
| 3361 | + downsample_case_internal_id: str, |
| 3362 | + number_of_reads_in_millions: int, |
| 3363 | + tmp_path_factory, |
| 3364 | +) -> DownSampleAPI: |
| 3365 | + """Return a DownsampleAPI.""" |
| 3366 | + downsample_api = DownSampleAPI( |
| 3367 | + config=downsample_context, |
| 3368 | + sample_id=downsample_sample_internal_id_1, |
| 3369 | + number_of_reads=number_of_reads_in_millions, |
| 3370 | + case_id=downsample_case_internal_id, |
| 3371 | + ) |
| 3372 | + return downsample_api |
0 commit comments