|
11 | 11 | import click |
12 | 12 |
|
13 | 13 | from . import index |
14 | | -from .index import IDCClient |
| 14 | +from .index import IDCClient, IDCClientInsufficientDiskSpaceError |
15 | 15 |
|
16 | 16 | # Set up logging for the CLI module |
17 | 17 | logging.basicConfig(format="%(asctime)s - %(message)s", level=logging.DEBUG) |
@@ -190,19 +190,22 @@ def download_from_selection( |
190 | 190 | logger_cli.debug(f"use_s5cmd_sync: {use_s5cmd_sync}") |
191 | 191 | logger_cli.debug(f"dirTemplate: {dir_template}") |
192 | 192 |
|
193 | | - client.download_from_selection( |
194 | | - download_dir, |
195 | | - dry_run=dry_run, |
196 | | - collection_id=collection_id, |
197 | | - patientId=patient_id, |
198 | | - studyInstanceUID=study_instance_uid, |
199 | | - seriesInstanceUID=series_instance_uid, |
200 | | - crdc_series_uuid=crdc_series_uuid, |
201 | | - quiet=quiet, |
202 | | - show_progress_bar=show_progress_bar, |
203 | | - use_s5cmd_sync=use_s5cmd_sync, |
204 | | - dirTemplate=dir_template, |
205 | | - ) |
| 193 | + try: |
| 194 | + client.download_from_selection( |
| 195 | + download_dir, |
| 196 | + dry_run=dry_run, |
| 197 | + collection_id=collection_id, |
| 198 | + patientId=patient_id, |
| 199 | + studyInstanceUID=study_instance_uid, |
| 200 | + seriesInstanceUID=series_instance_uid, |
| 201 | + crdc_series_uuid=crdc_series_uuid, |
| 202 | + quiet=quiet, |
| 203 | + show_progress_bar=show_progress_bar, |
| 204 | + use_s5cmd_sync=use_s5cmd_sync, |
| 205 | + dirTemplate=dir_template, |
| 206 | + ) |
| 207 | + except IDCClientInsufficientDiskSpaceError as e: |
| 208 | + logger_cli.error(e.message) |
206 | 209 |
|
207 | 210 |
|
208 | 211 | @idc.command() |
@@ -286,15 +289,18 @@ def download_from_manifest( |
286 | 289 | logger_cli.debug(f"dirTemplate: {dir_template}") |
287 | 290 |
|
288 | 291 | # Call IDCClient's download_from_manifest method with the provided parameters |
289 | | - client.download_from_manifest( |
290 | | - manifestFile=manifest_file, |
291 | | - downloadDir=download_dir, |
292 | | - quiet=quiet, |
293 | | - validate_manifest=validate_manifest, |
294 | | - show_progress_bar=show_progress_bar, |
295 | | - use_s5cmd_sync=use_s5cmd_sync, |
296 | | - dirTemplate=dir_template, |
297 | | - ) |
| 292 | + try: |
| 293 | + client.download_from_manifest( |
| 294 | + manifestFile=manifest_file, |
| 295 | + downloadDir=download_dir, |
| 296 | + quiet=quiet, |
| 297 | + validate_manifest=validate_manifest, |
| 298 | + show_progress_bar=show_progress_bar, |
| 299 | + use_s5cmd_sync=use_s5cmd_sync, |
| 300 | + dirTemplate=dir_template, |
| 301 | + ) |
| 302 | + except IDCClientInsufficientDiskSpaceError as e: |
| 303 | + logger_cli.error(e.message) |
298 | 304 |
|
299 | 305 |
|
300 | 306 | @idc.command() |
@@ -339,65 +345,68 @@ def download(generic_argument, download_dir, dir_template, log_level): |
339 | 345 | else: |
340 | 346 | download_dir = Path.cwd() |
341 | 347 |
|
342 | | - if ( |
343 | | - len(generic_argument) < _get_max_path_length() |
344 | | - and Path(generic_argument).is_file() |
345 | | - ): |
346 | | - # Parse the input parameters and pass them to IDC |
347 | | - logger_cli.info("Detected manifest file, downloading from manifest.") |
348 | | - client.download_from_manifest( |
349 | | - generic_argument, downloadDir=download_dir, dirTemplate=dir_template |
350 | | - ) |
351 | | - # this is not a file manifest |
352 | | - else: |
353 | | - # Split the input string and filter out any empty values |
354 | | - item_ids = [item for item in generic_argument.split(",") if item] |
355 | | - |
356 | | - if not item_ids: |
357 | | - logger_cli.error("No valid IDs provided.") |
358 | | - |
359 | | - index_df = client.index |
360 | | - |
361 | | - def check_and_download(column_name, item_ids, download_dir, kwarg_name): |
362 | | - matches = index_df[column_name].isin(item_ids) |
363 | | - matched_ids = index_df[column_name][matches].unique().tolist() |
364 | | - if not matched_ids: |
365 | | - return False |
366 | | - unmatched_ids = list(set(item_ids) - set(matched_ids)) |
367 | | - if unmatched_ids: |
368 | | - logger_cli.debug( |
369 | | - f"Partial match for {column_name}: matched {matched_ids}, unmatched {unmatched_ids}" |
370 | | - ) |
371 | | - logger_cli.info(f"Identified matching {column_name}: {matched_ids}") |
372 | | - client.download_from_selection( |
373 | | - **{ |
374 | | - kwarg_name: matched_ids, |
375 | | - "downloadDir": download_dir, |
376 | | - "dirTemplate": dir_template, |
377 | | - } |
| 348 | + try: |
| 349 | + if ( |
| 350 | + len(generic_argument) < _get_max_path_length() |
| 351 | + and Path(generic_argument).is_file() |
| 352 | + ): |
| 353 | + # Parse the input parameters and pass them to IDC |
| 354 | + logger_cli.info("Detected manifest file, downloading from manifest.") |
| 355 | + client.download_from_manifest( |
| 356 | + generic_argument, downloadDir=download_dir, dirTemplate=dir_template |
378 | 357 | ) |
379 | | - return True |
| 358 | + # this is not a file manifest |
| 359 | + else: |
| 360 | + # Split the input string and filter out any empty values |
| 361 | + item_ids = [item for item in generic_argument.split(",") if item] |
| 362 | + |
| 363 | + if not item_ids: |
| 364 | + logger_cli.error("No valid IDs provided.") |
| 365 | + |
| 366 | + index_df = client.index |
| 367 | + |
| 368 | + def check_and_download(column_name, item_ids, download_dir, kwarg_name): |
| 369 | + matches = index_df[column_name].isin(item_ids) |
| 370 | + matched_ids = index_df[column_name][matches].unique().tolist() |
| 371 | + if not matched_ids: |
| 372 | + return False |
| 373 | + unmatched_ids = list(set(item_ids) - set(matched_ids)) |
| 374 | + if unmatched_ids: |
| 375 | + logger_cli.debug( |
| 376 | + f"Partial match for {column_name}: matched {matched_ids}, unmatched {unmatched_ids}" |
| 377 | + ) |
| 378 | + logger_cli.info(f"Identified matching {column_name}: {matched_ids}") |
| 379 | + client.download_from_selection( |
| 380 | + **{ |
| 381 | + kwarg_name: matched_ids, |
| 382 | + "downloadDir": download_dir, |
| 383 | + "dirTemplate": dir_template, |
| 384 | + } |
| 385 | + ) |
| 386 | + return True |
380 | 387 |
|
381 | | - matches_found = 0 |
382 | | - matches_found += check_and_download( |
383 | | - "collection_id", item_ids, download_dir, "collection_id" |
384 | | - ) |
385 | | - matches_found += check_and_download( |
386 | | - "PatientID", item_ids, download_dir, "patientId" |
387 | | - ) |
388 | | - matches_found += check_and_download( |
389 | | - "StudyInstanceUID", item_ids, download_dir, "studyInstanceUID" |
390 | | - ) |
391 | | - matches_found += check_and_download( |
392 | | - "SeriesInstanceUID", item_ids, download_dir, "seriesInstanceUID" |
393 | | - ) |
394 | | - matches_found += check_and_download( |
395 | | - "crdc_series_uuid", item_ids, download_dir, "crdc_series_uuid" |
396 | | - ) |
397 | | - if not matches_found: |
398 | | - logger_cli.error( |
399 | | - "None of the values passed matched any of the identifiers: collection_id, PatientID, StudyInstanceUID, SeriesInstanceUID, crdc_series_uuid." |
| 388 | + matches_found = 0 |
| 389 | + matches_found += check_and_download( |
| 390 | + "collection_id", item_ids, download_dir, "collection_id" |
400 | 391 | ) |
| 392 | + matches_found += check_and_download( |
| 393 | + "PatientID", item_ids, download_dir, "patientId" |
| 394 | + ) |
| 395 | + matches_found += check_and_download( |
| 396 | + "StudyInstanceUID", item_ids, download_dir, "studyInstanceUID" |
| 397 | + ) |
| 398 | + matches_found += check_and_download( |
| 399 | + "SeriesInstanceUID", item_ids, download_dir, "seriesInstanceUID" |
| 400 | + ) |
| 401 | + matches_found += check_and_download( |
| 402 | + "crdc_series_uuid", item_ids, download_dir, "crdc_series_uuid" |
| 403 | + ) |
| 404 | + if not matches_found: |
| 405 | + logger_cli.error( |
| 406 | + "None of the values passed matched any of the identifiers: collection_id, PatientID, StudyInstanceUID, SeriesInstanceUID, crdc_series_uuid." |
| 407 | + ) |
| 408 | + except IDCClientInsufficientDiskSpaceError as e: |
| 409 | + logger_cli.error(e.message) |
401 | 410 |
|
402 | 411 |
|
403 | 412 | if __name__ == "__main__": |
|
0 commit comments