Skip to content

Commit b1634be

Browse files
authored
Release bioc 0.99.4 (#2)
* 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
1 parent b1dc05c commit b1634be

13 files changed

+229
-112
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ vignettes/*.pdf
4242
inst/doc
4343
doc
4444
Meta
45+
46+
# yaml
47+
*.yml
48+
*.Rproj

DESCRIPTION

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: metabolomicsWorkbenchR
22
Type: Package
33
Title: Metabolomics Workbench in R
4-
Version: 0.99.3
4+
Version: 0.99.4
55
Authors@R: c(
66
person(
77
c("Gavin","Rhys"),
@@ -15,13 +15,13 @@ Authors@R: c(
1515
1616
)
1717
Description: This package provides functions for interfacing with the
18-
Metabolomics Workbench RESTful API to access study, compound, protein and gene
19-
information. Methods to obtain study data in common Bioconductor formats such
20-
as SummarizedExperiment and MultiAssayExperiment are also included.
18+
Metabolomics Workbench RESTful API. Study, compound, protein and gene
19+
information can be searched for using the API. Methods to obtain study
20+
data in common Bioconductor formats such as SummarizedExperiment and
21+
MultiAssayExperiment are also included.
2122
License: GPL-3
2223
Encoding: UTF-8
23-
LazyData: true
24-
RoxygenNote: 7.1.0
24+
RoxygenNote: 7.1.1
2525
Collate:
2626
'parse_fcns.R'
2727
'generics.R'

R/class_def.R

Lines changed: 84 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ mw_base = function(private,locked){
2121

2222
#' Get slot value from mw_base objects
2323
#'
24-
#' Gets the value of a slot from mw_base objects, provided they are not listed as
25-
#' 'private'.
24+
#' Gets the value of a slot from mw_base objects, provided they are not listed
25+
#' as 'private'.
2626
#' @param x An object derived from mw_base.
2727
#' @param name The name of the slot to access.
2828
#' @return The assigned to the slot.
@@ -44,10 +44,13 @@ setMethod(f = "$",
4444
return(slot(x,name))
4545
} else {
4646
if (!is_slot) {
47-
stop(paste0('"',name,'" is not a valid slot for objects of class "', class(x)[1],'"'))
47+
stop(paste0('"',name,
48+
'" is not a valid slot for objects of class "',
49+
class(x)[1],'"'))
4850
}
4951
if (is_private) {
50-
stop(paste0('"',name,'" is a private slot for internal use only.'))
52+
stop(paste0('"',name,
53+
'" is a private slot for internal use only.'))
5154
}
5255
}
5356
}
@@ -97,15 +100,17 @@ setMethod(f = 'is_valid',
97100
signature = c('mw_context','character','character','character'),
98101
definition = function(context,input_item,input_value,output_item) {
99102

100-
name_valid = context@name %in% c('study','compound','refmet','gene','protein','moverz','exactmass')
103+
name_valid = context@name %in% c('study','compound','refmet','gene',
104+
'protein','moverz','exactmass')
101105
input_valid = all(input_item %in% context@input_items)
102106
output_valid = all(output_item %in% context@output_items)
103107
length_valid = (length(input_value)==length(input_item))
104108
length_out_valid = !(length(input_item)>1)
105109

106110
err=list()
107111
if (!name_valid) {
108-
err=c(err,paste0('name = "',input_item,'" is not a valid context name.\n'))
112+
err=c(err,paste0('name = "',input_item,
113+
'" is not a valid context name.\n'))
109114
}
110115
if (!input_valid) {
111116
err=c(err,paste0('An input_item is not valid for this context.\n'))
@@ -116,10 +121,12 @@ setMethod(f = 'is_valid',
116121
}
117122

118123
if (!length_valid) {
119-
err=c(err,"Length of input_value must be the same as length of input_item.\n")
124+
err=c(err,paste0("Length of input_value must be the same as',
125+
' length of input_item.\n"))
120126
}
121127
if (!length_out_valid) {
122-
err=c(err,"Length of intput_item is limited to 1 for this context.\n")
128+
err=c(err,paste0("Length of intput_item is limited to 1 for',
129+
' this context.\n"))
123130
}
124131

125132
if (length(err)>0) {
@@ -138,7 +145,8 @@ mw_moverz_context = function(input_items,ion_types,tol_range,mz_range,...) {
138145
ion_types = ion_types,
139146
tol_range = tol_range,
140147
mz_range = mz_range,
141-
locked = c('name','input_items','output_items','ion_types','tol_range','mz_range'),
148+
locked = c('name','input_items','output_items','ion_types',
149+
'tol_range','mz_range'),
142150
...
143151
)
144152
return(out)
@@ -163,9 +171,11 @@ setMethod(f = 'is_valid',
163171

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

166-
range_valid2 = as.numeric(input_value[2]) >= context@mz_range[1] & as.numeric(input_value[2]) <= context@mz_range[2]
174+
range_valid2 = as.numeric(input_value[2]) >= context@mz_range[1] &
175+
as.numeric(input_value[2]) <= context@mz_range[2]
167176
ion_valid = input_value[3] %in% context@ion_types
168-
range_valid4 = as.numeric(input_value[4]) >= context@tol_range[1] & as.numeric(input_value[4]) <= context@tol_range[2]
177+
range_valid4 = as.numeric(input_value[4]) >= context@tol_range[1] &
178+
as.numeric(input_value[4]) <= context@tol_range[2]
169179
database_valid=input_value[1] %in% c('LIPIDS','MB','REFMET')
170180

171181
err=list()
@@ -179,10 +189,12 @@ setMethod(f = 'is_valid',
179189
err=c(err,"input_value[4] is out of range for this context.\n")
180190
}
181191
if (!ion_valid) {
182-
err=c(err,paste0('"',input_value[3], '" is not a valid ion for this context.\n'))
192+
err=c(err,paste0('"',input_value[3],
193+
'" is not a valid ion for this context.\n'))
183194
}
184195
if (!database_valid) {
185-
err=c(err,paste0('"',input_value[1], '" is not a valid database for this context.\n'))
196+
err=c(err,paste0('"',input_value[1],
197+
'" is not a valid database for this context.\n'))
186198
}
187199
if (length(err)>0) {
188200
stop(err)
@@ -198,7 +210,8 @@ mw_exactmass_context = function(ion_types,lipid_types,...) {
198210
output_items = 'exactmass',
199211
ion_types = ion_types,
200212
lipid_types = lipid_types,
201-
locked = c('name','input_items','output_items','ion_types','lipid_types'),
213+
locked = c('name','input_items','output_items','ion_types',
214+
'lipid_types'),
202215
...
203216
)
204217
return(out)
@@ -227,10 +240,12 @@ setMethod(f = 'is_valid',
227240

228241
err=list()
229242
if (!ion_valid) {
230-
err=c(err,paste0('"',input_value[2], '" is not a valid ion for this context.\n'))
243+
err=c(err,paste0('"',input_value[2],
244+
'" is not a valid ion for this context.\n'))
231245
}
232246
if (!lipid_valid) {
233-
err=c(err,paste0('"',str[1], '" is not a valid Lipid for this context.\n'))
247+
err=c(err,paste0('"',str[1],
248+
'" is not a valid Lipid for this context.\n'))
234249
}
235250
if (length(err)>0) {
236251
stop(err)
@@ -267,9 +282,11 @@ setMethod(f = 'show',
267282
cat('A Metabolomics Workbench "input_item"\n\n')
268283
cat('Name:\t"',object@name,'"\n\n',sep='')
269284
cat('Exact pattern matching:\n')
270-
cat(paste0('\t"',object@pattern$exact,'"',collapse='\n'),'\n\n',sep='')
285+
cat(paste0('\t"',object@pattern$exact,'"',
286+
collapse='\n'),'\n\n',sep='')
271287
cat('Partial pattern matching:\n')
272-
cat(paste0('\t"',object@pattern$partial,'"',collapse='\n'),'\n\n',sep='')
288+
cat(paste0('\t"',object@pattern$partial,'"',
289+
collapse='\n'),'\n\n',sep='')
273290

274291
if (any(object$example != '')) {
275292
cat('Examples: \n')
@@ -337,7 +354,8 @@ setMethod(f = 'do_query',
337354
if (!(all(input_item %in% names(metabolomicsWorkbenchR::input_item)))) {
338355
stop(paste0('An input_item is not valid.'))
339356
}
340-
if (!(all(output_item %in% names(metabolomicsWorkbenchR::output_item)))) {
357+
if (!(all(output_item %in% names(metabolomicsWorkbenchR::output_item))))
358+
{
341359
stop(paste0('An output_item is not valid.'))
342360
}
343361

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

348366
if (length(input_item)>1) {
349367
input_item=as.list(input_item)
350-
for (k in 1:length(input_item)) {
368+
for (k in seq_along(input_item)) {
351369
input_item[[k]]=metabolomicsWorkbenchR::input_item[[k]]
352370
}
353371
} else {
@@ -386,7 +404,8 @@ setMethod(f = 'do_query',
386404
} else if (is(x,'character')) {
387405
return(x)
388406
} else {
389-
stop('input_item list must only contain characters or mw_input_item objects.')
407+
stop(paste0('input_item list must only contain characters',
408+
' or mw_input_item objects.'))
390409
}
391410
})
392411
namez=unlist(namez)
@@ -507,7 +526,8 @@ setMethod(f = 'do_query',
507526
} else if (is(x,'character')) {
508527
return(x)
509528
} else {
510-
stop('input_item list must only contain characters or mw_input_item objects.')
529+
stop(paste0('input_item list must only contain characters or',
530+
' mw_input_item objects.'))
511531
}
512532
})
513533
namez=unlist(namez)
@@ -637,7 +657,8 @@ setMethod(f = 'check_pattern',
637657
pattern = I$pattern[[match]]
638658
valid = grepl(x=input_value,pattern=pattern)
639659
if (!valid) {
640-
stop(paste0('The input_value does not match the required pattern for the provided input_item and output_item.'))
660+
stop(paste0('The input_value does not match the required pattern',
661+
' for the provided input_item and output_item.'))
641662
} else {
642663
return(TRUE)
643664
}
@@ -651,7 +672,8 @@ setMethod(f = 'check_puts',
651672
definition = function(input_item,output_item) {
652673
valid = input_item$name %in% output_item$inputs
653674
if (!valid) {
654-
stop(paste0('The input_value is not compatible with the output_item.'))
675+
stop(paste0('The input_value is not compatible with the',
676+
' output_item.'))
655677
} else {
656678
return(TRUE)
657679
}
@@ -671,6 +693,11 @@ use_api = function(str,output_item=NULL,input_value=NULL,testing=0) {
671693
)
672694
}
673695

696+
if (httr::http_error(response)) {
697+
status=httr::http_status(response)
698+
message(status$message)
699+
return()
700+
}
674701

675702
if (response$headers$`content-type`=="image/png") {
676703
# do nothing
@@ -719,7 +746,8 @@ setMethod(f = 'do_query',
719746
err=list()
720747
# check we have a study context
721748
if (context$name != 'study') {
722-
err=c(err,'SummarizedExperiment output_item can only be used with "study" context')
749+
err=c(err,paste0('SummarizedExperiment output_item can only be',
750+
'used with "study" context'))
723751
}
724752
if(length(err)>0) {
725753
stop(err)
@@ -733,7 +761,7 @@ setMethod(f = 'do_query',
733761

734762
## multiple analysis might be returned
735763
out=list()
736-
for (k in 1:length(df)) {
764+
for (k in seq_along(df)) {
737765

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

@@ -760,7 +788,10 @@ setMethod(f = 'do_query',
760788
# factors
761789
SM = do_query('study','study_id',input_value,'factors')[[1]]
762790
# merge with data samples in case some are missing
763-
SM=merge(data.frame('local_sample_id'=colnames(X)),SM,by='local_sample_id',all=TRUE,sort=FALSE)
791+
SM=merge(data.frame('local_sample_id'=colnames(X)),
792+
SM,by='local_sample_id',
793+
all=TRUE,
794+
sort=FALSE)
764795
rownames(SM)=SM$local_sample_id
765796

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

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

791-
SM=as.data.frame(t(X[1:nf,]))
792-
X=X[nf+1:nrow(X),]
822+
SM=as.data.frame(t(X[seq_len(nf),]))
823+
X=X[nf+seq_len(nrow(X)),]
793824

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

796-
rownames(X)=1:nrow(X)
827+
rownames(X)=seq_len(nrow(X))
797828

798829
M = list(
799830
'data_source' = 'Metabolomics Workbench',
@@ -853,12 +884,12 @@ setMethod(f = 'do_query',
853884

854885
nf=ncol(fq)-1
855886

856-
SM=as.data.frame(t(X[1:nf,]))
857-
X=X[nf+1:nrow(X),]
887+
SM=as.data.frame(t(X[seq_len(nf),]))
888+
X=X[nf+seq_len(nrow(X)),]
858889

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

861-
rownames(X)=1:nrow(X)
892+
rownames(X)=seq_len(nrow(X))
862893

863894
M = list(
864895
'data_source' = 'Metabolomics Workbench (untargeted)',
@@ -908,14 +939,19 @@ setMethod(f = 'do_query',
908939
err=list()
909940
# check we have a study context
910941
if (context$name != 'study') {
911-
err=c(err,'DatasetExperiment output_item can only be used with "study" context')
942+
err=c(err,paste0('DatasetExperiment output_item can only be used',
943+
' with "study" context'))
912944
}
913945
if(length(err)>0) {
914946
stop(err)
915947
}
916948

917949
# use SE, then convert to DE
918-
SE = do_query(context$name,input_item$name,input_value,'SummarizedExperiment')
950+
SE = do_query(
951+
context$name,
952+
input_item$name,
953+
input_value,
954+
'SummarizedExperiment')
919955

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

9661002
# use SE then convert
967-
SE = do_query(context$name,input_item$name,input_value,'untarg_SummarizedExperiment')
1003+
SE = do_query(
1004+
context$name,
1005+
input_item$name,
1006+
input_value,
1007+
'untarg_SummarizedExperiment')
9681008
DE = as.DatasetExperiment(SE)
9691009
return(DE)
9701010
})
@@ -1001,14 +1041,19 @@ setMethod(f = 'do_query',
10011041
err=list()
10021042
# check we have a study context
10031043
if (context$name != 'study') {
1004-
err=c(err,'MultiAssayExperiment output_item can only be used with "study" context')
1044+
err=c(err,paste0('MultiAssayExperiment output_item can only be',
1045+
' used with "study" context'))
10051046
}
10061047
if(length(err)>0) {
10071048
stop(err)
10081049
}
10091050

10101051
# use SE, then convert to DE
1011-
SE = do_query(context$name,input_item$name,input_value,'SummarizedExperiment')
1052+
SE = do_query(
1053+
context$name,
1054+
input_item$name,
1055+
input_value,
1056+
'SummarizedExperiment')
10121057

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

10181063
SE=MatchedAssayExperiment(SE,colData=colData(SE[[1]]))
10191064
return(SE)
1020-
})
1065+
})

0 commit comments

Comments
 (0)