Last updated: 2025-08-22

Checks: 7 0

Knit directory: DXR_continue/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20250701) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version c146c0a. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/Cormotif_data/
    Ignored:    data/DER_data/
    Ignored:    data/alignment_summary.txt
    Ignored:    data/all_peak_final_dataframe.txt
    Ignored:    data/cell_line_info_.tsv
    Ignored:    data/full_summary_QC_metrics.txt
    Ignored:    data/number_frag_peaks_summary.txt

Untracked files:
    Untracked:  code/corMotifcustom.R
    Untracked:  code/making_analysis_file_summary.R

Unstaged changes:
    Modified:   analysis/final_analysis.Rmd
    Modified:   analysis/multiQC_cut_tag.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/Cormotif_outlier_removal.Rmd) and HTML (docs/Cormotif_outlier_removal.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd c146c0a reneeisnowhere 2025-08-22 new index

library(tidyverse)
library(readr)
library(edgeR)
library(ComplexHeatmap)
library(data.table)
library(dplyr)
library(stringr)
library(ggplot2)
library(viridis)
library(DT)
library(kableExtra)
library(genomation)
library(GenomicRanges)
library(ggpubr) ## For customizing figures
library(corrplot) ## For correlation plot
library(ggpmisc)
library(gcplyr)
library(Rsubread)
library(limma)
library(ggrastr)
library(cowplot)
library(smplot2)
library(ggVennDiagram)
library(ggsignif)
library(BiocParallel)
sampleinfo <- read_delim("data/sample_info.tsv", delim = "\t")

Cormotif code

## Fit limma model using code as it is found in the original cormotif code. It has
## only been modified to add names to the matrix of t values, as well as the
## limma fits

limmafit.default <- function(exprs,groupid,compid) {
  limmafits  <- list()
  compnum    <- nrow(compid)
  genenum    <- nrow(exprs)
  limmat     <- matrix(0,genenum,compnum)
  limmas2    <- rep(0,compnum)
  limmadf    <- rep(0,compnum)
  limmav0    <- rep(0,compnum)
  limmag1num <- rep(0,compnum)
  limmag2num <- rep(0,compnum)

  rownames(limmat)  <- rownames(exprs)
  colnames(limmat)  <- rownames(compid)
  names(limmas2)    <- rownames(compid)
  names(limmadf)    <- rownames(compid)
  names(limmav0)    <- rownames(compid)
  names(limmag1num) <- rownames(compid)
  names(limmag2num) <- rownames(compid)

  for(i in 1:compnum) {
    selid1 <- which(groupid == compid[i,1])
    selid2 <- which(groupid == compid[i,2])
    eset   <- new("ExpressionSet", exprs=cbind(exprs[,selid1],exprs[,selid2]))
    g1num  <- length(selid1)
    g2num  <- length(selid2)
    designmat <- cbind(base=rep(1,(g1num+g2num)), delta=c(rep(0,g1num),rep(1,g2num)))
    fit <- lmFit(eset,designmat)
    fit <- eBayes(fit)
    limmat[,i] <- fit$t[,2]
    limmas2[i] <- fit$s2.prior
    limmadf[i] <- fit$df.prior
    limmav0[i] <- fit$var.prior[2]
    limmag1num[i] <- g1num
    limmag2num[i] <- g2num
    limmafits[[i]] <- fit

    # log odds
    # w<-sqrt(1+fit$var.prior[2]/(1/g1num+1/g2num))
    # log(0.99)+dt(fit$t[1,2],g1num+g2num-2+fit$df.prior,log=TRUE)-log(0.01)-dt(fit$t[1,2]/w, g1num+g2num-2+fit$df.prior, log=TRUE)+log(w)
  }
  names(limmafits) <- rownames(compid)
  limmacompnum<-nrow(compid)
  result<-list(t       = limmat,
               v0      = limmav0,
               df0     = limmadf,
               s20     = limmas2,
               g1num   = limmag1num,
               g2num   = limmag2num,
               compnum = limmacompnum,
               fits    = limmafits)
}

limmafit.counts <-
  function (exprs, groupid, compid, norm.factor.method = "TMM", voom.normalize.method = "none")
  {
    limmafits  <- list()
    compnum    <- nrow(compid)
    genenum    <- nrow(exprs)
    limmat     <- matrix(NA,genenum,compnum)
    limmas2    <- rep(0,compnum)
    limmadf    <- rep(0,compnum)
    limmav0    <- rep(0,compnum)
    limmag1num <- rep(0,compnum)
    limmag2num <- rep(0,compnum)

    rownames(limmat)  <- rownames(exprs)
    colnames(limmat)  <- rownames(compid)
    names(limmas2)    <- rownames(compid)
    names(limmadf)    <- rownames(compid)
    names(limmav0)    <- rownames(compid)
    names(limmag1num) <- rownames(compid)
    names(limmag2num) <- rownames(compid)

    for (i in 1:compnum) {
      message(paste("Running limma for comparision",i,"/",compnum))
      selid1 <- which(groupid == compid[i, 1])
      selid2 <- which(groupid == compid[i, 2])
      # make a new count data frame
      counts <- cbind(exprs[, selid1], exprs[, selid2])

      # remove NAs
      not.nas <- which(apply(counts, 1, function(x) !any(is.na(x))) == TRUE)

      # runn voom/limma
      d <- DGEList(counts[not.nas,])
      d <- calcNormFactors(d, method = norm.factor.method)
      g1num <- length(selid1)
      g2num <- length(selid2)
      designmat <- cbind(base = rep(1, (g1num + g2num)), delta = c(rep(0,
                                                                       g1num), rep(1, g2num)))

      y <- voom(d, designmat, normalize.method = voom.normalize.method)
      fit <- lmFit(y, designmat)
      fit <- eBayes(fit)

      limmafits[[i]] <- fit
      limmat[not.nas, i] <- fit$t[, 2]
      limmas2[i] <- fit$s2.prior
      limmadf[i] <- fit$df.prior
      limmav0[i] <- fit$var.prior[2]
      limmag1num[i] <- g1num
      limmag2num[i] <- g2num
    }
    limmacompnum <- nrow(compid)
    names(limmafits) <- rownames(compid)
    result <- list(t       = limmat,
                   v0      = limmav0,
                   df0     = limmadf,
                   s20     = limmas2,
                   g1num   = limmag1num,
                   g2num   = limmag2num,
                   compnum = limmacompnum,
                   fits    = limmafits)
  }

limmafit.list <-
  function (fitlist, cmp.idx=2)
  {
    compnum    <- length(fitlist)

    genes <- c()
    for (i in 1:compnum) genes <- unique(c(genes, rownames(fitlist[[i]])))

    genenum    <- length(genes)
    limmat     <- matrix(NA,genenum,compnum)
    limmas2    <- rep(0,compnum)
    limmadf    <- rep(0,compnum)
    limmav0    <- rep(0,compnum)
    limmag1num <- rep(0,compnum)
    limmag2num <- rep(0,compnum)

    rownames(limmat)  <- genes
    colnames(limmat)  <- names(fitlist)
    names(limmas2)    <- names(fitlist)
    names(limmadf)    <- names(fitlist)
    names(limmav0)    <- names(fitlist)
    names(limmag1num) <- names(fitlist)
    names(limmag2num) <- names(fitlist)

    for (i in 1:compnum) {
      this.t <- fitlist[[i]]$t[,cmp.idx]
      limmat[names(this.t),i] <- this.t

      limmas2[i]    <- fitlist[[i]]$s2.prior
      limmadf[i]    <- fitlist[[i]]$df.prior
      limmav0[i]    <- fitlist[[i]]$var.prior[cmp.idx]
      limmag1num[i] <- sum(fitlist[[i]]$design[,cmp.idx]==0)
      limmag2num[i] <- sum(fitlist[[i]]$design[,cmp.idx]==1)
    }

    limmacompnum <- compnum
    result <- list(t       = limmat,
                   v0      = limmav0,
                   df0     = limmadf,
                   s20     = limmas2,
                   g1num   = limmag1num,
                   g2num   = limmag2num,
                   compnum = limmacompnum,
                   fits    = limmafits)

  }

## Rank genes based on statistics
generank<-function(x) {
  xcol<-ncol(x)
  xrow<-nrow(x)
  result<-matrix(0,xrow,xcol)
  z<-(1:1:xrow)
  for(i in 1:xcol) {
    y<-sort(x[,i],decreasing=TRUE,na.last=TRUE)
    result[,i]<-match(x[,i],y)
    result[,i]<-order(result[,i])
  }
  result
}

## Log-likelihood for moderated t under H0
modt.f0.loglike<-function(x,df) {
  a<-dt(x, df, log=TRUE)
  result<-as.vector(a)
  flag<-which(is.na(result)==TRUE)
  result[flag]<-0
  result
}

## Log-likelihood for moderated t under H1
## param=c(df,g1num,g2num,v0)
modt.f1.loglike<-function(x,param) {
  df<-param[1]
  g1num<-param[2]
  g2num<-param[3]
  v0<-param[4]
  w<-sqrt(1+v0/(1/g1num+1/g2num))
  dt(x/w, df, log=TRUE)-log(w)
  a<-dt(x/w, df, log=TRUE)-log(w)
  result<-as.vector(a)
  flag<-which(is.na(result)==TRUE)
  result[flag]<-0
  result
}

## Correlation Motif Fit
cmfit.X<-function(x, type, K=1, tol=1e-3, max.iter=100) {
  ## initialize
  xrow <- nrow(x)
  xcol <- ncol(x)
  loglike0 <- list()
  loglike1 <- list()
  p <- rep(1, K)/K
  q <- matrix(runif(K * xcol), K, xcol)
  q[1, ] <- rep(0.01, xcol)
  for (i in 1:xcol) {
    f0 <- type[[i]][[1]]
    f0param <- type[[i]][[2]]
    f1 <- type[[i]][[3]]
    f1param <- type[[i]][[4]]
    loglike0[[i]] <- f0(x[, i], f0param)
    loglike1[[i]] <- f1(x[, i], f1param)
  }
  condlike <- list()
  for (i in 1:xcol) {
    condlike[[i]] <- matrix(0, xrow, K)
  }
  loglike.old <- -1e+10
  for (i.iter in 1:max.iter) {
    if ((i.iter%%50) == 0) {
      print(paste("We have run the first ", i.iter, " iterations for K=",
                  K, sep = ""))
    }
    err <- tol + 1
    clustlike <- matrix(0, xrow, K)
    #templike <- matrix(0, xrow, 2)
    templike1 <- rep(0, xrow)
    templike2 <- rep(0, xrow)
    for (j in 1:K) {
      for (i in 1:xcol) {
        templike1 <- log(q[j, i]) + loglike1[[i]]
        templike2 <- log(1 - q[j, i]) + loglike0[[i]]
        tempmax <- Rfast::Pmax(templike1, templike2)

        templike1 <- exp(templike1 - tempmax)
        templike2 <- exp(templike2 - tempmax)

        tempsum <- templike1 + templike2
        clustlike[, j] <- clustlike[, j] + tempmax +
          log(tempsum)
        condlike[[i]][, j] <- templike1/tempsum
      }
      clustlike[, j] <- clustlike[, j] + log(p[j])
    }
    #tempmax <- apply(clustlike, 1, max)
    tempmax <- Rfast::rowMaxs(clustlike, value=TRUE)
    for (j in 1:K) {
      clustlike[, j] <- exp(clustlike[, j] - tempmax)
    }
    #tempsum <- apply(clustlike, 1, sum)
    tempsum <- Rfast::rowsums(clustlike)
    for (j in 1:K) {
      clustlike[, j] <- clustlike[, j]/tempsum
    }
    #p.new <- (apply(clustlike, 2, sum) + 1)/(xrow + K)
    p.new <- (Rfast::colsums(clustlike) + 1)/(xrow + K)
    q.new <- matrix(0, K, xcol)
    for (j in 1:K) {
      clustpsum <- sum(clustlike[, j])
      for (i in 1:xcol) {
        q.new[j, i] <- (sum(clustlike[, j] * condlike[[i]][,
                                                           j]) + 1)/(clustpsum + 2)
      }
    }
    err.p <- max(abs(p.new - p)/p)
    err.q <- max(abs(q.new - q)/q)
    err <- max(err.p, err.q)
    loglike.new <- (sum(tempmax + log(tempsum)) + sum(log(p.new)) +
                      sum(log(q.new) + log(1 - q.new)))/xrow
    p <- p.new
    q <- q.new
    loglike.old <- loglike.new
    if (err < tol) {
      break
    }
  }
  clustlike <- matrix(0, xrow, K)
  for (j in 1:K) {
    for (i in 1:xcol) {
      templike1 <- log(q[j, i]) + loglike1[[i]]
      templike2 <- log(1 - q[j, i]) + loglike0[[i]]
      tempmax <- Rfast::Pmax(templike1, templike2)

      templike1 <- exp(templike1 - tempmax)
      templike2 <- exp(templike2 - tempmax)

      tempsum <- templike1 + templike2
      clustlike[, j] <- clustlike[, j] + tempmax + log(tempsum)
      condlike[[i]][, j] <- templike1/tempsum
    }
    clustlike[, j] <- clustlike[, j] + log(p[j])
  }
  #tempmax <- apply(clustlike, 1, max)
  tempmax <- Rfast::rowMaxs(clustlike, value=TRUE)
  for (j in 1:K) {
    clustlike[, j] <- exp(clustlike[, j] - tempmax)
  }
  #tempsum <- apply(clustlike, 1, sum)
  tempsum <- Rfast::rowsums(clustlike)
  for (j in 1:K) {
    clustlike[, j] <- clustlike[, j]/tempsum
  }
  p.post <- matrix(0, xrow, xcol)
  for (j in 1:K) {
    for (i in 1:xcol) {
      p.post[, i] <- p.post[, i] + clustlike[, j] * condlike[[i]][,
                                                                  j]
    }
  }
  loglike.old <- loglike.old - (sum(log(p)) + sum(log(q) +
                                                    log(1 - q)))/xrow
  loglike.old <- loglike.old * xrow
  result <- list(p.post = p.post, motif.prior = p, motif.q = q,
                 loglike = loglike.old, clustlike=clustlike, condlike=condlike)
}

## Fit using (0,0,...,0) and (1,1,...,1)
cmfitall<-function(x, type, tol=1e-3, max.iter=100) {
  ## initialize
  xrow<-nrow(x)
  xcol<-ncol(x)
  loglike0<-list()
  loglike1<-list()
  p<-0.01

  ## compute loglikelihood
  L0<-matrix(0,xrow,1)
  L1<-matrix(0,xrow,1)
  for(i in 1:xcol) {
    f0<-type[[i]][[1]]
    f0param<-type[[i]][[2]]
    f1<-type[[i]][[3]]
    f1param<-type[[i]][[4]]
    loglike0[[i]]<-f0(x[,i],f0param)
    loglike1[[i]]<-f1(x[,i],f1param)
    L0<-L0+loglike0[[i]]
    L1<-L1+loglike1[[i]]
  }


  ## EM algorithm to get MLE of p and q
  loglike.old <- -1e10
  for(i.iter in 1:max.iter) {
    if((i.iter%%50) == 0) {
      print(paste("We have run the first ", i.iter, " iterations",sep=""))
    }
    err<-tol+1

    ## compute posterior cluster membership
    clustlike<-matrix(0,xrow,2)
    clustlike[,1]<-log(1-p)+L0
    clustlike[,2]<-log(p)+L1

    tempmax<-apply(clustlike,1,max)
    for(j in 1:2) {
      clustlike[,j]<-exp(clustlike[,j]-tempmax)
    }
    tempsum<-apply(clustlike,1,sum)

    ## update motif occurrence rate
    for(j in 1:2) {
      clustlike[,j]<-clustlike[,j]/tempsum
    }

    p.new<-(sum(clustlike[,2])+1)/(xrow+2)

    ## evaluate convergence
    err<-abs(p.new-p)/p

    ## evaluate whether the log.likelihood increases
    loglike.new<-(sum(tempmax+log(tempsum))+log(p.new)+log(1-p.new))/xrow

    loglike.old<-loglike.new
    p<-p.new

    if(err<tol) {
      break;
    }
  }

  ## compute posterior p
  clustlike<-matrix(0,xrow,2)
  clustlike[,1]<-log(1-p)+L0
  clustlike[,2]<-log(p)+L1

  tempmax<-apply(clustlike,1,max)
  for(j in 1:2) {
    clustlike[,j]<-exp(clustlike[,j]-tempmax)
  }
  tempsum<-apply(clustlike,1,sum)

  for(j in 1:2) {
    clustlike[,j]<-clustlike[,j]/tempsum
  }

  p.post<-matrix(0,xrow,xcol)
  for(i in 1:xcol) {
    p.post[,i]<-clustlike[,2]
  }

  ## return

  #calculate back loglikelihood
  loglike.old<-loglike.old-(log(p)+log(1-p))/xrow
  loglike.old<-loglike.old*xrow
  result<-list(p.post=p.post, motif.prior=p, loglike=loglike.old)
}

## Fit each dataset separately
cmfitsep<-function(x, type, tol=1e-3, max.iter=100) {
  ## initialize
  xrow<-nrow(x)
  xcol<-ncol(x)
  loglike0<-list()
  loglike1<-list()
  p<-0.01*rep(1,xcol)
  loglike.final<-rep(0,xcol)

  ## compute loglikelihood
  for(i in 1:xcol) {
    f0<-type[[i]][[1]]
    f0param<-type[[i]][[2]]
    f1<-type[[i]][[3]]
    f1param<-type[[i]][[4]]
    loglike0[[i]]<-f0(x[,i],f0param)
    loglike1[[i]]<-f1(x[,i],f1param)
  }

  p.post<-matrix(0,xrow,xcol)

  ## EM algorithm to get MLE of p
  for(coli in 1:xcol) {
    loglike.old <- -1e10
    for(i.iter in 1:max.iter) {
      if((i.iter%%50) == 0) {
        print(paste("We have run the first ", i.iter, " iterations",sep=""))
      }
      err<-tol+1

      ## compute posterior cluster membership
      clustlike<-matrix(0,xrow,2)
      clustlike[,1]<-log(1-p[coli])+loglike0[[coli]]
      clustlike[,2]<-log(p[coli])+loglike1[[coli]]

      tempmax<-apply(clustlike,1,max)
      for(j in 1:2) {
        clustlike[,j]<-exp(clustlike[,j]-tempmax)
      }
      tempsum<-apply(clustlike,1,sum)

      ## evaluate whether the log.likelihood increases
      loglike.new<-sum(tempmax+log(tempsum))/xrow

      ## update motif occurrence rate
      for(j in 1:2) {
        clustlike[,j]<-clustlike[,j]/tempsum
      }

      p.new<-(sum(clustlike[,2]))/(xrow)

      ## evaluate convergence
      err<-abs(p.new-p[coli])/p[coli]
      loglike.old<-loglike.new
      p[coli]<-p.new

      if(err<tol) {
        break;
      }
    }

    ## compute posterior p
    clustlike<-matrix(0,xrow,2)
    clustlike[,1]<-log(1-p[coli])+loglike0[[coli]]
    clustlike[,2]<-log(p[coli])+loglike1[[coli]]

    tempmax<-apply(clustlike,1,max)
    for(j in 1:2) {
      clustlike[,j]<-exp(clustlike[,j]-tempmax)
    }
    tempsum<-apply(clustlike,1,sum)

    for(j in 1:2) {
      clustlike[,j]<-clustlike[,j]/tempsum
    }

    p.post[,coli]<-clustlike[,2]
    loglike.final[coli]<-loglike.old
  }


  ## return
  loglike.final<-loglike.final*xrow
  result<-list(p.post=p.post, motif.prior=p, loglike=loglike.final)
}

## Fit the full model
cmfitfull<-function(x, type, tol=1e-3, max.iter=100) {
  ## initialize
  xrow<-nrow(x)
  xcol<-ncol(x)
  loglike0<-list()
  loglike1<-list()
  K<-2^xcol
  p<-rep(1,K)/K
  pattern<-rep(0,xcol)
  patid<-matrix(0,K,xcol)

  ## compute loglikelihood
  for(i in 1:xcol) {
    f0<-type[[i]][[1]]
    f0param<-type[[i]][[2]]
    f1<-type[[i]][[3]]
    f1param<-type[[i]][[4]]
    loglike0[[i]]<-f0(x[,i],f0param)
    loglike1[[i]]<-f1(x[,i],f1param)
  }
  L<-matrix(0,xrow,K)
  for(i in 1:K)
  {
    patid[i,]<-pattern
    for(j in 1:xcol) {
      if(pattern[j] < 0.5) {
        L[,i]<-L[,i]+loglike0[[j]]
      } else {
        L[,i]<-L[,i]+loglike1[[j]]
      }
    }

    if(i < K) {
      pattern[xcol]<-pattern[xcol]+1
      j<-xcol
      while(pattern[j] > 1) {
        pattern[j]<-0
        j<-j-1
        pattern[j]<-pattern[j]+1
      }
    }
  }

  ## EM algorithm to get MLE of p and q
  loglike.old <- -1e10
  for(i.iter in 1:max.iter) {
    if((i.iter%%50) == 0) {
      print(paste("We have run the first ", i.iter, " iterations",sep=""))
    }
    err<-tol+1

    ## compute posterior cluster membership
    clustlike<-matrix(0,xrow,K)
    for(j in 1:K) {
      clustlike[,j]<-log(p[j])+L[,j]
    }

    tempmax<-apply(clustlike,1,max)
    for(j in 1:K) {
      clustlike[,j]<-exp(clustlike[,j]-tempmax)
    }
    tempsum<-apply(clustlike,1,sum)

    ## update motif occurrence rate
    for(j in 1:K) {
      clustlike[,j]<-clustlike[,j]/tempsum
    }

    p.new<-(apply(clustlike,2,sum)+1)/(xrow+K)

    ## evaluate convergence
    err<-max(abs(p.new-p)/p)

    ## evaluate whether the log.likelihood increases
    loglike.new<-(sum(tempmax+log(tempsum))+sum(log(p.new)))/xrow

    loglike.old<-loglike.new
    p<-p.new

    if(err<tol) {
      break;
    }
  }

  ## compute posterior p
  clustlike<-matrix(0,xrow,K)
  for(j in 1:K) {
    clustlike[,j]<-log(p[j])+L[,j]
  }

  tempmax<-apply(clustlike,1,max)
  for(j in 1:K) {
    clustlike[,j]<-exp(clustlike[,j]-tempmax)
  }
  tempsum<-apply(clustlike,1,sum)

  for(j in 1:K) {
    clustlike[,j]<-clustlike[,j]/tempsum
  }

  p.post<-matrix(0,xrow,xcol)
  for(j in 1:K) {
    for(i in 1:xcol) {
      if(patid[j,i] > 0.5) {
        p.post[,i]<-p.post[,i]+clustlike[,j]
      }
    }
  }

  ## return
  #calculate back loglikelihood
  loglike.old<-loglike.old-sum(log(p))/xrow
  loglike.old<-loglike.old*xrow
  result<-list(p.post=p.post, motif.prior=p, loglike=loglike.old)
}

generatetype<-function(limfitted)
{
  jtype<-list()
  df<-limfitted$g1num+limfitted$g2num-2+limfitted$df0
  for(j in 1:limfitted$compnum)
  {
    jtype[[j]]<-list(f0=modt.f0.loglike, f0.param=df[j], f1=modt.f1.loglike, f1.param=c(df[j],limfitted$g1num[j],limfitted$g2num[j],limfitted$v0[j]))
  }
  jtype
}

cormotiffit <- function(exprs, groupid=NULL, compid=NULL, K=1, tol=1e-3,
                        max.iter=100, BIC=TRUE, norm.factor.method="TMM",
                        voom.normalize.method = "none", runtype=c("logCPM","counts","limmafits"), each=3)
{
  # first I want to do some typechecking. Input can be either a normalized
  # matrix, a count matrix, or a list of limma fits. Dispatch the correct
  # limmafit accordingly.
  # todo: add some typechecking here
  limfitted <- list()
  if (runtype=="counts") {
    limfitted <- limmafit.counts(exprs,groupid,compid, norm.factor.method, voom.normalize.method)
  } else if (runtype=="logCPM") {
    limfitted <- limmafit.default(exprs,groupid,compid)
  } else if (runtype=="limmafits") {
    limfitted <- limmafit.list(exprs)
  } else {
    stop("runtype must be one of 'logCPM', 'counts', or 'limmafits'")
  }


  jtype<-generatetype(limfitted)
  fitresult<-list()
  ks <- rep(K, each = each)
  fitresult <- bplapply(1:length(ks), function(i, x, type, ks, tol, max.iter) {
    cmfit.X(x, type, K = ks[i], tol = tol, max.iter = max.iter)
  }, x=limfitted$t, type=jtype, ks=ks, tol=tol, max.iter=max.iter)

  best.fitresults <- list()
  for (i in 1:length(K)) {
    w.k <- which(ks==K[i])
    this.bic <- c()
    for (j in w.k) this.bic[j] <- -2 * fitresult[[j]]$loglike + (K[i] - 1 + K[i] * limfitted$compnum) * log(dim(limfitted$t)[1])
    w.min <- which(this.bic == min(this.bic, na.rm = TRUE))[1]
    best.fitresults[[i]] <- fitresult[[w.min]]
  }
  fitresult <- best.fitresults

  bic <- rep(0, length(K))
  aic <- rep(0, length(K))
  loglike <- rep(0, length(K))
  for (i in 1:length(K)) loglike[i] <- fitresult[[i]]$loglike
  for (i in 1:length(K)) bic[i] <- -2 * fitresult[[i]]$loglike + (K[i] - 1 + K[i] * limfitted$compnum) * log(dim(limfitted$t)[1])
  for (i in 1:length(K)) aic[i] <- -2 * fitresult[[i]]$loglike + 2 * (K[i] - 1 + K[i] * limfitted$compnum)
  if(BIC==TRUE) {
    bestflag=which(bic==min(bic))
  }
  else {
    bestflag=which(aic==min(aic))
  }
  result<-list(bestmotif=fitresult[[bestflag]],bic=cbind(K,bic),
               aic=cbind(K,aic),loglike=cbind(K,loglike), allmotifs=fitresult)

}

cormotiffitall<-function(exprs,groupid,compid, tol=1e-3, max.iter=100)
{
  limfitted<-limmafit(exprs,groupid,compid)
  jtype<-generatetype(limfitted)
  fitresult<-cmfitall(limfitted$t,type=jtype,tol=1e-3,max.iter=max.iter)
}

cormotiffitsep<-function(exprs,groupid,compid, tol=1e-3, max.iter=100)
{
  limfitted<-limmafit(exprs,groupid,compid)
  jtype<-generatetype(limfitted)
  fitresult<-cmfitsep(limfitted$t,type=jtype,tol=1e-3,max.iter=max.iter)
}

cormotiffitfull<-function(exprs,groupid,compid, tol=1e-3, max.iter=100)
{
  limfitted<-limmafit(exprs,groupid,compid)
  jtype<-generatetype(limfitted)
  fitresult<-cmfitfull(limfitted$t,type=jtype,tol=1e-3,max.iter=max.iter)
}

plotIC<-function(fitted_cormotif)
{
  oldpar<-par(mfrow=c(1,2))
  plot(fitted_cormotif$bic[,1], fitted_cormotif$bic[,2], type="b",xlab="Motif Number", ylab="BIC", main="BIC")
  plot(fitted_cormotif$aic[,1], fitted_cormotif$aic[,2], type="b",xlab="Motif Number", ylab="AIC", main="AIC")
}

plotMotif<-function(fitted_cormotif,title="")
{
  layout(matrix(1:2,ncol=2))
  u<-1:dim(fitted_cormotif$bestmotif$motif.q)[2]
  v<-1:dim(fitted_cormotif$bestmotif$motif.q)[1]
  image(u,v,t(fitted_cormotif$bestmotif$motif.q),
        col=gray(seq(from=1,to=0,by=-0.1)),xlab="Study",yaxt = "n",
        ylab="Corr. Motifs",main=paste(title,"pattern",sep=" "))
  axis(2,at=1:length(v))
  for(i in 1:(length(u)+1))
  {
    abline(v=(i-0.5))
  }
  for(i in 1:(length(v)+1))
  {
    abline(h=(i-0.5))
  }
  Ng=10000
  if(is.null(fitted_cormotif$bestmotif$p.post)!=TRUE)
    Ng=nrow(fitted_cormotif$bestmotif$p.post)
  genecount=floor(fitted_cormotif$bestmotif$motif.p*Ng)
  NK=nrow(fitted_cormotif$bestmotif$motif.q)
  plot(0,0.7,pch=".",xlim=c(0,1.2),ylim=c(0.75,NK+0.25),
       frame.plot=FALSE,axes=FALSE,xlab="No. of genes",ylab="", main=paste(title,"frequency",sep=" "))
  segments(0,0.7,fitted_cormotif$bestmotif$motif.p[1],0.7)
  rect(0,1:NK-0.3,fitted_cormotif$bestmotif$motif.p,1:NK+0.3,
       col="dark grey")
  mtext(1:NK,at=1:NK,side=2,cex=0.8)
  text(fitted_cormotif$bestmotif$motif.p+0.15,1:NK,
       labels=floor(fitted_cormotif$bestmotif$motif.p*Ng))
}

plotMotifnew<-function(fitted_cormotif,title="")
{
  layout(matrix(1:2,ncol=2))
  u<-1:dim(fitted_cormotif$motif.q)[2]
  v<-1:dim(fitted_cormotif$motif.q)[1]
  image(u,v,t(fitted_cormotif$motif.q),
        col=gray(seq(from=1,to=0,by=-0.1)),xlab="Experiment",yaxt = "n",
        ylab="Corr. Motifs",main=paste(title,"pattern",sep=" "))
  axis(2,at=1:length(v))
  for(i in 1:(length(u)+1))
  {
    abline(v=(i-0.5))
  }
  for(i in 1:(length(v)+1))
  {
    abline(h=(i-0.5))
  }
  Ng=10000
  if(is.null(fitted_cormotif$p.post)!=TRUE)
    Ng=nrow(fitted_cormotif$p.post)
  genecount=floor(fitted_cormotif$motif.p*Ng)
  NK=nrow(fitted_cormotif$motif.q)
  plot(0,0.7,pch=".",xlim=c(0,1.2),ylim=c(0.75,NK+0.25),
       frame.plot=FALSE,axes=FALSE,xlab="No. of regions",ylab="", main=paste(title,"frequency",sep=" "))
  segments(0,0.7,fitted_cormotif$motif.p[1],0.7)
  rect(0,1:NK-0.3,fitted_cormotif$motif.p,1:NK+0.3,
       col="dark grey")
  mtext(1:NK,at=1:NK,side=2,cex=0.8)
  text(fitted_cormotif$motif.p+0.15,1:NK,
       labels=floor(fitted_cormotif$motif.p*Ng))
}

Feature Counts

# H3K27ac_merged <- read_delim("data/peaks/H3K27ac_FINAL_counts.txt", 
#     delim = "\t", escape_double = FALSE, 
#     trim_ws = TRUE, skip = 1)
# H3K27me3_merged <- read_delim("data/peaks/H3K27me3_FINAL_counts.txt", 
#     delim = "\t", escape_double = FALSE, 
#     trim_ws = TRUE, skip = 1)
H3K36me3_merged <- read_delim("data/peaks/H3K36me3_FINAL_counts.txt", 
    delim = "\t", escape_double = FALSE, 
    trim_ws = TRUE, skip = 1)
H3K9me3_merged <- read_delim("data/peaks/H3K9me3_FINAL_counts.txt", 
    delim = "\t", escape_double = FALSE, 
    trim_ws = TRUE, skip = 1)
rename_list <- sampleinfo %>% 
  mutate(stem= "_nobl.bam") %>% 
  mutate(prefix=paste0("/scratch/10819/styu/MW_multiQC/peaks/",Histone_Mark,"/",Treatment,"/",Timepoint,"/")) %>%
  mutate(oldname=paste0(prefix,`Library ID`,"/",`Library ID`,stem)) %>% 
  mutate(newname=paste0(Individual,"_",Treatment,"_",Timepoint)) %>% 
  dplyr::select(oldname,newname)
rename_vec <- setNames(rename_list$newname, rename_list$oldname)
# names(H3K27ac_merged)[names(H3K27ac_merged) %in% names(rename_vec)] <- rename_vec[names(H3K27ac_merged)[names(H3K27ac_merged) %in% names(rename_vec)]]
# names(H3K27me3_merged)[names(H3K27me3_merged) %in% names(rename_vec)] <- rename_vec[names(H3K27me3_merged)[names(H3K27me3_merged) %in% names(rename_vec)]]
names(H3K36me3_merged)[names(H3K36me3_merged) %in% names(rename_vec)] <- rename_vec[names(H3K36me3_merged)[names(H3K36me3_merged) %in% names(rename_vec)]]
names(H3K9me3_merged)[names(H3K9me3_merged) %in% names(rename_vec)] <- rename_vec[names(H3K9me3_merged)[names(H3K9me3_merged) %in% names(rename_vec)]]

Removing outliers

H3K36me3_merged <- H3K36me3_merged %>% 
  dplyr::select(!Ind1_VEH_144R)

H3K9me3_merged<- H3K9me3_merged %>%
  dplyr::select(!Ind1_VEH_24T) %>% 
  dplyr::select(!Ind3_DOX_24T) %>%
  dplyr::select(!Ind5_DOX_144R)
# H3K27ac_merged_raw <- H3K27ac_merged %>% 
#   dplyr::select(Geneid,contains("Ind")) %>% 
#   column_to_rownames("Geneid") %>% 
#   as.matrix()
# H3K27ac_merged_lcpm <- H3K27ac_merged %>% 
#   dplyr::select(Geneid,contains("Ind")) %>% 
#   column_to_rownames("Geneid") %>% 
#   cpm(., log = TRUE)
# H3K27ac_merged_cor <- H3K27ac_merged_lcpm %>% 
#   cor()


# H3K27me3_merged_raw <- H3K27me3_merged %>% 
#   dplyr::select(Geneid,contains("Ind")) %>% 
#   column_to_rownames("Geneid") %>% 
#   as.matrix()
# H3K27me3_merged_lcpm <- H3K27me3_merged %>% 
#   dplyr::select(Geneid,contains("Ind")) %>% 
#   column_to_rownames("Geneid") %>% 
#   cpm(., log = TRUE)
# H3K27me3_merged_cor <- H3K27me3_merged_lcpm %>% 
#   cor()

H3K36me3_merged_raw <- H3K36me3_merged %>% 
  dplyr::select(Geneid,contains("Ind")) %>% 
  column_to_rownames("Geneid") %>% 
  as.matrix()
H3K36me3_merged_lcpm <- H3K36me3_merged %>% 
  dplyr::select(Geneid,contains("Ind")) %>% 
  column_to_rownames("Geneid") %>% 
  cpm(., log = TRUE)
H3K36me3_merged_cor <- H3K36me3_merged_lcpm %>% 
  cor()

H3K9me3_merged_raw <- H3K9me3_merged %>% 
  dplyr::select(Geneid,contains("Ind")) %>% 
  column_to_rownames("Geneid") %>% 
  as.matrix()
H3K9me3_merged_lcpm <- H3K9me3_merged %>% 
  dplyr::select(Geneid,contains("Ind")) %>% 
  column_to_rownames("Geneid") %>% 
  cpm(., log = TRUE)
H3K9me3_merged_cor <- H3K9me3_merged_lcpm %>% 
  cor()

Removing chrX and chrY

# H3K27ac_merged_raw <- H3K27ac_merged_raw[rowMeans(H3K27ac_merged_cor)>0,]
# H3K27ac_merged_raw <- H3K27ac_merged_raw[!grepl("chrY",rownames(H3K27ac_merged_raw)),]
# H3K27ac_merged_raw <- H3K27ac_merged_raw[!grepl("chrX",rownames(H3K27ac_merged_raw)),]
# 
# H3K27me3_merged_raw <- H3K27me3_merged_raw[rowMeans(H3K27me3_merged_cor)>0,]
# H3K27me3_merged_raw <- H3K27me3_merged_raw[!grepl("chrY",rownames(H3K27me3_merged_raw)),]
# H3K27me3_merged_raw <- H3K27me3_merged_raw[!grepl("chrX",rownames(H3K27me3_merged_raw)),]


H3K36me3_merged_raw <- H3K36me3_merged_raw[rowMeans(H3K36me3_merged_lcpm)>0,]
H3K36me3_merged_raw <- H3K36me3_merged_raw[!grepl("chrY",rownames(H3K36me3_merged_raw)),]
H3K36me3_merged_raw <- H3K36me3_merged_raw[!grepl("chrX",rownames(H3K36me3_merged_raw)),]

H3K9me3_merged_raw <- H3K9me3_merged_raw[rowMeans(H3K9me3_merged_lcpm)>0,]
H3K9me3_merged_raw <- H3K9me3_merged_raw[!grepl("chrY",rownames(H3K9me3_merged_raw)),]
H3K9me3_merged_raw <- H3K9me3_merged_raw[!grepl("chrX",rownames(H3K9me3_merged_raw)),]

Setting up Matrix

# H3K27ac_annomat <- data.frame(timeset=colnames(H3K27ac_merged_raw)) %>% 
#   mutate(sample=timeset) %>% 
#   separate(timeset, into = c("ind","tx","time")) %>% 
#   mutate(tx=factor(tx, levels = c("VEH", "DOX")),
#          time=factor(time, levels =c("24T","24R","144R"))) %>%
#   mutate(ind = gsub("Ind", "", ind)) %>%
#   mutate(txtime = paste0(tx, "_", time)) %>%
#   mutate(group = txtime)
# H3K27ac_annomat$group <- H3K27ac_annomat$group %>%
#   gsub("DOX_24T", "1", .) %>%
#   gsub("DOX_24R", "2", .) %>%
#   gsub("DOX_144R", "3", .) %>%
#   gsub("VEH_24T", "4", .) %>%
#   gsub("VEH_24R", "5", .) %>%
#   gsub("VEH_144R", "6", .)
# 
# H3K27me3_annomat <- data.frame(timeset=colnames(H3K27me3_merged_raw)) %>% 
#   mutate(sample=timeset) %>% 
#   separate(timeset, into = c("ind","tx","time")) %>% 
#   mutate(tx=factor(tx, levels = c("VEH", "DOX")),
#          time=factor(time, levels =c("24T","24R","144R"))) %>%
#   mutate(ind = gsub("Ind", "", ind)) %>%
#   mutate(txtime = paste0(tx, "_", time)) %>%
#   mutate(group = txtime)
# H3K27me3_annomat$group <- H3K27me3_annomat$group %>%
#   gsub("DOX_24T", "1", .) %>%
#   gsub("DOX_24R", "2", .) %>%
#   gsub("DOX_144R", "3", .) %>%
#   gsub("VEH_24T", "4", .) %>%
#   gsub("VEH_24R", "5", .) %>%
#   gsub("VEH_144R", "6", .)

H3K36me3_annomat <- data.frame(timeset=colnames(H3K36me3_merged_raw)) %>% 
  mutate(sample=timeset) %>% 
  separate(timeset, into = c("ind","tx","time")) %>% 
  mutate(tx=factor(tx, levels = c("VEH", "DOX")),
         time=factor(time, levels =c("24T","24R","144R"))) %>%
  mutate(ind = gsub("Ind", "", ind)) %>%
  mutate(txtime = paste0(tx, "_", time)) %>%
  mutate(group = txtime)
H3K36me3_annomat$group <- H3K36me3_annomat$group %>%
  gsub("DOX_24T", "1", .) %>%
  gsub("DOX_24R", "2", .) %>%
  gsub("DOX_144R", "3", .) %>%
  gsub("VEH_24T", "4", .) %>%
  gsub("VEH_24R", "5", .) %>%
  gsub("VEH_144R", "6", .)

H3K9me3_annomat <- data.frame(timeset=colnames(H3K9me3_merged_raw)) %>% 
  mutate(sample=timeset) %>% 
  separate(timeset, into = c("ind","tx","time")) %>% 
  mutate(tx=factor(tx, levels = c("VEH", "DOX")),
         time=factor(time, levels =c("24T","24R","144R"))) %>%
  mutate(ind = gsub("Ind", "", ind)) %>%
  mutate(txtime = paste0(tx, "_", time)) %>%
  mutate(group = txtime)
H3K9me3_annomat$group <- H3K9me3_annomat$group %>%
  gsub("DOX_24T", "1", .) %>%
  gsub("DOX_24R", "2", .) %>%
  gsub("DOX_144R", "3", .) %>%
  gsub("VEH_24T", "4", .) %>%
  gsub("VEH_24R", "5", .) %>%
  gsub("VEH_144R", "6", .)

# dge_H3K27ac <- edgeR::DGEList(counts = H3K27ac_merged_raw, group = H3K27ac_annomat$group, genes = row.names(H3K27ac_merged_raw))
# dge_H3K27me3 <- edgeR::DGEList(counts = H3K27me3_merged_raw, group = H3K27me3_annomat$group, genes = row.names(H3K27me3_merged_raw))
dge_H3K36me3 <- edgeR::DGEList(counts = H3K36me3_merged_raw, group = H3K36me3_annomat$group, genes = row.names(H3K36me3_merged_raw))
dge_H3K9me3 <- edgeR::DGEList(counts = H3K9me3_merged_raw, group = H3K9me3_annomat$group, genes = row.names(H3K9me3_merged_raw))

# dge_H3K27ac <- edgeR::calcNormFactors(dge_H3K27ac)
# dge_H3K27me3 <- edgeR::calcNormFactors(dge_H3K27me3)
dge_H3K36me3 <- edgeR::calcNormFactors(dge_H3K36me3)
dge_H3K9me3 <- edgeR::calcNormFactors(dge_H3K9me3)

# mm_H3K27ac <- model.matrix(~0 + H3K27ac_annomat$txtime)
# colnames(mm_H3K27ac) <- H3K27ac_annomat$txtime %>% unique()
# 
# mm_H3K27me3 <- model.matrix(~0 + H3K27me3_annomat$txtime)
# colnames(mm_H3K27me3) <- H3K27me3_annomat$txtime %>% unique()
# 
# mm_H3K36me3 <- model.matrix(~0 + H3K36me3_annomat$txtime)
# colnames(mm_H3K36me3) <- H3K36me3_annomat$txtime %>% unique()
# 
# mm_H3K9me3 <- model.matrix(~0 + H3K9me3_annomat$txtime)
# colnames(mm_H3K9me3) <- H3K9me3_annomat$txtime %>% unique()

making comparison and group matrices

# lcpm_dge_H3K27ac <- cpm(dge_H3K27ac, log = TRUE)
# lcpm_dge_H3K27me3 <- cpm(dge_H3K27me3, log = TRUE)
lcpm_dge_H3K36me3 <- cpm(dge_H3K36me3, log = TRUE)
lcpm_dge_H3K9me3 <- cpm(dge_H3K9me3, log = TRUE)

# H3K27ac_group <- H3K27ac_annomat$group
# H3K27me3_group <- H3K27me3_annomat$group
H3K36me3_group <- H3K36me3_annomat$group
H3K9me3_group <- H3K9me3_annomat$group

compid <- data.frame(c1= c(1,2,3), c2 = c( 4,5,6))
compid
  c1 c2
1  1  4
2  2  5
3  3  6

H3K27ac cormotif

set.seed(31415)
cormotif_initial_H3K27ac <- cormotiffit(exprs = lcpm_dge_H3K27ac, groupid = H3K27ac_group, compid = compid, K=1:8, max.iter = 500, runtype = "logCPM")

saveRDS(cormotif_initial_H3K27ac,"data/Cormotif_data/Cormotif_initial_H3K27ac.RDS")
plotIC(cormotif_initial_H3K27ac)
plotMotif(cormotif_initial_H3K27ac)

H3K27me3 cormotif

set.seed(31415)
cormotif_initial_H3K27me3 <- cormotiffit(exprs = lcpm_dge_H3K27me3, groupid = H3K27me3_group, compid = compid, K=1:8, max.iter = 500, runtype = "logCPM")

saveRDS(cormotif_initial_H3K27me3,"data/Cormotif_data/Cormotif_initial_H3K27me3.RDS")
plotIC(cormotif_initial_H3K27me3)
plotMotif(cormotif_initial_H3K27me3)

H3K36me3 cormotif

set.seed(31415)
cormotif_initial_H3K36me3 <- cormotiffit(exprs = lcpm_dge_H3K36me3, groupid = H3K36me3_group, compid = compid, K=1:8, max.iter = 500, runtype = "logCPM")

saveRDS(cormotif_initial_H3K36me3,"data/Cormotif_data/Cormotif_initial_H3K36me3_nooutlier.RDS")
cormotif_initial_H3K36me3 <- readRDS("data/Cormotif_data/Cormotif_initial_H3K36me3_nooutlier.RDS")

myColors <-  rev(c("#FFFFFF", "#E6E6E6" ,"#CCCCCC", "#B3B3B3", "#999999", "#808080", "#666666","#4C4C4C", "#333333", "#191919","#000000"))

plot.new()
legend('center',fill=myColors, legend =rev(c("0", "0.1", "0.2", "0.3", "0.4",  "0.5", "0.6", "0.7", "0.8","0.9", "1")), box.col="white",title = "Probability\nlegend", horiz=FALSE,title.cex=.8)

plotIC(cormotif_initial_H3K36me3)

plotMotif(cormotif_initial_H3K36me3)

H3K9me3 cormotif

set.seed(31415)
cormotif_initial_H3K9me3 <- cormotiffit(exprs = lcpm_dge_H3K9me3, groupid = H3K9me3_group, compid = compid, K=1:8, max.iter = 500, runtype = "logCPM")

saveRDS(cormotif_initial_H3K9me3,"data/Cormotif_data/Cormotif_initial_H3K9me3_nooutlier.RDS")
cormotif_initial_H3K9me3 <- readRDS("data/Cormotif_data/Cormotif_initial_H3K9me3_nooutlier.RDS")
plotIC(cormotif_initial_H3K9me3)

plotMotif(cormotif_initial_H3K9me3)


sessionInfo()
R version 4.4.2 (2024-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/Chicago
tzcode source: internal

attached base packages:
[1] stats4    grid      stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] BiocParallel_1.40.2   ggsignif_0.6.4        ggVennDiagram_1.5.4  
 [4] smplot2_0.2.5         cowplot_1.2.0         ggrastr_1.0.2        
 [7] Rsubread_2.20.0       gcplyr_1.12.0         ggpmisc_0.6.2        
[10] ggpp_0.5.9            corrplot_0.95         ggpubr_0.6.1         
[13] GenomicRanges_1.58.0  GenomeInfoDb_1.42.3   IRanges_2.40.1       
[16] S4Vectors_0.44.0      BiocGenerics_0.52.0   genomation_1.38.0    
[19] kableExtra_1.4.0      DT_0.33               viridis_0.6.5        
[22] viridisLite_0.4.2     data.table_1.17.8     ComplexHeatmap_2.22.0
[25] edgeR_4.4.2           limma_3.62.2          lubridate_1.9.4      
[28] forcats_1.0.0         stringr_1.5.1         dplyr_1.1.4          
[31] purrr_1.1.0           readr_2.1.5           tidyr_1.3.1          
[34] tibble_3.3.0          ggplot2_3.5.2         tidyverse_2.0.0      
[37] workflowr_1.7.1      

loaded via a namespace (and not attached):
  [1] splines_4.4.2               later_1.4.2                
  [3] BiocIO_1.16.0               bitops_1.0-9               
  [5] rpart_4.1.24                XML_3.99-0.18              
  [7] lifecycle_1.0.4             rstatix_0.7.2              
  [9] doParallel_1.0.17           rprojroot_2.1.0            
 [11] vroom_1.6.5                 processx_3.8.6             
 [13] lattice_0.22-7              MASS_7.3-65                
 [15] backports_1.5.0             magrittr_2.0.3             
 [17] Hmisc_5.2-3                 sass_0.4.10                
 [19] rmarkdown_2.29              jquerylib_0.1.4            
 [21] yaml_2.3.10                 plotrix_3.8-4              
 [23] httpuv_1.6.16               RColorBrewer_1.1-3         
 [25] abind_1.4-8                 zlibbioc_1.52.0            
 [27] RCurl_1.98-1.17             nnet_7.3-20                
 [29] git2r_0.36.2                circlize_0.4.16            
 [31] GenomeInfoDbData_1.2.13     MatrixModels_0.5-4         
 [33] svglite_2.2.1               codetools_0.2-20           
 [35] DelayedArray_0.32.0         xml2_1.4.0                 
 [37] tidyselect_1.2.1            shape_1.4.6.1              
 [39] UCSC.utils_1.2.0            farver_2.1.2               
 [41] matrixStats_1.5.0           base64enc_0.1-3            
 [43] GenomicAlignments_1.42.0    jsonlite_2.0.0             
 [45] GetoptLong_1.0.5            Formula_1.2-5              
 [47] survival_3.8-3              iterators_1.0.14           
 [49] systemfonts_1.2.3           foreach_1.5.2              
 [51] tools_4.4.2                 Rcpp_1.1.0                 
 [53] glue_1.8.0                  gridExtra_2.3              
 [55] SparseArray_1.6.2           xfun_0.52                  
 [57] MatrixGenerics_1.18.1       withr_3.0.2                
 [59] fastmap_1.2.0               SparseM_1.84-2             
 [61] callr_3.7.6                 digest_0.6.37              
 [63] timechange_0.3.0            R6_2.6.1                   
 [65] seqPattern_1.38.0           textshaping_1.0.1          
 [67] colorspace_2.1-1            dichromat_2.0-0.1          
 [69] generics_0.1.4              rtracklayer_1.66.0         
 [71] httr_1.4.7                  htmlwidgets_1.6.4          
 [73] S4Arrays_1.6.0              whisker_0.4.1              
 [75] pkgconfig_2.0.3             gtable_0.3.6               
 [77] impute_1.80.0               XVector_0.46.0             
 [79] htmltools_0.5.8.1           carData_3.0-5              
 [81] pwr_1.3-0                   clue_0.3-66                
 [83] scales_1.4.0                Biobase_2.66.0             
 [85] png_0.1-8                   knitr_1.50                 
 [87] rstudioapi_0.17.1           tzdb_0.5.0                 
 [89] reshape2_1.4.4              rjson_0.2.23               
 [91] checkmate_2.3.3             curl_7.0.0                 
 [93] zoo_1.8-14                  cachem_1.1.0               
 [95] GlobalOptions_0.1.2         KernSmooth_2.23-26         
 [97] parallel_4.4.2              vipor_0.4.7                
 [99] foreign_0.8-90              restfulr_0.0.16            
[101] pillar_1.11.0               vctrs_0.6.5                
[103] promises_1.3.3              car_3.1-3                  
[105] cluster_2.1.8.1             htmlTable_2.4.3            
[107] beeswarm_0.4.0              evaluate_1.0.4             
[109] cli_3.6.5                   locfit_1.5-9.12            
[111] compiler_4.4.2              Rsamtools_2.22.0           
[113] rlang_1.1.6                 crayon_1.5.3               
[115] ps_1.9.1                    getPass_0.2-4              
[117] plyr_1.8.9                  fs_1.6.6                   
[119] ggbeeswarm_0.7.2            stringi_1.8.7              
[121] gridBase_0.4-7              Biostrings_2.74.1          
[123] quantreg_6.1                Matrix_1.7-3               
[125] BSgenome_1.74.0             patchwork_1.3.1            
[127] hms_1.1.3                   bit64_4.6.0-1              
[129] statmod_1.5.0               SummarizedExperiment_1.36.0
[131] broom_1.0.9                 bslib_0.9.0                
[133] bit_4.6.0                   polynom_1.4-1