12
12
# ' @param description (character) The description of the term
13
13
# ' @param iri (character) The Internationalized Resource Identifier for the term
14
14
# ' @param rols (logical) TRUE or FALSE to query the Ontology Lookup Service for
15
- # ' missing label, description or iri if not provided as input.
15
+ # ' missing label, description or iri if not provided as input.
16
16
# ' Default rols = TRUE
17
17
# ' @include generics.R
18
18
# ' @examples
@@ -28,28 +28,28 @@ ontology_term = function(
28
28
iri = character (),
29
29
rols = TRUE
30
30
) {
31
-
31
+
32
32
# ensure we have a colon separator
33
33
id = gsub(' [ :_-]' ,id ,replacement = ' :' ,perl = TRUE )
34
-
34
+
35
35
if (length(ontology )== 0 ){
36
36
# split the id and use that as basis for ontology
37
37
ontology = regmatches(id ,regexpr(' ^[^: _-]+[^: _-]' ,id ))
38
38
ontology = tolower(ontology )
39
39
}
40
-
40
+
41
41
if (length(label )== 0 | length(description )== 0 | length(iri )== 0 | length(ontology )== 0 ) {
42
-
42
+
43
43
# do rols query
44
44
db = rols :: Ontology(ontology )
45
- tm = rols :: term (db ,id )
46
-
45
+ tm = rols :: Term (db ,id )
46
+
47
47
label = rols :: termLabel(tm )
48
48
description = rols :: termDesc(tm )
49
49
iri = tm @ iri
50
-
50
+
51
51
}
52
-
52
+
53
53
# new object
54
54
out = .ontology_term(
55
55
id = id ,
@@ -72,24 +72,24 @@ ontology_term = function(
72
72
)
73
73
74
74
.ontology_slot = function (x ,name ) {
75
-
75
+
76
76
if (! (name %in% slotNames(x ))) {
77
77
stop(' "' ,name ,' " is not a valid slot name for ' ,
78
- class(x )[1 ],' objects.' )
78
+ class(x )[1 ],' objects.' )
79
79
}
80
-
80
+
81
81
return (slot(x ,name ))
82
-
82
+
83
83
}
84
84
85
85
# ' Get/set ontology term slots
86
- # '
87
- # ' Dollar syntax can be used to as a shortcut for getting
86
+ # '
87
+ # ' Dollar syntax can be used to as a shortcut for getting
88
88
# ' values for ontology_term objects.
89
89
# ' @return Slot value
90
90
# ' @param x An ontology_term object
91
91
# ' @param name The name of the slot to access
92
- # ' @examples
92
+ # ' @examples
93
93
# ' \dontrun{
94
94
# ' OT = ontology_term(ontology='stato',id='STATO:0000555')
95
95
# ' }
@@ -104,7 +104,7 @@ setMethod(f = "$",
104
104
setMethod (f = 'show ',
105
105
signature = c(' ontology_term' ),
106
106
definition = function (object ) {
107
-
107
+
108
108
# padding for long descriptions and names
109
109
pad = ' \n '
110
110
desc = paste0(strwrap(object $ description ,width = 95 ,exdent = 2 ),collapse = pad )
@@ -114,16 +114,16 @@ setMethod(f = 'show',
114
114
cat(' label: ' ,label ,' \n ' ,sep = ' ' )
115
115
cat(' description: ' ,desc ,' \n ' ,sep = ' ' )
116
116
cat(' iri: ' ,object $ iri ,' \n ' ,sep = ' ' )
117
-
117
+
118
118
}
119
119
)
120
120
121
121
122
122
setAs(" ontology_term" , " data.frame" ,
123
123
function (from )
124
124
data.frame (
125
- id = from @ id ,
126
- label = from @ label ,
125
+ id = from @ id ,
126
+ label = from @ label ,
127
127
description = from @ description ,
128
128
ontology = from @ ontology ,
129
129
iri = from @ iri
@@ -151,32 +151,32 @@ setAs("ontology_term", "data.frame",
151
151
# ' }
152
152
# ' @rdname ontology
153
153
ontology_list = function (terms = list ()) {
154
-
154
+
155
155
if (is.null(terms ) | length(terms )== 0 ) {
156
156
# empty list
157
157
terms = list ()
158
158
}
159
-
159
+
160
160
if (is(terms ,' character' )){
161
161
# try and convert to terms
162
162
terms = lapply(terms ,function (x ){
163
163
ontology_term(id = x )
164
164
})
165
165
}
166
-
166
+
167
167
# if ontology_item is provided convert to a list
168
168
if (is(terms ,' ontology_term' )){
169
169
terms = list (terms )
170
170
}
171
-
171
+
172
172
# check all terms are ontology_item
173
173
if (length(terms )> 0 ) {
174
174
ok = lapply(terms ,is ,class = ' ontology_term' )
175
175
if (! (all(unlist(ok )))){
176
176
stop(' all ontologies must be in "ontology_term" format' )
177
177
}
178
178
}
179
-
179
+
180
180
# new object
181
181
out = .ontology_list(
182
182
terms = terms )
@@ -191,13 +191,13 @@ ontology_list = function(terms=list()) {
191
191
)
192
192
193
193
# ' Get/set ontology_list slots
194
- # '
195
- # ' Dollar syntax can be used to as a shortcut for getting
194
+ # '
195
+ # ' Dollar syntax can be used to as a shortcut for getting
196
196
# ' values for ontology_list objects.
197
197
# ' @return Slot value
198
198
# ' @param x An ontology_term object
199
199
# ' @param name The name of the slot to access
200
- # ' @examples
200
+ # ' @examples
201
201
# ' \dontrun{
202
202
# ' OL = ontology_list('STATO:0000555')
203
203
# ' OL$terms
@@ -271,7 +271,7 @@ setAs("ontology_list", "data.frame",
271
271
)
272
272
273
273
# ' catenate ontology_lists
274
- # '
274
+ # '
275
275
# ' ontology_lists can be catenated with other ontology lists or with ontology_items.
276
276
# ' @param x an ontology_list()
277
277
# ' @param ... any number of ontology_list() or ontology_item() objects to catenate
@@ -282,15 +282,15 @@ setMethod(f = "c",
282
282
y = list (... )
283
283
check = all(unlist(lapply(y ,is ,class2 = ' ontology_list' )))
284
284
if (! check ) {stop(' can only combine ontology_list objects' )}
285
-
285
+
286
286
x = x @ terms
287
287
y = lapply(y ,function (x ){
288
288
return (x @ terms )
289
289
})
290
-
290
+
291
291
terms = c(x ,unlist(y ))
292
292
out = ontology_list(terms )
293
-
293
+
294
294
return (out )
295
295
}
296
- )
296
+ )
0 commit comments