Révision 3761ede2 src/R/nucleominer.R
b/src/R/nucleominer.R | ||
---|---|---|
153 | 153 |
nuc_width = 160, ##<< Nucleosome width. |
154 | 154 |
only_f = FALSE, ##<< Filter only F reads. |
155 | 155 |
only_r = FALSE, ##<< Filter only R reads. |
156 |
filter_for_coverage = FALSE, ##<< Does it filter for plot coverage? |
|
157 |
USE_DPLYR = TRUE ##<< Use dplyr lib to filter reads. |
|
156 |
filter_for_coverage = FALSE ##<< Does it filter for plot coverage? |
|
158 | 157 |
) { |
159 |
n = names(inputs) |
|
160 |
|
|
161 |
if (!USE_DPLYR) { |
|
162 |
if (only_f) { |
|
163 |
inputs_out = inputs[inputs[,1]==chr & inputs[,2] >= x_min - nuc_width & inputs[,3] == "F" & inputs[,2] <= x_max + nuc_width,] |
|
164 |
} else if (only_r) { |
|
165 |
inputs_out = inputs[inputs[,1]==chr & inputs[,2] >= x_min - nuc_width & inputs[,3] == "R" & inputs[,2] <= x_max + nuc_width,] |
|
166 |
} else { |
|
167 |
inputs_out = inputs[inputs[,1]==chr & inputs[,2] >= x_min - nuc_width & inputs[,2] <= x_max + nuc_width,] |
|
168 |
} |
|
169 |
} else { |
|
170 |
names(inputs) = c("chr", "pos", "str", "lev") |
|
171 |
if (only_f) { |
|
172 |
inputs_out = filter(inputs, chr == chr, pos >= x_min - nuc_width, str == "F", pos <= x_max + nuc_width) |
|
173 |
} else if (only_r) { |
|
174 |
inputs_out = filter(inputs, chr == chr, pos >= x_min - nuc_width, str == "R" & pos <= x_max + nuc_width) |
|
175 |
} else { |
|
176 |
inputs_out = filter(inputs, chr == chr, pos >= x_min - nuc_width, pos <= x_max + nuc_width) |
|
177 |
} |
|
178 |
# if (!filter_for_coverage) { |
|
179 |
# inputs$corrected_inputs_coords = inputs[,2] + nuc_width/2 * sign_from_strand(inputs[,3]) |
|
180 |
# inputs = filter(inputs, chr == chr, corrected_inputs_coords >= x_min, corrected_inputs_coords <= x_max) |
|
181 |
# inputs$corrected_inputs_coords = NULL |
|
182 |
# } |
|
183 |
} |
|
184 |
|
|
158 |
if (only_f) { |
|
159 |
inputs = inputs[inputs[,1]==chr & inputs[,2] >= x_min - nuc_width & inputs[,3] == "F" & inputs[,2] <= x_max + nuc_width,] |
|
160 |
} else if (only_r) { |
|
161 |
inputs = inputs[inputs[,1]==chr & inputs[,2] >= x_min - nuc_width & inputs[,3] == "R" & inputs[,2] <= x_max + nuc_width,] |
|
162 |
} else { |
|
163 |
inputs = inputs[inputs[,1]==chr & inputs[,2] >= x_min - nuc_width & inputs[,2] <= x_max + nuc_width,] |
|
164 |
} |
|
185 | 165 |
if (!filter_for_coverage) { |
186 |
corrected_inputs_coords = inputs_out[,2] + nuc_width/2 * sign_from_strand(inputs_out[,3])
|
|
187 |
inputs_out = inputs_out[inputs_out[,1]==chr & corrected_inputs_coords >= x_min & corrected_inputs_coords <= x_max,]
|
|
166 |
corrected_inputs_coords = inputs[,2] + nuc_width/2 * sign_from_strand(inputs[,3])
|
|
167 |
inputs = inputs[inputs[,1]==chr & corrected_inputs_coords >= x_min & corrected_inputs_coords <= x_max,]
|
|
188 | 168 |
} |
189 |
|
|
190 |
names(inputs_out) = n |
|
191 |
return(inputs_out) |
|
169 |
return(inputs) |
|
192 | 170 |
### Returns filtred inputs. |
193 | 171 |
} |
194 | 172 |
|
195 | 173 |
|
196 | 174 |
|
175 |
# filter_tf_inputs = function(# Filter TemplateFilter inputs |
|
176 |
# ### This function filters TemplateFilter inputs according genome area observed properties. It takes into account reads that are at the frontier of this area and the strand of these reads. |
|
177 |
# inputs, ##<< TF inputs to be filtered. |
|
178 |
# chr, ##<< Chromosome observed, here chr is an integer. |
|
179 |
# x_min, ##<< Coordinate of the first bp observed. |
|
180 |
# x_max, ##<< Coordinate of the last bp observed. |
|
181 |
# nuc_width = 160, ##<< Nucleosome width. |
|
182 |
# only_f = FALSE, ##<< Filter only F reads. |
|
183 |
# only_r = FALSE, ##<< Filter only R reads. |
|
184 |
# filter_for_coverage = FALSE, ##<< Does it filter for plot coverage? |
|
185 |
# USE_DPLYR = FALSE ##<< Use dplyr lib to filter reads. |
|
186 |
# ) { |
|
187 |
# n = names(inputs) |
|
188 |
# |
|
189 |
# if (!USE_DPLYR) { |
|
190 |
# if (only_f) { |
|
191 |
# inputs_out = inputs[inputs[,1]==chr & inputs[,2] >= x_min - nuc_width & inputs[,3] == "F" & inputs[,2] <= x_max + nuc_width,] |
|
192 |
# } else if (only_r) { |
|
193 |
# inputs_out = inputs[inputs[,1]==chr & inputs[,2] >= x_min - nuc_width & inputs[,3] == "R" & inputs[,2] <= x_max + nuc_width,] |
|
194 |
# } else { |
|
195 |
# inputs_out = inputs[inputs[,1]==chr & inputs[,2] >= x_min - nuc_width & inputs[,2] <= x_max + nuc_width,] |
|
196 |
# } |
|
197 |
# } else { |
|
198 |
# names(inputs) = c("chr", "pos", "str", "lev") |
|
199 |
# if (only_f) { |
|
200 |
# inputs_out = filter(inputs, chr == chr, pos >= x_min - nuc_width, str == "F", pos <= x_max + nuc_width) |
|
201 |
# } else if (only_r) { |
|
202 |
# inputs_out = filter(inputs, chr == chr, pos >= x_min - nuc_width, str == "R" & pos <= x_max + nuc_width) |
|
203 |
# } else { |
|
204 |
# inputs_out = filter(inputs, chr == chr, pos >= x_min - nuc_width, pos <= x_max + nuc_width) |
|
205 |
# } |
|
206 |
# # if (!filter_for_coverage) { |
|
207 |
# # inputs$corrected_inputs_coords = inputs[,2] + nuc_width/2 * sign_from_strand(inputs[,3]) |
|
208 |
# # inputs = filter(inputs, chr == chr, corrected_inputs_coords >= x_min, corrected_inputs_coords <= x_max) |
|
209 |
# # inputs$corrected_inputs_coords = NULL |
|
210 |
# # } |
|
211 |
# } |
|
212 |
# |
|
213 |
# if (!filter_for_coverage) { |
|
214 |
# corrected_inputs_coords = inputs_out[,2] + nuc_width/2 * sign_from_strand(inputs_out[,3]) |
|
215 |
# inputs_out = inputs_out[inputs_out[,1]==chr & corrected_inputs_coords >= x_min & corrected_inputs_coords <= x_max,] |
|
216 |
# } |
|
217 |
# |
|
218 |
# names(inputs_out) = n |
|
219 |
# return(inputs_out) |
|
220 |
# ### Returns filtred inputs. |
|
221 |
# } |
|
222 |
|
|
223 |
|
|
224 |
|
|
197 | 225 |
get_comp_strand = function( |
198 | 226 |
### Compute the complementatry strand. |
199 | 227 |
strand ##<< The original strand. |
Formats disponibles : Unified diff