### Install ggtranscript from GitHub Source: https://dzhang32.github.io/ggtranscript/index.html Install the development version of ggtranscript from GitHub using devtools. Requires the devtools package to be installed first. ```R # you can install the development version of ggtranscript from GitHub: # install.packages("devtools") devtools::install_github("dzhang32/ggtranscript") ``` -------------------------------- ### Example: comparing transcripts to reference with to_diff() Source: https://dzhang32.github.io/ggtranscript/reference/to_diff.html Complete example demonstrating how to load the package, inspect example data, filter exons, identify a reference transcript, compute differences with to_diff(), and visualize the results using geom_range() and geom_intron(). ```r library(magrittr) library(ggplot2) # to illustrate the package's functionality # ggtranscript includes example transcript annotation sod1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31668931 + gene SOD1 NA #> 2 21 31659666 31668931 + transcript SOD1 SOD1-202 #> 3 21 31659666 31659784 + exon SOD1 SOD1-202 #> 4 21 31659770 31659784 + CDS SOD1 SOD1-202 #> 5 21 31659770 31659772 + start_codon SOD1 SOD1-202 #> 6 21 31663790 31663886 + exon SOD1 SOD1-202 #> # ℹ 1 more variable: transcript_biotype # extract exons sod1_exons <- sod1_annotation %>% dplyr::filter(type == "exon") sod1_exons %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31659784 + exon SOD1 SOD1-202 #> 2 21 31663790 31663886 + exon SOD1 SOD1-202 #> 3 21 31666449 31666518 + exon SOD1 SOD1-202 #> 4 21 31667258 31667375 + exon SOD1 SOD1-202 #> 5 21 31668471 31668931 + exon SOD1 SOD1-202 #> 6 21 31659693 31659841 + exon SOD1 SOD1-204 #> # ℹ 1 more variable: transcript_biotype # for this example, let's compare transcripts to the MANE-select transcript sod1_mane <- sod1_exons %>% dplyr::filter(transcript_name == "SOD1-201") sod1_not_mane <- sod1_exons %>% dplyr::filter(transcript_name != "SOD1-201") # to_diff() obtains the differences between the exons as ranges sod1_diffs <- to_diff( exons = sod1_not_mane, ref_exons = sod1_mane, group_var = "transcript_name" ) sod1_diffs %>% head() #> seqnames start end width strand type diff_type transcript_name #> 1 21 31659666 31659692 27 + diff not_in_ref SOD1-202 #> 2 21 31659785 31659841 57 + diff in_ref SOD1-202 #> 3 21 31661549 31661734 186 + diff not_in_ref SOD1-204 #> 4 21 31667342 31667375 34 + diff in_ref SOD1-204 #> 5 21 31668471 31668931 461 + diff in_ref SOD1-204 #> 6 21 31659693 31659708 16 + diff in_ref SOD1-203 # using geom_range(), it can be useful to visually overlay # the differences on top of the transcript annotation sod1_exons %>% ggplot(aes( xstart = start, xend = end, y = transcript_name )) + geom_range() + geom_intron( data = to_intron(sod1_exons, "transcript_name") ) + geom_range( data = sod1_diffs, ggplot2::aes(fill = diff_type), alpha = 0.2 ) ``` -------------------------------- ### Example: convert exons to introns and visualize Source: https://dzhang32.github.io/ggtranscript/reference/to_intron.html Complete example that loads required libraries, filters exons from the example annotation, converts them to introns using to_intron(), and visualizes the exons and introns with geom_range() and geom_intron(). ```r library(magrittr) library(ggplot2) # to illustrate the package's functionality # ggtranscript includes example transcript annotation sod1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31668931 + gene SOD1 NA #> 2 21 31659666 31668931 + transcript SOD1 SOD1-202 #> 3 21 31659666 31659784 + exon SOD1 SOD1-202 #> 4 21 31659770 31659784 + CDS SOD1 SOD1-202 #> 5 21 31659770 31659772 + start_codon SOD1 SOD1-202 #> 6 21 31663790 31663886 + exon SOD1 SOD1-202 #> # ℹ 1 more variable: transcript_biotype # extract exons sod1_exons <- sod1_annotation %>% dplyr::filter(type == "exon") sod1_exons %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31659784 + exon SOD1 SOD1-202 #> 2 21 31663790 31663886 + exon SOD1 SOD1-202 #> 3 21 31666449 31666518 + exon SOD1 SOD1-202 #> 4 21 31667258 31667375 + exon SOD1 SOD1-202 #> 5 21 31668471 31668931 + exon SOD1 SOD1-202 #> 6 21 31659693 31659841 + exon SOD1 SOD1-204 #> # ℹ 1 more variable: transcript_biotype # to_intron() is a helper function included in ggtranscript # which is useful for converting exon co-ordinates to introns sod1_introns <- sod1_exons %>% to_intron(group_var = "transcript_name") sod1_introns %>% head() #> # A tibble: 6 × 8 #> seqnames strand type gene_name transcript_name transcript_biotype start #> #> 1 21 + intron SOD1 SOD1-204 processed_transcript 31659841 #> 2 21 + intron SOD1 SOD1-202 protein_coding 31659784 #> 3 21 + intron SOD1 SOD1-204 processed_transcript 31661734 #> 4 21 + intron SOD1 SOD1-201 protein_coding 31659841 #> 5 21 + intron SOD1 SOD1-203 processed_transcript 31660708 #> 6 21 + intron SOD1 SOD1-202 protein_coding 31663886 #> # ℹ 1 more variable: end # this can be particular useful when combined with # geom_range() and geom_intron() # to visualize the core components of transcript annotation sod1_exons %>% ggplot(aes( xstart = start, xend = end, y = transcript_name )) + geom_range() + geom_intron( data = to_intron(sod1_exons, "transcript_name") ) ``` -------------------------------- ### Load libraries and inspect example data Source: https://dzhang32.github.io/ggtranscript/reference/geom_junction.html Loads magrittr and ggplot2, then displays the head of sod1_annotation and sod1_junctions to illustrate the package's example data. The annotation includes transcript features, and junctions originate from GTEx via snapcount. ```R library(magrittr) library(ggplot2) # to illustrate the package's functionality # ggtranscript includes example transcript annotation sod1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31668931 + gene SOD1 NA #> 2 21 31659666 31668931 + transcript SOD1 SOD1-202 #> 3 21 31659666 31659784 + exon SOD1 SOD1-202 #> 4 21 31659770 31659784 + CDS SOD1 SOD1-202 #> 5 21 31659770 31659772 + start_codon SOD1 SOD1-202 #> 6 21 31663790 31663886 + exon SOD1 SOD1-202 #> # ℹ 1 more variable: transcript_biotype # as well as a set of example (unannotated) junctions # originating from GTEx and downloaded via the Bioconductor package snapcount sod1_junctions #> # A tibble: 5 × 5 #> seqnames start end strand mean_count #> #> 1 chr21 31659787 31666448 + 0.463 #> 2 chr21 31659842 31660554 + 0.831 #> 3 chr21 31659842 31663794 + 0.316 #> 4 chr21 31659842 31667257 + 4.35 #> 5 chr21 31660351 31663789 + 0.324 ``` -------------------------------- ### Load libraries and inspect example annotation data Source: https://dzhang32.github.io/ggtranscript/reference/geom_range.html Loads magrittr and ggplot2, then displays the first rows of the sod1_annotation tibble to illustrate the package's example data structure. ```r library(magrittr) library(ggplot2) # to illustrate the package's functionality # ggtranscript includes example transcript annotation sod1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31668931 + gene SOD1 NA #> 2 21 31659666 31668931 + transcript SOD1 SOD1-202 #> 3 21 31659666 31659784 + exon SOD1 SOD1-202 #> 4 21 31659770 31659784 + CDS SOD1 SOD1-202 #> 5 21 31659770 31659772 + start_codon SOD1 SOD1-202 #> 6 21 31663790 31663886 + exon SOD1 SOD1-202 #> # ℹ 1 more variable: transcript_biotype ``` -------------------------------- ### Example: labeling junctions with geom_junction_label_repel Source: https://dzhang32.github.io/ggtranscript/reference/geom_junction_label_repel.html This example loads required libraries, inspects example data, extracts exons, adds transcript names to junctions, and creates a plot with geom_junction_label_repel to label junction counts. It uses the same junction.y.max parameter as geom_junction to ensure consistent curve midpoints. ```R library(magrittr) library(ggplot2) # to illustrate the package's functionality # ggtranscript includes example transcript annotation sod1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31668931 + gene SOD1 NA #> 2 21 31659666 31668931 + transcript SOD1 SOD1-202 #> 3 21 31659666 31659784 + exon SOD1 SOD1-202 #> 4 21 31659770 31659784 + CDS SOD1 SOD1-202 #> 5 21 31659770 31659772 + start_codon SOD1 SOD1-202 #> 6 21 31663790 31663886 + exon SOD1 SOD1-202 #> # ℹ 1 more variable: transcript_biotype # as well as a set of example (unannotated) junctions # originating from GTEx and downloaded via the Bioconductor package snapcount sod1_junctions #> # A tibble: 5 × 5 #> seqnames start end strand mean_count #> #> 1 chr21 31659787 31666448 + 0.463 #> 2 chr21 31659842 31660554 + 0.831 #> 3 chr21 31659842 31663794 + 0.316 #> 4 chr21 31659842 31667257 + 4.35 #> 5 chr21 31660351 31663789 + 0.324 # extract exons sod1_exons <- sod1_annotation %>% dplyr::filter( type == "exon", transcript_name == "SOD1-201" ) sod1_exons %>% head() #> # A tibble: 5 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659693 31659841 + exon SOD1 SOD1-201 #> 2 21 31663790 31663886 + exon SOD1 SOD1-201 #> 3 21 31666449 31666518 + exon SOD1 SOD1-201 #> 4 21 31667258 31667375 + exon SOD1 SOD1-201 #> 5 21 31668471 31668931 + exon SOD1 SOD1-201 #> # ℹ 1 more variable: transcript_biotype # add transcript_name to junctions for plotting sod1_junctions <- sod1_junctions %>% dplyr::mutate(transcript_name = "SOD1-201") # geom_junction_label_repel() can be used to label junctions base <- sod1_exons %>% ggplot(aes( xstart = start, xend = end, y = transcript_name )) + geom_range() + geom_intron( data = to_intron(sod1_exons, "transcript_name") ) # this can be useful to label junctions with their counts base + geom_junction( data = sod1_junctions, junction.y.max = 0.5 ) + geom_junction_label_repel( data = sod1_junctions, aes(label = round(mean_count, 2)), junction.y.max = 0.5 ) ``` -------------------------------- ### Load libraries and inspect example annotation Source: https://dzhang32.github.io/ggtranscript/reference/geom_intron.html Loads magrittr and ggplot2, then displays the first rows of the pknox1_annotation dataset included with ggtranscript to illustrate its structure. ```r library(magrittr) library(ggplot2) # to illustrate the package's functionality # ggtranscript includes example transcript annotation pknox1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 42974510 43033931 + gene PKNOX1 NA #> 2 21 42974510 43033931 + transcript PKNOX1 PKNOX1-203 #> 3 21 42974510 42974664 + exon PKNOX1 PKNOX1-203 #> 4 21 43004326 43004432 + exon PKNOX1 PKNOX1-203 #> 5 21 43007491 43007618 + exon PKNOX1 PKNOX1-203 #> 6 21 43013068 43013238 + exon PKNOX1 PKNOX1-203 #> # ℹ 1 more variable: transcript_biotype ``` -------------------------------- ### R example: add_utr() workflow with PKNOX1 annotation Source: https://dzhang32.github.io/ggtranscript/reference/add_utr.html This example demonstrates the full add_utr() workflow using the built-in pknox1_annotation dataset. It shows how to extract exons and CDS, manually add stop codons to the CDS (since Ensembl omits them), call add_utr() to generate UTR ranges, and optionally rescale introns with shorten_gaps() for visualization. The code includes output from head() calls showing the resulting tibbles. ```R library(magrittr) library(ggplot2) # to illustrate the package's functionality # ggtranscript includes example transcript annotation pknox1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 42974510 43033931 + gene PKNOX1 NA #> 2 21 42974510 43033931 + transcript PKNOX1 PKNOX1-203 #> 3 21 42974510 42974664 + exon PKNOX1 PKNOX1-203 #> 4 21 43004326 43004432 + exon PKNOX1 PKNOX1-203 #> 5 21 43007491 43007618 + exon PKNOX1 PKNOX1-203 #> 6 21 43013068 43013238 + exon PKNOX1 PKNOX1-203 #> # ℹ 1 more variable: transcript_biotype # extract exons pknox1_exons <- pknox1_annotation %>% dplyr::filter(type == "exon") pknox1_exons %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 42974510 42974664 + exon PKNOX1 PKNOX1-203 #> 2 21 43004326 43004432 + exon PKNOX1 PKNOX1-203 #> 3 21 43007491 43007618 + exon PKNOX1 PKNOX1-203 #> 4 21 43013068 43013238 + exon PKNOX1 PKNOX1-203 #> 5 21 43016908 43017007 + exon PKNOX1 PKNOX1-203 #> 6 21 43018133 43018230 + exon PKNOX1 PKNOX1-203 #> # ℹ 1 more variable: transcript_biotype # extract cds pknox1_cds <- pknox1_annotation %>% dplyr::filter(type == "CDS") pknox1_cds %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 43013068 43013238 + CDS PKNOX1 PKNOX1-203 #> 2 21 43016908 43017007 + CDS PKNOX1 PKNOX1-203 #> 3 21 43018133 43018230 + CDS PKNOX1 PKNOX1-203 #> 4 21 43021303 43021431 + CDS PKNOX1 PKNOX1-203 #> 5 21 43024871 43024947 + CDS PKNOX1 PKNOX1-203 #> 6 21 43028702 43028874 + CDS PKNOX1 PKNOX1-203 #> # ℹ 1 more variable: transcript_biotype # the CDS definition originating from the Ensembl reference annotation # does not include the stop codon # we must incorporate the stop codons into the CDS manually # by adding 3 base pairs to the end of the CDS of each transcript pknox1_cds_w_stop <- pknox1_cds %>% dplyr::group_by(transcript_name) %>% dplyr::mutate( end = ifelse(end == max(end), end + 3, end) ) %>% dplyr::ungroup() # add_utr() adds ranges that represent the UTRs pknox1_cds_utr <- add_utr( pknox1_exons, pknox1_cds_w_stop, group_var = "transcript_name" ) pknox1_cds_utr %>% head() #> # A tibble: 6 × 9 #> seqnames start end width strand transcript_name type gene_name #> #> 1 21 42974510 42974664 155 + PKNOX1-203 UTR NA #> 2 21 43004326 43004432 107 + PKNOX1-203 UTR NA #> 3 21 43007491 43007618 128 + PKNOX1-203 UTR NA #> 4 21 43013068 43013238 171 + PKNOX1-203 CDS PKNOX1 #> 5 21 43016908 43017007 100 + PKNOX1-203 CDS PKNOX1 #> 6 21 43018133 43018230 98 + PKNOX1-203 CDS PKNOX1 #> # ℹ 1 more variable: transcript_biotype # this can be useful when combined with shorten_gaps() # to visualize transcripts with long introns whilst differentiating UTRs pknox1_cds_utr_rescaled <- shorten_gaps( exons = pknox1_cds_utr, introns = to_intron(pknox1_cds_utr, "transcript_name"), group_var = "transcript_name" ) pknox1_cds_utr_rescaled %>% dplyr::filter(type == "CDS") %>% ggplot(aes( xstart = start, xend = end, y = transcript_name )) + geom_range() + geom_range( data = pknox1_cds_utr_rescaled %>% dplyr::filter(type == "UTR"), height = 0.25, fill = "white" ) + geom_intron( data = to_intron( pknox1_cds_utr_rescaled %>% dplyr::filter(type != "intron"), "transcript_name" ), arrow.min.intron.length = 110 ) ``` -------------------------------- ### Example workflow: add exon numbers and plot with ggplot2 Source: https://dzhang32.github.io/ggtranscript/reference/add_exon_number.html Complete example from the documentation. Loads libraries, inspects the sod1_annotation dataset, filters exons, adds exon numbers, creates a base plot with geom_range and geom_intron, and shows two annotation approaches: geom_text and ggrepel::geom_label_repel. Requires the 'strand' column and group_var for multiple transcripts. ```r library(magrittr) library(ggplot2) # to illustrate the package's functionality # ggtranscript includes example transcript annotation sod1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31668931 + gene SOD1 NA #> 2 21 31659666 31668931 + transcript SOD1 SOD1-202 #> 3 21 31659666 31659784 + exon SOD1 SOD1-202 #> 4 21 31659770 31659784 + CDS SOD1 SOD1-202 #> 5 21 31659770 31659772 + start_codon SOD1 SOD1-202 #> 6 21 31663790 31663886 + exon SOD1 SOD1-202 #> # ℹ 1 more variable: transcript_biotype # extract exons sod1_exons <- sod1_annotation %>% dplyr::filter(type == "exon") sod1_exons %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31659784 + exon SOD1 SOD1-202 #> 2 21 31663790 31663886 + exon SOD1 SOD1-202 #> 3 21 31666449 31666518 + exon SOD1 SOD1-202 #> 4 21 31667258 31667375 + exon SOD1 SOD1-202 #> 5 21 31668471 31668931 + exon SOD1 SOD1-202 #> 6 21 31659693 31659841 + exon SOD1 SOD1-204 #> # ℹ 1 more variable: transcript_biotype # add the exon number for each transcript sod1_exons <- sod1_exons %>% add_exon_number(group_var = "transcript_name") base <- sod1_exons %>% ggplot(aes( xstart = start, xend = end, y = transcript_name )) + geom_range() + geom_intron( data = to_intron(sod1_exons, "transcript_name"), strand = "+" ) # it can be useful to annotate exons with their exon number # using ggplot2::geom_text() base + geom_text(aes( x = (start + end) / 2, # plot label at midpoint of exon label = exon_number ), size = 3.5, nudge_y = 0.4 ) # Or alternatively, using ggrepel::geom_label_repel() # to separate labels from exons base + ggrepel::geom_label_repel(ggplot2::aes( x = (start + end) / 2, label = exon_number ), size = 3.5, min.segment.length = 0 ) ``` -------------------------------- ### Plot exons and introns with geom_range and geom_intron Source: https://dzhang32.github.io/ggtranscript/index.html Load required libraries and use ggtranscript's geom_range and geom_intron to plot exons and introns from example annotation data. The example uses the sod1_annotation dataset included with the package and converts exons to introns with to_intron(). ```R library(magrittr) library(dplyr) #> #> Attaching package: 'dplyr' #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union library(ggplot2) library(ggtranscript) # to illustrate the package's functionality # ggtranscript includes example transcript annotation sod1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31668931 + gene SOD1 #> 2 21 31659666 31668931 + transcript SOD1 SOD1-202 #> 3 21 31659666 31659784 + exon SOD1 SOD1-202 #> 4 21 31659770 31659784 + CDS SOD1 SOD1-202 #> 5 21 31659770 31659772 + start_codon SOD1 SOD1-202 #> 6 21 31663790 31663886 + exon SOD1 SOD1-202 #> # ℹ 1 more variable: transcript_biotype # extract exons sod1_exons <- sod1_annotation %>% dplyr::filter(type == "exon") sod1_exons %>% ggplot(aes( xstart = start, xend = end, y = transcript_name )) + geom_range( aes(fill = transcript_biotype) ) + geom_intron( data = to_intron(sod1_exons, "transcript_name"), aes(strand = strand) ) ``` -------------------------------- ### View PKNOX1 annotation data with head() Source: https://dzhang32.github.io/ggtranscript/articles/ggtranscript.html Displays the first rows of the pknox1_annotation tibble, showing the same required columns as the SOD1 example. The output is a tibble with 6 rows and 8 columns. ```r pknox1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 42974510 43033931 + gene PKNOX1 NA #> 2 21 42974510 43033931 + transcript PKNOX1 PKNOX1-203 #> 3 21 42974510 42974664 + exon PKNOX1 PKNOX1-203 #> 4 21 43004326 43004432 + exon PKNOX1 PKNOX1-203 #> 5 21 43007491 43007618 + exon PKNOX1 PKNOX1-203 #> 6 21 43013068 43013238 + exon PKNOX1 PKNOX1-203 #> # ℹ 1 more variable: transcript_biotype ``` -------------------------------- ### Import a BED file with rtracklayer::import.bed() Source: https://dzhang32.github.io/ggtranscript/articles/ggtranscript.html Imports a BED file using rtracklayer::import.bed(), creating a UCSCData object. The example uses the test BED file provided by rtracklayer. ```r # for the example, we'll use the test bed file provided by rtracklayer test_bed <- system.file("tests/test.bed", package = "rtracklayer") bed <- rtracklayer::import.bed(test_bed) class(bed) #> [1] "UCSCData" #> attr(,"package") #> [1] "rtracklayer" ``` -------------------------------- ### Create base plot with exons Source: https://dzhang32.github.io/ggtranscript/reference/geom_range.html Builds a ggplot object 'base' using sod1_exons with xstart, xend, and y aesthetics, which serves as the foundation for subsequent geom_range() and geom_half_range() examples. ```r base <- sod1_exons %>% ggplot(aes( xstart = start, xend = end, y = transcript_name )) ``` -------------------------------- ### Create base ggplot for introns Source: https://dzhang32.github.io/ggtranscript/reference/geom_intron.html Creates a ggplot object using the intron data, mapping xstart, xend, and y aesthetics. This base plot is used in subsequent examples. ```r base <- pknox1_introns %>% ggplot(aes( xstart = start, xend = end, y = transcript_name )) ``` -------------------------------- ### View SOD1 annotation data with head() Source: https://dzhang32.github.io/ggtranscript/articles/ggtranscript.html Displays the first rows of the sod1_annotation tibble, showing the required columns: seqnames, start, end, strand, type, gene_name, transcript_name, and transcript_biotype. The output is a tibble with 6 rows and 8 columns. ```r sod1_annotation %>% head() #> # A tibble: 6 × 8 #> seqnames start end strand type gene_name transcript_name #> #> 1 21 31659666 31668931 + gene SOD1 NA #> 2 21 31659666 31668931 + transcript SOD1 SOD1-202 #> 3 21 31659666 31659784 + exon SOD1 SOD1-202 #> 4 21 31659770 31659784 + CDS SOD1 SOD1-202 #> 5 21 31659770 31659772 + start_codon SOD1 SOD1-202 #> 6 21 31663790 31663886 + exon SOD1 SOD1-202 #> # ℹ 1 more variable: transcript_biotype ``` -------------------------------- ### Download and import a GTF file with rtracklayer::import() Source: https://dzhang32.github.io/ggtranscript/articles/ggtranscript.html Downloads a GTF file (Ensembl release 105) into a temporary directory and imports it into R using rtracklayer::import(). The resulting object is a GRanges object. ```r # download ens 105 gtf into a temporary directory gtf_path <- file.path(tempdir(), "Homo_sapiens.105.chr.gtf.gz") download.file( paste0( "http://ftp.ensembl.org/pub/release-105/gtf/homo_sapiens/", "Homo_sapiens.GRCh38.105.chr.gtf.gz" ), destfile = gtf_path ) gtf <- rtracklayer::import(gtf_path) class(gtf) #> [1] "GRanges" #> attr(,"package") #> [1] "GenomicRanges" ``` -------------------------------- ### Plot junction curves with geom_junction and geom_junction_label_repel Source: https://dzhang32.github.io/ggtranscript/index.html Adds junction curves and labels to a transcript plot using geom_junction and geom_junction_label_repel, with example junction data from GTEx. ```R # ggtranscript includes a set of example (unannotated) junctions # originating from GTEx and downloaded via the Bioconductor package snapcount sod1_junctions #> # A tibble: 5 × 5 #> seqnames start end strand mean_count #> #> 1 chr21 31659787 31666448 + 0.463 #> 2 chr21 31659842 31660554 + 0.831 #> 3 chr21 31659842 31663794 + 0.316 #> 4 chr21 31659842 31667257 + 4.35 #> 5 chr21 31660351 31663789 + 0.324 # add transcript_name to junctions for plotting sod1_junctions <- sod1_junctions %>% dplyr::mutate(transcript_name = "SOD1-201") sod1_201_exons %>% ggplot(aes( xstart = start, xend = end, y = transcript_name )) + geom_range( fill = "white", height = 0.25 ) + geom_range( data = sod1_201_cds ) + geom_intron( data = to_intron(sod1_201_exons, "transcript_name") ) + geom_junction( data = sod1_junctions, junction.y.max = 0.5 ) + geom_junction_label_repel( data = sod1_junctions, aes(label = round(mean_count, 2)), junction.y.max = 0.5 ) ``` -------------------------------- ### Load required libraries for ggtranscript Source: https://dzhang32.github.io/ggtranscript/articles/ggtranscript.html Loads magrittr, dplyr, ggtranscript, ggplot2, and rtracklayer. The output shows package startup messages and masking warnings from dplyr and Bioconductor packages. ```R library(magrittr) library(dplyr) #> #> Attaching package: 'dplyr' #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union library(ggtranscript) library(ggplot2) library(rtracklayer) #> Loading required package: GenomicRanges #> Loading required package: stats4 #> Loading required package: BiocGenerics #> #> Attaching package: 'BiocGenerics' #> The following objects are masked from 'package:dplyr': #> #> combine, intersect, setdiff, union #> The following objects are masked from 'package:stats': #> #> IQR, mad, sd, var, xtabs #> The following objects are masked from 'package:base': #> #> anyDuplicated, aperm, append, as.data.frame, basename, cbind, #> colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find, #> get, grep, grepl, intersect, is.unsorted, lapply, Map, mapply, #> match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, #> Position, rank, rbind, Reduce, rownames, sapply, setdiff, table, #> tapply, union, unique, unsplit, which.max, which.min #> Loading required package: S4Vectors #> #> Attaching package: 'S4Vectors' #> The following objects are masked from 'package:dplyr': #> #> first, rename #> The following object is masked from 'package:utils': #> #> findMatches #> The following objects are masked from 'package:base': #> #> expand.grid, I, unname #> Loading required package: IRanges #> #> Attaching package: 'IRanges' #> The following objects are masked from 'package:dplyr': #> #> collapse, desc, slice #> Loading required package: GenomeInfoDb #> #> Attaching package: 'GenomicRanges' #> The following object is masked from 'package:magrittr': #> #> subtract ``` -------------------------------- ### to_diff() function usage Source: https://dzhang32.github.io/ggtranscript/reference/to_diff.html Shows the function signature for to_diff(), which takes exons, ref_exons, and an optional group_var parameter. ```r to_diff(exons, ref_exons, group_var = NULL) ```