### Identify Differentially Methylated Cell-Types with CellDMC Source: https://context7.com/sjczheng/epidish/llms.txt This example shows how to use the `CellDMC` function to identify differentially methylated cell-types (DMCTs). It requires beta values, a phenotype vector, and estimated cell-type fractions. P-value adjustment methods and thresholds can be specified. ```r library(EpiDISH) # Load data and estimate cell fractions first data(centEpiFibIC.m) data(DummyBeta.m) # Step 1: Estimate cell-type fractions out <- epidish(DummyBeta.m, centEpiFibIC.m, method = "RPC") frac.m <- out$estF # Step 2: Define phenotype vector (case/control) pheno.v <- rep(c(0, 1), each = 5) # 5 controls, 5 cases # Step 3: Run CellDMC analysis celldmc_result <- CellDMC( beta.m = DummyBeta.m, # Beta values (CpGs x samples) pheno.v = pheno.v, # Phenotype vector (binary or continuous) frac.m = frac.m, # Cell-type fractions from epidish adjPMethod = "fdr", # P-value adjustment method adjPThresh = 0.05, # Threshold for calling DMCTs cov.mod = NULL, # Optional covariates design matrix sort = FALSE, # Sort results by p-value mc.cores = 1 # Number of cores for parallelization ) # Access DMCT matrix: 0 = not DMC/DMCT, 1 = hyper, -1 = hypo dmct_matrix <- celldmc_result$dmct print(head(dmct_matrix)) ``` ```r # Access detailed coefficients for each cell-type epi_results <- celldmc_result$coe$Epi print(head(epi_results)) ``` ```r # With covariates adjustment (e.g., age and gender) pheno_data <- data.frame( age = c(45, 52, 38, 61, 55, 48, 59, 42, 67, 51), gender = factor(c(rep("M", 5), rep("F", 5))) ) cov_matrix <- model.matrix(~ age + gender, data = pheno_data) celldmc_adjusted <- CellDMC( beta.m = DummyBeta.m, pheno.v = pheno.v, frac.m = frac.m, adjPMethod = "BH", adjPThresh = 0.05, cov.mod = cov_matrix, # Adjust for age and gender sort = TRUE, # Sort by p-value mc.cores = 4 # Use 4 cores ) # Find significant DMCTs for each cell-type sig_epi <- which(celldmc_adjusted$dmct[, "Epi"] != 0) sig_fib <- which(celldmc_adjusted$dmct[, "Fib"] != 0) sig_ic <- which(celldmc_adjusted$dmct[, "IC"] != 0) ``` -------------------------------- ### Load Reference and Beta Data in R Source: https://github.com/sjczheng/epidish/blob/devel/README.md Load the required reference centroid matrix and dummy beta value matrix for analysis. ```R data(centEpiFibIC.m) data(DummyBeta.m) ``` -------------------------------- ### Load EpiDISH library and data Source: https://github.com/sjczheng/epidish/blob/devel/README.md Loads the EpiDISH package and necessary data objects for cell-type fraction estimation. ```R library(EpiDISH) data(centDHSbloodDMC.m) data(LiuDataSub.m) ``` -------------------------------- ### Display Session Information Source: https://github.com/sjczheng/epidish/blob/devel/README.md Output the current R session environment details. ```R sessionInfo() ``` -------------------------------- ### Run CBS Method with hepidish Source: https://context7.com/sjczheng/epidish/llms.txt This snippet demonstrates how to use the `hepidish` function with the 'CBS' method to estimate cell-type fractions. Ensure necessary data like `DummyBeta.m`, `centEpiFibIC.m`, and `centBloodSub.m` are loaded. ```r frac_cbs <- hepidish( beta.m = DummyBeta.m, ref1.m = centEpiFibIC.m, ref2.m = centBloodSub.m, h.CT.idx = 3, method = "CBS", nu.v = c(0.25, 0.5, 0.75) ) ``` -------------------------------- ### Inspect EpiDISH Output Source: https://github.com/sjczheng/epidish/blob/devel/README.md Examine the estimated fractions and the dimensions of the reference and data matrices used. ```R out.l$estF dim(out.l$ref) dim(out.l$dataREF) ``` -------------------------------- ### Access and Construct DNAm Panels Source: https://context7.com/sjczheng/epidish/llms.txt Retrieve detailed probe selection results and construct custom DNA methylation panels using median summary methods. ```R cd4t_probes <- panel_result$DetailedResults$CD4T print(head(cd4t_probes)) ``` ```R fractions_custom <- epidish( beta.m = new_sample_data, ref.m = custom_reference, method = "RPC" )$estF ``` ```R panel_median <- ConstructDNAmPanel( dnam.matrix = dnam_matrix, cell.types.info = cell_info, panel.cell.types = c("CD4T", "Bcell", "Mono"), n.probes = 50, fdr.threshold = 0.01, summary.method = "median" ) ``` -------------------------------- ### Construct Custom DNAm Reference Panels Source: https://context7.com/sjczheng/epidish/llms.txt This snippet demonstrates how to use `ConstructDNAmPanel` to build custom cell-type-specific DNA methylation reference panels. It requires a DNA methylation matrix and cell type information for samples. The function selects top-ranked probes based on a specified metric. ```r library(EpiDISH) # Assume you have purified cell-type DNA methylation data # dnam_matrix: beta values matrix (probes x samples), no NAs # cell_info: data.frame with "CellType" column for each sample # Example structure: # dnam_matrix[1:5, 1:3] #> Sample1 Sample2 Sample3 #> cg00000029 0.521 0.534 0.498 #> cg00000108 0.123 0.145 0.089 #> cg00000165 0.867 0.854 0.891 # cell_info #> SampleID CellType #> Sample1 Sample1 CD4T #> Sample2 Sample2 CD4T #> Sample3 Sample3 Bcell # Construct reference panel for specific cell types panel_result <- ConstructDNAmPanel( dnam.matrix = dnam_matrix, # Beta values (probes x samples) cell.types.info = cell_info, # Must have "CellType" column panel.cell.types = c("CD4T", "Bcell", "Mono", "NK"), # Target cell types n.probes = 100, # Top probes per cell type fdr.threshold = 0.05, # FDR for differential methylation p.adjust.method = "BH", # Multiple testing correction summary.method = "mean", # "mean" or "median" equal.variance = FALSE # For t-test ) # Access the reference panel matrix (for use with epidish) custom_reference <- panel_result$ReferencePanel print(dim(custom_reference)) ``` ```r #> [1] 400 4 # 100 probes x 4 cell types print(head(custom_reference)) ``` -------------------------------- ### Utilize Built-in Reference Matrices Source: https://context7.com/sjczheng/epidish/llms.txt Load pre-built DNA methylation reference matrices for blood and solid tissues to perform deconvolution. ```R library(EpiDISH) data(centDHSbloodDMC.m) print(colnames(centDHSbloodDMC.m)) data(cent12CT.m) print(colnames(cent12CT.m)) data(cent12CT450k.m) data(centUniLIFE.m) data(centEpiFibIC.m) print(colnames(centEpiFibIC.m)) data(centBloodSub.m) data(centEpiFibFatIC.m) print(colnames(centEpiFibFatIC.m)) data(LiuDataSub.m) blood_fractions <- epidish(LiuDataSub.m, cent12CT.m, method = "RPC")$estF data(DummyBeta.m) solid_fractions <- hepidish( DummyBeta.m, ref1.m = centEpiFibIC.m, # Primary: Epi, Fib, IC ref2.m = centBloodSub.m, # Secondary: immune subtypes h.CT.idx = 3, # Decompose IC (column 3) method = "RPC" ) ``` -------------------------------- ### Perform Meta-Analysis with DoMetaEfron Source: https://context7.com/sjczheng/epidish/llms.txt Execute meta-analysis across EWAS studies using empirical Bayes and Stouffer's method, including filtering and diagnostic plotting. ```R library(EpiDISH) meta_result <- DoMetaEfron( stat.m = stat_matrix, # Signed statistics (t-stats) pval.m = pval_matrix, # Associated p-values bre = 120, # Breakpoints for locfdr df = 15, # Degrees of freedom for spline pct0 = 0.25, # Percentage for fitting null (25%) plotlocfdr = 0 # Set to 1 to see diagnostic plots ) print(head(meta_result)) significant_cpgs <- rownames(meta_result)[meta_result[, "AdjP(BH)"] < 0.05] length(significant_cpgs) hyper_cpgs <- rownames(meta_result)[meta_result[, "z(Stouffer)"] > 0 & meta_result[, "AdjP(BH)"] < 0.05] hypo_cpgs <- rownames(meta_result)[meta_result[, "z(Stouffer)"] < 0 & meta_result[, "AdjP(BH)"] < 0.05] meta_with_plots <- DoMetaEfron( stat.m = stat_matrix, pval.m = pval_matrix, plotlocfdr = 1 # Show locfdr diagnostic plots ) ``` -------------------------------- ### Estimate Breast Tissue Cell Fractions Source: https://context7.com/sjczheng/epidish/llms.txt Estimates cell-type fractions in breast tissue using the epidish function with the RPC method. Requires beta values and a reference matrix. ```r breast_fractions <- epidish( breast_betas, centEpiFibFatIC.m, method = "RPC" )$estF ``` -------------------------------- ### Infer Cell-Type Fractions with EpiDISH Source: https://github.com/sjczheng/epidish/blob/devel/README.md Use the epidish function with the RPC method to estimate cell-type fractions from beta values. ```R out.l <- epidish(beta.m = DummyBeta.m, ref.m = centEpiFibIC.m, method = "RPC") ``` -------------------------------- ### Visualize inferred blood cell-type fractions Source: https://github.com/sjczheng/epidish/blob/devel/README.md Generates boxplots to visualize the distribution of inferred cell-type fractions, useful for validating results. ```R boxplot(BloodFrac.m) ``` -------------------------------- ### Infer blood cell-type fractions using RPC Source: https://github.com/sjczheng/epidish/blob/devel/README.md Estimates cell-type fractions in a blood DNAm sample using the Robust Partial Correlations (RPC) method and a reference matrix. ```R BloodFrac.m <- epidish(beta.m = LiuDataSub.m, ref.m = centDHSbloodDMC.m, method = "RPC")$estF ``` -------------------------------- ### Estimate Immune Cell Subtypes with HEpiDISH Source: https://github.com/sjczheng/epidish/blob/devel/README.md Perform hierarchical estimation of cell-type fractions using primary and secondary DNAm references. ```R data(centBloodSub.m) frac.m <- hepidish(beta.m = DummyBeta.m, ref1.m = centEpiFibIC.m, ref2.m = centBloodSub.m[,c(1, 2, 5)], h.CT.idx = 3, method = 'RPC') frac.m ``` -------------------------------- ### Perform hierarchical deconvolution with hepidish Source: https://context7.com/sjczheng/epidish/llms.txt Uses hepidish to resolve cell-type fractions at multiple levels by decomposing a specific cell-type from a primary reference into subtypes from a secondary reference. ```r library(EpiDISH) # Load references for hierarchical deconvolution data(centEpiFibIC.m) # Primary: Epithelial, Fibroblast, Immune Cells data(centBloodSub.m) # Secondary: 7 immune cell subtypes data(DummyBeta.m) # Sample solid tissue data # Perform hierarchical deconvolution # h.CT.idx = 3 indicates "IC" (3rd column) in primary ref maps to secondary ref frac_hierarchical <- hepidish( beta.m = DummyBeta.m, # Beta values (CpGs x samples) ref1.m = centEpiFibIC.m, # Primary reference (Epi, Fib, IC) ref2.m = centBloodSub.m, # Secondary reference (immune subtypes) h.CT.idx = 3, # Index of cell-type to decompose (IC) method = "RPC", # Method: "RPC", "CBS", or "CP" maxit = 50 ) # Result contains: Epi, Fib, and 7 immune cell subtype fractions print(frac_hierarchical) #> Epi Fib B-cells CD4T CD8T NK Mono Neutro Eosino #> Sample1 0.4521 0.2134 0.0123 0.0456 0.0234 0.0167 0.0312 0.1834 0.0219 #> Sample2 0.3892 0.2567 0.0145 0.0523 0.0289 0.0198 0.0367 0.1756 0.0263 # Using only selected immune subtypes from secondary reference frac_selected <- hepidish( beta.m = DummyBeta.m, ref1.m = centEpiFibIC.m, ref2.m = centBloodSub.m[, c("B", "NK", "Mono")], # Subset of immune cells h.CT.idx = 3, method = "RPC" ) ``` -------------------------------- ### epidish - Cell-Type Fraction Estimation Source: https://context7.com/sjczheng/epidish/llms.txt The epidish function infers cell-type fractions from a DNA methylation beta-value matrix using a reference-based approach. ```APIDOC ## epidish ### Description Infers cell-type fractions from a DNA methylation beta-value matrix using reference-based deconvolution methods (RPC, CBS, or CP). ### Parameters - **beta.m** (matrix) - Required - Beta value matrix (CpGs x samples). - **ref.m** (matrix) - Required - Reference centroids (CpGs x cell-types). - **method** (string) - Optional - Deconvolution method: "RPC" (default), "CBS", or "CP". - **maxit** (integer) - Optional - Maximum iterations for RPC method. - **nu.v** (vector) - Optional - Candidate nu values for CBS method. - **constraint** (string) - Optional - Constraint type for CP method: "inequality" (default) or "equality". ### Response - **estF** (matrix) - Estimated cell-type fractions (samples x cell-types). - **ref** (matrix) - Reference matrix subset used. - **dataREF** (matrix) - Input data subset matching reference probes. ``` -------------------------------- ### View CellDMC Results Source: https://github.com/sjczheng/epidish/blob/devel/README.md Display the head of the DMCT prediction results. ```R head(celldmc.o$dmct) ``` -------------------------------- ### Identify Differentially Methylated Cell-Types with CellDMC Source: https://github.com/sjczheng/epidish/blob/devel/README.md Run CellDMC using a phenotype vector and previously estimated cell-type fractions. ```R pheno.v <- rep(c(0, 1), each = 5) celldmc.o <- CellDMC(DummyBeta.m, pheno.v, frac.m) ``` -------------------------------- ### hepidish - Hierarchical Cell-Type Deconvolution Source: https://context7.com/sjczheng/epidish/llms.txt The hepidish function performs hierarchical deconvolution to estimate cell-type fractions at multiple levels of resolution. ```APIDOC ## hepidish ### Description Implements hierarchical EpiDISH for multi-level cell-type resolution, using a primary reference for broad estimation and a secondary reference to decompose specific cell-types. ### Parameters - **beta.m** (matrix) - Required - Beta values (CpGs x samples). - **ref1.m** (matrix) - Required - Primary reference matrix. - **ref2.m** (matrix) - Required - Secondary reference matrix for sub-decomposition. - **h.CT.idx** (integer) - Required - Index of the cell-type in the primary reference to be decomposed by the secondary reference. - **method** (string) - Optional - Deconvolution method: "RPC", "CBS", or "CP". - **maxit** (integer) - Optional - Maximum iterations for RPC method. ### Response - **fractions** (matrix) - Combined matrix of primary and decomposed cell-type fractions. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.