umiAnalyzer vignette

Introduction

umiAnalyzer provides tools for analyzing UMIErrorCorrect output. UMIErrorCorrect is a Python package for processing targeted high-throughput sequencing data containing unique molecular identifiers (UMIs). UMIErrorCorrect is available at: https://github.com/stahlberggroup/umierrorcorrect.

Using the umiVisualizer shiny app

The shiny app can be run using the following command:

umiAnalyzer::runUmiVisualizer()

How to make your own UMIexperiment object

Define a variable containing the path to the directory with all the UMIErrorCorrect output folders belonging to your experiment. umiAnalyzer comes with raw test data generated with UMIErrorCorrect that you can import if you don’t have any of your own.

Call the createUmiExperiment to create your UMIexperiment object.

The UMIexperiment object always maintains your raw data, however you can create as many filters as you like, which will be saved as separate objects to access. You can filter the consensus table of UMIexperiment object with filterUmiObject. The only mandatory arguments are the object to be filtered and a user defined name. You can use that name to retrieve a filtered table using getFilteredData.

library(umiAnalyzer)
#> Warning: multiple methods tables found for 'union'
#> Warning: multiple methods tables found for 'intersect'
#> Warning: multiple methods tables found for 'setdiff'
#> Warning: multiple methods tables found for 'setequal'
#> Warning: multiple methods tables found for 'union'
#> Warning: multiple methods tables found for 'intersect'
#> Warning: multiple methods tables found for 'setdiff'
#> Warning: multiple methods tables found for 'intersect'
#> Warning: multiple methods tables found for 'union'
#> Warning: multiple methods tables found for 'intersect'
#> Warning: multiple methods tables found for 'setdiff'
#> Warning: multiple methods tables found for 'union'
#> Warning: multiple methods tables found for 'intersect'
#> Warning: multiple methods tables found for 'setdiff'
#> Warning: multiple methods tables found for 'setequal'

main <- system.file("extdata", package = "umiAnalyzer")

simsen <- createUmiExperiment(main)

simsen <- mergeAssays(
  object = simsen,
  name = "new",
  assay.list = c("PIK3CA_123", "PIK3CA_234")
)

createUmiExperiment has an optional flag importBam, which is set to FALSE by default. If this is set to TRUE it will automatically call parseBamFiles and store the read data in the ‘simsen’ object which can then be passed directly to plotFamilyHistogram, without having to run parseBamFiles again. Note that for large experiments, especially if consDepth is set lower than 10, the size of the experiment object may become too large.

reads <- parseBamFiles(main, consDepth = 10)

BarcodeFamilyHistogram(reads)
#> Warning: Removed 1787 rows containing non-finite outside the scale range
#> (`stat_bin()`).
#> Warning: Removed 4 rows containing missing values or values outside the scale range
#> (`geom_bar()`).

Next we generate Quality Control plots and filter the UMIexperiment object to select for consensus 3 reads.

QCplot(simsen)

Most downstream functions use filtered data, each each filtered data set receives a name, making it possible to apply multiple filters on the same object as the original data is maintained and can always be retrieved with saveConsData (see below). Each filtered data set can be retrieved using getFilteredData and assigned to a new variable or be saved as a csv file with the optional parameter save = TRUE, which is set to FALSE by

simsen <- filterUmiObject(simsen)

Optionally, the beta-binomial variant caller can be run on the data using callVariants.

# This is optional
simsen <- callVariants(simsen)

Retrieve filters using getFilteredData:

myfilter <- getFilteredData(simsen)
myfilter
#> # A tibble: 562 × 18
#>    `Sample Name`   Contig Position Name  Reference     A     C     G     T     I
#>    <chr>           <chr>     <dbl> <chr> <chr>     <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1 VAF-1-5ng-1-10x chr17   7673746 TP53… T             0     0     0  2809     0
#>  2 VAF-1-5ng-1-10x chr17   7673747 TP53… C             0  2809     0     0     0
#>  3 VAF-1-5ng-1-10x chr17   7673748 TP53… T             1     0     0  2808     0
#>  4 VAF-1-5ng-1-10x chr17   7673749 TP53… T             0     0     0  2809     0
#>  5 VAF-1-5ng-1-10x chr17   7673750 TP53… G             0     0  2809     0     0
#>  6 VAF-1-5ng-1-10x chr17   7673751 TP53… C             0  2810     0     0     0
#>  7 VAF-1-5ng-1-10x chr17   7673752 TP53… G             0     0  2810     0     0
#>  8 VAF-1-5ng-1-10x chr17   7673753 TP53… G             0     0  2810     0     0
#>  9 VAF-1-5ng-1-10x chr17   7673754 TP53… A          2810     0     0     0     0
#> 10 VAF-1-5ng-1-10x chr17   7673755 TP53… G             0     0  2809     1     0
#> # ℹ 552 more rows
#> # ℹ 8 more variables: D <dbl>, N <dbl>, Coverage <dbl>,
#> #   `Consensus group size` <dbl>, `Max Non-ref Allele Count` <dbl>,
#> #   `Max Non-ref Allele Frequency` <dbl>, `Max Non-ref Allele` <chr>,
#> #   sample <chr>

Error correction depends on UMI depth, i.e. how many reads per barcode are required to form a barcode family. We can plot the number of available reads for different consensus depths.

UmiCountsPlot(simsen)

Next we generate plots for the amplicons and samples in the UMIexperiment object.

If generateAmpliconPlots is called and the number of amplicons and samples is too large to plot all of them individually in a single plot the data is shown in summarized form. The user can specify amplicons and or samples optionally to plot only the selection.

All data

AmpliconPlot(simsen)

Selection

AmpliconPlot(
  object = simsen,
  amplicons = 'KIT_125',
  samples = 'VAF-1-5ng-1-10x'
)

Merging technical replicates

In the above analyses potential replicates are treated as individual samples, but it is possible to merge replicate information for statistical analyses and more convenient plotting.

Merging data requires the user to supply a file with meta data using the importDesign function. This will create a metadata attribute called “design”, which can be retrieved using getMetaData.

metaData <- system.file("extdata", "metadata.txt", package = "umiAnalyzer")

simsen <- importDesign(
  object = simsen,
  file = metaData
)

design <- getMetaData(
  object = simsen, 
  attributeName = "design"
)

design

Time series data

We can generate time course data using the analyzeTimeSeries function. This requires some information from the meta data that was uploaded above. Most importantly a time variable needs to be available in the meta data object called “time” by default. However the variable can have any name, which can be specified using the time.var parameter. If time.var has a date format that will be used for plotting, otherwise it will convert time.var to a categorical. If you have time.var in date format but want the plot to use categorical instead set the categorical parameter to TRUE.

We can also make use of replicate data to remove background noise. If you specify a group.by variable from the meta data only variants that occur at least twice per group will be used. If we specify ‘replicate’ that means only variants in at least 2 out of 3 replicates will be considered. The default value for group.by is NULL and each sample will be analyzed and plotted independently.

simsen <- umiAnalyzer::analyzeTimeSeries(
  object = simsen,
  time.var = 'time',
  group.by = 'replicate'
)

We can now use the mergeTechnicalReplicates function to create a summarized data table. Merging replicates also performs coverage normalization. This can remove bias incurred when comparing samples sequenced at different read depths, because background noise is expected to be higher in a sample that was sequenced to a greater depth. A drawback is that it is not possible to scale a count of zero variant reads one can set all 0 to a small value, such as 0.5, first and then scale the data.

simsen <- mergeTechnicalReplicates(
  object = simsen,
  group.by = 'replicate',
  option = 'Set1', 
  amplicons = c('new', 'TP53_1', 'TP53_7')
)

We can also have a look at the merged amplicon plots which now show the average maximum alternate allele count and standard deviation.

vizMergedData(
  simsen,
  amplicons = c('new')
)

Calling variants

umiAnalyzer comes with a build-in UMIexperiment object to explore, which was generated using the code above, so it can be used without creating the it first if so desired.

In order to call variants using the umiAnalyzer variant caller simply load the package and test data and use the callVariants function. You can then filter the resulting consensus data (cons.data) within the object, e.g. for significant variants.

simsen <- callVariants(simsen)

simsen <- filterVariants(simsen)

simsen <- generateAmpliconPlots(
  object = simsen
)

Other functions (experimental)

Writing a Variant Call File (VCF)

generateVCF(object = simsen, outFile = 'simsen.vcf', printAll = FALSE, save = FALSE)

Saving consensus data as a csv file

It is possible to retrieve consensus data as a tibble using saveConsData. This function can also be used to to save the data as a csv file with delimiters either ‘,’, ‘;’ or tab. This requires the user to set the save parameter to TRUE and to specify an output directory (default is the working directory), filename (default is ‘consensus_data.csv’) and delimiter (default is ‘;’).

consensus_data <- saveConsData(object = simsen)

outDir <- getwd()
saveConsData(object = simsen, outDir = outDir, delim = ';', save = TRUE)

System info

sessionInfo()
#> R version 4.4.2 (2024-10-31)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.1 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.26.so;  LAPACK version 3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
#>  [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] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] umiAnalyzer_1.0.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] gtable_0.3.6            xfun_0.49               bslib_0.8.0            
#>  [4] ggplot2_3.5.1           htmlwidgets_1.6.4       tzdb_0.4.0             
#>  [7] vctrs_0.6.5             tools_4.4.2             bitops_1.0-9           
#> [10] generics_0.1.3          stats4_4.4.2            parallel_4.4.2         
#> [13] tibble_3.2.1            fansi_1.0.6             pkgconfig_2.0.3        
#> [16] pheatmap_1.0.12         data.table_1.16.2       RColorBrewer_1.1-3     
#> [19] S4Vectors_0.45.1        lifecycle_1.0.4         GenomeInfoDbData_1.2.13
#> [22] farver_2.1.2            stringr_1.5.1           compiler_4.4.2         
#> [25] Rsamtools_2.23.0        Biostrings_2.75.1       munsell_0.5.1          
#> [28] codetools_0.2-20        httpuv_1.6.15           GenomeInfoDb_1.43.0    
#> [31] shinyWidgets_0.8.7      htmltools_0.5.8.1       sys_3.4.3              
#> [34] buildtools_1.0.0        sass_0.4.9              lazyeval_0.2.2         
#> [37] yaml_2.3.10             plotly_4.10.4           tidyr_1.3.1            
#> [40] later_1.3.2             pillar_1.9.0            crayon_1.5.3           
#> [43] jquerylib_0.1.4         DT_0.33                 BiocParallel_1.41.0    
#> [46] cachem_1.1.0            viridis_0.6.5           mime_0.12              
#> [49] tidyselect_1.2.1        digest_0.6.37           stringi_1.8.4          
#> [52] purrr_1.0.2             dplyr_1.1.4             labeling_0.4.3         
#> [55] forcats_1.0.0           maketools_1.3.1         fastmap_1.2.0          
#> [58] grid_4.4.2              colorspace_2.1-1        cli_3.6.3              
#> [61] magrittr_2.0.3          utf8_1.2.4              withr_3.0.2            
#> [64] readr_2.1.5             scales_1.3.0            UCSC.utils_1.3.0       
#> [67] promises_1.3.0          bit64_4.5.2             rmarkdown_2.29         
#> [70] XVector_0.47.0          httr_1.4.7              bit_4.5.0              
#> [73] gridExtra_2.3           hms_1.1.3               shiny_1.9.1            
#> [76] evaluate_1.0.1          knitr_1.49              GenomicRanges_1.59.0   
#> [79] IRanges_2.41.0          viridisLite_0.4.2       rlang_1.1.4            
#> [82] Rcpp_1.0.13-1           xtable_1.8-4            glue_1.8.0             
#> [85] BiocManager_1.30.25     BiocGenerics_0.53.2     shinydashboard_0.7.2   
#> [88] vroom_1.6.5             jsonlite_1.8.9          R6_2.5.1               
#> [91] shinyFiles_0.9.3        fs_1.6.5                zlibbioc_1.52.0