Libraries used to create and generate this report:
R version 4.3.3 (2024-02-29)2.211.421.0.40.341.3.4Libraries used to analyse data:
2.3.11.0.121.4.2Libraries used to load data:
1.16.11.14.86.24.01.0Cytoscape is used for visualization. Figures were generated using the Cytoscape v3.9.1 and several Cytoscape apps:
1.1.31.1.6Similarity Network Fusion (SNF) builds networks of samples for each data type. Then, it fuses them into one network, which represents the full spectrum of underlying data.
In other words, SNF integrates several types of data (e.g. omics data) into one network which represents the relationships between samples.
The SNF methods can be decomposed into three main steps, displayed in the Figure 2.1 (note that patient=samples in the description below):
Figure 2.1: Similarity Network Fusion method overview. The figure is comming from Wang et al., 2014.
In the final fused similarity network (e), you can identify which data type contributes to which edge:
You can retreive more information in:
Choose the dataset on which you want to apply SNF!!
Different datasets are available. Note that each dataset has its specificity and some analysis steps should be adapted.
Figure 3.1: Four datasets are available: Metagenomic dataset from Tara Ocean (image from Sunagawa et al., 2015), Breast cancer dataset from TCGA (image from TCGA website), CLL dataset (Dietrich et al., 2018) and tomato plant dataset (figure from google image).
To retrieve data: files are available in /shared/projects/tp_etbii_2024_165650/Networks/TaraOcean_mibiomics directory path in the IFB server.
dataset:
TARAoceans_proNOGS.cvsTARAoceans_proPhylo.csvmetadata:
TARAoceans_metadata.csvSamples come from eight oceans around the world (SPO: South Pacific Ocean, NAO: North Atlantic Ocean, IO: Indian Ocean, RS: Red Sea, MS: Mediterranean Sea, NPO: North Pacific Ocean, SO: Southern Ocean, SAO: South Atlantic Ocean).
Samples can come from different layers with different temperatures:
In a previous analysis (Sunagawa et al., 2015), they identified a stratification mostly driven by the temperature rather than geography or other environmental factors.
We have two types of data:
Does an integrative analysis of these two data types retrieve the stratification driver by the layers? Does it also find a geographical clustering?
Data are coming from: MiBiOmics gitlab.
To retrieve data:
dataset: using data("breast.TCGA") from the mixOmics R package
breast.TCGA$data.train$mirnabreast.TCGA$data.train$mrnabreast.TCGA$data.train$proteinmetadata: using data("breast.TCGA") from the mixOmics R package
breast.TCGA$data.train$subtypeHuman breast cancer is a heterogeneous disease. Breast tumors can be classified into several subtypes (PAM50 classification), according to the mRNA expression level (Sorlie et al., 2001). In this dataset, we have three subtypes:
We have three types of data:
Does an integrative analysis of these three data types retrieve the classification of the breast cancer? Or find another classification?
Data are coming from the mixOmics R package. The full data can be downloaded here.
To retrieve data:
dataset: using data("CLL_data") from the MOFAdata R package
CLL_data_t$DrugsCLL_data_t$MethylationCLL_data_t$mRNACLL_data_t$Mutationsmetadata: file is available in /shared/projects/tp_etbii_2024_165650/Networks/CLL directory path in the IFB server.
sample_metadata.txtThe Chronic Lymphocytic Leukaemia (CLL) is type of blood and bone marrow cancer. The full data are explained in Dietrich et al., 2018 and available here.
We have four types of data:
To retrieve data: files are available in /shared/projects/tp_etbii_2024_165650/Networks/Tomato directory path in the IFB server.
dataset:
mrna.tsvprots.tsvmetadata:
samples_metadata.tsvIn order to study the protein turnover in developing tomato fruit (Solanum lycopersicum) in Belouah et al., two omics data types were collected:
Each data type was collected in nine different developmental stages: GR1, GR2, GR3, GR4, GR5, GR6, GR7, GR8 and GR9. For each developmental stages, we have three replicates.
Does an integrative analysis of these data types retrieve the different developmental stages?
Data are coming from Belouah et al., 2019.
To retrieve data:
dataset: using data("X") from the WallomicsData R package
Phenomics_RosettesTranscriptomics_Rosettes_CWProteomics_Rosettes_CWmetadata: using data("X") from the WallomicsData R package also
Altitude_ClusterEcotypeIn order to study the cell wall plasticity of Arabidopsis thaliana plants, exposed to different temperature growth conditions, four omics data types were collected :
Each data type was collected for
To see all the available data, have a look to the manual.
Data are explained in Duruflé et al., 2019, 2020 and 2021.
The preprocessing step is the most important part of the analysis. Data need to be prepared correctly in order to extract relevant information and produce a correct and pertinent interpretation of the results.
Data preprocessing could be summarized by four main steps:
Figure 4.1: Distribution examples expected after preprocessing
The data must conform to a specific matrix shape:
HELP!
?functionName().For this tutorial, we assume that the data have been already prepared: outliers are already removed and there is no batch effect.
To load data from a file, you can use read.table() and specify the file name, the sep character and others parameters if it’s necessary.
To load data from a package, you can use data(dataName). Don’t forget to load the corresponding package before with library(packageName).
To load data from a website, you can use fread(url) from the data.table package.
The metadata contains complementary information about samples. You can load the metadata from package or file. See the section 4.2.1 about data loading.
We use mainly the metadata for visualization. So we suggest to follow these recommendations:
data.frame() or as.data.Frame() functions)read.table() use the row.names = 1 parameter)character or numerical (check using str() function)For instance, to load the ortologous gene data from Tara Ocean, the command could be:
tara_nog <- read.table(file = "../00_Data/TaraOcean_mibiomics/TARAoceans_proNOGS.csv", sep = ",", head = TRUE, row.names = 1)
tara_nog[c(1:5), c(1:5)]## NOG317682 NOG135470 NOG85325 NOG285859 NOG147792
## TARA_109_SRF 0 2.390962e-05 0 4.663604e-08 1.800215e-07
## TARA_149_MES 0 4.339824e-06 0 5.182915e-07 4.190123e-06
## TARA_110_MES 0 1.348252e-05 0 6.000043e-07 2.218342e-07
## TARA_102_MES 0 6.380711e-06 0 3.816016e-07 0.000000e+00
## TARA_142_SRF 0 9.484144e-06 0 6.437103e-08 1.132431e-06
Don’t hesitate to look the first rows of your data regularly using head(). It could be more convenient to display only the first 5 rows and columns when the data are big (tara_nog[c(1:5), c(1:5)]).
Practice:
These functions could help you: nrow(), ncol(), lapply(), dim(), t(), names(), type(), as.character() and unique().
In the SNF paper, authors recommend to filter out samples with more than 20% of missing data in a certain data type. They also recommend to filter out features with more than 20% of missing data across samples. Then, they impute the remaining missing data using K nearest neighbors (KNN) imputation.
In this tutorial, we decide to remove samples with at least one missing data. To remove samples with missing data, we propose the following NARemoving() function. Input parameters are:
data: the data typemargin: a vector giving the subscripts which the function will be applied over (e.g. 1 indicates rows and 2 indicates columns)threshold: threshold above which samples/features are deletedNARemoving <- function(data, margin, threshold){
#' NA removing
#'
#' Calculate percentage of na
#' Remove na from rows (margin = 1) or column (margin = 2)
#'
#' @param data data.frame.
#' @param margin int. 1 = row and 2 = column
#' @param threshold int. Number of missing data accepted
#'
#' @return Return data.frame with a specific number of na by row/column
data_na <- apply(data, MARGIN = margin, FUN = function(v){sum(is.na(v)) / length(v) * 100})
# print(table(data_na))
toRemove <- split(names(data_na[data_na > threshold]), " ")[[1]]
if(margin == 1){
data_withoutNa <- data[!(row.names(data) %in% toRemove),]
print(paste0("Remove ", as.character(length(toRemove)), " samples."))
}
if(margin == 2){
data_withoutNa <- data[,!(colnames(data) %in% toRemove)]
print(paste0("Remove ", as.character(length(toRemove)), " features"))
}
return(data_withoutNa)
}For instance, the CLL drug data contain missing data (sample H024).
## D_001_1 D_001_2 D_001_3 D_001_4 D_001_5
## H045 0.02363938 0.04623274 0.3187471 0.8237027 0.8962777
## H109 0.07359900 0.10623002 0.2732891 0.7171379 0.8850003
## H024 NA NA NA NA NA
## H056 0.05813930 0.09022028 0.2322145 0.7225736 0.7957497
## H079 0.02042077 0.04750543 0.3638962 0.8073907 0.8794886
To remove samples with missing data in drug data, we use the following command line:
data = CLL_data_t$Drugs: remove the samples with missing data in the drug datamargin = 1: samples are in rows, so we want to apply the function on the rowsthreshold = 0: we remove samples with at least one missing data## [1] "Remove 16 samples."
The H024 sample is not anymore in the CLL drug data.
## D_001_1 D_001_2 D_001_3 D_001_4 D_001_5
## H045 0.02363938 0.04623274 0.3187471 0.8237027 0.8962777
## H109 0.07359900 0.10623002 0.2732891 0.7171379 0.8850003
## H056 0.05813930 0.09022028 0.2322145 0.7225736 0.7957497
## H079 0.02042077 0.04750543 0.3638962 0.8073907 0.8794886
## H164 0.02962725 0.08054628 0.4725991 0.8179143 0.8927961
We repeat this step for each data type. Then, we filter out samples that are not present in all data type.
sampleNames <- Reduce(intersect, list(rownames(CLL_drug), rownames(CLL_mrna)))
CLL_drug <- CLL_drug[rownames(CLL_drug) %in% sampleNames,]
CLL_mrna <- CLL_mrna[rownames(CLL_mrna) %in% sampleNames,]Practice:
These functions could help you: is.na(), lapply(), table() and view().
The normalization should be adapted according the data type. For the data used here, we assumed that data have been already normalized, according their type. This step is really important, and should be correctly done before every type of data integration.
Each feature (column) needs to have the mean equals to zero and the standard deviation equals to one. For that, the SNF package provides the function standardNormalization().
In the Figure 4.2, you can see the data distribution for the breast cancer miRNA data before (on the left) and after (on the right) scaling. After scaling, the data distribution should be normal.
hist(as.matrix(tcga_mirna), nclass = 100, main = "Breast cancer miRNA data", xlab = "values")
hist(as.matrix(tcga_mirna_scaled), nclass = 100, main = "Breast cancer miRNA scaled data", xlab = "values")Figure 4.2: Breast cancer miRNA data distribution before (left) and after (right) scaling.
Practice:
standardNormalization().
These functions could help you: hist(), as.matrix().
In this section, we create a sample network for each type of data, based on the similarity between samples. The main steps are (Figure 5.1):
Figure 5.1: Similarity network creation overview. Data type 1 is in the first row, represented with the green matrices. Data type 2 is in the last row, represented with the purple matrices.
The similarity network is a sample network. It is defined as a network G with nodes (or vertices) called V and connections (or edges) called E. The connections between samples are weighted. Weights come from the similarity matrix.
We can define the similarity network G like this:
First, we calculate the distance between each pair of samples for each data type using the preprocessed data. The distance method used needs to be adapted to the feature type (e.g. continuous, discrete).
In the SNF paper (Wang et al.), authors suggest to use:
In the SNF R package, the dist2() function performs a squared Euclidean distances between samples.
Practice:
These functions could help you: as.matrix(), dim(), nrow() and ncol().
The distance matrix D is then transformed into the similarity matrix W. Distances are converted to weights using the scaled exponential similarity kernel (µ) and average distances between samples and their nearest neighbors (ε):
\[ W = exp(-\frac{D^2}{µ\varepsilon})\] In other words, distances are converted to weights according the distance with the nearest neighbors of each sample pair.
The SNF R package proposes the affinityMatrix() to calculate this similarity matrix. In this case, affinity and similarity are equivalent. This function needs three parameters:
diff: distance matrix DK: number of nearest neighbors (between 10 and 30)sigma: hyperparameter or variance (between 0.3 and 0.8)The K neighbors is used to set the similarities outside of the neighborhood to zero. The sigma parameter allows scaling exponential similarity kernel, which is used to calculated the similarity.
Then, you can visualized the similarity matrix using the pheatmap() function. This function creates an heatmap of samples. By default samples are clustered using hierarchical clustering. For a better visualization, we recommend to:
show_rownames = FALSE and show_colnames = FALSEannotationlog(x, 10))Practice:
K = 20 and sigma = 0.5 for each data type.Previously, we created a similarity matrix W and its corresponding similarity network G for each data type (Figure 6.1).
Figure 6.1: In the previous step, we create a similarity matrix that contains weights for each data type. We also created the corresponding similarity network.
Now, we integrate these similarity matrices (in the Figure 6.1 there are two data types). For that, we use an iterative fusion method. The number of iteration T, needs to be defined.
First, two matrices are created from the similarity matrix of each data type:
The P matrix carries the full information about the similarity of each samples to all others.
The S matrix carries the similarity to the K most similar samples for each sample (i.e. topology). The similarities between non-neighboring nodes are set to zero because authors assume that local similarities (high weights) are more reliable than the remote ones.
Then, the P matrix of each data type is iteratively updated with information from P matrices of the other data type, making them more similar at each step. In the Figure 6.2, you have an example with two data type. It’s a bit more complex with more data type (see the paper if you are interested in).
Figure 6.2: Example of the fusion method applied to two data types. Each data type is represented using a color: data type 1 in green and data type 2 in purple.
Finally after T iterations, the P matrices of each data type are merged together to create the final fused similarity matrix, and the corresponding fused similarity network.
Then, you can visualize the fused similarity network using Cytoscape.
First, we have to define the number of iteration called T. It should be between 10 and 20 (recommended by the authors).
Then, to perform the fusion, SNF R package proposes the SNF() function. You have to provide:
Practice:
T = 10).
These functions could help you: list(), length().
You can visualize the fused similarity network using Cytoscape.
First, you need to convert the fused similarity matrix into the corresponding fused similarity network. The igraph R package allows to create and manage networks.
You can create a the fused similarity network using the graph_from_adjacency_matrix() function. This function uses a similarity matrix to create the corresponding similarity network.
We don’t want duplicate information about connections between samples, neither connections between samples themselves (self loops). But we want to keep the connection weight values. You can use these parameters:
diag = FALSEmode = "upper"weighted = TRUEThen, you can save the fused similarity network into a edge file using write.table() function.
This is an example of the saving command line:
To create a network using Cytoscape, use the following steps: