-
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 12, 2023
1 parent
ae82bbd
commit c67a68c
Showing
22 changed files
with
1,061 additions
and
527 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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"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": null, | ||
"id": "49adac4a-82e5-4fae-a0e0-26dcce5661bf", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"os.system(\"curl -o coefficients.xlsx https://elifesciences.org/download/aHR0cHM6Ly9jZG4uZWxpZmVzY2llbmNlcy5vcmcvYXJ0aWNsZXMvNDA2NzUvZWxpZmUtNDA2NzUtc3VwcDMtdjIueGxzeA--/elife-40675-supp3-v2.xlsx?_hash=qzOMc4yUFACfDFG%2FlgxkFTHWt%2BSXSmP9zz1BM3oOTRM%3D\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "b9f484b1-f501-41b7-9565-82e03bfe97dc", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = pd.read_excel('coefficients.xlsx', sheet_name='Blood', nrows=90)\n", | ||
"\n", | ||
"intercept = 0.0\n", | ||
"\n", | ||
"df['feature'] = df['Chromosome'].astype(str) + ':' + df['Position'].astype(int).astype(str)\n", | ||
"df['coefficient'] = df['Weight']" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "a284fe99-dc47-4f0c-b2ff-274e136e7020", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"features = df['feature'].tolist()\n", | ||
"\n", | ||
"weights = torch.tensor(df['coefficient'].tolist()).unsqueeze(0)\n", | ||
"intercept = torch.tensor([intercept])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "7b4c3f6b-72af-4e99-84c4-65b8ef58c91d", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"LinearModel(\n", | ||
" (linear): Linear(in_features=90, out_features=1, bias=True)\n", | ||
")" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"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": 40, | ||
"id": "e32706f0-ce07-455e-bb17-1993c1c0e152", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"weights_dict = {\n", | ||
" 'preprocessing': None, \n", | ||
" 'preprocessing_helper': None,\n", | ||
" 'postprocessing': \"petkovichblood\",\n", | ||
" 'postprocessing_helper': None,\n", | ||
" 'features': features,\n", | ||
" 'weight_dict': model.state_dict(),\n", | ||
"}\n", | ||
"\n", | ||
"metadata_dict = {\n", | ||
" 'species': 'Mus musculus',\n", | ||
" 'data_type': 'methylation',\n", | ||
" 'year': 2017,\n", | ||
" 'implementation_approved_by_author(s)': '⌛',\n", | ||
" 'preprocessing': weights_dict['preprocessing'], \n", | ||
" 'postprocessing': weights_dict['postprocessing'], \n", | ||
" 'citation': \"Petkovich, Daniel A., et al. \\\"Using DNA methylation profiling to evaluate biological age and longevity interventions.\\\" Cell metabolism 25.4 (2017): 954-960.\",\n", | ||
" 'doi': \"https://doi.org/10.1016/j.cmet.2017.03.016\",\n", | ||
" \"notes\": None,\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 41, | ||
"id": "34136f3c-92b8-4641-a103-381d3a7dd857", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"torch.save(weights_dict, '../weights/petkovichblood.pt')\n", | ||
"torch.save(metadata_dict, '../metadata/petkovichblood.pt')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "83334bff-17c3-447c-9e37-fcb68edef5df", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"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 | ||
} |
Oops, something went wrong.