---
title: "miRSM: inferring miRNA sponge modules in heterogeneous data" 
author: "\\
    
    Junpeng Zhang (zjp@dali.edu.cn)\\
    
    School of Engineering, Dali University"
date: '`r Sys.Date()`'
output:
    BiocStyle::html_document:
      toc: yes
    BiocStyle::pdf_document:
      toc: yes
vignette: >
    %\VignetteIndexEntry{miRSM: inferring miRNA sponge modules in heterogeneous data} 
    %\VignettePackage{miRSM} 
    % \VignetteEngine{knitr::rmarkdown} 
    % \usepackage[utf8]{inputenc} 
    % \VignetteEncoding{UTF-8}
---

```{r style, echo=FALSE, results="asis", message=FALSE}
BiocStyle::markdown()
knitr::opts_chunk$set(tidy = FALSE,
    warning = FALSE,
    message = FALSE)
```

```{r echo=FALSE, results='hide', message=FALSE}
suppressPackageStartupMessages(library(miRSM))
```

# Introduction
MicroRNAs (miRNAs) play key roles in many biological processes including cancers [1-5]. Thus, uncovering miRNA functions and regulatory mechanisms is important for gene diagnosis and therapy.

Previous studies [6-9] have shown that a pool of coding and non-coding RNAs that shares common miRNA biding sites competes with each other, thus alter miRNA activity. The corresponding regulatory mechanism is named competing endogenous RNA (ceRNA) hypothesis [10]. These RNAs are called ceRNAs or miRNA sponges or miRNA decoys, and include long non-coding RNAs (lncRNAs), pseudogenes, circular RNAs (circRNAs) and messenger RNAs (mRNAs), etc. To study the module-level properties of miRNA sponges, it is necessary to identify miRNA sponge modules. The miRNA sponge modules will help to reveal the biological mechanism in cancer. 

To speed up the research of miRNA sponge modules, we develop an R/Bioconductor package `miRSM` to infer miRNA sponge modules. Unlike the existing R/Bioconductor packages (`r BiocStyle::Biocpkg("miRspongeR")` and `r BiocStyle::Biocpkg("SPONGE")`), `miRSM` focuses on identifying miRNA sponge modules by integrating expression data and miRNA-target binding information instead of miRNA sponge interaction networks. In addition to identifying miRNA sponge modules in the form of external competition (e.g. a group of lncRNAs compete with a group of mRNAs), `miRSM` can also infer miRNA sponge modules in the form of internal competition (e.g. a group of mRNAs compete with another group of mRNAs). Moreover, `miRSM` can infer miRNA sponge modules at both single-sample and multi-sample levels. 
    
# Identification of gene modules
Given matched ceRNA and mRNA expression data or single gene expression data, `miRSM` infers gene modules by using several methods from 21 packages, including `WGCNA`, `GFA`, `igraph`, `ProNet`, `NMF`, `stats`, `flashClust`, `dbscan`, `subspace`, `mclust`, `SOMbrero`, `ppclust`, `biclust`, `runibic`, `iBBiG`, `fabia`, `BicARE`, `isa2`, `s4vd`, `BiBitR` and `rqubic`. We assemble these methods into 7 functions: _module_WGCNA_, _module_GFA_, _module_igraph_, _module_ProNet_, _module_NMF_, _module_clust_ and _module_biclust_.

## Load BRCA sample data
The BRCA sample data includes matched miRNA, lncRNA, mRNA expression data, putative miRNA-target binding information and BRCA-related genes (lncRNAs and mRNAs).

```{r, eval=TRUE, include=TRUE}
data(BRCASampleData)
```

## module_WGCNA
By using WGCNA method [11], `miRSM` identifies co-expressed gene modules from matched ceRNA and mRNA expression data or single gene expression data.

```{r, eval=TRUE, include=TRUE}
modulegenes_WGCNA <- module_WGCNA(ceRExp[, seq_len(80)], 
                                  mRExp[, seq_len(80)])
modulegenes_WGCNA
```

## module_GFA
The gene modules are identified by using GFA method [12, 13] from matched ceRNA and mRNA expression data or single gene expression data.

```{r, eval=TRUE, include=TRUE}
modulegenes_GFA <- module_GFA(ceRExp[seq_len(20), seq_len(15)],
                              mRExp[seq_len(20), seq_len(15)], 
                              iter.max = 3000)
modulegenes_GFA
```

## module_igraph
By using `igraph` package [14], `miRSM` infers gene modules from matched ceRNA and mRNA expression data or single gene expression data. In the `igraph` package, users can select "betweenness", "greedy", "infomap", "prop", "eigen", "louvain" and "walktrap" methods for gene module identification. The default method is "greedy".

```{r, eval=TRUE, include=TRUE}
modulegenes_igraph <- module_igraph(ceRExp[, seq_len(10)],
                                    mRExp[, seq_len(10)])
modulegenes_igraph
```

## module_ProNet
In the `ProNet` package, users can select FN [15], MCL [16], LINKCOMM [17] and MCODE [18] for gene module identification from matched ceRNA and mRNA expression data or single gene expression data. The default method is MCL.

```{r, eval=TRUE, include=TRUE}
modulegenes_ProNet <- module_ProNet(ceRExp[, seq_len(10)],
                                    mRExp[, seq_len(10)])
modulegenes_ProNet
```

## module_NMF
By using `NMF` package [20], users infer gene modules from matched ceRNA and mRNA expression data or single gene expression data. In the `NMF` package, we can select "brunet", "Frobenius", "KL", "lee", "nsNMF", "offset", "siNMF", "snmf/l" and "snmf/r" methods for gene module identification. The default method is "brunet".

```{r, eval=TRUE, include=TRUE}
# Reimport NMF package to avoid conflicts with DelayedArray package
library(NMF)
modulegenes_NMF <- module_NMF(ceRExp[, seq_len(10)],
                              mRExp[, seq_len(10)])
modulegenes_NMF
```

## module_clust
`miRSM` Identifies gene modules from matched ceRNA and mRNA expression data or single gene expression data using a series of clustering packages, including `stats` [21], `flashClust` [22], `dbscan` [23], `subspace` [24], `mclust` [25], `SOMbrero` [26] and `ppclust` [27]. The clustering methods include "kmeans", "hclust", "dbscan", "clique", "gmm", "som" and "fcm". The default method is "kmeans".

```{r, eval=TRUE, include=TRUE}
modulegenes_clust <- module_clust(ceRExp[, seq_len(30)],
                                  mRExp[, seq_len(30)])
modulegenes_clust
```

## module_biclust
`miRSM` Identifies gene modules from matched ceRNA and mRNA expression data or single gene expression data using a series of biclustering packages, including `biclust` [28], `iBBiG` [29], `fabia` [30], `BicARE` [31], `isa2` [32], `s4vd` [33], `BiBitR` [34] and `rqubic` [35]. The biclustering methods include "BCBimax", "BCCC", "BCPlaid", "BCQuest", "BCSpectral", "BCXmotifs", "iBBiG", "fabia", "fabiap", "fabias", "mfsc", "nmfdiv", "nmfeu", "nmfsc", "FLOC", "isa", "BCs4vd", "BCssvd", "bibit" and "quBicluster". The default method is "fabia".

```{r, eval=TRUE, include=TRUE}
modulegenes_biclust <- module_biclust(ceRExp[, seq_len(30)],
                                      mRExp[, seq_len(30)])
modulegenes_biclust
```

# Discovery of miRNA sponge modules
The identified gene modules are regarded as candidate miRNA sponge modules. Based on the candidate miRNA sponge modules, `miRSM` uses the sensitivity canonical correlation (SCC), sensitivity distance correlation (SDC), sensitivity RV coefficient (SRVC), sensitivity similarity index (SSI), sensitivity generalized coefficient of determination (SGCD) and sensitivity Coxhead's or Rozeboom's coefficient (SCRC) methods to identify miRNA sponge modules. In addition, the sponge module (SM) method proposed in [36] is also added to predict miRNA sponge modules. 

```{r, eval=TRUE, include=TRUE}
modulegenes_igraph <- module_igraph(ceRExp[, seq_len(10)], 
                                  mRExp[, seq_len(10)])
# Identify miRNA sponge modules using sensitivity RV coefficient (SRVC)
miRSM_igraph_SRVC <- miRSM(miRExp, ceRExp, mRExp, miRTarget, 
                        modulegenes_igraph,
                        num_shared_miRNAs = 3, pvalue.cutoff = 0.05, 
                        method = "SRVC", MC.cutoff = 0.8,
                        SMC.cutoff = 0.01, RV_method = "RV")
miRSM_igraph_SRVC
```

# Inference of sample-specific miRNA sponge modules
`miRSM` uses statistical perturbation strategy to infer sample-specific miRNA sponge modules. By using the statistical perturbation strategy, `miRSM` identifies differential miRNA sponge modules between two cases (all samples and all samples except sample k).

```{r, eval=TRUE, include=TRUE}
nsamples <- 3
modulegenes_all <- module_igraph(ceRExp[, 151:300], mRExp[, 151:300])
modulegenes_exceptk <- lapply(seq(nsamples), function(i) 
                              module_WGCNA(ceRExp[-i, seq(150)], 
                              mRExp[-i, seq(150)]))
  
miRSM_SRVC_all <- miRSM(miRExp, ceRExp[, 151:300], mRExp[, 151:300], 
                        miRTarget, modulegenes_all, 
                        method = "SRVC", SMC.cutoff = 0.01, 
                        RV_method = "RV")
miRSM_SRVC_exceptk <- lapply(seq(nsamples), function(i) miRSM(miRExp[-i, ], 
                            ceRExp[-i, seq(150)], mRExp[-i, seq(150)], 
                            miRTarget, modulegenes_exceptk[[i]],
                            method = "SRVC",
                            SMC.cutoff = 0.01, RV_method = "RV"))

Modulegenes_all <- miRSM_SRVC_all[[2]]
Modulegenes_exceptk <- lapply(seq(nsamples), function(i) miRSM_SRVC_exceptk[[i]][[2]])

Modules_SS <- miRSM_SS(Modulegenes_all, Modulegenes_exceptk)
Modules_SS
```

# Modular analysis of miRNA sponge modules

## Functional analysis of miRNA sponge modules
`miRSM` implements _module_FA_ function to conduct functional analysis of miRNA sponge modules. The functional analysis includes two types: functional enrichment analysis (FEA) and disease enrichment analysis (DEA). Functional enrichment analysis includes GO, KEGG and Reactome enrichment analysis. The ontology databases used contain GO: Gene Ontology database (<http://www.geneontology.org/>), KEGG: Kyoto Encyclopedia of Genes and Genomes Pathway Database (<http://www.genome.jp/kegg/>), and Reactome: Reactome Pathway Database (<http://reactome.org/>). Disease enrichment analysis includes DO, DGN and NCG enrichment analysis. The disease databases used include DO: Disease Ontology database (<http://disease-ontology.org/>), DGN: DisGeNET database (<http://www.disgenet.org/>) and NCG: Network of Cancer Genes database (<http://ncg.kcl.ac.uk/>). 

```{r, eval=FALSE, include=TRUE}
modulegenes_WGCNA <- module_WGCNA(ceRExp[, seq_len(150)], 
                                  mRExp[, seq_len(150)])
# Identify miRNA sponge modules using sensitivity RV coefficient (SRVC)
miRSM_WGCNA_SRVC <- miRSM(miRExp, ceRExp, mRExp, miRTarget,
                         modulegenes_WGCNA, method = "SRVC",
                         SMC.cutoff = 0.01, RV_method = "RV")
miRSM_WGCNA_SRVC_genes <- miRSM_WGCNA_SRVC[[2]]
miRSM_WGCNA_SRVC_FEA <- module_FA(miRSM_WGCNA_SRVC_genes, Analysis.type = 'FEA')
miRSM_WGCNA_SRVC_DEA <- module_FA(miRSM_WGCNA_SRVC_genes, Analysis.type = 'DEA')
```

## Cancer enrichment analysis of miRNA sponge modules
To investigate whether the identified miRNA sponge modules are functionally associated with cancer of interest, `miRSM` implements _module_CEA_ function to conduct cancer enrichment analysis by using a hypergeometric test.

```{r, eval=TRUE, include=TRUE}
modulegenes_WGCNA <- module_WGCNA(ceRExp[, seq_len(150)], 
                                  mRExp[, seq_len(150)])
# Identify miRNA sponge modules using sensitivity RV coefficient (SRVC)
miRSM_WGCNA_SRVC <- miRSM(miRExp, ceRExp, mRExp, miRTarget,
                         modulegenes_WGCNA, method = "SRVC",
                         SMC.cutoff = 0.01, RV_method = "RV")
miRSM_WGCNA_SRVC_genes <- miRSM_WGCNA_SRVC[[2]]
miRSM.CEA.pvalue <- module_CEA(ceRExp, mRExp, BRCA_genes, miRSM_WGCNA_SRVC_genes)
miRSM.CEA.pvalue
```

## Validation of miRNA sponge interactions in miRNA sponge modules
The function _module_Validate_ is implemented to validate the miRNA sponge interactions existed in each miRNA sponge module. The built-in high-confidence groundtruth of miRNA sponge interactions is obtained from miRSponge (<http://bio-bigdata.hrbmu.edu.cn/miRSponge/>), LncACTdb 3.0 (<http://bio-bigdata.hrbmu.edu.cn/LncACTdb/>), LncCeRBase (<http://www.insect-genome.com/LncCeRBase/front/>). 

If you want to use low-confidence groundtruth of miRNA sponge interactions for validation, ENCORI (<https://rnasysu.com/encori/>) is suggested. For example, by using web API of ENCORI, the mRNA related miRNA sponge interactions are from <https://rna.sysu.edu.cn/encori/api/ceRNA/?assembly=hg38&geneType=mRNA&ceRNA=all&miRNAnum=1&pval=0.01&fdr=0.01&pancancerNum=1>, the lncRNA related miRNA sponge interactions are from <https://rna.sysu.edu.cn/encori/api/ceRNA/?assembly=hg38&geneType=lncRNA&ceRNA=all&miRNAnum=1&pval=0.01&fdr=0.01&pancancerNum=1>, and the pseudogene related miRNA sponge interactions are from <https://rna.sysu.edu.cn/encori/api/ceRNA/?assembly=hg38&geneType=pseudogene&ceRNA=all&miRNAnum=1&pval=0.01&fdr=0.01&pancancerNum=1>.

```{r, eval=FALSE, include=TRUE}
# Using the built-in groundtruth from the miRSM package
Groundtruthcsv <- system.file("extdata", "Groundtruth_high.csv", package="miRSM")
Groundtruth <- read.csv(Groundtruthcsv, header=TRUE, sep=",")
# Using the identified miRNA sponge modules based on WGCNA and sensitivity RV coefficient (SRVC)
miRSM.Validate <- module_Validate(miRSM_WGCNA_SRVC_genes, Groundtruth)
```

## Co-expression analysis of miRNA sponge modules
To evaluate whether the ceRNAs and mRNAs in the miRNA sponge modules are not randomly co-expressed, `miRSM` implements _module_Coexpress_ function to calculate average (mean and median) absolute Pearson correlation of all the ceRNA-mRNA pairs in each miRNA sponge module to see the overall co-expression level between the ceRNAs and mRNAs in the miRNA sponge module. For each miRNA sponge module, `miRSM` performs a permutation test by generating random modules (the parameter _resample_ is the number of random modules to be generated) with the same number of ceRNAs and mRNAs for it to compute the statistical significance p-value of the co-expression level.

```{r, eval=TRUE, include=TRUE}
# Using the identified miRNA sponge modules based on WGCNA and sensitivity RV coefficient (SRVC)
miRSM_WGCNA_Coexpress <-  module_Coexpress(ceRExp, mRExp, miRSM_WGCNA_SRVC_genes, resample = 10, method = "mean", test.method = "t.test")
miRSM_WGCNA_Coexpress
```

## Distribution analysis of sharing miRNAs
To investigate the distribution of sharing miRNAs in the identified miRNA sponge modules, `miRSM` implements _module_miRdistribute_ function. The miRNA distribution analysis can understand whether the sharing miRNAs act as crosslinks across different miRNA sponge modules.

```{r, eval=TRUE, include=TRUE}
# Using the identified miRNA sponge modules based on WGCNA and sensitivity RV coefficient (SRVC)
miRSM_WGCNA_share_miRs <-  share_miRs(miRExp, miRTarget, miRSM_WGCNA_SRVC_genes)
miRSM_WGCNA_miRdistribute <- module_miRdistribute(miRSM_WGCNA_share_miRs)
head(miRSM_WGCNA_miRdistribute)
```

## Predicting miRNA-target interactions
Since the identified miRNA sponge modules and their sharing miRNAs can also be used to predict miRNA-target interactions (including miRNA-ceRNA and miRNA-mRNA interactions), `miRSM` implements _module_miRtarget_ function to predict miRNA-target interactions underlying in each miRNA sponge module. 

```{r, eval=FALSE, include=TRUE}
# Using the identified miRNA sponge modules based on WGCNA and sensitivity RV coefficient (SRVC)
miRSM_WGCNA_miRtarget <- module_miRtarget(miRSM_WGCNA_share_miRs, miRSM_WGCNA_SRVC_genes)
```

## Identifying miRNA sponge interactions
To extract miRNA sponge interactions of each miRNA sponge module, `miRSM` implements _module_miRsponge_ function to identify miRNA sponge interactions.

```{r, eval=FALSE, include=TRUE}
# Using the identified miRNA sponge modules based on WGCNA and sensitivity RV coefficient (SRVC)
miRSM_WGCNA_miRsponge <- module_miRsponge(miRSM_WGCNA_SRVC_genes)
```

# Conclusions
`miRSM` provides several functions to study miRNA sponge modules at single-sample and multi-sample levels, including popular methods for inferring gene modules (candidate miRNA sponge or ceRNA modules), and two functions to identify miRNA sponge modules at single-sample and multi-sample levels, as well as several functions to conduct modular analysis of miRNA sponge modules. It could provide a useful tool for the research of miRNA sponge modules at single-sample and multi-sample levels.

# References
[1] Ambros V. microRNAs: tiny regulators with great potential. Cell, 2001, 107:823–6.

[2] Bartel DP. MicroRNAs: genomics, biogenesis, mechanism, and function. Cell, 2004, 116:281–97.

[3] Du T, Zamore PD. Beginning to understand microRNA function. Cell Research, 2007, 17:661–3.

[4] Esquela-Kerscher A, Slack FJ. Oncomirs—microRNAs with a role in cancer. 
Nature Reviews Cancer, 2006, 6:259–69.

[5] Lin S, Gregory RI. MicroRNA biogenesis pathways in cancer. 
Nature Reviews Cancer, 2015, 15:321–33.

[6] Cesana M, Cacchiarelli D, Legnini I, et al. A long noncoding RNA 
controls muscle differentiation by functioning as a competing endogenous 
RNA. Cell, 2011, 147:358–69.

[7] Poliseno L, Salmena L, Zhang J, et al. A coding-independent function 
of gene and pseudogene mRNAs regulates tumour biology. Nature, 2010,
465:1033–8.

[8] Hansen TB, Jensen TI, Clausen BH, et al. Natural RNA circles function 
as efficient microRNA sponges. Nature, 2013, 495:384–8.

[9] Memczak S, Jens M, Elefsinioti A, et al. Circular RNAs are a large 
class of animal RNAs with regulatory potency. Nature, 2013, 495:333–8.

[10] Salmena L, Poliseno L, Tay Y, et al. A ceRNA hypothesis: the Rosetta Stone 
of a hidden RNA language? Cell, 2011, 146(3):353-8.

[11] Langfelder P, Horvath S. WGCNA: an R package for weighted correlation network analysis. BMC Bioinformatics, 2008, 9:559.

[12] Bunte K, Lepp\"{a}aho E, Saarinen I, Kaski S. Sparse group factor analysis for biclustering of multiple data sources. Bioinformatics, 2016, 32(16):2457-63.

[13] Lepp\"{a}aho E, Ammad-ud-din M, Kaski S. GFA: exploratory analysis of multiple data sources with group factor analysis. J Mach Learn Res., 2017, 18(39):1-5.

[14] Csardi G, Nepusz T. The igraph software package for complex network research, InterJournal, Complex Systems, 2006:1695.

[15] Clauset A, Newman ME, Moore C. Finding community structure in very large networks. Phys Rev E Stat Nonlin Soft Matter Phys., 2004, 70(6 Pt 2):066111.

[16] Enright AJ, Van Dongen S, Ouzounis CA. An efficient algorithm for large-scale detection of protein families. Nucleic Acids Res., 2002, 30(7):1575-84.

[17] Kalinka AT, Tomancak P. linkcomm: an R package for the generation, visualization, and analysis of link communities in networks of arbitrary size and type. Bioinformatics, 2011, 27(14):2011-2.

[18] Bader GD, Hogue CW. An automated method for finding molecular complexes in large protein interaction networks. BMC Bioinformatics, 2003, 4:2.

[19] Zhang Y, Phillips CA, Rogers GL, Baker EJ, Chesler EJ, Langston MA. On finding bicliques in bipartite graphs: a novel algorithm and its application to the integration of diverse biological data types. BMC Bioinformatics, 2014, 15:110.

[20] Gaujoux R, Seoighe C. A flexible R package for nonnegative matrix factorization. BMC Bioinformatics, 2010, 11:367.

[21] R Core Team. R: A language and environment for statistical computing. R Foundation for
  Statistical Computing, Vienna, Austria, 2018.

[22] Langfelder P, Horvath S. Fast R Functions for Robust Correlations and Hierarchical Clustering. 
Journal of Statistical Software. 2012, 46(11):1-17.

[23] Hahsler M, Piekenbrock M. dbscan: Density Based Clustering of
  Applications with Noise (DBSCAN) and Related Algorithms. R package version 1.1-2, 2018.

[24] Cebeci Z, Yildiz F, Kavlak AT, Cebeci C, Onder H. ppclust: Probabilistic and
  Possibilistic Cluster Analysis. R package version 0.1.1, 2018.

[25] Scrucca L, Fop M, Murphy TB, Raftery AE. mclust 5: clustering, classification and density estimation using Gaussian finite mixture models The R Journal 8/1, 2016, pp. 205-233.

[26] Villa-Vialaneix N, Bendhaiba L, Olteanu M. SOMbrero: SOM Bound to Realize Euclidean and Relational Outputs. R package version 1.2-3, 2018.

[27] Cebeci Z, Yildiz F, Kavlak AT, Cebeci C, Onder H. ppclust: Probabilistic and Possibilistic Cluster Analysis. R package version 0.1.2, 2019.

[28] Kaiser S, Santamaria R, Khamiakova T, Sill M, Theron R, Quintales L, Leisch F, De TE. biclust: BiCluster Algorithms. R package version 1.2.0., 2015.

[29] Gusenleitner D, Howe EA, Bentink S, Quackenbush J, Culhane AC. iBBiG: iterative binary bi-clustering of gene sets. Bioinformatics, 2012, 28(19):2484-92.

[30] Hochreiter S, Bodenhofer U, Heusel M, Mayr A, Mitterecker A, Kasim A, Khamiakova T, Van Sanden S, Lin D, Talloen W, Bijnens L, G\"{o}hlmann HW, Shkedy Z, Clevert DA. FABIA: factor analysis for bicluster acquisition. Bioinformatics, 2010, 26(12):1520-7.

[31] Yang J, Wang H, Wang W, Yu, PS. An improved biclustering method for analyzing gene expression. Int J Artif Intell Tools, 2005, 14(5): 771-789.

[32] Bergmann S, Ihmels J, Barkai N. Iterative signature algorithm for the analysis of large-scale gene expression data. Phys Rev E Stat Nonlin Soft Matter Phys., 2003, 67(3 Pt 1):031902.

[33] Sill M, Kaiser S, Benner A, Kopp-Schneider A. Robust biclustering by sparse singular value decomposition incorporating stability selection. Bioinformatics, 2011, 27(15):2089-97.

[34] Rodriguez-Baena DS, Perez-Pulido AJ, Aguilar-Ruiz JS. A biclustering algorithm for extracting bit-patterns from binary datasets. Bioinformatics, 2011, 27(19):2738-45.

[35] Li G, Ma Q, Tang H, Paterson AH, Xu Y. QUBIC: a qualitative biclustering algorithm for analyses of gene expression data. Nucleic Acids Res., 2009, 37(15):e101.

[36] Zhang J, Le TD, Liu L, Li J. Identifying miRNA sponge modules using biclustering and regulatory scores. BMC Bioinformatics, 2017, 18(Suppl 3):44. 

# Session information
```{r}
sessionInfo()
```
