1 | Parse(x)
|
x |
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 84 85 86 87 88 89 90 91 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (x)
{
pos1 <- which(x == "[Header]")
pos2 <- which(x == "[File Information]")
pos3 <- which(x == "[Sample Information]")
pos4 <- which(x == "[MC Peak Table]")
pos5 <- which(x == "[Spectrum Process Table]")
pos6 <- which(x == "[MS Similarity Search Results for Spectrum Process Table]")
pos7 <- which(x == "[MS Chromatogram]")
pos8 <- which(x == "[MS Spectrum]")
header = vector()
for (i in 1:length(x)) {
if (i < pos2) {
header <- rbind(header, x[i])
}
}
SamInfo <- vector()
for (i in 1:length(x)) {
if ((i >= pos3) && (i < pos4)) {
SamInfo <- rbind(SamInfo, x[i])
}
}
PeakTable <- vector()
for (i in 1:length(x)) {
if ((i >= pos4) && (i < pos5)) {
PeakTable <- rbind(PeakTable, x[i])
PeakTable <- gsub("\t", " ", PeakTable)
}
}
TotalPeak <- PeakTable[2, ]
peaks <- PeakTable[-c(1:3), ]
peaks <- strsplit(peaks, " ", fixed = FALSE)
peaks <- t(sapply(peaks, "[", 1:max(sapply(peaks, length))))
colnames(peaks) <- peaks[1, ]
peaks <- peaks[-1, ]
peaks <- peaks[, -c(12:13)]
peaks <- data.frame(peaks)
Spectrum <- vector()
for (i in 1:length(x)) {
if ((i >= pos5) && (i < pos6)) {
Spectrum <- rbind(Spectrum, x[i])
}
}
Annotation <- vector()
for (i in 1:length(x)) {
if ((i >= pos6) && (i < pos7)) {
Annotation <- rbind(Annotation, x[i])
Annotation <- gsub("\t", " ", Annotation)
}
}
Chromatogram <- vector()
for (i in 1:length(x)) {
if ((i >= pos7) && (i < pos8[1])) {
Chromatogram <- rbind(Chromatogram, x[i])
}
}
y <- Chromatogram[-c(1:6), ]
y <- gsub("\t", " ", y)
y <- strsplit(y, " ", fixed = FALSE)
y <- t(sapply(y, "[", 1:max(sapply(y, length))))
colnames(y) <- y[1, ]
y <- y[-1, ]
y <- data.frame(y)
MsSpectrum <- vector()
for (i in 1:length(x)) {
if (i >= pos8) {
MsSpectrum <- rbind(MsSpectrum, x[i])
}
}
AllSpectrum <- split(MsSpectrum, cumsum(MsSpectrum[, 1] ==
"[MS Spectrum]"))
zz <- lapply(AllSpectrum, extract)
data <- peaks[, 1:4]
data <- na.omit(data)
total <- lapply(zz, FinalTable)
total <- t(sapply(total, "[", 1:max(sapply(total, length))))
tt <- cbind(data, total)
tt <- as.matrix(tt)
colnames(tt) <- c("Peaks", "RT", "StartRT", "EndRT", "MSPeaks",
"MZ", "TIC")
tt <- gsub("m/z", "", tt)
tt <- gsub("\\(.*)", "", tt)
tt <- data.frame(tt)
new("parse.Shimadzu", McPeakTable = peaks, Annotation = Annotation,
GasChromatogram = y, MassSpectrum = zz, FinalTable = tt)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.