Skip to content

Commit

Permalink
Updated to use newer tcia_utils version that doesn't require api_url,…
Browse files Browse the repository at this point in the history
… and to use simpleDicomViewer which replaces the old viewer functions in nbia.py
  • Loading branch information
kirbyju committed Oct 1, 2024
1 parent 6df6bf6 commit f171f35
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions CPTAC/CPTAC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"source": [
"# Analyzing DICOM images and annotations from the CPTAC datasets hosted on TCIA\n",
"\n",
"This notebook is focused on accessing the **\"Clinical Proteomic Tumor Analysis Consortium\"** collections hosted on [The Cancer Imaging Archive(TCIA)](https://cancerimagingarchive.net). These datasets include radiology and histopathology images hosted on TCIA as well as proteomic, genomic and clinical data hosted in the Proteomic Data Commons and Genomic Data Commons. The National Cancer Institute has also funded an activity to generate and publish annotations (3d segmentation labels and seed points) on TCIA to help jumpstart research on tumor detection, auto-segmentation methods and generating radiomics imaging features which can be compared with the proteomic, genomic and clinical data. \n",
"This notebook is focused on accessing the **\"Clinical Proteomic Tumor Analysis Consortium\"** collections hosted on [The Cancer Imaging Archive(TCIA)](https://cancerimagingarchive.net). These datasets include radiology and histopathology images hosted on TCIA as well as proteomic, genomic and clinical data hosted in the Proteomic Data Commons (PDC) and Genomic Data Commons (GDC). The National Cancer Institute has also funded an activity to generate and publish annotations (3d segmentation labels and seed points) on TCIA to help jumpstart research on tumor detection, auto-segmentation methods and generating radiomics imaging features which can be compared with the proteomic, genomic and clinical data. **This notebook is focused on demonstrating how to access the radiology images and tumor annotations to generate radiomic features using [MIRP](https://github.com/oncoray/mirp), as well as how to pull the corresponding clinical data from GDC to facilitate correlation with the image features.**\n",
"\n",
"**Note:** Users of this notebook will likely find the [CPTAC python package](https://github.com/PayneLab/cptac) useful for working with the non-image data types. This repository includes documentation about how to access genomic, proteomic and clinical data for CPTAC subjects using python dataframes.\n"
]
Expand All @@ -34,7 +34,7 @@
"source": [
"# 1 Setup\n",
"\n",
"The following installs and imports **[tcia_utils](https://pypi.org/project/tcia-utils/)**, which contains a variety of useful functions for accessing TCIA via Python and Juptyter Notebooks. It also ensures the necessary imports are performed. Finally, there are a few conditional steps that will execute if you're using Google Colab to adjust log settings."
"The following installs and imports the necessary Python packages and runs a few conditional steps if you're using Google Colab to adjust log settings."
]
},
{
Expand All @@ -50,7 +50,11 @@
"# install tcia utils, mirp and altair\n",
"!{sys.executable} -m pip install --upgrade -q tcia_utils\n",
"!{sys.executable} -m pip install --upgrade -q altair\n",
"!{sys.executable} -m pip install --upgrade -q mirp"
"!{sys.executable} -m pip install --upgrade -q mirp\n",
"\n",
"# install simpleDicomViewer and forked pydicom-seg dependency\n",
"!{sys.executable} -m pip install --upgrade -q git+https://github.com/kirbyju/pydicom-seg.git@master\n",
"!{sys.executable} -m pip install --upgrade -q simpleDicomViewer"
]
},
{
Expand All @@ -67,6 +71,7 @@
"import pandas as pd\n",
"import altair as alt\n",
"from tcia_utils import nbia\n",
"from simpleDicomViewer import dicomViewer\n",
"from mirp import extract_mask_labels\n",
"from mirp import extract_image_parameters\n",
"from mirp import extract_images\n",
Expand Down Expand Up @@ -141,24 +146,7 @@
"# 4 Accessing the REST APIs\n",
"The [NBIA REST APIs](https://wiki.cancerimagingarchive.net/x/ZoATBg) are another useful way for TCIA users to query metadata and download image data, which will be the focus of the rest of this notebook. We'll rely heavily on [tcia_utils](https://pypi.org/project/tcia-utils/) to simplify accessing them.\n",
"\n",
"If you have questions that are not covered in this notebook you can find many additional examples in the other notebooks at https://github.com/kirbyju/TCIA_Notebooks.\n",
"\n",
"Before we get started, we need to set the api_url parameter to \"restricted\" and create an API access token for those of you accessing CPTAC-HNSCC. If you selected a different collection, this will just set the api_url parameter to access the public APIs that don't require logging in."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "HaR2eLw8E6FZ"
},
"outputs": [],
"source": [
"if collection == \"CPTAC-HNSCC\":\n",
" api_url = \"restricted\"\n",
" nbia.getToken()\n",
"else:\n",
" api_url = \"\""
"If you have questions that are not covered in this notebook you can find many additional examples in the other notebooks at https://github.com/kirbyju/TCIA_Notebooks."
]
},
{
Expand Down Expand Up @@ -229,7 +217,7 @@
},
"outputs": [],
"source": [
"df = nbia.getPatient(collection, format = \"df\", api_url = api_url)\n",
"df = nbia.getPatient(collection, format = \"df\")\n",
"\n",
"display(df)"
]
Expand All @@ -252,7 +240,7 @@
"outputs": [],
"source": [
"# obtain study/visit details (e.g. anonymized study date, age at the time of visit)\n",
"df = nbia.getStudy(collection, format = \"csv\", api_url = api_url)\n",
"df = nbia.getStudy(collection, format = \"csv\")\n",
"display(df)"
]
},
Expand All @@ -274,7 +262,7 @@
"outputs": [],
"source": [
"# obtain scan/series metadata and save to variable for use in next example\n",
"series = nbia.getSeries(collection, api_url = api_url, format = \"df\")\n",
"series = nbia.getSeries(collection, format = \"df\")\n",
"\n",
"display(series)"
]
Expand All @@ -297,7 +285,7 @@
"outputs": [],
"source": [
"# Calculate summary statistics for a given collection\n",
"nbia.reportDoiSummary(series, api_url = api_url, input_type = \"df\")"
"nbia.reportDoiSummary(series, input_type = \"df\")"
]
},
{
Expand Down Expand Up @@ -367,7 +355,7 @@
},
"outputs": [],
"source": [
"nbia.downloadSeries([refSeries, segSeries], input_type= \"list\", api_url = api_url)"
"nbia.downloadSeries([refSeries, segSeries], input_type= \"list\")"
]
},
{
Expand All @@ -376,7 +364,7 @@
"id": "6HU0fGOwvxxO"
},
"source": [
"Now we can look at the images and segmentation together with **viewSeriesAnnotation()**. Note that this function is only meant to be a quick and dirty way to preview the data. There are more comprehensive solutions such as [3D Slicer](https://slicer.org/) or [itkWidgets](https://github.com/kirbyju/TCIA_Notebooks/blob/main/TCIA_RTStruct_SEG_Visualization_with_itkWidgets.ipynb) if you want analyze the data."
"Now we can look at the images and segmentation together with **viewSeriesAnnotation()** from [simpleDicomViewer](https://pypi.org/project/simpleDicomViewer/). Note that this function is only meant to be a quick and dirty way to preview the data. There are more comprehensive solutions such as [3D Slicer](https://slicer.org/) or [itkWidgets](https://github.com/kirbyju/TCIA_Notebooks/blob/main/TCIA_RTStruct_SEG_Visualization_with_itkWidgets.ipynb) if you want analyze the data."
]
},
{
Expand All @@ -387,7 +375,15 @@
},
"outputs": [],
"source": [
"nbia.viewSeriesAnnotation(seriesUid = refSeries, annotationUid = segSeries)"
"# Assuming you didn't change the default download options for downloadSeries\n",
"imgPath = \"tciaDownload/\" + refSeries\n",
"\n",
"# The annotation path has to be a file name (not directory name). Since there is generally\n",
"# only one file in a segmentation series we can assume it will always be called 1-1.dcm\n",
"segPath = \"tciaDownload/\" + segSeries + \"/1-1.dcm\"\n",
"\n",
"# Display the viewer\n",
"dicomViewer.viewSeriesAnnotation(imgPath, segPath)"
]
},
{
Expand Down Expand Up @@ -532,7 +528,7 @@
"unique_series_list = list(set(unique_series_list))\n",
"\n",
"# download the series from the unique series list\n",
"nbia.downloadSeries(unique_series_list, input_type=\"list\", api_url=api_url, format = \"df\")\n"
"nbia.downloadSeries(unique_series_list, input_type=\"list\", format = \"df\")\n"
]
},
{
Expand Down Expand Up @@ -565,7 +561,7 @@
"unique_series_list = list(set(unique_series_list))\n",
"\n",
"# download the series from the unique series list\n",
"nbia.downloadSeries(unique_series_list, input_type=\"list\", api_url=api_url, format = \"df\", number = number)"
"nbia.downloadSeries(unique_series_list, input_type=\"list\", format = \"df\", number = number)"
],
"metadata": {
"id": "WTQu-cOhs_EK"
Expand Down

0 comments on commit f171f35

Please sign in to comment.