8000 GitHub - woosflex/gcvisualyst: This repository contains the source code of R package designed to analyze GC content of DNA sequences across sliding windows and visualize them in a line graph. This tool provides a simple and effective way to calculate GC content and generate plots that illustrate GC content variations along sequences. · GitHub
[go: up one dir, main page]

Skip to content

About

This repository contains the source code of R package designed to analyze GC content of DNA sequences across sliding windows and visualize them in a line graph. This tool provides a simple and effective way to calculate GC content and generate plots that illustrate GC content variations along sequences.

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

gcvisualyst

Live demo: gcvisualyst on shinyapps.io — try the interactive app (GC content, GC skew, CpG islands, CSV/BED export) in your browser.

The goal of gcvisualyst is to analyze and visualize the GC content of DNA sequences across sliding windows and detect CpG islands within these sequences. This tool provides a simple and effective way to calculate GC content, compute GC skew, identify CpG islands, and generate informative plots illustrating variations in GC content and CpG islands. It also ships an interactive Shiny web application.

Features:

  • GC Content Calculation: Computes the GC content of DNA sequences across sliding windows of user-defined size.
  • GC Skew Calculation: Computes the GC skew (G - C)/(G + C) of DNA sequences across sliding windows of user-defined size.
  • CpG Island Detection: Identifies regions with high GC content and CpG dinucleotide enrichment based on customizable thresholds, merging adjacent windows into continuous islands.
  • Data Visualization: Generates visualizations of GC content, GC skew, and CpG islands for multiple sequences, either combined in a single plot or as separate facets for each sequence.
  • Interactive Shiny App: Launches a bundled web application with run_app() to compute GC content, GC skew and CpG islands in your browser, and export results.
  • BED Export: Writes detected CpG islands to a UCSC-compatible BED track with write_bed() for downstream browser / pipeline use.
  • Customizable Plots: Provides options for combined or facet-wrapped layouts for easy comparison of multiple sequences.
  • Efficient Processing: Utilizes dplyr, ggplot2, stringr, and purrr for efficient data manipulation and plotting.

Installation

You can install the development version of gcvisualyst like so:

# install.packages("devtools")
devtools::install_github("woosflex/gcvisualyst")

Usage

Detecting CpG Islands

gcvisualyst can identify CpG islands within DNA sequences using the detect_cpg_islands() function. This function calculates GC content and the observed-to-expected CpG ratio within sliding windows. Regions meeting user-defined thresholds for both metrics are identified as CpG islands.

library(gcvisualyst)

# Demo DNA sequences
sequences_df <- data.frame(
  headers = c("seq1", "seq2"),
  sequences = c("ATCGCGATCGCGATCG", "CGATCGATCGCGCGAT"),
  stringsAsFactors = FALSE
)

# Detect CpG islands and generate a plot
cpg_plot <- detect_cpg_islands(sequences_df, window = 10, gc_threshold = 0.5, cpg_threshold = 0.6)
print(cpg_plot)

Visualizing GC Content

gcvisualyst can be used to generate combined plots where all sequences are plotted in a single graph by using the combined = TRUE argument in the gc_visualize() function:

# Demo DNA sequences
sequences_df <- data.frame(
  headers = c("seq1", "seq2"),
  sequences = c(
    "AGCTGCGCGTATCGTACGCGATCGTATCGCGATCGTATCGCG",
    "GGCGCGCTAGCTCGAGTCGCGCGGCTCGATAGCTCGTACGTAG"
  ),
  stringsAsFactors = FALSE
)

# Calculate GC content with a sliding window of 10
gc_content_df <- gc_content(sequences_df, window = 10)

# Visualize GC content
gc_visualize(gc_content_df, combined = TRUE)

Alternatively, you can generate separate plots for all sequences by using the default combined = FALSE parameter of the gc_visualize() function:

# Visualize GC content for each sequence
gc_visualize(gc_content_df)

Exporting CpG Islands to BED

Detected CpG islands (from cpg_islands()) can be written to a UCSC-compatible BED file with write_bed(). gcvisualyst reports 1-based, closed coordinates; write_bed() converts them to the 0-based, half-open coordinates BED expects (chromStart = start - 1, chromEnd = end) so the BED span matches the island length. A track name=... type=bed line is written first so the file can be uploaded directly to the UCSC Genome Browser:

library(gcvisualyst)

# Demo sequences producing a ~600 bp CpG island
sequences_df <- data.frame(
  headers = "s1",
  sequences = strrep("CG", 300),
  stringsAsFactors = FALSE
)

islands <- cpg_islands(sequences_df, window = 100, min_length = 200)
print(islands)
#>   header start end length mean_gc
#> 1     s1     1 600    600       1

# Write a BED track (returns the path invisibly)
write_bed(islands, path = tempfile(fileext = ".bed"))

Calculating GC Skew

gcvisualyst can compute the GC skew (G - C)/(G + C) across sliding windows of DNA sequences using the gc_skew() function, then visualize the results with gc_skew_visualize():

library(gcvisualyst)

# Demo DNA sequences
sequences_df <- data.frame(
  headers = c("seq1", "seq2"),
  sequences = c(
    "AGCTGCGCGTATCGTACGCGATCGTATCGCGATCGTATCGCG",
    "GGCGCGCTAGCTCGAGTCGCGCGGCTCGATAGCTCGTACGTAG"
  ),
  stringsAsFactors = FALSE
)

# Calculate GC skew with a sliding window of 10
skew_df <- gc_skew(sequences_df, window = 10)

# Visualize GC skew (facets)
gc_skew_visualize(skew_df)

Launch the Shiny App

gcvisualyst bundles an interactive Shiny web application that lets you enter DNA sequences or upload a FASTA file, then computes and visualizes GC content, GC skew and CpG islands for the same input in a browser. Launch it with run_app():

library(gcvisualyst)

# Launch the app on 127.0.0.1 at an automatically chosen port
run_app()

# Launch on a specific port and open a browser
run_app(port = 3838, launch.browser = TRUE)

The extended app adds controls for the CpG island thresholds (gc_threshold, cpg_threshold, min_length) and a shared window size, shows GC content and GC skew side by side in tabs, displays the detected islands in a summary table, and includes CSV and BED download buttons for the island results. Errors (such as a window larger than a sequence) are surfaced as messages instead of crashing the app. The bundled app ships inside the package and is resolved via system.file("shiny", package = "gcvisualyst").

Run the Shiny app with Docker

Self-host the bundled Shiny app:

docker build -t gcvisualyst -f docker/Dockerfile .
docker run -d --name gcvisualyst-app -p 3838:3838 gcvisualyst
# open http://localhost:3838/gcvisualyst/

Or with Compose: docker compose -f docker/docker-compose.yml up -d.

About

This repository contains the source code of R package designed to analyze GC content of DNA sequences across sliding windows and visualize them in a line graph. This tool provides a simple and effective way to calculate GC content and generate plots that illustrate GC content variations along sequences.

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

0