{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"A malignant tumor in the brain is a life-threatening condition. Known as glioblastoma, it's both the most common form of brain cancer in adults and the one with the worst prognosis, with median survival being less than a year. The presence of a specific genetic sequence in the tumor known as MGMT promoter methylation has been shown to be a favorable prognostic factor and a strong predictor of responsiveness to chemotherapy.","metadata":{}},{"cell_type":"markdown","source":"# Importing libraries¶","metadata":{}},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport os\nimport glob\nimport pydicom\nfrom pydicom import dcmread\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nfrom skimage import exposure\nimport cv2\nimport warnings\nfrom fastai.vision.all import *\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:49:42.855020Z","iopub.execute_input":"2021-07-18T11:49:42.855441Z","iopub.status.idle":"2021-07-18T11:49:46.534071Z","shell.execute_reply.started":"2021-07-18T11:49:42.855354Z","shell.execute_reply":"2021-07-18T11:49:46.532911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading data","metadata":{}},{"cell_type":"code","source":"dataset_path = Path('../input/rsna-miccai-brain-tumor-radiogenomic-classification')\n\ndataset_path.ls()","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:50:18.984920Z","iopub.execute_input":"2021-07-18T11:50:18.985291Z","iopub.status.idle":"2021-07-18T11:50:18.998863Z","shell.execute_reply.started":"2021-07-18T11:50:18.985261Z","shell.execute_reply":"2021-07-18T11:50:18.997419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_path = \"../input/rsna-miccai-brain-tumor-radiogenomic-classification/train/\"\nimage_cls = ['FLAIR', 'T1w', 'T1wCE', 'T2w']  ","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:50:21.587662Z","iopub.execute_input":"2021-07-18T11:50:21.588097Z","iopub.status.idle":"2021-07-18T11:50:21.593162Z","shell.execute_reply.started":"2021-07-18T11:50:21.588046Z","shell.execute_reply":"2021-07-18T11:50:21.591778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"../input/rsna-miccai-brain-tumor-radiogenomic-classification/train_labels.csv\")\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:50:28.513683Z","iopub.execute_input":"2021-07-18T11:50:28.514051Z","iopub.status.idle":"2021-07-18T11:50:28.548504Z","shell.execute_reply.started":"2021-07-18T11:50:28.514016Z","shell.execute_reply":"2021-07-18T11:50:28.547462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Visualization","metadata":{}},{"cell_type":"code","source":"ax = sns.countplot(data=train_df, x=\"MGMT_value\",)\nax.bar_label(ax.containers[0])\nplt.title(\" Class Count\")\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:50:35.771680Z","iopub.execute_input":"2021-07-18T11:50:35.772040Z","iopub.status.idle":"2021-07-18T11:50:35.937094Z","shell.execute_reply.started":"2021-07-18T11:50:35.772010Z","shell.execute_reply":"2021-07-18T11:50:35.935893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(train_df.BraTS21ID[train_df.MGMT_value==0], label='0', shade=True)\nsns.kdeplot(train_df.BraTS21ID[train_df.MGMT_value==1], label='1', shade=True)\nplt.xlabel('MGMT_value distribution');","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:50:41.598648Z","iopub.execute_input":"2021-07-18T11:50:41.599053Z","iopub.status.idle":"2021-07-18T11:50:41.834471Z","shell.execute_reply.started":"2021-07-18T11:50:41.599019Z","shell.execute_reply":"2021-07-18T11:50:41.833504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndataset = pydicom.filereader.dcmread('../input/rsna-miccai-brain-tumor-radiogenomic-classification/train/00002/FLAIR/Image-446.dcm')\nimg = dataset.pixel_array\n\nfig, ax = plt.subplots()\nax.imshow(img, cmap='gray')\nax.set_axis_off()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:50:47.601306Z","iopub.execute_input":"2021-07-18T11:50:47.601695Z","iopub.status.idle":"2021-07-18T11:50:47.722680Z","shell.execute_reply.started":"2021-07-18T11:50:47.601661Z","shell.execute_reply":"2021-07-18T11:50:47.721668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_id = '000' + str(random.randint(0, len(patient_path)))\npatient_id","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:54:39.222291Z","iopub.execute_input":"2021-07-18T11:54:39.222659Z","iopub.status.idle":"2021-07-18T11:54:39.230104Z","shell.execute_reply.started":"2021-07-18T11:54:39.222625Z","shell.execute_reply":"2021-07-18T11:54:39.228772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path_FLAIR = os.path.join(patient_path,patient_id,\"FLAIR\")\ntrain_path_T1w = os.path.join(patient_path,patient_id,\"T1w\")\ntrain_path_T1wCE = os.path.join(patient_path,patient_id,\"T1wCE\")\ntrain_path_T2w = os.path.join(patient_path,patient_id,\"T2w\")\ntrain_path_T2w\n","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:54:42.443570Z","iopub.execute_input":"2021-07-18T11:54:42.444004Z","iopub.status.idle":"2021-07-18T11:54:42.453257Z","shell.execute_reply.started":"2021-07-18T11:54:42.443969Z","shell.execute_reply":"2021-07-18T11:54:42.451995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path_FLAIR_1 = sorted(glob.glob(train_path_FLAIR + '/*.dcm', recursive=True))\ntrain_path_T1w_1 = sorted(glob.glob(train_path_T1w + '/*.dcm', recursive=True))\ntrain_path_T1wCE_1 = sorted(glob.glob(train_path_T1wCE + '/*.dcm', recursive=True))\ntrain_path_T2w_1 = sorted(glob.glob(train_path_T2w + '/*.dcm', recursive=True))\n\n\ntrain_path_T1w_1","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:54:47.003671Z","iopub.execute_input":"2021-07-18T11:54:47.004529Z","iopub.status.idle":"2021-07-18T11:54:47.197137Z","shell.execute_reply.started":"2021-07-18T11:54:47.004477Z","shell.execute_reply":"2021-07-18T11:54:47.196103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from skimage import io\n\nimage = pydicom.dcmread(train_path_FLAIR_1[random.randint(0, len(train_path_FLAIR_1))])\nplt.imshow(image.pixel_array, cmap=plt.cm.bone)","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:54:52.212435Z","iopub.execute_input":"2021-07-18T11:54:52.213075Z","iopub.status.idle":"2021-07-18T11:54:52.547751Z","shell.execute_reply.started":"2021-07-18T11:54:52.213030Z","shell.execute_reply":"2021-07-18T11:54:52.546341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = pydicom.dcmread(train_path_T1w_1[random.randint(0, len(train_path_T1w_1))])\nplt.imshow(image.pixel_array, cmap=plt.cm.bone)\n#plt.imshow(image.pixel_array, cmap=\"gray\")","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:55:00.689867Z","iopub.execute_input":"2021-07-18T11:55:00.690232Z","iopub.status.idle":"2021-07-18T11:55:00.914767Z","shell.execute_reply.started":"2021-07-18T11:55:00.690199Z","shell.execute_reply":"2021-07-18T11:55:00.913277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = pydicom.dcmread(train_path_T1wCE_1[random.randint(0, len(train_path_T1wCE_1))])\nplt.imshow(image.pixel_array, cmap=plt.cm.bone)","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:55:09.099130Z","iopub.execute_input":"2021-07-18T11:55:09.099568Z","iopub.status.idle":"2021-07-18T11:55:09.337492Z","shell.execute_reply.started":"2021-07-18T11:55:09.099529Z","shell.execute_reply":"2021-07-18T11:55:09.336463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = pydicom.dcmread(train_path_T2w_1[random.randint(0, len(train_path_T2w_1))])\nplt.imshow(image.pixel_array, cmap=plt.cm.bone)\n","metadata":{"execution":{"iopub.status.busy":"2021-07-18T11:55:15.214694Z","iopub.execute_input":"2021-07-18T11:55:15.215136Z","iopub.status.idle":"2021-07-18T11:55:15.655566Z","shell.execute_reply.started":"2021-07-18T11:55:15.215089Z","shell.execute_reply":"2021-07-18T11:55:15.654464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Reference:\nhttps://www.kaggle.com/prokaggler/brain-tumor-radiogenomic-eda-wip","metadata":{}}]}