diff --git a/DESCRIPTION b/DESCRIPTION index ef9eba4..a44a50e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,7 @@ Description: This package provides functions for interfacing with the MultiAssayExperiment are also included. License: GPL-3 Encoding: UTF-8 -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.3 Collate: 'parse_fcns.R' 'generics.R' diff --git a/R/class_def.R b/R/class_def.R index 839aa6a..bd2834a 100644 --- a/R/class_def.R +++ b/R/class_def.R @@ -20,8 +20,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 +#' +#' 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. @@ -36,16 +36,16 @@ mw_base = function(private,locked){ setMethod(f = "$", signature = c("mw_base"), definition = function(x,name) { - + is_slot = name %in% slotNames(x) is_private = name %in% c(x@private,'private') - + if (is_slot & !is_private) { return(slot(x,name)) } else { if (!is_slot) { stop(paste0('"',name, - '" is not a valid slot for objects of class "', + '" is not a valid slot for objects of class "', class(x)[1],'"')) } if (is_private) { @@ -66,7 +66,7 @@ mw_context = function(name,input_items,output_items,...) { output_items = output_items, locked = c('name','input_items','output_items'), ... - ) + ) return(out) } @@ -98,14 +98,14 @@ setMethod(f = 'show', 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') 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, @@ -114,11 +114,11 @@ setMethod(f = 'is_valid', if (!input_valid) { err=c(err,paste0('An input_item is not valid for this context.\n')) } - + if (!output_valid) { err=c(err,paste0('An output_item is not valid for this context.\n')) } - + if (!length_valid) { err=c(err,paste0("Length of input_value must be the same as', ' length of input_item.\n")) @@ -127,7 +127,7 @@ setMethod(f = 'is_valid', err=c(err,paste0("Length of intput_item is limited to 1 for', ' this context.\n")) } - + if (length(err)>0) { stop(err) } else { @@ -147,7 +147,7 @@ mw_moverz_context = function(input_items,ion_types,tol_range,mz_range,...) { locked = c('name','input_items','output_items','ion_types', 'tol_range','mz_range'), ... - ) + ) return(out) } @@ -167,16 +167,16 @@ mw_moverz_context = function(input_items,ion_types,tol_range,mz_range,...) { setMethod(f = 'is_valid', signature = c('mw_moverz_context','character','character','missing'), definition = function(context,input_item,input_value) { - + input_valid = all(input_item %in% context@input_items) - - range_valid2 = as.numeric(input_value[2]) >= context@mz_range[1] & + + 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] & + 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() if (!input_valid) { err=c(err,paste0('An input_item is not valid for this context.\n')) @@ -188,11 +188,11 @@ 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], + 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], + err=c(err,paste0('"',input_value[1], '" is not a valid database for this context.\n')) } if (length(err)>0) { @@ -212,7 +212,7 @@ mw_exactmass_context = function(ion_types,lipid_types,...) { locked = c('name','input_items','output_items','ion_types', 'lipid_types'), ... - ) + ) return(out) } @@ -232,18 +232,18 @@ mw_exactmass_context = function(ion_types,lipid_types,...) { setMethod(f = 'is_valid', signature = c('mw_exactmass_context','character','character','missing'), definition = function(context,input_item,input_value) { - + str=strsplit(input_value[1],'(',fixed=TRUE)[[1]] lipid_valid = str[1] %in% context@lipid_types ion_valid = input_value[2] %in% context@ion_types - + err=list() if (!ion_valid) { - err=c(err,paste0('"',input_value[2], + 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], + err=c(err,paste0('"',str[1], '" is not a valid Lipid for this context.\n')) } if (length(err)>0) { @@ -286,7 +286,7 @@ setMethod(f = 'show', cat('Partial pattern matching:\n') cat(paste0('\t"',object@pattern$partial,'"', collapse='\n'),'\n\n',sep='') - + if (any(object$example != '')) { cat('Examples: \n') cat(paste0('\t"',object@example,'"',collapse='\n'),'\n\n',sep='') @@ -342,8 +342,8 @@ setMethod(f = 'show', setMethod(f = 'do_query', signature = c('character','character','character','character'), definition = function(context,input_item,input_value,output_item) { - - + + if (length(output_item)>1) { stop('output_item must be of length 1') } @@ -357,11 +357,11 @@ setMethod(f = 'do_query', { stop(paste0('An output_item is not valid.')) } - + # convert to objects context=metabolomicsWorkbenchR::context[[context]] output_item=metabolomicsWorkbenchR::output_item[[output_item]] - + if (length(input_item)>1) { input_item=as.list(input_item) for (k in seq_along(input_item)) { @@ -370,10 +370,10 @@ setMethod(f = 'do_query', } else { input_item=metabolomicsWorkbenchR::input_item[[input_item]] } - + # query the database out=do_query(context,input_item,input_value,output_item) - + return(out) } ) @@ -385,16 +385,16 @@ setMethod(f = 'do_query', setMethod(f = 'do_query', signature = c('mw_moverz_context','list','character','mw_output_item'), definition = function(context,input_item,input_value,output_item) { - - + + if (length(input_item)!=4) { stop('You must provide 4 input_item for the moverz context.') - } - + } + if (length(input_value)!=4) { stop('You must provide 4 input_value for the moverz context.') - } - + } + # get input list as strings namez = lapply(input_item,function(x) { if (is(x,'mw_input_item')) { @@ -408,7 +408,7 @@ setMethod(f = 'do_query', } }) namez=unlist(namez) - + # check namez if (namez[1]!='database') { stop('input_item[1] must be "database"') @@ -422,28 +422,28 @@ setMethod(f = 'do_query', if (namez[4]!='tolerance') { stop('input_item[4] must be "tolerance"') } - + # check context context_valid = is_valid( context, namez, input_value ) - + # build the url str=paste('https://www.metabolomicsworkbench.org/rest', context@name, paste(input_value,collapse='/',sep=''), sep='/') - - if (identical(Sys.getenv("TESTTHAT"), "true")) { - print(str) + + if (identical(Sys.getenv("TESTTHAT"), "true")) { + print(str) } - + out = use_api(str,output_item,input_value) - + return(out) - + } ) @@ -507,16 +507,16 @@ setMethod(f = 'do_query', setMethod(f = 'do_query', signature = c('mw_exactmass_context','list','character','mw_output_item'), definition = function(context,input_item,input_value,output_item) { - - + + if (length(input_item)!=2) { stop('You must provide 2 input_item for the exactmass context.') - } - + } + if (length(input_value)!=2) { stop('You must provide 2 input_value for the exactmass context.') - } - + } + # get input list as strings namez = lapply(input_item,function(x) { if (is(x,'mw_input_item')) { @@ -530,7 +530,7 @@ setMethod(f = 'do_query', } }) namez=unlist(namez) - + # check namez if (namez[1]!='lipid') { stop('input_item[1] must be "lipid"') @@ -538,28 +538,28 @@ setMethod(f = 'do_query', if (namez[2]!='ion') { stop('input_item[2] must be "ion"') } - + # check context context_valid = is_valid( context, namez, input_value ) - + # build the url str=paste('https://www.metabolomicsworkbench.org/rest', context@name, paste(input_value,collapse='/',sep=''), sep='/') - + if (identical(Sys.getenv("TESTTHAT"), "true")) { print(str) } - + out = use_api(str,output_item,input_value) - + return(out) - + } ) @@ -623,14 +623,14 @@ setMethod(f = 'do_query', setMethod(f = 'do_query', signature = c('mw_context','mw_input_item','character','mw_output_item'), definition = function(context,input_item,input_value,output_item) { - + # check the context is valid is_valid(context,input_item$name,input_value,output_item$name) # check the input pattern check_pattern(input_item,input_value,output_item$match) # check the output_item and input_item are compatible check_puts(input_item,output_item) - + # build the url str=paste('https://www.metabolomicsworkbench.org/rest', context@name, @@ -638,12 +638,12 @@ setMethod(f = 'do_query', paste(input_value,collapse='/',sep=''), paste(output_item$name,collapse=',',sep=''), sep='/') - + if (identical(Sys.getenv("TESTTHAT"), "true")) { print(str) } out = use_api(str,output_item,input_value) - + return(out) } ) @@ -680,7 +680,7 @@ setMethod(f = 'check_puts', ) use_api = function(str,output_item=NULL,input_value=NULL,testing=0) { - + if (identical(Sys.getenv("TESTTHAT"), "true")) { # return a stored result for testing print('TEST mode') @@ -691,25 +691,15 @@ use_api = function(str,output_item=NULL,input_value=NULL,testing=0) { url=str ) } - + if (httr::http_error(response)) { status=httr::http_status(response) message(status$message) return() } - - if (response$headers$`content-type`=="image/png") { - # do nothing - } else { - out=httr::content(response,as='text',encoding = 'UTF-8') - if (out=='[]') { - message('There were no results for your query.') - return(NULL) - } - } - + out = output_item$parse_fcn(response,output_item,input_value) - + return(out) } @@ -741,7 +731,7 @@ mw_SE_item = function(name,fields,inputs,parse_fcn,match,...) { setMethod(f = 'do_query', signature = c('mw_context','mw_input_item','character','mw_SE_item'), definition = function(context,input_item,input_value,output_item) { - + err=list() # check we have a study context if (context$name != 'study') { @@ -751,27 +741,27 @@ setMethod(f = 'do_query', if(length(err)>0) { stop(err) } - + ## get data if (input_item$name == 'study_id') { df = do_query(context$name,input_item$name,input_value,'data') - - - + + + ## multiple analysis might be returned out=list() for (k in seq_along(df)) { - + S=do_query('study','study_id',input_value,'summary') - + # raw data X = df[[k]][,8:ncol(df[[k]])] rownames(X)=df[[k]]$metabolite_id - + # feature meta data VM = df[[k]][,4:6] rownames(VM)=df[[k]]$metabolite_id - + # additional metadata M = list( data_source = 'Metabolomics Workbench', @@ -782,8 +772,8 @@ setMethod(f = 'do_query', name=paste0(S$study_id[[1]],':',df[[k]]$analysis_id[1]), description=S$study_title[[1]] ) - - + + # factors SM = do_query('study','study_id',input_value,'factors')[[1]] # merge with data samples in case some are missing @@ -792,10 +782,10 @@ setMethod(f = 'do_query', all=TRUE, sort=FALSE) rownames(SM)=SM$local_sample_id - + M[['subject_type']]=SM$subject_type[1] SM$subject_type=NULL - + # SE object SE = SummarizedExperiment( assays=list(X), @@ -803,46 +793,46 @@ setMethod(f = 'do_query', colData = SM, metadata = M ) - + out[[df[[k]]$analysis_id[1]]]=SE } - + if (length(out)==1) { out=out[[1]] } - + return(out) } else if (input_item$name == 'analysis_id') { df = do_query(context$name,input_item$name,input_value,'datatable') nf=attributes(df)$number_of_factors - + X=as.data.frame(t(df)) - + SM=as.data.frame(t(X[seq_len(nf),])) X=X[nf+seq_len(nrow(X)),] - + VM=data.frame(metabolite=rownames(X)) - + rownames(X)=seq_len(nrow(X)) - + M = list( 'data_source' = 'Metabolomics Workbench', 'analysis_id' = input_value, 'name'=input_value, 'description'='Downloaded from Metabolomics Workbench' ) - + SE = SummarizedExperiment( assays = X, rowData = VM, colData = SM, metadata = M ) - + out=SE return(out) } - + } ) @@ -873,34 +863,34 @@ mw_untarg_SE_item = function(name,fields,inputs,parse_fcn,match,...) { setMethod(f = 'do_query', signature = c('mw_context','mw_input_item','character','mw_untarg_SE_item'), definition = function(context,input_item,input_value,output_item) { - + ## get data - + df = do_query(context$name,input_item$name,input_value,'untarg_data') fq = do_query('study','analysis_id',input_value,'untarg_factors') - + fq=fq[,-1] SM=as.data.frame(df[,colnames(fq)]) df[,colnames(fq)]=NULL - + df=as.data.frame(t(df)) VM=data.frame(feature_id=rownames(df)) - + M = list( 'data_source' = 'Metabolomics Workbench (untargeted)', 'analysis_id' = input_value ) - + SE = SummarizedExperiment( assays = df, rowData = VM, colData = SM, metadata = M ) - + return(SE) - + } ) @@ -941,14 +931,14 @@ setMethod(f = 'do_query', if(length(err)>0) { stop(err) } - + # use SE, then convert to DE SE = do_query( context$name, input_item$name, input_value, 'SummarizedExperiment') - + if (is(SE,'SummarizedExperiment')) { DE=as.DatasetExperiment(SE) DE$name=input_value @@ -960,7 +950,7 @@ setMethod(f = 'do_query', } return(DE) } - + if (is(SE,'list')) { DE=lapply(SE,as.DatasetExperiment) return(DE) @@ -994,7 +984,7 @@ mw_untarg_DE_item = function(name,fields,inputs,parse_fcn,match,...) { setMethod(f = 'do_query', signature = c('mw_context','mw_input_item','character','mw_untarg_DE_item'), definition = function(context,input_item,input_value,output_item) { - + # use SE then convert SE = do_query( context$name, @@ -1043,19 +1033,19 @@ setMethod(f = 'do_query', if(length(err)>0) { stop(err) } - + # use SE, then convert to DE SE = do_query( context$name, input_item$name, input_value, 'SummarizedExperiment') - + if (is(SE,'SummarizedExperiment')) { SE=list(SE) names(SE)=input_value } - + SE=MatchedAssayExperiment(SE,colData=colData(SE[[1]])) return(SE) }) diff --git a/R/parse_fcns.R b/R/parse_fcns.R index 3dad3cf..2c09048 100644 --- a/R/parse_fcns.R +++ b/R/parse_fcns.R @@ -3,12 +3,17 @@ parse_data_frame=function(response,output_item,input_value) { out=httr::content(response,as='text',encoding = 'UTF-8') # parse json out=jsonlite::fromJSON(out) - + + # check for no results + if (length(out)==0){ + return(NULL) + } + # force to list of lists in case of length = 1 if (!is.list(out[[1]])) { out=list(out) } - + # tidy column names out=lapply(out,function(x){ # lower case @@ -17,53 +22,53 @@ parse_data_frame=function(response,output_item,input_value) { names(x)=gsub('([[:punct:]])|\\s+','_',names(x)) return(x) }) - - + + # create data.frame with expected return column names expected = as.data.frame(matrix(NA,nrow=0,ncol=length(output_item$fields))) colnames(expected) = output_item$fields # add it to the list out[[length(out)+1]]=expected - + # rbind the list and pad with NA if field not returned out = data.table::rbindlist(out,fill=TRUE) out = as.data.frame(out) # NB added row of NA already dropped - + # return the df return(out) } parse_factors=function(response,output_item,input_value) { - + # parse output to data.frame out_orig = parse_data_frame(response,output_item,input_value) - + # create a list with factors for each sample_id u = unique(out_orig$study_id) OUT=list() - + for (id in u) { # subset study_id out=out_orig[out_orig$study_id==id,,drop=FALSE] - + # expand factors # assume no more than 20 factors for a study - m=as.data.frame(matrix(NA,nrow=nrow(out),ncol=20)) - + m=as.data.frame(matrix(NA,nrow=nrow(out),ncol=20)) + for (k in seq(from=1,to=nrow(out))) { - + x=out$factors[k] - + # generate a data.frame from the factors by splitting at the pipes at_pipe=strsplit(x,'|',fixed=TRUE)[[1]] - + for (j in seq(from=1, to=length(at_pipe))) { # split each factor at colon at_colon=strsplit(at_pipe[[j]],':',fixed=TRUE)[[1]] - + m[k,j]=at_colon[2] - + fname=gsub('([[:punct:]])|\\s+','_',at_colon[1]) if (substr(fname,1,1)=='_') { fname=substr(fname,2,nchar(fname)) @@ -71,17 +76,17 @@ parse_factors=function(response,output_item,input_value) { colnames(m)[j]=fname } } - + m=m[,seq(from=1,to=length(at_pipe)),drop=FALSE] # set strings to factors - + m=as.data.frame(lapply(m,factor)) - + # bind the factors to the origin data.frame out=cbind(out,m) - + # remove superfluous info out=out[,-4] - + OUT[[id]]=out } return(OUT) @@ -91,7 +96,12 @@ parse_untarg_factors=function(response,output_item,input_value) { out=httr::content(response,as='text',encoding = 'UTF-8') # parse json out=jsonlite::fromJSON(out) - + + # check for no results + if (length(out)==0){ + return(NULL) + } + df = as.data.frame(unlist(out)) # remove number df$group=trimws(gsub(pattern='^[0-9]+.',replacement='',x=rownames(df))) @@ -112,7 +122,12 @@ parse_data=function(response,output_item,input_value) { out=httr::content(response,as='text',encoding = 'UTF-8') # parse json out=jsonlite::fromJSON(out) - + + # check for no results + if (length(out)==0){ + return(NULL) + } + out=lapply(out,function(x){ x$DATA=lapply(x$DATA,function(y){ if (is.null(y)) { @@ -127,31 +142,37 @@ parse_data=function(response,output_item,input_value) { colnames(out)=gsub('DATA.','',colnames(out),fixed=TRUE) # convert to numeric out[,8:ncol(out)]=lapply(out[,8:ncol(out)],as.numeric) - + # check for multiple analysis_id u=unique(out$analysis_id) - + # split by analysis_id out2=list() for (k in u) { out2[[k]]=out[out$analysis_id==k,] } - + return(out2) } parse_untarg_data=function(response,output_item,input_value) { out=httr::content(response,as='text',encoding = 'UTF-8') + + # check for no results + if (length(out)==0){ + return(NULL) + } + out=read.table( text=out, sep='\t', header = TRUE, row.names = 1, check.names = FALSE) - + # split the group column at the pipe to get factors m = create_factor_columns(out,'group') - + # add the factors into back into the table w=which(colnames(out)=='group') # convert to numeric @@ -161,24 +182,30 @@ parse_untarg_data=function(response,output_item,input_value) { colnames(temp)=colnames(out[(w+1):ncol(out)]) # exclude group out=cbind(out[seq_len(w-1)],m,temp) - + out$group=NULL return(out) } parse_datatable=function(response,output_item,input_value) { - + out=httr::content(response,as='text',encoding = 'UTF-8') + + # check for no results + if (length(out)==0){ + return(NULL) + } + out=read.delim( text=out, sep='\t', row.names = 1, header = TRUE, check.names = FALSE) - + # split the group column at the pipe to get factors m = create_factor_columns(out,'Class') - + # add the factors into back into the table w=which(colnames(out)=='Class') # convert to numeric @@ -190,7 +217,7 @@ parse_datatable=function(response,output_item,input_value) { out=cbind(out[seq_len(w-1)],m,temp) out$Class=NULL attributes(out)=c(attributes(out),list('number_of_factors'=ncol(m))) - + return(out) } @@ -199,13 +226,13 @@ create_factor_columns = function(out,fn) { m=matrix(NA,nrow=nrow(out),ncol=20) # assume no more than 20 factors # split at pipe at_pipe = strsplit(out[[fn]],'|',fixed=TRUE) - + m=lapply(at_pipe,function(x){ at_colon=strsplit(x,':',fixed=TRUE) m=matrix(NA,nrow=1,ncol=length(at_colon)) n=matrix(interaction('V',seq_along(at_colon),sep=''), - nrow=1, - ncol=ncol(m)) + nrow=1, + ncol=ncol(m)) for (j in seq_along(at_colon)) { m[1,j]=trimws(at_colon[[j]][length(at_colon[[j]])]) if (length(at_colon[[j]])==2) { @@ -227,16 +254,21 @@ parse_do_nothing=function(response,output_item,input_value) { parse_moverz=function(response,output_item,input_value) { out=httr::content(response,as='text',encoding = 'UTF-8') - + + # check for no results + if (length(out)==0){ + return(NULL) + } + if (input_value[[1]]=='MB') { - # remove extra column of - - - + # remove extra column of - - - out2=gsub(pattern = '\t-\t-\t-\n',replacement = '\n',out) - # remove extra column of - - + # remove extra column of - - out2=gsub(pattern = '\t-\t-\n',replacement = '\n',out2) # replace - - - with - out2=gsub(pattern = '\t-\t-\t-\t',replacement = '\t-\t',out2) } else if (input_value[[1]]=='LIPIDS') { - # remove extra column + # remove extra column out2=gsub(pattern = '\t\n',replacement = '\n',out) # split merged columns info=gregexpr('[0-9]+\\.[0-9]+\\.[0-9]+',out2) @@ -254,7 +286,7 @@ parse_moverz=function(response,output_item,input_value) { } else if (input_value[[1]]=='REFMET'){ out2=out } - + # datatable out=read.delim(text=out2,sep='\t',na.strings = '-') colnames(out)=tolower(colnames(out)) @@ -265,10 +297,16 @@ parse_moverz=function(response,output_item,input_value) { parse_exactmass=function(response,output_item,input_item) { out=httr::content(response,as='text',encoding = 'UTF-8') + + # check for no results + if (length(out)==0){ + return(NULL) + } + out2=gsub(pattern = '
',replacement = '',out) out2=gsub(pattern = '\n\n\n',replacement = '',out2) out2=gsub(pattern = '\n',replacement = '\t',out2) out=read.delim(text=out2,header=FALSE,sep='\t') colnames(out)=output_item$fields return(out) -} \ No newline at end of file +} diff --git a/R/sysdata.rda b/R/sysdata.rda index 39f1986..eb0cfbd 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/man/mw_base.Rd b/man/mw_base.Rd index cf09294..d5a64b7 100644 --- a/man/mw_base.Rd +++ b/man/mw_base.Rd @@ -15,7 +15,7 @@ The assigned to the slot. } \description{ -Gets the value of a slot from mw_base objects, provided they are not listed +Gets the value of a slot from mw_base objects, provided they are not listed as 'private'. } \examples{ diff --git a/vignettes/Introduction_to_metabolomicsWorkbenchR.Rmd b/vignettes/Introduction_to_metabolomicsWorkbenchR.Rmd index fc56666..5efa2d8 100644 --- a/vignettes/Introduction_to_metabolomicsWorkbenchR.Rmd +++ b/vignettes/Introduction_to_metabolomicsWorkbenchR.Rmd @@ -94,7 +94,7 @@ df[,1:3] ``` We can also request an image of the molecular structure: -```{r} +```{r, eval=FALSE} img = do_query( context = 'compound', input_item = 'regno', @@ -199,17 +199,19 @@ MAE ## `output_item` "untarg_SummarizedExperiment" and "untarg_DatasetExperiment" This output refers to the study context and uses multiple queries to return a SummarizedExperiment or DatasetExperiment object of untargeted data for an analysis_id. -```{r} +```{r,eval=FALSE} SE = do_query( context = 'study', input_item = 'analysis_id', - input_value = 'AN000023', + input_value = 'AN000025', output_item = 'untarg_SummarizedExperiment' # or 'untarg_DatasetExperiment' ) SE ``` - +```{r eval=TRUE,include=FALSE,echo=TRUE} +SE = metabolomicsWorkbenchR:::AN000025 +``` # S4 classes A number of classes have been defined in this package and for completeness they are described below. They are used to @@ -227,7 +229,7 @@ The name of all valid contexts can be displayed: ```{r} # list all context names -names(context) +names(metabolomicsWorkbenchR::context) ``` Information about a specific context can be obtained using the show method for a @@ -235,7 +237,7 @@ an `mw_context` object: ```{r} # list valid inputs/outputs for the "study" context -context$study +metabolomicsWorkbenchR::context$study ``` ## Input / Output Items Once the context of the search has been decided upon valid inputs and outputs can diff --git a/vignettes/example_using_structToolbox.Rmd b/vignettes/example_using_structToolbox.Rmd index 09c2d20..a9a0e96 100644 --- a/vignettes/example_using_structToolbox.Rmd +++ b/vignettes/example_using_structToolbox.Rmd @@ -68,7 +68,7 @@ In `metabolomicsWorkBenchR` contexts are stored as a list, and a list of valid contexts can be obtained using the `names` function: ```{r} -names(context) +names(metabolomicsWorkbenchR::context) ``` `input_item` is specific to a context. Valid items for a context can @@ -109,7 +109,7 @@ As there are multiple datasets per study untargeted data needs to be requested by Analysis ID. We will request DatasetExperiment format so that we can use the data directly with `structToolbox`. -```{r} +```{r,eval=FALSE} DE = do_query( context = 'study', input_item = 'analysis_id', @@ -117,13 +117,18 @@ DE = do_query( output_item = 'untarg_DatasetExperiment' ) DE +``` +```{r,eval=TRUE,include=FALSE} +DE=metabolomicsWorkbenchR:::AN000025 +DE=as.DatasetExperiment(DE) +DE ``` # Workflow Now we construct a minimal metabolomics workflow consisting of quality filtering, normalisation, imputation and scaling before applying PCA. -```{r} +```{r,warning=FALSE} # model sequence M = mv_feature_filter( diff --git a/vignettes/introduction/0/www.metabolomicsworkbench.org/rest/study/analysis_id/AN000023/untarg_factors.json b/vignettes/introduction/0/www.metabolomicsworkbench.org/rest/study/analysis_id/AN000023/untarg_factors.json deleted file mode 100644 index 31e70da..0000000 --- a/vignettes/introduction/0/www.metabolomicsworkbench.org/rest/study/analysis_id/AN000023/untarg_factors.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "1": { - "AFTER_MEAL_TIME:30_MIN | female | POST_SURGERY_TIME:12MO | GASTRIC_BAND": "3" - }, - "2": { - "AFTER_MEAL_TIME:30_MIN | female | POST_SURGERY_TIME:12MO | ROUX_EN_Y": "1" - }, - "3": { - "AFTER_MEAL_TIME:30_MIN | female | POST_SURGERY_TIME:6MO | GASTRIC_BAND": "4" - }, - "4": { - "AFTER_MEAL_TIME:30_MIN | female | POST_SURGERY_TIME:6MO | ROUX_EN_Y": "11" - }, - "5": { - "AFTER_MEAL_TIME:30_MIN | female | POST_SURGERY_TIME:NO_SURGERY | LEAN_CONTROL": "7" - }, - "6": { - "AFTER_MEAL_TIME:30_MIN | female | POST_SURGERY_TIME:PRE_SURGERY | GASTRIC_BAND": "7" - }, - "7": { - "AFTER_MEAL_TIME:30_MIN | female | POST_SURGERY_TIME:PRE_SURGERY | ROUX_EN_Y": "12" - }, - "8": { - "AFTER_MEAL_TIME:30_MIN | male | POST_SURGERY_TIME:12MO | GASTRIC_BAND": "2" - }, - "9": { - "AFTER_MEAL_TIME:30_MIN | male | POST_SURGERY_TIME:6MO | ROUX_EN_Y": "2" - }, - "10": { - "AFTER_MEAL_TIME:30_MIN | male | POST_SURGERY_TIME:NO_SURGERY | LEAN_CONTROL": "4" - }, - "11": { - "AFTER_MEAL_TIME:30_MIN | male | POST_SURGERY_TIME:PRE_SURGERY | GASTRIC_BAND": "2" - }, - "12": { - "AFTER_MEAL_TIME:30_MIN | male | POST_SURGERY_TIME:PRE_SURGERY | ROUX_EN_Y": "2" - }, - "13": { - "AFTER_MEAL_TIME:NO_WAIT | female | POST_SURGERY_TIME:12MO | GASTRIC_BAND": "3" - }, - "14": { - "AFTER_MEAL_TIME:NO_WAIT | female | POST_SURGERY_TIME:12MO | ROUX_EN_Y": "1" - }, - "15": { - "AFTER_MEAL_TIME:NO_WAIT | female | POST_SURGERY_TIME:6MO | GASTRIC_BAND": "4" - }, - "16": { - "AFTER_MEAL_TIME:NO_WAIT | female | POST_SURGERY_TIME:6MO | ROUX_EN_Y": "11" - }, - "17": { - "AFTER_MEAL_TIME:NO_WAIT | female | POST_SURGERY_TIME:NO_SURGERY | LEAN_CONTROL": "7" - }, - "18": { - "AFTER_MEAL_TIME:NO_WAIT | female | POST_SURGERY_TIME:PRE_SURGERY | GASTRIC_BAND": "7" - }, - "19": { - "AFTER_MEAL_TIME:NO_WAIT | female | POST_SURGERY_TIME:PRE_SURGERY | ROUX_EN_Y": "12" - }, - "20": { - "AFTER_MEAL_TIME:NO_WAIT | male | POST_SURGERY_TIME:12MO | GASTRIC_BAND": "2" - }, - "21": { - "AFTER_MEAL_TIME:NO_WAIT | male | POST_SURGERY_TIME:6MO | ROUX_EN_Y": "2" - }, - "22": { - "AFTER_MEAL_TIME:NO_WAIT | male | POST_SURGERY_TIME:NO_SURGERY | LEAN_CONTROL": "4" - }, - "23": { - "AFTER_MEAL_TIME:NO_WAIT | male | POST_SURGERY_TIME:PRE_SURGERY | GASTRIC_BAND": "2" - }, - "24": { - "AFTER_MEAL_TIME:NO_WAIT | male | POST_SURGERY_TIME:PRE_SURGERY | ROUX_EN_Y": "2" - } -} diff --git a/vignettes/structToolbox_example/0/www.metabolomicsworkbench.org/rest/study/analysis_id/AN000025/untarg_factors.json b/vignettes/structToolbox_example/0/www.metabolomicsworkbench.org/rest/study/analysis_id/AN000025/untarg_factors.json deleted file mode 100644 index 108df62..0000000 --- a/vignettes/structToolbox_example/0/www.metabolomicsworkbench.org/rest/study/analysis_id/AN000025/untarg_factors.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "1": { - "FCS:FCS | Hours:72 | REFED:NO_REFED | TGF:NO_TGF": "3" - }, - "2": { - "FCS:FCS | Hours:72 | REFED:NO_REFED | TGF:TGF": "3" - }, - "3": { - "FCS:NO_FCS | Hours:0 | REFED:NO_REFED | TGF:NO_TGF": "3" - }, - "4": { - "FCS:NO_FCS | Hours:12 | REFED:NO_REFED | TGF:NO_TGF": "3" - }, - "5": { - "FCS:NO_FCS | Hours:12 | REFED:NO_REFED | TGF:TGF": "3" - }, - "6": { - "FCS:NO_FCS | Hours:24 | REFED:NO_REFED | TGF:NO_TGF": "3" - }, - "7": { - "FCS:NO_FCS | Hours:24 | REFED:NO_REFED | TGF:TGF": "3" - }, - "8": { - "FCS:NO_FCS | Hours:2 | REFED:NO_REFED | TGF:NO_TGF": "3" - }, - "9": { - "FCS:NO_FCS | Hours:2 | REFED:NO_REFED | TGF:TGF": "3" - }, - "10": { - "FCS:NO_FCS | Hours:72 | REFED:NO_REFED | TGF:NO_TGF": "3" - }, - "11": { - "FCS:NO_FCS | Hours:72 | REFED:NO_REFED | TGF:TGF": "3" - }, - "12": { - "FCS:NO_FCS | Hours:72 | REFED:REFED_48 | TGF:NO_TGF": "3" - }, - "13": { - "FCS:NO_FCS | Hours:72 | REFED:REFED_48 | TGF:TGF": "3" - } -}