{ "cells": [ { "cell_type": "markdown", "id": "2f04eee0-5928-4e74-a754-6dc2e528810c", "metadata": {}, "source": [ "# DNAmFitAgeVO2Max" ] }, { "cell_type": "markdown", "id": "a3f514a3-772c-4a14-afdf-5a8376851ff4", "metadata": {}, "source": [ "## Index\n", "1. [Instantiate model class](#Instantiate-model-class)\n", "2. [Define clock metadata](#Define-clock-metadata)\n", "3. [Download clock dependencies](#Download-clock-dependencies)\n", "5. [Load features](#Load-features)\n", "6. [Load weights into base model](#Load-weights-into-base-model)\n", "7. [Load reference values](#Load-reference-values)\n", "8. [Load preprocess and postprocess objects](#Load-preprocess-and-postprocess-objects)\n", "10. [Check all clock parameters](#Check-all-clock-parameters)\n", "10. [Basic test](#Basic-test)\n", "11. [Save torch model](#Save-torch-model)\n", "12. [Clear directory](#Clear-directory)" ] }, { "cell_type": "markdown", "id": "d95fafdc-643a-40ea-a689-200bd132e90c", "metadata": {}, "source": [ "Let's first import some packages:" ] }, { "cell_type": "code", "execution_count": 1, "id": "4adfb4de-cd79-4913-a1af-9e23e9e236c9", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:23.621657Z", "iopub.status.busy": "2025-04-07T17:50:23.621346Z", "iopub.status.idle": "2025-04-07T17:50:25.088787Z", "shell.execute_reply": "2025-04-07T17:50:25.088401Z" } }, "outputs": [], "source": [ "import os\n", "import inspect\n", "import shutil\n", "import json\n", "import torch\n", "import pandas as pd\n", "import numpy as np\n", "import pyaging as pya" ] }, { "cell_type": "markdown", "id": "145082e5-ced4-47ae-88c0-cb69773e3c5a", "metadata": {}, "source": [ "## Instantiate model class" ] }, { "cell_type": "code", "execution_count": 2, "id": "8aa77372-7ed3-4da7-abc9-d30372106139", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:25.090492Z", "iopub.status.busy": "2025-04-07T17:50:25.090265Z", "iopub.status.idle": "2025-04-07T17:50:25.101917Z", "shell.execute_reply": "2025-04-07T17:50:25.101643Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "class DNAmFitAgeVO2Max(pyagingModel):\n", " def __init__(self):\n", " super().__init__()\n", "\n", " def preprocess(self, x):\n", " return x\n", " \n", " def postprocess(self, x):\n", " return x\n", "\n" ] } ], "source": [ "def print_entire_class(cls):\n", " source = inspect.getsource(cls)\n", " print(source)\n", "\n", "print_entire_class(pya.models.DNAmFitAgeVO2Max)" ] }, { "cell_type": "code", "execution_count": 3, "id": "914a94cf-bf6c-4b9d-862a-a2787842e07e", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:25.103160Z", "iopub.status.busy": "2025-04-07T17:50:25.103071Z", "iopub.status.idle": "2025-04-07T17:50:25.104710Z", "shell.execute_reply": "2025-04-07T17:50:25.104466Z" } }, "outputs": [], "source": [ "model = pya.models.DNAmFitAgeVO2Max()" ] }, { "cell_type": "markdown", "id": "51f8615e-01fa-4aa5-b196-3ee2b35d261c", "metadata": {}, "source": [ "## Define clock metadata" ] }, { "cell_type": "code", "execution_count": 4, "id": "6609d6dc-c0a0-4137-bdf5-9fb31ea85281", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:25.105997Z", "iopub.status.busy": "2025-04-07T17:50:25.105908Z", "iopub.status.idle": "2025-04-07T17:50:25.107874Z", "shell.execute_reply": "2025-04-07T17:50:25.107633Z" } }, "outputs": [], "source": [ "model.metadata[\"clock_name\"] = \"dnamfitagevo2max\"\n", "model.metadata[\"data_type\"] = \"DNA methylation\" # Paper: Blood DNA methylation was used to develop the fitness biomarkers.\n", "model.metadata[\"species\"] = \"Homo sapiens\" # Paper: The development cohorts were human adult studies (FHS, BLSA, and Budapest).\n", "model.metadata[\"year\"] = 2023\n", "model.metadata[\"approved_by_author\"] = \"⌛\"\n", "model.metadata[\"citation\"] = \"McGreevy, K. M., et al. “DNAmFitAge: biological age indicator incorporating physical fitness.” Aging 15(10): 3904–3938 (2023).\"\n", "model.metadata[\"doi\"] = \"https://doi.org/10.18632/aging.204538\"\n", "model.metadata[\"notes\"] = \"Joint-sex blood DNAm estimator of maximal oxygen uptake; 40 CpGs plus chronological age are packaged as 41 inputs.\"\n", "model.metadata[\"research_only\"] = None\n", "model.metadata[\"tissue\"] = [\"whole blood\"] # Paper: The biomarkers were developed from blood DNAm data.\n", "model.metadata[\"predicts\"] = [\"VO2max\"] # Paper: The algorithms generate DNAmGaitspeed, DNAmGripmax, or DNAmVO2max estimates in the corresponding physical-fitness scale.\n", "model.metadata[\"training_target\"] = [\"VO2max\"] # Paper: The directly measured fitness parameter was the dependent variable in LASSO regression.\n", "model.metadata[\"unit\"] = [\"milliliters per kilogram per minute\"] # Paper: Gait speed is measured in m/s, grip force in kg, and VO2max in mL/kg/min.\n", "model.metadata[\"model_type\"] = \"LASSO regression\" # Paper: Each fitness DNAm biomarker was developed using LASSO penalized regression with ten-fold cross-validation.\n", "model.metadata[\"platform\"] = [\"Illumina 450K\"] # Paper: The reported fitness CpG background and fitted loci were on the 450K array.\n", "model.metadata[\"population\"] = \"adults\" # Paper: Development used FHS (n=1,830), BLSA (n=820), and Budapest (n=307) adults.\n", "model.metadata[\"journal\"] = \"Aging\"\n", "model.metadata[\"last_author\"] = \"Steve Horvath\"\n", "model.metadata[\"n_features\"] = 41\n", "model.metadata[\"citations\"] = 99\n", "model.metadata[\"citations_date\"] = \"2026-07-05\"\n" ] }, { "cell_type": "markdown", "id": "74492239-5aae-4026-9d90-6bc9c574c110", "metadata": {}, "source": [ "## Download clock dependencies" ] }, { "cell_type": "markdown", "id": "7bec474f-80ce-4884-9472-30c193327117", "metadata": {}, "source": [ "#### Download GitHub repository" ] }, { "cell_type": "code", "execution_count": 5, "id": "aa4a1b59-dda3-4ea8-8f34-b3c53ecbc310", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:25.109229Z", "iopub.status.busy": "2025-04-07T17:50:25.109147Z", "iopub.status.idle": "2025-04-07T17:50:25.651487Z", "shell.execute_reply": "2025-04-07T17:50:25.650965Z" } }, "outputs": [ { "data": { "text/plain": [ "32768" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "github_url = \"https://github.com/kristenmcgreevy/DNAmFitAge.git\"\n", "github_folder_name = github_url.split('/')[-1].split('.')[0]\n", "os.system(f\"git clone {github_url}\")" ] }, { "cell_type": "markdown", "id": "6bd15521-363f-4029-99ff-9f0b2ae0ed2e", "metadata": {}, "source": [ "#### Download from R package" ] }, { "cell_type": "code", "execution_count": 6, "id": "f1f9bbe4-cfc8-494c-b910-c96da88afb2b", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:25.653928Z", "iopub.status.busy": "2025-04-07T17:50:25.653723Z", "iopub.status.idle": "2025-04-07T17:50:25.657586Z", "shell.execute_reply": "2025-04-07T17:50:25.657192Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Overwriting download.r\n" ] } ], "source": [ "%%writefile download.r\n", "\n", "options(repos = c(CRAN = \"https://cloud.r-project.org/\"))\n", "library(jsonlite)\n", "\n", "DNAmFitnessModels <- readRDS(\"DNAmFitAge/DNAmFitnessModelsandFitAge_Oct2022.rds\")\n", "\n", "AllCpGs <- DNAmFitnessModels$AllCpGs\n", "write_json(AllCpGs, \"AllCpGs.json\")\n", "\n", "MaleMedians <- DNAmFitnessModels$Male_Medians_All\n", "write.csv(MaleMedians, \"MaleMedians.csv\")\n", "FemaleMedians <- DNAmFitnessModels$Female_Medians_All\n", "write.csv(FemaleMedians, \"FemaleMedians.csv\")\n", "\n", "Gait_noAge_Females <- DNAmFitnessModels$Gait_noAge_Females\n", "Gait_noAge_Males <- DNAmFitnessModels$Gait_noAge_Males\n", "Grip_noAge_Females <- DNAmFitnessModels$Grip_noAge_Females\n", "Grip_noAge_Males <- DNAmFitnessModels$Grip_noAge_Males\n", "VO2maxModel <- DNAmFitnessModels$VO2maxModel\n", "write.csv(Gait_noAge_Females, \"Gait_noAge_Females.csv\")\n", "write.csv(Gait_noAge_Males, \"Gait_noAge_Males.csv\")\n", "write.csv(Grip_noAge_Females, \"Grip_noAge_Females.csv\")\n", "write.csv(Grip_noAge_Males, \"Grip_noAge_Males.csv\")\n", "write.csv(VO2maxModel, \"VO2maxModel.csv\")" ] }, { "cell_type": "code", "execution_count": 7, "id": "f1965587-a6ac-47ce-bd7a-bb98ca1d91b5", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:25.659496Z", "iopub.status.busy": "2025-04-07T17:50:25.659322Z", "iopub.status.idle": "2025-04-07T17:50:27.279878Z", "shell.execute_reply": "2025-04-07T17:50:27.279562Z" } }, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "os.system(\"Rscript download.r\")" ] }, { "cell_type": "markdown", "id": "5035b180-3d1b-4432-8ebe-b9c92bd93a7f", "metadata": {}, "source": [ "## Load features" ] }, { "cell_type": "markdown", "id": "d8025ed7-0013-419b-8cb5-1a2db98f9eba", "metadata": {}, "source": [ "#### From JSON file" ] }, { "cell_type": "code", "execution_count": 8, "id": "c0b63afa", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
termstepestimatelambdadev.ratiofeaturecoefficient
1(Intercept)169.6523171.80.368651(Intercept)69.652317
2cg0872111215.2491301.80.368651cg087211125.249130
3cg0654074713.0901761.80.368651cg065407473.090176
4cg223596061-7.5511671.80.368651cg22359606-7.551167
5cg030410291-5.7965451.80.368651cg03041029-5.796545
\n", "
" ], "text/plain": [ " term step estimate lambda dev.ratio feature coefficient\n", "1 (Intercept) 1 69.652317 1.8 0.368651 (Intercept) 69.652317\n", "2 cg08721112 1 5.249130 1.8 0.368651 cg08721112 5.249130\n", "3 cg06540747 1 3.090176 1.8 0.368651 cg06540747 3.090176\n", "4 cg22359606 1 -7.551167 1.8 0.368651 cg22359606 -7.551167\n", "5 cg03041029 1 -5.796545 1.8 0.368651 cg03041029 -5.796545" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_csv('VO2maxModel.csv', index_col=0)\n", "df['feature'] = df['term']\n", "df['coefficient'] = df['estimate']\n", "model.features = df['feature'][1:-1].tolist() + ['age']\n", "df.head()" ] }, { "cell_type": "markdown", "id": "ee6d8fa0-4767-4c45-9717-eb1c95e2ddc0", "metadata": {}, "source": [ "## Load weights into base model" ] }, { "cell_type": "code", "execution_count": 9, "id": "8d58875d", "metadata": {}, "outputs": [], "source": [ "weights = torch.tensor(df['coefficient'][1:].tolist()).unsqueeze(0)\n", "intercept = torch.tensor([df['coefficient'].iloc[0]])" ] }, { "cell_type": "markdown", "id": "69901c2b-9584-4de3-a642-ddb6b43d923a", "metadata": {}, "source": [ "#### Linear model" ] }, { "cell_type": "code", "execution_count": 10, "id": "5fb10110-a89a-4caa-a62a-59899ebccd23", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:27.292804Z", "iopub.status.busy": "2025-04-07T17:50:27.292717Z", "iopub.status.idle": "2025-04-07T17:50:27.302996Z", "shell.execute_reply": "2025-04-07T17:50:27.302732Z" } }, "outputs": [], "source": [ "base_model = pya.models.LinearModel(input_dim=len(model.features))\n", "\n", "base_model.linear.weight.data = weights.float()\n", "base_model.linear.bias.data = intercept.float()\n", "\n", "model.base_model = base_model" ] }, { "cell_type": "markdown", "id": "ad8b4c1d-9d57-48b7-9a30-bcfea7b747b1", "metadata": {}, "source": [ "## Load reference values" ] }, { "cell_type": "markdown", "id": "f7fdae64-096a-4640-ade7-6a17b78a01d5", "metadata": {}, "source": [ "#### From CSV file" ] }, { "cell_type": "code", "execution_count": 11, "id": "e1dc004f-06b7-4e24-a937-00736e93765f", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:27.308644Z", "iopub.status.busy": "2025-04-07T17:50:27.308553Z", "iopub.status.idle": "2025-04-07T17:50:27.323332Z", "shell.execute_reply": "2025-04-07T17:50:27.323061Z" } }, "outputs": [], "source": [ "reference_df_f = pd.read_csv('FemaleMedians.csv', index_col=0)\n", "reference_f = reference_df_f.loc[1, model.features[:-1]]\n", "reference_df_m = pd.read_csv('MaleMedians.csv', index_col=0)\n", "reference_m = reference_df_m.loc[1, model.features[:-1]]\n", "reference = (reference_f + reference_m)/2\n", "model.reference_values = list(reference) + [65] " ] }, { "cell_type": "markdown", "id": "af3bcf7b-74a8-4d21-9ccb-4de0c2b0516b", "metadata": {}, "source": [ "## Load preprocess and postprocess objects" ] }, { "cell_type": "code", "execution_count": 12, "id": "79a1b3a2-00f1-42b1-9fcd-f919343391d7", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:27.324794Z", "iopub.status.busy": "2025-04-07T17:50:27.324706Z", "iopub.status.idle": "2025-04-07T17:50:27.326219Z", "shell.execute_reply": "2025-04-07T17:50:27.325910Z" } }, "outputs": [], "source": [ "model.preprocess_name = None\n", "model.preprocess_dependencies = None" ] }, { "cell_type": "code", "execution_count": 13, "id": "ff4a21cb-cf41-44dc-9ed1-95cf8aa15772", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:27.327714Z", "iopub.status.busy": "2025-04-07T17:50:27.327614Z", "iopub.status.idle": "2025-04-07T17:50:27.329350Z", "shell.execute_reply": "2025-04-07T17:50:27.329050Z" } }, "outputs": [], "source": [ "model.postprocess_name = None\n", "model.postprocess_dependencies = None" ] }, { "cell_type": "markdown", "id": "86e3d6b1-e67e-4f3d-bd39-0ebec5726c3c", "metadata": {}, "source": [ "## Check all clock parameters" ] }, { "cell_type": "code", "execution_count": 14, "id": "2168355c-47d9-475d-b816-49f65e74887c", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:27.330820Z", "iopub.status.busy": "2025-04-07T17:50:27.330730Z", "iopub.status.idle": "2025-04-07T17:50:27.336089Z", "shell.execute_reply": "2025-04-07T17:50:27.335809Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "%==================================== Model Details ====================================%\n", "Model Attributes:\n", "\n", "training: True\n", "metadata: {'approved_by_author': '⌛',\n", " 'citation': 'McGreevy, Kristen M., et al. \"DNAmFitAge: biological age '\n", " 'indicator incorporating physical fitness.\" Aging (Albany NY) '\n", " '15.10 (2023): 3904.',\n", " 'clock_name': 'dnamfitagevo2max',\n", " 'data_type': 'methylation',\n", " 'doi': 'https://doi.org/10.18632/aging.204538',\n", " 'notes': 'Reference values is mean between male and female training medians',\n", " 'research_only': None,\n", " 'species': 'Homo sapiens',\n", " 'version': None,\n", " 'year': 2023}\n", "reference_values: [0.588137182005736, 0.091356441802012, 0.0707204363181266, 0.6412617944885715, 0.535138543094586, 0.5437546990565185, 0.930382573680189, 0.0242279670663961, 0.09365587082155075, 0.6242147821751816, 0.35000302571538, 0.869293193371122, 0.1280519183158855, 0.0294186147410821, 0.09983154938858019, 0.9755683687837085, 0.600750498775525, 0.14779655808084802, 0.1563590903974515, 0.537387884063212, 0.923580030601587, 0.9329177575485086, 0.07460485276649155, 0.6081440126190596, 0.7695271383829341, 0.9139682130144675, 0.1163057238787645, 0.0245550999871068, 0.247020660722574, 0.8178191327449524]... [Total elements: 41]\n", "preprocess_name: None\n", "preprocess_dependencies: None\n", "postprocess_name: None\n", "postprocess_dependencies: None\n", "features: ['cg08721112', 'cg06540747', 'cg22359606', 'cg03041029', 'cg25693769', 'cg08140055', 'cg02401614', 'cg24960960', 'cg09184832', 'cg11998932', 'cg22103219', 'cg16037896', 'cg18788741', 'cg12054428', 'cg14470803', 'cg13557031', 'cg03804621', 'cg14868747', 'cg08533783', 'cg04835841', 'cg11846355', 'cg09910000', 'cg26494929', 'cg06808011', 'cg05708497', 'cg23441888', 'cg27615578', 'cg08648367', 'cg17609057', 'cg04605816']... [Total elements: 41]\n", "base_model_features: None\n", "\n", "%==================================== Model Details ====================================%\n", "Model Structure:\n", "\n", "base_model: LinearModel(\n", " (linear): Linear(in_features=41, out_features=1, bias=True)\n", ")\n", "\n", "%==================================== Model Details ====================================%\n", "Model Parameters and Weights:\n", "\n", "base_model.linear.weight: [5.249129772186279, 3.0901758670806885, -7.551166534423828, -5.796545028686523, -1.094834804534912, -2.3806116580963135, -0.0022889631800353527, 1.0938740968704224, -1.4775551557540894, 1.4427802562713623, 1.268430471420288, 5.4764933586120605, -8.934550285339355, -1.9918478727340698, -5.6620774269104, -6.2174201011657715, -0.6082701086997986, -7.513339996337891, -1.4299590587615967, -3.6723220348358154, 14.669830322265625, 0.5884844660758972, -0.9597266912460327, -1.0253041982650757, -1.802089810371399, -4.9922356605529785, -0.6746888160705566, -10.973499298095703, -0.6614307761192322, 2.365175247192383]... [Tensor of shape torch.Size([1, 41])]\n", "base_model.linear.bias: tensor([69.6523])\n", "\n", "%==================================== Model Details ====================================%\n", "\n" ] } ], "source": [ "pya.utils.print_model_details(model)" ] }, { "cell_type": "markdown", "id": "986d0262-e0c7-4036-b687-dee53ba392fb", "metadata": {}, "source": [ "## Basic test" ] }, { "cell_type": "code", "execution_count": 15, "id": "352cffb0-c5a8-4c82-8f61-fce35baf5a22", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:27.337690Z", "iopub.status.busy": "2025-04-07T17:50:27.337490Z", "iopub.status.idle": "2025-04-07T17:50:27.346106Z", "shell.execute_reply": "2025-04-07T17:50:27.345820Z" } }, "outputs": [ { "data": { "text/plain": [ "tensor([[ 40.8178],\n", " [ 99.1144],\n", " [ 95.0538],\n", " [ 67.0306],\n", " [105.7898],\n", " [ 33.1438],\n", " [ 64.7387],\n", " [ 74.8257],\n", " [129.5815],\n", " [ 17.3352]], dtype=torch.float64, grad_fn=)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "torch.manual_seed(42)\n", "input = torch.randn(10, len(model.features), dtype=float)\n", "model.eval()\n", "model.to(float)\n", "pred = model(input)\n", "pred" ] }, { "cell_type": "markdown", "id": "fe8299d7-9285-4e22-82fd-b664434b4369", "metadata": {}, "source": [ "## Save torch model" ] }, { "cell_type": "code", "execution_count": 16, "id": "0c3a2d80-1b5f-458a-926c-cbc0aa9416e1", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:27.347459Z", "iopub.status.busy": "2025-04-07T17:50:27.347364Z", "iopub.status.idle": "2025-04-07T17:50:27.350847Z", "shell.execute_reply": "2025-04-07T17:50:27.350573Z" } }, "outputs": [], "source": [ "torch.save(model, f\"../weights/{model.metadata['clock_name']}.pt\")" ] }, { "cell_type": "markdown", "id": "bac6257b-8d08-4a90-8d0b-7f745dc11ac1", "metadata": {}, "source": [ "## Clear directory\n", "" ] }, { "cell_type": "code", "execution_count": 17, "id": "11aeaa70-44c0-42f9-86d7-740e3849a7a6", "metadata": { "execution": { "iopub.execute_input": "2025-04-07T17:50:27.352136Z", "iopub.status.busy": "2025-04-07T17:50:27.352040Z", "iopub.status.idle": "2025-04-07T17:50:27.360420Z", "shell.execute_reply": "2025-04-07T17:50:27.360132Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Deleted file: Grip_noAge_Females.csv\n", "Deleted file: Grip_noAge_Males.csv\n", "Deleted file: Gait_noAge_Females.csv\n", "Deleted file: VO2maxModel.csv\n", "Deleted file: AllCpGs.json\n", "Deleted file: Gait_noAge_Males.csv\n", "Deleted folder: DNAmFitAge\n", "Deleted file: download.r\n", "Deleted file: FemaleMedians.csv\n", "Deleted file: MaleMedians.csv\n" ] } ], "source": [ "# Function to remove a folder and all its contents\n", "def remove_folder(path):\n", " try:\n", " shutil.rmtree(path)\n", " print(f\"Deleted folder: {path}\")\n", " except Exception as e:\n", " print(f\"Error deleting folder {path}: {e}\")\n", "\n", "# Get a list of all files and folders in the current directory\n", "all_items = os.listdir('.')\n", "\n", "# Loop through the items\n", "for item in all_items:\n", " # Check if it's a file and does not end with .ipynb\n", " if os.path.isfile(item) and not item.endswith('.ipynb'):\n", " os.remove(item)\n", " print(f\"Deleted file: {item}\")\n", " # Check if it's a folder\n", " elif os.path.isdir(item):\n", " remove_folder(item)" ] } ], "metadata": { "kernelspec": { "display_name": "research", "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.7" } }, "nbformat": 4, "nbformat_minor": 5 }