Created
August 28, 2019 20:38
-
-
Save kstawiski/1eee58bb2b7615ead3a5cfa2a2a06d82 to your computer and use it in GitHub Desktop.
miRNA-gene interaction network using miRTarBase and networkD3 in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nasza = read.csv("nasza.csv", header=T, stringsAsFactors = F) | |
library("openxlsx") | |
library(dplyr) | |
miRtarbase = openxlsx::read.xlsx("hsa_MTI.xlsx") | |
refdb = filter(miRtarbase, Support.Type == "Functional MTI" | Support.Type == "Non-Functional MTI") | |
miR = unique(nasza$hsa.miRNA) | |
miR = miR[-which(miR=="")] | |
#korekty | |
miR[36] = "hsa-miR-106a" | |
miRy = c(miR,paste0(miR,rep("-5p",length(miR))),paste0(miR,rep("-3p",length(miR)))) | |
target = list() | |
for(i in 1:length(miRy)) { | |
target[[i]] = unique(refdb$Target.Gene[which(refdb$miRNA == miRy[i])]) | |
} | |
pubtab1 = data.frame(miR = miR, targets = NA) | |
target2 = list() | |
for(i in 1:length(miR)) { | |
target2[[i]] = unique(c(target[[i]],target[[i+length(miR)]],target[[i+(length(miR)*2)]])) | |
pubtab1$targets[i] = paste0(target2[[i]], collapse = ", ") | |
} | |
ftemp = table(unlist(target)) | |
ftemp2 = ftemp[order(ftemp, decreasing = T)] | |
write.csv(ftemp2,"ftemp2.csv") | |
# Wszystkie, ale nie weak | |
write.csv(pubtab1,"wszystkie_nieweak.csv") | |
tab1 = pubtab1 | |
#### | |
refdb = miRtarbase | |
target = list() | |
for(i in 1:length(miRy)) { | |
target[[i]] = unique(refdb$Target.Gene[which(refdb$miRNA == miRy[i])]) | |
} | |
pubtab1 = data.frame(miR = miR, targets = NA) | |
target2 = list() | |
for(i in 1:length(miR)) { | |
target2[[i]] = unique(c(target[[i]],target[[i+length(miR)]],target[[i+(length(miR)*2)]])) | |
pubtab1$targets[i] = paste0(target2[[i]], collapse = ", ") | |
} | |
# Wszystkie, ale nie weak | |
write.csv(pubtab1,"wszystkie_plusweak.csv") | |
tab2 = pubtab1 | |
ftemp = table(unlist(target)) | |
ftemp2 = ftemp[order(ftemp, decreasing = T)] | |
temp = data.frame(lapply(ftemp2, type.convert), stringsAsFactors=FALSE) | |
### Venn | |
library(VennDiagram) | |
calculate.overlap(target2) | |
#BiocManager::install("SpidermiR") | |
miRbase = read.csv("miRNA.csv", stringsAsFactors = F) | |
czy_istnieja = match(miRy, c(miRbase$Mature1_ID,miRbase$Mature2_ID,miRbase$ID)) | |
miRy_final = miRy[!is.na(czy_istnieja)] | |
cat(paste0(miRy_final,collapse = "\n")) | |
list<-SpidermiRdownload_miRNAvalidate(miRy_final) | |
org<-SpidermiRquery_species(species) | |
net_shar_prot<-SpidermiRquery_spec_networks(organismID = org[6,], | |
network = "PATH") | |
out_net<-SpidermiRdownload_net(net_shar_prot) | |
list<-SpidermiRdownload_miRNAvalidate(validated) | |
list_circ<-SpidermiRdownload_miRNAextra_cir(miRNAextra_cir) | |
mir_pharmaco<-SpidermiRdownload_pharmacomir(pharmacomir=pharmacomir) | |
geneSymb_net<-SpidermiRprepare_NET(organismID = org[6,], | |
data = out_net) | |
refdb = filter(miRtarbase, Support.Type == "Functional MTI" | Support.Type == "Non-Functional MTI") | |
target = list() | |
for(i in 1:length(miRy)) { | |
target[[i]] = unique(refdb$Target.Gene[which(refdb$miRNA == miRy_final[i])]) | |
} | |
ftemp = table(unlist(target)) | |
ftemp = ftemp[order(ftemp, decreasing = T)] | |
temp = as.data.frame(ftemp) | |
ftemp2 = ftemp[ftemp>5] | |
write.csv(temp,"forGOrilla.csv") | |
temp2 = data.frame(gene = NA, miR = NA) | |
for (i in 1:length(ftemp2)) { | |
temp = names(ftemp2)[i] | |
for (ii in 1:length(target)) { | |
if(!is.na(match(temp,target[[ii]]))) { temp2 = rbind(temp2, c(temp,miRy_final[ii]))} | |
} | |
} | |
temp2 = temp2[complete.cases(temp2),] | |
net = function (data) | |
{ | |
library(networkD3) | |
colnames(data) <- c("V1", "V2") | |
if (length(grep("hsa", data$V1)) != 0 | length(grep("hsa", | |
data$V2)) != 0) { | |
IDs2 <- sort.int(unique(c(data$V1, data$V2)), decreasing = FALSE) | |
IDs2 <- data.frame(ID = seq_along(IDs2) - 1, name = IDs2) | |
dataIDs2 <- merge(data, IDs2, by.x = "V1", by.y = "name") | |
dataIDs2$V1 <- dataIDs2$ID | |
dataIDs2$ID <- NULL | |
dataIDs2 <- merge(dataIDs2, IDs2, by.x = "V2", by.y = "name") | |
dataIDs2$V2 <- dataIDs2$ID | |
dataIDs2$ID <- NULL | |
dataIDs2 <- dataIDs2[, c("V1", "V2")] | |
data2 <- data[order(data$V1, data$V2, decreasing = FALSE), | |
] | |
dataIDs2 <- dataIDs2[order(dataIDs2$V1, dataIDs2$V2, | |
decreasing = FALSE), ] | |
att <- as.data.frame(sort(unique(unlist(data)), decreasing = FALSE)) | |
colnames(att)[1] <- "v1" | |
att$v2 <- "" | |
att$v2 <- replace(att$v2, att$v2 == "", "gene") | |
att$v2[(grep("[a-z]", att$v1))] <- "Pharmaco" | |
att$v2[grep("hsa", att$v1)] <- "miRNA" | |
att$v2[grep("orf", att$v1)] <- "gene" | |
att <- as.data.frame(att[order(att$v2, decreasing = FALSE), | |
]) | |
i <- sapply(att, is.factor) | |
att[i] <- lapply(att[i], as.character) | |
colnames(att)[1] <- "name" | |
colnames(att)[2] <- "Group" | |
attr2 <- merge(att, IDs2) | |
attr2 <- attr2[order(attr2$ID), ] | |
ColourScal <- "d3.scaleOrdinal()\n .domain([\"gene\", \"Pharmaco\",\"miRNA\"])\n .range([\"#000000\", \"#37bf30\" , \"#37bf30\"]);" | |
return(forceNetwork(Links = dataIDs2, Nodes = attr2, | |
Source = "V1", Target = "V2", NodeID = "name", Group = "Group", | |
height = 1500, width = 1500, opacity = 1, zoom = F, fontFamily = "Calibri", | |
legend = F, opacityNoHover = FALSE, colourScale = JS(ColourScal), bounded = F, charge = -2000, | |
#radiusCalculation = JS("Math.sqrt(d.nodesize)+6"), | |
#linkDistance = JS("function(d){return d.value * 10}"), | |
#linkWidth = JS("function(d) { return Math.sqrt(d.value); }"), | |
fontSize = 26)) | |
} | |
if (length(grep("hsa", data$V1)) == 0) { | |
.SpidermiRvisualize_gene(data) | |
} | |
} | |
net(data=temp2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment