Package 'chromosomix'

Title: Explore Hi-C Contact Maps and Genome Tracks in the chromosomix Viewer
Description: The chromosomix viewer (<https://chromosomix.app/>) draws a contact map with the tracks beside it, a 1D genome browser or a 3D model of a genome, and this package puts it in an R session: at the console, on an R Markdown or Quarto page, and in a Shiny app. A view is described with the classes Bioconductor already uses for the same things - a map named by a path, an address or a HiCExperiment CoolFile, a block as a GRanges or a GInteractions, tracks as rtracklayer and Rsamtools files or as GRanges, GInteractions and coverage held in memory - and it is read back the same way: the contacts on screen into a HiCExperiment, the reader's place into a GRanges, the app's saved workspaces into views with their bookmarks and marks. The viewer itself is the app's own embed in an <iframe>; files on this machine are served to it by byte range from the R session, and nothing is uploaded.
Authors: Jacques Serizay [aut, cre]
Maintainer: Jacques Serizay <[email protected]>
License: GPL (>= 3)
Version: 0.99.0
Built: 2026-12-06 14:55:41 UTC
Source: https://github.com/js2264/chromosomix

Help Index


Bookmarks and marks

Description

Two things a reader of the viewer keeps with a map, which a view carries as Bioconductor objects:

Usage

bookmarks(x)

bookmarks(x) <- value

marks(x)

marks(x) <- value

## S4 method for signature 'ChromosomixView'
bookmarks(x)

## S4 replacement method for signature 'ChromosomixView'
bookmarks(x) <- value

## S4 method for signature 'ChromosomixView'
marks(x)

## S4 replacement method for signature 'ChromosomixView'
marks(x) <- value

Arguments

x

A ChromosomixView.

value

A GRanges of places (⁠bookmarks<-⁠), or a GInteractions of marks (⁠marks<-⁠); a GRanges given as marks is a box on the diagonal per range. NULL empties either.

Details

  • bookmarks, the places listed in the viewer's Bookmarks card, are a GRanges with a label column and a resolution one - the bin size the map was at when the place was kept, or NA;

  • marks, drawn on the map, are a GInteractions of one pair of anchors per mark, with a kind column: an "arrowhead" points at the pixel of its two anchors - a loop, off the diagonal; a "rect" is a box over the block of its two anchors - a domain on the diagonal, the contacts of two loci off it; a "line" draws guide lines through the base of its first anchor, axis saying which ("vertical", "horizontal", "both"). colour is each mark's colour, and missing is the viewer's palette.

A view's bookmarks and marks are drawn with it, carried in the frame's address as a shared link carries a tab (SPECS §5.6); they are read from a workspace and written into one by import() and export() with a ChromosomixFile. Coordinates are counted from 1, as a GRanges counts.

Value

bookmarks(): a GRanges. marks(): a GInteractions. The setters: the view, changed.

Examples

view <- chromosomix("https://example.org/sample.mcool",
    focus = "chr2:10000001-14000000")
bookmarks(view) <- GenomicRanges::GRanges(
    c("chr2:10500001-10600000", "chr2:12000001-12100000"),
    label = c("a boundary", "a loop"))
tads <- GenomicRanges::GRanges("chr2:10000001-11000000")
marks(view) <- tads
marks(view)

The chromosomix viewer, from R

Description

chromosomix() describes a view in the chromosomix viewer - a contact map with the maps and tracks beside it, a 1D genome browser, a 3D model next to a map - as a ChromosomixView, which is drawn as the viewer itself wherever it is printed: the RStudio viewer or a browser at the console, an R Markdown or Quarto page, a Shiny app (renderChromosomix()). It is the viewer's own embed in an ⁠<iframe>⁠, with its side panels and its gestures, driven over its message channel; nothing is uploaded.

Usage

chromosomix(
  map = NULL,
  tracks = NULL,
  focus = NULL,
  locus = NULL,
  resolution = NULL,
  ...,
  window = NULL,
  bookmarks = NULL,
  marks = NULL,
  viewer = NULL,
  title = "chromosomix",
  width = "100%",
  height = 600,
  elementId = NULL
)

Arguments

map

What the view opens on: a contact map, several (a deck), a HiCExperiment, or nothing, as above.

tracks

The tracks put beside the map once it is drawn, in order: a list (named, for trackNames()) or a character vector of files and objects, as above. A map or a 3D model among them opens beside the map, a workspace as its tabs, as the viewer's + opens them.

focus

The block of the map the view reads, counted from 1: a string, a GRanges of one range or two, or a GInteractions of one pair. With no focus a map opens whole.

locus

Where a 1D browser is placed, written the same way.

resolution

The bin size to draw the map at, in base pairs: one of the file's resolutions, or a multiple of one.

...

Any other key of the view as the app's address bar carries it, one value each: transform ("log10", "log2", "log1p", "none"), colormap, balance, vmin, vmax, oe, smooth, view, .... region is focus's other name, counted from 1 too, and region2 the columns of an off-diagonal block.

window

A window inside the focus the map opens zoomed to, which the reader can pan out of to the whole focus.

bookmarks

A GRanges of places to keep beside the view, listed in the viewer's Bookmarks card; see bookmarks().

marks

A GInteractions of marks to draw on the map; see marks().

viewer

The build of the viewer in the frame; see resolve_viewer().

title

The frame's title, for a screen reader.

width, height

The widget's size: CSS units, or a number of pixels.

elementId

An id for the widget's element.

Details

What it opens on is one of:

  • a contact map, by its path or address (.cool, .mcool, .hic, .pairs, a HiC-Pro .matrix; "x.mcool::/resolutions/5000" for one resolution of a multi-resolution file), or as HiCExperiment names one - a CoolFile, McoolFile, HicFile, HicproFile or PairsFile. Several are a deck, the first the view's own and the others beside it;

  • a HiCExperiment: the file it was imported from, at its focus and its resolution, with its topological features (compartments, borders, loops, viewpoints) as tracks. The viewer draws the file's contacts and normalises them itself; a score computed in R (detrended, ratio, ...) has no file to be read from, and oe = TRUE asks the viewer for observed / expected;

  • nothing - NULL, or ranges or a track file as map - for a 1D genome browser of the tracks alone, whose first track is the tab's.

A file is a path on this machine, served to the viewer by byte range from this R session (serve()) once the view is drawn, or an address the app opens: ⁠https://⁠, ⁠s3://⁠, ⁠gs://⁠, a Dropbox or Google Drive share. A track is any of those, a BiocFile (BigWigFile, BEDFile, GFFFile, ...) or an Rsamtools file (BamFile, TabixFile), whose index goes with it - or an object of ranges this session holds: a GRanges (a BED, or a bedGraph when it has a numeric score and no name and no range overlaps another), a GRangesList (a BED12 of transcripts), a GInteractions or a Pairs of GRanges (a BEDPE, drawn on the map as arrowheads and boxes as well as beside it), or a coverage RleList (a bedGraph). Those are sent to the viewer as a file's bytes, so a knitted page carries them in itself; they need a viewer that takes files from R, from the release after 0.21.0.

Coordinates are counted as a GRanges counts: from 1, both ends included. focus = "IV:1000001-1400000" is the 400 kb from base 1,000,001 to base 1,400,000 - the string the viewer's locus box shows for it, and the one HiCExperiment's focus takes. A focus is also a GRanges of one range, or of two for an off-diagonal block - the rows, then the columns, as "II:1-100000|III:1-50000" writes it - or a GInteractions of one pair.

Value

A ChromosomixView.

See Also

chromosomix_goto() and its siblings to move a view; chromosomixOutput() for Shiny; chromosomixSession() for a view the console drives as the reader moves it; ChromosomixFile to read and write the app's workspaces.

Examples

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

## Ranges this session holds, as tracks: a GRanges and a GInteractions.
peaks <- GenomicRanges::GRanges(c("IV:1100001-1102000",
    "IV:1250001-1251000"), name = c("p1", "p2"))
loops <- InteractionSet::GInteractions(
    GenomicRanges::GRanges("IV:1100001-1105000"),
    GenomicRanges::GRanges("IV:1250001-1255000"))
view <- chromosomix_add(view, peaks = peaks, loops = loops)
trackNames(view)

## A 1D genome browser of tracks alone.
chromosomix(tracks = file.path(yeast, "Yeast_ATAC.bw"),
    locus = "IV:1000001-1100000")

Move a view, and put more in it

Description

Three requests, made of a view - and of one on screen:

Usage

chromosomix_goto(view, where, ...)

chromosomix_navigate(view, ...)

chromosomix_add(view, ...)

## S4 method for signature 'ChromosomixView'
chromosomix_goto(view, where, ...)

## S4 method for signature 'ChromosomixView'
chromosomix_navigate(view, ...)

## S4 method for signature 'ChromosomixView'
chromosomix_add(view, ...)

## S4 method for signature 'htmlwidget'
chromosomix_goto(view, where, ...)

## S4 method for signature 'htmlwidget'
chromosomix_navigate(view, ...)

## S4 method for signature 'htmlwidget'
chromosomix_add(view, ...)

## S4 method for signature 'chromosomix_proxy'
chromosomix_goto(view, where, ...)

## S4 method for signature 'chromosomix_proxy'
chromosomix_navigate(view, ...)

## S4 method for signature 'chromosomix_proxy'
chromosomix_add(view, ...)

Arguments

view

A ChromosomixView, a proxy from chromosomixProxy(), a ChromosomixSession, or the htmlwidget a view is drawn as.

where

Where to go, counted from 1: "II:100001-200000", a block "II:1-100000|III:1-50000", a GRanges of one range or two, a GInteractions of one pair.

...

chromosomix_navigate(): keys and their values, named. chromosomix_add(): files and objects, named for trackNames() where a name is given.

Details

  • chromosomix_goto() moves the view to a place: the map's block, or the 1D browser's locus when that is what the view shows;

  • chromosomix_navigate() changes any key of the view: focus (or region), locus, window and resolution as chromosomix() takes them, counted from 1, and any other key as the app's address bar spells it, one value each; NULL takes one away;

  • chromosomix_add() puts more files and objects of ranges beside the map, as chromosomix()'s tracks takes them: a track among the tracks, another map or a 3D model beside the map, a workspace's tabs.

Of a ChromosomixView, each returns the view changed - a view is a value, drawn from what it says, so chromosomix(map) |> chromosomix_goto(where) is the view drawn at where. Of a view on screen - a Shiny output, through chromosomixProxy(), or one the console drives, a ChromosomixSession - each is sent to the viewer, which makes them in the order they were made, each once the one before it is done: a locus asked for after tracks were added is the locus on those tracks. Moves in a row are laid on as one; additions never are.

Value

view, changed or with the request sent, so requests chain.

Examples

yeast <- "https://rsglab-data.s3.eu-west-3.amazonaws.com/demo/yeast"
view <- chromosomix(file.path(yeast, "Yeast_microC_G2M_1kb.cool")) |>
    chromosomix_goto("IV:1150001-1300000") |>
    chromosomix_navigate(transform = "log2", oe = TRUE) |>
    chromosomix_add(ATAC = file.path(yeast, "Yeast_ATAC.bw"))
focus(view)
trackNames(view)

A chromosomix workspace file

Description

A workspace is every tab of a window of the app in one file, ⁠<name>.chromosomix.json⁠: each tab's view, its tracks, its bookmarks and the marks drawn on its map - what the app's save button writes, and what it opens dropped on its window or from ⁠?config=<address>⁠. ChromosomixFile() names one, for BiocIO::import(), which reads it into a list of ChromosomixViews, and BiocIO::export(), which writes views as one.

Usage

ChromosomixFile(resource)

Arguments

resource

The workspace's path or address.

Details

A workspace written here opens in the app: each view is a tab, its maps and tracks named by address or by a path relative to the workspace, and the tracks an R session holds in memory written beside it as BED, bedGraph or BEDPE files. A local path is a file the app asks its reader for, as it asks for any local file a workspace names (SPECS §8.6).

Value

ChromosomixFile(): a ChromosomixFile.

See Also

import,ChromosomixFile,ANY,ANY-method and export,ChromosomixView,ChromosomixFile,ANY-method.

Examples

file <- ChromosomixFile(tempfile(fileext = ".chromosomix.json"))
file

Read and write workspaces

Description

A workspace (.chromosomix.json) is every tab of a window of the app in one file. import() reads one into a ChromosomixViewList of ChromosomixViews, one per tab; export() writes views as one, which the app opens - dropped on its window, or from ⁠?config=<address>⁠ when the workspace is published beside its data.

Usage

## S4 method for signature 'ChromosomixViewList,ChromosomixFile,ANY'
export(object, con, format, ...)

## S4 method for signature 'ChromosomixView,ChromosomixFile,ANY'
export(object, con, format, ...)

## S4 method for signature 'list,ChromosomixFile,ANY'
export(object, con, format, ...)

## S4 method for signature 'ChromosomixView,character,ANY'
export(object, con, format, ...)

## S4 method for signature 'ChromosomixViewList,character,ANY'
export(object, con, format, ...)

## S4 method for signature 'ChromosomixFile,ANY,ANY'
import(con, format, text, ...)

Arguments

object

A ChromosomixView, a ChromosomixViewList or a list of views.

con

A ChromosomixFile, or (export()) a path ending in .chromosomix.json.

format, text

Not used: the format is the file's.

...

Not used.

Details

A workspace written here names each map and track by its address, or by its path relative to the workspace; the objects of ranges a view holds are written beside it, in a directory named after it (⁠<name>_files/⁠), as BED, bedGraph, BED12 or BEDPE files, and named there. Each view is a tab, named after the list's names, with its bookmarks and its marks. A view with no map is a tab of its first track, as the app opens a track alone.

A workspace read here is read for what a view holds: each tab's maps, its view, its tracks by their addresses, its bookmarks and its marks, every coordinate counted from 1. The rest of what the app keeps in a tab - each track's colours and heights, the tables' filters, the deck's arrangement - is not read, and a workspace written back from it names its tracks afresh. A track the app had from a file dropped on its window is read where it is beside the workspace, and is otherwise left out, with a message.

Value

import(): a ChromosomixViewList. export(): the ChromosomixFile, invisibly.

Examples

yeast <- "https://rsglab-data.s3.eu-west-3.amazonaws.com/demo/yeast"
view <- chromosomix(file.path(yeast, "Yeast_microC_G2M_1kb.cool"),
    focus = "IV:1000001-1400000",
    tracks = list(ATAC = file.path(yeast, "Yeast_ATAC.bw")))
bookmarks(view) <- GenomicRanges::GRanges("IV:1100001-1150000",
    label = "a boundary")
file <- ChromosomixFile(tempfile(fileext = ".chromosomix.json"))
export(view, file)
views <- import(file)
views[[1]]
bookmarks(views[[1]])

A view in a Shiny app

Description

chromosomixOutput() and renderChromosomix() put a ChromosomixView in a Shiny app. What the viewer says comes back as inputs named after the output:

Usage

chromosomixOutput(outputId, width = "100%", height = "600px")

renderChromosomix(expr, env = parent.frame(), quoted = FALSE)

chromosomixProxy(outputId, session = shiny::getDefaultReactiveDomain())

Arguments

outputId

The output's id.

width, height

Its size, in CSS units.

expr

An expression that returns a ChromosomixView (or the htmlwidget one is drawn as).

env

The environment expr is evaluated in.

quoted

Whether expr is already quoted.

session

The Shiny session the output is in.

Details

  • ⁠input$<id>_range⁠ - where the reader is, as a GRanges counted from 1: the block of the map, rows then columns, or the 1D browser's locus; empty on the viewer's picker;

  • ⁠input$<id>_state⁠ - the viewer's whole view state, as its address bar writes it, a list, NULL on its picker; it changes as the reader moves from block to block and changes the scale;

  • ⁠input$<id>_rendered⁠ - the report of the last finished picture (what is drawn, at what resolution);

  • ⁠input$<id>_version⁠ - the viewer's version, once its frame is up;

  • ⁠input$<id>_height⁠ - the height in pixels the reader left the view at, with the grip under its frame;

  • ⁠input$<id>_notice⁠ - what the view says above a frame too old to take the tracks it was given.

chromosomixProxy() drives a view already on screen, without drawing it again: chromosomix_goto(), chromosomix_navigate() and chromosomix_add() take it in place of a view. A request through a proxy is sent once the outputs of the flush it was made in are, so a view drawn in that flush is on the page first; one that reaches the page before its view is drawn is held, and made after the view's own. Drawn again by renderChromosomix(), the view is a new frame, and only the new view's requests are made in it.

Value

chromosomixOutput(): the output's UI. renderChromosomix(): a render function. chromosomixProxy(): a proxy for the requests.

Examples

if (interactive()) {
    library(shiny)
    mcool <- system.file("extdata", "yeast_II-III.mcool",
        package = "chromosomix")
    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(mcool, focus = "II:1-400000"))
        observeEvent(input$go,
            chromosomix_goto(chromosomixProxy("view"), input$where))
        output$range <- renderPrint(input$view_range)
    }
    shinyApp(ui, server)
}

A view the console drives

Description

chromosomixSession() draws a view at the console - in the RStudio viewer, or a browser - 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, and moves the view and adds to it, in place. It is a BrowserSession for the chromosomix viewer, as rtracklayer's UCSCSession is the UCSC Genome Browser's, so browseGenome(ranges, "Chromosomix") draws ranges in it.

Usage

chromosomix_state(x)

chromosomixSession(map = NULL, ..., draw = interactive())

## S4 method for signature 'ChromosomixSession'
chromosomix_state(x)

## S4 method for signature 'ChromosomixSession'
range(x, ..., na.rm = FALSE)

## S4 method for signature 'ChromosomixSession'
focus(x)

## S4 method for signature 'ChromosomixSession'
resolution(x)

## S4 method for signature 'ChromosomixSession'
fileName(object, ...)

## S4 method for signature 'ChromosomixSession,ANY,ANY'
import(con, format, text, ...)

## S4 method for signature 'ChromosomixSession'
show(object)

## S4 method for signature 'ChromosomixSession'
chromosomix_goto(view, where, ...)

## S4 method for signature 'ChromosomixSession'
chromosomix_navigate(view, ...)

## S4 method for signature 'ChromosomixSession'
chromosomix_add(view, ...)

## S4 replacement method for signature 'ChromosomixSession,ANY'
track(object, name = deparse(substitute(value)), ...) <- value

## S4 method for signature 'ChromosomixSession'
track(object, name, ...)

## S4 method for signature 'ChromosomixSession'
trackNames(object, ...)

## S4 method for signature 'ChromosomixSession'
browserView(object, range, track, ...)

## S4 method for signature 'ChromosomixSession'
browserViews(object)

## S4 method for signature 'ChromosomixSession'
activeView(object)

## S4 method for signature 'ChromosomixBrowserView'
range(x, ..., na.rm = FALSE)

## S4 method for signature 'ChromosomixSession'
close(con, ...)

Arguments

x, object, con, view

A ChromosomixSession.

map, ...

What the view opens on and everything else, as chromosomix() takes them; or a ChromosomixView, drawn as it is.

draw

Whether to draw the session now: at an interactive console, by default. One not drawn is drawn by browserView().

na.rm

Not used.

format, text

Not used.

where

Where to go, counted from 1, as chromosomix_goto() takes it.

name

A track's name.

value

A track to add: a file or an object of ranges, as chromosomix()'s tracks takes them.

range

Where to go: a GRanges, a string, a GInteractions, as chromosomix_goto() takes them. The first range of several.

track

Not used: every track the session has is drawn.

Details

What the page says reaches R while R is idle, as it does in Shiny:

  • range() is where the reader is - the block of the map, rows then columns, or the 1D browser's locus - as a GRanges, counted from 1; focus() is the block as a focus string, and resolution() the bin size of the map on screen;

  • chromosomix_state() is the viewer's whole view state, as its address bar writes it, and NULL before the page has said it;

  • import() reads the contacts on screen - the block, at the bin size drawn - into a HiCExperiment::HiCExperiment, from a map on this machine; as(session, "ChromosomixView") is the view on screen, to draw again, save with export() or keep.

And what R asks of it is made on every page the session is drawn on, in order: chromosomix_goto(), chromosomix_navigate() and chromosomix_add(), as of a view; browserView(session, range) and track(session, name) <- ranges, as rtracklayer asks a browser; and browserView(session) draws the session again, on a page of its own. close() ends it.

browserSession("Chromosomix", map, ...) makes a session as rtracklayer makes one, not yet drawn: browserView() draws it. So does browseGenome(ranges, "Chromosomix"), which draws the ranges, as a track, where they are; browserView(session, range) moves it after. as(session, "htmlwidget") is the session's page as a widget, for a page of one's own (htmlwidgets::saveWidget()): opened while this R session runs, it connects, and is sent every request made of the session.

The viewer leaves pan and zoom out of its state, as it leaves them out of its address bar: range() of a map is its block, the part read whole, which the reader moves by the locus box, the overview or a bookmark.

Value

chromosomixSession(): a ChromosomixSession. browserView() and activeView(): a ChromosomixBrowserView, which says where it is with range(); browserViews(), a list of them. The others: as their generics say.

See Also

chromosomix() for a view drawn once, as it is; import() and HiCExperiment::HiCExperiment for the contacts it reads.

Examples

mcool <- system.file("extdata", "yeast_II-III.mcool",
    package = "chromosomix")

## A session not drawn: until a page says where its reader is, it is
## where it was opened, and what R asks of it is kept for the page.
session <- chromosomixSession(mcool, focus = "II:1-400000", draw = FALSE)
range(session)
chromosomix_goto(session, "III:1-200000")
close(session)

if (interactive()) {
    session <- chromosomixSession(mcool, focus = "II:1-400000")
    ## ... the reader moves the view, then:
    range(session)
    hic <- import(session)
    chromosomix_goto(session, "III:1-200000")

    ## Ranges in the viewer, as rtracklayer draws them in UCSC's.
    peaks <- GenomicRanges::GRanges(c("II:120001-121000",
        "II:250001-251000"))
    browseGenome(peaks, "Chromosomix")
}

Read and change a view

Description

A ChromosomixView is read and changed with the generics a Bioconductor user already knows, each returning a changed copy, as values are changed in R:

Usage

## S4 method for signature 'ChromosomixView'
fileName(object, ...)

## S4 method for signature 'ChromosomixView'
focus(x)

## S4 replacement method for signature 'ChromosomixView,ANY'
focus(x) <- value

## S4 method for signature 'ChromosomixView,ANY'
refocus(x, focus)

## S4 method for signature 'ChromosomixView'
resolution(x)

## S4 method for signature 'ChromosomixView,ANY'
zoom(x, resolution)

## S4 method for signature 'ChromosomixView'
resolutions(x)

## S4 method for signature 'ChromosomixView'
range(x, ..., na.rm = FALSE)

## S4 replacement method for signature 'ChromosomixView'
range(x, ...) <- value

## S4 method for signature 'ChromosomixView'
trackNames(object, ...)

## S4 method for signature 'ChromosomixView'
track(object, name, ...)

## S4 replacement method for signature 'ChromosomixView,ANY'
track(object, name, ...) <- value

Arguments

...

Not used.

x, object

A ChromosomixView.

value, focus

The new value.

resolution

A bin size, in base pairs.

na.rm

Not used.

name

A track's name.

Details

  • fileName() - the path or address of the view's own map, as given;

  • focus() and ⁠focus<-⁠, refocus() - the block of the map the view reads, as HiCExperiment writes a focus, counted from 1: "II:1-100000", or "II:1-100000|III:1-50000" for an off-diagonal block, rows then columns; NULL for the whole map. A new focus drops a window inside the old one;

  • resolution() and zoom() - the bin size the map is drawn at, in base pairs; resolutions() - the ones its file holds, read from it where it is on this machine;

  • range() and ⁠range<-⁠ - what the view shows as a GRanges: the 1D browser's locus, or the focus's rows and its columns;

  • trackNames(), track() and ⁠track<-⁠ - the tracks, by name; a value of NULL takes one away;

  • bookmarks() and marks();

  • metadata() - a list kept beside the view, as any S4Vectors::Annotated object keeps one.

Value

The getters: the value. The setters, refocus() and zoom(): the view, changed.

Examples

view <- chromosomix("https://example.org/sample.mcool",
    focus = "chr2:10000001-14000000")
focus(view)
view <- refocus(view, "chr2:11000001-12000000|chr3:1-1000000")
range(view)
view <- zoom(view, 10000)
resolution(view)
track(view, "peaks") <- GenomicRanges::GRanges("chr2:11500001-11501000")
trackNames(view)

A view in the chromosomix viewer

Description

A ChromosomixView is what chromosomix() makes: a description of what the viewer shows - a contact map and the maps beside it, the block of it to read, the tracks next to it, a 1D browser's locus, the scale and the colours

  • which is drawn as the viewer itself wherever it is printed: in the RStudio viewer or a browser at the console, on an R Markdown or Quarto page, in a Shiny app (renderChromosomix()). Describing a view reads no file and opens no port; drawing it does.

Usage

## S4 method for signature 'ChromosomixView'
show(object)

Arguments

object

A ChromosomixView.

Details

It extends S4Vectors::Annotated, so S4Vectors::metadata() holds whatever a user wants to keep beside it, and its parts are read and changed with the generics a Bioconductor user knows - HiCExperiment's HiCExperiment::focus(), HiCExperiment::refocus(), HiCExperiment::resolution() and HiCExperiment::zoom(), rtracklayer's rtracklayer::track() and rtracklayer::trackNames(), BiocGenerics' BiocGenerics::fileName() and base::range() - and with bookmarks() and marks(). BiocIO::import() of a view reads the contacts it shows into a HiCExperiment, and BiocIO::export() writes it as a workspace the app opens (ChromosomixFile).

Every coordinate is counted as a GRanges counts, from 1 with both ends included: "IV:1000001-1400000" is the 400 kb that starts at base 1,000,001, as the viewer's locus box writes it.

as(view, "htmlwidget") is the view as the htmlwidget it is drawn as, for what takes one: htmlwidgets::saveWidget(), htmltools::tagList().

Value

show() prints what the view shows - and, in an interactive session, draws it - and returns the view, invisibly. as(view, "htmlwidget"): the htmlwidget the view is drawn as.

Slots

maps

A S4Vectors::SimpleList of the maps the view opens: the first is the view's own, and the others are the deck beside it. Each is a path or an address, or a BiocFile.

tracks

A named S4Vectors::SimpleList of the tracks beside the map, in order: files, and objects of ranges sent as bytes.

focus

The block of the map the view reads, as HiCExperiment writes a focus - "II:1-100000", or "II:1-100000|III:1-50000" for an off-diagonal block, rows then columns - or empty for the whole map.

window

A window inside the focus the map opens zoomed to, which the reader can pan out of, or empty.

locus

The 1D browser's window, or empty.

resolution

The bin size the map is drawn at, in base pairs, or empty.

keys

The other keys of the view, as the app's address bar spells them: transform, colormap, balance, oe, view, ....

bookmarks

A GRanges of places kept beside the view, with columns label and resolution.

marks

A GInteractions of marks drawn on the map: arrowheads at a pixel, rectangles over a block and guide lines, as column kind says.

viewer

The build of the viewer in the frame; see resolve_viewer().

options

The widget's title, width, height and elementId.

See Also

chromosomix(), which makes one.

Examples

view <- chromosomix("https://example.org/sample.mcool",
    focus = "chr2:10000001-14000000", resolution = 5000)
view
focus(view)
range(view)

Views, together

Description

A ChromosomixViewList is a list of ChromosomixViews - the tabs of a workspace, as import() reads one from a ChromosomixFile and export() writes one. Its names are the tabs' names, and its S4Vectors::metadata() says, for one read from a file, when the file was written (createdAt), by what (producer) and which tab was in front (active).

Usage

ChromosomixViewList(...)

Arguments

...

ChromosomixViews, or one list of them.

Value

A ChromosomixViewList.

Examples

views <- ChromosomixViewList(
    whole = chromosomix("https://example.org/sample.mcool"),
    chr2 = chromosomix("https://example.org/sample.mcool",
        focus = "chr2:10000001-14000000"))
names(views)

Read the contacts a view shows

Description

import() of a ChromosomixView reads the block of its map the view reads - its focus(), at its resolution() - into a HiCExperiment::HiCExperiment, as HiCExperiment::import() reads a .cool, an .mcool, a .hic or a HiC-Pro matrix: what the viewer shows, to work on in R. A view with no focus reads the whole map, and one with no resolution reads the file's first, or the one its address names ("x.mcool::/resolutions/5000").

Usage

## S4 method for signature 'ChromosomixView,ANY,ANY'
import(con, format, text, ...)

Arguments

con

A ChromosomixView, or a ChromosomixSession: the view the reader is looking at.

format, text

Not used.

...

Passed to HiCExperiment's import(): metadata, pairsFile, ....

Details

The map is read where it is, on this machine; one named by an address is read by the viewer, not here. A resolution the view draws by adding up a file's bins - a multiple of one of its resolutions - is read at the file's resolution nearest it that it is a multiple of, with a message.

Value

A HiCExperiment::HiCExperiment.

Examples

mcool <- system.file("extdata", "yeast_II-III.mcool",
    package = "chromosomix")
view <- chromosomix(mcool, focus = "II:100001-300000", resolution = 4000)
hic <- import(view)
hic

## The view's block, at a resolution it adds the file's bins up to.
import(zoom(view, 8000))

Which build of the viewer a view frames

Description

A view is drawn as the viewer's own embed in an ⁠<iframe>⁠, and viewer names the build in it:

Usage

resolve_viewer(viewer = NULL)

installed_viewers()

install_viewer(version = "latest")

Arguments

viewer

NULL, a version, an address or a directory, as above.

version

The npm version to fetch, or "latest".

Details

  • NULL - the option chromosomix.viewer where it is set, then the environment variable CHROMOSOMIX_VIEWER, then the newest build install_viewer() fetched, and the site, https://chromosomix.app/, where there is none of them. While a page is knitted, the build install_viewer() fetched is named by the release's permanent address on the site instead of being served: the page is read after the render's R session has ended, and its server with it;

  • a version, "0.21.0" or "v0.21.0" - the release the site keeps for ever at ⁠/v/<tag>/⁠, which is what a document that must draw the same picture next year names;

  • an address - any ⁠http(s)://⁠ build, a lab's own copy of the npm package's ⁠dist/⁠ among them;

  • a directory - a built ⁠dist/⁠ on this machine, served beside the data (serve()), so the app and the files are one origin and nothing is fetched from the network.

install_viewer() fetches the npm package chromosomix once - the app built to run from any path - and keeps it in the user's cache directory (tools::R_user_dir(), or CHROMOSOMIX_CACHE); every view after uses it. With files on this machine that is the build to prefer: the site reading ⁠http://127.0.0.1⁠ works too, but Chrome asks the reader once to let the page reach this machine. The tarball is checked against the sha512 npm gives for it (dist.integrity) where the openssl package is installed - base R has no sha512 - and put in place whole: unpacked apart, copied beside its place and renamed into it, so a download or a copy cut short leaves nothing a view would frame.

A viewer from 0.17.0 on takes the tracks a view puts beside its map; one from 0.22.0 on takes the objects of ranges an R session holds as well.

Value

resolve_viewer(): the build's address, ending in /. install_viewer(): the build's directory. installed_viewers(): the directories of every build fetched, the newest version last.

Examples

resolve_viewer("0.21.0")
resolve_viewer("https://lab.example/viewer")
installed_viewers()

Serve a file on this machine to the viewer

Description

serve() gives a local file an address the viewer can read by byte range: a server on ⁠127.0.0.1⁠ in this R session, started on first use, serving the directory the file is named in under a random token so its sidecars (.bai, .fai, .tbi, .px2) are read from beside it. Nothing outside that directory is served but what a link in it points to - a DataLad or git-annex file is such a link, and its sidecars are read from beside the link - and no name that starts with a dot. address() is what a view calls on a file when it is drawn: an address (⁠https://⁠, ⁠s3://⁠, ⁠gs://⁠, a Dropbox or Google Drive share) is kept as it is, and a local path is served.

Usage

serve(file)

address(file)

Arguments

file

A path on this machine. With address(), an address or a path; a :: after a container's path names a group inside it, as in the app ("sample.mcool::/resolutions/5000"), and is kept on the served address.

Details

The server answers while R is idle - at the console, in RStudio, under Shiny. A rendered R Markdown or Quarto page that names local files draws them only while the R session that rendered it is running, and a Knit or ⁠quarto render⁠ session ends as soon as the page is written: a page for others names its files by address. Knitting, the first local file served says so in a warning, once a session.

Behind RStudio Server the server is reached through RStudio's proxy (with the rstudioapi package installed); CHROMOSOMIX_PUBLIC_URL, with {port} where the port goes, names any other way in. There only a viewer this session serves - install_viewer()'s, or a built ⁠dist/⁠ - reads local files: RStudio's proxy asks for its login, which the public site's requests to it do not carry.

Value

The address, a string.

Examples

address("https://data.example/yeast.mcool::/resolutions/1000")
mcool <- system.file("extdata", "yeast_II-III.mcool",
    package = "chromosomix")
address(paste0(mcool, "::/resolutions/4000"))