Skip to content

Commit

Permalink
Release bioc 0.99.4 (#2)
Browse files Browse the repository at this point in the history
* Bioc feedback (#1)

* ignore yaml files

add *.yml to .gitignore so that they are not included in the repo

* ignore yaml files

add *.yml to .gitignore so that they are not included in the repo

* add bioconductor install instructions

* update package description to be at least three sentences

* remove LazyData: true

* ignore rproj

* update description and add see_also

see_also links to API documentation, package vignette and do_query

* add donttest to example

Avoid testing the do_query example in case metabolomicsworkbench is down which would cause it to fail and therefore prevent a bioconductor build.

* add donttest to example

avoid example during testing to prevent error if MB is down

* use seq_along and seq_len

replace as many cases of 1: as possible with seq_len and seq_along, as per bioconductor guidelines

* split lines >80 chars and...

also remove donttest and add message to show http status if its an error

* version bump
  • Loading branch information
grlloyd committed Aug 25, 2020
1 parent b1dc05c commit b1634be
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 112 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ vignettes/*.pdf
inst/doc
doc
Meta

# yaml
*.yml
*.Rproj
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: metabolomicsWorkbenchR
Type: Package
Title: Metabolomics Workbench in R
Version: 0.99.3
Version: 0.99.4
Authors@R: c(
person(
c("Gavin","Rhys"),
Expand All @@ -15,13 +15,13 @@ Authors@R: c(
email="[email protected]")
)
Description: This package provides functions for interfacing with the
Metabolomics Workbench RESTful API to access study, compound, protein and gene
information. Methods to obtain study data in common Bioconductor formats such
as SummarizedExperiment and MultiAssayExperiment are also included.
Metabolomics Workbench RESTful API. Study, compound, protein and gene
information can be searched for using the API. Methods to obtain study
data in common Bioconductor formats such as SummarizedExperiment and
MultiAssayExperiment are also included.
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
Collate:
'parse_fcns.R'
'generics.R'
Expand Down
123 changes: 84 additions & 39 deletions R/class_def.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ mw_base = function(private,locked){

#' Get slot value from mw_base objects
#'
#' Gets the value of a slot from mw_base objects, provided they are not listed as
#' 'private'.
#' Gets the value of a slot from mw_base objects, provided they are not listed
#' as 'private'.
#' @param x An object derived from mw_base.
#' @param name The name of the slot to access.
#' @return The assigned to the slot.
Expand All @@ -44,10 +44,13 @@ setMethod(f = "$",
return(slot(x,name))
} else {
if (!is_slot) {
stop(paste0('"',name,'" is not a valid slot for objects of class "', class(x)[1],'"'))
stop(paste0('"',name,
'" is not a valid slot for objects of class "',
class(x)[1],'"'))
}
if (is_private) {
stop(paste0('"',name,'" is a private slot for internal use only.'))
stop(paste0('"',name,
'" is a private slot for internal use only.'))
}
}
}
Expand Down Expand Up @@ -97,15 +100,17 @@ setMethod(f = 'is_valid',
signature = c('mw_context','character','character','character'),
definition = function(context,input_item,input_value,output_item) {

name_valid = context@name %in% c('study','compound','refmet','gene','protein','moverz','exactmass')
name_valid = context@name %in% c('study','compound','refmet','gene',
'protein','moverz','exactmass')
input_valid = all(input_item %in% context@input_items)
output_valid = all(output_item %in% context@output_items)
length_valid = (length(input_value)==length(input_item))
length_out_valid = !(length(input_item)>1)

err=list()
if (!name_valid) {
err=c(err,paste0('name = "',input_item,'" is not a valid context name.\n'))
err=c(err,paste0('name = "',input_item,
'" is not a valid context name.\n'))
}
if (!input_valid) {
err=c(err,paste0('An input_item is not valid for this context.\n'))
Expand All @@ -116,10 +121,12 @@ setMethod(f = 'is_valid',
}

if (!length_valid) {
err=c(err,"Length of input_value must be the same as length of input_item.\n")
err=c(err,paste0("Length of input_value must be the same as',
' length of input_item.\n"))
}
if (!length_out_valid) {
err=c(err,"Length of intput_item is limited to 1 for this context.\n")
err=c(err,paste0("Length of intput_item is limited to 1 for',
' this context.\n"))
}

if (length(err)>0) {
Expand All @@ -138,7 +145,8 @@ mw_moverz_context = function(input_items,ion_types,tol_range,mz_range,...) {
ion_types = ion_types,
tol_range = tol_range,
mz_range = mz_range,
locked = c('name','input_items','output_items','ion_types','tol_range','mz_range'),
locked = c('name','input_items','output_items','ion_types',
'tol_range','mz_range'),
...
)
return(out)
Expand All @@ -163,9 +171,11 @@ setMethod(f = 'is_valid',

input_valid = all(input_item %in% context@input_items)

range_valid2 = as.numeric(input_value[2]) >= context@mz_range[1] & as.numeric(input_value[2]) <= context@mz_range[2]
range_valid2 = as.numeric(input_value[2]) >= context@mz_range[1] &
as.numeric(input_value[2]) <= context@mz_range[2]
ion_valid = input_value[3] %in% context@ion_types
range_valid4 = as.numeric(input_value[4]) >= context@tol_range[1] & as.numeric(input_value[4]) <= context@tol_range[2]
range_valid4 = as.numeric(input_value[4]) >= context@tol_range[1] &
as.numeric(input_value[4]) <= context@tol_range[2]
database_valid=input_value[1] %in% c('LIPIDS','MB','REFMET')

err=list()
Expand All @@ -179,10 +189,12 @@ setMethod(f = 'is_valid',
err=c(err,"input_value[4] is out of range for this context.\n")
}
if (!ion_valid) {
err=c(err,paste0('"',input_value[3], '" is not a valid ion for this context.\n'))
err=c(err,paste0('"',input_value[3],
'" is not a valid ion for this context.\n'))
}
if (!database_valid) {
err=c(err,paste0('"',input_value[1], '" is not a valid database for this context.\n'))
err=c(err,paste0('"',input_value[1],
'" is not a valid database for this context.\n'))
}
if (length(err)>0) {
stop(err)
Expand All @@ -198,7 +210,8 @@ mw_exactmass_context = function(ion_types,lipid_types,...) {
output_items = 'exactmass',
ion_types = ion_types,
lipid_types = lipid_types,
locked = c('name','input_items','output_items','ion_types','lipid_types'),
locked = c('name','input_items','output_items','ion_types',
'lipid_types'),
...
)
return(out)
Expand Down Expand Up @@ -227,10 +240,12 @@ setMethod(f = 'is_valid',

err=list()
if (!ion_valid) {
err=c(err,paste0('"',input_value[2], '" is not a valid ion for this context.\n'))
err=c(err,paste0('"',input_value[2],
'" is not a valid ion for this context.\n'))
}
if (!lipid_valid) {
err=c(err,paste0('"',str[1], '" is not a valid Lipid for this context.\n'))
err=c(err,paste0('"',str[1],
'" is not a valid Lipid for this context.\n'))
}
if (length(err)>0) {
stop(err)
Expand Down Expand Up @@ -267,9 +282,11 @@ setMethod(f = 'show',
cat('A Metabolomics Workbench "input_item"\n\n')
cat('Name:\t"',object@name,'"\n\n',sep='')
cat('Exact pattern matching:\n')
cat(paste0('\t"',object@pattern$exact,'"',collapse='\n'),'\n\n',sep='')
cat(paste0('\t"',object@pattern$exact,'"',
collapse='\n'),'\n\n',sep='')
cat('Partial pattern matching:\n')
cat(paste0('\t"',object@pattern$partial,'"',collapse='\n'),'\n\n',sep='')
cat(paste0('\t"',object@pattern$partial,'"',
collapse='\n'),'\n\n',sep='')

if (any(object$example != '')) {
cat('Examples: \n')
Expand Down Expand Up @@ -337,7 +354,8 @@ setMethod(f = 'do_query',
if (!(all(input_item %in% names(metabolomicsWorkbenchR::input_item)))) {
stop(paste0('An input_item is not valid.'))
}
if (!(all(output_item %in% names(metabolomicsWorkbenchR::output_item)))) {
if (!(all(output_item %in% names(metabolomicsWorkbenchR::output_item))))
{
stop(paste0('An output_item is not valid.'))
}

Expand All @@ -347,7 +365,7 @@ setMethod(f = 'do_query',

if (length(input_item)>1) {
input_item=as.list(input_item)
for (k in 1:length(input_item)) {
for (k in seq_along(input_item)) {
input_item[[k]]=metabolomicsWorkbenchR::input_item[[k]]
}
} else {
Expand Down Expand Up @@ -386,7 +404,8 @@ setMethod(f = 'do_query',
} else if (is(x,'character')) {
return(x)
} else {
stop('input_item list must only contain characters or mw_input_item objects.')
stop(paste0('input_item list must only contain characters',
' or mw_input_item objects.'))
}
})
namez=unlist(namez)
Expand Down Expand Up @@ -507,7 +526,8 @@ setMethod(f = 'do_query',
} else if (is(x,'character')) {
return(x)
} else {
stop('input_item list must only contain characters or mw_input_item objects.')
stop(paste0('input_item list must only contain characters or',
' mw_input_item objects.'))
}
})
namez=unlist(namez)
Expand Down Expand Up @@ -637,7 +657,8 @@ setMethod(f = 'check_pattern',
pattern = I$pattern[[match]]
valid = grepl(x=input_value,pattern=pattern)
if (!valid) {
stop(paste0('The input_value does not match the required pattern for the provided input_item and output_item.'))
stop(paste0('The input_value does not match the required pattern',
' for the provided input_item and output_item.'))
} else {
return(TRUE)
}
Expand All @@ -651,7 +672,8 @@ setMethod(f = 'check_puts',
definition = function(input_item,output_item) {
valid = input_item$name %in% output_item$inputs
if (!valid) {
stop(paste0('The input_value is not compatible with the output_item.'))
stop(paste0('The input_value is not compatible with the',
' output_item.'))
} else {
return(TRUE)
}
Expand All @@ -671,6 +693,11 @@ use_api = function(str,output_item=NULL,input_value=NULL,testing=0) {
)
}

if (httr::http_error(response)) {
status=httr::http_status(response)
message(status$message)
return()
}

if (response$headers$`content-type`=="image/png") {
# do nothing
Expand Down Expand Up @@ -719,7 +746,8 @@ setMethod(f = 'do_query',
err=list()
# check we have a study context
if (context$name != 'study') {
err=c(err,'SummarizedExperiment output_item can only be used with "study" context')
err=c(err,paste0('SummarizedExperiment output_item can only be',
'used with "study" context'))
}
if(length(err)>0) {
stop(err)
Expand All @@ -733,7 +761,7 @@ setMethod(f = 'do_query',

## multiple analysis might be returned
out=list()
for (k in 1:length(df)) {
for (k in seq_along(df)) {

S=do_query('study','study_id',input_value,'summary')

Expand All @@ -760,7 +788,10 @@ setMethod(f = 'do_query',
# factors
SM = do_query('study','study_id',input_value,'factors')[[1]]
# merge with data samples in case some are missing
SM=merge(data.frame('local_sample_id'=colnames(X)),SM,by='local_sample_id',all=TRUE,sort=FALSE)
SM=merge(data.frame('local_sample_id'=colnames(X)),
SM,by='local_sample_id',
all=TRUE,
sort=FALSE)
rownames(SM)=SM$local_sample_id

M[['subject_type']]=SM$subject_type[1]
Expand Down Expand Up @@ -788,12 +819,12 @@ setMethod(f = 'do_query',

X=as.data.frame(t(df))

SM=as.data.frame(t(X[1:nf,]))
X=X[nf+1:nrow(X),]
SM=as.data.frame(t(X[seq_len(nf),]))
X=X[nf+seq_len(nrow(X)),]

VM=data.frame(metabolite=rownames(X))

rownames(X)=1:nrow(X)
rownames(X)=seq_len(nrow(X))

M = list(
'data_source' = 'Metabolomics Workbench',
Expand Down Expand Up @@ -853,12 +884,12 @@ setMethod(f = 'do_query',

nf=ncol(fq)-1

SM=as.data.frame(t(X[1:nf,]))
X=X[nf+1:nrow(X),]
SM=as.data.frame(t(X[seq_len(nf),]))
X=X[nf+seq_len(nrow(X)),]

VM=data.frame(feature_id=rownames(X))

rownames(X)=1:nrow(X)
rownames(X)=seq_len(nrow(X))

M = list(
'data_source' = 'Metabolomics Workbench (untargeted)',
Expand Down Expand Up @@ -908,14 +939,19 @@ setMethod(f = 'do_query',
err=list()
# check we have a study context
if (context$name != 'study') {
err=c(err,'DatasetExperiment output_item can only be used with "study" context')
err=c(err,paste0('DatasetExperiment output_item can only be used',
' with "study" context'))
}
if(length(err)>0) {
stop(err)
}

# use SE, then convert to DE
SE = do_query(context$name,input_item$name,input_value,'SummarizedExperiment')
SE = do_query(
context$name,
input_item$name,
input_value,
'SummarizedExperiment')

if (is(SE,'SummarizedExperiment')) {
DE=as.DatasetExperiment(SE)
Expand Down Expand Up @@ -964,7 +1000,11 @@ setMethod(f = 'do_query',
definition = function(context,input_item,input_value,output_item) {

# use SE then convert
SE = do_query(context$name,input_item$name,input_value,'untarg_SummarizedExperiment')
SE = do_query(
context$name,
input_item$name,
input_value,
'untarg_SummarizedExperiment')
DE = as.DatasetExperiment(SE)
return(DE)
})
Expand Down Expand Up @@ -1001,14 +1041,19 @@ setMethod(f = 'do_query',
err=list()
# check we have a study context
if (context$name != 'study') {
err=c(err,'MultiAssayExperiment output_item can only be used with "study" context')
err=c(err,paste0('MultiAssayExperiment output_item can only be',
' used with "study" context'))
}
if(length(err)>0) {
stop(err)
}

# use SE, then convert to DE
SE = do_query(context$name,input_item$name,input_value,'SummarizedExperiment')
SE = do_query(
context$name,
input_item$name,
input_value,
'SummarizedExperiment')

if (is(SE,'SummarizedExperiment')) {
SE=list(SE)
Expand All @@ -1017,4 +1062,4 @@ setMethod(f = 'do_query',

SE=MatchedAssayExperiment(SE,colData=colData(SE[[1]]))
return(SE)
})
})
Loading

0 comments on commit b1634be

Please sign in to comment.