Skip to content

Commit

Permalink
Merge branch 'ar/fix-percentile-rank' into 'master'
Browse files Browse the repository at this point in the history
[sample-probs] use correct formula for percentile rank.

See merge request machine-learning/modkit!205
  • Loading branch information
ArtRand committed Aug 15, 2024
2 parents 255464c + 521cf22 commit 9d65d2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/adjust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::mod_bam::{
};
use crate::mod_base_code::DnaBase;
use crate::threshold_mod_caller::MultipleThresholdModCaller;
use crate::util::{get_query_name_string, get_spinner, get_ticker};
use crate::util::{get_query_name_string, get_ticker};

pub fn adjust_mod_probs(
mut record: bam::Record,
Expand Down
20 changes: 12 additions & 8 deletions src/writers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ use std::fs::File;
use std::io::{BufWriter, Stdout, Write};
use std::path::{Path, PathBuf};

use crate::mod_base_code::{BaseState, DnaBase, ModCodeRepr, ProbHistogram};
use crate::pileup::duplex::DuplexModBasePileup;
use crate::pileup::{ModBasePileup, PartitionKey, PileupFeatureCounts};
use crate::summarize::ModSummary;
use crate::thresholds::Percentiles;
use anyhow::{anyhow, bail, Context, Result as AnyhowResult};
use charming::component::{
Axis, DataZoom, DataZoomType, Feature, Legend, Restore, SaveAsImage, Title,
Expand All @@ -25,6 +20,12 @@ use prettytable::format::FormatBuilder;
use prettytable::{row, Table};
use rustc_hash::FxHashMap;

use crate::mod_base_code::{BaseState, DnaBase, ModCodeRepr, ProbHistogram};
use crate::pileup::duplex::DuplexModBasePileup;
use crate::pileup::{ModBasePileup, PartitionKey, PileupFeatureCounts};
use crate::summarize::ModSummary;
use crate::thresholds::Percentiles;

pub trait PileupWriter<T> {
fn write(&mut self, item: T, motif_labels: &[String]) -> AnyhowResult<u64>;
}
Expand Down Expand Up @@ -830,10 +831,13 @@ impl ProbHistogram {
let (stats, _) = counts.iter().fold(
(BTreeMap::new(), 0f32),
|(mut acc, cum_sum), (b, c)| {
let f = *c as f32 / total;
let percentile_rank = cum_sum / total;
let n = *c as f32;
let f = n / total;
let cum_sum = cum_sum + n;
let percentile_rank =
((cum_sum - (0.5f32 * n)) / total) * 100f32;
acc.insert(*b, (*c, f, percentile_rank));
(acc, cum_sum + *c as f32)
(acc, cum_sum)
},
);

Expand Down

0 comments on commit 9d65d2a

Please sign in to comment.