Skip to content

Commit

Permalink
added EPICv2 probe aggregation function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Camillo authored and Lucas Camillo committed Feb 3, 2024
1 parent d3d20c0 commit 2350216
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 274 deletions.
155 changes: 29 additions & 126 deletions clocks/notebooks/han.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@
"cell_type": "code",
"execution_count": 1,
"id": "4adfb4de-cd79-4913-a1af-9e23e9e236c9",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:27.997592Z",
"iopub.status.busy": "2024-01-21T18:01:27.997245Z",
"iopub.status.idle": "2024-01-21T18:01:29.436585Z",
"shell.execute_reply": "2024-01-21T18:01:29.436277Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"import os\n",
Expand All @@ -70,14 +63,7 @@
"cell_type": "code",
"execution_count": 2,
"id": "8aa77372-7ed3-4da7-abc9-d30372106139",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.438855Z",
"iopub.status.busy": "2024-01-21T18:01:29.438591Z",
"iopub.status.idle": "2024-01-21T18:01:29.445989Z",
"shell.execute_reply": "2024-01-21T18:01:29.445725Z"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -128,14 +114,7 @@
"cell_type": "code",
"execution_count": 3,
"id": "78536494-f1d9-44de-8583-c89a310d2307",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.447512Z",
"iopub.status.busy": "2024-01-21T18:01:29.447426Z",
"iopub.status.idle": "2024-01-21T18:01:29.449053Z",
"shell.execute_reply": "2024-01-21T18:01:29.448790Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"model = pya.models.Han()"
Expand All @@ -153,21 +132,14 @@
"cell_type": "code",
"execution_count": 4,
"id": "6601da9e-8adc-44ee-9308-75e3cd31b816",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.450593Z",
"iopub.status.busy": "2024-01-21T18:01:29.450517Z",
"iopub.status.idle": "2024-01-21T18:01:29.452360Z",
"shell.execute_reply": "2024-01-21T18:01:29.452134Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"model.metadata[\"clock_name\"] = 'han'\n",
"model.metadata[\"data_type\"] = 'methylation'\n",
"model.metadata[\"species\"] = 'Homo sapiens'\n",
"model.metadata[\"year\"] = 2020\n",
"model.metadata[\"approved_by_author\"] = ''\n",
"model.metadata[\"approved_by_author\"] = ''\n",
"model.metadata[\"citation\"] = \"Han, Yang, et al. \\\"New targeted approaches for epigenetic age predictions.\\\" BMC biology 18 (2020): 1-15.\"\n",
"model.metadata[\"doi\"] = \"https://doi.org/10.1186/s12915-020-00807-2\"\n",
"model.metadata[\"notes\"] = None"
Expand All @@ -185,14 +157,7 @@
"cell_type": "code",
"execution_count": 5,
"id": "f1965587-a6ac-47ce-bd7a-bb98ca1d91b5",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.453897Z",
"iopub.status.busy": "2024-01-21T18:01:29.453822Z",
"iopub.status.idle": "2024-01-21T18:01:29.457401Z",
"shell.execute_reply": "2024-01-21T18:01:29.457151Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"# from authors\n",
Expand Down Expand Up @@ -347,14 +312,7 @@
"cell_type": "code",
"execution_count": 6,
"id": "77face1a-b58f-4f8f-9fe8-1f12037be99a",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.458774Z",
"iopub.status.busy": "2024-01-21T18:01:29.458700Z",
"iopub.status.idle": "2024-01-21T18:01:29.460648Z",
"shell.execute_reply": "2024-01-21T18:01:29.460422Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame({\n",
Expand All @@ -376,14 +334,7 @@
"cell_type": "code",
"execution_count": 7,
"id": "e09b3463-4fd4-41b1-ac21-e63ddd223fe0",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.462163Z",
"iopub.status.busy": "2024-01-21T18:01:29.462081Z",
"iopub.status.idle": "2024-01-21T18:01:29.463918Z",
"shell.execute_reply": "2024-01-21T18:01:29.463696Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"weights = torch.tensor(df['coefficient'][1:].tolist()).unsqueeze(0)\n",
Expand All @@ -402,14 +353,7 @@
"cell_type": "code",
"execution_count": 8,
"id": "d7f43b99-26f2-4622-9a76-316712058877",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.465279Z",
"iopub.status.busy": "2024-01-21T18:01:29.465206Z",
"iopub.status.idle": "2024-01-21T18:01:29.467199Z",
"shell.execute_reply": "2024-01-21T18:01:29.466975Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"base_model = pya.models.LinearModel(input_dim=len(model.features))\n",
Expand All @@ -432,14 +376,7 @@
"cell_type": "code",
"execution_count": 9,
"id": "ade0f4c9-2298-4fc3-bb72-d200907dd731",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.468705Z",
"iopub.status.busy": "2024-01-21T18:01:29.468624Z",
"iopub.status.idle": "2024-01-21T18:01:29.470055Z",
"shell.execute_reply": "2024-01-21T18:01:29.469821Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"model.reference_values = None"
Expand All @@ -457,14 +394,7 @@
"cell_type": "code",
"execution_count": 10,
"id": "7a22fb20-c605-424d-8efb-7620c2c0755c",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.471500Z",
"iopub.status.busy": "2024-01-21T18:01:29.471414Z",
"iopub.status.idle": "2024-01-21T18:01:29.472811Z",
"shell.execute_reply": "2024-01-21T18:01:29.472591Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"model.preprocess_name = None\n",
Expand All @@ -475,14 +405,7 @@
"cell_type": "code",
"execution_count": 11,
"id": "ff4a21cb-cf41-44dc-9ed1-95cf8aa15772",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.474175Z",
"iopub.status.busy": "2024-01-21T18:01:29.474086Z",
"iopub.status.idle": "2024-01-21T18:01:29.475546Z",
"shell.execute_reply": "2024-01-21T18:01:29.475285Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"model.postprocess_name = 'anti_log_linear'\n",
Expand All @@ -501,25 +424,18 @@
"cell_type": "code",
"execution_count": 12,
"id": "2168355c-47d9-475d-b816-49f65e74887c",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.476990Z",
"iopub.status.busy": "2024-01-21T18:01:29.476918Z",
"iopub.status.idle": "2024-01-21T18:01:29.479593Z",
"shell.execute_reply": "2024-01-21T18:01:29.479375Z"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"%========================================== Model Details ==========================================%\n",
"%==================================== Model Details ====================================%\n",
"Model Attributes:\n",
"\n",
"training: True\n",
"metadata: {'approved_by_author': '',\n",
"metadata: {'approved_by_author': '',\n",
" 'citation': 'Han, Yang, et al. \"New targeted approaches for epigenetic age '\n",
" 'predictions.\" BMC biology 18 (2020): 1-15.',\n",
" 'clock_name': 'han',\n",
Expand All @@ -537,20 +453,20 @@
"features: ['cg19283806', 'cg11807280', 'cg00329615', 'cg22454769', 'cg16867657', 'cg22796704', 'cg09809672', 'cg18618815', 'cg25533247', 'cg02286081', 'cg20222376', 'cg19344626', 'cg07082267', 'cg15845821', 'cg11741201', 'cg16054275', 'cg18933331', 'cg20249566', 'cg16604658', 'cg07583137', 'cg16008966', 'cg14556683', 'cg03746976', 'cg14314729', 'cg03431918', 'cg22156456', 'cg23078123', 'cg09748749', 'cg17457912', 'cg06492796']... [Total elements: 65]\n",
"base_model_features: None\n",
"\n",
"%========================================== Model Details ==========================================%\n",
"%==================================== Model Details ====================================%\n",
"Model Structure:\n",
"\n",
"base_model: LinearModel(\n",
" (linear): Linear(in_features=65, out_features=1, bias=True)\n",
")\n",
"\n",
"%========================================== Model Details ==========================================%\n",
"%==================================== Model Details ====================================%\n",
"Model Parameters and Weights:\n",
"\n",
"base_model.linear.weight: [-0.5883540511131287, -0.21203859150409698, 0.014351188205182552, 0.051285527646541595, 2.152191638946533, -0.6899405717849731, -0.6437299847602844, -0.772516131401062, 0.11666256934404373, -0.23340967297554016, 0.0028022590558975935, -0.062172431498765945, -0.22402729094028473, 1.5352094173431396, 0.344367653131485, 0.1888265311717987, -0.40915000438690186, -0.7760649919509888, 0.5003366470336914, 0.061250049620866776, -0.3916240930557251, 0.10044917464256287, 0.0200040303170681, 0.2660444676876068, -0.25982967019081116, 0.25406306982040405, -0.7261783480644226, -1.1419471502304077, -0.0632244125008583, -0.19692613184452057]... [Tensor of shape torch.Size([1, 65])]\n",
"base_model.linear.bias: tensor([0.7112])\n",
"\n",
"%========================================== Model Details ==========================================%\n",
"%==================================== Model Details ====================================%\n",
"\n"
]
}
Expand All @@ -571,14 +487,7 @@
"cell_type": "code",
"execution_count": 13,
"id": "936b9877-d076-4ced-99aa-e8d4c58c5caf",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.481157Z",
"iopub.status.busy": "2024-01-21T18:01:29.481041Z",
"iopub.status.idle": "2024-01-21T18:01:29.486806Z",
"shell.execute_reply": "2024-01-21T18:01:29.486544Z"
}
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -621,14 +530,7 @@
"cell_type": "code",
"execution_count": 14,
"id": "5ef2fa8d-c80b-4fdd-8555-79c0d541788e",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.488291Z",
"iopub.status.busy": "2024-01-21T18:01:29.488209Z",
"iopub.status.idle": "2024-01-21T18:01:29.490674Z",
"shell.execute_reply": "2024-01-21T18:01:29.490432Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"torch.save(model, f\"../weights/{model.metadata['clock_name']}.pt\")"
Expand All @@ -647,15 +549,16 @@
"cell_type": "code",
"execution_count": 15,
"id": "11aeaa70-44c0-42f9-86d7-740e3849a7a6",
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-21T18:01:29.492392Z",
"iopub.status.busy": "2024-01-21T18:01:29.492305Z",
"iopub.status.idle": "2024-01-21T18:01:29.494858Z",
"shell.execute_reply": "2024-01-21T18:01:29.494634Z"
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Deleted folder: .ipynb_checkpoints\n"
]
}
},
"outputs": [],
],
"source": [
"# Function to remove a folder and all its contents\n",
"def remove_folder(path):\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/_static/clock_glossary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ camilloh3k4me3,histone mark,Homo sapiens,2023,✅,https://doi.org/10.1101/2023.0
camilloh3k9ac,histone mark,Homo sapiens,2023,✅,https://doi.org/10.1101/2023.08.21.554165,,,,
camilloh3k9me3,histone mark,Homo sapiens,2023,✅,https://doi.org/10.1101/2023.08.21.554165,,,,
camillopanhistone,histone mark,Homo sapiens,2023,✅,https://doi.org/10.1101/2023.08.21.554165,,,,
han,methylation,Homo sapiens,2020,✅,https://doi.org/10.1186/s12915-020-00807-2,,,anti_log_linear,
knight,methylation,Homo sapiens,2016,✅,https://doi.org/10.1186/s13059-016-1068-z,,,,True
leecontrol,methylation,Homo sapiens,2019,✅,https://doi.org/10.18632/aging.102049,,,,
leerefinedrobust,methylation,Homo sapiens,2019,✅,https://doi.org/10.18632/aging.102049,,,,
leerobust,methylation,Homo sapiens,2019,✅,https://doi.org/10.18632/aging.102049,,,,
thompson,methylation,Mus musculus,2018,✅,https://doi.org/10.18632/aging.101590,,,,
dnamfitage,methylation,Homo sapiens,2023,⌛,https://doi.org/10.18632/aging.204538,,,,True
dnamfitage,methylation,Homo sapiens,2023,⌛,https://doi.org/10.18632/aging.204538,Reference values is mean between male and female training medians,,,True
dnamphenoage,methylation,Homo sapiens,2018,⌛,https://doi.org/10.18632%2Faging.101414,,,,
dnamtl,methylation,Homo sapiens,2019,⌛,https://doi.org/10.18632/aging.102173,,,,
dunedinpace,methylation,Homo sapiens,2022,⌛,https://doi.org/10.7554/eLife.73420,The automatic failure if fewer than 80% of the CpG probes are available is not implemented and left to the user's discretion.,quantile_normalization_with_gold_standard,,True
encen100,methylation,Homo sapiens,2023,⌛,https://doi.org/10.1007/s11357-023-00731-7,,,,
encen40,methylation,Homo sapiens,2023,⌛,https://doi.org/10.1007/s11357-023-00731-7,,,,
grimage,methylation,Homo sapiens,2019,⌛,https://doi.org/10.18632/aging.101684,,,cox_to_years,True
grimage2,methylation,Homo sapiens,2022,⌛,https://doi.org/10.18632/aging.204434,,,cox_to_years,True
han,methylation,Homo sapiens,2020,⌛,https://doi.org/10.1186/s12915-020-00807-2,,,anti_log_linear,
hannum,methylation,Homo sapiens,2013,⌛,https://doi.org/10.1016/j.molcel.2012.10.016,,,,
horvath2013,methylation,Homo sapiens,2013,⌛,https://doi.org/10.1186/gb-2013-14-10-r115,,,anti_log_linear,True
hrsinchphenoage,methylation,Homo sapiens,2022,⌛,https://doi.org/10.1038/s43587-022-00248-2,,,,
Expand Down
Loading

0 comments on commit 2350216

Please sign in to comment.