Skip to content

Commit 396e9f8

Browse files
committed
fix broken tests due to changes in rols
- ols apir was updated to use ols4, which led to breaking changes in the rols package
1 parent 3bf2b24 commit 396e9f8

File tree

3 files changed

+71
-67
lines changed

3 files changed

+71
-67
lines changed

R/ontology_term_class.R

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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 = "$",
104104
setMethod(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

122122
setAs("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
153153
ontology_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+
)

tests/testthat/test-base.R

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
test_that('struct objects can be created and modified',{
33
# a test object
44
test_object=struct_class(
5-
name = 'test_name',
5+
name = 'test_name',
66
description=c(
77
'A'='test_desc_A',
88
'B'='test_desc_B'),
@@ -15,14 +15,14 @@ test_that('struct objects can be created and modified',{
1515
pages = '122-128',
1616
author = as.person("Nestor F. Perez and Joan Ferre and Ricard Boque"),
1717
title = paste0('Calculation of the reliability of ',
18-
'classification in discriminant partial least-squares ',
19-
'binary classification'),
18+
'classification in discriminant partial least-squares ',
19+
'binary classification'),
2020
journal = "Chemometrics and Intelligent Laboratory Systems"
2121
),
2222
ontology='STATO:0000572'
23-
24-
)
25-
23+
24+
)
25+
2626
# name
2727
expect_equal({test_object$name},'test_name') # get
2828
expect_equal({test_object$name='cabbage';test_object$name},'cabbage') # set
@@ -37,26 +37,30 @@ test_that('struct objects can be created and modified',{
3737
expect_equal({test_object$description='cabbage';test_object$description},'cabbage') #set
3838
# show
3939
expect_output(show(test_object),'A "struct_class" object')
40-
40+
4141
expect_error({
42-
test_object=struct_class(name = 'test_name', description='test_desc','type' = 'test_type',
43-
citations= list(bibentry(
44-
bibtype ='Article',
45-
year = 2009,
46-
volume = 95,
47-
number = 2,
48-
pages = '122-128',
49-
author = as.person("Nestor F. Perez and Joan Ferre and Ricard Boque"),
50-
title = paste0('Calculation of the reliability of ',
51-
'classification in discriminant partial least-squares ',
52-
'binary classification'),
53-
journal = "Chemometrics and Intelligent Laboratory Systems"
54-
),
42+
test_object=struct_class(
43+
name = 'test_name',
44+
description='test_desc',
45+
type = 'test_type',
46+
citations= list(
47+
bibentry(
48+
bibtype ='Article',
49+
year = 2009,
50+
volume = 95,
51+
number = 2,
52+
pages = '122-128',
53+
author = as.person("Nestor F. Perez and Joan Ferre and Ricard Boque"),
54+
title = paste0('Calculation of the reliability of ',
55+
'classification in discriminant partial least-squares ',
56+
'binary classification'),
57+
journal = "Chemometrics and Intelligent Laboratory Systems"
58+
),
5559
'cake'
56-
60+
5761
))
5862
})
59-
63+
6064
cit=citations(test_object)
6165
expect_true(length(cit)==2)
6266
lib=libraries(test_object)
@@ -69,12 +73,12 @@ test_that('struct objects can be created and modified',{
6973
description = 'test_ontology',
7074
iri = 'test_ontology',
7175
rols=FALSE
72-
)
7376
)
7477
)
78+
)
7579
expect_true(length(ont)==1)
76-
77-
80+
81+
7882
})
7983

8084
# test metric object

tests/testthat/test-ontology.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_that('ontology works as expected',{
88
O=ontology_list('STATO:0000555')
99
expect_true(is(O,'ontology_list'))
1010
expect_true(O[1]$id=='STATO:0000555')
11-
11+
1212
# term to list
1313
O=ontology_list(ontology_term('STATO:0000555',rols=FALSE))
1414
expect_true(is(O,'ontology_list'))
@@ -22,36 +22,36 @@ test_that('ontology works as expected',{
2222
)
2323
expect_true(O[1]$id=='STATO:0000555')
2424
expect_true(O[2]$id=='STATO:0000555')
25-
25+
2626
# assignment
2727
O[2]=ontology_term('STATO:0000555',rols=FALSE)
2828
expect_true(O[2]$id=='STATO:0000555')
29-
29+
3030
# length
3131
expect_equal(length(O),2)
32-
32+
3333
# ontology list to data.frame
3434
df=as(O,'data.frame')
3535
expect_equal(nrow(df),2)
3636
expect_equal(ncol(df),5)
3737
expect_equal(df[1,1],'STATO:0000555')
38-
38+
3939
# catenate several ontology_lists
4040
O=c(O,O)
4141
expect_equal(length(O),4)
4242
expect_true(is(O,'ontology_list'))
43-
43+
4444
# ontology method
4545
M=example_model(ontology='STATO:0000555')
4646
expect_equal(M$ontology,'STATO:0000555')
47-
47+
4848
expect_error(O$cake)
49-
49+
5050
expect_output(show(O[1]),"STATO:0000555",regexp = 'STATO:0000555')
5151

5252
O=ontology_list()
5353
expect_equal(length(O),0)
54-
54+
5555
expect_error(c(O,struct_class()))
5656
expect_error({O[1] = struct_class()})
5757
expect_error(ontology_list(terms=list(O,struct_class())))

0 commit comments

Comments
 (0)