@@ -79,39 +79,43 @@ sbcWrapper <- function(id, qcData, order, qcBatch, qcOrder, log=log, spar=spar,
79
79
batch = batch , minQC ) {
80
80
81
81
out <- tryCatch ({
82
- # Measurment order can be non consecutive numbers as well
83
- maxOrder <- length(order )
84
- newOrder <- seq_len(maxOrder )
82
+
83
+ # qc data for feature
85
84
subData <- qcData [id , ]
85
+
86
+ # unique batches
86
87
nbatch <- unique(qcBatch )
87
88
88
- outl <- matrix (nrow = maxOrder , ncol = length(nbatch ))
89
+ # preallocate output
90
+ outl <- numeric (length(order ))
89
91
92
+ # for each batch
90
93
for (nb in seq_len(length(nbatch ))) {
94
+ # get the injection order for the QCs
91
95
x <- qcOrder [qcBatch == nbatch [nb ]]
96
+ # get the response for the QCs
92
97
y <- subData [qcBatch == nbatch [nb ]]
98
+
99
+ # remove any index with NA in the response
93
100
NAhits <- which(is.na(y ))
94
101
95
102
if (length(NAhits ) > 0 ) {
96
103
x <- x [- c(NAhits )]
97
104
y <- y [- c(NAhits )]
98
105
}
99
106
107
+ # if we have enough QCs values
100
108
if (length(y ) > = minQC ) {
101
- outl [,nb ] <- splineSmoother(x = x , y = y , newX = newOrder , log = log ,
109
+ # fit spline to QCs and get predictions for all samples in batch
110
+ outl [batch == nbatch [nb ]] <- splineSmoother(x = x , y = y , newX = order [batch == nbatch [nb ]], log = log ,
102
111
a = 1 , spar = spar )
103
112
} else {
104
- outl [,nb ] <- rep(NA , maxOrder )
113
+ # otherwise replace with NA
114
+ outl [batch == nbatch [nb ]] = NA
105
115
}
106
116
}
107
117
108
- outp <- rep(NA , nrow(outl ))
109
- for (nb in seq_len(length(nbatch ))) {
110
- range <- c(batch == nbatch [nb ])
111
- outp [range ] <- outl [range , nb ]
112
- }
113
-
114
- outp
118
+ outp = outl
115
119
},
116
120
117
121
error = function (e ){
0 commit comments