Biomarker Analysis Catalog - Dev
  • Dev
    • Stable
  1. Graphs
  2. RNAG
  3. RNAG6
  • Index

  • Tables
    • CPMT
      • CPMT1
      • CPMT2
        • CPMT2A
      • CPMT3
    • DT
      • DT1
        • DT1A
        • DT1B
        • DT1C
      • DT2
        • DT2A
    • TET
      • TET1
        • TET1A

  • Graphs
    • AG
      • AG1
    • DG
      • DG1
        • DG1A
        • DG1B
      • DG2
      • DG3
        • DG3A
      • DG4
    • KG
      • KG1
        • KG1A
        • KG1B
      • KG2
        • KG2A
      • KG3
      • KG4
        • KG4A
        • KG4B
      • KG5
        • KG5A
        • KG5B
    • RFG
      • RFG1
        • RFG1A
      • RFG2
        • RFG2A
        • RFG2B
        • RFG2C
      • RFG3
    • RG
      • RG1
        • RG1A
        • RG1B
        • RG1C
      • RG2
        • RG2A
      • RG3
        • RG3A
        • RG3B
    • SPG
      • SPG1
      • SPG2
    • RNAG
      • RNAG1
      • RNAG2
      • RNAG3
      • RNAG4
      • RNAG5
      • RNAG6
      • RNAG7
      • RNAG8
      • RNAG9
      • RNAG10
    • SFG
      • SFG1
        • SFG1A
        • SFG1B
      • SFG2
        • SFG2A
        • SFG2B
        • SFG2C
        • SFG2D
      • SFG3
        • SFG3A
      • SFG4
      • SFG5
        • SFG5A
        • SFG5B
        • SFG5C
      • SFG6
        • SFG6A
        • SFG6B
        • SFG6C
  1. Graphs
  2. RNAG
  3. RNAG6

RNAG6

RNAseq Barplot

RNAG

  • Setup: Import, Filter and Normalize
  • Barplot for a Single Gene
  • Barplot for Gene Signatures
  • Additional Options for Customization
  • Teal Module for Barplot
  • Session Info

This page can be used as a template of how to use the available hermes functions to produce a barplot of the dichotomized gene expression counts into two or three categories based on custom defined percentiles.

The draw_barplot() function used below needs HermesData as input. See RNAG1 for details on how to import, filter and normalize HermesData.

Code
library(hermes)
object <- hermes_data %>%
  add_quality_flags() %>%
  filter() %>%
  normalize()

We can create a barplot for gene expression counts of single genes by specifying a gene in the gene_spec (gene specification) as follows. This function creates a scatterplot with the default percentiles (0.33, 0.67), to specify custom percentiles, please use the percentile argument.

Code
draw_barplot(
  object = object,
  assay_name = "counts",
  x_spec = gene_spec(genes(object)[1])
)

We can also specify a gene summary function for multiple genes, thereby using the corresponding gene signature. Note that here we just want to use the first 3 genes from the object without explicitly specifying the gene IDs, and this can be done through the genes() function in hermes.

Code
draw_barplot(
  object = object,
  assay_name = "counts",
  x_spec = gene_spec(
    genes(object)[1:3],
    fun = colMeans,
    fun_name = "Median"
  )
)

It is also possible to pass additional arguments to the function draw_barplot(), ex. if we wish to specify an optional faceting variable or optional fill variable. See ?hermes::draw_barplot() for details about the additional parameters available.

Code
draw_barplot(
  object = object,
  assay_name = "counts",
  x_spec = gene_spec(
    genes(object)[1:3],
    fun = colMeans,
    fun_name = "Median"
  ),
  facet_var = "SEX",
  fill_var = "AGE18"
)

Code
draw_barplot(
  object = object,
  assay_name = "counts",
  x_spec = gene_spec(
    genes(object)[1:3],
    fun = colMeans,
    fun_name = "Median"
  ),
  facet_var = "SEX",
  fill_var = "AGE18",
  percentiles = c(0.1, 0.9)
)

We start by importing a MultiAssayExperiment; here we use the example multi_assay_experiment available in hermes. It is wrapped as a teal::dataset. We can then use the provided teal module tm_g_barplot to have add a barplot module in our teal app.

Code
library(teal.modules.hermes)

data <- teal_data()
data <- within(data, {
  library(hermes)
  MAE <- multi_assay_experiment
})
datanames(data) <- "MAE"

app <- init(
  data = data,
  modules = modules(
    tm_g_barplot(
      label = "barplot",
      mae_name = "MAE"
    )
  )
)
shinyApp(app$ui, app$server)
Warning: 'experiments' dropped; see 'drops()'

Code
sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] teal.modules.hermes_0.1.6.9020 teal_0.15.2.9061              
 [3] teal.slice_0.5.1.9011          teal.data_0.6.0.9010          
 [5] teal.code_0.5.0.9009           shiny_1.9.1                   
 [7] hermes_1.7.2.9002              SummarizedExperiment_1.34.0   
 [9] Biobase_2.64.0                 GenomicRanges_1.56.1          
[11] GenomeInfoDb_1.40.1            IRanges_2.38.1                
[13] S4Vectors_0.42.1               BiocGenerics_0.50.0           
[15] MatrixGenerics_1.16.0          matrixStats_1.4.1             
[17] ggfortify_0.4.17               ggplot2_3.5.1                 

loaded via a namespace (and not attached):
  [1] RColorBrewer_1.1-3          jsonlite_1.8.8             
  [3] shape_1.4.6.1               MultiAssayExperiment_1.30.3
  [5] magrittr_2.0.3              farver_2.1.2               
  [7] rmarkdown_2.28              GlobalOptions_0.1.2        
  [9] zlibbioc_1.50.0             vctrs_0.6.5                
 [11] memoise_2.0.1               webshot_0.5.5              
 [13] BiocBaseUtils_1.7.3         htmltools_0.5.8.1          
 [15] S4Arrays_1.4.1              forcats_1.0.0              
 [17] progress_1.2.3              curl_5.2.2                 
 [19] SparseArray_1.4.8           sass_0.4.9                 
 [21] parallelly_1.38.0           bslib_0.8.0                
 [23] fontawesome_0.5.2           htmlwidgets_1.6.4          
 [25] testthat_3.2.1.1            httr2_1.0.3                
 [27] cachem_1.1.0                teal.widgets_0.4.2.9020    
 [29] mime_0.12                   lifecycle_1.0.4            
 [31] iterators_1.0.14            pkgconfig_2.0.3            
 [33] webshot2_0.1.1              Matrix_1.7-0               
 [35] R6_2.5.1                    fastmap_1.2.0              
 [37] future_1.34.0               GenomeInfoDbData_1.2.12    
 [39] rbibutils_2.2.16            clue_0.3-65                
 [41] digest_0.6.37               colorspace_2.1-1           
 [43] shinycssloaders_1.1.0       ps_1.8.0                   
 [45] AnnotationDbi_1.66.0        DESeq2_1.44.0              
 [47] RSQLite_2.3.7               filelock_1.0.3             
 [49] labeling_0.4.3              fansi_1.0.6                
 [51] httr_1.4.7                  abind_1.4-8                
 [53] compiler_4.4.1              bit64_4.0.5                
 [55] withr_3.0.1                 doParallel_1.0.17          
 [57] backports_1.5.0             BiocParallel_1.38.0        
 [59] DBI_1.2.3                   logger_0.3.0               
 [61] biomaRt_2.60.1              rappdirs_0.3.3             
 [63] DelayedArray_0.30.1         rjson_0.2.22               
 [65] chromote_0.3.1              tools_4.4.1                
 [67] httpuv_1.6.15               glue_1.7.0                 
 [69] callr_3.7.6                 promises_1.3.0             
 [71] grid_4.4.1                  checkmate_2.3.2            
 [73] cluster_2.1.6               generics_0.1.3             
 [75] gtable_0.3.5                websocket_1.4.2            
 [77] tidyr_1.3.1                 hms_1.1.3                  
 [79] xml2_1.3.6                  utf8_1.2.4                 
 [81] XVector_0.44.0              ggrepel_0.9.6              
 [83] foreach_1.5.2               pillar_1.9.0               
 [85] stringr_1.5.1               limma_3.60.4               
 [87] later_1.3.2                 circlize_0.4.16            
 [89] dplyr_1.1.4                 BiocFileCache_2.12.0       
 [91] lattice_0.22-6              bit_4.0.5                  
 [93] tidyselect_1.2.1            ComplexHeatmap_2.20.0      
 [95] locfit_1.5-9.10             Biostrings_2.72.1          
 [97] knitr_1.48                  gridExtra_2.3              
 [99] teal.logger_0.2.0.9009      edgeR_4.2.1                
[101] xfun_0.47                   statmod_1.5.0              
[103] brio_1.1.5                  stringi_1.8.4              
[105] UCSC.utils_1.0.0            yaml_2.3.10                
[107] shinyWidgets_0.8.6          evaluate_0.24.0            
[109] codetools_0.2-20            tibble_3.2.1               
[111] cli_3.6.3                   xtable_1.8-4               
[113] Rdpack_2.6.1                jquerylib_0.1.4            
[115] processx_3.8.4              munsell_0.5.1              
[117] teal.reporter_0.3.1.9015    Rcpp_1.0.13                
[119] globals_0.16.3              dbplyr_2.5.0               
[121] png_0.1-8                   parallel_4.4.1             
[123] assertthat_0.2.1            blob_1.2.4                 
[125] prettyunits_1.2.0           listenv_0.9.1              
[127] scales_1.3.0                purrr_1.0.2                
[129] crayon_1.5.3                GetoptLong_1.0.5           
[131] rlang_1.1.4                 formatR_1.14               
[133] KEGGREST_1.44.1             shinyjs_2.1.0              

Reuse

Copyright 2023, Hoffmann-La Roche Ltd.
RNAG5
RNAG7
Source Code
---
title: RNAG6
subtitle: RNAseq Barplot
categories: [RNAG]
---

------------------------------------------------------------------------

{{< include ../misc/hooks.qmd >}}

::: panel-tabset
## Setup: Import, Filter and Normalize

This page can be used as a template of how to use the available `hermes` functions to produce a barplot of the dichotomized gene expression counts into two or three categories based on custom defined percentiles.

The `draw_barplot()` function used below needs `HermesData` as input.
See [RNAG1](../graphs/rnag01.qmd) for details on how to import, filter and normalize `HermesData`.

```{r, message = FALSE}
library(hermes)
object <- hermes_data %>%
  add_quality_flags() %>%
  filter() %>%
  normalize()
```

## Barplot for a Single Gene

We can create a barplot for gene expression counts of single genes by specifying a gene in the `gene_spec` (gene specification) as follows.
This function creates a scatterplot with the default percentiles (0.33, 0.67), to specify custom percentiles, please use the `percentile` argument.

```{r}
draw_barplot(
  object = object,
  assay_name = "counts",
  x_spec = gene_spec(genes(object)[1])
)
```

## Barplot for Gene Signatures

We can also specify a gene summary function for multiple genes, thereby using the corresponding gene signature.
Note that here we just want to use the first 3 genes from the `object` without explicitly specifying the gene IDs, and this can be done through the `genes()` function in `hermes`.

```{r}
draw_barplot(
  object = object,
  assay_name = "counts",
  x_spec = gene_spec(
    genes(object)[1:3],
    fun = colMeans,
    fun_name = "Median"
  )
)
```

## Additional Options for Customization

It is also possible to pass additional arguments to the function `draw_barplot()`, ex.
if we wish to specify an optional faceting variable or optional fill variable.
See `?hermes::draw_barplot()` for details about the additional parameters available.

```{r}
draw_barplot(
  object = object,
  assay_name = "counts",
  x_spec = gene_spec(
    genes(object)[1:3],
    fun = colMeans,
    fun_name = "Median"
  ),
  facet_var = "SEX",
  fill_var = "AGE18"
)
```

```{r}
draw_barplot(
  object = object,
  assay_name = "counts",
  x_spec = gene_spec(
    genes(object)[1:3],
    fun = colMeans,
    fun_name = "Median"
  ),
  facet_var = "SEX",
  fill_var = "AGE18",
  percentiles = c(0.1, 0.9)
)
```

## Teal Module for Barplot

We start by importing a `MultiAssayExperiment`; here we use the example `multi_assay_experiment` available in `hermes`.
It is wrapped as a `teal::dataset`.
We can then use the provided teal module `tm_g_barplot` to have add a barplot module in our teal app.

```{r,  message = FALSE, cache = FALSE, opts.label=c('app')}
library(teal.modules.hermes)

data <- teal_data()
data <- within(data, {
  library(hermes)
  MAE <- multi_assay_experiment
})
datanames(data) <- "MAE"

app <- init(
  data = data,
  modules = modules(
    tm_g_barplot(
      label = "barplot",
      mae_name = "MAE"
    )
  )
)
shinyApp(app$ui, app$server)
```

{{< include ../misc/session_info.qmd >}}
:::

Made with ❤️ by the Statistical Engineering Team StatisticalEngineering

  • License

  • Edit this page
  • Report an issue
Cookie Preferences