---
title: "Working with SpidermiR package"
author: " Claudia Cava, Antonio Colaprico, Alex Graudenzi, Gloria Bertoli,Tiago C. Silva,Catharina Olsen,Houtan Noushmehr, Gianluca Bontempi, Giancarlo Mauri, Isabella Castiglioni"
date: "`r Sys.Date()`"
output:
    BiocStyle::html_document:
        toc: true
        number_sections: false
        toc_depth: 2
        highlight: haddock


references:
- id: ref1
  title: The Gene Mania prediction server biological network integration for gene prioritization and predicting gene function
  author: 
  - family:  Warde-Farley D, Donaldson S, Comes O, Zuberi K, Badrawi R, and others
    given:
  journal: Nucleic Acids Res.
  volume: 38
  number: 2
  pages: 214-220
  issued:
    year: 2010

- id: ref2
  title: miR2Disease a manually curated database for microRNA deregulation in human disease. 
  author: 
  - family: Jiang Q, Wang Y, Hao Y, Juan L, Teng M, Zhang X, Li M, Wang G, Liu Y.
    given:
  journal: Nucleic Acids Res.
  volume: 37
  number: 1
  pages: 98-104
  issued:
    year: 2009


- id: ref3
  title: miRWalk - database prediction of possible miRNA binding sites by "walking" the genes of 3 genomes.
  author: 
  - family: Dweep H, Sticht C, Pandey P, Gretz N.
    given:
  journal: Journal of Biomedical Informatics
  volume: 44
  number: 1
  pages: 839-7
  issued:
    year: 2011

- id: ref4
  title: miRandola Extracellular Circulating microRNAs Database.
  author: 
  - family: Russo F, Di Bella S, Nigita G, Macca V, Lagana A, Giugno R, Pulvirenti A, Ferro A.
    given:
  journal: PLoS ONE
  volume: 7
  number: 10
  pages: e47786
  issued:
    year: 2012

- id: ref5
  title: The igraph software package for complex network research.
  author: 
  - family: Csardi G, Nepusz T.
    given:
  journal: InterJournal
  volume: Complex Systems
  number: 
  pages: 1695
  issued:
    year: 2006


- id: ref6
  title: Pharmaco miR linking microRNAs and drug effects.
  author: 
  - family: Rukov J, Wilentzik R, Jaffe I, Vinther J, Shomron N.
    given:
  journal: Briefings in Bioinformatics
  volume: 15
  number: 4
  pages: 648-59
  issued:
    year: 2013



vignette: >
  %\VignetteIndexEntry{Working with SpidermiR package}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(dpi = 300)
knitr::opts_chunk$set(cache=FALSE)
```

```{r, eval = TRUE, echo = FALSE,hide=TRUE, message=FALSE,warning=FALSE}
devtools::load_all()
```

# Introduction 

Biological systems are composed of multiple layers of dynamic interaction networks. These networks can be decomposed, for example, into: co-expression, physical, co-localization, genetic, pathway, and shared protein domains.

GeneMania provides us with an enormous collection of data sets for interaction network studies [@ref1]. The data can be accessed and downloaded from different database, using a web portal.  But currently, there is not a R-package to query and download these data.

An important regulatory mechanism of these network data involves microRNAs (miRNAs). miRNAs are involved in various cellular functions, such as differentiation, proliferation, and tumourigenesis. 
However, our understanding of the processes regulated by miRNAs is currently limited and the integration of miRNA data in these networks provides a comprehensive genome-scale analysis of miRNA regulatory networks.Actually, GeneMania doesn't integrate the information of miRNAs and their interactions in the network.

`SpidermiR` allows the user to query, prepare, download network data (e.g. from GeneMania), and to integrate this information with miRNA data 
with the possibility to analyze 
these downloaded data directly in one single R package. 
This techincal report gives a short overview of the essential `SpidermiR` methods and their application. 


# Installation

To install use the code below.

```{r, eval = FALSE}
source("https://bioconductor.org/biocLite.R")
biocLite("SpidermiR")
```

# `SpidermiRquery`: Searching network 


You can easily search GeneMania data using the `SpidermiRquery` function.


## `SpidermiRquery_species`: Searching by species
The user can query the species supported by GeneMania, using the function SpidermiRquery_species:


```{r, eval = TRUE}

org<-SpidermiRquery_species(species)
```

The list of species is shown below:
```{r, eval = TRUE, echo = FALSE}
knitr::kable(org, digits = 2,
             caption = "List of species",row.names = TRUE)
```



## `SpidermiRquery_networks_type`: Searching by network categories

The user can query the network types supported by GeneMania for a specific specie, using the function `SpidermiRquery_networks_type`. The user can select a specific specie using an index obtained by the function `SpidermiRquery_species` (e.g. organismID=org[6,] is the input for Homo_sapiens,organismID=org[9,]  is the input for Saccharomyces cerevisiae  )

```{r, eval = TRUE}
net_type<-SpidermiRquery_networks_type(organismID=org[9,])
```

The list of network categories in Saccharomyces cerevisiae is shown below:

```{r, eval = TRUE, echo = FALSE}
net_type
```


## `SpidermiRquery_spec_networks`: Searching by species, and network categories
You can filter the search by species using organism ID (above reported), and the network category.
The network category can be filtered using the following parameters: 

* **COexp** Co-expression 
* **PHint** Physical_interactions 
* **COloc**  Co-localization 
* **GENint** Genetic_interactions 
* **PATH** Pathway 
* **SHpd**  Shared_protein_domains 
* **pred**  predicted

```{r, eval = TRUE}

net_shar_prot<-SpidermiRquery_spec_networks(organismID = org[9,],
                                    network = "SHpd")
```

The databases, which data are collected, are the output of this step. An example is shown below ( for Shared protein domains in Saccharomyces_cerevisiae data are collected in INTERPRO, and PFAM):
```{r, eval = TRUE, echo = FALSE}
net_shar_prot
```


## `SpidermiRquery_disease`: Searching by miRNA-disease 

The user can obtain a list of the diseases supported by SpidermiR, in order to focus only on miRNAs that have been already studied in a particular disease (retrieving data from miR2Disease [@ref2]).

```{r, eval = TRUE}
disease<-SpidermiRquery_disease(diseaseID)
```

Currently, the list of diseases supported is:

```{r, eval = TRUE, echo = FALSE}
disease
```

# `SpidermiRdownload`: Downloading network data
The user in this step can download the data, as previously queried.

## `SpidermiRdownload_net`: Download network
The user can download the data (previously queried) with `SpidermiRdownload_net`.

```{r, eval = TRUE}
out_net<-SpidermiRdownload_net(net_shar_prot)
```


The list of SpidermiRdownload_net is shown below:
```{r, eval = TRUE, echo = FALSE}
str(out_net)
```

## `SpidermiRdownload_miRNAprediction`: Downloading miRNA predicted data target
The user can download the predicted miRNA-gene from 4 databases:DIANA, Miranda, PicTar and TargetScan 

```{r, eval = FALSE}
mirna<-c('hsa-miR-567','hsa-miR-566')
SpidermiRdownload_miRNAprediction(mirna_list=mirna)
```
## `SpidermiRdownload_miRNAvalidate`: Downloading miRNA validated data target
The user can download the validated miRNA-gene from: miRTAR and miRwalk [@ref2] [@ref3]. 

```{r, eval = FALSE}
list<-SpidermiRdownload_miRNAvalidate(validated)
```


## `SpidermiRdownload_miRNAextra_cir`:Download Extracellular Circulating microRNAs
The user can download extracellular circulating miRNAs from miRandola database

```{r, eval = FALSE}
list<-SpidermiRdownload_miRNAextra_cir(miRNAextra_cir)
```


## `SpidermiRdownload_pharmacomir`: Download Pharmaco-miR Verified Sets from PharmacomiR database
The user can download Pharmaco-miR Verified Sets from PharmacomiR database [@ref6].

```{r, eval = TRUE}
mir_pharmaco<-SpidermiRdownload_pharmacomir(pharmacomir=pharmacomir)
```



# `SpidermiRprepare`: Preparing the data

## `SpidermiRprepare_NET`: Prepare matrix of gene network  with Ensembl Gene ID, and gene symbols
`SpidermiRprepare_NET` reads network data from `SpidermiRdownload_net` and enables user to prepare them for downstream analysis. In particular, it prepares matrix of gene network mapping Ensembl Gene ID to gene symbols. Gene symbols are needed to integrate miRNAdata. 


```{r, eval = TRUE}

geneSymb_net<-SpidermiRprepare_NET(organismID = org[9,],
                                    data = out_net)
```

The network with gene symbols ID is shown below:
```{r, eval = TRUE, echo = FALSE}
knitr::kable(geneSymb_net[[1]][1:5,c(1,2,3,5,8)], digits = 2,
             caption = "shared protein domain",row.names = FALSE)
```

# `SpidermiRanalyze`: : Analyze data from network data

## `SpidermiRanalyze_mirna_network`: Integration of microRNA-target interactions. 
The user in this step obtained a network matrix with miRNA-target interactions starting from a specific network. The user can focus on miRNAs that have been already linked to a particular disease or take all miRNAs. miRNA-gene interactions include data from validated or predicted studies.
You can filter the search by disease.
The miRNA network can be filtered by disease using the name of the disease, as obtained from `SpidermiRquery_disease`.


```{r, eval = TRUE}
miRNA_NET<-SpidermiRanalyze_mirna_network(data=geneSymb_net,disease="prostate cancer",miR_trg="val")
```

The list of miRNA network is shown below:
```{r, eval = TRUE, echo = FALSE}
str(miRNA_NET)
```



## `SpidermiRanalyze_mirna_gene_complnet`: Integration of microRNA-target complete interactions 
The user in this step obtained a gene network matrix with miRNA-gene   and gene-gene interaction. 
The user can focus on miRNAs that have been already linked to a particular disease or take all miRNAs. miRNA-gene interactions include data from validated or predicted studies.
The miRNA network can be filtered by disease using the name of the disease, as obtained from `SpidermiRquery_disease`.


```{r, eval = FALSE}
miRNA_complNET<-SpidermiRanalyze_mirna_gene_complnet(data=geneSymb_net,disease="prostate cancer",miR_trg="val")
```


## `SpidermiRanalyze_mirnanet_pharm`: Integration of pharmacomiR in the network
The user in this step can integrate the pharmacomiR database in order to link miRNA and drug effect in a specific network.

```{r, eval = TRUE}
mir_pharmnet<-SpidermiRanalyze_mirnanet_pharm(mir_ph=mir_pharmaco,net=miRNA_NET)
```



## `SpidermiRanalyze_mirna_extra_cir`: Integration of Extracellular/Circulating miRNA

The user can select the extracellular/circulating miRNAs found in the obtained network.
Extracellular/circulating miRNAs include data from mirandola database [@ref4].
The user using the following parameteres can specify the network type: 

* **mT** to obtain a miRNA-gene interaction
* **mCT** to obtain a miRNA-gene-gene interaction.

```{r, eval = FALSE}
miRNA_NET_ext_circmT<-SpidermiRanalyze_mirna_extra_cir(data=miRNA_complNET,"mT")
```



```{r, eval = FALSE}
miRNA_NET_ext_circmCT<-SpidermiRanalyze_mirna_extra_cir(data=miRNA_complNET,"mCT")
```

## `SpidermiRanalyze_direct_net`: Searching by biomarkers of interest with direct interaction

Starting from a set of biomarkers of interest (BI), genes, miRNA or both, given by the user, this function finds sub-networks including all direct interactions involving at least one of the BI.

```{r, eval = TRUE}
biomark_of_interest<-c("hsa-miR-214","PTEN","FOXO1","hsa-miR-27a")

GIdirect_net<-SpidermiRanalyze_direct_net(data=miRNA_NET,BI=biomark_of_interest)
```

The data frame of `SpidermiRanalyze_direct_net`, GIdirect_net, is shown below:
```{r, eval = TRUE, echo = FALSE}
str(GIdirect_net)
```

## `SpidermiRanalyze_direct_subnetwork`: Network composed by only the nodes in a set of biomarkers of interest

Starting from  BI, this function finds sub-networks including all direct interactions involving only BI.

```{r, eval = FALSE}

subnet<-SpidermiRanalyze_direct_subnetwork(data=miRNA_NET,BI=biomark_of_interest)

```



## `SpidermiRanalyze_subnetwork_neigh`: Network composed by the nodes in the list of BI and all the edges among this brunch of nodes. 

Starting from  BI, this function finds sub-networks including all direct and indirect interactions involving at least one of BI.


```{r, eval = FALSE}

GIdirect_net_neigh<-SpidermiRanalyze_subnetwork_neigh(data=miRNA_NET,BI=biomark_of_interest)
```



## `SpidermiRanalyze_degree_centrality`: Ranking degree centrality genes

This function finds the number of direct neighbours of a BI and allows the selection of those BI with a number of direct neighbours higher than a selected cut-off.

```{r, eval = FALSE}
top10_cent_gene<-SpidermiRanalyze_degree_centrality(miRNA_NET,cut=10)
```



## `SpidermiRanalyze_Community_detection`: Find community detection

This function find the communities in the network, and describes them in terms of number of community elements (both genes and miRNAs). The function uses one of the algorithms currently implemented in [@ref5], selected by the user according to the user need. 

The user can choose the algorithm in order to calculate the community structure: 

* **EB** edge.betweenness.community
* **FC** fastgreedy.community
* **WC**  walktrap.community 
* **SC** spinglass.community
* **LE** leading.eigenvector.community
* **LP**  label.propagation.community 




```{r, eval = FALSE}
comm<-  SpidermiRanalyze_Community_detection(data=miRNA_NET,type="FC")
```



## `SpidermiRanalyze_Community_detection_net`: Community detection

Starting from one community to which some BI belong (the output of the previously described function) this function describes the community as network of elements (both genes and miRNAs).

```{r, eval = FALSE}
cd_net<-SpidermiRanalyze_Community_detection_net(data=miRNA_NET,comm_det=comm,size=1)
```


## `SpidermiRanalyze_Community_detection_bi`: Community detection from a set of biomarkers of interest

Starting from the community to which BI belong (the output of the previously described function), this function indicates if a set of BI is included within such community.

```{r, eval = FALSE}
gi=c("CF","ROCK1","KIT","CCND2")
mol<-SpidermiRanalyze_Community_detection_bi(data=comm,BI=gi)
```

# `SpidermiRvisualize`: To visualize the network 
## `SpidermiRvisualize_mirnanet`: To Visualize the network. 
The user can visualize a 3D representation of the network  in different colours for miRNA, genes, and pharmaco.  The user can manage the network directly moving the nodes and the edges, in order to interpret the results in the graphic way. 

```{r, eval = TRUE}
library(networkD3)

SpidermiRvisualize_mirnanet(data=mir_pharmnet[sample(nrow(mir_pharmnet), 100), ] )
```

## `SpidermiRvisualize_BI`: To Visualize the network from a set of BI. 

Starting from a graphical representation of a network, the user can highlight with a different color specific BI. 

```{r, eval = TRUE}

biomark_of_interest<-c("hsa-let-7b","MUC1","PEX7","hsa-miR-222")
SpidermiRvisualize_BI(data=mir_pharmnet[sample(nrow(mir_pharmnet), 100), ],BI=biomark_of_interest)
```


## `SpidermiRvisualize_direction`: To visualize the network 
```{r, eval = TRUE}
library(visNetwork)

SpidermiRvisualize_direction(data=mir_pharmnet[sample(nrow(mir_pharmnet), 100), ] )
```


## `SpidermiRvisualize_plot_target`: Visualize the plot with miRNAs and the number of their targets in the network. 
For each BI of a community, the user can visualize a plot showing the number of direct neighbours of such BI (the degree centrality of such BI).

```{r, eval = TRUE}

SpidermiRvisualize_plot_target(data=miRNA_NET[1:15,])
```

## `SpidermiRvisualize_degree_dist`: plots the degree distribution of the network 
This function plots the cumulative frequency distribution of degree centrality of a community.

```{r,fig.width=4, fig.height=4, eval = TRUE}
SpidermiRvisualize_degree_dist(data=miRNA_NET)
```


## `SpidermiRvisualize_adj_matrix`: plots the adjacency matrix of the network
It plots the adjacency matrix of the community, representing the degree of connections among the nodes.

```{r, fig.width=10, fig.height=10,eval = TRUE}
SpidermiRvisualize_adj_matrix(data=miRNA_NET[1:30,])
```

## `SpidermiRvisualize_3Dbarplot`: 3D barplot 
It plots a summary representation of the networks with the number of edges, nodes and miRNAs.

```{r,fig.width=4, fig.height=4, eval = TRUE}
SpidermiRvisualize_3Dbarplot(Edges_1net=1041003,Edges_2net=100016,Edges_3net=3008,Edges_4net=1493,Edges_5net=1598,NODES_1net=16502,NODES_2net=13338,NODES_3net=1429,NODES_4net=675,NODES_5net=712,nmiRNAs_1net=0,nmiRNAs_2net=74,nmiRNAs_3net=0,nmiRNAs_4net=0,nmiRNAs_5net=37)
```


```{r, eval = TRUE,echo = FALSE}
B<-matrix( c("Gene network", "Validated miRNA-target","","", "Predicted miRNA-target","","","", "Extracellular Circulating microRNAs", "miRNA-disease", "Drug Associations",
      
             "GeneMania", "miRTAR", "miRwalk","miRTarBase", "DIANA", "Miranda", "PicTar","TargetScan","miRandola","miR2disease","Pharmaco-miR",
             
             "Current","N/A","miRwalk2","miRTarBase 7","DIANA- 5.0","N/A","N/A","TargetScan7.1","miRandola v 02/2017","N/A","N/A",
             2016,2009,2015,2017,2013,2010,"N/A","2016",2017,2009,"N/A",
             "http://genemania.org/data/current/","http://watson.compbio.iupui.edu:8080/miR2Disease/download/miRtar.txt","http://zmf.umm.uni-heidelberg.de/apps/zmf/mirwalk2/downloads/vtm/hsa-vtm-gene.rdata.zip","mirtarbase.mbc.nctu.edu.tw/cache/download/7.0/miRTarBase_SE_WR.xls","https://bioconductor.org/packages/release/bioc/html/miRNAtap.html","https://bioconductor.org/packages/release/bioc/html/miRNAtap.html","https://bioconductor.org/packages/release/bioc/html/miRNAtap.html","https://bioconductor.org/packages/release/bioc/html/miRNAtap.html","http://mirandola.iit.cnr.it/download/miRandola_version_02_2017.txt","http://watson.compbio.iupui.edu:8080/miR2Disease/download/AllEntries.txt","http://pharmaco-mir.org/home/download_VERSE_db/pharmacomir_VERSE_DB.csv"
             
             ), nrow=11, ncol=5)
colnames(B)<-c("CATEGORY","EXTERNAL DATABASE","VERSION","LAST UPDATE","LINK")

```

# `Features databases SpidermiR`: 

Features of databases integrated in `SpidermiR` are:
```{r, eval = TRUE, echo = FALSE}
knitr::kable(B, digits = 2,
             caption = "Features",row.names = FALSE)
```



# SpidermiR Downstream Analysis: Case Study Please see `SpidermiR:Application Examples` for more information.
## Case Study n.1: Role of miRNAs in shared protein domains network in Prostate Cancer

In this case study, we downloaded shared protein domains network in Homo Sapiens, using SpidermiRquery, SpidermiRprepare, and SpidermiRdownload.   

Then, we focused on role of miRNAs in this network. We integrated miRNA information using SpidermiRanalyze. We obtained a big network, and in order to understand the underlying biological process of a set of biomarker of interest (e.g. from DEG) we performed an analysis to identify their neighbor biomarkers in the shared protein domains network. Please see `SpidermiR:Application Examples` for more information. 

SpidermiRvisualize was used to see the results.

```{r, eval = FALSE}

a<-Case_Study1_loading_1_network(species)
b<-Case_Study1_loading_2_network(data=a)
c<-Case_Study1_loading_3_network(data=b,dataFilt=dataFilt,dataClin=dataClin)
d<-Case_Study1_loading_4_network(TERZA_NET=c)

```

## Case Study n.2: miRNAs regulating degree centrality genes in physical interactions network in breast cancer

We studied in this case study the relationships between miRNAs with higher centrality and their target proteins with higher centrality. Please see `SpidermiR:Application Examples` for more information. 


```{r, eval = FALSE}
a2<-Case_Study2_loading_1_network(species)
b2<-Case_Study2_loading_2_network(data=a2)
c2<-Case_Study2_loading_3_network(sdas=a2,miRNA_NET=b2)
```

******

Session Information
******
```{r sessionInfo}
sessionInfo()
```

# References
