Skip to content

Commit 552898c

Browse files
authored
Devel_1_1_1 (#6)
* fix for #4 ensure imported data is numeric * add helper functions * add structToolbox vignette * add HDF5Array to suggests for MultiAssayExperiment * add some output items to study context * update vignettes
1 parent 8717c46 commit 552898c

15 files changed

+388
-21
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
^doc$
77
^Meta$
88
^data-raw$
9+
^\.github$

.github/workflows/check-bioc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ env:
3838
run_covr: 'true'
3939
run_pkgdown: 'false'
4040
has_RUnit: 'false'
41-
cache-version: 'cache-v1'
41+
cache-version: 'cache-v2'
4242

4343
jobs:
4444
build-check:

DESCRIPTION

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Collate:
2727
'generics.R'
2828
'class_def.R'
2929
'constants.R'
30+
'helper_fcns.R'
3031
'metabolomicsWorkbenchR.R'
3132
Imports:
3233
data.table,
@@ -41,8 +42,13 @@ Suggests:
4142
BiocStyle,
4243
covr,
4344
knitr,
45+
HDF5Array,
4446
rmarkdown,
45-
testthat
47+
structToolbox,
48+
testthat,
49+
pmp,
50+
grid,
51+
png
4652
VignetteBuilder:
4753
knitr
4854
biocViews: Software, Metabolomics

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
export(check_pattern)
44
export(check_puts)
55
export(context)
6+
export(context_inputs)
7+
export(context_outputs)
68
export(do_query)
9+
export(input_example)
710
export(input_item)
811
export(is_valid)
912
export(output_item)

R/class_def.R

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ setMethod(f = 'show',
9393
}
9494
)
9595

96-
9796
#' @rdname is_valid
9897
#' @export
9998
setMethod(f = 'is_valid',
@@ -880,24 +879,21 @@ setMethod(f = 'do_query',
880879
df = do_query(context$name,input_item$name,input_value,'untarg_data')
881880
fq = do_query('study','analysis_id',input_value,'untarg_factors')
882881

883-
X=as.data.frame(t(df))
884-
885-
nf=ncol(fq)-1
886-
887-
SM=as.data.frame(t(X[seq_len(nf),]))
888-
X=X[nf+seq_len(nrow(X)),]
889-
890-
VM=data.frame(feature_id=rownames(X))
882+
fq=fq[,-1]
883+
884+
SM=as.data.frame(df[,colnames(fq)])
885+
df[,colnames(fq)]=NULL
891886

892-
rownames(X)=seq_len(nrow(X))
887+
df=as.data.frame(t(df))
888+
VM=data.frame(feature_id=rownames(df))
893889

894890
M = list(
895891
'data_source' = 'Metabolomics Workbench (untargeted)',
896892
'analysis_id' = input_value
897893
)
898894

899895
SE = SummarizedExperiment(
900-
assays = X,
896+
assays = df,
901897
rowData = VM,
902898
colData = SM,
903899
metadata = M

R/constants.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ context$study = mw_context(
5757
output_items = c('summary','factors','analysis','metabolites','mwtab',
5858
'source','species','disease','number_of_metabolites','data','datatable',
5959
'untarg_studies','untarg_factors','untarg_data','metabolite_info',
60-
'SummarizedExperiment')
60+
'SummarizedExperiment','untarg_SummarizedExperiment','DatasetExperiment',
61+
'untarg_DatasetExperiment')
6162
)
6263

6364
context$compound = mw_context(

R/helper_fcns.R

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#' Valid inputs
2+
#'
3+
#' Get a list of valid input_items for a context.
4+
#'
5+
#' @param context The name of a valid context (character)
6+
#' @return A list of input item names for a context
7+
#' @examples
8+
#' # list of input items for the "study" context
9+
#' context_inputs("study")
10+
#' @export
11+
context_inputs = function(context) {
12+
if (!is.character(context)) {
13+
stop('"context" must be of type "character"')
14+
}
15+
16+
name_valid = context %in% names(metabolomicsWorkbenchR::context)
17+
if (!name_valid) {
18+
stop(paste0('"',context,'" is not a recognised context. Use ',
19+
'names(context) for a list of valid contexts'))
20+
}
21+
22+
return(metabolomicsWorkbenchR::context[[context]]$input_items)
23+
}
24+
25+
#' Valid outputs
26+
#'
27+
#' Get a list of valid output_items for a context.
28+
#'
29+
#' @param context The name of a valid context (character)
30+
#' @return A list of output item names for a context
31+
#' @examples
32+
#' # list of output items for the "study" context
33+
#' context_outputs("study")
34+
#' @export
35+
context_outputs = function(context) {
36+
if (!is.character(context)) {
37+
stop('"context" must be of type "character"')
38+
}
39+
40+
name_valid = context %in% names(metabolomicsWorkbenchR::context)
41+
if (!name_valid) {
42+
stop(paste0('"',context,'" is not a recognised context. Use ',
43+
'names(context) for a list of valid contexts'))
44+
}
45+
46+
x=metabolomicsWorkbenchR::context[[context]]$output_items
47+
w=which(x=='all')
48+
if (length(w)>0){
49+
x=x[-w]
50+
}
51+
return(x)
52+
}
53+
54+
#' Valid input_value for input_item
55+
#'
56+
#' Displays a valid input_value for an input_item and returns an example that
57+
#' matches the required input pattern.
58+
#'
59+
#' @param input_item The name of a valid input_item (character)
60+
#' @return An example input value matching the pattern required for the chosen
61+
#' input item.
62+
#' @examples
63+
#' # example input_value for input item "study_id"
64+
#' input_example('study_id')
65+
#' @export
66+
input_example = function(input_item) {
67+
if (!is.character(input_item)) {
68+
stop('"input_item" must be of type "character"')
69+
}
70+
71+
name_valid = input_item %in% names(metabolomicsWorkbenchR::input_item)
72+
if (!name_valid) {
73+
stop(paste0('"',input_item,'" is not a recognised input_item. Use ',
74+
'names(input_item) for a list of valid input items'))
75+
}
76+
77+
show(metabolomicsWorkbenchR::input_item[[input_item]])
78+
79+
return(
80+
invisible(metabolomicsWorkbenchR::input_item[[input_item]]$example[1]))
81+
}
82+
83+

R/parse_fcns.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,13 @@ parse_untarg_data=function(response,output_item,input_value) {
154154

155155
# add the factors into back into the table
156156
w=which(colnames(out)=='group')
157+
# convert to numeric
158+
temp=lapply(out[(w+1):ncol(out)],as.numeric)
159+
temp=as.data.frame(temp)
160+
rownames(temp)=rownames(out)
161+
colnames(temp)=colnames(out[(w+1):ncol(out)])
157162
# exclude group
158-
out=cbind(out[seq_len(w-1)],m,out[(w+1):ncol(out)])
163+
out=cbind(out[seq_len(w-1)],m,temp)
159164

160165
out$group=NULL
161166
return(out)
@@ -176,8 +181,13 @@ parse_datatable=function(response,output_item,input_value) {
176181

177182
# add the factors into back into the table
178183
w=which(colnames(out)=='Class')
184+
# convert to numeric
185+
temp=lapply(out[(w+1):ncol(out)],as.numeric)
186+
temp=as.data.frame(temp)
187+
rownames(temp)=rownames(out)
188+
colnames(temp)=colnames(out[(w+1):ncol(out)])
179189
# exclude group
180-
out=cbind(out[seq_len(w-1)],m,out[(w+1):ncol(out)])
190+
out=cbind(out[seq_len(w-1)],m,temp)
181191
out$Class=NULL
182192
attributes(out)=c(attributes(out),list('number_of_factors'=ncol(m)))
183193

man/context_inputs.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/context_outputs.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)