### Install Biolearn using pip Source: https://bio-learn.github.io/quickstart.html Use this command to install the biolearn library. Ensure you have Python 3.10+ installed. ```bash pip install biolearn ``` -------------------------------- ### Deconvolution Example Source: https://bio-learn.github.io/auto_examples/index.html This example shows how to perform deconvolution on a dataset with known cell proportions. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of deconvolution # ... (actual code would go here) ``` -------------------------------- ### Exploring the Challenge Data Source: https://bio-learn.github.io/auto_examples/index.html This example shows how to explore the data provided for a challenge. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of exploring challenge data # ... (actual code would go here) ``` -------------------------------- ### Training an ElasticNet Model Source: https://bio-learn.github.io/auto_examples/index.html This example demonstrates how to train an ElasticNet model. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of training an ElasticNet model # ... (actual code would go here) ``` -------------------------------- ### Building a Competition Submission Source: https://bio-learn.github.io/auto_examples/index.html This example demonstrates how to build a competition submission using an existing model. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of building a competition submission # ... (actual code would go here) ``` -------------------------------- ### Hurdle InflammAge API Example Source: https://bio-learn.github.io/auto_examples/index.html This example demonstrates how to use the Hurdle InflammAge API. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example usage of Hurdle InflammAge API # ... (actual code would go here) ``` -------------------------------- ### Local Data Loading Example Source: https://bio-learn.github.io/auto_examples/index.html This example shows how to load data locally using Biolearn. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of local data loading # ... (actual code would go here) ``` -------------------------------- ### Clock/Model Visualizations using GEO Datasets Source: https://bio-learn.github.io/auto_examples/index.html This example shows how to visualize clocks and models using GEO datasets. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of clock/model visualizations with GEO datasets # ... (actual code would go here) ``` -------------------------------- ### Verify Biolearn Installation Source: https://bio-learn.github.io/quickstart.html After installation, run this code in a Python interpreter or Jupyter notebook to confirm that the DataLibrary class can be imported without errors. ```python from biolearn.data_library import DataLibrary ``` -------------------------------- ### Quality Control Visualization using GEO Datasets Source: https://bio-learn.github.io/auto_examples/index.html This example demonstrates visualization for quality control using GEO datasets. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of quality control visualization with GEO datasets # ... (actual code would go here) ``` -------------------------------- ### DNA Methylation Visualizations using GEO Datasets Source: https://bio-learn.github.io/auto_examples/index.html This example demonstrates DNA methylation visualizations using GEO datasets. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of DNA methylation visualizations with GEO datasets # ... (actual code would go here) ``` -------------------------------- ### Transcriptomic Clock using GEO Data Source: https://bio-learn.github.io/auto_examples/index.html This example demonstrates how to use a transcriptomic clock with data from GEO. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of transcriptomic clock using GEO data # ... (actual code would go here) ``` -------------------------------- ### Epigenetic Clocks using GEO Data Source: https://bio-learn.github.io/auto_examples/index.html This example demonstrates how to use epigenetic clocks with data from GEO. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of epigenetic clocks using GEO data # ... (actual code would go here) ``` -------------------------------- ### Phenotypic Ages in NHANES Data Source: https://bio-learn.github.io/auto_examples/index.html This example shows how to calculate and plot phenotypic ages using NHANES data. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of phenotypic ages in NHANES data # ... (actual code would go here) ``` -------------------------------- ### Performing Custom Imputations Source: https://bio-learn.github.io/auto_examples/index.html This example demonstrates how to perform custom data imputations using Biolearn. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of performing custom imputations # ... (actual code would go here) ``` -------------------------------- ### Down Syndrome Epigenetic Plotting Source: https://bio-learn.github.io/auto_examples/index.html This example shows how to perform epigenetic plotting for Down Syndrome data. Ensure you have write permissions in the directory where you run the examples. ```python import biolearn # Example of Down Syndrome epigenetic plotting # ... (actual code would go here) ``` -------------------------------- ### Import BioLearn Classes and Functions Source: https://bio-learn.github.io/_downloads/37a16eeb64cb047f7329c72df903f23a/plot_quality_control.ipynb Imports DataLibrary, GeoData, and plot_sample_deviations from the biolearn library. Ensure these modules are installed. ```python from biolearn.data_library import DataLibrary, GeoData from biolearn.visualize import plot_sample_deviations ``` -------------------------------- ### Load NHANES 2010 Data Source: https://bio-learn.github.io/auto_examples/01_composite_biomarkers/plot_nhanes.html Loads blood exam data from NHANES 2010 and calculates 'years_until_death'. Ensure the biolearn library is installed. ```python from biolearn.load import load_nhanes year = 2010 df = load_nhanes(year) df["years_until_death"] = df["months_until_death"] / 12 ``` -------------------------------- ### Regression statistics output Source: https://bio-learn.github.io/auto_examples/04_additional_visualizations/plot_dnam_relationships.html Example output showing R-squared and Pearson correlation values for a specific CpG site. ```text Computed statistics for CpG site: cg00000029 Linear Regression R^2: 0.0311 Pearson Correlation (r): -0.1764 Pearson Correlation p-value: 8.2813e-03 Polynomial Regression (Degree 2) R^2: 0.0327 ``` -------------------------------- ### Metadata CSV Format Source: https://bio-learn.github.io/methylation-standard.html Example of a metadata file formatted as a CSV with sample identifiers and associated clinical fields. ```text SampleID Sex Age Disease State GSM3074480 0 25.2 None GSM3074481 0 29.5 COVID GSM3074482 1 39.7 None ``` -------------------------------- ### GET biolearn.load.load_nhanes Source: https://bio-learn.github.io/modules/generated/biolearn.load.load_nhanes.html Loads data from the National Health and Nutrition Examination Survey (NHANES) for a specified year. ```APIDOC ## GET biolearn.load.load_nhanes ### Description Loads data from the National Health and Nutrition Examination Survey (NHANES). Note that NHANES data comes in two-year groupings and the year passed in should be the later year. ### Parameters #### Query Parameters - **year** (number) - Required - A year number for which to load data. Supported inputs are 2010 and 2012. ### Response #### Success Response (200) - **df** (Pandas.Dataframe) - A pandas dataframe where each row represents an individual and each column represents a measurement about that individual. ``` -------------------------------- ### DNA Methylation Data Format Source: https://bio-learn.github.io/methylation-standard.html Example of a DNA methylation file showing CpG sites as rows and samples as columns with beta values. ```text cpgSite GSM3074480 GSM3074481 GSM3074482 GSM3074483 cg00000029 0.395 0.499 0.42 0.423 cg00000109 0.821 0.868 0.877 0.841 cg00000155 0.878 0.89 0.894 0.822 ``` -------------------------------- ### GET biolearn.cache.NoCache.get Source: https://bio-learn.github.io/modules/generated/biolearn.cache.NoCache.html Retrieves a cache entry. In the NoCache implementation, this method always returns None, indicating a cache miss. ```APIDOC ## GET biolearn.cache.NoCache.get ### Description Retrieve a cache entry. This method always returns None, indicating a cache miss. ### Parameters #### Query Parameters - **key** (str) - Required - Unique key identifying the cache entry. - **category** (str) - Required - Cache category name. - **version** (str) - Required - Version string for invalidation. ### Response #### Success Response (200) - **result** (None) - Always returns None. ``` -------------------------------- ### LocalFolderCache Initialization Source: https://bio-learn.github.io/modules/generated/biolearn.cache.LocalFolderCache.html Initializes the LocalFolderCache with a specified path and maximum size. ```APIDOC ## LocalFolderCache.__init__ ### Description Initialize the LocalFolderCache. ### Method __init__ ### Parameters #### Path Parameters - **path** (str) - Required - Directory path for storing cache files. - **max_size_gb** (float) - Required - Maximum total cache size in gigabytes. ``` -------------------------------- ### Import biolearn visualization classes and functions Source: https://bio-learn.github.io/_downloads/108af8868614eea84b27d2927b9893eb/plot_clock_model_relationships.ipynb Initializes the necessary modules for data loading, model retrieval, and visualization. ```python from biolearn.data_library import DataLibrary from biolearn.model_gallery import ModelGallery from biolearn.visualize import ( plot_clock_correlation_matrix, plot_clock_deviation_heatmap, plot_age_prediction, plot_health_outcome ) ``` -------------------------------- ### ModelGallery Initialization Source: https://bio-learn.github.io/modules/generated/biolearn.model_gallery.ModelGallery.html Initializes the ModelGallery instance with a dictionary of model definitions. ```APIDOC ## ModelGallery.__init__ ### Description Initializes the ModelGallery instance. ### Method __init__ ### Parameters #### Request Body - **models** (dict) - Required - A dictionary of model definitions. ### Request Example ```json { "models": { "model1": { ... }, "model2": { ... } } } ``` ### Response #### Success Response (200) - **ModelGallery instance** (object) - The initialized ModelGallery object. ### Response Example ```json { "message": "ModelGallery initialized successfully" } ``` ``` -------------------------------- ### LocalFolderCache Initialization Source: https://bio-learn.github.io/data.html Initialize `LocalFolderCache` to use a local folder for caching. Specify the directory path for storing cached data. ```python from biolearn.cache import LocalFolderCache cache = LocalFolderCache(cache_dir='/path/to/cache') ``` -------------------------------- ### DataLibrary Get Source Source: https://bio-learn.github.io/modules/generated/biolearn.data_library.DataLibrary.html Retrieves a data source by its identifier. ```APIDOC ## DataLibrary.get ### Description Retrieves a data source by its identifier. ### Method get ### Parameters #### Path Parameters - **source_id** (str) - Required - The identifier of the data source to retrieve. ### Response #### Success Response (200) - **source** (object) - The data source with the given identifier if found, otherwise None. ``` -------------------------------- ### GET biolearn.load.load_fhs Source: https://bio-learn.github.io/modules/generated/biolearn.load.load_fhs.html Retrieves the Framingham Heart Study dataset as a pandas DataFrame. ```APIDOC ## biolearn.load.load_fhs ### Description Loads data from the Framingham Heart Study. ### Response #### Success Response (200) - **df** (Pandas.Dataframe) - A pandas dataframe where each row represents an individual and each column represents a measurement about that individual. ``` -------------------------------- ### DataLibrary Initialization Source: https://bio-learn.github.io/modules/generated/biolearn.data_library.DataLibrary.html Initializes the DataLibrary instance with an optional library file and cache mechanism. ```APIDOC ## DataLibrary.__init__ ### Description Initializes the DataLibrary instance with an optional library file and cache mechanism. ### Method __init__ ### Parameters #### Path Parameters - **library_file** (str) - Optional - The path to the library file. If None, the default biolearn library file is loaded. - **cache** (object) - Optional - An object that adheres to the caching interface used in the caching module. If None, the default cache is used. This cache will be used by all returned data sources ``` -------------------------------- ### DataLibrary Initialization Source: https://bio-learn.github.io/clocks.html Initialize a `DataLibrary` object from `biolearn.data_library` to manage data sources. Specify the directory where data is stored. ```python from biolearn.data_library import DataLibrary data_library = DataLibrary(data_dir="/path/to/data") ``` -------------------------------- ### Split data into training and test sets Source: https://bio-learn.github.io/_downloads/9d6419c1b7da427cabe6da2ae524be9e/training_simple_model.ipynb Prepares the feature matrix and target vector, then splits the data for model evaluation. ```python from sklearn.model_selection import train_test_split df = data.dnam.transpose() df['age'] = data.metadata['age'] top_sites_df = df[stable_cpg_names] X = top_sites_df y = df['age'] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) ``` -------------------------------- ### DataSource Initialization Source: https://bio-learn.github.io/clocks.html Create a `DataSource` object from `biolearn.data_library` to represent a specific data source. This is typically done within a `DataLibrary` context. ```python from biolearn.data_library import DataSource source = DataSource(name="my_source", data_dir="/path/to/source") ``` -------------------------------- ### Load Data and Initialize Hurdle InflammAge API Source: https://bio-learn.github.io/auto_examples/hurdle_api_example.html Loads sample data from the DataLibrary and checks for the required HURDLE_API_KEY environment variable before proceeding with model operations. ```python import os import pandas as pd from biolearn.model_gallery import ModelGallery from biolearn.data_library import DataLibrary print("Loading sample data...") data = DataLibrary().get("BoAChallengeData").load() # Use first 5 samples for quick testing sample_data = data.dnam.iloc[:, :5] print(f"Using {sample_data.shape[1]} samples with {sample_data.shape[0]} CpG sites") gallery = ModelGallery() # Check if API key is set if not os.environ.get("HURDLE_API_KEY"): print("\nNo HURDLE_API_KEY environment variable found.") api_key = input("Enter your Hurdle API key: ").strip() if api_key: os.environ["HURDLE_API_KEY"] = api_key else: print("No API key provided. Exiting.") exit(1) ``` -------------------------------- ### ModelGallery Initialization Source: https://bio-learn.github.io/data.html Initialize `ModelGallery` to access a collection of pre-trained models. This class is central to applying existing models to new data. ```python from biolearn.model_gallery import ModelGallery model_gallery = ModelGallery() ``` -------------------------------- ### Load NHANES 2010 Data Source: https://bio-learn.github.io/_downloads/6ba1afcbb57f61d1d68110657ea7d4a7/plot_nhanes.ipynb Imports the NHANES dataset and calculates the years until death from the provided months. ```python from biolearn.load import load_nhanes year = 2010 df = load_nhanes(year) df["years_until_death"] = df["months_until_death"] / 12 ``` -------------------------------- ### Load Methylation Data from GEO Source: https://bio-learn.github.io/auto_examples/00_omics_biomarkers/plot_down_syndrome_model.html Loads DNA methylation data from a specified GEO accession using the DataLibrary. Ensure the 'biolearn' library is installed. ```python from biolearn.data_library import DataLibrary test_data = DataLibrary().get("GSE52588").load() ``` -------------------------------- ### Generate Quality Reports for Datasets Source: https://bio-learn.github.io/_downloads/37a16eeb64cb047f7329c72df903f23a/plot_quality_control.ipynb Iterates through the loaded datasets and generates a quality report for each. The .show() method displays the report. ```python [dataset.quality_report().show() for dataset in datasets.values()] ``` -------------------------------- ### Load GEO Blood Methylation Dataset Source: https://bio-learn.github.io/_downloads/ed93f9c54e6f01466b8a5a0db47f22b0/plot_blood_deconvolution.ipynb Loads the GSE112618 dataset, which contains blood DNA methylation data measured on the EPIC platform. Ensure the biolearn library is installed. ```python from biolearn.data_library import DataLibrary epic_facs_salas_18 = DataLibrary().get("GSE112618").load() ``` -------------------------------- ### Plot Predicted vs. Chronological Age Source: https://bio-learn.github.io/auto_examples/00_omics_biomarkers/plot_transcriptomic_clock.html Calculates the Pearson correlation coefficient and generates a scatter plot comparing predicted ages with chronological ages using seaborn and matplotlib. Requires 'seaborn', 'matplotlib', and 'scipy' to be installed. ```python import matplotlib.pyplot as plt import seaborn as sns from scipy.stats import pearsonr predicted_values = predicted['Predicted'] true_values = data.metadata['age'] correlation, _ = pearsonr(true_values, predicted_values) print(f"Pearson Correlation Coefficient: {correlation}") sns.set_theme(style="whitegrid") sns.regplot(x=true_values, y=predicted_values, scatter_kws={'alpha':0.5}) plt.title('Transcriptomic Prediction Model') plt.xlabel('Chronological Age') plt.ylabel('Transcriptomic Age') plt.show() ``` ```text Pearson Correlation Coefficient: 0.7025211774998293 ``` -------------------------------- ### Load Challenge Data with BioLearn Source: https://bio-learn.github.io/_downloads/e2c40c72c94a18149a91c1d47ee4de74/plot_challenge_data.ipynb Loads the challenge dataset using DataLibrary. Use this to access competition data. ```python from biolearn.data_library import DataLibrary challenge_data = DataLibrary().get("BoAChallengeData").load() ``` -------------------------------- ### DataLibrary Initialization Source: https://bio-learn.github.io/data.html Initialize `DataLibrary` to manage data sources. This is a core component for accessing various datasets within Biolearn. ```python from biolearn.data_library import DataLibrary data_library = DataLibrary() ``` -------------------------------- ### Process Challenge Data for Prediction Source: https://bio-learn.github.io/_downloads/9d6419c1b7da427cabe6da2ae524be9e/training_simple_model.ipynb Prepares challenge data by transposing, selecting stable CpG sites, filling missing values with 0, and then predicting ages using the trained model. ```python pruned_data = challenge_data.dnam.T[stable_cpg_names] pruned_data = pruned_data.fillna(0) challenge_results = model.predict(pruned_data) ``` -------------------------------- ### NoCache Initialization Source: https://bio-learn.github.io/data.html Initialize `NoCache` to disable caching mechanisms. This is useful when explicit control over caching is required. ```python from biolearn.cache import NoCache cache = NoCache() ``` -------------------------------- ### DataSource Initialization Source: https://bio-learn.github.io/data.html Initialize `DataSource` to represent a specific data source. This class is used in conjunction with `DataLibrary`. ```python from biolearn.data_library import DataSource my_source = DataSource(name='my_data', path='/path/to/data') ``` -------------------------------- ### Import biolearn visualization modules Source: https://bio-learn.github.io/_downloads/a78e2414f22fb790bca7559350d8cb52/plot_dnam_relationships.ipynb Import necessary classes and functions from the biolearn library to perform methylation analysis. ```python from biolearn.data_library import DataLibrary from biolearn.visualize import ( identify_stable_cpg_sites, compute_age_group_stats, compute_methylation_stats, plot_methylation_by_age_sex, plot_methylation_vs_age ) ``` -------------------------------- ### GeoData Initialization Source: https://bio-learn.github.io/clocks.html Initialize a `GeoData` object from `biolearn.data_library` to handle GEO datasets. Provide the path to the GEO data. ```python from biolearn.data_library import GeoData geo_data = GeoData(data_dir="/path/to/geo/data") ``` -------------------------------- ### Data Loading Utilities Source: https://bio-learn.github.io/modules/load.html Functions for loading datasets. ```APIDOC ## `biolearn.load`: Data Loading Utilities ### Description Provides functions to load datasets from various sources. ### Functions #### `load_nhanes(year)` ##### Description Loads data from the National Health and Nutrition Examination Survey. ##### Parameters - **year** (int) - Required - The year of the NHANES data to load. ##### Response Example ```json { "data": "NHANES dataset for the specified year" } ``` #### `load_fhs()` ##### Description Loads data from the Framingham Heart Study. ##### Parameters None ##### Response Example ```json { "data": "Framingham Heart Study dataset" } ``` ``` -------------------------------- ### Load Competition Data with GeoData Source: https://bio-learn.github.io/_downloads/097efd573efd69c248c612b7d5ada8b7/simple_competiton_submission.ipynb Loads methylation data for a competition using the GeoData class. Ensure you replace 'ADD YOUR PATH HERE' with the actual path to your downloaded data file. ```python from biolearn.data_library import GeoData #Download the data file for the warmup challenge linked here https://www.synapse.org/#!Synapse:syn52966292/wiki/625231 DOWNLOADED_DATA_FILE_PATH="ADD YOUR PATH HERE" challenge_data = GeoData.from_methylation_matrix(DOWNLOADED_DATA_FILE_PATH) challenge_data ``` -------------------------------- ### Load GEO methylation datasets Source: https://bio-learn.github.io/_downloads/a78e2414f22fb790bca7559350d8cb52/plot_dnam_relationships.ipynb Initialize the DataLibrary and load specific GEO datasets into a dictionary of GeoData objects. ```python # List dataset IDs dataset_ids = ["GSE112618", "GSE110554", "GSE41169", "GSE52588"] # Load datasets into a dictionary of GeoData objects library = DataLibrary() datasets = {id: library.get(id).load() for id in dataset_ids} ``` -------------------------------- ### LocalFolderCache.get Source: https://bio-learn.github.io/modules/generated/biolearn.cache.LocalFolderCache.html Retrieves a cached value using its key, category, and version. ```APIDOC ## LocalFolderCache.get ### Description Retrieve a cached value. ### Method get ### Parameters #### Path Parameters - **key** (str) - Required - Unique key identifying the cache entry. - **category** (str) - Required - Cache category name. - **version** (str) - Required - Version string for invalidation. ### Returns Any | None - The cached object, or None if not found or on load error. ``` -------------------------------- ### biolearn.load.load_nhanes Source: https://bio-learn.github.io/modules/generated/biolearn.imputation.impute_from_average.html Loads data from the NHANES dataset. ```APIDOC ## load_nhanes ### Description Loads data from the NHANES dataset. ### Method N/A (Function Signature) ### Endpoint N/A (Function Signature) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **data** (pd.DataFrame) - DataFrame containing the loaded NHANES data. #### Response Example N/A ``` -------------------------------- ### biolearn.model_gallery : ModelGallery Source: https://bio-learn.github.io/modules/generated/biolearn.model_gallery.ModelGallery.html Reference for the ModelGallery class. ```APIDOC ## biolearn.model_gallery.ModelGallery ### Description Provides access to a gallery of pre-trained models. ### Parameters This class does not have explicit parameters listed in the provided text. ``` -------------------------------- ### GeoData Class Initialization Source: https://bio-learn.github.io/modules/generated/biolearn.data_library.GeoData.html Initializes a GeoData instance with metadata and optional methylation data. ```APIDOC ## GeoData Class ### Description Represents genomic data with a focus on metadata and methylation data. GeoData facilitates the organization and access to metadata and methylation data. ### Parameters - **metadata** (DataFrame) - Required - Metadata associated with genomic samples. - **dnam** (DataFrame) - Optional - Methylation data associated with genomic samples. - **rna** (DataFrame) - Optional - RNA data associated with genomic samples. - **protein_alamar** (DataFrame) - Optional - Protein data associated with genomic samples. - **protein_olink** (DataFrame) - Optional - Protein data associated with genomic samples. ``` -------------------------------- ### Load GEO Datasets into DataLibrary Source: https://bio-learn.github.io/_downloads/37a16eeb64cb047f7329c72df903f23a/plot_quality_control.ipynb Creates a DataLibrary instance and loads specified GEO datasets. The datasets are stored in a dictionary mapping dataset IDs to loaded GeoData objects. ```python library = DataLibrary() dataset_ids = ["GSE112618", "GSE110554", "GSE41169", "GSE52588"] datasets = {id: library.get(id).load() for id in dataset_ids} ``` -------------------------------- ### Search for datasets using DataLibrary Source: https://bio-learn.github.io/modules/generated/biolearn.data_library.DataLibrary.html Demonstrates filtering datasets by metadata criteria and retrieving available metadata fields. ```python >>> # Find all datasets with female subjects >>> library = DataLibrary() >>> female_datasets = library.search(sex="female") ``` ```python >>> # Find datasets with elderly subjects (70+ years) >>> elderly_datasets = library.search(min_age=70) ``` ```python >>> # Find male datasets with subjects over 50 >>> male_elderly = library.search(sex="male", min_age=50) ``` ```python >>> # View available metadata fields >>> all_datasets = library.search() >>> print(all_datasets.columns.tolist()) ``` -------------------------------- ### Data Loading Utilities Source: https://bio-learn.github.io/index.html Utilities for loading data from various sources. ```APIDOC ## Data Loading Utilities ### Description Provides functions to load data from common sources like NHANES, FHS, and GEO. ### Functions #### `biolearn.load.load_nhanes` Loads data from the National Health and Nutrition Examination Survey (NHANES). ### Parameters (Specific parameters not detailed in the provided text) ### Request Example (Not available in the provided text) ### Response (Not available in the provided text) #### `biolearn.load.load_fhs` Loads data from the Framingham Heart Study (FHS). ### Parameters (Specific parameters not detailed in the provided text) ### Request Example (Not available in the provided text) ### Response (Not available in the provided text) ``` -------------------------------- ### biolearn.load : Data Loading Utilities Source: https://bio-learn.github.io/modules/generated/biolearn.model_gallery.ModelGallery.html Reference for data loading utility functions. ```APIDOC ## biolearn.load.load_nhanes ### Description Loads data from the NHANES dataset. ### Parameters This function does not have explicit parameters listed in the provided text. ## biolearn.load.load_fhs ### Description Loads data from the FHS dataset. ### Parameters This function does not have explicit parameters listed in the provided text. ``` -------------------------------- ### Load Model and Predict InflammAge Source: https://bio-learn.github.io/auto_examples/hurdle_api_example.html Loads the Hurdle InflammAge model and makes predictions on sample data. Requires user consent for data transmission. Handles potential API errors. ```python model = gallery.get("HurdleInflammAge") print("\nMaking predictions...") print("Note: You will be prompted to consent to sending data to Hurdle's servers.") try: predictions = model.predict(sample_data) print("\nInflammAge Results:") print("-" * 40) for sample, age in predictions.items(): print(f"{sample}: {age:.1f} years") # If metadata is available, show age acceleration if hasattr(data, "metadata") and "age" in data.metadata.columns: print("\nAge Acceleration (InflammAge - Chronological Age):") print("-" * 40) for sample in predictions.index: if sample in data.metadata.index: inflamm_age = predictions[sample] chrono_age = data.metadata.loc[sample, "age"] delta = inflamm_age - chrono_age print(f"{sample}: {delta:+.1f} years") except ValueError as e: print(f"Error: {e}") except Exception as e: print(f"API Error: {e}") print("\nTroubleshooting:") print("- Verify your API key is correct") print("- Check your internet connection") print("- Ensure you have access to https://api.hurdle.bio") ``` -------------------------------- ### biolearn.load: Data Loading Utilities Source: https://bio-learn.github.io/modules/model_gallery.html Utilities for loading various biological datasets. ```APIDOC ## `biolearn.load`: Data Loading Utilities ### Description Utilities for loading various biological datasets. ### Functions - **load_nhanes**: Loads data from the NHANES dataset. - **load_fhs**: Loads data from the Framingham Heart Study (FHS) dataset. ``` -------------------------------- ### biolearn.load Source: https://bio-learn.github.io/authors.html Utilities for loading specific biological datasets. ```APIDOC ## biolearn.load ### Description Functions to load standardized datasets into the environment. ### Functions - **load_nhanes**: Load NHANES dataset. - **load_fhs**: Load FHS dataset. ``` -------------------------------- ### Model Gallery Source: https://bio-learn.github.io/index.html Access to a gallery of pre-implemented aging models. ```APIDOC ## Model Gallery ### Description Provides access to a gallery of pre-implemented aging models. ### Class #### `biolearn.model_gallery.ModelGallery` Represents the model gallery. ### Methods (Specific methods not detailed in the provided text) ### Request Example (Not available in the provided text) ### Response (Not available in the provided text) ``` -------------------------------- ### biolearn.load Source: https://bio-learn.github.io/modules/generated/biolearn.imputation.hybrid_impute.html Contains utilities for loading data, specifically supporting NHANES and FHS datasets. ```APIDOC ## biolearn.load: Data Loading Utilities ### Description This module provides utility functions for loading specific datasets. ### Functions - `load_nhanes` - `load_fhs` ``` -------------------------------- ### Load training data Source: https://bio-learn.github.io/_downloads/9d6419c1b7da427cabe6da2ae524be9e/training_simple_model.ipynb Retrieves and loads a specific dataset from the DataLibrary. ```python from biolearn.data_library import DataLibrary data = DataLibrary().get("GSE40279").load() data.metadata ``` -------------------------------- ### Load NHANES Data Source: https://bio-learn.github.io/clocks.html Use `biolearn.load.load_nhanes` to load data from the National Health and Nutrition Examination Survey. Ensure the NHANES data is downloaded and accessible. ```python from biolearn.load import load_nhanes data = load_nhanes(data_dir="/path/to/nhanes/data") ``` -------------------------------- ### DataLibrary Load Sources Source: https://bio-learn.github.io/modules/generated/biolearn.data_library.DataLibrary.html Loads data sources from a given library file, appending them to the current set of data sources. ```APIDOC ## DataLibrary.load_sources ### Description Loads data sources from a given library file appending them to the current set of data sources. ### Method load_sources ### Parameters #### Path Parameters - **library_file** (str) - Required - The file path of the library file to load data sources from. ``` -------------------------------- ### ModelGallery API Source: https://bio-learn.github.io/modules/generated/biolearn.cache.LocalFolderCache.html Reference for the ModelGallery class. ```APIDOC ## ModelGallery API ### Description Manages a gallery of pre-trained models. ### Classes - **biolearn.model_gallery.ModelGallery**: Class for interacting with the model gallery. ``` -------------------------------- ### Visualize Age Relationship Source: https://bio-learn.github.io/_downloads/6ba1afcbb57f61d1d68110657ea7d4a7/plot_nhanes.ipynb Creates a scatter plot to compare chronological age against calculated phenotypic age. ```python import seaborn as sn sn.scatterplot(data=df,x="age", y="phenotypic_age",s=2); ``` -------------------------------- ### Data Loading Utilities API Source: https://bio-learn.github.io/modules/generated/biolearn.cache.LocalFolderCache.html Utilities for loading specific datasets. ```APIDOC ## Data Loading Utilities API ### Description Provides utility functions for loading specific datasets. ### Functions - **biolearn.load.load_nhanes**: Loads data from the NHANES dataset. - **biolearn.load.load_fhs**: Loads data from the FHS dataset. ``` -------------------------------- ### Cache Management Source: https://bio-learn.github.io/index.html Utilities for managing data caching. ```APIDOC ## Cache Management ### Description Utilities for managing data caching. ### Classes #### `biolearn.cache.NoCache` Represents no caching. ### Methods (Specific methods not detailed in the provided text) ### Request Example (Not available in the provided text) ### Response (Not available in the provided text) #### `biolearn.cache.LocalFolderCache` Represents caching to a local folder. ### Methods (Specific methods not detailed in the provided text) ### Request Example (Not available in the provided text) ### Response (Not available in the provided text) ``` -------------------------------- ### LocalFolderCache.store Source: https://bio-learn.github.io/modules/generated/biolearn.cache.LocalFolderCache.html Stores a value in the cache, associated with a key, category, and version. Objects exceeding the cache size limit are not stored. Stale files in the same category but different versions are removed before storing. ```APIDOC ## LocalFolderCache.store ### Description Store a value in the cache under the given key/category/version. ### Method store ### Parameters #### Path Parameters - **key** (str) - Required - Unique key identifying the cache entry. - **value** (Any) - Required - Object to store. - **category** (str) - Required - Cache category name. - **version** (str) - Required - Version string for invalidation. ### Notes If the serialized object exceeds the cache size limit, it will not be stored. Before storing, stale files in the same category but different version are removed. ``` -------------------------------- ### Predict Age using the Lin Model Source: https://bio-learn.github.io/_downloads/097efd573efd69c248c612b7d5ada8b7/simple_competiton_submission.ipynb Utilizes the 'Lin' model from ModelGallery to predict age based on the loaded challenge data. This model was selected for its performance. ```python from biolearn.model_gallery import ModelGallery #Lin scored the best so lets use that results = ModelGallery().get("Lin").predict(challenge_data) results ``` -------------------------------- ### Cache Management Source: https://bio-learn.github.io/clocks.html Classes for managing data caching. ```APIDOC ## Cache Management ### Description Utilities for handling data caching to improve performance. ### Classes #### `biolearn.cache.NoCache` Disables caching. #### `biolearn.cache.LocalFolderCache` Implements caching using a local folder. ``` -------------------------------- ### Model Gallery Access Source: https://bio-learn.github.io/clocks.html Class for accessing the model gallery. ```APIDOC ## Model Gallery ### Description Provides access to a gallery of pre-trained biological models. ### Class #### `biolearn.model_gallery.ModelGallery` Interface for browsing and retrieving models from the gallery. ``` -------------------------------- ### Cache Management Source: https://bio-learn.github.io/data.html Classes for managing data caching to improve performance. ```APIDOC ## Cache Management ### Description Utilities for handling data caching. ### Classes #### `biolearn.cache.NoCache` Disables caching. #### `biolearn.cache.LocalFolderCache` Uses a local folder for caching. ``` -------------------------------- ### Load NHANES Data Source: https://bio-learn.github.io/data.html Use `load_nhanes` to load data from the National Health and Nutrition Examination Survey. Ensure the data is available in the expected format. ```python from biolearn.load import load_nhanes data = load_nhanes() ``` -------------------------------- ### Predict Age with Decorated Clock and Verify Results Source: https://bio-learn.github.io/_downloads/3e6fece343f1c608886b6406c2c75b77/plot_custom_imputation_implementation.ipynb Uses the decorated clock model to predict epigenetic age and verifies that the results are identical to performing direct imputation followed by prediction. ```python # Predict epigenetic age using the decorated clock (with imputation) decorated_clock_predictions = decorated_clock.predict(target_dataset) # Verify that the results are the same as the direct imputation approach same_results = all(decorated_clock_predictions == imputed_age_predictions) print(same_results) ``` -------------------------------- ### Model Gallery Access Source: https://bio-learn.github.io/data.html Class for accessing a gallery of pre-trained biological models. ```APIDOC ## Model Gallery ### Description Provides access to a collection of biological models. ### Class #### `biolearn.model_gallery.ModelGallery` Represents a gallery of models. ``` -------------------------------- ### Visualize correlation matrix across aging models Source: https://bio-learn.github.io/_downloads/108af8868614eea84b27d2927b9893eb/plot_clock_model_relationships.ipynb Generates a correlation matrix heatmap for a specified set of aging models using a loaded GEO dataset. ```python # Load an appropriate GEO dataset for the models data = DataLibrary().get("GSE120307").load() # Create a list of ModelGallery objects to be analyzed. modelnames = ["Horvathv1", "Hannum", "PhenoAge", "DunedinPACE", "Lin", "Zhang_10"] models = [ModelGallery().get(names) for names in modelnames] plot_clock_correlation_matrix( models=models, data=data, ) ``` -------------------------------- ### Cache API Source: https://bio-learn.github.io/modules/generated/biolearn.cache.LocalFolderCache.html Reference for cache management utilities. ```APIDOC ## Cache API ### Description Utilities for managing data caching to improve performance. ### Classes - **biolearn.cache.NoCache**: A cache implementation that does not store any data. - **biolearn.cache.LocalFolderCache**: A cache implementation that stores data in a local folder. ``` -------------------------------- ### GeoData Initialization Source: https://bio-learn.github.io/data.html Initialize `GeoData` to handle data from GEO (Gene Expression Omnibus). This class is specifically designed for GEO datasets. ```python from biolearn.data_library import GeoData geo_data = GeoData(accession='GSE12345') ``` -------------------------------- ### Load local data file Source: https://bio-learn.github.io/auto_examples/00_omics_biomarkers/plot_local_data_load.html Loads methylation data from a local directory using the GeoData class. Ensure files follow the [name]_metadata.csv and [name]_methylation_part0.csv naming convention. ```python from biolearn.data_library import GeoData from biolearn.util import get_test_data_file #Files formatted as described in the standard https://bio-learn.github.io/methylation-standard.html will load correctly. #Load will search for files names [name]_metadata.csv and [name]_methylation_part0.csv file_path = get_test_data_file("") data = GeoData.load_csv(file_path, "example") data.dnam ``` -------------------------------- ### Predict Biological Age with Hurdle InflammAge Source: https://bio-learn.github.io/_downloads/08e83fe39adcdfae93db7cbbc90ed77d/hurdle_api_example.ipynb Requires the HURDLE_API_KEY environment variable to be set. The model will prompt for user consent before transmitting data to Hurdle's servers. ```python import os import pandas as pd from biolearn.model_gallery import ModelGallery from biolearn.data_library import DataLibrary print("Loading sample data...") data = DataLibrary().get("BoAChallengeData").load() # Use first 5 samples for quick testing sample_data = data.dnam.iloc[:, :5] print(f"Using {sample_data.shape[1]} samples with {sample_data.shape[0]} CpG sites") gallery = ModelGallery() # Check if API key is set if not os.environ.get("HURDLE_API_KEY"): print("\nNo HURDLE_API_KEY environment variable found.") api_key = input("Enter your Hurdle API key: ").strip() if api_key: os.environ["HURDLE_API_KEY"] = api_key else: print("No API key provided. Exiting.") exit(1) # Load the model model = gallery.get("HurdleInflammAge") print("\nMaking predictions...") print("Note: You will be prompted to consent to sending data to Hurdle's servers.") try: predictions = model.predict(sample_data) print("\nInflammAge Results:") print("-" * 40) for sample, age in predictions.items(): print(f"{sample}: {age:.1f} years") # If metadata is available, show age acceleration if hasattr(data, "metadata") and "age" in data.metadata.columns: print("\nAge Acceleration (InflammAge - Chronological Age):") print("-" * 40) for sample in predictions.index: if sample in data.metadata.index: inflamm_age = predictions[sample] chrono_age = data.metadata.loc[sample, "age"] delta = inflamm_age - chrono_age print(f"{sample}: {delta:+.1f} years") except ValueError as e: print(f"Error: {e}") except Exception as e: print(f"API Error: {e}") print("\nTroubleshooting:") print("- Verify your API key is correct") print("- Check your internet connection") print("- Ensure you have access to https://api.hurdle.bio") ``` -------------------------------- ### Create Submission DataFrame Source: https://bio-learn.github.io/_downloads/9d6419c1b7da427cabe6da2ae524be9e/training_simple_model.ipynb Generates a Pandas DataFrame containing the predicted ages for the challenge data, indexed by 'sampleId', suitable for submission. Requires pandas. ```python import pandas as pd predicted_age_df = pd.DataFrame({ 'predictedAge': challenge_results }, index=challenge_data.dnam.columns) predicted_age_df.index.name = 'sampleId' predicted_age_df ``` -------------------------------- ### Predict and verify decorated clock results Source: https://bio-learn.github.io/auto_examples/00_omics_biomarkers/plot_custom_imputation_implementation.html Execute predictions using the decorated clock and compare them against direct imputation results. ```python # Predict epigenetic age using the decorated clock (with imputation) decorated_clock_predictions = decorated_clock.predict(target_dataset) # Verify that the results are the same as the direct imputation approach same_results = all(decorated_clock_predictions == imputed_age_predictions) print(same_results) ``` ```text True ``` -------------------------------- ### GeoData Methods Source: https://bio-learn.github.io/modules/generated/biolearn.data_library.GeoData.html Documentation for the methods available in the GeoData class. ```APIDOC ## GeoData Methods ### copy() - **Description**: Creates a deep copy of the GeoData instance. - **Returns**: A new instance of GeoData with copies of the metadata and dnam DataFrames. - **Return type**: GeoData ``` ```APIDOC ### quality_report(sites=None) - **Description**: Generates a quality control report for the genomic data, optionally filtered by specified methylation sites, and includes a detailed section reporting the missing percentage for each methylation site. - **Parameters**: - **sites** (list, optional) - A list of methylation site identifiers to include in the report. If None, all sites are included. - **Returns**: An object containing both detailed methylation data, a summary, and a detailed section for missing percentages per site. - **Return type**: QualityReport ``` ```APIDOC ### from_methylation_matrix(matrix) - **Description**: Creates a GeoData instance from a methylation matrix which can be either a DataFrame directly or a path to a CSV file. - **Parameters**: - **matrix** (Union[str, DataFrame]) - Methylation matrix as a DataFrame or the path to the CSV file containing the matrix. - **Returns**: An instance of GeoData with the methylation data loaded and metadata initialized. - **Return type**: GeoData ``` ```APIDOC ### save_csv(folder_path, name) - **Description**: Saves the GeoData instance to CSV files according to the DNA Methylation Array Data Standard V-2410. - **Parameters**: - **folder_path** (str) - The directory where the files will be saved. - **name** (str) - The base name for the saved files. - **Returns**: None ``` ```APIDOC ### load_csv(folder_path, name, series_part='all', validate=True) - **Description**: Loads a GeoData instance from CSV files according to the DNA Methylation Array Data Standard V-2410. - **Parameters**: - **folder_path** (str) - The directory where the files are located. - **name** (str) - The base name for the files. - **series_part** (str or int) - “all” to load all methylation parts and concatenate; otherwise, an integer specifying the part number to load. - **validate** (bool) - Whether to validate metadata-omics consistency. Default is True. - **Returns**: A GeoData instance with metadata, methylation data, RNA, and protein data loaded. - **Return type**: GeoData ``` -------------------------------- ### DataSource Class Reference Source: https://bio-learn.github.io/modules/generated/biolearn.data_library.DataSource.html Overview of the DataSource class methods and attributes for data management. ```APIDOC ## DataSource Class ### Description The `DataSource` class is the primary interface for interacting with epigenetic data libraries. It handles the loading of datasets and manages cache categories and versions. ### Attributes - **REQUIRED_FIELDS** (list) - List of fields that must be present in the data source. - **CACHE_CATEGORY** (string) - The category identifier used for caching data. - **CACHE_VERSION** (string) - The version identifier for the cached data. ### Methods - **__init__** - Initializes a new instance of the DataSource. - **load** - Loads the data from the source into the application environment. ``` -------------------------------- ### ModelGallery.search Source: https://bio-learn.github.io/modules/generated/biolearn.model_gallery.ModelGallery.html Search models based on species and tissue criteria. ```APIDOC ## ModelGallery.search ### Description Searches for models based on species and tissue criteria. ### Method GET ### Endpoint /models/search ### Parameters #### Query Parameters - **species** (str) - Optional - The species to filter models by. - **tissue** (str) - Optional - The tissue to filter models by. ### Request Example ```json { "species": "human", "tissue": "liver" } ``` ### Response #### Success Response (200) - **models** (dict) - A dictionary of models that match the specified criteria. ### Response Example ```json { "model_name_1": { ... }, "model_name_2": { ... } } ``` ``` -------------------------------- ### Visualize model predictions against chronological age Source: https://bio-learn.github.io/_downloads/108af8868614eea84b27d2927b9893eb/plot_clock_model_relationships.ipynb Plots predicted ages from selected models against actual chronological age. ```python # Use appropriate clocks/models modelnames = ["Horvathv1", "Hannum", "PhenoAge", "Lin"] age_prediction_models = [ModelGallery().get(name) for name in modelnames] plot_age_prediction( models=age_prediction_models, data=data, ) ``` -------------------------------- ### biolearn.cache : Cache Source: https://bio-learn.github.io/modules/generated/biolearn.model_gallery.ModelGallery.html Reference for caching mechanisms. ```APIDOC ## biolearn.cache.NoCache ### Description Represents a cache that does not store any data. ### Parameters This class does not have explicit parameters listed in the provided text. ## biolearn.cache.LocalFolderCache ### Description Implements a cache that stores data in a local folder. ### Parameters This class does not have explicit parameters listed in the provided text. ``` -------------------------------- ### biolearn.cache.LocalFolderCache Source: https://bio-learn.github.io/modules/cache.html An LRU-style cache that stores pickled objects in a specified local directory. ```APIDOC ## Class: biolearn.cache.LocalFolderCache ### Description LRU-style cache that stores pickled objects in a local directory. ### Constructor `LocalFolderCache(path, max_size_gb)` ### Parameters - **path** (string) - Required - The local directory path where cached objects are stored. - **max_size_gb** (float) - Required - The maximum size of the cache in gigabytes. ``` -------------------------------- ### Visualize methylation by age and sex Source: https://bio-learn.github.io/_downloads/a78e2414f22fb790bca7559350d8cb52/plot_dnam_relationships.ipynb Compute age group statistics and generate a violin plot for a specific CpG site. ```python # Initialize an appropriate CpG site cpg_site = "cg00000029" # Compute statistics by age group for the specified CpG site stats_df, combined_data1 = compute_age_group_stats(datasets, cpg_site, age_bins=5) # Plot DNA methylation levels by age group and sex across datasets in a violin plot # Note: In the datasets, '1' represents Female and '2' represents Male. plot_methylation_by_age_sex(combined_data1, cpg_site) ``` -------------------------------- ### Visualize methylation vs age with regression Source: https://bio-learn.github.io/_downloads/a78e2414f22fb790bca7559350d8cb52/plot_dnam_relationships.ipynb Compute regression statistics and plot DNA methylation against age using linear and polynomial regression lines. ```python # Compute regression statistics to plot methylation vs. age combined_data2, stats_df = compute_methylation_stats(datasets, cpg_site) # Plot DNA methylation against age across datasets with linear and polynomial regression lines plot_methylation_vs_age(combined_data2, stats_df, cpg_site) ``` -------------------------------- ### View Combined Metadata Source: https://bio-learn.github.io/_downloads/e2c40c72c94a18149a91c1d47ee4de74/plot_challenge_data.ipynb Displays the combined metadata associated with the challenge data. This includes all metadata, even if data points do not overlap between different data types. ```python challenge_data.metadata ```