Skip to content

Commit

Permalink
Added code files
Browse files Browse the repository at this point in the history
  • Loading branch information
smruthig authored Feb 13, 2024
1 parent c01a4cc commit bbba403
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions Code/1. Feature Generation/Global Binary Measures.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Code/1. Feature Generation/Global Weighted Measures.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Code/1. Feature Generation/Local Binary Measures.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Code/1. Feature Generation/Local Weighted Measures.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"code","execution_count":null,"id":"b6465562-8ef4-4cce-b589-4bf396b72d88","metadata":{"ExecuteTime":{"end_time":"2022-09-01T14:16:20.681431Z","start_time":"2022-09-01T14:16:18.996297Z"},"id":"b6465562-8ef4-4cce-b589-4bf396b72d88","outputId":"f51bb94a-fd6a-4327-c450-cfb1dccd18ef"},"outputs":[{"name":"stdout","output_type":"stream","text":["Metal device set to: Apple M1 Pro\n"]},{"name":"stderr","output_type":"stream","text":["2022-09-29 16:40:43.892988: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.\n","2022-09-29 16:40:43.893315: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)\n"]}],"source":["#imports \n","\n","from stellargraph import StellarGraph\n","import stellargraph as sg\n","from stellargraph.mapper import PaddedGraphGenerator\n","from stellargraph.layer import DeepGraphCNN\n","import pandas as pd\n","import os\n","import numpy as np\n","import networkx as nx\n","import matplotlib.pyplot as plt\n","\n","from sklearn import model_selection\n","from IPython.display import display, HTML\n","\n","from tensorflow.keras import Model\n","from tensorflow.keras.optimizers import Adam\n","from tensorflow.keras.layers import Dense, Conv1D, MaxPool1D, Dropout, Flatten\n","from tensorflow.keras.losses import binary_crossentropy\n","import tensorflow as tf\n","from tensorflow import keras"]},{"cell_type":"code","execution_count":null,"id":"35043e60-8ee2-466a-b238-0155bd5ed901","metadata":{"ExecuteTime":{"end_time":"2022-09-01T14:16:20.691586Z","start_time":"2022-09-01T14:16:20.682684Z"},"id":"35043e60-8ee2-466a-b238-0155bd5ed901","outputId":"64523b08-d833-4810-f7a7-f41d4742d925"},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Subject</th>\n"," <th>Subject Type</th>\n"," <th>Label</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>40013</td>\n"," <td>Control</td>\n"," <td>0</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>40014</td>\n"," <td>Control</td>\n"," <td>0</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>40017</td>\n"," <td>Control</td>\n"," <td>0</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>40018</td>\n"," <td>Control</td>\n"," <td>0</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>40019</td>\n"," <td>Control</td>\n"," <td>0</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n"," <th>416</th>\n"," <td>2168</td>\n"," <td>Patient</td>\n"," <td>1</td>\n"," </tr>\n"," <tr>\n"," <th>417</th>\n"," <td>2169</td>\n"," <td>Patient</td>\n"," <td>1</td>\n"," </tr>\n"," <tr>\n"," <th>418</th>\n"," <td>2170</td>\n"," <td>Patient</td>\n"," <td>1</td>\n"," </tr>\n"," <tr>\n"," <th>419</th>\n"," <td>2171</td>\n"," <td>Patient</td>\n"," <td>1</td>\n"," </tr>\n"," <tr>\n"," <th>420</th>\n"," <td>2172</td>\n"," <td>Patient</td>\n"," <td>1</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>421 rows × 3 columns</p>\n","</div>"],"text/plain":[" Subject Subject Type Label\n","0 40013 Control 0\n","1 40014 Control 0\n","2 40017 Control 0\n","3 40018 Control 0\n","4 40019 Control 0\n",".. ... ... ...\n","416 2168 Patient 1\n","417 2169 Patient 1\n","418 2170 Patient 1\n","419 2171 Patient 1\n","420 2172 Patient 1\n","\n","[421 rows x 3 columns]"]},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":["combined_phenotype = '/content/drive/MyDrive/SUPPLEMENTARY CODE/Data/Metadata/phenotypic_data.csv'\n","labels_mappings= pd.read_csv(combined_phenotype)\n","labels_mappings"]},{"cell_type":"code","execution_count":null,"id":"41482575-e663-4a45-bb6a-89a1bb957e8c","metadata":{"ExecuteTime":{"end_time":"2022-09-01T14:16:20.694814Z","start_time":"2022-09-01T14:16:20.692476Z"},"id":"41482575-e663-4a45-bb6a-89a1bb957e8c"},"outputs":[],"source":["def row_transform(arr, threshold):\n"," for i in range(len(arr)):\n"," arr[i] = arr[i] if arr[i]> threshold else abs(arr[i])+0.0001\n"," return arr\n","\n","def binarize(df, threshold):\n"," df = df.transform(lambda x: row_transform(x, threshold))"]},{"cell_type":"code","execution_count":null,"id":"64ad9c6b-103c-4c08-a601-8c676fead8a9","metadata":{"ExecuteTime":{"end_time":"2022-09-01T14:16:20.698854Z","start_time":"2022-09-01T14:16:20.697197Z"},"id":"64ad9c6b-103c-4c08-a601-8c676fead8a9"},"outputs":[],"source":["uw = '/content/drive/MyDrive/SUPPLEMENTARY CODE/Data/Preprocessed Data/UCLA Weighted v2'"]},{"cell_type":"code","execution_count":null,"id":"05fff533","metadata":{"ExecuteTime":{"end_time":"2022-09-01T14:16:20.701227Z","start_time":"2022-09-01T14:16:20.699595Z"},"id":"05fff533"},"outputs":[],"source":["dirs=[uw]\n","count = 0 "]},{"cell_type":"code","execution_count":null,"id":"1a9bd4a7","metadata":{"ExecuteTime":{"end_time":"2022-09-01T14:16:20.703445Z","start_time":"2022-09-01T14:16:20.701965Z"},"id":"1a9bd4a7"},"outputs":[],"source":["graphs = list()\n","graph_labels = list()\n","sub_lst = list(range(0,164))"]},{"cell_type":"code","execution_count":null,"id":"8e19c8b2-515c-4199-b03c-78b846699ee1","metadata":{"ExecuteTime":{"end_time":"2022-09-04T12:28:03.198174Z","start_time":"2022-09-01T14:16:20.704592Z"},"id":"8e19c8b2-515c-4199-b03c-78b846699ee1","outputId":"6ada93f3-345b-4cfa-9e8f-6a66703244b1"},"outputs":[{"name":"stdout","output_type":"stream","text":["1\n","2\n","3\n","4\n","5\n","6\n","7\n","8\n","9\n","10\n","11\n","12\n","13\n","14\n","15\n","16\n","17\n","18\n","19\n","20\n","21\n"]}],"source":["for dir in dirs:\n"," for file in os.listdir(dir):\n"," if file.endswith(\".csv\"):\n"," subject = file[14:18]\n"," df = pd.read_csv(dir+'/'+file, header=None)\n"," binarize(df,0)\n"," df = df.replace(np.nan ,0)\n"," G = nx.from_pandas_adjacency(df)\n","\n"," #adding other attributes\n"," wd = dict(G.degree(weight='weight'))\n"," cv = nx.closeness_vitality(G, node=None, weight=\"weight\", wiener_index=None)\n"," andeg = nx.average_neighbor_degree(G, weight=\"weight\")\n"," cons = nx.constraint(G, nodes=None, weight=\"weight\")\n"," es = nx.effective_size(G, nodes=None, weight=\"weight\")\n"," \n"," node_features_data=list(zip(wd.values(),cv.values(),andeg.values(),cons.values(),es.values()))\n"," node_features_columns= ['weighted degree','closeness vitality','avg neighbor degree',\n"," 'constraint','effective size']\n"," node_data= pd.DataFrame(node_features_data, index=sub_lst, columns=node_features_columns)\n"," \n"," #saving individual node features\n"," csv_path='weighted_node_features_'+str(subject)+'.csv'\n"," node_data.to_csv(csv_path)\n"," \n"," count+=1\n"," print(count)"]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.6"},"toc":{"base_numbering":1,"nav_menu":{},"number_sections":true,"sideBar":true,"skip_h1_title":false,"title_cell":"Table of Contents","title_sidebar":"Contents","toc_cell":false,"toc_position":{},"toc_section_display":true,"toc_window_display":false},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":5}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Code/4. Machine Learning/All ML Models 10 fold CV.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Code/5. Graph Neural Network/DGCNN model 10 Fold CV.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Code/5. Graph Neural Network/DGCNN model.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Code/5. Graph Neural Network/DGCNN with node2vec.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit bbba403

Please sign in to comment.