-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCheckFormatsData.R
197 lines (172 loc) · 7.44 KB
/
CheckFormatsData.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
library(biocViews)
library(igraph)
library(XML)
library(stringr)
library(jsonlite)
library(ontologyIndex)
# get_OWL got depreciated, therefore load function from version 2.2
# library(ontoCAT)
setwd("/home/veit/devel/Bioinformatics/ELIXIR_EDAM/biotoolsExtract/")
# source("ontologyIndex_get_OWL.R")
# ############### get recent EDAM ontology for mapping of terms
# system("rm EDAM.owl")
# system("wget http://edamontology.org/EDAM.owl")
# EDAM <- get_OWL("EDAM.owl")
#
# ## Remove obsolete terms
# FullEDAM <- EDAM
# EDAM$id <- EDAM$id[!EDAM$obsolete]
# EDAM$name <- EDAM$name[!EDAM$obsolete]
# EDAM$parents <- EDAM$parents[!EDAM$obsolete]
# EDAM$children <- EDAM$children[!EDAM$obsolete]
# EDAM$ancestors <- EDAM$ancestors[!EDAM$obsolete]
# EDAM$obsolete <- EDAM$obsolete[!EDAM$obsolete]
#
############### ELIXIR REGISTRY -> MSUTILS.ORG
FullReg <- list()
for (i in 1:1300) {
# request <- paste("wget 'https://bio.tools/api/tool?page=",i, "&format=xml' -O FullElixir.xml", sep="")
# url <- system(request)
request <- paste("wget 'https://bio.tools/api/tool?page=",i, "&format=json' -O FullElixir.json", sep="")
url <- system(request)
FullReg[[i]] <- fromJSON("FullElixir.json")$list
# FullRegistry <- xmlTreeParse("FullElixir.xml")
# FullReg[[i]] <- xmlToList(FullRegistry)$list
}
save(FullReg,file="FullRegJSON.RData")
load("FullRegJSON.RData")
AllTools <- NULL
for (i in 1:length(FullReg)) {
# AllTools <- c(AllTools, FullReg[[i]])
AllTools <- rbind(AllTools, FullReg[[i]][,c("collectionID","accessibility","topic","owner",
"download","validated","homepage_status","maturity",
"canonicalID","availability","version","homepage",
"function","lastUpdate","description")])
}
## Functions!
fdmaps <- NULL
for (i in 1:nrow(AllTools)) {
for (j in 1:length(AllTools$'function'[[i]]$output)) {
# print(paste("Tool",i))
entry <- AllTools$'function'[[i]]$output[j][[1]]
for (k in 1:(length(entry$data)/2)) {
entryf <- entry$format[[k]]$uri
if(length(entryf)>0) {
for (l in 1:length(entryf))
print(c(entry$data[k,]$uri,entryf[l]))
fdmaps <- rbind(fdmaps,c(entry$data[k,]$uri,entryf[l]))
}
}
}
for (j in 1:length(AllTools$'function'[[i]]$input)) {
# print(paste("Tool",i))
entry <- AllTools$'function'[[i]]$input[j][[1]]
for (k in 1:(length(entry$data)/2)) {
entryf <- entry$format[[k]]$uri
if(length(entryf)>0) {
for (l in 1:length(entryf))
print(c(entry$data[k,]$uri,entryf[l]))
fdmaps <- rbind(fdmaps,c(entry$data[k,]$uri,entryf[l]))
}
}
}
}
fdmaps <- unique(fdmaps)
# output <- lapply(AllTools$'function',function(x) lapply(x$output,function(y)
# c(grep("format_",unlist(y),value=T),grep("data_",unlist(y),value=T))))
# input <- lapply(AllTools$'function',function(x) lapply(x$input,function(y)
# c(grep("format_",unlist(y),value=T),grep("data_",unlist(y),value=T))))
# for (i in 1:length(input)) {
# for (j in input[[i]]) {
# tformats <- grep("format_",j,value=T)
# tdata <- grep("data_",j,value=T)
# # restricting to case of only one data to avoid wrong matches
# if (length(tformats)>0 & length(tdata)==1)
# for (f in tformats)
# fdmaps <- rbind(fdmaps, c(f,tdata))
# }
# }
# for (i in 1:length(output)) {
# for (j in output[[i]]) {
# tformats <- grep("format_",j,value=T)
# tdata <- grep("data_",j,value=T)
# # restricting to case of only one data to avoid wrong matches
# if (length(tformats)>0 & length(tdata)==1)
# for (f in tformats)
# fdmaps <- rbind(fdmaps, c(f,tdata))
# }
# }
# fdmaps <- unique(fdmaps)
length(unique(fdmaps[,1]))
length(unique(fdmaps[,2]))
## extracting relationship from EDAM
EDAM <- read.csv("http://edamontology.org/EDAM.csv")
names(EDAM)
FullEDAM <- EDAM
EDAM <- EDAM[!EDAM$Obsolete,]
EDAMformats <- EDAM[grep("format_",EDAM$Class.ID),]
EDAMformats$Parents
# generic file formats to be removed
fdmaps3 <- NULL
EDAMformats$Parents <- sub("http://edamontology.org/format_2333","",EDAMformats$Parents)
EDAMformats$Parents <- sub("http://edamontology.org/format_2331","",EDAMformats$Parents)
EDAMformats$Parents <- sub("http://edamontology.org/format_3464","",EDAMformats$Parents)
EDAMformats$Parents <- sub("http://edamontology.org/format_2376","",EDAMformats$Parents)
EDAMformats$Parents <- sub("http://edamontology.org/format_2330","",EDAMformats$Parents)
EDAMformats$Parents <- sub("http://edamontology.org/format_2332","",EDAMformats$Parents)
EDAMformats$Parents <- sub("http://edamontology.org/format_3750","",EDAMformats$Parents)
fparents <- sapply(EDAMformats$Parents, function(x) str_extract_all(x,"format_[0-9]*"))
for (i in 1:nrow(EDAMformats)) {
ttt <- unlist(fparents[i])
for (j in 1:length(ttt)) {
fdmaps3 <- rbind(fdmaps3, c(as.character(EDAMformats$Class.ID[i]),
paste("http://edamontology.org/",ttt[j],sep="")))
}
}
## get is_format_of
fdmaps2 <- NULL
system('grep \'<owl:someValuesFrom rdf:resource="http://edamontology.org/data_\\|<owl:onProperty rdf:resource="http://edamontology.org/is_format_of"/>\\|<!-- http://edamontology.org/format_\' /tmp/EDAM_1.21.owl > t')
t_is_format_of <- readLines("t")
for (i in 1:(length(t_is_format_of)-2)) {
if (grepl('<!-- http://edamontology.org/format_',t_is_format_of[i])) {
if (grepl('<owl:onProperty rdf:resource=', t_is_format_of[i+1])) {
if (grepl('<owl:someValuesFrom rdf:resource=',t_is_format_of[i+2])) {
j <- 1
while(grepl('<owl:someValuesFrom rdf:resource=',t_is_format_of[i+j+1]) &
grepl('<owl:onProperty rdf:resource=', t_is_format_of[i+j])) {
fdmaps2 <- rbind(fdmaps2, c(
paste("http://edamontology.org/",str_extract(t_is_format_of[i], "format_[0-9]*"),sep=""),
paste("http://edamontology.org/",
str_extract(t_is_format_of[i+j+1], "data_[0-9]*"),sep="")))
j <- j+2
}
}
}
}
}
rownames(EDAM) <- EDAM$Class.ID
EDAM[fdmaps[,2],]$Preferred.Label
## put everything into table and think about how to validate
fdmaps <- cbind(fdmaps[,2], as.character(EDAM[fdmaps[,2], "Preferred.Label"]),
fdmaps[,1], as.character(EDAM[fdmaps[,1], "Preferred.Label"]))
fdmaps2 <- cbind(fdmaps2[,1], as.character(EDAM[fdmaps2[,1], "Preferred.Label"]),
fdmaps2[,2], as.character(EDAM[fdmaps2[,2], "Preferred.Label"]))
fdmaps3 <- cbind(fdmaps3[,1], as.character(EDAM[fdmaps3[,1], "Preferred.Label"]),
fdmaps3[,2], as.character(EDAM[fdmaps3[,2], "Preferred.Label"]))
fullFormats <- NULL
for (f in EDAMformats$Class.ID) {
matches <- fdmaps[,1] == f
entries <- rep(NA,6)
if (sum(matches)> 0)
entries[1:2] <- c(paste(fdmaps[matches,3],collapse="|"), paste(fdmaps[matches,4],collapse="|"))
matches <- fdmaps2[,1] == f
if (sum(matches)> 0)
entries[3:4] <- c(paste(fdmaps2[matches,3],collapse="|"), paste(fdmaps2[matches,4],collapse="|"))
matches <- fdmaps3[,1] == f
if (sum(matches)> 0)
entries[5:6] <- c(paste(fdmaps3[matches,3],collapse="|"), paste(fdmaps3[matches,4],collapse="|"))
fullFormats <- rbind(fullFormats, as.vector(c(f, as.character(EDAM[f,"Preferred.Label"]), entries )))
}
colnames(fullFormats) <- c("Format", "Format label", "from bio.tools","from bio.tools label",
"is_format_of", "is_format_of label", "parent", "parent label")
write.csv(fullFormats, "FormatDataMappings.csv")