Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/shorvath/MammalianMethylationConsortium
17 May 2026, 06:12:37 UTC
  • Code
  • Branches (9)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/ahaghani-patch-1
    • refs/heads/main
    • refs/tags/3.1.1
    • refs/tags/v1.0.0
    • refs/tags/v2.0.0
    • refs/tags/v2.1.0
    • refs/tags/v3.0.0
    • refs/tags/v3.1.0
    • refs/tags/v4.0.0
    No releases to show
  • d6a46b2
  • /
  • EnsembleAge
  • /
  • example_usage.R
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:a35ab48d1fb565e8fdebd9890225f86f96f6abfd
origin badgedirectory badge
swh:1:dir:43679180423705e9ce82cc3814e4f0af656a72fe
origin badgerevision badge
swh:1:rev:b70331d458b457af9c277b92710e7b79d6d1f889
origin badgesnapshot badge
swh:1:snp:d600778902cd3425991ed38b173a218accf69df9

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: b70331d458b457af9c277b92710e7b79d6d1f889 authored by Amin Haghani on 21 January 2026, 23:46:19 UTC
Add files via upload
Tip revision: b70331d
example_usage.R
#!/usr/bin/env Rscript
#' EnsembleAge: Simple Usage Example
#' 
#' This script demonstrates how to use EnsembleAge with simulated data.
#' Run this script to test the package installation and basic functionality.

# Load required libraries
library(EnsembleAge)
library(dplyr)
library(tidyr)
library(tibble)
library(data.table)

# Source the functions directly (needed for development)
source('R/ultimate_predict.R')
source('R/easy_workflow.R')
source('R/data_preprocessing.R')
source('R/predict_age.R') 
source('R/user_prediction_functions.R')
source('R/core_functions.R')
source('R/efficient_data_loading.R')
source('R/platform_utils.R')
source('R/data_orientation.R')

cat("🧬 EnsembleAge Simple Example\n")
cat("============================\n\n")

# Step 1: Create simulated methylation data
cat("šŸ“Š Creating simulated methylation data...\n")
set.seed(123)

# Simulate mammal40k-style data with realistic CpG sites
n_probes <- 1000   # Using subset for quick example
n_samples <- 8

# Create methylation data: probes as rows, samples as columns
methylation_data <- data.frame(
  CGid = paste0("cg", sprintf("%08d", sample(10000000:99999999, n_probes))),
  matrix(
    # Realistic beta values with some biological variation
    pmax(0, pmin(1, rnorm(n_probes * n_samples, mean = 0.5, sd = 0.2))), 
    nrow = n_probes
  )
)

# Add sample names
sample_names <- paste0("Sample_", sprintf("%02d", 1:n_samples))
names(methylation_data)[-1] <- sample_names

cat("āœ“ Created methylation data:", dim(methylation_data), "(probes Ɨ samples)\n")

# Step 2: Create sample sheet with realistic ages
cat("šŸ“‹ Creating sample sheet...\n")
sample_sheet <- data.frame(
  Basename = sample_names,
  Age = c(0.5, 1.2, 2.1, 0.8, 1.5, 2.8, 1.1, 0.9),  # Mouse ages in years
  Female = c(1, 0, 1, 1, 0, 1, 0, 1),                # Sex: 1=female, 0=male
  Tissue = rep("Blood", n_samples),                    # All blood samples
  SpeciesLatinName = rep("Mus musculus", n_samples)   # Mouse species
)

cat("āœ“ Created sample sheet with", nrow(sample_sheet), "samples\n")
print(sample_sheet)

cat("\nšŸš€ Running EnsembleAge predictions...\n")
cat("======================================\n")

# Step 3: Run predictions using the ultimate one-liner
results <- predictEnsemble(methylation_data, sample_sheet, verbose = TRUE)

cat("\nšŸ“ˆ Results Summary:\n")
cat("===================\n")
cat("Total predictions:", nrow(results), "\n")
cat("Unique samples:", length(unique(results$Basename)), "\n")
cat("Unique clocks:", length(unique(results$epiClock)), "\n")
cat("Clock families:", paste(unique(results$clockFamily), collapse = ", "), "\n")

cat("\nšŸ“Š Sample Results (first 10 rows):\n")
print(head(results[, c("Basename", "Age", "epiClock", "epiAge", "AgeAccelation")], 10))

cat("\nšŸ“ˆ Age Predictions by Sample:\n")
sample_summary <- results %>%
  group_by(Basename, Age) %>%
  summarise(
    n_clocks = n(),
    mean_epiAge = round(mean(epiAge, na.rm = TRUE), 2),
    mean_acceleration = round(mean(AgeAccelation, na.rm = TRUE), 2),
    .groups = "drop"
  )
print(sample_summary)

cat("\nšŸ’¾ Saving results...\n")
write.csv(results, "ensembleage_example_results.csv", row.names = FALSE)
cat("āœ“ Results saved to: ensembleage_example_results.csv\n")

cat("\nšŸŽ‰ Example completed successfully!\n")
cat("===================================\n\n")

cat("šŸ“š What happened:\n")
cat("1. āœ… Created simulated mammal methylation data (1000 probes Ɨ 8 samples)\n")
cat("2. āœ… Created sample sheet with ages, sex, tissue, and species info\n")
cat("3. āœ… EnsembleAge automatically detected the platform\n")
cat("4. āœ… Selected appropriate clock methods based on data coverage\n")
cat("5. āœ… Generated age predictions using multiple clocks\n")
cat("6. āœ… Saved results in long format (one row per sample-clock combination)\n\n")

cat("šŸ”„ Try different options:\n")
cat("- Long format (default): predictEnsemble(methylation_data, sample_sheet)\n")
cat("- Wide format: predictEnsemble(methylation_data, sample_sheet, output_format = 'wide')\n")
cat("- Both formats: predictEnsemble(methylation_data, sample_sheet, output_format = 'both')\n")
cat("- Custom directory: predictEnsemble(data, samples, output_dir = 'results/')\n")
cat("- Custom prefix: predictEnsemble(data, samples, output_prefix = 'MyStudy')\n")
cat("- Custom filename: predictEnsemble(data, samples, output_filename = 'results.csv')\n")
cat("- No saving: predictEnsemble(data, samples, save_results = FALSE)\n\n")

cat("šŸš€ Ready to use EnsembleAge with your own data!\n")

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API