-
Notifications
You must be signed in to change notification settings - Fork 1
/
Multipath.R
44 lines (43 loc) · 1.67 KB
/
Multipath.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#' Generate Multipath Graph from General Data
#'
#' @param name The name of the graph to be generated
#' @param up The Uniprot.ws() object
#' @param proteinList The list of proteins of which the interactions should be retrieved
#' @param data The dataframe containing the parsed information of DrugBank. This argument can be obtained using the function loadDBXML(DrugBankFile)
#' @param drugList The list of DrugBank Ids of the drugs. This argument can be either a string (one drug) or a list of strings (multiple drugs)
#'
#' @return A mully graph with the added data
#' @export
#' @import mully
#' @importFrom igraph V
multipath<-function(name="Multipath",up=NA,proteinList=NA,data=NA,drugList=NA){
g=mully(name,direct=T)
proteinLayer=F
drugLayer=F
if(!is.na(drugList) & !is.na(data)){
message("Multipath: Drug Layer will be added")
g=addDBLayer(g,data,drugList)
drugLayer=T
}
if(!is.na(proteinList) & !is.na(up)){
message("Multipath: Protein List will be added")
g=addUPKBLayer(g,up,proteinList)
proteinLayer=T
}
#Add Drug-Protein Relations
if(drugLayer & proteinLayer){
updbrelations=getUPKBDBRelations(up,data,proteinList,drugList)
message("Multipath: Adding DrugBank UniProt Edges")
for (i in 1:dim(updbrelations)[1]) {
progress(i,progress.bar = T)
startName=V(g)[which(V(g)$name == updbrelations$'dbid'[i])]$name
endName=V(g)[which(V(g)$name == updbrelations$'upid'[i])]$name
attrList=updbrelations[i,]
attr=as.list(attrList)
names(attr)=names(updbrelations)
g=mully::addEdge(g,startName,endName,attributes = attr[-2])
}
message("Multipath: DONE - Adding DrugBank UniProt Edges")
}
return(g)
}