Skip to contents

E.coli Lac operon

Click to see the code
lacZ_operon <- data.frame(
  start = c(361249, 361926, 363231, 366428), 
  end = c(361860, 363179, 366305, 367510), 
  Gene_symbol = c("lacA", "lacY", "lacZ", "lacI"), 
  Strand = c("minus", "minus", "minus", "minus"), 
  NCBI_Gene_ID = as.character(c(945674, 949083, 945006, 945007)), 
  Description = c("galactoside O-acetyltransferase", 
                  "lactose permease", "beta-galactosidase", 
                  "DNA-binding transcriptional repressor LacI")
)

GC_chart(lacZ_operon, group = "Gene_symbol", height = "140px") %>%
  GC_labels() %>%
  GC_scaleBar(title = "0.2 kb", scaleBarUnit = 200, y=30) %>%
  GC_tooltip(
    formatter = "
    <b>ID:</b> {NCBI_Gene_ID}<br>
    <b>Description:</b> {Description}<br>
    <b>Start:</b> {start}<br>
    <b>End:</b> {end}",
  ) %>%
  GC_clusterFooter(
    align = "center",
    y = -30,
    subtitle = "<i>Escherichia coli</i> str. K-12 substr. MG1655" 
  ) %>%
  GC_coordinates(
    rotate = 0,
    tickValuesBottom = c(min(lacZ_operon$start), max(lacZ_operon$end)),
    textStyle = list(fontSize = "10px", x = -2.2, y = 1.2),
    tickStyle = list(lineLength = 10)
    ) %>%
  GC_legend(FALSE)

Omphalotin gene clusters

Click to see the code
  GC_chart(ophA_clusters, group = "class", cluster = "cluster") %>%
  GC_clusterFooter(
    title = c("<i>Omphalotus olearius</i>", "<i>Dendrothele bispora</i>"), 
    subtitle = c("Locus: 2,522 - 21,484", "Locus: 19,236 - 43,005"),
    align = "left") %>%
  GC_legend(position = "top") %>%
  GC_labels(label = "name") %>%
  GC_scaleBar(y = 20) %>%
  GC_scale(cluster = 1,  scale_breaks = TRUE, hidden = TRUE) %>%
  GC_scale(cluster = 2, reverse = TRUE, hidden = TRUE) %>%
  GC_tooltip(
    formatter = "<b>Gene:</b> {name}<br> <b>Start:</b> {start}<br><b>end:</b> {end}"
  ) %>%
  GC_theme("vintage")


Click to see the code
  GC_chart(ophA_clusters, 
           start = "start",
           end = "end",
           group = "class",
           cluster = "cluster") %>%
  GC_clusterFooter(
    title = c("<i>Omphalotus olearius</i>", "<i>Dendrothele bispora</i>"), 
    subtitle = c("Locus: 2,522 - 21,484", "Locus: 19,236 - 43,005"),
    align = "left") %>%
  GC_legend(position = "top") %>%
  GC_labels(label = "name") %>%
  GC_scaleBar(y = 20) %>%
  GC_scale(cluster = 1,  scale_breaks = TRUE, hidden = TRUE) %>%
  GC_scale(cluster = 2, reverse = TRUE, hidden = TRUE) %>%
  GC_theme("bw")


Click to see the code
  GC_chart(
    ophA_clusters,
    cluster = "cluster",
    group = "class",
    width = "800px",
    height = "400px"
  ) %>%
  GC_labels(
    cluster = 1,
    label = "name"
  ) %>%
  GC_links(
    "class",
    use_group_colors = FALSE,
    measure = "none",
    normal_color = "#969696",
    inverted_color = "#969696",
    curve = TRUE,
    label = FALSE,
    linkWidth = 0.2,
  ) %>%
  GC_links(
    group = "name",
    value1 = "ophA",
    value2 = "dbophA",
    use_group_colors = TRUE,
    linkStyle = list(
      stroke = "black",
      strokeWidth = 2
    )
  ) %>%
  GC_clusterLabel(
    title = c("<i>O.</i> <i>olearius</i>", "<i>D. bispora</i>"),
    wrapLabel = FALSE
  ) %>%
  # Reduce space between legend and cluster
  GC_grid(
    cluster = 2,
    height = "25%"
  ) %>%
  GC_legend(
    legendTextOptions = list(fontSize = "14px")
  ) %>%
  GC_annotation(
    cluster = 1,
    x = 10884,
    y = 11,
    type = "text",
    text = "90%",
    style = list(fontSize = "16px", fill = "#1c641c")
  ) %>%
  GC_trackMouse()


H. sapiens Hox genes using biomaRt

Click to see the code
# Get HOX gene positions 
library(biomaRt)

ensembl <- useMart("ensembl", dataset = "hsapiens_gene_ensembl")

hox_gene_sets <- list(
  HOXA = c("HOXA1", "HOXA2", "HOXA3", "HOXA4", "HOXA5", "HOXA6", "HOXA7", "HOXA9", "HOXA10", "HOXA11", "HOXA13"),
  HOXB = c("HOXB1", "HOXB2", "HOXB3", "HOXB4", "HOXB5", "HOXB6", "HOXB7", "HOXB8", "HOXB9", "HOXB13"),
  HOXC = c("HOXC4", "HOXC5", "HOXC6", "HOXC8", "HOXC9", "HOXC10", "HOXC11", "HOXC12", "HOXC13"),
  HOXD = c("HOXD1", "HOXD3", "HOXD4", "HOXD8", "HOXD9", "HOXD10", "HOXD11", "HOXD12", "HOXD13")
)

get_gene_positions <- function(gene_list, cluster_name) {

  result <- getBM(attributes = c('hgnc_symbol', 'chromosome_name', 'strand', 'start_position', 'end_position'),
                  filters = 'hgnc_symbol',
                  values = gene_list,
                  mart = ensembl)
  transform(result, cluster = cluster_name)
}

# Apply get_gene_positions to each gene set
hox_gene_positions <- base::lapply(names(hox_gene_sets), function(cluster_name) {
  get_gene_positions(hox_gene_sets[[cluster_name]], cluster_name)
})

# Combine the results into a single data frame
combined_hox_genes <- do.call(rbind, hox_gene_positions)

# Add gene names
combined_hox_genes$name <- paste0(substr(combined_hox_genes$hgnc_symbol, 1, 3), substr(combined_hox_genes$hgnc_symbol, 5, nchar(combined_hox_genes$hgnc_symbol)))
GC_chart(
  combined_hox_genes,
  start = "start_position",
  end = "end_position",
  group = "cluster",
  strand = "strand",
  cluster = "cluster",
  height = "400px") %>%
  GC_clusterLabel() %>%
  GC_legend(FALSE) %>%
  GC_genes(
    marker = "boxarrow",
    markerHeight = 10,
    arrowheadHeight = 10,
    arrowheadWidth = 6
  ) %>%
  GC_labels("name", fontSize = "10px") %>%
  GC_scale(cluster = c(1, 2), hidden = TRUE, reverse = TRUE) %>%
  GC_cluster(prevent_gene_overlap = TRUE) %>%
  GC_theme("dark")


BRCA1 splice variants

Click to see the code
GC_chart(BRCA1_splice_variants, height = "600px") %>%
  GC_transcript(
    transcript = "ensembl_transcript_id", 
    strand = "strand", 
    type = "type",
  ) %>%
  GC_clusterTitle(
    title = unique(BRCA1_splice_variants$ensembl_transcript_id),
    titleFont = list(
      fontSize = "12px"
    )
  ) %>%
  GC_clusterFooter(
    title = c("0.8%", "0.1%", "0.07%", "0.02%", "0.01%"),
    align = "center"
  ) %>%
  GC_theme("infographic", textColor = "#333333")

Saccharopolyspora erythraea Erythromycin

Click to see the code
GC_chart(erythromycin_cluster,
         start = "Start",
         end = "End",
         group = "Functions",
         height = "170px") %>%
  GC_title(
    title = "Erythromycin A biosynthetic gene cluster from <i>Saccharopolyspora erythraea</i>",
    align = "left"
  ) %>%
  GC_genes(marker = "boxarrow", marker_size = "small") %>%
  GC_tooltip(
    formatter = "<b>{Identifiers}</b><br>{Product}<br>{start} - {end}({Strand})"
  ) %>%
  GC_scale(start = 778000, end = 832000, ticksCount = 8) %>%
  GC_legend(order = c(setdiff(sort(erythromycin_cluster$Functions), "Other"), "Other")) %>%
  GC_color(customColors = list(Other = "grey")) %>%
  GC_theme("classic")


Saccharopolyspora erythraea Erythromycin BlastP

Click to see the code
### Erythromycin BlastP
# Genes without a BlastP hit have no function: give them their own group
blastp <- erythromycin_BlastP
blastp$Functions[is.na(blastp$Functions)] <- "No Hit"

GC_chart(blastp, 
         cluster = "cluster",
         strand = "strand",
         group = "Functions",
         height = 700) %>%
  GC_title(
    title = "BlastP Results"
  ) %>%
  GC_labels("Gene", cluster = 1) %>%
  GC_links(group = "Gene", 
           show_links = FALSE,
           color_bar = FALSE,
           labelStyle = list(fontSize = "10px")
           ) %>%
  GC_clusterLabel() %>%
  GC_genes(stroke = "#6E7079", strokeWidth = 0.5) %>%
  GC_legend(order = c(setdiff(sort(unique(blastp$Functions)), "No Hit"), "No Hit")) %>%
  GC_color(customColors = list("No Hit" = "white")) %>%
  GC_theme("infographic", textColor = "#333333", palette = "okabeIto")
Click to see the code
library(dplyr)
### Erythromycin BlastP
# Genes without a BlastP hit have no function: give them their own group
blastp <- erythromycin_BlastP %>% dplyr::filter(cluster %in% c("BGC0000055", "BGC0000054"))
blastp$Functions[is.na(blastp$Functions)] <- "No Hit"

GC_chart(blastp, 
         cluster = "cluster",
         strand = "strand",
         group = "Functions",
         height = 250) %>%
  GC_labels("Gene", cluster = 1) %>%
  GC_genes(marker_size = "small", marker = "rbox", markerHeight = 15,
           stroke = "#6E7079", strokeWidth = 0.5) %>%
  GC_links(group = "BlastP", 
           label = FALSE,
           color_bar = FALSE
           ) %>%
  GC_clusterLabel() %>%
  GC_legend(FALSE) %>%
  GC_color(customColors = list("No Hit" = "white")) %>%
  GC_theme("classic", textColor = "#333333", palette = "okabeIto")

blaKPC-2 plasmid pQEB1 and its variants

Click to see the code
plasmids <- dplyr::distinct(pQEB1_plasmids, cluster, host)
colors <- list(
  "Carbapenemase (KPC)" = "#d62728",
  "Other resistance" = "#ff7f0e",
  "Arsenic resistance" = "#8c564b",
  "Mobile element" = "#9467bd",
  "Conjugation" = "#1f77b4",
  "Replication & maintenance" = "#2ca02c",
  "Hypothetical" = "#d9d9d9",
  "Other" = "#9e9e9e"
)

GC_chart(pQEB1_plasmids, cluster = "cluster", group = "category",
         strand = "strand", height = "760px") %>%
  GC_links(data = pQEB1_alignment, measure = "none", label = FALSE,
           color_bar = FALSE, normal_color = "#7f9cbf",
           inverted_color = "#e6894e") %>%
  GC_genes(marker_size = "small") %>%
  GC_scale(axis_type = "range") %>%
  GC_clusterLabel(
    title = plasmids$cluster,
    subtitle = plasmids$host,
    width = "175px",
    fontSize = "13px",
    subtitleFont = list(fontSize = "12px", fontStyle = "italic"),
    align = "right",
    x = -10
  ) %>%
  GC_title(
    "<i>bla</i>KPC-2 plasmid pQEB1 and its rearranged variants",
    subtitle = paste("IncN plasmids aligned with nucmer",
                     "(all blocks \u2265 99.2% identity);",
                     "orange links mark inversions"),
    height = "70px",
    titleFont = list(fontSize = "20px", fontWeight = "bold"),
    subtitleFont = list(fontSize = "15px", fontStyle = "italic")
  ) %>%
  GC_tooltip(formatter = "<b>{gene}</b> {product}<br>{start} - {end}") %>%
  GC_color(customColors = colors) %>%
  GC_legend(position = "top", align = "center", order = names(colors),
            legendTextOptions = list(fontSize = "14px")) %>%
  GC_theme("publication")

Tn7-like transposons carrying a CRISPR-Cas system

Redrawn from Figure 3 of Peters et al. (2017). The tutorial builds this chart step by step.

Click to see the code
# The element ends are single positions in the data. They are drawn as tall
# bars, the way the inverted repeats at the ends of a transposon are often
# drawn: 100 bp wide, from the end into the element, so they stay clear of the
# gene next to them.
genes <- tn7_crispr_elements %>%
  dplyr::mutate(end = ifelse(gene == "R", end + 100, end),
                start = ifelse(gene == "L", start - 100, start))

elements <- dplyr::distinct(genes, cluster, strain_short)

colors <- list(
  "insertion site" = "#F3C79B",
  "tnsA" = "#D62728",
  "tnsB" = "#AEB6F0",
  "tnsC" = "#D7F2F2",
  "tniQ / tnsD" = "#2CA02C",
  "tnsE" = "#C7E02C",
  "cas8f / cas5f" = "#8C1515",
  "cas7f" = "#F2A5C4",
  "cas6f" = "#7B3FD4",
  "cas5" = "#B5651D",
  "cas, other" = "#C9A0DC",
  "CRISPR array" = "#555555",
  "right end" = "#9FD4DE",
  "left end" = "#F28E2B",
  "other" = "#E8E8E8"
)

# In the legend the gene names are italic, the other entries upright
gene_names <- c("tnsA", "tnsB", "tnsC", "tniQ / tnsD", "tnsE", "cas8f / cas5f",
                "cas7f", "cas6f", "cas5")
legend_styles <- lapply(stats::setNames(nm = gene_names),
                        function(x) list(fontStyle = "italic"))

# The labels by their text: white on the dark genes, and above the SRP RNA
# genes, which are too short for it, ending clear of the right end beside them
white <- list(fill = "white")
label_styles <- list(
  tnsA = white, cas8f = white, cas6f = white, cas5 = white,
  "SRP-RNA" = list(y = 55, dy = "0px", textAnchor = "end", x = -4)
)

# By gene: the ends (R and L) are tall bars, the CRISPR arrays and the fused
# tnsA boxes the height of the genes
end_bar <- list(marker = "box", markerHeight = 38, arrowheadHeight = 38)
gene_box <- list(marker = "box", markerHeight = 20, arrowheadHeight = 20)
shapes <- list(
  R = end_bar,
  L = end_bar,
  CRISPR = c(gene_box, stroke = "black", strokeWidth = 1),
  "tnsA (fused)" = gene_box
)

chart <- GC_chart(genes, cluster = "cluster", group = "category",
                  strand = "strand", height = "900px") %>%
  # tall arrows, with the labels inside them
  GC_genes(marker_size = "small", markerHeight = 20,
           style_by = "gene", groupStyle = shapes) %>%
  GC_labels(label = "label", fontSize = "9px", y = 50, dy = "14.5px",
            adjustLabels = FALSE, style_by = "label", groupStyle = label_styles) %>%
  # most elements run on far beyond the genes shown, up to ~100 kb: scale breaks
  # (//) leave out such long stretches, as in the published figure
  GC_scale(axis_type = "range", hidden = TRUE, scale_breaks = TRUE,
           scale_break_padding = "500bp") %>%
  # line the elements up on their right end, as in the published figure
  GC_align("gene", "R", align = "left") %>%
  GC_clusterLabel(
    title = elements$cluster,
    subtitle = elements$strain_short,
    width = "190px",
    fontSize = "12px",
    subtitleFont = list(fontSize = "10px", fontStyle = "italic"),
    align = "right",
    x = -10
  ) %>%
  GC_title(
    "Tn7-like transposons that carry a minimal CRISPR-Cas system",
    subtitle = paste("Redrawn from Fig. 3 of Peters et al. (2017),",
                     "Proc Natl Acad Sci USA 114:E7358-E7366"),
    height = "70px",
    titleFont = list(fontSize = "19px", fontWeight = "bold"),
    subtitleFont = list(fontSize = "14px", fontStyle = "italic")
  ) %>%
  GC_tooltip(formatter = "<b>{gene}</b> {product}<br>{start} - {end}") %>%
  GC_color(customColors = colors) %>%
  # the two ends share a pattern and are told apart by their colour
  GC_pattern(patterns = list("right end" = "diagonal", "left end" = "diagonal"),
             background = NULL, size = 4) %>%
  GC_legend(position = "bottom", align = "center", order = names(colors),
            legendTextOptions = list(fontSize = "12px"),
            groupStyle = legend_styles) %>%
  GC_theme("publication")

chart