## ----setup, include=FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- options(width = 1000) knitr::opts_chunk$set(echo = TRUE) # Set CRAN mirror options(repos = c(CRAN = "https://cran.rstudio.com/")) # BiocManager::install("BiocStyle") library(BiocStyle) ## ----message=FALSE, warning=FALSE, eval=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # if (!requireNamespace("BiocManager", quietly = TRUE)) { # install.packages("BiocManager") # } # # BiocManager::install("scHiCcompare") # # # For the latest version install from GitHub # # devtools::install_github("dozmorovlab/scHiCcompare") ## ----message=FALSE, warning=FALSE, echo=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # devtools::install_github("dozmorovlab/scHiCcompare", force = T) ## ----message=FALSE, warning=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- library(scHiCcompare) library(HiCcompare) library(tidyr) library(ggplot2) library(gridExtra) library(lattice) library(data.table) library(mclust) ## ----echo=FALSE, out.width="100%", fig.cap="An example of how different pooling styles assign genomic distance into each band", fig.align="center"------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ knitr::include_graphics("Pooling_Example.png") ## ----echo=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- data("ODC.bandnorm_chr20_1") ## ----echo=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- names(ODC.bandnorm_chr20_1) <- c("chr1", "start1", "chr2", "start2", "IF") head(ODC.bandnorm_chr20_1) ## ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ## Load folder of ODC file path ODCs_example_path <- system.file("extdata/ODCs_example", package = "scHiCcompare" ) ## Load folder of MG file path MGs_example_path <- system.file("extdata/MGs_example", package = "scHiCcompare" ) ## ----eval=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # scHiCcompare( # file.path.1, file.path.2, # select.chromosome = "chr1", # imputation = "RF", # normalization = "LOESS", # differential.detect = "MD.cluster", # save.output.path = "results/", # ... # ) ## ----message=F, warning=FALSE, fig.cap='Chromatin differential detection between ODC and MG in chromosome 20 in example above'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ## Imputation with 'progressive' pooling result <- scHiCcompare( file.path.1 = ODCs_example_path, file.path.2 = MGs_example_path, select.chromosome = "chr20", main.Distances = 1:10000000, imputation = "RF", normalization = "LOESS", differential.detect = "MD.cluster", pool.style = "progressive", fprControl.logfc = 0.8, Plot = TRUE ) ## ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ### Summary the analysis print(result) ## ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ### Extract imputed differential result diff_result <- result$Differential_Analysis DT::datatable(head(diff_result), options = list(scrollX = TRUE), width = 700) ## ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ### Extract imputed pseudo bulk matrices normalization norm_result <- result$Intermediate$Bulk.Normalization DT::datatable(head(norm_result), options = list(scrollX = TRUE), width = 700) ## ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ### Extract imputed ODC cell type table imp_ODC_table <- result$Intermediate$Imputation$condition1 DT::datatable(head(imp_ODC_table), options = list(scrollX = TRUE), width = 700) ## ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ## Extract Pseudo-bulk matrix from imputed scHi-C data ## Pseudo bulk matrix in standard sparse format psudobulk_result <- result$Intermediate$PseudoBulk$condition1 DT::datatable(head(psudobulk_result), options = list(scrollX = TRUE), width = 700 ) ## ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- data("ODC.bandnorm_chr20_1") plot_HiCmatrix_heatmap( scHiC.sparse = ODC.bandnorm_chr20_1, main = "Figure 3. Heatmap of a single cell matrix", zlim = c(0, 5) ) ## ----message=FALSE, warning=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Extract imputed table result imp_MG_table <- result$Intermediate$Imputation$condition2 imp_ODC_table <- result$Intermediate$Imputation$condition1 ## ----echo=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- DT::datatable(imp_ODC_table, options = list(scrollX = TRUE), width = 700) ## ----message=FALSE, warning=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Create scHiC table object for original ODC interaction frequencies (IF) scHiC.table_ODC <- imp_ODC_table[c("region1", "region2", "cell", "chr")] # List all files in the specified directory for original ODC data file.names <- list.files( path = ODCs_example_path, full.names = TRUE, recursive = TRUE ) # Loop through each file to read and merge data for (i in 1:length(file.names)) { # Read the current file into a data frame data <- read.delim(file.names[[i]]) names(data) <- c("chr", "region1", "chr2", "region2", paste0("IF_", i)) data <- data[, names(data) %in% c("chr", "region1", "region2", paste0("IF_", i))] # Merge the newly read data with the existing scHiC.table_ODC scHiC.table_ODC <- merge(scHiC.table_ODC, data, by = c("region1", "region2", "chr"), all = TRUE ) } # Create scHiC table object for original MG interaction frequencies (IF) scHiC.table_MG <- imp_MG_table[c("region1", "region2", "cell", "chr")] # List all files in the specified directory for original MG data file.names <- list.files( path = MGs_example_path, full.names = TRUE, recursive = TRUE ) # Loop through each file to read and merge data for (i in 1:length(file.names)) { # Read the current file into a data frame data <- read.delim(file.names[[i]]) names(data) <- c("chr", "region1", "chr2", "region2", paste0("IF_", i)) data <- data[, names(data) %in% c("chr", "region1", "region2", paste0("IF_", i))] # Merge the newly read data with the existing scHiC.table_MG scHiC.table_MG <- merge(scHiC.table_MG, data, by = c("region1", "region2", "chr"), all = TRUE ) } ## ----message=FALSE, warning=FALSE, , fig.cap='Distribution diagnostic plot of imputed MG cells in some genomic distance'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # plot imputed Distance Diagnostic of MG plot1 <- plot_imputed_distance_diagnostic( raw_sc_data = scHiC.table_MG, imp_sc_data = imp_MG_table, D = 1 ) plot2 <- plot_imputed_distance_diagnostic( raw_sc_data = scHiC.table_MG, imp_sc_data = imp_MG_table, D = 2 ) plot3 <- plot_imputed_distance_diagnostic( raw_sc_data = scHiC.table_MG, imp_sc_data = imp_MG_table, D = 3 ) plot4 <- plot_imputed_distance_diagnostic( raw_sc_data = scHiC.table_MG, imp_sc_data = imp_MG_table, D = 4 ) gridExtra::grid.arrange(plot1, plot2, plot3, plot4, ncol = 2, nrow = 2) ## ----eval=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # if (!requireNamespace("BiocManager", quietly = TRUE)) { # install.packages("BiocManager") # } # # BiocManager::install("GEOquery") ## ----eval=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # library(GEOquery) # # For example, we want to download (Flyamer et al.2017) data # geo_id <- "GSE80006" # # Download the information, notation, feature data, etc # gse <- getGEO(geo_id, GSEMatrix = TRUE) # # You can read more about this function # ?getGEO() # # # Download and extract the supplementary files (processed data) # getGEOSuppFiles(geo_id, baseDir = "path/to/save") ## ----eval=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # install.packages(c("ggplot2", "dplyr", "data.table", "Rtsne", "umap")) # # if (!requireNamespace("BiocManager", quietly = TRUE)) { # install.packages("BiocManager") # } # # BiocManager::install("immunogenomics/harmony") # # devtools::install_github("sshen82/BandNorm", build_vignettes = FALSE) # # library(BandNorm) ## ----eval=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # ### Download scHiC data of ODC and MG # download_schic("Lee2019", cell_type = "ODC", cell_path = "ODCs_example") # download_schic("Lee2019", cell_type = "MG", cell_path = "MGs_example") ## ----eval=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # if (!requireNamespace("BiocManager", quietly = TRUE)) { # install.packages("BiocManager") # } # # BiocManager::install("strawr") ## ----eval=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # library(strawr) # # # Example to read the contact matrix from a .hic file of a single-cell # filepath <- "path/to/your/schic.hic" # # contact_matrix <- straw( # norm = "NONE", # Normalization method (KR, VC, or NONE) # filepath, # Path to .hic file # chr1loc = "chr1", # Chromosome 1 # chr2loc = "chr1", # Chromosome 2 (intra-chromosomal interactions) # unit = "BP", # Base pair (BP) resolution or fragment (FRAG) resolution # binsize = 200000 # Bin size (e.g., 200kb) # ) ## ----eval=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # # Install BiocManager if not already installed # if (!requireNamespace("BiocManager", quietly = TRUE)) { # install.packages("BiocManager") # } # # # Install HiCcompare package from Bioconductor # BiocManager::install("HiCcompare") # # # Load the HiCcompare package # library(HiCcompare) ## ----eval=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # cool.file <- read_files("path/to/schic.cool") ## ----echo=FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- sessionInfo()