/glossary

Simple glossary management for R/Rmd

Primary LanguageR

Introduction

This small script allows the management of simple glossaries.

Dependencies

This script depends on the following packages:

library(magrittr)
library(dplyr)
library(glue)
library(reactable)

Use

Load and create a glossary

source("glossary.R")
glossary <- create_glossary()

Add terms in the glossary

glossary$add_term(
   "UMI",
   "Unique Molecular Identifier. Each PCR primer is associated to a UMI to identify PCR duplicates when quantifying the transcripts. Therefore the number of counts corresponds to the number of UMI which is the quantification measure per feature."
)

Synonyms can also be provided:

glossary$add_term(
   "MT",
   "Genes coded by mitochondrial genome. MT (%) corresponds to the percentage of UMI corresponding to mitochondrial genes."
)
glossary$add_synonyms("MT", "MT (%)")

Showing the glossary

  • glossary$get_table() returns the glossary tibble
  • glossary$view() shows the glossary in a reactable

Get definitions

The following function is used to get the definitions of terms of interest. It’s case insensitive and support plurals by default.

glossary$get_definitions(c("mt", "UMIs"))
## # A tibble: 2 x 3
##   Term  Definition                                                      Synonyms
##   <chr> <chr>                                                           <list>  
## 1 mt    Genes coded by mitochondrial genome. MT (%) corresponds to the… <chr [2…
## 2 UMIs  Unique Molecular Identifier. Each PCR primer is associated to … <chr [1…

In an markdown or html document, the definitions can be shown in tooltips using the glossary$get_html_definitions() function. For example: UMIs. CSS style can be customized using the style parameter (Unfortunately, CSS are not rendered in GitHub markdown as it is a part of the sanitization process).

To make it easier to use in an Rmd document in RStudio this function can be copied in a function with a shorter name such as:

td <- glossary$get_html_definitions

And then the following markdown snippet can be added in RStudio (Edit Snippets button in Global Options -> Code):

snippet td
    `r${2} td(${1})`