Skip to content

Commit

Permalink
small bonus
Browse files Browse the repository at this point in the history
  • Loading branch information
ACEnglish committed Feb 4, 2024
1 parent 07824aa commit 8db1db0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
1 change: 1 addition & 0 deletions trust/confirm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
truvari.entry_is_filtered(entry),
round(truvari.entry_seq_similarity(up_record, entry), 7),
))
x.build_match(up_record, entry)
up_record = entry

b = time.time()
Expand Down
8 changes: 5 additions & 3 deletions trust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ fn main() {
.build_from_path("sample.vcf.gz")
.expect("Unable to parse vcf");
let header = reader.read_header().expect("Unable to parse header");
let mut mmatch1 = matching::MatchResult::new();
let mut mmatch1 = matching::MatchResult{ ..Default::default() };
mmatch1.base_gt_count = 4;
mmatch1.score = Some(4.0);
let mut mmatch2 = matching::MatchResult::new();
let mut mmatch2 = matching::MatchResult{ ..Default::default() };
mmatch2.score = Some(5.0);
let mut mmatch3 = matching::MatchResult::new();
let mut mmatch3 = matching::MatchResult{ ..Default::default() };
mmatch3.state = true;
let mut parts = vec![mmatch1, mmatch2, mmatch3];
parts.sort();
Expand Down Expand Up @@ -48,6 +48,8 @@ fn main() {
comparisons::entry_is_filtered(&dn_record),
comparisons::entry_seq_similarity(&up_record, &dn_record),
);
let x = mat.build_match(&up_record, &dn_record, Some("".to_string()), false, false);
println!("{:?}", x);
up_record = dn_record;
}
}
54 changes: 48 additions & 6 deletions trust/src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ pub struct MatchResult {
pub seqsim: Option<f32>,
pub sizesim: Option<f32>,
pub ovlpct: Option<f32>,
pub sizediff: Option<i64>,
pub st_dist: Option<i64>,
pub ed_dist: Option<i64>,
pub sizediff: Option<isize>,
pub st_dist: Option<isize>,
pub ed_dist: Option<isize>,
pub gt_match: Option<bool>,
pub multi: Option<bool>,
pub score: Option<f32>,
pub matid: Option<String>,
}

impl MatchResult {
pub fn new() -> Self {
impl Default for MatchResult {
fn default() -> MatchResult {
MatchResult {
base: None,
comp: None,
base_gt: None,
base_gt_count: 0,
comp_gt: None,
comp_gt_count: 0,
state: false,
state: true,
seqsim: None,
sizesim: None,
ovlpct: None,
Expand All @@ -46,7 +46,9 @@ impl MatchResult {
matid: None,
}
}
}

impl MatchResult {
pub fn calc_score(mut self) {
self.score = match (self.seqsim, self.sizesim, self.ovlpct) {
(Some(seq), Some(size), Some(ovl)) => Some((seq + size + ovl) / 3.0 * 100.0),
Expand Down Expand Up @@ -179,6 +181,46 @@ impl Matcher {

false
}

pub fn build_match(&self, base: &vcf::Record, comp: &vcf::Record, matid: Option<String>, skip_gt: bool, short_circuit: bool) -> MatchResult {
let mut ret = MatchResult { base: Some(base.clone()), comp: Some(comp.clone()), matid: matid, ..Default::default() };

if !self.params.typeignore & !comparisons::entry_same_variant_type(base, comp, self.params.dup_to_ins) {
ret.state = false;
if short_circuit {
return ret
}
}

// Don't want to call this twice, but also might want to add in insertion inflation...
// Revisit after the alpha
let (bstart, bend) = comparisons::entry_boundaries(base, false);
let (cstart, cend) = comparisons::entry_boundaries(comp, false);
// PctOvl...?
if !comparisons::overlaps(bstart - self.params.refdist, bend + self.params.refdist, cstart, cend) {
ret.state = false;
if short_circuit {
return ret
}
}

let (szsim, szdiff) =comparisons::entry_size_similarity(base, comp);
ret.sizesim = Some(szsim);
ret.sizediff = Some(szdiff);
if ret.sizesim < Some(self.params.pctsize) {
ret.state = false;
if short_circuit {
return ret
}
}

//if !skip_gt {
//ret.base_gt = Some(comp
//}

return ret

}
}
//check_monref and alts is None
//# check_multi and
Expand Down

0 comments on commit 8db1db0

Please sign in to comment.