Introduction to TCIApathfinder

api_key <- Sys.getenv("TCIA_API_KEY")
if (identical(api_key, "")) {
  knitr::opts_chunk$set(eval = FALSE)
  message("Note: code examples will not be evaluated because the system does not have a valid API key installed.")


From within R:


From GitHub:

# install.packages("devtools")


An API key is required to access data from TCIA. To obtain and correctly store your API key:

  1. Request a key from TCIA by following the instructions here.

  2. Create a text file in your home directory (~/) called .Renviron.

  3. Create the contents of the .Renviron file like this, making sure the last line in the file is empty. Otherwise, R will silently fail to load the file.

    ``` TCIA_API_KEY=xxx-xxx-xxx-xxx


  4. Restart R. .Renviron is only processed at the beginning of an R session.


Load the package:


Get the names of all TCIA collections:

collections <- get_collection_names()

Get the names of all imaging modalities

modalities <- get_modality_names()

Note: a collection or body part can be specified to narrow down results.

Get the names of all body parts studied:

body_parts <- get_body_part_names()

Note: a collection or modality can be specified to narrow down results.

Get information for all patients in a collection

patients_tcga_brca <- get_patient_info(collection = "TCGA-BRCA")

Note: if no collection is passed, patients for all collections are returned.

Get all image series based on criteria

series <- get_series_info(patient_id = "TCGA-AR-A1AQ")

Note: other ways to narrow down results include

Get detailed information on all imaging studies for a patient

studies <- get_patient_studies(patient_id = "TCGA-AR-A1AQ")

The variables in studies$patient_studies correspond to the fields of a PatientStudy object as described in the API documentation.

Note: other ways to narrow down results include a collection or a study instance UID.

Get all imaging studies for a collection

studies_tcga_brca <- get_studies_in_collection(collection = "TCGA-BRCA")

Note: a patient ID can be provided to further narrow down results.

Get individual DICOM image IDs for an image series

sop_uids <- get_sop_instance_uids(
  series_instance_uid = "")

Download a single DICOM image

im <- save_single_image(series_instance_uid = "",
                  sop_instance_uid = "")

Note: a file name can be provided to override the original file name.

Download an image series and extract it

ser <- save_image_series(series_instance_uid = "",
                         out_file_name = "")
zip <- ser$out_file
extracted <- extract_image_series(zip)

Download, save and extract an image series, optionally to a temporary location

ser <- save_extracted_image_series(series_instance_uid = "")

Additional functions

See package documentation for further details:

Try the TCIApathfinder package in your browser

Any scripts or data that you put into this service are public.

TCIApathfinder documentation built on Sept. 21, 2019, 5:03 p.m.