11
11
# ' @export
12
12
# '
13
13
# ' @examples
14
+
14
15
parsePeakAbundanceMatrixQF <- function (qfeatures ,
15
16
doPrecursorDeisotoping ,
16
17
mzDeviationInPPM_precursorDeisotoping ,
@@ -19,33 +20,36 @@ parsePeakAbundanceMatrixQF <- function(qfeatures,
19
20
progress = FALSE )
20
21
{
21
22
# # read file
22
-
23
23
if (! is.na(progress )) {
24
24
if (progress ) {
25
25
incProgress(amount = 0.1 , detail = paste(" Parsing MS1 file content..." , sep = " " ))
26
26
} else {
27
27
print(paste(" Parsing MS1 file content..." , sep = " " ))
28
28
}
29
29
}
30
+
31
+
32
+
30
33
31
34
cols_to_exclude <- c(" Reference RT" ," Reference m/z" ," Comment" ,
32
35
" Manually modified for quantification" ,
33
36
" Total score" ," RT similarity" ," Average" ," Stdev" )
34
37
35
38
cols_to_keep <- which(! colnames(rowData(qfeatures ))[[1 ]] %in% cols_to_exclude )
36
-
39
+
37
40
dataFrame <- cbind(rowData(qfeatures )[[1 ]][,cols_to_keep ] ,assay(qfeatures ))
38
-
39
- ncol(rowData(qfeatures )[[1 ]])
41
+ # workaround for avoiding change in colnames during coercion
42
+ cnames <- colnames(dataFrame )
43
+ dataFrame <- as.data.frame(dataFrame )
44
+ colnames(dataFrame ) <- cnames
45
+ oldFormat <- ncol(colData(qfeatures ))== 3
46
+ numRowDataCols <- ncol(rowData(qfeatures )[[1 ]])
47
+ dataColumnStartEndIndeces <- c(numRowDataCols + 1 ,ncol(dataFrame ))
40
48
numberOfPrecursors <- nrow(dataFrame )
41
49
numberOfPrecursorsPrior <- numberOfPrecursors
42
-
43
50
44
-
45
- if (nrow(colData(qfeatures ))> 0 ){
46
-
47
- dataColumnStartEndIndeces <- 1
48
- numberOfDataColumns <- nrow(colData(qfeatures ))
51
+ if (ncol(assay(qfeatures ))> 0 ){
52
+ numberOfDataColumns <- ncol(assay(qfeatures ))
49
53
sampleClass <- colData(qfeatures )$ Class
50
54
sampleType <- colData(qfeatures )$ Type
51
55
sampleInjectionOrder <- colData(qfeatures )$ " Injection order"
@@ -74,7 +78,7 @@ parsePeakAbundanceMatrixQF <- function(qfeatures,
74
78
75
79
# # replace -1 by 0
76
80
if (numberOfDataColumns > 0 ) {
77
- for (colIdx in dataColumnStartEndIndeces [[ 1 ]] : dataColumnStartEndIndeces [[ 2 ]] ){
81
+ for (colIdx in ( numRowDataCols + 1 ) : ncol( dataFrame ) ){
78
82
dataFrame [ , colIdx ] <- gsub(x = gsub(x = dataFrame [ , colIdx ], pattern = " \\ ." , replacement = " " ), pattern = " ," , replacement = " ." )
79
83
}
80
84
}
@@ -97,13 +101,13 @@ parsePeakAbundanceMatrixQF <- function(qfeatures,
97
101
98
102
# # replace -1 by 0
99
103
if (numberOfDataColumns > 0 ){
100
- for (colIdx in dataColumnStartEndIndeces [[ 1 ]] : dataColumnStartEndIndeces [[ 2 ]] ){
104
+ for (colIdx in ( numRowDataCols + 1 ) : ncol( dataFrame ) ){
101
105
dataFrame [ , colIdx ] <- as.numeric(dataFrame [ , colIdx ])
102
106
if (! is.na(sum(dataFrame [,colIdx ] == - 1 )))
103
107
dataFrame [(dataFrame [,colIdx ] == - 1 ),colIdx ] <- 0
104
108
}
105
109
}
106
-
110
+ vals <- NULL
107
111
# # deisotoping
108
112
numberOfRemovedIsotopePeaks <- 0
109
113
if (doPrecursorDeisotoping & ! is.null(dataFrame $ " Average Mz" )){
@@ -114,7 +118,7 @@ parsePeakAbundanceMatrixQF <- function(qfeatures,
114
118
precursorsToRemove <- vector(mode = " logical" , length = numberOfPrecursors )
115
119
116
120
if (numberOfDataColumns > 0 ){
117
- intensities <- dataFrame [ , dataColumnStartEndIndeces [[ 1 ]] : dataColumnStartEndIndeces [[ 2 ]] ]
121
+ intensities <- dataFrame [ , ( numRowDataCols + 1 ) : ncol( dataFrame ) ]
118
122
medians <- apply(X = as.matrix(intensities ), MARGIN = 1 , FUN = median )
119
123
}
120
124
@@ -139,21 +143,23 @@ parsePeakAbundanceMatrixQF <- function(qfeatures,
139
143
} else {
140
144
validPrecursorsInIntensity <- TRUE
141
145
}
142
-
146
+
143
147
if (any(validPrecursorsInRt & validPrecursorsInMz & validPrecursorsInIntensity ))
144
148
precursorsToRemove [[precursorIdx ]] <- TRUE
145
- }
146
149
150
+ }
151
+
147
152
# # remove isotopes
148
153
dataFrame <- dataFrame [! precursorsToRemove , ]
149
154
150
155
numberOfRemovedIsotopePeaks <- sum(precursorsToRemove )
151
156
numberOfPrecursors <- nrow(dataFrame )
152
157
}
153
-
158
+
154
159
if (! is.na(progress )) if (progress ) incProgress(amount = 0 , detail = paste(" Boxing..." , sep = " " )) else print(paste(" Boxing..." , sep = " " ))
155
160
returnObj <- list ()
156
161
returnObj $ dataFrame <- dataFrame
162
+ returnObj $ vals <- vals
157
163
158
164
# # meta
159
165
returnObj $ oldFormat <- oldFormat
0 commit comments