{"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":"# Prerequisites","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import SimpleITK as sitk\nimport os\nimport pandas as pd","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create list of test patients\npatients = sorted(os.listdir('../input/rsna-miccai-brain-tumor-radiogenomic-classification/test/'))\nprint(patients)","metadata":{"execution":{"iopub.status.busy":"2021-10-10T11:38:01.680481Z","iopub.execute_input":"2021-10-10T11:38:01.680757Z","iopub.status.idle":"2021-10-10T11:38:01.707387Z","shell.execute_reply.started":"2021-10-10T11:38:01.680732Z","shell.execute_reply":"2021-10-10T11:38:01.706418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Function to load DICOM Series\n\nreader = sitk.ImageSeriesReader()\nreader.LoadPrivateTagsOn()\n\ndef load(path):\n    \n    filenamesDICOM = reader.GetGDCMSeriesFileNames(path)\n    reader.SetFileNames(filenamesDICOM)\n    loadedImage = reader.Execute()\n    \n    return loadedImage","metadata":{"execution":{"iopub.status.busy":"2021-10-10T11:24:03.810035Z","iopub.execute_input":"2021-10-10T11:24:03.810272Z","iopub.status.idle":"2021-10-10T11:24:03.821078Z","shell.execute_reply.started":"2021-10-10T11:24:03.810245Z","shell.execute_reply":"2021-10-10T11:24:03.819949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Preprocessing","metadata":{}},{"cell_type":"code","source":"sequences = [('FLAIR', 0), ('T1w', 1), ('T2w', 3)]\n\nfor p in patients:\n    \n    try:\n    \n        print(f'Processing {p}')\n        print('T1wCE')\n\n        T1Norm = load(f'/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/test/{p}/T1wCE')\n        sitk.WriteImage(T1Norm, f'/kaggle/working/{p}_RES_0002.nii.gz')\n\n        for s, i in sequences:\n\n            print(s)\n            \n            Img = load(f'/kaggle/input/rsna-miccai-brain-tumor-radiogenomic-classification/test/{p}/{s}')\n            sitk.WriteImage(Img, f'/kaggle/working/{p}_RES_000{i}.nii.gz')\n        \n    except Exception as e:\n        \n        print(f'could not process {p}')\n        print(e)","metadata":{"execution":{"iopub.status.busy":"2021-10-10T11:24:03.822263Z","iopub.execute_input":"2021-10-10T11:24:03.822498Z","iopub.status.idle":"2021-10-10T11:37:44.104706Z","shell.execute_reply.started":"2021-10-10T11:24:03.822471Z","shell.execute_reply":"2021-10-10T11:37:44.102265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inference","metadata":{}},{"cell_type":"code","source":"# Placeholder Code\npredictions = [0.5]*len(patients)\nprint(predictions)","metadata":{"execution":{"iopub.status.busy":"2021-10-10T11:37:44.108647Z","iopub.execute_input":"2021-10-10T11:37:44.108960Z","iopub.status.idle":"2021-10-10T11:37:44.116262Z","shell.execute_reply.started":"2021-10-10T11:37:44.108925Z","shell.execute_reply":"2021-10-10T11:37:44.114998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submission","metadata":{}},{"cell_type":"code","source":"submission = pd.DataFrame({'BraTS21ID' : patients,'MGMT_value' : predictions})\nsubmission = submission.reset_index(drop=True)\nsubmission.to_csv('submission.csv', index = False)\nsubmission","metadata":{"execution":{"iopub.status.busy":"2021-10-10T11:38:07.689325Z","iopub.execute_input":"2021-10-10T11:38:07.689593Z","iopub.status.idle":"2021-10-10T11:38:07.741922Z","shell.execute_reply.started":"2021-10-10T11:38:07.689567Z","shell.execute_reply":"2021-10-10T11:38:07.740945Z"},"trusted":true},"execution_count":null,"outputs":[]}]}