Skip to content

Commit

Permalink
added grouping thresold
Browse files Browse the repository at this point in the history
  • Loading branch information
zargham-ahmad committed Jun 28, 2024
1 parent c1937cd commit 10e8f9f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions R/remove_noise.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ remove_noise <- function(filename,
baseline_correct_noise_percentile,
intensity_weighted,
do.plot,
cache) {
cache,
grouping_threshold = 0) {
raw.data <- load_file(filename)

raw.prof <- adaptive.bin(
Expand All @@ -87,10 +88,28 @@ remove_noise <- function(filename,
raw.prof$features$intensities,
raw.prof$features$grps
)

run.sel <- raw.prof$height.rec[which(raw.prof$height.rec[, 2] >= raw.prof$min.count.run * min_pres & raw.prof$height.rec[, 3] > baseline_correct), 1]

newprof <- newprof[newprof[, 4] %in% run.sel, ]

if (grouping_threshold > 0) {
sorted_newprof <- newprof[order(newprof[,2]),]
new_grps <- cumsum(c(0, diff(sorted_newprof[,2])) > grouping_threshold)
sorted_newprof <- cbind(sorted_newprof, new_grps, deparse.level = 0)

sorted_newprof_df <- tibble::as_tibble(sorted_newprof)

newprof <- as.matrix(sorted_newprof_df |>
dplyr::group_by(V4, V5) |>
dplyr::mutate(cluster = cur_group_id()) |>
dplyr::ungroup() |>
dplyr::arrange(cluster) |>
dplyr::select(-V4, -V5)
)
colnames(newprof) <- NULL
}

new.prof <- run_filter(
newprof,
min_pres = min_pres,
Expand Down

0 comments on commit 10e8f9f

Please sign in to comment.