I am trying to det telomere length values from processed dna methylation data. I am using the package methylclockdata
the code I used is as follows:
library(minfi)
library(knitr)
library(limma)
library(minfi)
library(IlluminaHumanMethylation450kanno.ilmn12.hg19)
library(IlluminaHumanMethylation450kmanifest)
library(RColorBrewer)
library(Gviz)
library(stringr)
library(ENmix)
library(tidyverse)
library(ggpubr)
library(methylclockData)
library(methylclock)
library(impute)
require(minfiData)
path <- file.path("C:/Users/Sarah Vasavan/Documents/DNA methylation project")
rgSet <- readidat(path = path,recursive = TRUE)
qc<-QCinfo(rgSet)
mdat<-preprocessENmix(rgSet, bgParaEst="oob", dyeCorr="RELIC", nCores=6)
mdat<-norm.quantile(mdat, method="quantile1")
beta_values <- getBeta(mdat)
knitr::opts_chunk$set(echo = TRUE)
library(ExperimentHub)
library(methylclockData)
eh <- ExperimentHub()
pData <- query(eh , "methylclockData")
df <- mcols(pData)
df
pData["EH6071"]
Telomere Length clock coefficients
coefTL <- get_coefTL()
head(coefTL)
Matrix multiplication to estimate telomere length
telomere_length_estimates <- beta_values %*% coefTL
the error I keep getting is:
requires numeric/complex matrix/vector arguments
based on chatgpt's recommendations, I then did the following steps:
Assuming beta_values is a matrix of beta values where rows represent CpG sites and columns represent samples
Check the class and structure of beta_values
class(beta_values)
str(beta_values)
Convert beta_values to a numeric matrix if it's not already in matrix format
beta_matrix <- as.matrix(beta_values)
Perform matrix multiplication
telomere_length_estimates <- beta_matrix %*% coefTL
The coefTL object is a data frame with 141 observations and 22 variables. To perform matrix multiplication, we need to extract the numeric coefficients from coefTL and convert them into a numeric matrix.
Extract numeric coefficients from coefTL
coefTL_numeric <- coefTL[, !(names(coefTL) %in% "CpGmarker")]
coefTL_matrix <- as.matrix(coefTL_numeric)
Check the structure of coefTL_matrix
str(coefTL_matrix)
Perform matrix multiplication
telomere_length_estimates <- beta_matrix %*% coefTL_matrix
Convert elements of coefTL_matrix to numeric
coefTL_matrix <- as.matrix(as.numeric(coefTL_matrix))
Check the structure of coefTL_matrix after conversion
str(coefTL_matrix)
Perform matrix multiplication
telomere_length_estimates <- beta_matrix %*% coefTL_matrix
Check dimensions of beta_matrix and coefTL_matrix
dim(beta_matrix)
[1] 473026 12
dim(coefTL_matrix)
[1] 2961 1
The issue is that the number of columns in beta_matrix (12) does not match the number of rows in coefTL_matrix (2961). To perform matrix multiplication, the number of columns in the first matrix must match the number of rows in the second matrix.
It seems like coefTL_matrix has only one column, which might not be what you intended. Double-check how you extracted or created coefTL_matrix to ensure it has the correct dimensions.
If coefTL_matrix should have more than one column, you need to revise how you extracted or created it so that it matches the expected dimensions for matrix multiplication with beta_matrix.
based on this feedback, I dont know what I should do next. any feedback is appreciated. thanks