forked from ISA-tools/Risa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Risa-ms.R
83 lines (62 loc) · 3.07 KB
/
Risa-ms.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
### Methods to deal with assays whose technology type is mass spectrometry
### 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, ...){
i <- which(isa["assay.filenames"]==assay.filename)
#if 'Raw Spectral Data File' is one of the columns in the assay file = it is a mass spectrometry assay
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 ]]
#the assay file as an AnnotatedDataFrame
pd = try(read.AnnotatedDataFrame(file.path(isa["path"], isa["assay.filenames"][i]),
row.names = NULL, blank.lines.skip = TRUE, fill = TRUE,
varMetadata.char = "$", quote="\""))
#Adding the raw spectral data files as the row names
sampleNames(pd) = pd$Raw.Spectral.Data.File
if (length(grep(isatab.syntax$factor.value, colnames(isa["assay.files"][[i]]))) != 0) {
## If there are explicit factors, use the first of 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]]
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
}#processAssayXcmsSet
### specific function to deal with assays whose technology type is mass spectrometry using the xcms package
### it returns an xcmsSet,
processAssayXcmsSet = function(isa, assay.filename, ...){
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 (length(grep(isatab.syntax$factor.value, colnames(isa["assay.files"][[i]]))) != 0) {
## If there are explicit factors, use them
sclass <- as.data.frame(isa["factors"])
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
}#processAssayXcmsSet