Contents

This vignette shows an example workflow for ensemble biclustering analysis with the mosbi package. Every function of the package has a help page with a detailed documentation. To access these type help(package=mosbi) in the R console.

0.0.1 Load packages

Import dependencies.

library(mosbi)

0.0.2 Helper functions

Two additional functions are defined, to calculate z-scores of the data and to visualize the biclusters as a histogram.

z_score <- function(x, margin = 2) {
    z_fun <- function(y) {
        (y - mean(y, na.rm = TRUE)) / sd(y, na.rm = TRUE)
    }

    if (margin == 2) {
        return(apply(x, margin, z_fun))
    } else if (margin == 1) {
        return(t(apply(x, margin, z_fun)))
    }
}

bicluster_histo <- function(biclusters) {
    cols <- mosbi::colhistogram(biclusters)
    rows <- mosbi::rowhistogram(biclusters)

    graphics::par(mfrow = c(1, 2))
    hist(cols, main = "Column size ditribution")
    hist(rows, main = "Row size ditribution")
}

0.0.3 1. Download and prepare data

Biclustering will be done on a data matrix. As an example,
lipidomics dataset from the metabolights database will be used https://www.ebi.ac.uk/metabolights/MTBLS562. The data consists of 40 samples (columns) and 245 lipids (rows).

# Download file
download.file(paste0("https://www.ebi.ac.uk/metabolights/ws/studies/MTBLS562/",
              "download/1fb6c4f0-e87b-463a-bc77-1a0ff345ec3d?file=",
              "m_aging_mouse_brains_metabolite_profiling_mass_",
              "spectrometry-1_v2_maf.tsv"),
    destfile = "aging_mouse_brain_data.tsv"
)

# Load data
data_table <- read.csv("aging_mouse_brain_data.tsv", sep = "\t")
data_table <- data_table[c(
    grep(
        "metabolite_identification",
        colnames(data_table)
    ),
    grep("^X", colnames(data_table))
)]

# Make data matrix
data_matrix <- z_score(log2(as.matrix(data_table[2:ncol(data_table)])), 1)

rownames(data_matrix) <- data_table$metabolite_identification

stats::heatmap(data_matrix)

The data has a gaussian-like distribution and no missing values, so we can proceed with biclustering.

0.0.4 2. Compute biclusters

The mosbi package is able to work with results of different biclustering algorithms. The approach unites the results from different algorithms. The results of four example algorithms will be computed and converted to mosbi::bicluster objects. For a list of all supported biclustering algorithms/packages type ?mosbi::get_biclusters in the R console.

# Fabia
fb <- mosbi::run_fabia(data_matrix) # In case the algorithms throws an error,
#> Cycle: 0
Cycle: 20
Cycle: 40
Cycle: 60
Cycle: 80
Cycle: 100
Cycle: 120
Cycle: 140
Cycle: 160
Cycle: 180
Cycle: 200
Cycle: 220
Cycle: 240
Cycle: 260
Cycle: 280
Cycle: 300
Cycle: 320
Cycle: 340
Cycle: 360
Cycle: 380
Cycle: 400
Cycle: 420
Cycle: 440
Cycle: 460
Cycle: 480
Cycle: 500
# return an empty list

# isa2
BCisa <- mosbi::run_isa(data_matrix)

# Plaid
BCplaid <- mosbi::run_plaid(data_matrix)
#> layer: 0 
#>  5882.744
#> layer: 1 
#> [1]   0 110  10
#> [1]   1 103  10
#> [1]   2 101  10
#> [1]  30 101  10
#> [1] 31 39 10
#> [1] 32 39  9
#> [1] 33 37  9
#> [1] 34 37  9
#> [1] 35 37  9
#> [1] 60 37  9
#> [1] 3
#> [1] 154.413   0.000   0.000   0.000
#> back fitting 2 times
#> layer: 2 
#> [1]   0 110  11
#> [1]  1 98 11
#> [1]  2 93 11
#> [1]  3 90 11
#> [1]  4 88 11
#> [1]  5 87 11
#> [1] 30 87 11
#> [1] 31 37 11
#> [1] 32 37  6
#> [1] 33 37  6
#> [1] 60 37  6
#> [1] 6
#> [1] 202.7203   0.0000   0.0000   0.0000
#> back fitting 2 times
#> layer: 3 
#> [1]   0 120  20
#> [1]   1 106  20
#> [1]   2 103  19
#> [1]   3 102  19
#> [1]   4 100  19
#> [1]  30 100  19
#> [1] 31 22 19
#> [1] 32 22  9
#> [1] 33 22  9
#> [1] 34 22  7
#> [1] 35 22  7
#> [1] 60 22  7
#> [1] 5
#> [1] 60.8523  0.0000  0.0000  0.0000
#> back fitting 2 times
#> layer: 4 
#> [1]  0 83 19
#> [1]  1 68 16
#> [1]  2 66 15
#> [1]  3 65 15
#> [1]  4 64 15
#> [1]  5 63 15
#> [1] 30 63 15
#> [1] 31  2 15
#> [1] 32  2 12
#> [1] 33  2 12
#> [1] 34  2 11
#> [1] 35  2 11
#> [1] 60  2 11
#> [1] 6
#> [1] 11.844620  0.000000  4.039105  0.000000
#> back fitting 2 times
#> layer: 5 
#> [1]   0 100  20
#> [1]  1 86 18
#> [1]  2 84 17
#> [1]  3 84 17
#> [1]  4 83 17
#> [1] 30 83 17
#> [1] 31  2 17
#> [1] 32  2 11
#> [1] 33  2 11
#> [1] 60  2 11
#> [1] 5
#> [1]  3.004898  0.000000  0.000000 10.403229
#>      
#> Layer Rows Cols  Df      SS    MS Convergence Rows Released Cols Released
#>     0  245   40 284 5985.10 21.07          NA            NA            NA
#>     1   37    9  45  248.78  5.53           1            64             1
#>     2   37    6  42  387.79  9.23           1            50             5
#>     3   22    7  28  108.18  3.86           1            78            12
#>     4    2   11  12   20.54  1.71           1            61             4

# QUBIC
BCqubic <- mosbi::run_qubic(data_matrix)

# Merge results of all algorithms
all_bics <- c(fb, BCisa, BCplaid, BCqubic)

bicluster_histo(all_bics)

The histogram visualizes the distribution of bicluster sizes (separately for the number of rows and columns of each bicluster). The total number of found biclusters are given in the title.

0.0.5 3. Compute network

The next step of the ensemble approach is the computation of a similarity network of biclusters. To filter for for similarities due to random overlaps of biclusters, we apply an error model (For more details refer to our publication). Different similarity metrics are available. For details type mosbi::bicluster_network in the R console.

bic_net <- mosbi::bicluster_network(all_bics, # List of biclusters
    data_matrix, # Data matrix
    n_randomizations = 5,
    # Number of randomizations for the
    # error model
    MARGIN = "both",
    # Use datapoints for metric evaluation
    metric = 4, # Fowlkes–Mallows index
    # For information about the metrics,
    # visit the "Similarity metrics
    # evaluation" vignette
    n_steps = 1000,
    # At how many steps should
    # the cut-of is evaluated
    plot_edge_dist = TRUE
    # Plot the evaluation of cut-off estimation
)
#> Esimated cut-off:  0.05005005

The two resulting plot visualize the process of cut-off estimation. The right plot show the remaining number of edges for the computed bicluster network (red) and for randomizations of biclusters (black). The vertical red line showed the threshold with the highest signal-to-noise ratio (SNR). All evaluated SNRs are again visualized in the left plot.

The next plot shows the bicluster similarity matrix. It reveals highly similar biclusters.

stats::heatmap(get_adjacency(bic_net))

0.0.5.1 Visualize network

Before the final step, extraction of bicluster communities (ensemble biclusters), the bicluster network can be layouted as a network.

plot(bic_net)

The networks are plotted using the igraph package. igraph specific plotting parameters can be added. For help type: ?igraph::plot.igraph

To see, which bicluster was generated by which algorithm, the following function can be executed:

mosbi::plot_algo_network(bic_net, all_bics, vertex.label = NA)

The downloaded data contains samples from different weeks of development. This can be visualized on the network, showing from which week the samples within a bicluster come from.

# Prepare groups for plotting
weeks <- vapply(
    strsplit(colnames(data_matrix), "\\."),
    function(x) {
        return(x[1])
    }, ""
)

names(weeks) <- colnames(data_matrix)

print(sort(unique(weeks))) # 5 colors required
#> [1] "X12W" "X24W" "X32W" "X4W"  "X52W"

week_cols <- c("yellow", "orange", "red", "green", "brown")

# Plot network colored by week
mosbi::plot_piechart_bicluster_network(bic_net, all_bics, weeks,
    week_cols,
    vertex.label = NA
)
graphics::legend("topright",
    legend = sort(unique(weeks)),
    fill = week_cols, title = "Week"
)

Such a visualization is also possible for the samples:

# Prepare groups for plotting
samples <- vapply(
    strsplit(colnames(data_matrix), "\\."),
    function(x) {
        return(x[2])
    }, ""
)

names(samples) <- colnames(data_matrix)

samples_cols <- RColorBrewer::brewer.pal(
    n = length(sort(unique(samples))),
    name = "Set3"
)


# Plot network colored by week
mosbi::plot_piechart_bicluster_network(bic_net, all_bics, samples,
    samples_cols,
    vertex.label = NA
)
graphics::legend("topright",
    legend = sort(unique(samples)),
    fill = samples_cols, title = "Sample"
)

0.0.6 4. Extract louvain communities

Calculate the communities

coms <- mosbi::get_louvain_communities(bic_net,
    min_size = 3,
    bics = all_bics
)
# Only communities with a minimum size of 3 biclusters are saved.

0.0.6.1 Visualization of the communities

# Plot all communities
for (i in seq(1, length(coms))) {
    tmp_bics <- mosbi::select_biclusters_from_bicluster_network(
        coms[[i]],
        all_bics
    )

    mosbi::plot_piechart_bicluster_network(coms[[i]], tmp_bics,
        weeks, week_cols,
        main = paste0("Community ", i)
    )
    graphics::legend("topright",
        legend = sort(unique(weeks)),
        fill = week_cols, title = "Week"
    )

    cat("\nCommunity ", i, " conists of results from the
             following algorithms:\n")
    cat(get_bic_net_algorithms(coms[[i]]))
    cat("\n")
}

#> 
#> Community  1  conists of results from the
#>              following algorithms:
#> fabia isa2 biclust-plaid biclust-qubic

#> 
#> Community  2  conists of results from the
#>              following algorithms:
#> fabia

#> 
#> Community  3  conists of results from the
#>              following algorithms:
#> isa2 biclust-qubic

#> 
#> Community  4  conists of results from the
#>              following algorithms:
#> isa2 biclust-qubic

#> 
#> Community  5  conists of results from the
#>              following algorithms:
#> biclust-plaid biclust-qubic

0.0.6.2 Extraction of the communities

Finally, communities of the network can be extracted as ensemble biclusters. The are saved as a list of mosbi::bicluster objects and therefore in the same format as the imported results of all the algorithms. With the parameters row_threshold & col_threshold, the minimum occurrence of a row- or column-element in the biclusters of a community can be defined.

ensemble_bicluster_list <- mosbi::ensemble_biclusters(coms, all_bics,
    data_matrix,
    row_threshold = .1,
    col_threshold = .1
)

1 Session Info

sessionInfo()
#> R version 4.1.2 (2021-11-01)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.3 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.14-bioc/R/lib/libRblas.so
#> LAPACK: /home/biocbuild/bbs-3.14-bioc/R/lib/libRlapack.so
#> 
#> 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       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] mosbi_1.0.3      BiocStyle_2.22.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] tidyselect_1.1.1      modeltools_0.2-23     xfun_0.29            
#>  [4] bslib_0.3.1           purrr_0.3.4           lattice_0.20-45      
#>  [7] flexclust_1.4-0       generics_0.1.1        colorspace_2.0-2     
#> [10] vctrs_0.3.8           htmltools_0.5.2       stats4_4.1.2         
#> [13] yaml_2.2.1            utf8_1.2.2            rlang_0.4.12         
#> [16] jquerylib_0.1.4       pillar_1.6.4          DBI_1.1.2            
#> [19] glue_1.6.0            BiocGenerics_0.40.0   RColorBrewer_1.1-2   
#> [22] QUBIC_1.22.0          lifecycle_1.0.1       stringr_1.4.0        
#> [25] munsell_0.5.0         gtable_0.3.0          evaluate_0.14        
#> [28] Biobase_2.54.0        knitr_1.37            fastmap_1.1.0        
#> [31] parallel_4.1.2        class_7.3-19          fansi_0.5.0          
#> [34] biclust_2.0.3         highr_0.9             Rcpp_1.0.7           
#> [37] scales_1.1.1          BiocManager_1.30.16   additivityTests_1.1-4
#> [40] RcppParallel_5.1.5    magick_2.7.3          jsonlite_1.7.2       
#> [43] fabia_2.40.0          ggplot2_3.3.5         digest_0.6.29        
#> [46] stringi_1.7.6         bookdown_0.24         dplyr_1.0.7          
#> [49] grid_4.1.2            BH_1.78.0-0           tools_4.1.2          
#> [52] magrittr_2.0.1        sass_0.4.0            tibble_3.1.6         
#> [55] tidyr_1.1.4           crayon_1.4.2          isa2_0.3.5           
#> [58] pkgconfig_2.0.3       MASS_7.3-54           ellipsis_0.3.2       
#> [61] assertthat_0.2.1      rmarkdown_2.11        R6_2.5.1             
#> [64] igraph_1.2.11         compiler_4.1.2