From 214151e36ff5b0bc31c6a103e14a4b1e3b9bfb4a Mon Sep 17 00:00:00 2001 From: Jermiah Joseph Date: Sat, 24 Feb 2024 12:34:56 -0500 Subject: [PATCH] docs: fix a few cells --- docs/Tutorial.ipynb | 796 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 726 insertions(+), 70 deletions(-) diff --git a/docs/Tutorial.ipynb b/docs/Tutorial.ipynb index 39c2cc7..3946acb 100644 --- a/docs/Tutorial.ipynb +++ b/docs/Tutorial.ipynb @@ -24,7 +24,16 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/bhklab/Documents/GitHub/NBIA-toolkit/src/nbiatoolkit/nbia_cli.py:20: SyntaxWarning: invalid escape sequence '\\/'\n", + " f = \"\"\"\n" + ] + } + ], "source": [ "import nbiatoolkit\n", "from nbiatoolkit import NBIAClient\n", @@ -43,7 +52,7 @@ { "data": { "text/plain": [ - "'0.22.1'" + "'0.32.1'" ] }, "execution_count": 2, @@ -56,6 +65,42 @@ "nbiatoolkit.__version__" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Return Types\n", + "\n", + "Most functions will by default return a list of dictionaries. If you would like to return a pandas DataFrame instead you can pass in the parameter `return_type`.\n", + "\n", + "Available options are made available through the `ReturnType` Enum which can be passed in as a parameter or alternatively, the string representation of the Enum value can be passed in as a string." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[, ]\n" + ] + } + ], + "source": [ + "from nbiatoolkit.utils import ReturnType\n", + "print(list(ReturnType))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "passing in `return_type=ReturnType.DATAFRAME` or `return_type=\"dataframe\"` will return a pandas DataFrame." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -69,46 +114,122 @@ "source": [ "### get list of collections (names only)\n", "``` python\n", - "client.getCollections(prefix: str = \"\")\n", + "client.getCollections(\n", + " prefix: str = \"\",\n", + " return_type: ReturnType | str = ReturnType.LIST)\n", "```" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Total collections: 124\n", - "['4D-Lung', 'ACRIN-6698', 'ACRIN-Contralateral-Breast-MR', 'ACRIN-FLT-Breast', 'ACRIN-NSCLC-FDG-PET']\n" + "[{'Collection': '4D-Lung'}, {'Collection': 'ACRIN-6698'}, {'Collection': 'ACRIN-Contralateral-Breast-MR'}, {'Collection': 'ACRIN-FLT-Breast'}, {'Collection': 'ACRIN-NSCLC-FDG-PET'}]\n" ] } ], "source": [ + "# To get all the collections:\n", "collections = client.getCollections()\n", - "print(\"Total collections: \", len(collections))\n", "print(collections[0:5])" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['TCGA-BLCA', 'TCGA-BRCA', 'TCGA-CESC', 'TCGA-COAD', 'TCGA-ESCA', 'TCGA-KICH', 'TCGA-KIRC', 'TCGA-KIRP', 'TCGA-LIHC', 'TCGA-LUAD', 'TCGA-LUSC', 'TCGA-OV', 'TCGA-PRAD', 'TCGA-READ', 'TCGA-SARC', 'TCGA-STAD', 'TCGA-THCA', 'TCGA-UCEC']\n" + "[{'Collection': 'TCGA-BLCA'}, {'Collection': 'TCGA-BRCA'}, {'Collection': 'TCGA-CESC'}, {'Collection': 'TCGA-COAD'}, {'Collection': 'TCGA-ESCA'}]\n" ] } ], "source": [ + "# To get all the collections with a prefix:\n", "collections = client.getCollections(prefix = \"TCGA\")\n", - "print(collections)" + "print(collections[0:5])" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Collection
0TCGA-BLCA
1TCGA-BRCA
2TCGA-CESC
3TCGA-COAD
4TCGA-ESCA
\n", + "
" + ], + "text/plain": [ + " Collection\n", + "0 TCGA-BLCA\n", + "1 TCGA-BRCA\n", + "2 TCGA-CESC\n", + "3 TCGA-COAD\n", + "4 TCGA-ESCA" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# To get the same but as a pandas dataframe:\n", + "collections_df = client.getCollections(prefix = \"TCGA\", return_type=ReturnType.DATAFRAME)\n", + "collections_df.head()" ] }, { @@ -119,14 +240,15 @@ "\n", "``` python\n", "getCollectionDescriptions(\n", - " collectionName: str # (required)\n", + " collectionName: str, # (required)\n", + " return_type: ReturnType | str = ReturnType.LIST\n", ")\n", "```" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -153,28 +275,94 @@ "pprint(client.getCollectionDescriptions(\"TCGA-BLCA\"))" ] }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
collectionNamedescriptiondescriptionURIlastUpdated
0TCGA-BLCAThe Cancer Genome Atlas-Bladder Endothelial Ca...https://doi.org/10.7937/K9/TCIA.2016.8LNG8XDR2023-03-16
\n", + "
" + ], + "text/plain": [ + " collectionName description \\\n", + "0 TCGA-BLCA The Cancer Genome Atlas-Bladder Endothelial Ca... \n", + "\n", + " descriptionURI lastUpdated \n", + "0 https://doi.org/10.7937/K9/TCIA.2016.8LNG8XDR 2023-03-16 " + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client.getCollectionDescriptions(\"TCGA-BLCA\", ReturnType.DATAFRAME)" + ] + }, { "cell_type": "markdown", "metadata": {}, "source": [ "### get Counts of Patients for each collection\n", - "`getCollectionPatientCount(prefx: str = \"\")`" + "``` python\n", + "getCollectionPatientCount(\n", + " prefx: str = \"\",\n", + " return_type: ReturnType | str = ReturnType.LIST\n", + ")\n", + "```" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[{'Collection': '4D-Lung', 'PatientCount': 20},\n", - " {'Collection': 'ACRIN-6698', 'PatientCount': 385},\n", - " {'Collection': 'ACRIN-Contralateral-Breast-MR', 'PatientCount': 984},\n", - " {'Collection': 'ACRIN-FLT-Breast', 'PatientCount': 83},\n", - " {'Collection': 'ACRIN-NSCLC-FDG-PET', 'PatientCount': 242}]\n" + "[{'count': '20', 'criteria': '4D-Lung'},\n", + " {'count': '385', 'criteria': 'ACRIN-6698'},\n", + " {'count': '984', 'criteria': 'ACRIN-Contralateral-Breast-MR'},\n", + " {'count': '83', 'criteria': 'ACRIN-FLT-Breast'},\n", + " {'count': '242', 'criteria': 'ACRIN-NSCLC-FDG-PET'}]\n" ] } ], @@ -185,41 +373,209 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[{'Collection': 'TCGA-BLCA', 'PatientCount': 120},\n", - " {'Collection': 'TCGA-BRCA', 'PatientCount': 139},\n", - " {'Collection': 'TCGA-CESC', 'PatientCount': 54},\n", - " {'Collection': 'TCGA-COAD', 'PatientCount': 25},\n", - " {'Collection': 'TCGA-ESCA', 'PatientCount': 16},\n", - " {'Collection': 'TCGA-KICH', 'PatientCount': 15},\n", - " {'Collection': 'TCGA-KIRC', 'PatientCount': 267},\n", - " {'Collection': 'TCGA-KIRP', 'PatientCount': 33},\n", - " {'Collection': 'TCGA-LIHC', 'PatientCount': 97},\n", - " {'Collection': 'TCGA-LUAD', 'PatientCount': 69},\n", - " {'Collection': 'TCGA-LUSC', 'PatientCount': 37},\n", - " {'Collection': 'TCGA-OV', 'PatientCount': 143},\n", - " {'Collection': 'TCGA-PRAD', 'PatientCount': 14},\n", - " {'Collection': 'TCGA-READ', 'PatientCount': 3},\n", - " {'Collection': 'TCGA-SARC', 'PatientCount': 5},\n", - " {'Collection': 'TCGA-STAD', 'PatientCount': 46},\n", - " {'Collection': 'TCGA-THCA', 'PatientCount': 6},\n", - " {'Collection': 'TCGA-UCEC', 'PatientCount': 65}]\n", - "Collection with max PatientCount: {'Collection': 'TCGA-KIRC', 'PatientCount': 267}\n" + "[{'count': '120', 'criteria': 'TCGA-BLCA'},\n", + " {'count': '139', 'criteria': 'TCGA-BRCA'},\n", + " {'count': '54', 'criteria': 'TCGA-CESC'},\n", + " {'count': '25', 'criteria': 'TCGA-COAD'},\n", + " {'count': '16', 'criteria': 'TCGA-ESCA'},\n", + " {'count': '15', 'criteria': 'TCGA-KICH'},\n", + " {'count': '267', 'criteria': 'TCGA-KIRC'},\n", + " {'count': '33', 'criteria': 'TCGA-KIRP'},\n", + " {'count': '97', 'criteria': 'TCGA-LIHC'},\n", + " {'count': '69', 'criteria': 'TCGA-LUAD'},\n", + " {'count': '37', 'criteria': 'TCGA-LUSC'},\n", + " {'count': '143', 'criteria': 'TCGA-OV'},\n", + " {'count': '14', 'criteria': 'TCGA-PRAD'},\n", + " {'count': '3', 'criteria': 'TCGA-READ'},\n", + " {'count': '5', 'criteria': 'TCGA-SARC'},\n", + " {'count': '46', 'criteria': 'TCGA-STAD'},\n", + " {'count': '6', 'criteria': 'TCGA-THCA'},\n", + " {'count': '65', 'criteria': 'TCGA-UCEC'}]\n" + ] + }, + { + "ename": "KeyError", + "evalue": "'PatientCount'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[19], line 6\u001b[0m\n\u001b[1;32m 3\u001b[0m pprint(collectionsPatientCount)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;66;03m# get the collection with max PatientCount\u001b[39;00m\n\u001b[0;32m----> 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCollection with max PatientCount: \u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;43mmax\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mcollectionsPatientCount\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkey\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mlambda\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m:\u001b[49m\u001b[43mx\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mPatientCount\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m)\n", + "Cell \u001b[0;32mIn[19], line 6\u001b[0m, in \u001b[0;36m\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 3\u001b[0m pprint(collectionsPatientCount)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;66;03m# get the collection with max PatientCount\u001b[39;00m\n\u001b[0;32m----> 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCollection with max PatientCount: \u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28mmax\u001b[39m(collectionsPatientCount, key\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mlambda\u001b[39;00m x:\u001b[43mx\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mPatientCount\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m))\n", + "\u001b[0;31mKeyError\u001b[0m: 'PatientCount'" ] } ], "source": [ + "# use prefix to get the patient count for a specific collection and then find the collection with max patient count\n", "collectionsPatientCount = client.getCollectionPatientCount(prefix=\"TCGA\")\n", "pprint(collectionsPatientCount)\n", "\n", "# get the collection with max PatientCount\n", - "print(\"Collection with max PatientCount: \", max(collectionsPatientCount, key=lambda x:x['PatientCount']))" + "print(\"Collection with max PatientCount: \", max(collectionsPatientCount, key=lambda x: x['PatientCount']))" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
criteriacount
0TCGA-BLCA120
1TCGA-BRCA139
2TCGA-CESC54
3TCGA-COAD25
4TCGA-ESCA16
5TCGA-KICH15
6TCGA-KIRC267
7TCGA-KIRP33
8TCGA-LIHC97
9TCGA-LUAD69
10TCGA-LUSC37
11TCGA-OV143
12TCGA-PRAD14
13TCGA-READ3
14TCGA-SARC5
15TCGA-STAD46
16TCGA-THCA6
17TCGA-UCEC65
\n", + "
" + ], + "text/plain": [ + " criteria count\n", + "0 TCGA-BLCA 120\n", + "1 TCGA-BRCA 139\n", + "2 TCGA-CESC 54\n", + "3 TCGA-COAD 25\n", + "4 TCGA-ESCA 16\n", + "5 TCGA-KICH 15\n", + "6 TCGA-KIRC 267\n", + "7 TCGA-KIRP 33\n", + "8 TCGA-LIHC 97\n", + "9 TCGA-LUAD 69\n", + "10 TCGA-LUSC 37\n", + "11 TCGA-OV 143\n", + "12 TCGA-PRAD 14\n", + "13 TCGA-READ 3\n", + "14 TCGA-SARC 5\n", + "15 TCGA-STAD 46\n", + "16 TCGA-THCA 6\n", + "17 TCGA-UCEC 65" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "client.getCollectionPatientCount(prefix=\"TCGA\", return_type=ReturnType.DATAFRAME)" ] }, { @@ -227,12 +583,17 @@ "metadata": {}, "source": [ "### get Counts of Patients grouped by Body Parts\n", - "`getBodyPartCounts(collection: str = \"\", modality: str = \"\")`" + "``` python\n", + "getBodyPartCounts(\n", + " collection: str = \"\", \n", + " modality: str = \"\",\n", + " return_type: ReturnType | str = ReturnType.LIST\n", + ")" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -241,11 +602,11 @@ "text": [ "Total Number of body parts:60\n", "First 5 body parts:\n", - "[{'BodyPartExamined': 'NOT SPECIFIED', 'Count': 7839},\n", - " {'BodyPartExamined': 'ABDOMEN', 'Count': 1731},\n", - " {'BodyPartExamined': 'ABDOMEN CAVIT', 'Count': 2},\n", - " {'BodyPartExamined': 'ABDOMENPELVIC', 'Count': 2},\n", - " {'BodyPartExamined': 'ABDOMENPELVIS', 'Count': 50}]\n" + "[{'count': '7839', 'criteria': 'NOT SPECIFIED'},\n", + " {'count': '1731', 'criteria': 'ABDOMEN'},\n", + " {'count': '2', 'criteria': 'ABDOMEN CAVIT'},\n", + " {'count': '2', 'criteria': 'ABDOMENPELVIC'},\n", + " {'count': '50', 'criteria': 'ABDOMENPELVIS'}]\n" ] } ], @@ -259,30 +620,130 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Total Number of body parts:1\n", - "Number of patients for each body part in 4D-Lung collection:\n", - "[{'BodyPartExamined': 'LUNG', 'Count': 20}]\n" + "Total Number of body parts:11\n" ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
criteriacount
0NOT SPECIFIED239
1ABDOMEN91
2ABDOMENPELVIS2
3BRAIN W/WO_AH321
4CHEST124
5CHEST (THORAX)1
6CHESTABDOMEN1
7CHESTABDPELVIS1
8HEAD1
9OUTSIDE FIL1
10THORAX2
\n", + "
" + ], + "text/plain": [ + " criteria count\n", + "0 NOT SPECIFIED 239\n", + "1 ABDOMEN 91\n", + "2 ABDOMENPELVIS 2\n", + "3 BRAIN W/WO_AH32 1\n", + "4 CHEST 124\n", + "5 CHEST (THORAX) 1\n", + "6 CHESTABDOMEN 1\n", + "7 CHESTABDPELVIS 1\n", + "8 HEAD 1\n", + "9 OUTSIDE FIL 1\n", + "10 THORAX 2" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "bodypart_count = client.getBodyPartCounts(Collection = '4D-Lung')\n", + "bodypart_count = client.getBodyPartCounts(Collection = 'ACRIN-NSCLC-FDG-PET', return_type=ReturnType.DATAFRAME)\n", "print(\"Total Number of body parts:\" + str(len(bodypart_count)))\n", - "\n", - "print(\"Number of patients for each body part in 4D-Lung collection:\")\n", - "pprint(bodypart_count)" + "bodypart_count" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -290,21 +751,84 @@ "output_type": "stream", "text": [ "Total Number of body parts:5\n", - "Number of patients for each body part in 4D-Lung collection:\n", - "[{'BodyPartExamined': 'NOT SPECIFIED', 'Count': 194},\n", - " {'BodyPartExamined': 'ABDOMEN', 'Count': 11},\n", - " {'BodyPartExamined': 'CHEST', 'Count': 54},\n", - " {'BodyPartExamined': 'HEART', 'Count': 2},\n", - " {'BodyPartExamined': 'THORAX', 'Count': 1}]\n" + "Number of patients for each body part in 4D-Lung collection:\n" ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
criteriacount
0NOT SPECIFIED194
1ABDOMEN11
2CHEST54
3HEART2
4THORAX1
\n", + "
" + ], + "text/plain": [ + " criteria count\n", + "0 NOT SPECIFIED 194\n", + "1 ABDOMEN 11\n", + "2 CHEST 54\n", + "3 HEART 2\n", + "4 THORAX 1" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "bodypart_count = client.getBodyPartCounts(Collection = 'NSCLC Radiogenomics', Modality='CT')\n", + "bodypart_count = client.getBodyPartCounts(Collection = 'NSCLC Radiogenomics', Modality='CT', return_type=ReturnType.DATAFRAME)\n", "print(\"Total Number of body parts:\" + str(len(bodypart_count)))\n", "\n", "print(\"Number of patients for each body part in 4D-Lung collection:\")\n", - "pprint(bodypart_count)" + "bodypart_count" ] }, { @@ -322,13 +846,14 @@ "``` python\n", "getPatients(\n", " Collection: str = \"\", # (optional)\n", + " return_type: ReturnType | str = ReturnType.LIST\n", ")\n", "````" ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -361,6 +886,130 @@ "pprint(patients[0:2])" ] }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total patients in NSCLC-Radiomics: 422\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PatientIdPatientNamePatientSexCollectionPhantomSpeciesCodeSpeciesDescription
0LUNG1-001LUNG1-001MNSCLC-RadiomicsNO337915000Homo sapiens
1LUNG1-007LUNG1-007MNSCLC-RadiomicsNO337915000Homo sapiens
2LUNG1-029LUNG1-029FNSCLC-RadiomicsNO337915000Homo sapiens
3LUNG1-036LUNG1-036FNSCLC-RadiomicsNO337915000Homo sapiens
4LUNG1-056LUNG1-056FNSCLC-RadiomicsNO337915000Homo sapiens
\n", + "
" + ], + "text/plain": [ + " PatientId PatientName PatientSex Collection Phantom SpeciesCode \\\n", + "0 LUNG1-001 LUNG1-001 M NSCLC-Radiomics NO 337915000 \n", + "1 LUNG1-007 LUNG1-007 M NSCLC-Radiomics NO 337915000 \n", + "2 LUNG1-029 LUNG1-029 F NSCLC-Radiomics NO 337915000 \n", + "3 LUNG1-036 LUNG1-036 F NSCLC-Radiomics NO 337915000 \n", + "4 LUNG1-056 LUNG1-056 F NSCLC-Radiomics NO 337915000 \n", + "\n", + " SpeciesDescription \n", + "0 Homo sapiens \n", + "1 Homo sapiens \n", + "2 Homo sapiens \n", + "3 Homo sapiens \n", + "4 Homo sapiens " + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "patients_df = client.getPatients(Collection = \"NSCLC-Radiomics\", return_type=ReturnType.DATAFRAME)\n", + "print(f\"Total patients in NSCLC-Radiomics: {len(patients_df)}\")\n", + "patients_df.head()" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -370,13 +1019,14 @@ "getPatientsByCollectionAndModality(\n", " Collection: str, # (required)\n", " Modality: str, # (required)\n", + " return_type: ReturnType | str = ReturnType.LIST\n", ")\n", - "````" + "```" ] }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -384,7 +1034,11 @@ "output_type": "stream", "text": [ "Total patients in TCGA-BLCA with modality CT: 107\n", - "['TCGA-CU-A3QU', 'TCGA-CU-A3KJ', 'TCGA-CU-A0YR', 'TCGA-CU-A0YO', 'TCGA-CU-A3YL']\n" + "[{'PatientId': 'TCGA-CU-A3QU'},\n", + " {'PatientId': 'TCGA-CU-A3KJ'},\n", + " {'PatientId': 'TCGA-CU-A0YR'},\n", + " {'PatientId': 'TCGA-CU-A0YO'},\n", + " {'PatientId': 'TCGA-CU-A3YL'}]\n" ] } ], @@ -406,7 +1060,8 @@ " Date: str, # (required) accepted formats:\n", " # \"%Y-%m-%d\", \"%Y/%m/%d\", \"%Y%m%d\", \n", " # \"%m/%d/%Y\", \"%d/%m/%Y\", \"%d-%m-%Y\"\n", - ")\n" + ")\n", + "```" ] }, { @@ -476,12 +1131,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "\n", "``` python\n", "getStudies(\n", " Collection: str, # (required)\n", " PatientID: str = \"\", # (optional)\n", " StudyInstanceUID: str = \"\" # (optional)\n", - " ) \n", + ") \n", "```" ] },