-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lucas Camillo
authored and
Lucas Camillo
committed
Dec 28, 2023
1 parent
2e4f506
commit 0cd95da
Showing
22 changed files
with
1,178 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "ae756043-21a3-46e9-9fd8-1e5449eba9cb", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import torch\n", | ||
"import pandas as pd\n", | ||
"import pyaging as pya\n", | ||
"import os" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "46c6fc26-9a6b-4027-bd01-601b70eb401a", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0" | ||
] | ||
}, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"os.system(\"git clone https://github.com/MorganLevineLab/methylCIPHER.git\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "ef41c1be-5a8b-463f-914c-3f74fcc04465", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = pd.read_csv('methylCIPHER/data-raw/HRSInChPhenoAge_CpG.csv')\n", | ||
"\n", | ||
"df['feature'] = df['CpG']\n", | ||
"df['coefficient'] = df['Weight']" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "aeadf8d3-e31b-4e44-9928-39cb3986deb0", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"features = df['feature'].tolist()\n", | ||
"\n", | ||
"weights = torch.tensor(df['coefficient'].tolist()).unsqueeze(0)\n", | ||
"intercept = torch.tensor([52.8334080])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "1b43e476-72ef-43fd-9871-f41d95c8b269", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"LinearModel(\n", | ||
" (linear): Linear(in_features=959, out_features=1, bias=True)\n", | ||
")" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"model = pya.models.LinearModel(len(features))\n", | ||
"\n", | ||
"model.linear.weight.data = weights\n", | ||
"model.linear.bias.data = intercept\n", | ||
"\n", | ||
"model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "4f437c4e-313a-401a-8e30-6e68ad397fc4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"weights_dict = {\n", | ||
" 'preprocessing': None, \n", | ||
" 'preprocessing_helper': None,\n", | ||
" 'postprocessing': None,\n", | ||
" 'postprocessing_helper': None,\n", | ||
" 'features': features,\n", | ||
" 'weight_dict': model.state_dict(),\n", | ||
"}\n", | ||
"\n", | ||
"metadata_dict = {\n", | ||
" 'species': 'Homo sapiens',\n", | ||
" 'data_type': 'methylation',\n", | ||
" 'year': 2022,\n", | ||
" 'implementation_approved_by_author(s)': '⌛',\n", | ||
" 'preprocessing': weights_dict['preprocessing'], \n", | ||
" 'postprocessing': weights_dict['postprocessing'], \n", | ||
" 'citation': \"Higgins-Chen, Albert T., et al. \\\"A computational solution for bolstering reliability of epigenetic clocks: Implications for clinical trials and longitudinal tracking.\\\" Nature aging 2.7 (2022): 644-661.\",\n", | ||
" 'doi': \"https://doi.org/10.1038/s43587-022-00248-2\",\n", | ||
" \"notes\": None,\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "34136f3c-92b8-4641-a103-381d3a7dd857", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"torch.save(weights_dict, '../weights/hrsinchphenoage.pt')\n", | ||
"torch.save(metadata_dict, '../metadata/hrsinchphenoage.pt')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"id": "d7a8c672-d9f7-487e-af1d-addc55155534", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0" | ||
] | ||
}, | ||
"execution_count": 12, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"os.system(\"rm -r methylCIPHER\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.9.17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "fb157849-5454-4a60-8548-fff633fff764", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import torch\n", | ||
"import pandas as pd\n", | ||
"import pyaging as pya\n", | ||
"import os" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "46c6fc26-9a6b-4027-bd01-601b70eb401a", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"os.system(\"curl -o coefficients.csv https://static-content.springer.com/esm/art%3A10.1186%2Fs13059-016-1068-z/MediaObjects/13059_2016_1068_MOESM3_ESM.csv\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "b9f484b1-f501-41b7-9565-82e03bfe97dc", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = pd.read_csv('coefficients.csv')\n", | ||
"\n", | ||
"df['feature'] = df['CpGmarker']\n", | ||
"df['coefficient'] = df['CoefficientTraining']" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "a284fe99-dc47-4f0c-b2ff-274e136e7020", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"features = df['feature'][1:].tolist()\n", | ||
"\n", | ||
"weights = torch.tensor(df['coefficient'][1:].tolist()).unsqueeze(0)\n", | ||
"intercept = torch.tensor([df['coefficient'][0]])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "7b4c3f6b-72af-4e99-84c4-65b8ef58c91d", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"LinearModel(\n", | ||
" (linear): Linear(in_features=148, out_features=1, bias=True)\n", | ||
")" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"model = pya.models.LinearModel(len(features))\n", | ||
"\n", | ||
"model.linear.weight.data = weights\n", | ||
"model.linear.bias.data = intercept\n", | ||
"\n", | ||
"model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "e32706f0-ce07-455e-bb17-1993c1c0e152", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"weights_dict = {\n", | ||
" 'preprocessing': None, \n", | ||
" 'preprocessing_helper': None,\n", | ||
" 'postprocessing': None,\n", | ||
" 'postprocessing_helper': None,\n", | ||
" 'features': features,\n", | ||
" 'weight_dict': model.state_dict(),\n", | ||
"}\n", | ||
"\n", | ||
"metadata_dict = {\n", | ||
" 'species': 'Homo sapiens',\n", | ||
" 'data_type': 'methylation',\n", | ||
" 'year': 2016,\n", | ||
" 'implementation_approved_by_author(s)': '⌛',\n", | ||
" 'preprocessing': weights_dict['preprocessing'], \n", | ||
" 'postprocessing': weights_dict['postprocessing'], \n", | ||
" 'citation': \"Knight, Anna K., et al. \\\"An epigenetic clock for gestational age at birth based on blood methylation data.\\\" Genome biology 17.1 (2016): 1-11.\",\n", | ||
" 'doi': \"https://doi.org/10.1186/s13059-016-1068-z\",\n", | ||
" \"notes\": None,\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"id": "34136f3c-92b8-4641-a103-381d3a7dd857", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"torch.save(weights_dict, '../weights/knight.pt')\n", | ||
"torch.save(metadata_dict, '../metadata/knight.pt')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"id": "303e9b76-993f-4691-af9d-1151b3c7638f", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0" | ||
] | ||
}, | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"os.system(\"rm coefficients.csv\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.9.17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.