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
  • /
  • R
  • /
  • core_functions.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:4640704b2f2483dd0e61d6895ba4702cfdc89e0c
origin badgedirectory badge
swh:1:dir:b389ec81a8fbdafe5378daf4a8c28a017d62b1ee
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
core_functions.R
#' Age transformation function
#'
#' This function performs age transformation used in epigenetic clock calculations.
#' 
#' @param x Numeric vector of ages to transform
#' @param offset Numeric offset value (default: 0.06)
#' @param adult.age Numeric adult age threshold (default: 1.2)
#' @return Numeric vector of transformed ages
#' @export
#' @examples
#' # Transform ages for epigenetic clock calculations
#' ages <- c(0.5, 1.0, 2.0, 5.0)
#' transformed <- trafo(ages)
#' print(transformed)
trafo <- function(x, offset = 0.06, adult.age = 1.2) {
  y <- ifelse(x <= adult.age, 
              log(x + offset),
              x / (adult.age + offset) + log(adult.age + offset) - adult.age / (adult.age + offset))
  return(y)
}

#' Inverse age transformation function
#'
#' This function performs the inverse of the age transformation used in epigenetic clock calculations.
#' 
#' @param x Numeric vector of transformed ages to reverse
#' @param offset Numeric offset value (default: 0.06)
#' @param adult.age Numeric adult age threshold (default: 1.2)
#' @return Numeric vector of original ages
#' @export
#' @examples
#' # Transform and then reverse transform ages
#' ages <- c(0.5, 1.0, 2.0, 5.0)
#' transformed <- trafo(ages)
#' original <- anti.trafo(transformed)
#' print(original)
anti.trafo <- function(x, offset = 0.06, adult.age = 1.2) {
  ifelse(x <= log(adult.age + offset), 
         exp(x) - offset, 
         (adult.age + offset) * x - log(adult.age + offset) * (adult.age + offset) + adult.age)
}

#' Universal clock inverse transformation function
#'
#' Inverse transformation function used in universal clocks (F2 type).
#' 
#' @param y Numeric vector of predicted values to transform
#' @param y.maxAge Numeric maximum age for the species
#' @param y.gestation Numeric gestation time in years
#' @param const Numeric constant (default: 1)
#' @return Numeric vector of transformed ages
#' @export
F2_antitrans <- function(y, y.maxAge, y.gestation, const = 1) {
  x0 <- const * exp(-exp(-1 * y))
  x1 <- x0 * (y.maxAge + y.gestation)
  x <- x1 - y.gestation
  return(x)
}

#' Log-linear transformation function for Clock 3
#'
#' This function performs the log-linear transformation used in Universal Clock 3.
#' 
#' @param age1 Numeric vector of ages to transform
#' @param m1 Numeric parameter m1 for transformation
#' @param m2 Numeric parameter m2 for transformation (default: same as m1)
#' @param c1 Numeric parameter c1 for transformation (default: 1)
#' @return Numeric vector of transformed values
#' @export
F1_logli <- function(age1, m1, m2 = m1, c1 = 1) {
  ifelse(age1 >= m1, 
         (age1 - m1) / m2, 
         c1 * log((age1 - m1) / m2 / c1 + 1))
}

#' Reverse transformation function for Clock 3
#'
#' This function performs the reverse transformation for Universal Clock 3 predictions.
#' 
#' @param y.pred Numeric vector of predicted values to reverse transform
#' @param m1 Numeric parameter m1 for transformation
#' @param m2 Numeric parameter m2 for transformation (default: same as m1)
#' @param c1 Numeric parameter c1 for transformation (default: 1)
#' @return Numeric vector of original scale values
#' @export
F2_revtrsf <- function(y.pred, m1, m2 = m1, c1 = 1) {
  ifelse(y.pred < 0, 
         (exp(y.pred / c1) - 1) * m2 * c1 + m1, 
         y.pred * m2 + m1)
}

#' Calculate parameters for log-linear transformation
#'
#' This function calculates the necessary parameters for the log-linear transformation
#' used in Universal Clock 3.
#' 
#' @param dat1 Data frame containing species information with columns: maxAgeCaesar, 
#'   GestationTimeInYears, averagedMaturity.yrs, Age
#' @param b1 Numeric parameter b1 (default: 1)
#' @param max_tage Numeric maximum transformed age (default: 4)
#' @param c1 Numeric parameter c1 (default: 5)
#' @param c2 Numeric parameter c2 (default: 0.38)
#' @param c0 Numeric parameter c0 (default: 0)
#' @return Data frame with additional columns for transformation parameters
#' @export
#' @importFrom dplyr mutate
F3_loglifn <- function(dat1, b1 = 1, max_tage = 4, c1 = 5, c2 = 0.38, c0 = 0) {
  n <- nrow(dat1)
  
  age1 <- (dat1$maxAgeCaesar + dat1$GestationTimeInYears) / 
          (dat1$averagedMaturity.yrs + dat1$GestationTimeInYears)
  
  a1 <- age1 / (1 + max_tage)
  dat1$a1_Logli <- a1 # x/m1 in manuscript
  
  a2 <- (dat1$GestationTimeInYears + c0) / (dat1$averagedMaturity.yrs)
  dat1$a_Logli <- a_Logli <- c1 * a2^c2
  # m=5*(G/ASM)^0.38 from regression analysis/formula(7)
  
  x <- dat1$Age + dat1$GestationTimeInYears
  t2 <- dat1$averagedMaturity.yrs * b1 + dat1$GestationTimeInYears
  x2 <- x / t2 #### log(x/t2)
  y <- F1_logli(x2, a_Logli, a_Logli)
  
  dat1$LogliAge <- y
  return(dat1)
}

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