Installation
You can install the released version of geneviewer from CRAN with:
install.packages("geneviewer")And the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("nvelden/geneviewer")Cluster Visualization
Single Gene Cluster
To visualize a single gene cluster, the minimum requirements are the start and end positions of each gene, typically named “start” and “end”. In addition a group can be defined which is used for color coding the genes and is used by default as the categorical variable for the legend.
Multiple Gene Clusters
For visualizing multiple gene clusters, an additional variable is needed which is used to define the clusters (as shown in the ‘cluster’ column below). In the example below the overall chart height is set at “300px”. Since there are two distinct gene clusters the height of each cluster will be 150px.
# Example data for two Gene clusters
GC_chart(ophA_clusters,
start = "start",
end = "end",
group = "class",
cluster = "cluster",
height = "300px"
)Shiny
The GC_chartOutput() and renderGC_chart()
functions enable you to visualize gene clusters within Shiny
applications.
# Load necessary libraries
library(shiny)
library(geneviewer)
# Define UI
ui <- fluidPage(titlePanel("Omphalotin Gene Cluster Visualization"),
mainPanel(# Output for GC_chart
GC_chartOutput(
"gcChart", width = "100%", height = "400px"
)))
# Define server logic
server <- function(input, output) {
output$gcChart <- renderGC_chart({
GC_chart(
ophA_clusters,
cluster = "cluster",
group = "class"
) %>%
GC_clusterTitle(title = c("<i>O. olearius</i>", "<i>D. bispora</i>")) %>%
GC_labels("name") %>%
GC_legend(position = "bottom") %>%
GC_scaleBar() %>%
GC_clusterLabel(title = "ophA")
})
}
# Run the application
shinyApp(ui = ui, server = server)Click interactions
Note:
GC_events()is only available in the development version of geneviewer. Install it withdevtools::install_github("nvelden/geneviewer").
Charts react to the mouse only when you ask for it with
GC_events(). Each kind of interaction has its own argument,
and FALSE switches it off:
| Argument | What it does |
|---|---|
click |
Reports a click to Shiny in
input$<outputId>_click: the part of the chart
("genes", "labels", "links",
"scale", "clusterTitle", …), its cluster and
the data of the clicked gene, link or legend group. On by default. |
select |
A click selects a gene, label, coordinate, legend label or marker,
the scale, or the title or subtitle of a cluster title, footer or label,
and outlines it. Shift-, Ctrl- or Cmd-click and a box drawn on empty
space select several (see Moving
elements). A click elsewhere or Escape ends the selection. Reported
in input$<outputId>_select (the element selected
last) and input$<outputId>_selection (all of
them). |
drag |
Elements can be moved with the mouse and the arrow keys, and moves
undone (see Moving elements). Reported in
input$<outputId>_drag and
input$<outputId>_moves. |
zoom |
Reports the window of the zoom slider in
input$<outputId>_zoom (see Zoom). |
dblclick |
Reports double-clicks in
input$<outputId>_dblclick; Enter opens a selected
element. |
highlight |
Outlines the part of the chart under the mouse. |
legend_click |
FALSE leaves legend clicks out of click.
Hiding and showing groups in the legend always works. |
The payload of a selected element also has style: how it
is drawn (its colour, size, font, …), for example to show the current
values in an editor. In the app below a click on a gene shows its row of
the data. Protein sequences (the translation and
sequence columns) are left out of it, as they are not sent
to the browser unless the chart shows them (see Tooltip); click$data$rowID finds them
in the data.
library(shiny)
library(geneviewer)
ui <- fluidPage(
GC_chartOutput("gcChart", height = "300px"),
verbatimTextOutput("clicked")
)
server <- function(input, output) {
output$gcChart <- renderGC_chart({
GC_chart(ophA_clusters, cluster = "cluster", group = "class") %>%
GC_labels("name") %>%
GC_events(click = TRUE, select = TRUE, highlight = TRUE)
})
output$clicked <- renderPrint({
click <- input$gcChart_click
req(click, click$component == "genes")
str(click$data)
})
}
shinyApp(ui = ui, server = server)Selection also works outside Shiny, as a
geneviewer:select event in the browser. Click a gene, label
or cluster title in the chart below to select it:
Moving elements
Note: Dragging, multi-select, undo and the toolbar are only available in the development version of geneviewer. Install it with
devtools::install_github("nvelden/geneviewer").
With GC_events(drag = TRUE) you can arrange a chart with
the mouse, e.g. to move a label away from a gene or the legend to an
empty corner before saving a figure. Gene labels, the chart title and
subtitle, the titles, footers and labels of the clusters, the scale axis
and scale bar (each as a whole) and the labels and markers of the legend
(each on its own) can be moved. It works in the browser, also outside
Shiny. Try it in the chart below:
- Drag an element to move it. A press without moving is still a click.
- Shift-, Ctrl- or Cmd-click adds an element to the selection, or takes it out again. Drag on empty space to draw a box: the elements entirely inside it are selected, e.g. all items of the legend. Dragging one of the selected elements moves them all.
- Arrow keys move the selected elements by a pixel, or 10 pixels with Shift.
- Undo, redo and reset appear next to the download icon once something has moved. Reset moves everything back to where it was first drawn. After clicking the chart, Ctrl+Z (Cmd+Z on a Mac) undoes and Ctrl+Shift+Z or Ctrl+Y redoes.
- Escape cancels a drag, or ends the selection.
GC_chart(ophA_clusters, cluster = "cluster", group = "class", height = "350px") %>%
GC_title("ophA gene clusters", subtitle = "Drag me") %>%
GC_labels("name") %>%
GC_clusterLabel(title = c("O. olearius", "D. bispora")) %>%
GC_scaleBar() %>%
GC_events(select = TRUE, drag = TRUE)Moved elements are part of the SVG and PNG of the save button. A move
is kept until the page is loaded again; to keep it in the chart, give
its offset in pixels, moveX (right) and moveY
(down), to GC_element_style(). Elements are identified as
they are for styling (see Individual
Items): a gene label by its row, a cluster title, footer or label by
its cluster and part, the scale and scale bar by their cluster, and a
legend label or marker by its group and part.
GC_chart(ophA_clusters, cluster = "cluster", group = "class", height = "350px") %>%
GC_labels("name") %>%
GC_clusterLabel(title = c("O. olearius", "D. bispora")) %>%
GC_scaleBar() %>%
GC_element_style("labels", row_id = 3, moveY = -12) %>%
GC_element_style("clusterLabel", cluster = 2, part = "title", moveX = 10) %>%
GC_element_style("scaleBar", cluster = 1, moveX = -40) %>%
GC_element_style("legend", group = "Methyltransferase", part = "marker", moveY = 4) %>%
GC_events(select = TRUE, drag = TRUE)In Shiny, each move is reported, so an app can keep it: a drag of one
element in input$<outputId>_drag, with the element,
its new position (moveX and
moveY) and the action ("drag",
"nudge", "undo" or "redo"), and a
move of several elements at once, such as a reset or a drag of a
selection, once in input$<outputId>_moves, with the
action and a list of moves. The app below
keeps the positions of gene labels and applies them when the chart is
drawn again, e.g. with other settings.
library(shiny)
library(geneviewer)
ui <- fluidPage(
checkboxInput("italic", "Italic labels"),
GC_chartOutput("gcChart", height = "300px")
)
server <- function(input, output) {
# The position of each moved label, by its row
positions <- reactiveVal(list())
keep <- function(moves) {
all <- positions()
for (move in moves) {
if (move$component == "labels") all[[as.character(move$data$rowID)]] <- move$position
}
positions(all)
}
observeEvent(input$gcChart_drag, keep(list(input$gcChart_drag)))
observeEvent(input$gcChart_moves, keep(input$gcChart_moves$moves))
output$gcChart <- renderGC_chart({
chart <- GC_chart(ophA_clusters, cluster = "cluster", group = "class") %>%
GC_labels("name", fontStyle = if (input$italic) "italic" else "normal") %>%
GC_events(select = TRUE, drag = TRUE)
for (row in names(positions())) {
chart <- GC_element_style(chart, "labels", row_id = as.numeric(row),
moveX = positions()[[row]]$moveX,
moveY = positions()[[row]]$moveY)
}
chart
})
}
shinyApp(ui = ui, server = server)Toolbar
The undo, redo and reset icons, the reset zoom icon of the zoom
slider (see Zoom) and the save button make up the
toolbar of the chart. GC_toolbar() sets when it shows
("hover", "always", e.g. for touch screens, or
"never"), its corner, which buttons it has, the size and
colours of its icons and the look of its tooltips. The icons are Font Awesome icons, by
name, e.g. "camera", or by their classes for another style,
e.g. "fa-regular fa-floppy-disk".
GC_chart(ophA_cluster, group = "class", height = "180px") %>%
GC_labels("name") %>%
GC_events(select = TRUE, drag = TRUE) %>%
GC_toolbar(show = "always",
position = "topleft",
size = 16,
color = "#9e9e9e",
hoverColor = "#1f77b4",
tooltipBackground = "#1f77b4",
icons = list(undo = "arrow-left", redo = "arrow-right",
reset = "arrows-to-circle", save = "camera"))The built-in themes style the toolbar to fit (see Themes), and a theme of your own can set it as a
component:
GC_theme(toolbar = list(color = "grey", hoverColor = "black")).
GC_toolbar() takes precedence over the theme.
Selections
Specific Clusters
Customization functions are by default set to alter the styling of
all gene clusters across the chart. To select a specific cluster one can
use the cluster variable which is available in most
customization functions. You can select a cluster either by it’s name or
number.
In the below example the y position is adjusted for the first cluster shifting the labels below the cluster.
Individual Items
To apply styling to a particular item within a gene cluster, the
itemStyle variable can be used. This variable, accessible
in most customization functions, requires a list that specifies the
index number of the desired item along with the intended styling
attributes. It’s important to note that indexing for
itemStyle begins at 0, following a zero-based numbering
system.
In the example below, the 3rd label in the ophA cluster is styled with red color and bold font. The code also customizes labels in cluster 2, where the 5th label is similarly styled in red and bold, and the 4th label’s position is adjusted.
GC_chart(ophA_clusters, cluster = "cluster", group = "class", height = "300px") %>%
GC_title(title = "ophA Gene Clusters", height = "30px") %>%
GC_labels(label = "name",
cluster = "ophA",
itemStyle =
list(
list(index = 2, fill = "red", fontWeight = "bold")
)
) %>%
GC_labels(
label = "name",
cluster = 2,
itemStyle =
list(
list(index = 4, fill = "red", fontWeight = "bold"),
list(index = 3, y = 10, x = -5)
)
)Note:
GC_element_style()is only available in the development version of geneviewer. Install it withdevtools::install_github("nvelden/geneviewer").
GC_element_style() styles one element at a time, without
the index: a gene, label or coordinate by its row in the data
(row_id, the rowID column of the chart), or
the title or subtitle of a cluster title, footer or label by its
cluster and part. Its options add to the other
styles of the chart, so it is called after them. These are also the
calls an editor records, e.g. one built with the selection of
GC_events() (see Click
interactions). Legend labels and markers are styled by their
group and part, and moveX and
moveY move an element (see Moving elements).
GC_chart(ophA_clusters, cluster = "cluster", group = "class", height = "300px") %>%
GC_labels("name") %>%
GC_coordinates() %>%
GC_clusterLabel(title = c("O. olearius", "D. bispora"), subtitle = "ophA") %>%
GC_element_style("genes", row_id = 3, fill = "red", markerHeight = 30) %>%
GC_element_style("labels", row_id = 3, text = "ophMA", fontWeight = "bold") %>%
GC_element_style("coordinates", row_id = 1, end = "start", show = FALSE) %>%
GC_element_style("clusterLabel", cluster = 2, part = "subtitle",
text = "dbophA", fill = "grey")Cluster
The GC_cluster function can be used to style and adjust
the margins of specific clusters.
In the below example we set a different background color for each
cluster and decrease the left and right margins to 25px. Note that the
margins of the title and legend are not adjusted. To adjust those as
well it is easiest to use the GC_grid
function which will adjust the margins of all elements at once.
GC_chart(
ophA_clusters,
group = "class",
cluster = "cluster",
height = "300px"
) %>%
GC_title("Adjust margins of GC clusters", align = "left") %>%
GC_cluster(margin = list(left = 25, right = 25)) %>%
GC_cluster(cluster = 1, style = list(backgroundColor = "green")) %>%
GC_cluster(cluster = 2, style = list(backgroundColor = "red"))Separation of Forward and Reverse strands
Forward and reverse strands can be separated into distinct tracks. In the below example forward and reverse strands are separated for the second cluster. The vertical spacing is slightly increased (default = 0).
Note: The GC_cluster() function must be
called after setting genes, labels or coordinates for proper effect.
Prevent Gene Overlap
With prevent_gene_overlap = TRUE, genes that overlap are
put on separate tracks, below each other. A gene goes on the first track
where it overlaps no gene placed before it, and
overlap_spacing sets the vertical spacing between the
tracks.
In the below example the overlapping HOX genes are put on separate tracks, 30 pixels apart.
Note: Setting both separate_strands and prevent_gene_overlap to TRUE is not supported at the moment.
GC_chart(
subset(human_hox_genes, cluster %in% c("HOXA", "HOXB")),
group = "name",
cluster = "cluster",
height = "300px"
) %>%
GC_labels(label = "name", adjustLabels = FALSE) %>%
GC_labels(label = "name",
cluster = 2,
itemStyle = list(list(index = 5, x=10))
) %>%
GC_cluster(prevent_gene_overlap = TRUE, overlap_spacing = 30) %>%
GC_legend(FALSE)Note:
prevent_gene_overlap = "nested"is only available in the development version of geneviewer. Install it withdevtools::install_github("nvelden/geneviewer").
With prevent_gene_overlap = "nested" only the genes that
lie inside another gene, e.g. an ORF in another reading frame, go on the
tracks below; all other genes stay on the first track, also where they
overlap. style_by = "geneTrack" styles the genes of each
track, here to draw the nested ORFs of SARS-CoV-2 smaller.
nested <- list(markerHeight = 8, arrowheadHeight = 8)
GC_chart(
subset(coronavirus_genomes, cluster == "SARS-CoV-2"),
group = "category",
cluster = "cluster",
height = "230px"
) %>%
GC_cluster(prevent_gene_overlap = "nested") %>%
GC_genes(style_by = "geneTrack", groupStyle = list("2" = nested, "3" = nested)) %>%
GC_labels("gene") %>%
GC_zoom(range = c(0.83, 1))Grid
The GC_grid() function can be used to modify the grid of
the chart or specific clusters. In the below example the top and bottom
margins are increased and the left and right margins decreased from 50px
which is the default to 25px.
GC_chart(ophA_clusters, group = "class", cluster = "cluster",
style = list(backgroundColor = "red"),
height = "300px"
) %>%
GC_title(
"Adjusting Margins of a GC_chart",
align = "left",
y = 15,
style = list(backgroundColor = "yellow",
align = "left")
) %>%
GC_cluster(style = list(backgroundColor = "green")) %>%
GC_legend(TRUE, style = list(backgroundColor = "yellow")) %>%
GC_grid(margin = list(top = 50, bottom = 50, left = 25, right = 25))Clusters can be shown side by side by setting the
direction to row and adjusting the
width of each cluster.
GC_chart(ophA_clusters, group = "class", cluster = "cluster", height = "250px") %>%
GC_grid(direction = "row", margin = list(left = 15, right = 15)) %>%
GC_clusterTitle(c("<i>Omphalotus Olearius</i>", "<i>Dendrothele Bisporus</i>")) %>%
GC_legend(position = "top") %>%
GC_grid(
cluster = c(1,2),
width = "50%",
height = "50%"
)Genes
The GC_genes() function can be used to custom style the
genes. In the below example the stroke and stroke width are altered but
it can take any valid CSS style. The color coding is set according to
the group in the GC_chart() function. Changing the color
scheme is best done through the GC_color() function (see:
Colors section) as this will uniformly change the
colors in both the genes and legend.
GC_chart(ophA_cluster, cluster = "cluster", group = "class", height = "150px") %>%
GC_genes(
show = TRUE,
stroke = "grey",
strokeWidth = 2
# Any other CSS style
) %>%
GC_color(colorScheme = "schemeAccent") %>%
GC_legend()By default the genes are displayed as arrows. To alter there
appearance one can use the marker and
marker_size variables. Beside the default arrow marker one
can use boxarrow, box, rbox and cbox. You can set each marker to small,
medium (default) or large.
GC_chart(ophA_cluster, cluster = "cluster", group = "class", height = "100px") %>%
GC_genes(marker = "arrow", marker_size = "small") %>%
GC_clusterLabel("arrow") %>%
GC_legend(FALSE)For finer control one can use the markerHeight variable
which will overwrite the marker_size variable. In addition
you can change the position of the markers using the x and
y variables. In case of the arrow and boxarrow markers you
can also alter the arrowhead using the arrowheadWidth and
arrowheadHeight variables.
GC_chart(ophA_cluster, cluster = "cluster", group = "class", height = "100px") %>%
GC_genes(
y = 55,
marker = "arrow",
markerHeight = 10,
arrowheadHeight = 15,
arrowheadWidth = 15
) %>%
GC_clusterLabel("customized arrows") %>%
GC_legend(FALSE)Note:
groupStyleis only available in the development version of geneviewer. Install it withdevtools::install_github("nvelden/geneviewer").
groupStyle styles all genes of a group at once, with the
same options as itemStyle.
Gene alignment
The GC_align() function can be used to align a specific
gene across clusters. In the example below, we specify the column that
contains gene identifiers and then vertically align the gene across the
clusters to the left. Please note that the gene identifier used for
alignment must be the same across clusters but unique within each
cluster.
Gene normalization
The GC_normalize function can be used to normalize the
genomic coordinates of a set of genes within a cluster, ensuring that
the genes are evenly spaced along the entire range of the cluster. In
the below example we normalize the genes of the first cluster to have
even spacing between all genes while preserving their original length.
Optionally, a custom spacing between the genes can be set using the
gap variable.
Note: Normalization will adjust the start and end
positions of the genes, causing them to differ from the original
coordinates. To display the original start and end positions in the
tooltip, the formatter can be updated to use the
original_start and original_end values.
GC_chart(ophA_clusters, cluster = "cluster", group = "class", height = "150px") %>%
GC_normalize(
group = "class",
cluster = 1, # By default all clusters are normalized
gap = NULL, # 0-1
preserve_gene_length = TRUE
) %>%
# Update tooltip
GC_tooltip(
cluster = 1,
formatter = "<b>Start:</b> {original_start}<br><b>End:</b> {original_end}"
) %>%
GC_legend(FALSE)You can adjust the spacing between specific genes using the
custom_gaps variable. In the example below, we normalize
the spacing between the genes in the first cluster, set a uniform
gap width for all genes, and increase the gap by 5x after
the genes ophC and ophB2.
GC_chart(ophA_clusters, cluster = "cluster", group = "class", height = "280px") %>%
GC_normalize(
group = "name",
cluster = 1, # By default all clusters are normalized
gap = 0.01, # 0-1
custom_gaps = list(ophC = 5, ophB2 = 5),
preserve_gene_length = FALSE
) %>%
GC_labels(label = "name") %>%
# Update tooltip
GC_tooltip(
cluster = 1,
formatter = "<b>Start:</b> {original_start}<br><b>End:</b> {original_end}"
) %>%
GC_legend(FALSE)BlastP
The protein_blast() function can be used to perform a
BlastP alignment between clusters. For more information see the Cluster
comparison using BlastP tutorial.
BlastP_results <-
protein_blast(
data, # or path to folder containing .gbk files
query, # The name of the query cluster to be used for BLAST comparisons.
id = "protein_id", # The name of the column that contains the gene identifiers.
start = "start",
end = "end",
cluster = "cluster",
genes = NULL, #Vector of protein IDs to include for BlastP analysis.
identity = 30
)Transcripts
The GC_transcript() function can be used to visualize
transcripts. It requires setting the transcript column with unique IDs
for each transcript and a type column identifying whether the feature is
a “UTR”, or “exon”. Optionally, you can also set the direction by
specifying the strand column. Please note that introns are calculated
based on exon positions.
transcript_data <- data.frame(
transcript = c("transcript1", "transcript1", "transcript1", "transcript1",
"transcript2", "transcript2", "transcript2"),
type = c("5_utr", "exon", "exon", "3_utr",
"5_utr", "exon", "3_utr"),
start = c(1, 101, 201, 301,
1, 101, 301),
end = c(50, 150, 250, 350,
50, 150, 350),
strand = rep("forward", 7)
)
GC_chart(
transcript_data,
start = "start",
end = "end",
height = "200px") %>%
GC_transcript(
transcript = "transcript",
strand = "strand",
)There is a wide range of options to customize the exons, introns and
UTRs. For all options see the documentation by running
?GC_transcript(). Junctions can be added to the transcripts
using the Arc annotation. Below is an example of
setting custom colors by grouping by “type” and specifying the colors
using customColors.
GC_chart(
transcript_data,
start = "start",
end = "end",
height = "200px"
) %>%
GC_transcript(
group = "type",
customColors =
list(
exon = "green",
intron = "blue",
`5_utr` = "black",
`3_utr` = "grey"
)
)The introns, exons, UTRs, and labels can be styled using the
styleIntrons, styleExons,
styleUTRs, and labelOptions variables
respectively.
GC_chart(transcript_data, height = "200px") %>%
GC_transcript(
styleIntrons =
list(
strokeWidth = 2,
markerHeight = 60
# Any other CSS style
),
styleExons =
list(
markerSize = "small",
fill = "none",
strokeWidth = 2,
stroke = "red"
# Any other CSS style
),
styleUTRs = list(
marker = "boxarrow",
markerSize = "small",
fill = "green"
# Any other CSS style
),
labelOptions = list(
show = TRUE,
xOffset = 0,
yOffset = 0,
fontSize = "10px",
fontWeight = "bold"
# Any other CSS style
)
)The itemStyle in combination with the
selection variable allows for the customization of
individual exons, introns, or UTRs within specific transcripts.
GC_chart(
transcript_data,
start = "start",
end = "end",
height = "200px"
) %>%
GC_transcript(
transcript = "transcript",
selection = 1,
itemStyleExons =
list(
list(index = 0, fill = "red")
)
) %>%
GC_transcript(
transcript = "transcript",
selection = 2,
itemStyleIntrons =
list(
list(index = 1, stroke = "red", strokeWidth = 2)
)
)Links
The get_links and GC_links() functions can
be used to add links between genes. In the below example, we initially
create a chart object. Subsequently, we generate links among all
clusters. This is achieved by specifying a grouping column which will
generate links for all value pairs between the different clusters.
# Generate chart object
chart <- GC_chart(
ophA_clusters,
cluster = "cluster",
group = "class",
height = "250px") %>%
GC_legend(FALSE)
# Add links to chart
chart %>% GC_links("class")Using the value1 and value2 variables in
the get_links function you can generate links between
specific genes. In case there are more than 2 clusters you can use the
cluster variable which allows to specify the clusters to
generate links for.
# Add links to chart
chart %>%
GC_links(
"name",
value1 = c("ophB1", "ophC"),
value2 = c("dbophB1", "dbophC"),
cluster = c(1,2)
) %>%
GC_labels("name")An “identity” or “similarity” column can be added to the data which
will be used as measure to set the color intensity of the links. In
addition links and labels can be styled using the linkStyle
and labelStyle options. The width of the links can be
adjusted using the linkWidth parameter.
ophA_clusters$identity <- sample(1:100, size = nrow(ophA_clusters), replace = TRUE)
ophA_clusters$identity[ophA_clusters$cluster == "ophA"] <- NA
chart <- GC_chart(
ophA_clusters,
cluster = "cluster",
group = "class",
height = "250px") %>%
GC_links(
"class",
value1 = c("Methyltransferase", "Prolyloligopeptidase"),
value2 = c("Methyltransferase", "Prolyloligopeptidase"),
inverted_color = "green",
measure = "identity", # similarity / none
label = TRUE,
curve = FALSE,
color_bar = TRUE,
colorBarOptions = list(
x = 0,
y = 24,
width = 10,
height = 60,
labelOptions = list(
fontSize = 8,
xOffset = 2,
yOffset = 0
# Any other CSS style
),
titleOptions = list(
fontSize = 10,
xOffset = 2,
yOffset = 0
# Any other CSS style
),
barOptions = list(
stroke = "#000",
strokeWidth = 0.5,
opacity = 1
# Any other CSS style
)
),
linkWidth = 0.5,
linkStyle = list(
stroke = "black",
strokeWidth = 0.5
# Any other CSS style
),
labelStyle = list(
fill = "red"
# Any other CSS style
)
) %>%
GC_legend(TRUE)
chartThe data parameter allows you to load a data frame that
defines links between genomic regions by their start and end positions,
rather than linking specific genes. You can include an “identity” or
“similarity” column that will be used to set the color intensity of
these links. Links run from nearly white at a measure of
vmin to the full color at vmax (0 and 100 by
default), which are also the ends of the color bar. Setting
vmin to the lowest measure spreads the colors over the
data; measures below vmin or above vmax get
the color of that end.
Note: The
vminandvmaxarguments ofGC_links()are only available in the development version of geneviewer. Install it withdevtools::install_github("nvelden/geneviewer").
links_data <- data.frame(
start1 = c(5000, 16000),
end1 = c(9000, 19000),
start2 = c(20000, 42000),
end2 = c(25000, 32000),
cluster1 = c("ophA","ophA"),
cluster2 = c("dbophA", "dbophA"),
identity = c(20, 100),
similarity = c(10, 90)
)
# Add links to chart
GC_chart(
ophA_clusters,
cluster = "cluster",
group = "class",
height = "250px") %>%
GC_links(
data = links_data,
measure = "identity",
vmin = 20,
vmax = 100
)Note:
label_positionand thepositionofcolorBarOptionsare only available in the development version of geneviewer. Install it withdevtools::install_github("nvelden/geneviewer").
With label_position = "link" the measure is written in
the middle of each link where it fits, also for links from
data. The position of
colorBarOptions moves the color bar to another corner or,
with "legend", into the legend.
Sequence
The sequence line in the GC_sequence() function is
initially presented as a solid black line, but can be customized with
the sequenceStyle option. Additionally, the
markerStyle option allows adjusting the style of the break
markers.
GC_chart(
ophA_clusters, group = "class",
cluster = "cluster",
height = "150px") %>%
GC_sequence(
show = TRUE,
cluster = NULL,
y = 50,
sequenceStyle = list(
stroke = "grey",
strokeWidth = 1
# Any other CSS style
),
markerStyle = list(
stroke = "grey",
strokeWidth = 1,
gap = 3,
tiltAmount = 5
# Any other CSS style
)
) %>%
GC_legend(FALSE)Labels
To each gene cluster one can add a title, gene labels, a cluster label and a footer as shown in the example below.
GC_chart(ophA_clusters,
start = "start",
end = "end",
group = "class",
cluster = "cluster",
height = "450px"
) %>%
GC_clusterTitle(
title = c("<i>Omphalotus Olearius</i>", "<i>Dendrothele Bisporus</i>"),
titleFont = list(fontWeight = "normal")
) %>%
GC_labels("name") %>%
GC_clusterLabel(title = unique(ophA_clusters$cluster)) %>%
GC_clusterFooter(
title = c("Nr. of Genes: 7", "Nr. of Genes: 10"),
subtitle = c("Locus: 2522 - 21,484", "Locus 19,236 - 43,005")
) %>%
GC_legend(position="top")To adjust the positioning of labels, the x,
y, and align variables can be used. Note that
in this example, GC_labels() is employed twice: initially,
it sets labels uniformly for all gene clusters, and then it specifically
adjusts the fourth and eight label (considering the index starts at 0)
in cluster 2, to ensure there is no overlap.
GC_chart(ophA_clusters, group = "class", cluster = "cluster", height = "360px") %>%
GC_clusterTitle(
c("<i>Omphalotus Olearius</i>", "<i>Dendrothele Bisporus</i>"),
position = "left",
x = 20) %>%
GC_labels("name", y = 20) %>%
GC_labels("name",
cluster = 2,
y = 20,
itemStyle =
list(
list(index = 3, y = 52),
list(index = 7, y = 52)
)
) %>%
GC_clusterFooter(
title = c("Nr. of Genes: 7", "Nr. of Genes: 10"),
subtitle = c("Locus: 2522 - 21,484", "Locus 19,236 - 43,005"),
align = "center"
)To adjust the position or styling of specific labels one can use the
cluster and itemStyle variables. With the
cluster variable one can select a specific cluster by their name or
number. Using itemStyle variable one can provide a list
with the index number of a specific label and the styles that should be
applied to it. Note that the index for itemStyle starts
with 0.
GC_chart(ophA_clusters, group = "class", cluster = "cluster", height = "360px") %>%
GC_labels("name", y = 20) %>%
GC_labels("name",
cluster = 2,
y = 20,
itemStyle = list(
list(index = 3, y = 52, fill = "red"),
list(index = 7, y = 52, fill = "red")
)
)Labels that overlap another label are turned by default; in the
development version, adjustLabels = "hide" hides them
instead, until there is room for them, e.g. when zoomed in with GC_zoom().
Annotations
The GC_annotation function can be used to add
annotations to specified clusters within a GC chart. The types of
annotations available are: text, textMarker, line, arrow, symbol,
rectangle, promoter, and terminator.
Annotations are placed by specifying the type followed
by the type specific parameters. As shown in the below example multiple
annotations of the same type can be placed by providing a list of
values. The GC_trackMouse() function can be used to track
the mouse coordinates while hoovering over the chart which makes it more
easy to determine the x and y positions to
place the annotation.
GC_chart(ophA_clusters, group = "class", cluster = "cluster", height = "300px") %>%
GC_annotation(
cluster = 1,
type = "text",
text = "Gene 1",
x = 2970,
y = 60
) %>%
GC_annotation(
cluster = 2,
type = "text",
text = c("Gene 1", "Gene 2", "Gene 3"),
x = c(19400, 22200, 25600),
y = 60
) %>%
GC_legend(FALSE) %>%
GC_trackMouse()Text
Below shows an example with all options to place a text annotation.
The text, x and y variables can
also take a list of values.
GC_chart(ophA_cluster, group = "class", cluster = "cluster", height = "150px") %>%
GC_annotation(
cluster = 1,
type = "text",
text = "Gene 1",
x = 2970,
y = 58,
style = list(
fontSize = "10px",
fontStyle = "normal",
fontWeight = "normal",
textDecoration = "none",
fontFamily = "sans-serif",
cursor = "default"
# Any other CSS style
)
) %>%
GC_legend(FALSE) %>%
GC_trackMouse()Text Marker
Below shows an example with all options to place a text Marker. With
the exception of the styles all other variables can also take a list of
values. By default x1 and x2 are NULL and
position is used for the horizontal placement.
GC_chart(ophA_cluster, group = "class", cluster = "cluster", height = "150px") %>%
GC_annotation(
cluster = 1,
type = "textMarker",
text = "Gene 1",
x1 = NULL,
y1 = 66,
x2 = NULL,
y2 = 50,
position = 9300,
labelX = 0,
labelY = 0,
showArrow = FALSE,
arrowSize = 8,
textStyle = list(
fontSize = "10px",
fontFamily = "sans-serif",
fill = "black",
textAnchor = "middle"
),
arrowStyle = list(
fill = "black"
),
lineStyle = list(
stroke = "black",
strokeWidth = 1
)
) %>%
GC_legend(FALSE) Promoter / Terminator
Below shows an example with all options to place a promoter. With the exception of the styles all other variables can also take a list of values.
GC_chart(ophA_cluster, group = "class", cluster = "cluster", height = "150px") %>%
GC_annotation(
cluster = 1,
type = "promoter", # terminator
x = 9300,
y = 50,
direction = "forward", # reverse
style = list(
fill = "none",
stroke = "black",
strokeWidth = 1
# Any other CSS style
),
rotation = 0,
scale = 1
) %>%
GC_legend(FALSE) %>%
GC_trackMouse()Symbol
Below shows an example with all options to place a symbol. Supported symbols are circle, cross, diamond, square, star, triangle, wye. With the exception of the styles all other variables can also take a list of values.
GC_chart(ophA_cluster, group = "class", cluster = "cluster", height = "150px") %>%
GC_annotation(
cluster = 1,
type = "symbol", # circle/cross/diamond/square/star/triangle/wye
symbol = "circle",
x = 9300,
y = 50,
size = 64,
rotation = 0,
style = list(
fill = "black",
stroke = "black",
strokeWidth = 2
# Any other CSS style
)
) %>%
GC_legend(FALSE) %>%
GC_trackMouse()Arrow
Below shows an example with all options to place an arrow. With the exception of the styles all other variables can also take a list of values.
GC_chart(ophA_cluster, group = "class", cluster = "cluster", height = "150px") %>%
GC_annotation(
cluster = 1,
type = "arrow",
x1 = 9300,
y1 = 70,
x2 = 9300,
y2 = 50,
arrowSize = 8,
arrowStyle = list(
fill = "black"
# Any other CSS style
),
lineStyle = list(
stroke = "black",
strokeWidth = 1
# Any other CSS style
)
) %>%
GC_legend(FALSE) %>%
GC_trackMouse()Line
Below shows an example with all options to place a line. With the exception of the styles all other variables can also take a list of values.
GC_chart(ophA_cluster, group = "class", cluster = "cluster", height = "150px") %>%
GC_annotation(
cluster = 1,
type = "line",
x1 = 9300,
y1 = 70,
x2 = 9300,
y2 = 50,
style = list(
stroke = "black",
strokeWidth = 1
# Any other CSS styles
)
) %>%
GC_legend(FALSE) %>%
GC_trackMouse()Arc
Below shows an example with all options to place arcs.
transcript_data <- data.frame(
transcript = c("transcript1", "transcript1", "transcript1", "transcript1"),
type = c("5_utr", "exon", "exon", "3_utr"),
start = c(1, 101, 201, 301),
end = c(50, 150, 250, 350),
strand = rep("forward", 4)
)
GC_chart(
transcript_data,
start = "start",
end = "end",
height = "200px") %>%
GC_transcript(
transcript = "transcript",
strand = "strand",
) %>%
GC_annotation(
cluster = NULL,
type = "arc",
x1 = c(150, 50),
y1 = c(50),
x2 = c(301, 201),
y2 = c(50),
midY = c(80, 20),
stroke = c("black"),
strokeWidth = c(0.8, 0.1),
labelX = c(0),
labelY = c(0),
text = c(0.8, 0.1),
lineStyle = list(
# Any other CSS styles
),
textStyle = list(
fontSize = "10px",
fontFamily = "sans-serif",
fill = "black",
textAnchor = "middle"
# Any other CSS styles
)
) %>%
GC_legend(FALSE) %>%
GC_trackMouse()Square
Below shows an example with all options to place a square. The
rotation variable can also take a list of values.
GC_chart(ophA_cluster, group = "class", cluster = "cluster", height = "150px") %>%
GC_annotation(
cluster = 1,
type = "rectangle",
rotation = 0,
position =
list(
list(c(9200, 60), c(11100, 40)),
list(c(11700, 60), c(12900, 40))
),
style = list(
stroke = "black",
strokeWidth = 1
# Any other CSS styles
)
) %>%
GC_legend(FALSE) %>%
GC_trackMouse()Colors
The color of the legend and genes can be controlled through the
GC_color function using the colorScheme or
customColors variables.
colorScheme
Defines a predefined color scheme for the legend, such as “schemeCategory10” or “schemeAccent” from D3.js.
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_color(colorScheme = "schemeAccent")Supported schemes include:
-
schemeCategory10: An array of ten categorical colors.
-
schemeAccent: An array of eight categorical colors.
-
schemeDark2: An array of eight categorical colors.
-
schemePaired: An array of twelve categorical colors.
-
schemePastel1: An array of nine categorical colors.
-
schemePastel2: An array of eight categorical colors.
-
schemeSet1: An array of nine categorical colors.
-
schemeSet2: An array of eight categorical colors.
-
schemeSet3: An array of twelve categorical colors.
-
schemeTableau10: An array of ten categorical colors, originally created for Tableau.
customColors
The customColors parameter specifies colors for each
group in the legend. It accepts either a vector of colors or a named
list for direct mapping, such as
list("Class1" = "#FF5733", "Class2" = "#33CFFF").
Using a list of colors:
# Pass a list of Colors
custom_colors <- c("#F8766D","#00BA38","#619CFF","#F564E3","#FFC61E","#00BFC4")
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_color(customColors = custom_colors )Using a named list of colors;
# Pass a list of Colors
custom_colors <- c("#D62728", "#2CA02C", "#1F77B4", "#9467BD", "#FF7F0E", "#17BECF")
# Create a named list of colors
named_vector <- setNames(custom_colors, unique(ophA_cluster$class))
custom_colors <- as.list(named_vector)
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_color(customColors = custom_colors )To ensure the color changes take effect, the GC_color function call
must be placed after all other function calls. In the example below, the
custom_colors are overwritten by the color settings in the
GC_genes function. Therefore, always place the
GC_color function call last.
# Pass a list of Colors
custom_colors <- c("#D62728", "#D62728", "#D62728", "#D62728", "#D62728", "#D62728")
# Create a named list of colors
named_vector <- setNames(custom_colors, unique(ophA_cluster$class))
custom_colors <- as.list(named_vector)
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_color(customColors = custom_colors ) %>%
GC_genes() %>%
GC_legend()Patterns
Note:
GC_pattern()is only available in the development version of geneviewer. Install it withdevtools::install_github("nvelden/geneviewer").
Journals sometimes ask for figures in black and white. The
GC_pattern() function fills the genes, exons and legend
markers with a pattern for each group instead of a colour. By default
each group gets the next pattern from a fixed list, drawn in black on a
white background.
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_pattern()There are 16 patterns. Without patterns, the groups get
them in the order shown below, which keeps patterns that look alike
(such as “diagonal” and “wideStripes”) far apart; “none” is not used by
default.
all_patterns <- c(
"diagonal", "dots", "horizontal", "crosshatch", "vertical", "zigzag",
"checkerboard", "solid", "rings", "bricks", "inverseDots", "grid",
"wideStripes", "plus", "antidiagonal", "none"
)
# Two rows of 8 genes
pattern_genes <- data.frame(
start = rep(seq(0, by = 100, length.out = 8), 2),
end = rep(seq(85, by = 100, length.out = 8), 2),
pattern = all_patterns,
row = rep(c("1", "2"), each = 8)
)
GC_chart(pattern_genes, group = "pattern", cluster = "row",
height = "260px") %>%
GC_labels("pattern", fontSize = "11px") %>%
GC_legend(order = all_patterns) %>%
GC_pattern(patterns = setNames(as.list(all_patterns), all_patterns))Use patterns to choose them: a vector is recycled over
the groups, and a named list sets the pattern for each group.
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_pattern(
patterns = list(
"Monooxygenase" = "diagonal",
"NTF2-like" = "dots",
"Methyltransferase" = "horizontal",
"O-acyltransferase" = "crosshatch",
"Prolyloligopeptidase" = "vertical",
"F-box/RNHI-like" = "none"
)
)With many groups, combine the patterns with grey backgrounds. The
background vector is recycled over the groups in the same
way as patterns, so 3 patterns and 2 greys give 6 different
fills. color sets the colour of the pattern lines and dots,
size the width of one pattern tile and
strokeWidth the width of the lines.
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_pattern(
patterns = c("diagonal", "dots", "crosshatch"),
background = c("white", "grey75"),
size = 8,
strokeWidth = 1.5
)Set background = NULL to draw the patterns on top of the
gene colours. Each group is then shown by both a colour and a pattern,
which also helps readers who cannot tell some colours apart.
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_color(colorScheme = "schemeSet2") %>%
GC_pattern(background = NULL)Like background, color can be a vector or a
named list, so some groups can have white patterns on black.
“inverseDots” draws the dots in the background colour on a tile filled
with color.
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_pattern(
patterns = c("diagonal", "dots", "horizontal",
"checkerboard", "bricks", "rings"),
color = c("black", "black", "white", "black", "black", "white"),
background = c("white", "white", "black", "white", "white", "black")
)Like GC_color(), place GC_pattern() after
GC_genes() and GC_transcript(), as these
functions reset the pattern settings.
Themes
Note:
GC_theme(),geneviewer_theme()andgeneviewer_palette()are only available in the development version of geneviewer. Install it withdevtools::install_github("nvelden/geneviewer").
The GC_theme() function sets the default look of the
whole chart at once: fonts, text and line colours, the background, the
gene colours and the options of each component. There are 7 built-in
themes:
-
"default": the default look of geneviewer. -
"classic": the default theme of ECharts 5. -
"dark": light text and soft colours on a dark background. -
"vintage": muted colours on a cream background. -
"infographic": strong colours. -
"publication": for journal figures (Arial, 7 pt text, black text and axes, italic gene labels and colour-blind safe colours). -
"bw": black and white, with a pattern for each group (see Patterns).
GC_chart(ophA_cluster, group = "class", height = "150px") %>%
GC_labels("name") %>%
GC_theme("dark")
GC_chart(ophA_cluster, group = "class", height = "150px") %>%
GC_labels("name") %>%
GC_theme("vintage")
GC_chart(ophA_cluster, group = "class", height = "150px") %>%
GC_labels("name") %>%
GC_scale() %>%
GC_theme("publication")A theme only changes how things look. It does not add components to
the chart: a scale still needs GC_scale() and labels
GC_labels().
Each built-in theme also styles the toolbar of the chart (see Toolbar): its icons in colours of the theme and its tooltips in the style of the theme’s tooltip. Hover the chart below and drag a label to see the undo icon in the dark theme.
GC_chart(ophA_cluster, group = "class", height = "150px") %>%
GC_labels("name") %>%
GC_events(select = TRUE, drag = TRUE) %>%
GC_theme("dark")Global settings
Next to theme, GC_theme() takes settings
that apply to all components: fontFamily,
textColor, lineColor (the sequence line, axis,
coordinates and scale bar), background,
palette (the gene colours) and pattern. Use
them to change a built-in theme, or call GC_theme() without
a theme to change the current one.
GC_chart(ophA_cluster, group = "class", height = "150px") %>%
GC_labels("name") %>%
GC_theme("classic",
fontFamily = "Georgia",
textColor = "navy",
lineColor = "steelblue",
palette = c("#1b9e77", "#d95f02", "#7570b3", "#e7298a", "#66a61e", "#e6ab02"))palette takes a vector of colours, the name of a d3
colour scheme (e.g. "schemeSet2") or the name of a
geneviewer palette. geneviewer_palette() lists these
palettes, and geneviewer_palette("okabeIto") returns the
colours of one. The geneviewer palettes can also be used as the
colorScheme of GC_genes(),
GC_transcript() and GC_color().
geneviewer_palette()
#> [1] "okabeIto" "classic" "vivid" "dark" "vintage"
#> [6] "infographic" "greys" "blues"Text size
textScale scales all text of the chart at once, e.g. for
a slide or a figure that is printed small. The title and the width of
the cluster labels grow with the text.
Component options
Options for a single component are given as a list named after the
component, with the arguments of its GC_ function,
e.g. labels = list(fontSize = "10px") for
GC_labels() or links = list(curve = FALSE) for
GC_links(). See ?GC_theme for all
components.
GC_chart(ophA_cluster, group = "class", height = "150px") %>%
GC_labels("name") %>%
GC_theme("classic",
labels = list(fontSize = "10px", fill = "grey"),
genes = list(marker = "rbox", stroke = "none"),
legend = list(position = "top"))Options set with the other GC_ functions always take
precedence over the theme, whatever the order of the calls. Below the
gene labels stay 14px, although the theme sets them to 10px.
A theme of your own
geneviewer_theme() returns the settings of a built-in
theme as a list. Change it and pass it as the theme of
GC_theme() to reuse your own theme in all your charts.
my_theme <- utils::modifyList(
geneviewer_theme("classic"),
list(textColor = "darkgreen", palette = "okabeIto")
)
GC_chart(ophA_cluster, group = "class", height = "150px") %>%
GC_labels("name") %>%
GC_theme(my_theme)Legend
The GC_legend() function can be used to show / hide and
customize the legend. By default the legend is shown at the bottom. The
below example shows the GC_function() with all its default
settings.
GC_chart(
ophA_clusters,
group = "class",
cluster = "cluster",
height = "200px") %>%
GC_legend(
show = TRUE,
position = "bottom", #top (left and right no supported for now)
orientation = "horizontal", #vertical
x = 0,
y = 0,
margin = list(top = 0, left = 50, bottom = 0, right = 50),
adjustHeight = TRUE,
order = list(),
style = list(
#backgroundColor = "#0000"
# Additional CSS styles
),
positions = "bottom",
legendOptions = list(
cursor = "pointer",
colorScheme = NULL,
customColors = NULL
# Additional CSS styles
),
legendTextOptions = list(
cursor = "pointer",
textAnchor = "start",
dy = ".35em",
fontSize = "12px",
fontFamily = "sans-serif",
fill = "black"
# Additional CSS styles
)
)In the below example a more advanced customization is shown changing
the order, size, position and appearance of the legend. The color is
changed using the GC_color function which simultaneously
adjusts the colors of the legend and genes.
GC_chart(
ophA_clusters,
group = "class",
cluster = "cluster",
height = "200px") %>%
GC_legend(
y = 10,
position = "top",
width = "60%",
order = sort(unique(ophA_clusters$class)),
legendTextOptions = list(
fontSize = "14px"
),
legendOptions = list(stroke = "black", strokeWidth = "2px")
) %>%
GC_color(colorScheme = "schemePaired")Scale
The GC_scale() function is utilized for adjusting the
chart’s scale. The padding parameter can be used to add extra space to
start and end of the cluster. The visibility of the scale can be
controlled by the hidden parameter, which, when set to TRUE, hides the
axis. The y parameter can be used to adjust the horizontal
position of the axis (1 at the bottom and 100 being the top).
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_scale(
padding = 2,
hidden = FALSE,
axisType = "bottom",
y = NULL) %>%
GC_legend(FALSE)Automatic Scale Breaks
In the GC_scale() function, the parameters
scale_breaks, scale_break_threshold, and
scale_break_padding can be used to avoid issues with widely
spaced genes within a cluster. Setting scale_breaks to TRUE
introduces breaks in the genomic scale which will avoid long empty
stretches. The scale_break_threshold defines the spacing
percentage between genes needed to activate these breaks.
scale_break_padding controls the padding around these
breaks.
In the given example, a scale break will be introduced in cases where the intergenic region exceeds 20% of the total range of the gene cluster. Additionally, a padding of 1% will be added to both the left and right sides of this break.
Manual Scale Adjustments
By default the minimum and maximum of the genes start and end
positions are used to position the genes along the sequence. With the
use of the start and end parameters, these
values can be adjusted. Scale breaks can be added manually using the
breaks parameter.
In the provided example the range is altered by providing custom
start and end values. Additionally, a scale
break is introduced to remove the extensive intergenic region that
exists between gene 2 and gene 3.
Shared genomic scale
By setting axis_type to range, you can standardize the
axis across clusters, shifting from precise genomic coordinates to a
unified scale. This scale is based on the widest span observed among the
clusters, starting from 0 and extending to the endpoint of the cluster
covering the largest range. Warning: By using a shared
axis some of the options like setting breaks and reversing the scale
might not work anymore.
Styling
The scale can be styled using the tickStyle,
textStyle and lineStyle options. You can pass
any valid CSS styles to the respective styling list(). The amount of
ticks can be specified using the ticksCount option.
Alternatively, ticks can be manually specified using the
tickValues parameter. The ticksFormat
parameter is used to define how the numerical labels on the tick marks
are formatted (see: link).
GC_chart(ophA_cluster, group = "class", height = "100px") %>%
GC_scale(
ticksFormat = ".2s", # Default: ",.0f"
tickValues = c(ophA_cluster$start, ophA_cluster$end),
#ticksCount = 10,
tickStyle =
list(
stroke = "black",
strokeWidth = 2,
lineLength = 12
# Any other CSS styles
),
textStyle =
list(
y = 15,
fill = "black",
fontSize = "8px",
fontFamily = "Arial"
# Any other CSS styles
),
lineStyle = list(
stroke = "black",
strokeWidth = 2
# Any other CSS styles
)
) %>%
GC_legend(FALSE)Zoom
Note:
GC_zoom()is only available in the development version of geneviewer. Install it withdevtools::install_github("nvelden/geneviewer").
GC_zoom() adds a slider below the clusters to zoom in on
part of them. Drag a handle to change the window, drag the window to
move it and click the track to move the window there. Double-click the
slider, or use the reset zoom icon in the toolbar, to show everything
again. With the keyboard, the arrow keys move a focused handle or the
window (Shift: in bigger steps). The slider shows the genes of each
cluster in their colours, and genes, labels, links and the axis follow
the window. range sets the window shown first:
GC_chart(ophA_clusters, cluster = "cluster", group = "class", height = "350px") %>%
GC_labels("name") %>%
GC_links("class") %>%
GC_scale(hidden = FALSE) %>%
GC_zoom(range = c(0.2, 0.6))By default every cluster zooms to the same share of its own range,
which suits clusters of different genomes. With
mode = "absolute" the window is in base pairs and every
cluster shows the same positions. update = "release" draws
the chart only when the slider is let go, for large charts, and
height, overview, color,
style, windowStyle and
handleStyle set the look of the slider:
GC_chart(ophA_clusters, cluster = "cluster", group = "class", height = "300px") %>%
GC_labels("name") %>%
GC_scale(hidden = FALSE) %>%
GC_zoom(mode = "absolute", range = c(10000, 20000), update = "release", height = 30,
handleStyle = list(backgroundColor = "#d9d9d9"))In Shiny, GC_events(zoom = TRUE) reports the window in
input$<outputId>_zoom: its range, which
goes back into GC_zoom(range = ), and the base pairs each
cluster shows. It is reported on the first render and after every
change. GC_zoom_to() moves the window from the server. A
chart drawn again with the same data, e.g. after another setting
changed, keeps the window the user picked.
library(shiny)
library(geneviewer)
ui <- fluidPage(
actionButton("first", "First half"),
actionButton("all", "Everything"),
GC_chartOutput("gcChart", height = "300px"),
verbatimTextOutput("window")
)
server <- function(input, output, session) {
output$gcChart <- renderGC_chart({
GC_chart(ophA_clusters, cluster = "cluster", group = "class") %>%
GC_labels("name") %>%
GC_zoom() %>%
GC_events(zoom = TRUE)
})
observeEvent(input$first, GC_zoom_to("gcChart", c(0, 0.5)))
observeEvent(input$all, GC_zoom_to("gcChart", NULL))
output$window <- renderPrint(str(input$gcChart_zoom[c("range", "clusters")]))
}
shinyApp(ui = ui, server = server)Coordinates
Gene coordinates can be displayed with the
GC_coordinates() function. When overlapping coordinates
occur, they are, by default, shifted to the top axis for clearer
visualization. By default the overlapThreshold parameter is
set to 20.
dbophA_cluster <- subset(ophA_clusters, cluster == "dbophA")
GC_chart(dbophA_cluster, group = "class",height = "100px") %>%
GC_coordinates(
rotate = -45,
yPositionTop = 55,
yPositionBottom = 45,
overlapThreshold = 20
) %>%
GC_legend(FALSE)The style of the ticks and text can be customized using the
tickStyle and textStyle variables. The scale
itself can only be changed using the GC_scale() function.
If you for instance want to use a reverse scale with displaying only the
coordinates you can set GC_scale to hidden.
GC_chart(dbophA_cluster, group = "class",height = "100px") %>%
GC_scale(hidden = TRUE, reverse = TRUE) %>%
GC_coordinates(
tickStyle = list(stroke = "grey", strokeWidth = 1, lineLength = 10),
textStyle = list(fill = "gray", fontSize = "10px", fontFamily = "Arial", cursor = "default")
) %>%
GC_legend(FALSE)By default, the start and end positions of each gene are indicated by
coordinates. However, you can customize these by providing your own
values for the top and bottom ticks, using the
tickValuesTop and tickValuesBottom options.
The ticksFormat parameter is used to define how the
numerical labels on the tick marks are formatted (see: link).
Scalebar
A scalebar can be added to the gene cluster chart using
GC_scaleBar(). This function, by default, displays a scale
bar of 1000 base pairs (bp) labeled as “1kb”.
GC_chart(ophA_clusters, group = "class", cluster = "cluster", height = "150px") %>%
GC_scaleBar(
title = "1kb",
scaleBarUnit = 1000
) %>%
GC_legend(FALSE)The scalebar’s position and label can be customized using the
x, y, and labelPosition
parameters. CSS styles can be added to modify the labels. The appearance
of the scalebar line and ticks is adjustable through the
scaleBarLine and scaleBarTick options.
GC_chart(ophA_clusters, group = "class", cluster = "cluster", height = "150px") %>%
GC_scaleBar(
title = "1kb",
scaleBarUnit = 1000,
cluster = NULL,
x = 0,
y = 0,
labelStyle = list(
labelPosition = "left",
fontSize = "10px",
fontFamily = "sans-serif",
fill = "black",
cursor = "default"
# Any other CSS style for the label
),
textPadding = 2,
scaleBarLineStyle = list(
stroke = "black",
strokeWidth = 1
# Any other CSS style for the line
),
scaleBarTickStyle = list(
stroke = "black",
strokeWidth = 1
# Any other CSS style for the tick
)
) %>%
GC_legend(y = 10) # Increase space Tooltip
By default, the tooltip in the gene chart displays the start and end
positions of a gene when hovering over it. These positions are
dynamically replaced by the actual start and end data values for each
gene. You can customize the text of the tooltip using the
formatter variable. In the example below, the tooltip is
customized to not only include the gene’s start and end positions but
also its name. The gene name is pulled from the ‘name’ column in the
data set.
To keep charts small, protein sequences (the translation
and sequence columns, e.g. from GenBank files) are only
sent to the browser when an option names them, such as
{translation} in the formatter.
GC_chart(ophA_cluster, group = "class", height = "150px") %>%
GC_tooltip(
formatter = "<b>Gene: </b>{name}<br><b>Start:</b> {start}<br><b>End:</b> {end}",
) %>%
GC_legend(FALSE)Saving Plots
You can save plots directly in the browser using the save button that
appears when hovering over the graph. Hover the download icon and choose
“Save as SVG” for a vector image that can be edited in e.g. Inkscape or
Illustrator and scaled for publications, or “Save as PNG” for an image
at screen resolution (make the chart larger for a larger PNG). This
option can be disabled by setting the save_button parameter
to FALSE in the GC_chart function, and its
icon and look changed with GC_toolbar() (see Toolbar). Elements moved in the chart (see Moving elements) are saved where they are. A
zoomed chart is saved as it shows, without the zoom slider (see Zoom).
Note: Saving as SVG is only available in the development version of geneviewer. Install it with
devtools::install_github("nvelden/geneviewer").
To save plots in different formats, you can use the
webshot2 package as illustrated below. If your plots
contain complex elements like gene links, it is recommended to specify
the width and height dimensions explicitly to ensure proper
rendering.
library(webshot2)
# Generate plot with width and height specifications
cluster_plot <-
GC_chart(ophA_clusters,
group = "class",
cluster = "cluster",
width = "400px", # Essential to prevent misalignment of gene links
height = "250px")
# Save plot to temp.html file
htmlwidgets::saveWidget(cluster_plot, "temp.html", selfcontained = TRUE)
# Save plot to .png (or .jpg, .jpeg, .webp, .pdf)
webshot2::webshot(
"temp.html",
"output.png",
zoom = 1, # Increase zoom for higher resolution
selector = ".geneviewer")