1212# ' @param description (character) The description of the term
1313# ' @param iri (character) The Internationalized Resource Identifier for the term
1414# ' @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.
1616# ' Default rols = TRUE
1717# ' @include generics.R
1818# ' @examples
@@ -28,28 +28,28 @@ ontology_term = function(
2828 iri = character (),
2929 rols = TRUE
3030) {
31-
31+
3232 # ensure we have a colon separator
3333 id = gsub(' [ :_-]' ,id ,replacement = ' :' ,perl = TRUE )
34-
34+
3535 if (length(ontology )== 0 ){
3636 # split the id and use that as basis for ontology
3737 ontology = regmatches(id ,regexpr(' ^[^: _-]+[^: _-]' ,id ))
3838 ontology = tolower(ontology )
3939 }
40-
40+
4141 if (length(label )== 0 | length(description )== 0 | length(iri )== 0 | length(ontology )== 0 ) {
42-
42+
4343 # do rols query
4444 db = rols :: Ontology(ontology )
45- tm = rols :: term (db ,id )
46-
45+ tm = rols :: Term (db ,id )
46+
4747 label = rols :: termLabel(tm )
4848 description = rols :: termDesc(tm )
4949 iri = tm @ iri
50-
50+
5151 }
52-
52+
5353 # new object
5454 out = .ontology_term(
5555 id = id ,
@@ -72,24 +72,24 @@ ontology_term = function(
7272)
7373
7474.ontology_slot = function (x ,name ) {
75-
75+
7676 if (! (name %in% slotNames(x ))) {
7777 stop(' "' ,name ,' " is not a valid slot name for ' ,
78- class(x )[1 ],' objects.' )
78+ class(x )[1 ],' objects.' )
7979 }
80-
80+
8181 return (slot(x ,name ))
82-
82+
8383}
8484
8585# ' 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
8888# ' values for ontology_term objects.
8989# ' @return Slot value
9090# ' @param x An ontology_term object
9191# ' @param name The name of the slot to access
92- # ' @examples
92+ # ' @examples
9393# ' \dontrun{
9494# ' OT = ontology_term(ontology='stato',id='STATO:0000555')
9595# ' }
@@ -104,7 +104,7 @@ setMethod(f = "$",
104104setMethod (f = 'show ',
105105 signature = c(' ontology_term' ),
106106 definition = function (object ) {
107-
107+
108108 # padding for long descriptions and names
109109 pad = ' \n '
110110 desc = paste0(strwrap(object $ description ,width = 95 ,exdent = 2 ),collapse = pad )
@@ -114,16 +114,16 @@ setMethod(f = 'show',
114114 cat(' label: ' ,label ,' \n ' ,sep = ' ' )
115115 cat(' description: ' ,desc ,' \n ' ,sep = ' ' )
116116 cat(' iri: ' ,object $ iri ,' \n ' ,sep = ' ' )
117-
117+
118118 }
119119)
120120
121121
122122setAs(" ontology_term" , " data.frame" ,
123123 function (from )
124124 data.frame (
125- id = from @ id ,
126- label = from @ label ,
125+ id = from @ id ,
126+ label = from @ label ,
127127 description = from @ description ,
128128 ontology = from @ ontology ,
129129 iri = from @ iri
@@ -151,32 +151,32 @@ setAs("ontology_term", "data.frame",
151151# ' }
152152# ' @rdname ontology
153153ontology_list = function (terms = list ()) {
154-
154+
155155 if (is.null(terms ) | length(terms )== 0 ) {
156156 # empty list
157157 terms = list ()
158158 }
159-
159+
160160 if (is(terms ,' character' )){
161161 # try and convert to terms
162162 terms = lapply(terms ,function (x ){
163163 ontology_term(id = x )
164164 })
165165 }
166-
166+
167167 # if ontology_item is provided convert to a list
168168 if (is(terms ,' ontology_term' )){
169169 terms = list (terms )
170170 }
171-
171+
172172 # check all terms are ontology_item
173173 if (length(terms )> 0 ) {
174174 ok = lapply(terms ,is ,class = ' ontology_term' )
175175 if (! (all(unlist(ok )))){
176176 stop(' all ontologies must be in "ontology_term" format' )
177177 }
178178 }
179-
179+
180180 # new object
181181 out = .ontology_list(
182182 terms = terms )
@@ -191,13 +191,13 @@ ontology_list = function(terms=list()) {
191191)
192192
193193# ' 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
196196# ' values for ontology_list objects.
197197# ' @return Slot value
198198# ' @param x An ontology_term object
199199# ' @param name The name of the slot to access
200- # ' @examples
200+ # ' @examples
201201# ' \dontrun{
202202# ' OL = ontology_list('STATO:0000555')
203203# ' OL$terms
@@ -271,7 +271,7 @@ setAs("ontology_list", "data.frame",
271271)
272272
273273# ' catenate ontology_lists
274- # '
274+ # '
275275# ' ontology_lists can be catenated with other ontology lists or with ontology_items.
276276# ' @param x an ontology_list()
277277# ' @param ... any number of ontology_list() or ontology_item() objects to catenate
@@ -282,15 +282,15 @@ setMethod(f = "c",
282282 y = list (... )
283283 check = all(unlist(lapply(y ,is ,class2 = ' ontology_list' )))
284284 if (! check ) {stop(' can only combine ontology_list objects' )}
285-
285+
286286 x = x @ terms
287287 y = lapply(y ,function (x ){
288288 return (x @ terms )
289289 })
290-
290+
291291 terms = c(x ,unlist(y ))
292292 out = ontology_list(terms )
293-
293+
294294 return (out )
295295 }
296- )
296+ )
0 commit comments