Skip to content

Commit

Permalink
GOSEMSIM and Mantel test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazzat Aibekova authored and Lazzat Aibekova committed Jul 1, 2019
1 parent 3e8f2db commit 0874a7d
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 0 deletions.
13 changes: 13 additions & 0 deletions GOSEMSIM_matrix_microbiome_up.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"","V1","V2","V3","V4","V5","V6","V7","V8","V9","V10","V11","V12"
"1",0,0.95,0.933,0.941,0.953,0.951,0.942,0.935,0.932,0.938,0.945,0.936
"2",0,0,0.956,0.929,0.96,0.962,0.944,0.961,0.958,0.956,0.945,0.973
"3",0,0,0,0.938,0.942,0.948,0.954,0.962,0.96,0.956,0.953,0.957
"4",0,0,0,0,0.941,0.937,0.963,0.943,0.942,0.954,0.979,0.938
"5",0,0,0,0,0,0.965,0.938,0.958,0.953,0.948,0.953,0.949
"6",0,0,0,0,0,0,0.951,0.946,0.943,0.963,0.949,0.944
"7",0,0,0,0,0,0,0,0.953,0.954,0.975,0.969,0.949
"8",0,0,0,0,0,0,0,0,0.992,0.957,0.959,0.97
"9",0,0,0,0,0,0,0,0,0,0.958,0.958,0.967
"10",0,0,0,0,0,0,0,0,0,0,0.964,0.953
"11",0,0,0,0,0,0,0,0,0,0,0,0.953
"12",0,0,0,0,0,0,0,0,0,0,0,0
13 changes: 13 additions & 0 deletions GOSEMSIM_matrix_mite_up.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"","V1","V2","V3","V4","V5","V6","V7","V8","V9","V10","V11","V12"
"1",0,0.972,0.972,0.971,0.968,0.969,0.968,0.967,0.967,0.972,0.973,0.973
"2",0,0,0.974,0.971,0.968,0.967,0.968,0.966,0.968,0.974,0.962,0.988
"3",0,0,0,0.968,0.965,0.965,0.97,0.963,0.961,0.974,0.966,0.972
"4",0,0,0,0,0.974,0.968,0.973,0.976,0.975,0.973,0.979,0.974
"5",0,0,0,0,0,0.963,0.956,0.98,0.973,0.958,0.971,0.969
"6",0,0,0,0,0,0,0.975,0.958,0.962,0.978,0.968,0.969
"7",0,0,0,0,0,0,0,0.963,0.969,0.986,0.973,0.972
"8",0,0,0,0,0,0,0,0,0.983,0.96,0.974,0.968
"9",0,0,0,0,0,0,0,0,0,0.963,0.976,0.97
"10",0,0,0,0,0,0,0,0,0,0,0.97,0.977
"11",0,0,0,0,0,0,0,0,0,0,0,0.969
"12",0,0,0,0,0,0,0,0,0,0,0,0
146 changes: 146 additions & 0 deletions GOSemSim_Mantel.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
title: "GOSemSim_mantel"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, cache = T)
```

```{r}
library(GOSemSim)
library(org.Dm.eg.db)
library(vegan)
```
###Reference for Fly
```{r}
d = godata('org.Dm.eg.db', ont = "BP", computeIC = FALSE)
contrast = read.csv("contrasts_mite_life_stages.csv", header = F)
```

#UP_REGULATED
##MITE
```{r cachedChunk, cache=TRUE}
GOSEMSIM_matrix_mite_up = matrix(0, 12, nrow=12)
for(i in 1:(length(contrast$V1)-1))
{
first_contrast = toString(contrast$V1[i])
second_contrast = toString(contrast$V2[i])
filename = paste("./GO_enrichment_output/contrast_", first_contrast, "_", second_contrast, "_upregulated", ".csv", sep = "")
GO1 = read.csv(filename, header = T)
GO1ID = as.character(GO1[,1])
for(j in (i+1):length(contrast$V1))
{
print(paste(i, j))
first_contrast = toString(contrast$V1[j])
second_contrast = toString(contrast$V2[j])
filename = paste("./GO_enrichment_output/contrast_", first_contrast, "_", second_contrast, "_upregulated", ".csv", sep = "")
GO2 = read.csv(filename, header = T)
GO2ID = as.character(GO2[,1])
GOSEMSIM_matrix_mite_up[i,j] <- mgoSim(GO1ID, GO2ID, semData = d, measure = "Wang", combine = "BMA")
}
}
```
###MICROBIOME
```{r cachedChunk, cache=TRUE}
GOSEMSIM_matrix_microbiome_up = matrix(0, 12, nrow=12)
for(i in 1:(length(contrast$V1)-1))
{
first_contrast = toString(contrast$V1[i])
second_contrast = toString(contrast$V2[i])
filename = paste("./GO_enrichment_microbiome_output/contrast_", first_contrast, "_", second_contrast, "_upregulated", ".csv", sep = "")
GO1 = read.csv(filename, header = T)
GO1ID = as.character(GO1[,1])
for(j in (i+1):(length(contrast$V1)))
{
print(paste(i, j))
first_contrast = toString(contrast$V1[j])
second_contrast = toString(contrast$V2[j])
filename = paste("./GO_enrichment_microbiome_output/contrast_", first_contrast, "_", second_contrast, "_upregulated", ".csv", sep = "")
GO2 = read.csv(filename, header = T)
GO2ID = as.character(GO2[,1])
GOSEMSIM_matrix_microbiome_up[i,j] <- mgoSim(GO1ID, GO2ID, semData = d, measure = "Wang", combine = "BMA")
}
}
```

```{r cachedChunk, cache=TRUE}
microb_dist_up = as.dist(t(GOSEMSIM_matrix_microbiome_up))
mite_dist_up = as.dist(t(GOSEMSIM_matrix_mite_up))
mantel(mite_dist_up, microb_dist_up)
```

```{r}
write.csv(as.data.frame(GOSEMSIM_matrix_microbiome_up), "GOSEMSIM_matrix_microbiome_up.csv")
write.csv(as.data.frame(GOSEMSIM_matrix_mite_up), "GOSEMSIM_matrix_mite_up.csv")
```

#DOWN_REGULATED
##MITE
```{r cachedChunk, cache=TRUE}
GOSEMSIM_matrix_mite_down = matrix(0, 12, nrow=12)
for(i in 1:(length(contrast$V1)-1))
{
first_contrast = toString(contrast$V1[i])
second_contrast = toString(contrast$V2[i])
filename = paste("./GO_enrichment_output/contrast_", first_contrast, "_", second_contrast, "_downregulated", ".csv", sep = "")
GO1 = read.csv(filename, header = T)
GO1ID = as.character(GO1[,1])
for(j in (i+1):length(contrast$V1))
{
print(paste(i, j))
first_contrast = toString(contrast$V1[j])
second_contrast = toString(contrast$V2[j])
filename = paste("./GO_enrichment_output/contrast_", first_contrast, "_", second_contrast, "_downregulated", ".csv", sep = "")
GO2 = read.csv(filename, header = T)
GO2ID = as.character(GO2[,1])
GOSEMSIM_matrix_mite_down[i,j] <- mgoSim(GO1ID, GO2ID, semData = d, measure = "Wang", combine = "BMA")
}
}
```
###MICROBIOME
```{r cachedChunk, cache=TRUE}
GOSEMSIM_matrix_microbiome_down = matrix(0, 12, nrow=12)
for(i in 1:(length(contrast$V1)-1))
{
first_contrast = toString(contrast$V1[i])
second_contrast = toString(contrast$V2[i])
filename = paste("./GO_enrichment_microbiome_output/contrast_", first_contrast, "_", second_contrast, "_downregulated", ".csv", sep = "")
GO1 = read.csv(filename, header = T)
GO1ID = as.character(GO1[,1])
for(j in (i+1):(length(contrast$V1)))
{
print(paste(i, j))
first_contrast = toString(contrast$V1[j])
second_contrast = toString(contrast$V2[j])
filename = paste("./GO_enrichment_microbiome_output/contrast_", first_contrast, "_", second_contrast, "_downregulated", ".csv", sep = "")
GO2 = read.csv(filename, header = T)
GO2ID = as.character(GO2[,1])
GOSEMSIM_matrix_microbiome_down[i,j] <- mgoSim(GO1ID, GO2ID, semData = d, measure = "Wang", combine = "BMA")
}
}
```

```{r cachedChunk, cache=TRUE}
microb_dist_down = as.dist(t(GOSEMSIM_matrix_microbiome_down))
mite_dist_down = as.dist(t(GOSEMSIM_matrix_mite_down))
mantel(mite_dist_down, microb_dist_down)
```

```{r}
write.csv(as.data.frame(GOSEMSIM_matrix_microbiome_down), "GOSEMSIM_matrix_microbiome_down.csv")
write.csv(as.data.frame(GOSEMSIM_matrix_mite_down), "GOSEMSIM_matrix_mite_down.csv")
```

```{r cachedChunk, cache=TRUE}
plot(microb_dist_down,mite_dist_down, main = "Down-regulated GO term correlation plot")
```

45 changes: 45 additions & 0 deletions GOSemSim_miteVSmicrobiome.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
library(GOSemSim)
library(org.Dm.eg.db)
#Reference for Fly
d = godata('org.Dm.eg.db', ont = "BP", computeIC = FALSE)
contrast = read.csv("contrasts_mite_life_stages.csv", header = F)

similarities_upregulated = list()
similarities_downregulated = list()
contrast_names = list()

for (id in 1:length(contrast$V1))
{
print(paste(id, "id"))
first_contrast = toString(contrast$V1[id])
second_contrast = toString(contrast$V2[id])

#UP-REGULATED
filename = paste("./GO_enrichment_microbiome_output/contrast_", first_contrast, "_", second_contrast, "_upregulated", ".csv", sep = "")
GO1 = read.csv(filename, header = T)
GO1ID = as.character(GO1[,1])

filename = paste("./GO_enrichment_output/contrast_", first_contrast, "_", second_contrast, "_upregulated", ".csv", sep = "")
GO2 = read.csv(filename, header = T)
GO2ID = as.character(GO2[,1])

name = paste(first_contrast, "_", second_contrast,sep = "")
contrast_names[length(contrast_names)+1] = name
similarities_upregulated[[length(similarities_upregulated)+1]] = mgoSim(GO1ID, GO2ID, semData = d, measure = "Wang", combine = "BMA")

#DOWN-REGULATED
filename = paste("./GO_enrichment_microbiome_output/contrast_", first_contrast, "_", second_contrast, "_downregulated", ".csv", sep = "")
GO1 = read.csv(filename, header = T)
GO1ID = as.character(GO1[,1])

filename = paste("./GO_enrichment_output/contrast_", first_contrast, "_", second_contrast, "_downregulated", ".csv", sep = "")
GO2 = read.csv(filename, header = T)
GO2ID = as.character(GO2[,1])

similarities_downregulated[[length(similarities_downregulated)+1]] = mgoSim(GO1ID, GO2ID, semData = d, measure = "Wang", combine = "BMA")
}

names(similarities_downregulated) = as.vector(unlist(contrast_names))
names(similarities_upregulated) = as.vector(unlist(contrast_names))
GOSemSim_table = do.call(rbind, Map(data.frame, A=similarities_upregulated, B=similarities_downregulated))
write.csv(GOSemSim_table, "GOSemSim_table.csv")
13 changes: 13 additions & 0 deletions GOSemSim_table_miteVSmicrobiome.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
,Up_regulated,Down_regulated
young_males,0.763,0.917
young_phoretic,0.803,0.887
phoretic_phoreticCaged,0.798,0.866
phoretic_arresting,0.759,0.901
arresting_prelaying,0.793,0.892
prelaying_laying,0.799,0.899
laying_postlaying,0.782,0.911
postlaying_emerging,0.817,0.864
postlaying_nonlaying,0.811,0.884
laying_nonlaying,0.8,0.899
emerging_phoretic,0.785,0.891
emerging_young,0.816,0.881

0 comments on commit 0874a7d

Please sign in to comment.