-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload-maldiquant-species.R
49 lines (32 loc) · 1.25 KB
/
load-maldiquant-species.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
library("MALDIquant")
library("MALDIquantForeign")
library("MALDIquantExamples")
spectra <- import(getPathSpecies(), verbose = FALSE)
spectra <- trim(spectra)
set.seed(2019)
spectra <- transformIntensity(spectra, method = "sqrt")
spectra <-
smoothIntensity(spectra, method = "SavitzkyGolay", halfWindowSize = 10)
spectra <- removeBaseline(spectra, method = "SNIP", iterations = 25)
spectra <- calibrateIntensity(spectra, method = "TIC")
spectra <- alignSpectra(spectra)
metaData(spectra[[1]])$spot
spots <- sapply(spectra, function(x)
metaData(x)$spot)
species <- sapply(spectra, function(x)
metaData(x)$sampleName)
avgSpectra <-
averageMassSpectra(spectra, labels = paste0(species, spots))
peaks <- detectPeaks(avgSpectra, SNR = 2, halfWindowSize = 10)
peaks.binned <- binPeaks(peaks)
peaks.binned.filtered <-
filterPeaks(peaks.binned, minFrequency = 0.25)
spots <- sapply(avgSpectra, function(x)
metaData(x)$spot)
species <- sapply(avgSpectra, function(x)
metaData(x)$sampleName)
species <- factor(species)
#binnedPeaksMatrix <- intensityMatrix(peaks.binned.filtered, avgSpectra)
binnedPeaksMatrix <- intensityMatrix(peaks.binned.filtered)
rownames(binnedPeaksMatrix) <- paste(species, spots, sep = ".")
binnedPeaksMatrix.conditions <- species