Contents

1 Getting started

The SEtools package is a set of convenience functions for the Bioconductor class SummarizedExperiment. It facilitates merging, melting, and plotting SummarizedExperiment objects.

NOTE that the heatmap-related and melting functions have been moved to a standalone package, sechm. The old sehm function of SEtools should be considered deprecated, and most SEtools functions are conserved for legacy/reproducibility reasons (or until they find a better home).

1.1 Package installation

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("SEtools")

Or, to install the latest development version:

BiocManager::install("plger/SEtools")

1.2 Example data

To showcase the main functions, we will use an example object which contains (a subset of) whole-hippocampus RNAseq of mice after different stressors:

suppressPackageStartupMessages({
  library(SummarizedExperiment)
  library(SEtools)
})
## Warning: replacing previous import 'utils::findMatches' by
## 'S4Vectors::findMatches' when loading 'AnnotationDbi'
data("SE", package="SEtools")
SE
## class: SummarizedExperiment 
## dim: 100 20 
## metadata(0):
## assays(2): counts logcpm
## rownames(100): Egr1 Nr4a1 ... CH36-200G6.4 Bhlhe22
## rowData names(2): meanCPM meanTPM
## colnames(20): HC.Homecage.1 HC.Homecage.2 ... HC.Swim.4 HC.Swim.5
## colData names(2): Region Condition

This is taken from Floriou-Servou et al., Biol Psychiatry 2018.

1.3 Merging and aggregating SEs

se1 <- SE[,1:10]
se2 <- SE[,11:20]
se3 <- mergeSEs( list(se1=se1, se2=se2) )
se3
## class: SummarizedExperiment 
## dim: 100 20 
## metadata(3): se1 se2 anno_colors
## assays(2): counts logcpm
## rownames(100): AC139063.2 Actr6 ... Zfp667 Zfp930
## rowData names(2): meanCPM meanTPM
## colnames(20): se1.HC.Homecage.1 se1.HC.Homecage.2 ... se2.HC.Swim.4
##   se2.HC.Swim.5
## colData names(3): Dataset Region Condition

All assays were merged, along with rowData and colData slots.

By default, row z-scores are calculated for each object when merging. This can be prevented with:

se3 <- mergeSEs( list(se1=se1, se2=se2), do.scale=FALSE)

If more than one assay is present, one can specify a different scaling behavior for each assay:

se3 <- mergeSEs( list(se1=se1, se2=se2), use.assays=c("counts", "logcpm"), do.scale=c(FALSE, TRUE))

Differences to the cbind method include prefixes added to column names, optional scaling, handling of metadata (e.g. for sechm)

1.3.1 Merging by rowData columns

It is also possible to merge by rowData columns, which are specified through the mergeBy argument. In this case, one can have one-to-many and many-to-many mappings, in which case two behaviors are possible:

  • By default, all combinations will be reported, which means that the same feature of one object might appear multiple times in the output because it matches multiple features of another object.
  • If a function is passed through aggFun, the features of each object will by aggregated by mergeBy using this function before merging.
rowData(se1)$metafeature <- sample(LETTERS,nrow(se1),replace = TRUE)
rowData(se2)$metafeature <- sample(LETTERS,nrow(se2),replace = TRUE)
se3 <- mergeSEs( list(se1=se1, se2=se2), do.scale=FALSE, mergeBy="metafeature", aggFun=median)
## Aggregating the objects by metafeature
## Merging...
sechm::sechm(se3, features=row.names(se3))

1.3.2 Aggregating a SE

A single SE can also be aggregated by using the aggSE function:

se1b <- aggSE(se1, by = "metafeature")
## Aggregation methods for each assay:
## counts: sum; logcpm: expsum
se1b
## class: SummarizedExperiment 
## dim: 25 10 
## metadata(0):
## assays(2): counts logcpm
## rownames(25): A B ... Y Z
## rowData names(0):
## colnames(10): HC.Homecage.1 HC.Homecage.2 ... HC.Handling.4
##   HC.Handling.5
## colData names(2): Region Condition

If the aggregation function(s) are not specified, aggSE will try to guess decent aggregation functions from the assay names.

This is similar to scuttle::sumCountsAcrossFeatures, but preserves other SE slots.


1.4 Other convenience functions

Calculate an assay of log-foldchanges to the controls:

SE <- log2FC(SE, fromAssay="logcpm", controls=SE$Condition=="Homecage")



Session info

## R version 4.3.0 RC (2023-04-13 r84269)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.2 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.17-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              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: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] SEtools_1.14.0              sechm_1.8.0                
##  [3] SummarizedExperiment_1.30.0 Biobase_2.60.0             
##  [5] GenomicRanges_1.52.0        GenomeInfoDb_1.36.0        
##  [7] IRanges_2.34.0              S4Vectors_0.38.0           
##  [9] BiocGenerics_0.46.0         MatrixGenerics_1.12.0      
## [11] matrixStats_0.63.0          BiocStyle_2.28.0           
## 
## loaded via a namespace (and not attached):
##   [1] DBI_1.1.3               bitops_1.0-7            rlang_1.1.0            
##   [4] magrittr_2.0.3          clue_0.3-64             GetoptLong_1.0.5       
##   [7] RSQLite_2.3.1           compiler_4.3.0          mgcv_1.8-42            
##  [10] png_0.1-8               vctrs_0.6.2             sva_3.48.0             
##  [13] stringr_1.5.0           pkgconfig_2.0.3         shape_1.4.6            
##  [16] crayon_1.5.2            fastmap_1.1.1           magick_2.7.4           
##  [19] XVector_0.40.0          ca_0.71.1               utf8_1.2.3             
##  [22] rmarkdown_2.21          bit_4.0.5               xfun_0.39              
##  [25] zlibbioc_1.46.0         cachem_1.0.7            jsonlite_1.8.4         
##  [28] blob_1.2.4              highr_0.10              DelayedArray_0.26.0    
##  [31] BiocParallel_1.34.0     parallel_4.3.0          cluster_2.1.4          
##  [34] R6_2.5.1                bslib_0.4.2             stringi_1.7.12         
##  [37] RColorBrewer_1.1-3      limma_3.56.0            genefilter_1.82.0      
##  [40] jquerylib_0.1.4         Rcpp_1.0.10             bookdown_0.33          
##  [43] iterators_1.0.14        knitr_1.42              splines_4.3.0          
##  [46] Matrix_1.5-4            tidyselect_1.2.0        yaml_2.3.7             
##  [49] TSP_1.2-4               doParallel_1.0.17       codetools_0.2-19       
##  [52] curl_5.0.0              lattice_0.21-8          tibble_3.2.1           
##  [55] KEGGREST_1.40.0         evaluate_0.20           Rtsne_0.16             
##  [58] survival_3.5-5          zip_2.3.0               Biostrings_2.68.0      
##  [61] circlize_0.4.15         pillar_1.9.0            BiocManager_1.30.20    
##  [64] foreach_1.5.2           generics_0.1.3          RCurl_1.98-1.12        
##  [67] ggplot2_3.4.2           munsell_0.5.0           scales_1.2.1           
##  [70] xtable_1.8-4            glue_1.6.2              pheatmap_1.0.12        
##  [73] tools_4.3.0             data.table_1.14.8       openxlsx_4.2.5.2       
##  [76] annotate_1.78.0         locfit_1.5-9.7          registry_0.5-1         
##  [79] XML_3.99-0.14           Cairo_1.6-0             grid_4.3.0             
##  [82] seriation_1.4.2         AnnotationDbi_1.62.0    edgeR_3.42.0           
##  [85] colorspace_2.1-0        nlme_3.1-162            GenomeInfoDbData_1.2.10
##  [88] randomcoloR_1.1.0.1     cli_3.6.1               fansi_1.0.4            
##  [91] ComplexHeatmap_2.16.0   dplyr_1.1.2             V8_4.3.0               
##  [94] gtable_0.3.3            DESeq2_1.40.0           sass_0.4.5             
##  [97] digest_0.6.31           rjson_0.2.21            memoise_2.0.1          
## [100] htmltools_0.5.5         lifecycle_1.0.3         httr_1.4.5             
## [103] GlobalOptions_0.1.2     bit64_4.0.5