Skip to content

Commit

Permalink
add bimodal marker warning
Browse files Browse the repository at this point in the history
  • Loading branch information
yezhengSTAT authored and yezhengSTAT committed May 28, 2024
1 parent 746c184 commit fd5911b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions R/get_peak_midpoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ get_peak_midpoint = function(cell_x_adt = NULL, cell_x_feature = NULL, adt_marke
peak_mode = list()
peak_region = list()

bimodal_marker_index_original = bimodal_marker_index
for(sample_name in sample_name_list){
bimodal_marker_index = bimodal_marker_index_original
## extract the ADT counts for this sample
cell_ind_tmp = which(cell_x_feature$sample == sample_name)
cell_notNA = which(!is.na(cell_x_adt[cell_ind_tmp, adt_marker_select]))
Expand Down Expand Up @@ -80,6 +82,10 @@ get_peak_midpoint = function(cell_x_adt = NULL, cell_x_feature = NULL, adt_marke
## if most are around 0 and there are very few unique value: add random small number
if(zero_prop > 0.95){
if(length(unique(adt_expression)) < 50){
if(adt_marker_index %in% bimodal_marker_index){
print(paste0("This marker only has ", length(unique(adt_expression)), " unique values and the near-zero proportion is ", zero_prop, ". It is highly likely not a bimodal marker. Excluded from 'bimodal_marker' list."))
bimodal_marker_index = bimodal_marker_index[!bimodal_marker_index %in% adt_marker_index]
}
adt_expression = adt_expression + stats::rnorm(length(adt_expression), mean = 0, sd = 0.05)
# exprs(dat[[sample_name]])[, adt_marker_select] = adt_expression
}
Expand Down
11 changes: 10 additions & 1 deletion R/get_peak_mode.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ get_peak_mode = function(cell_x_adt = NULL, cell_x_feature = NULL, adt_marker_se
peak_num = 0
peak_mode = list()
peak_region = list()


bimodal_marker_index_original = bimodal_marker_index
for(sample_name in sample_name_list){

bimodal_marker_index = bimodal_marker_index_original

## extract the ADT counts for this sample
cell_ind_tmp = which(cell_x_feature$sample == sample_name)
cell_notNA = which(!is.na(cell_x_adt[cell_ind_tmp, adt_marker_select]))
Expand Down Expand Up @@ -75,8 +79,13 @@ get_peak_mode = function(cell_x_adt = NULL, cell_x_feature = NULL, adt_marker_se
## if most are around 0 and there are very few unique value: add random small number
if(zero_prop >= 0.95){
if(length(unique(adt_expression)) < 50){
if(adt_marker_index %in% bimodal_marker_index){
print(paste0("This marker only has ", length(unique(adt_expression)), " unique values and the near-zero proportion is ", zero_prop, ". It is highly likely not a bimodal marker. Excluded from 'bimodal_marker' list."))
bimodal_marker_index = bimodal_marker_index[!bimodal_marker_index %in% adt_marker_index]
}
adt_expression = adt_expression + stats::rnorm(length(adt_expression), mean = 0, sd = 0.05)
# exprs(dat[[sample_name]])[, adt_marker_select] = adt_expression

}
}
fres1 = flowCore::filter(fcs, flowStats::curv1Filter(adt_marker_select, bwFac = max(2, bwFac_smallest)))
Expand Down

0 comments on commit fd5911b

Please sign in to comment.