diff --git a/R/Risa-ms.R b/R/Risa-ms.R index dcf82bc..926c391 100644 --- a/R/Risa-ms.R +++ b/R/Risa-ms.R @@ -3,41 +3,39 @@ ### specific function to deal with assays whose technology type is mass spectrometry using the xcms package ### it returns an xcmsSet processAssayXcmsSet.1factor = function(isa, assay.filename, ...){ - for(i in seq_len(length(isa["assay.filenames"]))){ + + i <- which(isa["assay.filenames"]==assay.filename) + + if (isatab.syntax$raw.spectral.data.file %in% colnames(isa["data.filenames"][[i]])) + { + #mass spectrometry files + msfiles = isa["data.filenames"][[i]][[ isatab.syntax$raw.spectral.data.file ]] + + pd = try(read.AnnotatedDataFrame(file.path(isa["path"], isa["assay.filenames"][i]), + row.names = NULL, blank.lines.skip = TRUE, fill = TRUE, + varMetadata.char = "$", quote="\"")) + + sampleNames(pd) = pd$Raw.Spectral.Data.File - if (isa["assay.filenames"][[i]]==assay.filename){ + if (length(grep(isatab.syntax$factor.value, colnames(isa["assay.files"][[i]]))) != 0) { + ## If there are explicit factors, use them + sclass = isa["assay.files"][[i]][ which(isa["assay.files"][[i]][[isatab.syntax$sample.name]] %in% pd$Sample.Name), grep(isatab.syntax$factor.value, colnames(isa["assay.files"][[i]]))[1]] - if (isatab.syntax$raw.spectral.data.file %in% colnames(isa["data.filenames"][[i]])) - { - #mass spectrometry files - msfiles = isa["data.filenames"][[i]][[ isatab.syntax$raw.spectral.data.file ]] - - pd = try(read.AnnotatedDataFrame(file.path(isa["path"], isa["assay.filenames"][i]), - row.names = NULL, blank.lines.skip = TRUE, fill = TRUE, - varMetadata.char = "$", quote="\"")) - - sampleNames(pd) = pd$Raw.Spectral.Data.File - - if (length(grep("Factor.Value", colnames(isa["assay.files"][[i]]))) != 0) { - ## If there are explicit factors, use them - sclass = isa["assay.files"][[i]][ which(isa["assay.files"][[i]][[isatab.syntax$sample.name]] %in% pd$Sample.Name), grep("Factor.Value", colnames(isa["assay.files"][[i]]))[1]] - - wd <- getwd() - setwd(isa["path"]) - xset = xcmsSet(files=msfiles, sclass=sclass, ...) - setwd(wd) - } else { - wd <- getwd() - setwd(isa["path"]) - ## Otherwise just use what was there - xset = try(xcmsSet(msfiles, phenoData=pData(pd), ...)) - setwd(wd) - } - return(xset) - }#if + wd <- getwd() + setwd(isa["path"]) + xset = xcmsSet(files=msfiles, sclass=sclass, ...) + setwd(wd) - }#if - }#for + } else { + wd <- getwd() + setwd(isa["path"]) + ## Otherwise just use what was there + xset = try(xcmsSet(msfiles, phenoData=pData(pd), ...)) + setwd(wd) + } + return(xset) + }#if + }#processAssayXcmsSet @@ -50,41 +48,39 @@ processAssayXcmsSet = function(isa, assay.filename, ...){ phenodata.data.frame <- as.data.frame(isa["factors"]) + assay.names <- isa["assay.names"][assay.filename] + row.names(phenodata.data.frame) <- assay.names[[assay.filename]][[1]] - for(i in seq_len(length(isa["assay.filenames"]))){ + i <- which(isa["assay.filenames"]==assay.filename) + + if (isatab.syntax$raw.spectral.data.file %in% colnames(isa["data.filenames"][[i]])) + { + #mass spectrometry files + msfiles = isa["data.filenames"][[i]][[ isatab.syntax$raw.spectral.data.file ]] + + pd = try(read.AnnotatedDataFrame(file.path(isa["path"], isa["assay.filenames"][i]), + row.names = NULL, blank.lines.skip = TRUE, fill = TRUE, + varMetadata.char = "$", quote="\"")) + + sampleNames(pd) = pd$Raw.Spectral.Data.File - if (isa["assay.filenames"][[i]]==assay.filename){ + if (length(grep(isatab.syntax$factor.value, colnames(isa["assay.files"][[i]]))) != 0) { + ## If there are explicit factors, use them + sclass = isa["assay.files"][[i]][ which(isa["assay.files"][[i]][[isatab.syntax$sample.name]] %in% pd$Sample.Name), grep(isatab.syntax$factor.value, colnames(isa["assay.files"][[i]]))[1]] - if (isatab.syntax$raw.spectral.data.file %in% colnames(isa["data.filenames"][[i]])) - { - #mass spectrometry files - msfiles = isa["data.filenames"][[i]][[ isatab.syntax$raw.spectral.data.file ]] - - pd = try(read.AnnotatedDataFrame(file.path(isa["path"], isa["assay.filenames"][i]), - row.names = NULL, blank.lines.skip = TRUE, fill = TRUE, - varMetadata.char = "$", quote="\"")) - - sampleNames(pd) = pd$Raw.Spectral.Data.File - - if (length(grep("Factor.Value", colnames(isa["assay.files"][[i]]))) != 0) { - ## If there are explicit factors, use them - sclass = isa["assay.files"][[i]][ which(isa["assay.files"][[i]][[isatab.syntax$sample.name]] %in% pd$Sample.Name), grep("Factor.Value", colnames(isa["assay.files"][[i]]))[1]] - - wd <- getwd() - setwd(isa["path"]) - xset = xcmsSet(files=msfiles, sclass=sclass, ...) - setwd(wd) - } else { - wd <- getwd() - setwd(isa["path"]) - ## Otherwise just use what was there - xset = try(xcmsSet(msfiles, phenoData=pData(pd), ...)) - setwd(wd) - } - return(xset) - }#if + wd <- getwd() + setwd(isa["path"]) + xset = xcmsSet(files=msfiles, sclass=sclass, ...) + setwd(wd) - }#if - }#for + } else { + wd <- getwd() + setwd(isa["path"]) + ## Otherwise just use what was there + xset = try(xcmsSet(msfiles, phenoData=pData(pd), ...)) + setwd(wd) + } + return(xset) + }#if }#processAssayXcmsSet \ No newline at end of file diff --git a/R/Risa.R b/R/Risa.R index 3b1b51e..f24d819 100755 --- a/R/Risa.R +++ b/R/Risa.R @@ -17,6 +17,7 @@ isatab.syntax <- list( array.data.file="Array Data File", raw.spectral.data.file="Raw Spectral Data File", factor.name="Factor Name", + factor.value="Factor Value", assay.name="Assay Name" )