17
17
# ' found back in \code{colnames(flowCore::exprs(ff))}. If a channel is not
18
18
# ' listed in this parameter, its default internal values will be used. The
19
19
# ' default of this parameter is NULL.
20
+ # ' @param remove_min The channel indices or channel names that have to be checked
21
+ # ' for minimum margins. The default of this parameter is channels.
22
+ # ' @param remove_max The channel indices or channel names that have to be checked
23
+ # ' for maximum margins. The default of this parameter is channels.
20
24
# ' @param output If set to "full", a list with the filtered flowframe and the
21
25
# ' indices of the margin event is returned. If set to "frame", only the
22
26
# ' filtered flowframe is returned. The default is "frame".
@@ -54,7 +58,9 @@ RemoveMargins <- function(
54
58
ff ,
55
59
channels ,
56
60
channel_specifications = NULL ,
57
- output = " frame" ) {
61
+ output = " frame" ,
62
+ remove_min = channels ,
63
+ remove_max = channels ) {
58
64
59
65
if (! is(ff , " flowFrame" ))
60
66
stop(" ff should be a flowframe." )
@@ -96,11 +102,21 @@ RemoveMargins <- function(
96
102
channels <- colnames(flowCore :: exprs(ff ))[channels ]
97
103
}
98
104
# Make selection
105
+ margin_matrix <- matrix (nrow = length(channels ), ncol = 2 , dimnames = list (channels , c(" min" , " max" )))
99
106
for (d in channels ) {
100
107
101
- selection <- selection &
102
- e [, d ] > max(min(meta [d , " minRange" ], 0 ), min(e [, d ])) &
103
- e [, d ] < min(meta [d , " maxRange" ], max(e [, d ]))
108
+ if (d %in% remove_min ){
109
+ min_margin_ev <- e [, d ] < = max(min(meta [d , " minRange" ], 0 ), min(e [, d ]))
110
+ margin_matrix [d , " min" ] <- sum(min_margin_ev )
111
+ selection <- selection & ! min_margin_ev
112
+ }
113
+ if (d %in% remove_max ){
114
+ max_margin_ev <- e [, d ] > min(meta [d , " maxRange" ], max(e [, d ]))
115
+ margin_matrix [d , " max" ] <- sum(max_margin_ev )
116
+ selection <- selection & ! max_margin_ev
117
+
118
+ }
119
+
104
120
}
105
121
106
122
if ((length(flowCore :: keyword(ff )$ FILENAME ) > 0 ) &&
@@ -120,6 +136,7 @@ RemoveMargins <- function(
120
136
}
121
137
122
138
new_ff <- ff [selection , ]
139
+ attr(new_ff , " margin_matrix" ) <- margin_matrix
123
140
if (! (" Original_ID" %in% colnames(flowCore :: exprs(new_ff )))){
124
141
new_ff <- AppendCellID(new_ff , which(selection ))}
125
142
if (output == " full" ){
0 commit comments