Figure 3 Dip-C

Figure 3 Dip-C highlights the geomeTriD package, illustrating its ability to visualize 3D models derived from Dip-C, along with multiple genomic signals mapped onto single-cell 3D structures.

Load Libraries

library(geomeTriD)
library(geomeTriD.documentation)
library(GenomicRanges)
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
library(org.Hs.eg.db)
library(colorRamps)

Present single cell 3D structure for human Dip-C data

This data were downloaded from GEO with accession GSE117874. We will first present the GM12878 cell 3 with all chromosomes.

## set supperloop positions
supperloops <- GRanges(c('Xa:56800000-56850000',
                         'Xa:75350000-75400000',
                         'Xa:115000000-115050000',
                         'Xa:130850000-130900000',
                         'Xb:56800000-56850000',
                         'Xb:75350000-75400000',
                         'Xb:115000000-115050000',
                         'Xb:130850000-130900000'))
names(supperloops) <- c('ICCE', 'x75', 'DXZ4', 'FIRRE',
                        'ICCE', 'x75', 'DXZ4', 'FIRRE')
supperloops$label <- names(supperloops)
supperloops$col <- c(2:5, 2:5) ## set colors for each element
supperloops$type <- 'gene' ## set it as gene

## set the data folder, all data are available in the extdata folder of this package
extdata <- system.file('extdata', 'GSE117874', package='geomeTriD.documentation')
hickit_3dg <- dir(extdata, '3dg', full.names = TRUE)
## load the data
hickit <- import3dg(hickit_3dg, parental_postfix=NULL)[[1]]
## subset sample chromosome information to avoid the tool overload
hickit <- hickit[seq_along(hickit) %in% 
                   sample.int(length(hickit), size = 5000) |
                   seqnames(hickit) %in% c('Xa', 'Xb')]
## set colors to emphersize the Xa and Xb
col.backbone <- gray.colors(n = length(seqlevels(hickit)))
names(col.backbone) <- seqlevels(hickit)
col.backbone['Xa'] <- 'brown'
col.backbone['Xb'] <- 'orange'

cell3 <- view3dStructure(hickit, feature.gr = supperloops,
                renderer = 'none', resolution=1,
                col.backbone = col.backbone, lwd.backbone = 0.25)
backbone <- extractBackbonePositions(cell3, names(cell3)[grepl('backbone', names(cell3))])
supperloop_spheres <- createTADGeometries(supperloops, backbone, alpha = 0.8)
## Warning in createTADGeometries(supperloops, backbone, alpha = 0.8): input tad
## has duplicated label. Please keep it unique.
threeJsViewer(cell3, supperloop_spheres)

We will then present the four supperloop anchors in chrX of GM12878 cell with segment and sphere style.

hickit <- import3dg(hickit_3dg, parental_postfix=c('a', 'b'))[[1]]
## split it into maternal and paternal 3D structures.
hickit.a <- hickit[hickit$parental=='a'] ## mat
hickit.b <- hickit[hickit$parental=='b'] ## pat
## delete the parental information
hickit.a$parental <- hickit.b$parental <- NULL
## set data range
range <- GRanges('X:1-155270560')
## prepare the coordinates for the four superloops. 
supperloops <- GRanges(c('X:56800000-56850000',
                      'X:75350000-75400000',
                      'X:115000000-115050000',
                      'X:130850000-130900000'))
names(supperloops) <- c('ICCE', 'x75', 'DXZ4', 'FIRRE')
supperloops$label <- names(supperloops)
supperloops$col <- 2:5 ## set colors for each element
supperloops$type <- 'gene' ## set it as gene
## subset the data by given range
hickit.a <- subsetByOverlaps(hickit.a, range)
hickit.b <- subsetByOverlaps(hickit.b, range)
hickit.a <- alignCoor(hickit.a, hickit.b)
## prepare the backbone colors
resolution <- 3
backbone_colors <- matlab.like2(n=resolution*length(hickit.a))
## add the superloops as segments
c1 <- view3dStructure(hickit.a,
                      feature.gr=supperloops,
                      renderer = 'none',
                      region = range,
                      resolution=resolution,
                      show_coor=FALSE,
                      lwd.backbone = 0.25,
                      col.backbone = backbone_colors,
                      lwd.gene=6)
c2 <- view3dStructure(hickit.b,
                      feature.gr=supperloops,
                      renderer = 'none',
                      region = range,
                      resolution=resolution,
                      show_coor=FALSE,
                      lwd.backbone = 0.25,
                      col.backbone = backbone_colors,
                      lwd.gene=6)
c2 <- lapply(c2, function(.ele) { ## put pat to right pannel
  .ele$side = 'right'
  .ele
})
## view the data
threeJsViewer(c1, c2, title = c('GM12878 cell 3 mat', 'GM12878 cell 3 pat'))
#widget <-threeJsViewer(c1, c2, title = c('mat', 'pat'))
#tempfile <- 'Fig4.html'
#htmlwidgets::saveWidget(widget, file=tempfile)
#utils::browseURL(tempfile)
## view the superloops as spheres
addFeaturesAsSphere <- function(obj, features, ...){
  backbone <- extractBackbonePositions(obj)
  spheres <- createTADGeometries(features, backbone, ...)
  c(obj, spheres)
}
mat <- view3dStructure(hickit.a, renderer = 'none', region = range,
                       resolution=resolution, show_coor=FALSE,
                       lwd.backbone = 0.25,
                       col.backbone = backbone_colors)
mat <- addFeaturesAsSphere(mat, supperloops, alpha = 0.5)
pat <- view3dStructure(hickit.b, renderer = 'none', region = range,
                       resolution=resolution, show_coor=FALSE,
                       lwd.backbone = 0.25,
                       col.backbone = backbone_colors)
mat <- addFeaturesAsSphere(mat, supperloops, alpha = 0.5)
pat <- addFeaturesAsSphere(pat, supperloops, alpha = 0.5)
showPairs(mat, pat, title = c('GM12878 cell 3 mat', 'GM12878 cell 3 pat'))

Plot all cells to show the cell heterogeneity

## load the processed data.
hickit.a <- readRDS(file.path(extdata, 'hickit.a.rds'))
hickit.b <- readRDS(file.path(extdata, 'hickit.b.rds'))
widgets <- mapply(function(a, b, i){
  mat <- view3dStructure(a, renderer = 'none', region = range,
                         resolution=resolution, show_coor=FALSE, lwd.backbone = 0.25,
                      col.backbone = backbone_colors)
  mat <- addFeaturesAsSphere(mat, supperloops, alpha = 0.5)
  pat <- view3dStructure(b, renderer = 'none', region = range,
                         resolution=resolution, show_coor=FALSE, lwd.backbone = 0.25,
                      col.backbone = backbone_colors)
  pat <- addFeaturesAsSphere(pat, supperloops, alpha = 0.5)
  showPairs(mat, pat, title = paste('cell', i, c('mat', 'pat')),
            background = c("#11111188",
                           "#222222DD",
                           "#222222DD",
                           "#11111188"))
}, hickit.a, hickit.b, names(hickit.a), SIMPLIFY = FALSE)

widgets[[1]]
widgets[[8]]

SessionInfo

## R Under development (unstable) (2025-10-13 r88918)
## Platform: aarch64-apple-darwin20
## Running under: macOS Sequoia 15.6
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.6-arm64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.6-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: America/New_York
## tzcode source: internal
## 
## attached base packages:
## [1] grid      stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] colorRamps_2.3.4                        
##  [2] org.Hs.eg.db_3.22.0                     
##  [3] TxDb.Hsapiens.UCSC.hg38.knownGene_3.22.0
##  [4] GenomicFeatures_1.61.6                  
##  [5] AnnotationDbi_1.71.2                    
##  [6] Biobase_2.69.1                          
##  [7] GenomicRanges_1.61.5                    
##  [8] Seqinfo_0.99.2                          
##  [9] IRanges_2.43.5                          
## [10] S4Vectors_0.47.4                        
## [11] BiocGenerics_0.55.4                     
## [12] generics_0.1.4                          
## [13] geomeTriD.documentation_0.0.6           
## [14] geomeTriD_1.3.19                        
## 
## loaded via a namespace (and not attached):
##   [1] strawr_0.0.92               RColorBrewer_1.1-3         
##   [3] rstudioapi_0.17.1           jsonlite_2.0.0             
##   [5] magrittr_2.0.4              farver_2.1.2               
##   [7] rmarkdown_2.30              fs_1.6.6                   
##   [9] BiocIO_1.19.0               ragg_1.5.0                 
##  [11] vctrs_0.6.5                 memoise_2.0.1              
##  [13] Rsamtools_2.25.3            RCurl_1.98-1.17            
##  [15] base64enc_0.1-3             htmltools_0.5.8.1          
##  [17] S4Arrays_1.9.1              progress_1.2.3             
##  [19] plotrix_3.8-4               curl_7.0.0                 
##  [21] Rhdf5lib_1.31.1             rhdf5_2.53.6               
##  [23] SparseArray_1.9.1           Formula_1.2-5              
##  [25] sass_0.4.10                 parallelly_1.45.1          
##  [27] bslib_0.9.0                 htmlwidgets_1.6.4          
##  [29] desc_1.4.3                  Gviz_1.53.1                
##  [31] httr2_1.2.1                 cachem_1.1.0               
##  [33] GenomicAlignments_1.45.4    igraph_2.2.0               
##  [35] lifecycle_1.0.4             pkgconfig_2.0.3            
##  [37] Matrix_1.7-4                R6_2.6.1                   
##  [39] fastmap_1.2.0               MatrixGenerics_1.21.0      
##  [41] future_1.67.0               aricode_1.0.3              
##  [43] clue_0.3-66                 digest_0.6.37              
##  [45] colorspace_2.1-2            textshaping_1.0.4          
##  [47] Hmisc_5.2-4                 RSQLite_2.4.3              
##  [49] filelock_1.0.3              progressr_0.17.0           
##  [51] httr_1.4.7                  abind_1.4-8                
##  [53] compiler_4.6.0              bit64_4.6.0-1              
##  [55] backports_1.5.0             htmlTable_2.4.3            
##  [57] S7_0.2.0                    BiocParallel_1.43.4        
##  [59] DBI_1.2.3                   R.utils_2.13.0             
##  [61] biomaRt_2.65.16             MASS_7.3-65                
##  [63] rappdirs_0.3.3              DelayedArray_0.35.3        
##  [65] rjson_0.2.23                tools_4.6.0                
##  [67] foreign_0.8-90              future.apply_1.20.0        
##  [69] nnet_7.3-20                 R.oo_1.27.1                
##  [71] glue_1.8.0                  restfulr_0.0.16            
##  [73] dbscan_1.2.3                InteractionSet_1.37.1      
##  [75] rhdf5filters_1.21.4         checkmate_2.3.3            
##  [77] cluster_2.1.8.1             gtable_0.3.6               
##  [79] BSgenome_1.77.2             trackViewer_1.45.2         
##  [81] R.methodsS3_1.8.2           ensembldb_2.33.2           
##  [83] data.table_1.17.8           hms_1.1.4                  
##  [85] XVector_0.49.1              RANN_2.6.2                 
##  [87] pillar_1.11.1               stringr_1.5.2              
##  [89] dplyr_1.1.4                 BiocFileCache_2.99.6       
##  [91] lattice_0.22-7              deldir_2.0-4               
##  [93] rtracklayer_1.69.1          bit_4.6.0                  
##  [95] biovizBase_1.57.1           tidyselect_1.2.1           
##  [97] Biostrings_2.77.2           knitr_1.50                 
##  [99] gridExtra_2.3               ProtGenerics_1.41.0        
## [101] SummarizedExperiment_1.39.2 xfun_0.53                  
## [103] matrixStats_1.5.0           stringi_1.8.7              
## [105] UCSC.utils_1.5.0            lazyeval_0.2.2             
## [107] yaml_2.3.10                 evaluate_1.0.5             
## [109] codetools_0.2-20            interp_1.1-6               
## [111] tibble_3.3.0                cli_3.6.5                  
## [113] rpart_4.1.24                systemfonts_1.3.1          
## [115] jquerylib_0.1.4             dichromat_2.0-0.1          
## [117] Rcpp_1.1.0                  GenomeInfoDb_1.45.12       
## [119] globals_0.18.0              grImport_0.9-7             
## [121] dbplyr_2.5.1                png_0.1-8                  
## [123] XML_3.99-0.19               parallel_4.6.0             
## [125] pkgdown_2.1.3               rgl_1.3.24                 
## [127] ggplot2_4.0.0               blob_1.2.4                 
## [129] prettyunits_1.2.0           jpeg_0.1-11                
## [131] latticeExtra_0.6-31         AnnotationFilter_1.33.0    
## [133] bitops_1.0-9                txdbmaker_1.5.6            
## [135] listenv_0.9.1               VariantAnnotation_1.55.2   
## [137] scales_1.4.0                crayon_1.5.3               
## [139] rlang_1.1.6                 KEGGREST_1.49.2