Skill Tracer
Skills › Scientific Agent Skills › imaging-data-commons › cli_guide.md

cli_guide.md

299 lines · skills/imaging-data-commons/references/cli_guide.md at 5f2bc03

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1# idc-index Command Line Interface Guide
2
3**Verified:** idc-index 0.12.5 CLI signatures and dry runs, 2026-09-30. Downloads below are illustrative.
4
5The `idc-index` package provides command-line tools for downloading DICOM data from the NCI Imaging Data Commons without writing Python code.
6

idc-index Command Line Interface Guide

Verified: idc-index 0.12.5 CLI signatures and dry runs, 2026-09-30. Downloads below are illustrative.

The idc-index package provides command-line tools for downloading DICOM data from the NCI Imaging Data Commons without writing Python code.

Raw lines 1 to 6
7## Installation
8
9Needs `idc-index` installed — run `python scripts/check_version.py`, which reports the installed
10version and prints the install command for the interpreter you are running.
12After installation, the `idc` command is available in your terminal.
14In 0.12.5, Boolean options take a value: `--dry-run true`, `--show-progress-bar true`,
15`--use-s5cmd-sync true`, `--quiet false`, `--validate-manifest true`. They are not bare flags.
16Always include a selection. In 0.12.5 an entirely omitted selection errors; do not rely
17on this implementation detail to limit a transfer.

Installation

Needs idc-index installed — run python scripts/check_version.py, which reports the installed version and prints the install command for the interpreter you are running.

After installation, the idc command is available in your terminal.

In 0.12.5, Boolean options take a value: --dry-run true, --show-progress-bar true, --use-s5cmd-sync true, --quiet false, --validate-manifest true. They are not bare flags. Always include a selection. In 0.12.5 an entirely omitted selection errors; do not rely on this implementation detail to limit a transfer.

Raw lines 7 to 18
Runs code python scripts/check_version.py :9
19## Available Commands
21| Command | Purpose |
22|---------|---------|
23| `idc download` | General-purpose download with auto-detection of input type |
24| `idc download-from-manifest` | Download from manifest file with validation and progress tracking |
25| `idc download-from-selection` | Filter-based download with multiple criteria |
27---

Available Commands

CommandPurpose
idc downloadGeneral-purpose download with auto-detection of input type
idc download-from-manifestDownload from manifest file with validation and progress tracking
idc download-from-selectionFilter-based download with multiple criteria

Raw lines 19 to 28
29## idc download
31General-purpose download command that intelligently interprets input. It determines whether the input corresponds to a manifest file path or a list of identifiers (collection_id, PatientID, StudyInstanceUID, SeriesInstanceUID, crdc_series_uuid).

idc download

General-purpose download command that intelligently interprets input. It determines whether the input corresponds to a manifest file path or a list of identifiers (collection_id, PatientID, StudyInstanceUID, SeriesInstanceUID, crdc_series_uuid).

Raw lines 29 to 32
33### Usage
35```bash
36# Download entire collection
37idc download rider_pilot --download-dir ./data
39# Download specific series by UID
40idc download "1.3.6.1.4.1.9328.50.1.69736" --download-dir ./data
42# Download multiple items (comma-separated)
43idc download "tcga_luad,tcga_lusc" --download-dir ./data
45# Download from manifest file (auto-detected because the file exists)
46idc download manifest.txt --download-dir ./data
47```

Usage

# Download entire collection
idc download rider_pilot --download-dir ./data

# Download specific series by UID
idc download "1.3.6.1.4.1.9328.50.1.69736" --download-dir ./data

# Download multiple items (comma-separated)
idc download "tcga_luad,tcga_lusc" --download-dir ./data

# Download from manifest file (auto-detected because the file exists)
idc download manifest.txt --download-dir ./data
Raw lines 33 to 48
49### Options
51| Option | Description |
52|--------|-------------|
53| `--download-dir` | Destination directory (default: current directory) |
54| `--dir-template` | Directory hierarchy template (default: `%collection_id/%PatientID/%StudyInstanceUID/%Modality_%SeriesInstanceUID`) |
55| `--log-level` | Verbosity: debug, info, warning, error, critical |

Options

OptionDescription
--download-dirDestination directory (default: current directory)
--dir-templateDirectory hierarchy template (default: %collection_id/%PatientID/%StudyInstanceUID/%Modality_%SeriesInstanceUID)
--log-levelVerbosity: debug, info, warning, error, critical
Raw lines 49 to 56
57### Directory Template Variables
59The same templates apply in Python, where the argument is `dirTemplate=` rather than the
60`--dir-template` flag. The default is
61`%collection_id/%PatientID/%StudyInstanceUID/%Modality_%SeriesInstanceUID`:
63```python
64# Simplified hierarchy (omit StudyInstanceUID level)
65client.download_from_selection(
66 downloadDir="./data",
67 collection_id="tcga_luad",
68 dirTemplate="%collection_id/%PatientID/%Modality"
70# Results in: ./data/tcga_luad/TCGA-05-4244/CT/
72# dirTemplate="" disables the hierarchy, writing every file straight into downloadDir
73```
75Use these variables in `--dir-template` to organize downloads:
77- `%collection_id` - Collection identifier
78- `%PatientID` - Patient identifier
79- `%StudyInstanceUID` - Study UID
80- `%SeriesInstanceUID` - Series UID
81- `%Modality` - Imaging modality (CT, MR, PT, etc.)
83**Examples:**
85```bash
86# Flat structure (all files in one directory)
87idc download rider_pilot --download-dir ./data --dir-template ""
89# Simplified hierarchy
90idc download rider_pilot --download-dir ./data --dir-template "%collection_id/%PatientID/%Modality"
91```
93---

Directory Template Variables

The same templates apply in Python, where the argument is dirTemplate= rather than the --dir-template flag. The default is %collection_id/%PatientID/%StudyInstanceUID/%Modality_%SeriesInstanceUID:

# Simplified hierarchy (omit StudyInstanceUID level)
client.download_from_selection(
    downloadDir="./data",
    collection_id="tcga_luad",
    dirTemplate="%collection_id/%PatientID/%Modality"
)
# Results in: ./data/tcga_luad/TCGA-05-4244/CT/

# dirTemplate="" disables the hierarchy, writing every file straight into downloadDir

Use these variables in --dir-template to organize downloads:

  • %collection_id - Collection identifier
  • %PatientID - Patient identifier
  • %StudyInstanceUID - Study UID
  • %SeriesInstanceUID - Series UID
  • %Modality - Imaging modality (CT, MR, PT, etc.)

Examples:

# Flat structure (all files in one directory)
idc download rider_pilot --download-dir ./data --dir-template ""

# Simplified hierarchy
idc download rider_pilot --download-dir ./data --dir-template "%collection_id/%PatientID/%Modality"

Raw lines 57 to 94
95## idc download-from-manifest
97Specialized for downloading from manifest files with built-in validation, progress tracking, and resume capability.

idc download-from-manifest

Specialized for downloading from manifest files with built-in validation, progress tracking, and resume capability.

Raw lines 95 to 98
99### Usage
101```bash
102# Basic download from manifest
103idc download-from-manifest --manifest-file cohort.txt --download-dir ./data
105# With progress bar and validation
106idc download-from-manifest --manifest-file cohort.txt --download-dir ./data --show-progress-bar true
108# Resume interrupted download with s5cmd sync
109idc download-from-manifest --manifest-file cohort.txt --download-dir ./data --use-s5cmd-sync true
110```

Usage

# Basic download from manifest
idc download-from-manifest --manifest-file cohort.txt --download-dir ./data

# With progress bar and validation
idc download-from-manifest --manifest-file cohort.txt --download-dir ./data --show-progress-bar true

# Resume interrupted download with s5cmd sync
idc download-from-manifest --manifest-file cohort.txt --download-dir ./data --use-s5cmd-sync true
Raw lines 99 to 111
112### Options
114| Option | Description |
115|--------|-------------|
116| `--manifest-file` | **Required.** Path to manifest file containing S3 URLs |
117| `--download-dir` | **Required.** Destination directory |
118| `--validate-manifest true` | Validate manifest before download (enabled by default) |
119| `--show-progress-bar true` | Display download progress |
120| `--use-s5cmd-sync true` | Enable resumable downloads - skips already-downloaded files |
121| `--quiet true` | Suppress subprocess output |
122| `--dir-template` | Directory hierarchy template |
123| `--log-level` | Logging verbosity |

Options

OptionDescription
--manifest-fileRequired. Path to manifest file containing S3 URLs
--download-dirRequired. Destination directory
--validate-manifest trueValidate manifest before download (enabled by default)
--show-progress-bar trueDisplay download progress
--use-s5cmd-sync trueEnable resumable downloads - skips already-downloaded files
--quiet trueSuppress subprocess output
--dir-templateDirectory hierarchy template
--log-levelLogging verbosity
Raw lines 112 to 124
125### Manifest File Format
127Manifest files contain S3 URLs, one per line. A CSV of bare DICOM UIDs is not a download
128manifest; `idc download existing-file.csv` treats it as a manifest and fails validation:
130```
131s3://idc-open-data/cb09464a-c5cc-4428-9339-d7fa87cfe837/*
132s3://idc-open-data/88f3990d-bdef-49cd-9b2b-4787767240f2/*
133```
135**How to get a manifest file:**
1371. **IDC Portal**: Export cohort selection as manifest
1382. **Python query**: Generate from SQL results
140```python
141from idc_index import IDCClient
143client = IDCClient()
144results = client.sql_query("""
145 SELECT series_aws_url
146 FROM index
147 WHERE collection_id = 'rider_pilot' AND Modality = 'CT'
148""")
150with open('ct_manifest.txt', 'w') as f:
151 for url in results['series_aws_url']:
152 f.write(url + '\n')
153```
155---

Manifest File Format

Manifest files contain S3 URLs, one per line. A CSV of bare DICOM UIDs is not a download manifest; idc download existing-file.csv treats it as a manifest and fails validation:

s3://idc-open-data/cb09464a-c5cc-4428-9339-d7fa87cfe837/*
s3://idc-open-data/88f3990d-bdef-49cd-9b2b-4787767240f2/*

How to get a manifest file:

  1. IDC Portal: Export cohort selection as manifest
  2. Python query: Generate from SQL results
from idc_index import IDCClient

client = IDCClient()
results = client.sql_query("""
    SELECT series_aws_url
    FROM index
    WHERE collection_id = 'rider_pilot' AND Modality = 'CT'
""")

with open('ct_manifest.txt', 'w') as f:
    for url in results['series_aws_url']:
        f.write(url + '\n')

Raw lines 125 to 156
157## idc download-from-selection
159Download data using one explicit identifier selection. In 0.12.5 the SDK uses the most
160specific supplied selector, not the intersection of all selectors: CRDC UUID, SOP UID
161(Python only), series UID, study UID, patient ID, then collection ID. Higher-level filters
162are ignored when a more specific one is supplied. For a conjunction, query SQL first and
163pass the resulting series UIDs or URL manifest.

idc download-from-selection

Download data using one explicit identifier selection. In 0.12.5 the SDK uses the most specific supplied selector, not the intersection of all selectors: CRDC UUID, SOP UID (Python only), series UID, study UID, patient ID, then collection ID. Higher-level filters are ignored when a more specific one is supplied. For a conjunction, query SQL first and pass the resulting series UIDs or URL manifest.

Raw lines 157 to 164
165### Usage
167```bash
168# Download by collection
169idc download-from-selection --collection-id rider_pilot --download-dir ./data
171# Download specific series
172idc download-from-selection --series-instance-uid "1.3.6.1.4.1.9328.50.1.69736" --download-dir ./data
174# Patient selection (the more-specific patient ID takes precedence over collection)
175idc download-from-selection --collection-id nlst --patient-id "100004" --download-dir ./data
177# Dry run - see what would be downloaded without actually downloading
178idc download-from-selection --collection-id tcga_luad --dry-run true --download-dir ./data
179```

Usage

# Download by collection
idc download-from-selection --collection-id rider_pilot --download-dir ./data

# Download specific series
idc download-from-selection --series-instance-uid "1.3.6.1.4.1.9328.50.1.69736" --download-dir ./data

# Patient selection (the more-specific patient ID takes precedence over collection)
idc download-from-selection --collection-id nlst --patient-id "100004" --download-dir ./data

# Dry run - see what would be downloaded without actually downloading
idc download-from-selection --collection-id tcga_luad --dry-run true --download-dir ./data
Raw lines 165 to 180
181### Options
183| Option | Description |
184|--------|-------------|
185| `--download-dir` | **Required.** Destination directory |
186| `--collection-id` | Filter by collection identifier |
187| `--patient-id` | Filter by patient identifier |
188| `--study-instance-uid` | Filter by study UID |
189| `--series-instance-uid` | Filter by series UID |
190| `--crdc-series-uuid` | Filter by CRDC UUID |
191| `--dry-run true` | Calculate cohort size without downloading |
192| `--show-progress-bar true` | Display download progress |
193| `--use-s5cmd-sync true` | Enable resumable downloads |
194| `--dir-template` | Directory hierarchy template |

Options

OptionDescription
--download-dirRequired. Destination directory
--collection-idFilter by collection identifier
--patient-idFilter by patient identifier
--study-instance-uidFilter by study UID
--series-instance-uidFilter by series UID
--crdc-series-uuidFilter by CRDC UUID
--dry-run trueCalculate cohort size without downloading
--show-progress-bar trueDisplay download progress
--use-s5cmd-sync trueEnable resumable downloads
--dir-templateDirectory hierarchy template
Raw lines 181 to 195
196### Dry Run for Size Estimation
198Use `--dry-run` to estimate download size before committing:
200```bash
201idc download-from-selection --collection-id nlst --dry-run true --download-dir ./data
202```
204This shows:
205- Number of series matching filters
206- Total download size
207- No files are downloaded
209---

Dry Run for Size Estimation

Use --dry-run to estimate download size before committing:

idc download-from-selection --collection-id nlst --dry-run true --download-dir ./data

This shows:

  • Number of series matching filters
  • Total download size
  • No files are downloaded

Raw lines 196 to 210
211## Common Workflows

Common Workflows

Raw lines 211 to 212
213### 1. Download Small Collection for Testing
215```bash
216# rider_pilot is about 11 GB in the reviewed snapshot; estimate before transferring
217idc download rider_pilot --download-dir ./test_data
218```

1. Download Small Collection for Testing

# rider_pilot is about 11 GB in the reviewed snapshot; estimate before transferring
idc download rider_pilot --download-dir ./test_data
Raw lines 213 to 219
220### 2. Large Dataset with Progress and Resume
222```bash
223# Use s5cmd sync for large downloads - can resume if interrupted
224idc download-from-selection \
225 --collection-id nlst \
226 --download-dir ./nlst_data \
227 --show-progress-bar true \
228 --use-s5cmd-sync true
229```

2. Large Dataset with Progress and Resume

# Use s5cmd sync for large downloads - can resume if interrupted
idc download-from-selection \
    --collection-id nlst \
    --download-dir ./nlst_data \
    --show-progress-bar true \
    --use-s5cmd-sync true
Raw lines 220 to 230
231### 3. Estimate Size Before Download
233```bash
234# Check size first
235idc download-from-selection --collection-id tcga_luad --dry-run true --download-dir ./data
237# Then download if size is acceptable
238idc download-from-selection --collection-id tcga_luad --download-dir ./data
239```

3. Estimate Size Before Download

# Check size first
idc download-from-selection --collection-id tcga_luad --dry-run true --download-dir ./data

# Then download if size is acceptable
idc download-from-selection --collection-id tcga_luad --download-dir ./data
Raw lines 231 to 240
241### 4. Download Specific Modality via Python + CLI
243```python
244# First, query for public series URLs in Python
245from idc_index import IDCClient
247client = IDCClient()
248results = client.sql_query("""
249 SELECT series_aws_url
250 FROM index
251 WHERE collection_id = 'nlst'
252 AND Modality = 'CT'
253 AND BodyPartExamined = 'CHEST'
254 LIMIT 50
255""")
257# Save to manifest
258results['series_aws_url'].to_csv('my_series.txt', index=False, header=False)
259```
261```bash
262# Then download via CLI
263idc download-from-manifest --manifest-file my_series.txt --download-dir ./lung_ct
264```
266---

4. Download Specific Modality via Python + CLI

# First, query for public series URLs in Python
from idc_index import IDCClient

client = IDCClient()
results = client.sql_query("""
    SELECT series_aws_url
    FROM index
    WHERE collection_id = 'nlst'
      AND Modality = 'CT'
      AND BodyPartExamined = 'CHEST'
    LIMIT 50
""")

# Save to manifest
results['series_aws_url'].to_csv('my_series.txt', index=False, header=False)
# Then download via CLI
idc download-from-manifest --manifest-file my_series.txt --download-dir ./lung_ct

Raw lines 241 to 267
268## Built-in Safety Features
270The CLI includes several safety features:
272- **Disk space checking**: Verifies sufficient space before starting downloads
273- **Manifest validation**: Validates manifest file format by default
274- **Progress tracking**: Optional progress bar for monitoring large downloads
275- **Resume capability**: Use `--use-s5cmd-sync` to continue interrupted downloads
277---

Built-in Safety Features

The CLI includes several safety features:

  • Disk space checking: Verifies sufficient space before starting downloads
  • Manifest validation: Validates manifest file format by default
  • Progress tracking: Optional progress bar for monitoring large downloads
  • Resume capability: Use --use-s5cmd-sync to continue interrupted downloads

Raw lines 268 to 278
279## Troubleshooting

Troubleshooting

Raw lines 279 to 280
281### Download Interrupted
283Use `--use-s5cmd-sync` to resume:
285```bash
286idc download-from-manifest --manifest-file cohort.txt --download-dir ./data --use-s5cmd-sync true
287```

Download Interrupted

Use --use-s5cmd-sync to resume:

idc download-from-manifest --manifest-file cohort.txt --download-dir ./data --use-s5cmd-sync true
Raw lines 281 to 288
289### Connection Timeout
291For unstable networks, download in smaller batches using Python to generate multiple manifests, then download sequentially.
293---

Connection Timeout

For unstable networks, download in smaller batches using Python to generate multiple manifests, then download sequentially.


Raw lines 289 to 294
295## See Also
297- [idc-index Documentation](https://idc-index.readthedocs.io/)
298- [IDC Portal](https://portal.imaging.datacommons.cancer.gov/) - Interactive cohort building
299- [IDC Tutorials](https://github.com/ImagingDataCommons/IDC-Tutorials)