Skip to content

Commit

Permalink
seq kmer
Browse files Browse the repository at this point in the history
  • Loading branch information
dagou committed Jun 20, 2024
1 parent 62219dc commit 5ccdfd0
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions kr2r/src/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,34 +159,40 @@ pub fn count_values(

fn stat_hits(
hits: &OptionPair<HitGroup<Row>>,
cur_taxon_counts: &TaxonCountersDash,
counts: &mut HashMap<u32, u64>,
value_mask: usize,
taxonomy: &Taxonomy,
) -> (usize, String) {
) -> (usize, TaxonCountersDash, String) {
// let mut counts = HashMap::new();
let mut hit_count: usize = 0;

let cur_taxon_counts = TaxonCountersDash::new();
let hit_str = hits.apply(|group| {
let mut last_pos = 0;
let count = group.marker_size as u32;
let mut result = Vec::new();

let mut last_row: Row = Row::new(0, 0, 0);
// let mut last_row: Row = Row::new(0, 0, 0);
for row in &group.rows {
// 统计计数
let value = row.value;
let key = value.right(value_mask);
*counts.entry(key).or_insert(0) += 1;

if !(last_row.value == value && row.kmer_id - last_row.kmer_id == 1) {
cur_taxon_counts
.entry(key as u64)
.or_default()
.add_kmer(value as u64);
hit_count += 1;
}
last_row = *row;
// if !(last_row.value == value && row.kmer_id - last_row.kmer_id == 1) {
// cur_taxon_counts
// .entry(key as u64)
// .or_default()
// .add_kmer(value as u64);
// hit_count += 1;
// }

cur_taxon_counts
.entry(key as u64)
.or_default()
.add_kmer(value as u64);
hit_count += 1;
// last_row = *row;

let adjusted_pos = row.kmer_id - group.offset;

Expand Down Expand Up @@ -229,7 +235,7 @@ fn stat_hits(
});

let hit_string = hit_str.reduce_str(" |:| ", |str| str.to_owned());
(hit_count, hit_string)
(hit_count, cur_taxon_counts, hit_string)
}

pub fn process_hitgroup(
Expand All @@ -245,9 +251,15 @@ pub fn process_hitgroup(
let value_mask = hash_config.value_mask;

let mut counts = HashMap::new();
let (hit_groups, hit_string) =
stat_hits(hits, cur_taxon_counts, &mut counts, value_mask, taxonomy);
let (hit_groups, cur_counts, hit_string) = stat_hits(hits, &mut counts, value_mask, taxonomy);

cur_counts.iter().for_each(|entry| {
cur_taxon_counts
.entry(*entry.key())
.or_default()
.merge(entry.value())
.unwrap();
});
let mut call = resolve_tree(&counts, taxonomy, total_kmers, confidence_threshold);
if call > 0 && hit_groups < minimum_hit_groups {
call = 0;
Expand Down

0 comments on commit 5ccdfd0

Please sign in to comment.