### Basic Track Visualization Example Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Demonstrates the fundamental usage of trackViewer for visualizing a single genomic track. This serves as a starting point for most use cases. ```R library(trackViewer) # Example: Visualize a BED file file_path <- "path/to/your/data.bed" track_data <- importScore(file_path) viewTracks(trackList = list(track_data)) ``` -------------------------------- ### Install trackViewer via BiocManager Source: https://github.com/jianhong/trackviewer/blob/devel/README.md Use this command to install the package from Bioconductor within an R session. ```r library(BiocManager) BiocManager::install("trackViewer") ``` -------------------------------- ### Create and modify a track from imported data Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Shows how to create a track object by importing data from a BED file, then modify its style and x-scale parameters. Includes an example of clearing the track's data. ```r # Create a track from imported data fox2 <- importScore(file.path(extdata, "fox2.bed"), format="BED") # Modify track style setTrackStyleParam(fox2, "color", c("red", "green")) setTrackStyleParam(fox2, "tracktype", "peak") # Set x-scale parameters setTrackXscaleParam(fox2, "gp", list(cex=0.5)) # Clear data fox2$dat <- GRanges(score=numeric(0)) ``` -------------------------------- ### Track X-Scale Parameter Modification Example Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Demonstrates how to modify x-scale parameters for a track object using `setTrackXscaleParam`. ```APIDOC ## Modifying Track X-Scale Parameters ### Description Use `setTrackXscaleParam` to adjust x-scale related parameters of a track. ### Method `setTrackXscaleParam(track, attr, value)` ### Parameters - **track** (track): The track object. - **attr** (character): The x-scale attribute to change (e.g., "gp"). - **value** (list): The new value for the x-scale attribute. ### Example ```r # Set x-scale parameters setTrackXscaleParam(fox2, "gp", list(cex=0.5)) ``` ``` -------------------------------- ### ideogramPlot Parameter List Example Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/configuration.md An example of a parameter list for ideogramPlot, demonstrating options for plot viewport, track heights, labels, and data display types. Configure this list to customize the appearance and data representation in ideogram plots. ```r parameterList = list( vp = plotViewport(margins=c(.1, 4.1, .3, .1)), ideoHeight = unit(1/(1+n_datasets), "npc"), vgap = unit(.3, "lines"), ylabs = "auto", ylabsRot = 0, ylabsPos = unit(2.5, "lines"), xaxis = FALSE, yaxis = FALSE, xlab = "", types = "barplot", # or "line", "point", "heatmap" heights = NULL, dataColumn = "score", gps = gpar(col="black", fill="gray") ) ``` -------------------------------- ### Track Style Modification Example Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Demonstrates how to modify the visual style of a track object using `setTrackStyleParam`. ```APIDOC ## Modifying Track Style ### Description Use `setTrackStyleParam` to adjust visual attributes of a track. ### Method `setTrackStyleParam(track, attr, value)` ### Parameters - **track** (track): The track object to modify. - **attr** (character): The style attribute to change (e.g., "color", "tracktype"). - **value** (any): The new value for the style attribute. ### Example ```r # Create a track from imported data fox2 <- importScore(file.path(extdata, "fox2.bed"), format="BED") # Modify track style setTrackStyleParam(fox2, "color", c("red", "green")) setTrackStyleParam(fox2, "tracktype", "peak") ``` ``` -------------------------------- ### Chromosome Navigation Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Provides examples of how to navigate between chromosomes or specific genomic locations. Functions like getLocation are useful for this purpose. ```R library(trackViewer) # Example: Navigate to a specific location # Assuming a trackList is already defined viewTracks(trackList = myTrackList, genome = "hg19", location = "chr1:100000-200000") # Or using getLocation to get coordinates coords <- getLocation(genome = "hg19", chr = "chr1", pos = 150000) print(coords) ``` -------------------------------- ### Launch Interactive Track Browser Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/README.md Create tracks as usual and then launch an interactive web browser session using browseTracks with specified dimensions. ```r # Create tracks as before tracks <- trackList(...) # Launch interactive browser browseTracks(tracks, gr=region, width=800, height=600) ``` -------------------------------- ### Initialize trackStyle Object Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/configuration.md Constructs a new trackStyle object with default or specified parameters. Use this to define the visual appearance of a track. ```r new("trackStyle", tracktype="peak", color=c("black", "black"), NAcolor="white", breaks=0, height=NA, marginTop=0, marginBottom=0.05, xscale=new("xscale"), yaxis=new("yaxisStyle"), ylim=NA, ylabpos="left", ylablas=0, ylabgp=list(), ysplit=0.5) ``` -------------------------------- ### Save Track Visualizations to Files (R) Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/common-patterns.md Demonstrates saving track visualizations to PDF, PNG, SVG, and interactive HTML formats. Ensure necessary libraries are loaded. ```r library(trackViewer) track <- importScore("data.bw", format="BigWig") gr <- GRanges("chr1", IRanges(1e6, 2e6)) # Save as PDF pdf("tracks.pdf", width=10, height=6) viewTracks(trackList(track), gr=gr) dev.off() # Save as PNG png("tracks.png", width=800, height=400) viewTracks(trackList(track), gr=gr) dev.off() # Save as SVG svg("tracks.svg", width=10, height=6) viewTracks(trackList(track), gr=gr) dev.off() # Interactive widget to HTML library(htmlwidgets) widget <- browseTracks(trackList(track), gr=gr) saveWidget(widget, "tracks.html") ``` -------------------------------- ### Setting Xscale Graphics Parameters Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/types.md Illustrates how to set graphical parameters for an xscale object, such as line color, width, text size, and font style. ```r xscale$gp <- list( col="black", # Line color lwd=1, # Line width cex=1, # Text size fontface="plain" # Font style ) ``` -------------------------------- ### xscale Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Defines x-scale visualization on tracks, including start and end positions, labels, graphics parameters, and drawing options. ```APIDOC ## xscale ### Description Defines x-scale visualization on tracks. ### Slots - **from** (pos) - Start position. - **to** (pos) - End position. - **label** (character) - Scale label. - **gp** (list) - Graphics parameters. - **draw** (logical) - Whether to draw the scale. ### Methods - `setTrackXscaleParam(track, param, value)` — Modify x-scale parameters. ``` -------------------------------- ### Creating a Position Object Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Shows how to construct a 'pos' object, which represents a point location with x, y coordinates and a specified unit system. ```r pos(x=100, y=0.5, unit="native") ``` -------------------------------- ### Get Sequence Levels with seqlevels() Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/s4-methods-reference.md Retrieve chromosome or sequence names from a track or trackList object. For trackList, it returns the seqlevels from the first track. ```r chrs <- seqlevels(track) # c("chr1", "chr2", "chr3", ...) chrs_list <- seqlevels(trackList) # Returns seqlevels from first track ``` -------------------------------- ### Create custom trackStyle Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Initializes a trackStyle object with specific visual parameters like track type, colors, and height. Requires the 'new' function. ```r # Create custom style style <- new("trackStyle", tracktype="histogram", color=c("red", "blue"), height=0.3, ylim=c(0, 100)) ``` -------------------------------- ### Get Giemsa Stain Colors Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-utilities.md Retrieves the standard Giemsa stain color scheme used for ideograms. This can be used to customize ideogram plotting. ```r colors <- gieStain() # Use in ideogramPlot ideogramPlot(ideo, dataList, colorSheme=gieStain()) ``` -------------------------------- ### Comprehensive trackViewer Usage Pattern Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Illustrates a complete workflow for using the trackViewer package, from importing data and customizing track styles to plotting tracks with viewer-specific styles. ```r library(trackViewer) # 1. Create tracks from data track1 <- importScore("data1.bed", format="BED") track2 <- importScore("data2.bw", format="BigWig") # 2. Customize track styles setTrackStyleParam(track1, "color", c("red", "darkred")) setTrackStyleParam(track1, "tracktype", "histogram") setTrackYaxisParam(track1, "label", TRUE) # 3. Create track list with heights tracks <- trackList(track1=track1, track2=track2, heightDist=c(2, 1)) # 4. Create viewer style viewer_style <- trackViewerStyle(margin=c(.05, .1, .02, 0), xaxis=TRUE) # 5. Plot tracks gr <- GRanges("chr1", IRanges(1000000, 2000000)) viewTracks(tracks, gr=gr, viewerStyle=viewer_style, autoOptimizeStyle=TRUE) ``` -------------------------------- ### Add Gene Annotations to Tracks Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/README.md Incorporate gene annotations into your tracks using a TxDb object. This example uses known human genes (hg19). ```r library(TxDb.Hsapiens.UCSC.hg19.knownGene) olds <- c("3312", "390259") tracks <- geneTrack(ids, TxDb.Hsapiens.UCSC.hg19.knownGene) ``` -------------------------------- ### Get Sequence Level Style with seqlevelsStyle() Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/s4-methods-reference.md Determine the naming style of chromosome names (e.g., 'UCSC', 'Ensembl'). This is useful for understanding how sequence identifiers are formatted. ```r style <- seqlevelsStyle(track) # "UCSC" ``` -------------------------------- ### Create nested trackList Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Demonstrates creating a hierarchical trackList by nesting one trackList within another. This allows for grouping of tracks. ```r # Nested structure tl <- trackList(trackList(tr1, tr2), tr3) ``` -------------------------------- ### List Chromosomes and Navigate Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/common-patterns.md Import a BigWig track, list all available chromosomes, and then plot data for the first few chromosomes. Use `Sys.sleep` to pause between plots. ```r library(trackViewer) # Import track track <- importScore("data.bw", format="BigWig") # Get all chromosomes chroms <- listChromosomes(track) print(chroms) # c("chr1", "chr2", ..., "chrX", "chrY") # Get location of specific position # (useful for finding genes, peaks, etc.) loc <- getLocation(track, pos=1000) # Plot different regions for(chrom in chroms[1:5]) { # First 5 chromosomes gr <- GRanges(chrom, IRanges(1e6, 2e6)) viewTracks(trackList(track), gr=gr) Sys.sleep(1) # Pause between plots } ``` -------------------------------- ### setTrackXscaleParam Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/s4-methods-reference.md Modifies an x-scale attribute of a track. This function allows customization of the track's horizontal scale, including its start and end positions, label, and graphical parameters. ```APIDOC ## setTrackXscaleParam ### Description Modifies an x-scale attribute of a track. This function allows customization of the track's horizontal scale, including its start and end positions, label, and graphical parameters. ### Signature ```r setTrackXscaleParam(ts, attr, value) ``` ### Parameters #### Path Parameters - **ts** (track) - Required - Track object to modify - **attr** (character) - Required - Attribute name - **value** (any) - Required - New value ### Available Attributes - **from** (pos) - Starting position - **to** (pos) - Ending position - **label** (character) - Scale label text - **gp** (list) - Graphics parameters - **draw** (logical) - Whether to draw the scale - **position** (list) - Special: list(x, y, label) for auto-positioning ### Position Attribute When `attr="position"`, value must be a list: ```r setTrackXscaleParam(track, "position", list(x=122929675, y=4, label=500)) ``` This creates a scale bar at position x with the specified label. ### Returns The modified track object (invisibly). ### Examples ```r # Draw x-scale setTrackXscaleParam(track, "draw", TRUE) # Set scale label setTrackXscaleParam(track, "label", "1 Mb") # Set graphics parameters setTrackXscaleParam(track, "gp", list(col="blue", lwd=2)) # Auto-position scale bar setTrackXscaleParam(track, "position", list(x=1500000, y=0.5, label=500000)) ``` ``` -------------------------------- ### Track Configuration Methods Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/README.md Methods for configuring track, x-scale, y-axis, and viewer styles. ```APIDOC ## Track Configuration Methods - `setTrackStyleParam(track, attr, value)`: Modifies a style attribute of a `track` object. - `setTrackXscaleParam(track, attr, value)`: Modifies an attribute of the x-scale for a `track` object. - `setTrackYaxisParam(track, attr, value)`: Modifies an attribute of the y-axis for a `track` object. - `setTrackViewerStyleParam(tvs, attr, value)`: Modifies an attribute of the `trackViewerStyle` object. ``` -------------------------------- ### Set Track Style Parameter Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/s4-methods-reference.md Use to modify a specific style attribute of a track. Examples include changing the track type, setting colors, or adjusting y-axis limits. ```r setTrackStyleParam(track, "tracktype", "histogram") ``` ```r setTrackStyleParam(track, "color", c("red", "blue")) ``` ```r setTrackStyleParam(track, "ylim", c(0, 100)) ``` ```r setTrackStyleParam(track, "ylabpos", "right") ``` ```r setTrackStyleParam(track, "ylabgp", list(cex=0.8, col="blue")) ``` -------------------------------- ### Annotate 3D Chromatin Interactions with Lines Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-visualization.md Adds annotations for 3D chromatin interactions or TADs to plots using lines. This example demonstrates reading interaction data and visualizing it with custom line styles. ```r library(trackViewer) library(InteractionSet) gi <- readRDS(system.file("extdata", "nij.chr6.51120000.53200000.gi.rds", package="trackViewer")) tads <- GInteractions( GRanges("chr6", IRanges(c(51130001, 51130001, 51450001, 52210001), width=20000)), GRanges("chr6", IRanges(c(51530001, 52170001, 52210001, 53210001), width=20000))) range <- GRanges("chr6", IRanges(51120000, 53200000)) tr <- gi2track(gi) viewTracks(trackList(tr), gr=range, autoOptimizeStyle=TRUE) addInteractionAnnotation(tads, "tr", grid.lines, gp=gpar(col="#E69F00", lwd=3, lty=3)) ``` -------------------------------- ### Import Paired WIG Files for Back-to-Back Visualization Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-core.md Imports two WIG files for back-to-back visualization, populating both `dat` and `dat2` slots. A specific genomic range is also applied. ```r wigfile1 <- system.file("extdata", "cpsf160.repA_+.wig", package="trackViewer", mustWork=TRUE) wigfile2 <- system.file("extdata", "cpsf160.repA_-.wig", package="trackViewer", mustWork=TRUE) dat <- importScore(wigfile1, wigfile2, format="WIG", ranges=GRanges("chr11", IRanges(122817703, 122889073))) ``` -------------------------------- ### Display Track Object Summary Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/s4-methods-reference.md The show method displays a summary of a track object, including its slots and their contents. This is helpful for inspecting the structure and data within a track. ```r show(track) # Output: # This is an object of track # slot name: Sample1 # slot type: data # slot format: BED # slot dat: # GRanges object with N ranges and 1 metadata column # ... # slot dat2: # GRanges object with 0 ranges and 0 metadata columns # slot style: try object$style to see details. ``` -------------------------------- ### Access and modify track slots Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Demonstrates using the $ operator to access and modify slots within a track object, including GRanges data and track style. Also shows how to get and set sequence level information. ```r # Extract slots using $ operator track$dat # Access GRanges data track$style # Access track style track$type # Access track type # Set slots using $<- operator track$dat <- GRanges(...) # Get sequence information seqlevels(track) # Get chromosome names seqlevelsStyle(track) # Get style of chromosome names # Set sequence style seqlevelsStyle(track) <- "UCSC" # Set to UCSC format (chr1, chr2, ...) ``` -------------------------------- ### Use Auto-Optimization for Styles (R) Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/common-patterns.md Enables automatic optimization of track styles for better visualization performance. ```r # Let trackViewer optimize styles automatically viewTracks(tracks, gr=gr, autoOptimizeStyle=TRUE) ``` -------------------------------- ### Interactive HTML Widget Visualization Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Demonstrates how to generate an interactive HTML widget for exploring genomic tracks using browseTracks. This allows for zooming, panning, and tooltips. ```R library(trackViewer) # Example: Create an interactive track viewer track1 <- importScore("path/to/data1.bw") track2 <- importScore("path/to/data2.bed") browser <- browseTracks(trackList = list(track1, track2)) # To save the widget to an HTML file: # htmlwidgets::saveWidget(browser, "interactive_tracks.html") ``` -------------------------------- ### Plot Genomic Tracks with viewTracks Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-visualization.md Use this function to plot a collection of genomic tracks for a specified region. It requires a list of tracks and either a GRanges object or chromosome, start, and end coordinates. Strand information can be ignored or used for filtering. ```r extdata <- system.file("extdata", package="trackViewer", mustWork=TRUE) files <- dir(extdata, "-.wig") tracks <- lapply(paste(extdata, files, sep="/"), importScore, format="WIG") tracks <- lapply(tracks, function(.ele) {strand(.ele@dat) <- "-"; .ele}) fox2 <- importScore(paste(extdata, "fox2.bed", sep="/"), format="BED") dat <- coverageGR(fox2@dat) fox2@dat <- dat[strand(dat)=="+"] fox2@dat2 <- dat[strand(dat)=="-"] gr <- GRanges("chr11", IRanges(122929275, 122930122), strand="-") viewTracks(trackList(track=tracks, fox2=fox2), gr=gr, autoOptimizeStyle=TRUE) ``` -------------------------------- ### Plotting Genomic Data on Ideograms Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-visualization.md This example demonstrates how to plot genomic data on chromosome ideograms using the ideogramPlot function. It requires loading ideogram coordinates and preparing data as a GRangesList. Custom layouts and plotting parameters like heatmap type and color key title can be specified. ```r ideo <- loadIdeogram("hg38") library(rtracklayer) library(grid) dataList <- ideo dataList$score <- as.numeric(dataList$gieStain) dataList <- dataList[dataList$gieStain!="gneg"] dataList <- GRangesList(dataList) grid.newpage() ideogramPlot(ideo, dataList, layout=list("chr1", "chr2", c("chr3", "chr22"), c("chr4", "chr21"), c("chr5", "chr20"), c("chr6", "chr19"), c("chr7", "chr18"), c("chr8", "chr17"), c("chr9", "chr16"), c("chr10", "chr15"), c("chr11", "chr14"), c("chr12", "chr13"), c("chrX", "chrY")), parameterList = list(types="heatmap", colorKeyTitle="sample1")) ``` -------------------------------- ### Import WIG File Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-core.md Imports data from a WIG file. The format parameter is explicitly set to 'WIG'. ```r wigfile <- system.file("tests", "step.wig", package="rtracklayer", mustWork=TRUE) dat <- importScore(file=wigfile, format="WIG") ``` -------------------------------- ### Precompute Styles for Reuse (R) Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/common-patterns.md Defines custom track styles once and applies them to multiple tracks for consistent visualization. ```r # Define styles once, reuse for multiple plots style <- new("trackStyle", tracktype="histogram", color=c("blue", "blue"), ylim=c(0, 100)) track$style <- style ``` -------------------------------- ### Initialize and Modify Track Viewer Style Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/s4-methods-reference.md Initializes a track viewer style object and demonstrates setting various style parameters like margins, x-axis visibility, font, flipping, and label direction. ```r tvs <- trackViewerStyle() # Set margins setTrackViewerStyleParam(tvs, "margin", c(.05, .1, .02, 0)) # Enable x-axis setTrackViewerStyleParam(tvs, "xaxis", TRUE) # Set x-axis font setTrackViewerStyleParam(tvs, "xgp", list(cex=0.7)) # Flip x-axis setTrackViewerStyleParam(tvs, "flip", TRUE) # Set label direction setTrackViewerStyleParam(tvs, "xlas", 2) ``` -------------------------------- ### Access trackViewer Vignettes Source: https://github.com/jianhong/trackviewer/blob/devel/README.md Open the package documentation vignettes in a web browser. ```r browseVignettes("trackViewer") ``` -------------------------------- ### Create trackList with equal heights Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Constructs a trackList with multiple tracks, assigning equal heights by default. Requires pre-defined track objects (e.g., tr1, tr2, tr3). ```r # Create a track list with equal heights tl <- trackList(track1=tr1, track2=tr2, track3=tr3) ``` -------------------------------- ### Create trackList with custom height distribution Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Constructs a trackList with specified relative heights for each track. The heightDist parameter normalizes the provided ratios to sum to 1. ```r # Create with custom height distribution (3:1:2 ratio) tl <- trackList(track1=tr1, track2=tr2, track3=tr3, heightDist=c(3, 1, 2)) ``` -------------------------------- ### List Normalization Methods in Hi-C File Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-utilities.md Lists available normalization methods for a given Hi-C file. Requires the path to the HDF5 formatted file. ```r listNormalizations(file) ``` -------------------------------- ### Initialize Track Viewer Style Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/configuration.md Constructs a new trackViewerStyle object with default or specified parameters for margins, axis labels, and graphics. ```r trackViewerStyle(margin=c(.01, .05, 0, 0), xlas=0, xgp=list(), xaxis=FALSE, xat=numeric(0), xlabel=character(0), autolas=FALSE, flip=FALSE) ``` -------------------------------- ### show Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/s4-methods-reference.md Displays a summary of a track object, including its slots and their contents. ```APIDOC ## show ### Description Displays a summary of a track object, including its slots and their contents. ### Signature ```r show(object) ``` ### Examples ```r show(track) # Output: # This is an object of track # slot name: Sample1 # slot type: data # slot format: BED # slot dat: # GRanges object with N ranges and 1 metadata column # ... # slot dat2: # GRanges object with 0 ranges and 0 metadata columns # slot style: try object$style to see details. ``` ``` -------------------------------- ### Visualize Strand-Specific Data Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/README.md Import forward and reverse strand WIG data, create a back-to-back track, set colors, and visualize using viewTracks. ```r # Import forward and reverse strand data forward <- importScore("forward.wig", format="WIG") reverse <- importScore("reverse.wig", format="WIG") # Create back-to-back track track <- new("track", dat=forward@dat, dat2=reverse@dat, type="data", format="WIG") setTrackStyleParam(track, "color", c("green", "red")) setTrackStyleParam(track, "tracktype", "histogram") viewTracks(trackList(track), gr=region) ``` -------------------------------- ### Create and Modify trackViewerStyle Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Demonstrates how to create a trackViewerStyle object with custom margins and axis settings, and how to modify its parameters after creation using setTrackViewerStyleParam. ```r trackViewerStyle() trackViewerStyle(margin=c(.02, .05, 0, 0), xaxis=TRUE) ``` ```r # Create with custom margins tvs <- trackViewerStyle(margin=c(.05, .1, 0.01, 0), xaxis=TRUE) # Modify after creation setTrackViewerStyleParam(tvs, "xaxis", TRUE) setTrackViewerStyleParam(tvs, "margin", c(.05, .1, .02, 0)) ``` -------------------------------- ### Class Constructors Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/README.md Constructors for creating core TrackViewer objects. ```APIDOC ## Class Constructors - `trackList()`: Creates an empty track list. - `trackViewerStyle()`: Creates a track viewer style object. ``` -------------------------------- ### importScore Parameters Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/configuration.md Parameters for importing score files like BED, bedGraph, WIG, or BigWig. ```APIDOC ## importScore Parameters ### Description Imports score data from a specified file. ### Parameters #### Path Parameters - **file** (character) - Required - File path to import - **file2** (character) - Optional - Second file for paired data #### Query Parameters - **format** (character) - Optional - File format (default: "BED", accepted: "BED", "bedGraph", "WIG", "BigWig") - **ranges** (GRanges) - Optional - Genomic region(s) to import (default: empty GRanges) - **ignore.strand** (logical) - Optional - Ignore strand when filtering (default: TRUE) ``` -------------------------------- ### trackStyle Constructor Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/configuration.md Initializes a new trackStyle object with default or specified parameters. This object defines the visual appearance of a track. ```APIDOC ## trackStyle Constructor ### Description Initializes a new trackStyle object with default or specified parameters. This object defines the visual appearance of a track. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor Signature ```r new("trackStyle", tracktype="peak", color=c("black", "black"), NAcolor="white", breaks=0, height=NA, marginTop=0, marginBottom=0.05, xscale=new("xscale"), yaxis=new("yaxisStyle"), ylim=NA, ylabpos="left", ylablas=0, ylabgp=list(), ysplit=0.5) ``` ### Parameter Details - **tracktype** (character) - Required/Optional - Track visualization type. Default: "peak" - **color** (character) - Required/Optional - Color(s) for track; 2 for paired. Default: c("black", "black") - **NAcolor** (character) - Required/Optional - Color for NA values in heatmap. Default: "white" - **breaks** (numeric) - Required/Optional - Heatmap color scale breaks. Default: 0 - **height** (numeric) - Required/Optional - Height as fraction [0,1]. Default: NA - **marginTop** (numeric) - Required/Optional - Top margin. Default: 0 - **marginBottom** (numeric) - Required/Optional - Bottom margin. Default: 0.05 - **xscale** (xscale) - Required/Optional - X-scale configuration. Default: new("xscale") - **yaxis** (yaxisStyle) - Required/Optional - Y-axis configuration. Default: new("yaxisStyle") - **ylim** (numeric) - Required/Optional - Y-axis limits. Default: NA - **ylabpos** (character) - Required/Optional - Y-label position. Default: "left" - **ylablas** (numeric) - Required/Optional - Y-label orientation (0-3). Default: 0 - **ylabgp** (list) - Required/Optional - Y-label graphics parameters. Default: list() - **ysplit** (numeric) - Required/Optional - Y-split ratio for interactions. Default: 0.5 ``` -------------------------------- ### importGInteractions Parameters Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/configuration.md Parameters for importing interaction files, with options for normalization and resolution. ```APIDOC ## importGInteractions Parameters ### Description Imports interaction data from a file. ### Parameters #### Path Parameters - **file** (character) - Required - Interaction file path #### Query Parameters - **ranges** (GRanges) - Optional - Genomic region(s) to import (default: empty GRanges) - **format** (character) - Optional - File format (default: NA) - **norm** (character) - Optional - Normalization method (Hi-C files) (default: NA) - **resolution** (numeric) - Optional - Resolution/bin size (Hi-C files) (default: NA) ``` -------------------------------- ### Render BrowseTracks Widget Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-visualization.md Renders an existing browseTracks htmlwidget. Requires the widget object and a target HTML div ID. ```r renderbrowseTracks(x, div_id, ...) ``` -------------------------------- ### importBam Parameters Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/configuration.md Parameters for importing BAM files, including options for paired-end reads. ```APIDOC ## importBam Parameters ### Description Imports data from BAM files. ### Parameters #### Path Parameters - **file** (character) - Required - BAM file path - **file2** (character) - Optional - Second BAM file for paired data #### Query Parameters - **ranges** (GRanges) - Optional - Genomic region(s) to import (default: empty GRanges) - **pairs** (logical) - Optional - Whether reads are paired-end (default: FALSE) ``` -------------------------------- ### Smoothed Signal Visualization Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Demonstrates how to visualize smoothed signal data. Smoothing can help in reducing noise and highlighting trends in genomic signal tracks. ```R library(trackViewer) # Example: Visualize a smoothed signal track signal_track <- importScore("path/to/noisy_signal.bw") # Smoothing might be applied during import or as a separate step # For example, using a rolling mean if the data allows # smoothed_signal <- ... # calculation of smoothed signal # Assuming smoothed_signal is a track object viewTracks(trackList = list(smoothed_signal)) ``` -------------------------------- ### Visualize ChIP-seq Peaks and Coverage Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/README.md Import BED peaks and WIG background coverage, set track styles, add gene annotations, and plot them together using TxDb and geneModelFromTxdb. ```r # Import peaks and compute coverage peaks <- importScore("peaks.bed", format="BED") setTrackStyleParam(peaks, "tracktype", "peak") setTrackStyleParam(peaks, "color", c("darkblue", "darkblue")) # Import background coverage bkgd <- importScore("background.wig", format="WIG") setTrackStyleParam(bkgd, "tracktype", "histogram") setTrackStyleParam(bkgd, "color", c("gray", "gray")) # Add gene annotation library(TxDb.Hsapiens.UCSC.hg19.knownGene) genes <- geneModelFromTxdb(TxDb.Hsapiens.UCSC.hg19.knownGene, org.Hs.eg.db, gr=region) # Plot together tracks <- trackList(peaks=peaks, coverage=bkgd, genes=genes) viewTracks(tracks, gr=region, autoOptimizeStyle=TRUE) ``` -------------------------------- ### Import BED, bedGraph, WIG, BigWig Files Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Use importScore to import genomic data files. Ensure files are in BED, bedGraph, WIG, or BigWig format. ```R importScore(file = "path/to/your/file.bed") ``` -------------------------------- ### Basic Track Visualization Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/common-patterns.md Use this pattern to visualize a single genomic track from a BED file within a specified region. Ensure the trackViewer library is loaded. ```r library(trackViewer) # Import data track <- importScore("data.bed", format="BED") # Specify region to display gr <- GRanges("chr1", IRanges(1000000, 2000000)) # Plot viewTracks(trackList(track), gr=gr) ``` -------------------------------- ### Import BAM Files with Coverage Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Use importBam to import BAM files and generate coverage tracks. This function is useful for visualizing alignment data. ```R importBam(file = "path/to/your/file.bam") ``` -------------------------------- ### Hi-C Utilities Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Use listResolutions and listNormalizations for Hi-C data utilities. These functions help in exploring Hi-C experiment parameters. ```R listResolutions(genome = "hg19") ``` ```R listNormalizations(genome = "hg19") ``` -------------------------------- ### Compute Ratios of BigWig Tracks Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/common-patterns.md Use the 'operator' argument in viewTracks to compute ratios between imported BigWig samples. Ensure samples are imported using importScore. ```r library(trackViewer) # Import two samples sample1 <- importScore("sample1.bw", format="BigWig") sample2 <- importScore("sample2.bw", format="BigWig") # Plot with operator to show ratio gr <- GRanges("chr1", IRanges(1e6, 2e6)) # Divide scores: sample1 / sample2 viewTracks(trackList(sample1, sample2), gr=gr, operator=c("/", "/")) # Apply division operator ``` -------------------------------- ### Custom Style Optimization Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Demonstrates the use of optimizeStyle to automatically adjust track styles for better visual presentation. This function can help in managing complex track layouts. ```R library(trackViewer) # Example: Optimize styles for a list of tracks track1 <- importScore("path/to/track1.bw") track2 <- importScore("path/to/track2.bed") trackList <- list(track1, track2) optimized_tracks <- optimizeStyle(trackList = trackList) viewTracks(trackList = optimized_tracks) ``` -------------------------------- ### List Resolutions in Hi-C File Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-utilities.md Lists available resolutions (bin sizes) for a given Hi-C file. Requires the path to the HDF5 formatted file. ```r listResolutions(file) ``` -------------------------------- ### Configure Strand-Specific Track Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/configuration.md Sets up a track for strand-specific data, importing two WIG files for forward and reverse strands. Configures the track type and colors for each strand. ```R track <- importScore("forward.wig", "reverse.wig", format="WIG") setTrackStyleParam(track, "color", c("darkgreen", "darkred")) setTrackStyleParam(track, "tracktype", "histogram") ``` -------------------------------- ### browseTracks Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-visualization.md Creates an interactive HTML widget for browsing genomic tracks. It returns an htmlwidget object that displays tracks interactively. ```APIDOC ## browseTracks ### Description Creates an interactive HTML widget for browsing genomic tracks. ### Signature ```r browseTracks(trackList, gr=GRanges(), ignore.strand=TRUE, width=NULL, height=NULL, ...) ``` ### Parameters #### Arguments - **trackList** (trackList or list) - Required - Collection of track objects to display. - **gr** (GRanges) - Required - Region to display. - **ignore.strand** (logical) - TRUE - Ignore strand when filtering tracks. - **width** (integer) - NULL - Width of the HTML widget in pixels. - **height** (integer) - NULL - Height of the HTML widget in pixels. - **...** (any) - Unused - Additional parameters. ### Returns An htmlwidget object that displays tracks interactively in a web browser or R Markdown document. ### Throws - Error if gr is not a GRanges object - Error if gr length is not 1 - Error if trackList is missing in non-interactive sessions ### Examples ```r extdata <- system.file("extdata", package="trackViewer", mustWork=TRUE) files <- dir(extdata, "-.wig") tracks <- lapply(paste(extdata, files, sep="/"), importScore, format="WIG") tracks <- lapply(tracks, function(.ele) {strand(.ele@dat) <- "-"; .ele}) names(tracks) <- c("trackA", "trackB") fox2 <- importScore(paste(extdata, "fox2.bed", sep="/"), format="BED") dat <- coverageGR(fox2@dat) fox2@dat <- dat[strand(dat)=="+"] fox2@dat2 <- dat[strand(dat)=="-"] gr <- GRanges("chr11", IRanges(122929275, 122930122)) browseTracks(trackList(tracks, fox2), gr=gr) ``` ``` -------------------------------- ### Import BAM Files Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/configuration.md Use importBam to load data from BAM files. Provide the BAM file path, and optionally a second file for paired-end data, genomic ranges, and a flag indicating if the reads are paired. ```r importBam(file, file2, ranges=GRanges(), pairs=FALSE) ``` -------------------------------- ### Configure Margin for Track Viewer Style Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/configuration.md Sets the margin parameters (bottom, left, top, right) for the track viewer style. ```r setTrackViewerStyleParam(tvs, "margin", c(.05, .1, .02, 0)) ``` -------------------------------- ### Create a track object Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Constructs a new 'track' object using the 'new' function. Requires GRanges data, track type, and input format. ```r track <- new("track", dat=GRanges(...), type="data", format="BED") ``` -------------------------------- ### listResolutions(file) Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-utilities.md Lists available resolutions in a Hi-C file. This function is useful for understanding the different granularities at which Hi-C data is stored. ```APIDOC ## listResolutions(file) ### Description Lists available resolutions in a Hi-C file. ### Parameters #### Path Parameters - **file** (character) - Required - Path to Hi-C file (HDF5 format) ### Returns A numeric vector of available resolutions (bin sizes). ``` -------------------------------- ### Sequence Level Methods Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Reference for seqlevels() and seqlevelsStyle() methods for managing chromosome naming and styles. seqlevelsStyle()<- allows setting the style. ```R seqlevels(myGRangesObject) ``` ```R seqlevelsStyle(myGRangesObject) ``` ```R seqlevelsStyle(myGRangesObject) <- "UCSC" ``` -------------------------------- ### Access tracks in trackList Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-classes.md Shows how to access individual tracks within a trackList by their index or name. Assumes a trackList object 'tl' has been created. ```r # Access tracks first_track <- tl[[1]] track_by_name <- tl(("track1")) ``` -------------------------------- ### Annotations (Guidelines, Arrows) Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Covers adding various types of annotations to track visualizations, including vertical guidelines and arrows. These annotations help in highlighting specific features or regions of interest. ```R library(trackViewer) # Example: Add a guideline and an arrow track_data <- importScore("path/to/data.bw") # Add a vertical guideline at position 1,000,000 plot_with_guideline <- addGuideLine(position = 1000000) # Add an arrow annotation plot_with_arrow <- addArrowMark(start = 500000, end = 700000, direction = "reverse") # Combine annotations (conceptual - actual implementation depends on viewTracks usage) viewTracks(trackList = list(track_data), annotations = list(plot_with_guideline, plot_with_arrow)) ``` -------------------------------- ### listNormalizations(file) Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-utilities.md Lists available normalization methods in a Hi-C file. This function helps identify compatible normalization strategies for Hi-C data analysis. ```APIDOC ## listNormalizations(file) ### Description Lists available normalization methods in a Hi-C file. ### Parameters #### Path Parameters - **file** (character) - Required - Path to Hi-C file (HDF5 format) ### Returns A character vector of available normalization methods. ``` -------------------------------- ### Class Definitions Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Reference for the core classes used in TrackViewer, including their slots and methods. ```APIDOC ## track class ### Description Represents a single genomic track, including its data, styling, and display properties. ### Slots - **data** (object) - The genomic data for the track. - **style** (trackStyle object) - Styling options for the track. - **...** - Other slots defining track properties. ### Constructor Provides constructor signatures and examples for creating track objects. ### Accessor Methods Defines accessor methods for retrieving slot values. ## trackList class ### Description Manages a collection of track objects, supporting nesting and ordering. ### Slots - **tracks** (list) - A list of track objects. - **...** - Other slots for list management. ### Constructor Provides constructor signatures and examples for creating trackList objects. ### Accessor Methods Defines accessor methods for retrieving trackList properties. ## trackStyle class ### Description Defines styling options for a genomic track. ### Slots - **color** (string) - Track color. - **height** (numeric) - Track height. - **...** - All available styling parameters. ### Constructor Provides constructor signatures and examples for creating trackStyle objects. ### Accessor Methods Defines accessor methods for styling attributes. ## trackViewerStyle class ### Description Configuration for the overall track viewer appearance and behavior. ### Slots - **width** (numeric) - Viewer width. - **height** (numeric) - Viewer height. - **...** - Viewer configuration options. ### Constructor Provides constructor signatures and examples for trackViewerStyle objects. ### Accessor Methods Defines accessor methods for viewer style attributes. ## xscale, yaxisStyle, pos helper classes ### Description Helper classes for defining x-axis scaling, y-axis styling, and positional information. ### Constructor Provides constructor signatures and examples for these helper classes. ### Accessor Methods Defines accessor methods for their respective properties. ``` -------------------------------- ### importScore Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/api-reference-core.md Reads a track object from BED, bedGraph, WIG, or BigWig files. It supports importing single or paired files for back-to-back visualization. ```APIDOC ## importScore ### Description Reads a track object from a BED, bedGraph, WIG, or BigWig file. Supports importing single or paired files for back-to-back visualization. ### Signature importScore(file, file2 = NULL, format = c("BED", "bedGraph", "WIG", "BigWig"), ranges = GRanges(), ignore.strand = TRUE) ### Parameters #### Path Parameters - **file** (character) - Required - Path to the file to read. - **file2** (character) - Optional - Path to the second file to read (for paired tracks). #### Query Parameters - **format** (character) - Optional - File format: "BED", "bedGraph", "WIG", or "BigWig". Defaults to "BED". - **ranges** (GRanges) - Optional - Genomic range to limit import scope. Defaults to an empty GRanges object. - **ignore.strand** (logical) - Optional - Whether to ignore strand information when filtering. Defaults to TRUE. ### Returns An object of class `track` with data read from the specified file(s). If `file2` is provided, returns a track with both `dat` and `dat2` slots populated for back-to-back visualization. ### Throws - Error if `ranges` is not a GRanges object. - Error if `format` is not one of the supported formats. - Error if file format does not match the specified format parameter. ### Request Example ```r # Import a BED file bedfile <- system.file("tests", "test.bed", package="rtracklayer", mustWork=TRUE) dat <- importScore(file=bedfile, format="BED", ranges=GRanges("chr7", IRanges(127471197, 127474697))) # Import a WIG file wigfile <- system.file("tests", "step.wig", package="rtracklayer", mustWork=TRUE) dat <- importScore(file=wigfile, format="WIG") # Import two paired files for back-to-back visualization wigfile1 <- system.file("extdata", "cpsf160.repA_+.wig", package="trackViewer", mustWork=TRUE) wigfile2 <- system.file("extdata", "cpsf160.repA_-.wig", package="trackViewer", mustWork=TRUE) dat <- importScore(wigfile1, wigfile2, format="WIG", ranges=GRanges("chr11", IRanges(122817703, 122889073))) ``` ``` -------------------------------- ### Back-to-Back (Strand-Specific) Visualization Source: https://github.com/jianhong/trackviewer/blob/devel/_autodocs/COMPLETION_SUMMARY.txt Demonstrates how to create back-to-back plots, which are useful for visualizing strand-specific data, such as gene expression or methylation levels on forward and reverse strands. ```R library(trackViewer) # Example: Visualize strand-specific data strand_data <- importScore("path/to/strand_data.wig") # Assuming strand_data has strand information viewTracks(trackList = list(strand_data), type = "backtoback") ```