@@ -31,17 +31,27 @@ logFit <- function (x, a=1, inverse=FALSE) {
31
31
# #' @param spar Smoothing parameter of the fitted curve. Should be in the range
32
32
# #'0 to 1. If set to 0 it will be estimated using leave-one-out
33
33
# #'cross-validation.
34
+ # #' @param spar_lim A 2 element numeric vector containing the min and max
35
+ # #'values of spar when searching for an optimum. Default \code{spar_lim = c(-1.5,1.5)}
34
36
# #' @return vector of cubic smoothing spline fitted values
35
37
# #' @noRd
36
38
37
- splineSmoother <- function (x , y , newX , log = log , a = 1 , spar ) {
39
+ splineSmoother <- function (x , y , newX , log = log , a = 1 , spar ,
40
+ spar_lim = c(- 1.5 ,1.5 )) {
38
41
if (log == TRUE ) {
39
42
y <- logFit(y , a = a )
40
43
}
44
+
45
+ control.spar = list (
46
+ low = spar_lim [1 ],
47
+ high = spar_lim [2 ]
48
+ )
49
+
41
50
if (spar == 0 ) {
42
51
# Supress spline fitting CV messages cluttering terminal output
43
52
smoothSplineMessages <- capture.output(sp.obj
44
- <- smooth.spline(x , y , cv = TRUE ), file = NULL , type = " message" )
53
+ <- smooth.spline(x , y , cv = TRUE ,control.spar = control.spar ),
54
+ file = NULL , type = " message" )
45
55
} else {
46
56
smoothSplineMessages <- character ()
47
57
sp.obj <- smooth.spline(x , y , spar = spar )
@@ -72,11 +82,13 @@ splineSmoother <- function(x, y, newX, log=log, a=1, spar) {
72
82
# #' @param minQC Minimum number of QC samples required for signal correction.
73
83
# #' @param order A numeric vector indicating the order in which samples
74
84
# #'were measured.
85
+ # #' @param spar_lim A 2 element numeric vector containing the min and max
86
+ # #'values of spar when searching for an optimum. Default \code{spar_lim = c(-1.5,1.5)}
75
87
# #' @return vector of corrected values of selected feature for QC data
76
88
# #' @noRd
77
89
78
90
sbcWrapper <- function (id , qcData , order , qcBatch , qcOrder , log = log , spar = spar ,
79
- batch = batch , minQC ) {
91
+ batch = batch , minQC , spar_lim = c( - 1.5 , 1.5 ) ) {
80
92
81
93
out <- tryCatch ({
82
94
@@ -108,7 +120,7 @@ sbcWrapper <- function(id, qcData, order, qcBatch, qcOrder, log=log, spar=spar,
108
120
if (length(y ) > = minQC ) {
109
121
# fit spline to QCs and get predictions for all samples in batch
110
122
outl [batch == nbatch [nb ]] <- splineSmoother(x = x , y = y , newX = order [batch == nbatch [nb ]], log = log ,
111
- a = 1 , spar = spar )
123
+ a = 1 , spar = spar , spar_lim = spar_lim )
112
124
} else {
113
125
# otherwise replace with NA
114
126
outl [batch == nbatch [nb ]] = NA
0 commit comments