Contact maps and genome tracks with chromosomix

Introduction

chromosomix is a viewer for chromosome conformation capture (Hi-C, Micro-C) data that runs in a web browser: contact maps (.cool, .mcool, .hic, .pairs, HiC-Pro matrices) with genome tracks beside them (bigWig, BED, GTF, BAM, VCF, …), a 1D genome browser, 3D models of the genome and the analyses that go with them. It reads every file where it is, by byte range: nothing is uploaded.

The chromosomix package puts the viewer in R. It speaks Bioconductor:

  • what it shows is a ChromosomixView, a value made by chromosomix() from a path, a HiCExperiment file (CoolFile, HicFile, …) or a HiCExperiment, and read and changed with the generics HiCExperiment, rtracklayer and BiocGenerics define: focus(), refocus(), resolution(), zoom(), track(), trackNames(), fileName(), range();
  • its tracks are files - paths, addresses, BiocFiles such as BigWigFile, Rsamtools’s BamFile with its index - or the GRanges, GRangesList, GInteractions and coverage RleList an R session holds, sent to the viewer as they are;
  • every coordinate is counted as a GRanges counts them, from 1 with both ends included;
  • import() of a view reads the contacts it shows into a HiCExperiment, and export() writes views as a workspace the app opens;
  • a view is drawn wherever it is printed: in the RStudio viewer or a browser at the console, on an R Markdown or Quarto page such as this one, in a Shiny app; and a session, an rtracklayer BrowserSession, keeps a line open between the console and the view the reader moves by hand.

Installation

if (!requireNamespace("BiocManager", quietly = TRUE)) {
    install.packages("BiocManager")
}
BiocManager::install("chromosomix")
library(chromosomix)
library(GenomicRanges)
library(InteractionSet)

A view of a contact map

chromosomix() describes a view: the map it opens on, the block of it to read (focus), the tracks beside it, and any other key of the view as the app’s address bar carries one - here, the contacts on a log10 scale. This page draws the yeast demo of the app’s repository, a Micro-C map of S. cerevisiae in G2/M with ATAC-seq and the genes, from its bucket.

yeast <- "https://rsglab-data.s3.eu-west-3.amazonaws.com/demo/yeast"
map <- file.path(yeast, "Yeast_microC_G2M_1kb.cool")
view <- chromosomix(map,
    focus = "IV:1000001-1400000",
    tracks = list(ATAC = file.path(yeast, "Yeast_ATAC.bw"),
        genes = file.path(yeast, "Yeast_annotations.gtf")),
    transform = "log10",
    height = 720)
view

Printed, a view is drawn: the viewer itself, its side panels and its gestures. show() says what it holds instead, and its parts are read with the generics a Bioconductor user knows.

show(view)
#> class: ChromosomixView
#> map: https://rsglab-data.s3.eu-west-3.amazonaws.com/demo/yeast/Yeast_microC_G2M_1kb.cool
#> focus: IV:1000001-1400000
#> tracks(2): ATAC (Yeast_ATAC.bw), genes (Yeast_annotations.gtf)
#> keys(1): transform = log10
fileName(view)
#> [1] "https://rsglab-data.s3.eu-west-3.amazonaws.com/demo/yeast/Yeast_microC_G2M_1kb.cool"
focus(view)
#> [1] "IV:1000001-1400000"
range(view)
#> GRanges object with 1 range and 0 metadata columns:
#>       seqnames          ranges strand
#>          <Rle>       <IRanges>  <Rle>
#>   [1]       IV 1000001-1400000      *
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
trackNames(view)
#> [1] "ATAC"  "genes"

A view is a value: its setters and verbs return a changed copy. refocus() takes a block as HiCExperiment writes one - rows, then columns, "A|B" for an off-diagonal block - or as a GRanges of one range or two, and zoom() sets the bin size the map is drawn at.

off <- refocus(view, GRanges(c("IV:1100001-1200000", "IV:1250001-1350000")))
focus(off)
#> [1] "IV:1100001-1200000|IV:1250001-1350000"
range(off)
#> GRanges object with 2 ranges and 0 metadata columns:
#>       seqnames          ranges strand
#>          <Rle>       <IRanges>  <Rle>
#>   [1]       IV 1100001-1200000      *
#>   [2]       IV 1250001-1350000      *
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
resolution(zoom(off, 2000))
#> [1] 2000

Tracks from Bioconductor objects

A track is a file the viewer reads where it is - a path on this machine, an address, a BiocFile, a BamFile or TabixFile whose index goes with it - or ranges this session holds. A GRanges is sent as a BED, or a bedGraph when it has a numeric score and its ranges do not overlap; a GInteractions as a BEDPE, which the viewer draws on the map as well as beside it; a GRangesList as BED12 transcripts; a coverage RleList as a bedGraph. They are carried in the page, as this one carries them.

peaks <- GRanges(c("IV:1105001-1106000", "IV:1262001-1263000"),
    name = c("peak 1", "peak 2"))
anchors <- GRanges(c("IV:1103001-1108000", "IV:1260001-1265000"))
loops <- GInteractions(anchors[1], anchors[2], score = 12)
signal <- coverage(GRanges(c("IV:1100001-1180000", "IV:1150001-1300000")))
view <- chromosomix_add(view, peaks = peaks, loops = loops, depth = signal)
trackNames(view)
#> [1] "ATAC"  "genes" "peaks" "loops" "depth"

A GRanges given as the map, or a track file alone, opens the 1D genome browser instead.

chromosomix(
    tracks = list(ATAC = file.path(yeast, "Yeast_ATAC.bw"),
        Pol2 = file.path(yeast, "Yeast_ChIP_Pol2-vs-input.bw"),
        genes = file.path(yeast, "Yeast_annotations.gtf")),
    locus = "IV:400001-460000",
    height = 480)

HiCExperiment, both ways

The package carries a small .mcool: chromosomes II and III of the same Micro-C map, at 4 kb and 16 kb. A HiCExperiment imported from it is a view of its file, at its focus and its resolution, with its topological features as tracks.

mcool <- system.file("extdata", "yeast_II-III.mcool",
    package = "chromosomix")
hic <- import(HiCExperiment::CoolFile(mcool, resolution = 4000),
    focus = "II:100001-300000")
hic
#> `HiCExperiment` object with 2,656,896 contacts over 50 regions 
#> -------
#> fileName: "/tmp/Rtmp6Qayn9/Rinst135c758121de/chromosomix/extdata/yeast_II-III.mcool" 
#> focus: "II:100,001-300,000" 
#> resolutions(2): 4000 16000
#> active resolution: 4000 
#> interactions: 1270 
#> scores(2): count balanced 
#> topologicalFeatures: compartments(0) borders(0) loops(0) viewpoints(0) 
#> pairsFile: N/A 
#> metadata(0):
view <- chromosomix(hic)
show(view)
#> class: ChromosomixView
#> map: /tmp/Rtmp6Qayn9/Rinst135c758121de/chromosomix/extdata/yeast_II-III.mcool
#> focus: II:100001-300000
#> resolution: 4000
#> tracks(0):
resolutions(view)
#> [1]  4000 16000

And import() of a view reads the contacts it shows back into a HiCExperiment, at its resolution - here a block off the diagonal, at a bin size the viewer adds the file’s 4 kb bins up to.

block <- zoom(refocus(view, "II:150001-250000|III:1-100000"), 8000)
import(block)
#> The view draws bins of 8000, which yeast_II-III.mcool does not hold: read at 4000.
#> `HiCExperiment` object with 2,920 contacts over 51 regions 
#> -------
#> fileName: "/tmp/Rtmp6Qayn9/Rinst135c758121de/chromosomix/extdata/yeast_II-III.mcool" 
#> focus: "II:150001-250000|III:1-100000" 
#> resolutions(2): 4000 16000
#> active resolution: 4000 
#> interactions: 501 
#> scores(2): count balanced 
#> topologicalFeatures: compartments(0) borders(0) loops(0) viewpoints(0) 
#> pairsFile: N/A 
#> metadata(0):

Moving a view, and putting more in it

chromosomix_goto(), chromosomix_navigate() and chromosomix_add() change a view before it is drawn, as requests made in order once its frame is up: here a closer block, observed over expected on a log2 scale, and the 3D model of the genome beside the map. The same three move a view already on screen, in Shiny and at the console.

chromosomix(map, focus = "IV:1000001-1400000", transform = "log10",
    tracks = file.path(yeast, "Yeast_ATAC.bw"), height = 720) |>
    chromosomix_goto("IV:1150001-1300000") |>
    chromosomix_navigate(transform = "log2", oe = TRUE) |>
    chromosomix_add(file.path(yeast, "Yeast_structure.g3d.gz"))

Bookmarks and marks

What a reader keeps beside a map and draws on it is carried by a view too: bookmarks, the places listed in the viewer’s Bookmarks card, as a GRanges with a label; marks drawn on the map as a GInteractions with a kind - an "arrowhead" pointing at a loop, a "rect" over a domain or a block, a "line" through a base. A GRanges given as marks is a box on the diagonal per range.

domains <- GRanges(c("IV:1040001-1100000", "IV:1100001-1240000"))
view <- chromosomix(map, focus = "IV:1000001-1400000", transform = "log10",
    height = 720,
    bookmarks = GRanges("IV:1245001-1255000", label = "a boundary"),
    marks = c(GInteractions(domains, domains, kind = "rect"),
        GInteractions(anchors[1], anchors[2], kind = "arrowhead")))
marks(view)
#> GInteractions object with 3 interactions and 3 metadata columns:
#>       seqnames1         ranges1     seqnames2         ranges2 |        kind
#>           <Rle>       <IRanges>         <Rle>       <IRanges> | <character>
#>   [1]        IV 1040001-1100000 ---        IV 1040001-1100000 |        rect
#>   [2]        IV 1100001-1240000 ---        IV 1100001-1240000 |        rect
#>   [3]        IV 1103001-1108000 ---        IV 1260001-1265000 |   arrowhead
#>              axis      colour
#>       <character> <character>
#>   [1]        both     #111318
#>   [2]        both     #c0392b
#>   [3]        both     #1f5fa9
#>   -------
#>   regions: 4 ranges and 0 metadata columns
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
view

Workspaces

A workspace (.chromosomix.json) is every tab of a window of the app in one file - what its save button writes, and what it opens dropped on its window or from ?config=<address>. export() writes views as one, each a tab, the ranges they hold written beside it as BED, bedGraph and BEDPE files; import() reads one, written by the app or here, into a ChromosomixViewList.

file <- ChromosomixFile(tempfile(fileext = ".chromosomix.json"))
views <- ChromosomixViewList(
    map = chromosomix_add(view, peaks = peaks),
    browser = chromosomix(tracks = file.path(yeast, "Yeast_ATAC.bw"),
        locus = "IV:400001-460000"))
export(views, file)
back <- import(file)
back
#> ChromosomixViewList of length 2
#> names(2): map browser
bookmarks(back[["map"]])
#> GRanges object with 1 range and 2 metadata columns:
#>       seqnames          ranges strand |       label resolution
#>          <Rle>       <IRanges>  <Rle> | <character>  <numeric>
#>   [1]       IV 1245001-1255000      * |  a boundary         NA
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
trackNames(back[["map"]])
#> [1] "peaks.bed"

In a Shiny app

chromosomixOutput() and renderChromosomix() draw a view in Shiny, chromosomixProxy() moves it in place, and what the viewer says comes back as inputs: input$<id>_range, where the reader is, as a GRanges; input$<id>_state, the whole view; input$<id>_rendered, what was drawn.

library(shiny)
ui <- fluidPage(
    textInput("where", "Go to", "II:200001-400000"),
    actionButton("go", "Go"),
    chromosomixOutput("view", height = "600px"),
    verbatimTextOutput("range"))
server <- function(input, output, session) {
    output$view <- renderChromosomix(
        chromosomix(map, focus = "IV:1000001-1400000"))
    observeEvent(input$go,
        chromosomix_goto(chromosomixProxy("view"), input$where))
    output$range <- renderPrint(input$view_range)
}
shinyApp(ui, server)

system.file("examples", "app.R", package = "chromosomix") is a fuller app.

At the console: a session

chromosomixSession() draws a view at the console and keeps a line open to it: the reader moves the view by hand, and R reads where it is, reads the contacts on screen into a HiCExperiment, moves it and adds to it, in place. It is rtracklayer’s BrowserSession for this viewer, as UCSCSession is the UCSC Genome Browser’s.

session <- chromosomixSession(mcool, focus = "II:1-400000")
## ... the reader moves the view, then:
range(session)
hic <- import(session)
chromosomix_goto(session, "III:1-200000")
track(session, "peaks") <- GRanges("III:50001-51000")

## Ranges in the viewer, as rtracklayer draws them in UCSC's.
session <- browseGenome(peaks, "Chromosomix")
browserView(session, GRanges("IV:1100001-1300000"))
close(session)

Files on this machine, and which viewer

A path on this machine is served to the viewer by byte range from this R session, from a small server on 127.0.0.1 (serve()), its index files read from beside it. A page that names local files draws them only while the R session that drew it runs, so a page for others - a vignette, a report - names its files by address, as this one does.

The frame holds the site, https://chromosomix.app/, unless viewer (or the option chromosomix.viewer) names another build: a release such as "0.21.0", kept for ever at its own address, any address, or a built dist/ on this machine. install_viewer() fetches the app’s npm package once, so the viewer and the data are served together and work offline.

Session information

sessionInfo()
#> R version 4.6.2 (2026-10-29)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 26.04.1 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so;  LAPACK version 3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] InteractionSet_1.43.0       SummarizedExperiment_1.45.0
#>  [3] Biobase_2.75.1              MatrixGenerics_1.27.0      
#>  [5] matrixStats_1.5.0           GenomicRanges_1.67.0       
#>  [7] Seqinfo_1.5.0               IRanges_2.49.0             
#>  [9] S4Vectors_0.53.1            BiocGenerics_0.61.1        
#> [11] generics_0.1.4              chromosomix_0.99.0         
#> [13] BiocStyle_2.43.0           
#> 
#> loaded via a namespace (and not attached):
#>  [1] rjson_0.2.23             xfun_0.63                bslib_0.12.0            
#>  [4] htmlwidgets_1.6.4        rhdf5_2.59.4             lattice_0.23-1          
#>  [7] tzdb_0.5.0               bitops_1.1-0             rhdf5filters_1.27.0     
#> [10] vctrs_0.7.3              tools_4.6.2              curl_8.2.0              
#> [13] parallel_4.6.2           tibble_3.3.1             pkgconfig_2.0.3         
#> [16] BiocBaseUtils_1.17.0     Matrix_1.7-6             cigarillo_1.5.0         
#> [19] lifecycle_1.0.5          compiler_4.6.2           Rsamtools_2.31.1        
#> [22] Biostrings_2.83.1        codetools_0.2-20         htmltools_0.5.9         
#> [25] sys_3.4.3                buildtools_1.0.0         sass_0.5.0              
#> [28] RCurl_1.98-1.20          yaml_2.3.12              pillar_1.11.1           
#> [31] crayon_1.5.3             jquerylib_0.1.4          BiocParallel_1.49.0     
#> [34] DelayedArray_0.41.0      cachem_1.1.0             abind_1.4-8             
#> [37] tidyselect_1.2.1         digest_0.6.39            restfulr_0.0.17         
#> [40] dplyr_1.2.1              maketools_1.3.2          fastmap_1.2.0           
#> [43] grid_4.6.2               HiCExperiment_1.15.0     cli_3.6.6               
#> [46] SparseArray_1.15.0       magrittr_2.0.5           S4Arrays_1.15.0         
#> [49] XML_3.99-0.25            withr_3.0.3              bit64_4.8.6             
#> [52] httr_1.4.9               rmarkdown_2.32           XVector_0.55.0          
#> [55] bit_4.6.0                otel_0.3.0               evaluate_1.0.5          
#> [58] knitr_1.52               BiocIO_1.25.0            rtracklayer_1.75.0      
#> [61] rlang_1.3.0              Rcpp_1.1.2               glue_1.8.1              
#> [64] BiocManager_1.30.27      vroom_1.7.1              jsonlite_2.0.0          
#> [67] strawr_0.0.92            R6_2.6.1                 Rhdf5lib_2.3.0          
#> [70] GenomicAlignments_1.51.1