Skip to content

Commit

Permalink
fix use of "term"
Browse files Browse the repository at this point in the history
- due to breaking changes in rols required to for update to ols4
- "term" replaced with "Term"
  • Loading branch information
grlloyd committed Feb 15, 2024
1 parent c16a1cb commit 03769d2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
18 changes: 13 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: struct
Type: Package
Title: Statistics in R Using Class-based Templates
Version: 1.14.0
Version: 1.14.1
Authors@R: c(
person(
c("Gavin","Rhys"),
Expand Down Expand Up @@ -49,7 +49,7 @@ Collate:
'resampler_class.R'
'struct.R'
'struct_templates.R'
RoxygenNote: 7.1.2
RoxygenNote: 7.3.1
Depends: R (>= 4.0)
Suggests:
testthat,
Expand All @@ -61,7 +61,15 @@ Suggests:
ggplot2,
magick
VignetteBuilder: knitr
Imports: methods,ontologyIndex,
datasets, graphics, stats, utils, knitr,
SummarizedExperiment, S4Vectors, rols
Imports:
methods,
ontologyIndex,
datasets,
graphics,
stats,
utils,
knitr,
SummarizedExperiment,
S4Vectors,
rols (>= 2.30.1)
biocViews: WorkflowStep
66 changes: 33 additions & 33 deletions R/ontology_term_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @param description (character) The description of the term
#' @param iri (character) The Internationalized Resource Identifier for the term
#' @param rols (logical) TRUE or FALSE to query the Ontology Lookup Service for
#' missing label, description or iri if not provided as input.
#' missing label, description or iri if not provided as input.
#' Default rols = TRUE
#' @include generics.R
#' @examples
Expand All @@ -28,28 +28,28 @@ ontology_term = function(
iri=character(),
rols=TRUE
) {

# ensure we have a colon separator
id=gsub('[ :_-]',id,replacement = ':',perl=TRUE)

if (length(ontology)==0){
# split the id and use that as basis for ontology
ontology=regmatches(id,regexpr('^[^: _-]+[^: _-]',id))
ontology=tolower(ontology)
}

if (length(label)==0 | length(description)==0 | length(iri)==0 | length(ontology)==0) {

# do rols query
db=rols::Ontology(ontology)
tm=rols::term(db,id)
tm=rols::Term(db,id)

label=rols::termLabel(tm)
description=rols::termDesc(tm)
iri=tm@iri

}

# new object
out = .ontology_term(
id=id,
Expand All @@ -72,24 +72,24 @@ ontology_term = function(
)

.ontology_slot = function(x,name) {

if (!(name %in% slotNames(x))) {
stop('"',name,'" is not a valid slot name for ',
class(x)[1],' objects.')
class(x)[1],' objects.')
}

return(slot(x,name))

}

#' Get/set ontology term slots
#'
#' Dollar syntax can be used to as a shortcut for getting
#'
#' Dollar syntax can be used to as a shortcut for getting
#' values for ontology_term objects.
#' @return Slot value
#' @param x An ontology_term object
#' @param name The name of the slot to access
#' @examples
#' @examples
#' \dontrun{
#' OT = ontology_term(ontology='stato',id='STATO:0000555')
#' }
Expand All @@ -104,7 +104,7 @@ setMethod(f = "$",
setMethod(f = 'show',
signature = c('ontology_term'),
definition = function(object) {

# padding for long descriptions and names
pad = '\n '
desc=paste0(strwrap(object$description,width=95,exdent = 2),collapse=pad)
Expand All @@ -114,16 +114,16 @@ setMethod(f = 'show',
cat('label: ',label,'\n',sep='')
cat('description: ',desc,'\n',sep='')
cat('iri: ',object$iri,'\n',sep='')

}
)


setAs("ontology_term", "data.frame",
function(from)
data.frame(
id=from@id,
label=from@label,
id=from@id,
label=from@label,
description=from@description,
ontology=from@ontology,
iri=from@iri
Expand Down Expand Up @@ -151,32 +151,32 @@ setAs("ontology_term", "data.frame",
#' }
#' @rdname ontology
ontology_list = function(terms=list()) {

if (is.null(terms) | length(terms)==0) {
# empty list
terms=list()
}

if (is(terms,'character')){
# try and convert to terms
terms=lapply(terms,function(x){
ontology_term(id=x)
})
}

# if ontology_item is provided convert to a list
if (is(terms,'ontology_term')){
terms=list(terms)
}

# check all terms are ontology_item
if (length(terms)>0) {
ok=lapply(terms,is,class='ontology_term')
if (!(all(unlist(ok)))){
stop('all ontologies must be in "ontology_term" format')
}
}

# new object
out = .ontology_list(
terms = terms)
Expand All @@ -191,13 +191,13 @@ ontology_list = function(terms=list()) {
)

#' Get/set ontology_list slots
#'
#' Dollar syntax can be used to as a shortcut for getting
#'
#' Dollar syntax can be used to as a shortcut for getting
#' values for ontology_list objects.
#' @return Slot value
#' @param x An ontology_term object
#' @param name The name of the slot to access
#' @examples
#' @examples
#' \dontrun{
#' OL = ontology_list('STATO:0000555')
#' OL$terms
Expand Down Expand Up @@ -271,7 +271,7 @@ setAs("ontology_list", "data.frame",
)

#' catenate ontology_lists
#'
#'
#' ontology_lists can be catenated with other ontology lists or with ontology_items.
#' @param x an ontology_list()
#' @param ... any number of ontology_list() or ontology_item() objects to catenate
Expand All @@ -282,15 +282,15 @@ setMethod(f = "c",
y=list(...)
check=all(unlist(lapply(y,is,class2='ontology_list')))
if (!check) {stop('can only combine ontology_list objects')}

x=x@terms
y=lapply(y,function(x){
return(x@terms)
})

terms=c(x,unlist(y))
out=ontology_list(terms)

return(out)
}
)
)

0 comments on commit 03769d2

Please sign in to comment.