-
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 11, 2023
1 parent
f76cb96
commit 165fc72
Showing
13 changed files
with
1,342 additions
and
670 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
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,197 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"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": 9, | ||
"id": "46c6fc26-9a6b-4027-bd01-601b70eb401a", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"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": 1, | ||
"id": "bf89303a-6e7f-4585-a439-655fe0a79b05", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# You have to manually open Excel and convert to .csv (multi tissue, whole lifespan)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"id": "b9f484b1-f501-41b7-9565-82e03bfe97dc", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = pd.read_csv('coefficients.csv')\n", | ||
"\n", | ||
"intercept = df['Position'].iloc[-1]\n", | ||
"\n", | ||
"df = df[0:-2]\n", | ||
"\n", | ||
"df['feature'] = df['Chromosome'].astype(str) + ':' + df['Position'].astype(int).astype(str)\n", | ||
"df['coefficient'] = df['Weight']" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 22, | ||
"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": 23, | ||
"id": "7b4c3f6b-72af-4e99-84c4-65b8ef58c91d", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"LinearModel(\n", | ||
" (linear): Linear(in_features=435, out_features=1, bias=True)\n", | ||
")" | ||
] | ||
}, | ||
"execution_count": 23, | ||
"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": 30, | ||
"id": "e32706f0-ce07-455e-bb17-1993c1c0e152", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"weights_dict = {\n", | ||
" 'preprocessing': \"times100\", \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': 'Mus musculus',\n", | ||
" 'data_type': 'methylation',\n", | ||
" 'year': 2018,\n", | ||
" 'implementation_approved_by_author(s)': '⌛',\n", | ||
" 'preprocessing': weights_dict['preprocessing'], \n", | ||
" 'postprocessing': weights_dict['postprocessing'], \n", | ||
" 'citation': \"Meer, Margarita V., et al. \\\"A whole lifespan mouse multi-tissue DNA methylation clock.\\\" Elife 7 (2018): e40675.\",\n", | ||
" 'doi': \"https://doi.org/10.7554/eLife.40675\",\n", | ||
" \"notes\": \"Predicts age in days\",\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 31, | ||
"id": "34136f3c-92b8-4641-a103-381d3a7dd857", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"torch.save(weights_dict, '../weights/meermultitissue.pt')\n", | ||
"torch.save(metadata_dict, '../metadata/meermultitissue.pt')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 27, | ||
"id": "303e9b76-993f-4691-af9d-1151b3c7638f", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0" | ||
] | ||
}, | ||
"execution_count": 27, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"os.system(\"rm coefficients.xlsx\")\n", | ||
"os.system(\"rm coefficients.csv\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "6f111912-501e-4d2c-a592-1cc9829092dd", | ||
"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.