1 Introduction

Methods to find similarities have been developed for several purposes, being Jaccard and Dice similarities the most known. In bioinformatics much of the research on the topic is centered around Gene Ontologies because they provide controlled vocabularies, as part of their mission:

The mission of the GO Consortium is to develop an up-to-date, comprehensive, computational model of biological systems, from the molecular level to larger pathways, cellular and organism-level systems.

However, there is another resource of similarities between genes: metabolic pathways. Metabolic pathways describe the relationship between genes, proteins, lipids and other elements of the cells. A pathway describes, to some extent, the function in which it is involved in the cell. There exists several databases about which gene belong to which pathway. Together with pathways, gene sets related to a function or to a phenotype are a source of information of the genes function. With this package we provide the methods to calculate functional similarities based on this information.

Here we provides functions to calculate functional similarities for pathways, gene sets, genes and clusters of genes. The name BioCor stands from biological correlation, shortened to BioCor, because as said we look if some genes are in the same pathways or gene sets as other genes.

As it development started aiming to improve clustering of genes by functionality in weighted gene co-expression networks using WGCNA. The package has some functions to combine similarities in order to integrate with WGCNA.

2 Citation

The main article describing the software and its usefulness is currently under writing. However you can cite as said in:

citation("BioCor")

3 Installation

The BioCor package is available at Bioconductor and can be downloaded and installed via biocLite:

source("http://bioconductor.org/biocLite.R")
biocLite("BioCor")

You can install the latest version of BioCor from Github with:

library("devtools")
install_github("llrs/BioCor")

4 Using BioCor

4.1 Preparation

We can load the package and prepare the data for which we want to calculate the similarities:

library("BioCor")
## Load libraries with the data of the pathways
library("org.Hs.eg.db")
library("reactome.db")
genesKegg <- as.list(org.Hs.egPATH)
genesReact <- as.list(reactomeEXTID2PATHID)
# Remove genes and pathways which are not from human pathways 
genesReact <- sapply(genesReact, function(x){grep("R-HSA-", x, value = TRUE)}) 
genesReact <- genesReact[lengths(genesReact) >= 1] 

To avoid having biased data it is important to have all the data about the pathways and genes associated to all pathways for the organism under study. Here we assume that we are interested in human pathways. We use this two databases KEGG and Reactome as they are easy to obtain the data. However KEGG database is no longer free for large retrievals therefore it is not longer updated in the Bioconductor annotation packages.

However, one can use any list where the names of the list are the genes and the elements of the list the pathways or groups where the gene belong. One could also read from a GMT file or use GeneSetCollections in addition or instead of those associations from a pathway database and convert it to list using:

library("GSEABase")
paths2Genes <- geneIds(getGmt("/path/to/file.symbol.gmt",
                 geneIdType=SymbolIdentifier()))

genes <- unlist(paths2Genes, use.names = FALSE)
pathways <- rep(names(paths2Genes), lengths(paths2Genes))
genes2paths <- split(pathways, genes) # List of genes and the gene sets

With genes2paths we have the information ready to use.

4.2 Pathway similarities

We can compute similarities (Dice similarity, see question 1 of FAQ) between two pathways or between several pathways and combine them, or not:

(paths <- sample(unique(unlist(genesReact)), 2))
## [1] "R-HSA-1236394" "R-HSA-1660661"
pathSim(paths[1], paths[2], genesReact)
## [1] 0

(pathways <- sample(unique(unlist(genesReact)), 10))
##  [1] "R-HSA-2990846" "R-HSA-1296072" "R-HSA-77075"   "R-HSA-3000497"
##  [5] "R-HSA-2142850" "R-HSA-446205"  "R-HSA-169131"  "R-HSA-5689901"
##  [9] "R-HSA-1482839" "R-HSA-176033"
mpathSim(pathways, genesReact)
##               R-HSA-2990846 R-HSA-1296072 R-HSA-77075 R-HSA-3000497
## R-HSA-2990846   0.789156627             0           0             0
## R-HSA-1296072   0.000000000             1           0             0
## R-HSA-77075     0.000000000             0           1             0
## R-HSA-3000497   0.000000000             0           0             1
## R-HSA-2142850   0.000000000             0           0             0
## R-HSA-446205    0.000000000             0           0             0
## R-HSA-169131    0.000000000             0           0             0
## R-HSA-5689901   0.009852217             0           0             0
## R-HSA-1482839   0.000000000             0           0             0
## R-HSA-176033    0.273170732             0           0             0
##               R-HSA-2142850 R-HSA-446205 R-HSA-169131 R-HSA-5689901
## R-HSA-2990846             0            0            0   0.009852217
## R-HSA-1296072             0            0            0   0.000000000
## R-HSA-77075               0            0            0   0.000000000
## R-HSA-3000497             0            0            0   0.000000000
## R-HSA-2142850             1            0            0   0.000000000
## R-HSA-446205              0            1            0   0.000000000
## R-HSA-169131              0            0            1   0.000000000
## R-HSA-5689901             0            0            0   1.000000000
## R-HSA-1482839             0            0            0   0.000000000
## R-HSA-176033              0            0            0   0.000000000
##               R-HSA-1482839 R-HSA-176033
## R-HSA-2990846             0    0.2731707
## R-HSA-1296072             0    0.0000000
## R-HSA-77075               0    0.0000000
## R-HSA-3000497             0    0.0000000
## R-HSA-2142850             0    0.0000000
## R-HSA-446205              0    0.0000000
## R-HSA-169131              0    0.0000000
## R-HSA-5689901             0    0.0000000
## R-HSA-1482839             1    0.0000000
## R-HSA-176033              0    1.0000000

When the method to combine the similarities is set to NULL mpathSim returns a matrix of pathway similarities, otherwise it combines the values. In the next section we can see the methods to combine pathway similarities.

4.2.1 Combining values

To combine values we provide a function with several methods:

sim <- mpathSim(pathways, genesReact)
methodsCombineScores <- c("avg", "max", "rcmax", "rcmax.avg", "BMA",
                          "reciprocal")
sapply(methodsCombineScores, combineScores, scores = sim)
##        avg        max      rcmax  rcmax.avg        BMA reciprocal 
##  0.1035520  1.0000000  0.9789157  0.9789157  0.9789157  0.9789157

We can also specify the method to combine the similarities in mpathSim, geneSim, mgeneSim, clusterSim, mclusterSim, clusterGeneSim and mclusterGeneSim, argument method. By default the method is set to “max” to combine pathways (except in mpathSim where the default is to show all the pathway similarities) and “BMA” to combine similarities of genes or for cluster analysis. This function is adapted from GOSemSim package.

The function combineScoresPar allows to use a parallel background (using BiocParallel) to combine the scores. It is recommended to use a parallel background if you calculate more than 300 gene similarities. It also have an argument in case you want to calculate the similarity scores of severeal sets.

4.3 Gene similarities

To compare the function of two genes there is the geneSim function and mgeneSim function for several comparisons. In this example we compare the genes BRCA1 and BRCA2 and NAT2, which are the genes 672, 675 and 10 respectively in ENTREZID:

geneSim("672", "675", genesKegg)
## [1] 0.0824295
geneSim("672", "675", genesReact)
## [1] 1

mgeneSim(c("BRCA1" = "672", "BRCA2" = "675", "NAT2" = "10"), genesKegg)
##           BRCA1       BRCA2        NAT2
## BRCA1 1.0000000 0.082429501 0.000000000
## BRCA2 0.0824295 1.000000000 0.008241758
## NAT2  0.0000000 0.008241758 1.000000000
mgeneSim(c("BRCA1" = "672", "BRCA2" = "675", "NAT2" = "10"), genesReact)
##           BRCA1      BRCA2       NAT2
## BRCA1 1.0000000 1.00000000 0.14148472
## BRCA2 1.0000000 1.00000000 0.07012901
## NAT2  0.1414847 0.07012901 1.00000000

Note that for the same genes each database or list provided has different annotations, which result on different similarity scores. In this example BRCA1 has 3 and 14 pathways in KEGG and Reactome respectively and BRCA2 has 1 and 39 pathways in KEGG and Reactome respectively which results on different scores.

4.4 Gene cluster similarities

There are two methods:

  • Combining all the pathways for each cluster and compare between them.
  • Calculate the similarity between genes of a cluster and the other cluster.

4.4.1 By pathways

As explained, in this method all the pathways of a cluster are compared with all the pathways of the other cluster. If a method to combine pathways similarities is not provided, all pathway similarities are returned:

clusterSim(c("672", "675"), c("100", "10", "1"), genesKegg)
## [1] 0.04210526
clusterSim(c("672", "675"), c("100", "10", "1"), genesKegg, NULL)
##            00230       01100       05340 00232 00983
## 04120 0.00000000 0.000000000 0.011764706     0     0
## 03440 0.04210526 0.006908463 0.000000000     0     0
## 05200 0.00000000 0.008241758 0.005540166     0     0
## 05212 0.00000000 0.001666667 0.019047619     0     0

clusters <- list(cluster1 = c("672", "675"),
                 cluster2 = c("100", "10", "1"),
                 cluste