rGenomeTracks package leverages the power of pyGenomeTracks software with the interactivity of R. pyGenomeTracks is a python software that offers robust method for visualizing epigenetic data files like narrowPeak, Hic matrix, TADs and arcs, however though, here is no way currently to use it within R interactive session. rGenomeTracks wrapped the whole functionality of pyGenomeTracks with additional utilites to make to more pleasant for R users.
# loading the rGenomeTracks
library(rGenomeTracks)
# loading example data
#library(rGenomeTracksData)
You should have pyGenomeTracks installed on R’s loading environment.
To avoid dependency clash, we highly recommend using
install_pyGenomeTracks()
. That way, you ensure using the
tested pyGenomeTracks version with the current release. rGenomeTracks is
supposed to automatically prompt you to install this dependency after
running plot_gtracks()
. If this step failed, you can
manually install pyGenomeTracks with
install_pyGenomeTracks()
install_pyGenomeTracks()
rGenomeTracks deals creates tracks in a class
genome_track
. Currently, there are 14 tracks available: 1.
track_bed() 2. track_bedgraph() 3. track_bedgraph_matrix() 4.
track_gtf() 5. track_hlines() 6. track_vlines() 7. track_spacer() 8.
track_bigwig() 9. track_epilogos() 10. track_narrowPeak() 11.
track_domains() 12. track_hic_matrix() 13. track_links() 14.
track_scalebar() 15. track_x_axis()
Please refer to the help page for each one of them for details and examples.
We will download .h5 matrix and store the location in temporary directory for demonstration.
# Download h5 example
<- AnnotationHub()
ah query(ah, "rGenomeTracksData")
<- ah[["AH95901"]]
h5_dir
# Create HiC track from HiC matrix
<- track_hic_matrix(
h5 file = h5_dir, depth = 250000, min_value = 5, max_value = 200,
transform = "log1p", show_masked_bins = FALSE
)
Other demonstration for TADS, arcs and bigwig data will be loaded from the built-in package example data.
# Load other examples
<- system.file("extdata", "tad_classification.bed", package = "rGenomeTracks")
tads_dir <- system.file("extdata", "links2.links", package = "rGenomeTracks")
arcs_dir <- system.file("extdata", "bigwig2_X_2.5e6_3.5e6.bw", package = "rGenomeTracks")
bw_dir
# Create TADS track
<- track_domains(
tads file = tads_dir, border_color = "black",
color = "none", height = 5,
line_width = 5,
show_data_range = FALSE,
overlay_previous = "share-y"
)
# Create arcs track
<- track_links(
arcs file = arcs_dir, links_type = "triangles",
line_style = "dashed",
overlay_previous = "share-y",
color = "darkred",
line_width = 3,
show_data_range = FALSE
)
# Create bigwig track
<- track_bigwig(
bw file = bw_dir, color = "red",
max_value = 50,
min_value = 0,
height = 4,
overlay_previous = "no",
show_data_range = FALSE
)
genome_track
objects can be added together using
+
function.
# Create one object from HiC, arcs and bigwid
<- tads + arcs + bw tracks
The track(s) to be plotted is to be passed to
plot_gtracks()
for the generation of the plot.
Additionally, plot_gtracks()
requires the genomic region to
be plotted. Optionally, you can set plot title, dpi, width, height,
fontsize, track-to-label fraction, label alignment position, and
directory to save the plot.
# Plot the tracks
## Note to verify installing miniconda if not installed.
layout(matrix(c(1,1,2,3,4,4), nrow = 3, ncol = 2, byrow = TRUE))
plot_gtracks(tracks, chr = "X", start = 25 * 10^5, end = 31 * 10^5)
# Plot HiC, TADS and bigwig tracks
plot_gtracks(h5 + tads + bw, chr = "X", start = 25 * 10^5, end = 31 * 10^5)
If you have tracks with the same format, you can import them quickly by using lapply() and reduce() functions.
<- list.files(system.file("extdata", package = "rGenomeTracks"), full.names = TRUE)
dirs
# filter only bed files (without bedgraphs or narrowpeaks)
<- grep(
bed_dirs pattern = ".bed(?!graph)", perl = TRUE, value = TRUE)
dirs,
<- lapply(bed_dirs, track_bed)
bed_list
<- Reduce("+", bed_list) bed_tracks
You can repeat this process for tracks of same category then pass the tracks to plot_gtracks()
You may choose create a complex figure using layout() and split.screen() function then save the device.
Note that you cannot make use of dir argument in plot_gtracks() if you used this method as it is passed to pyGenomeTracks. So, you have to capture R’s graphic device and save it manually.
sessionInfo()
#> R version 4.2.1 Patched (2022-07-09 r82577)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur ... 10.16
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
#>
#> locale:
#> [1] C/en_US.UTF-8/en_US.UTF-8/C/en_GB/en_US.UTF-8
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] rGenomeTracks_1.4.0
#>
#> loaded via a namespace (and not attached):
#> [1] igraph_1.3.5 Rcpp_1.0.9 rGenomeTracksData_0.99.0
#> [4] knitr_1.40 magrittr_2.0.3 lattice_0.20-45
#> [7] R6_2.5.1 jpeg_0.1-9 rlang_1.0.6
#> [10] fastmap_1.1.0 highr_0.9 stringr_1.4.1
#> [13] tools_4.2.1 grid_4.2.1 xfun_0.34
#> [16] png_0.1-7 cli_3.4.1 jquerylib_0.1.4
#> [19] htmltools_0.5.3 yaml_2.3.6 digest_0.6.30
#> [22] Matrix_1.5-1 bmp_0.3 purrr_0.3.5
#> [25] sass_0.4.2 cachem_1.0.6 evaluate_0.17
#> [28] tiff_0.1-11 rmarkdown_2.17 readbitmap_0.1.5
#> [31] stringi_1.7.8 compiler_4.2.1 bslib_0.4.0
#> [34] imager_0.42.13 reticulate_1.26 jsonlite_1.8.3
#> [37] pkgconfig_2.0.3