Skip to content

Commit

Permalink
actual fix dna validation; almost there
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegenes committed Dec 12, 2024
1 parent 1a0c29f commit 82ff63e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/core/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl ReadingFrame {
ReadingFrame::DNA { fw, rc, len }
}

// TODO -- handle bad DNA sequence here??
pub fn new_protein(sequence: &[u8], dayhoff: bool, hp: bool) -> Self {
let fw: Vec<u8> = if dayhoff {
sequence.iter().map(|&aa| aa_to_dayhoff(aa)).collect()
Expand Down Expand Up @@ -417,13 +418,13 @@ impl SeqToHashes {
}

/// Process a DNA k-mer, including canonicalization and validation
fn dna_hash(&self, frame: &ReadingFrame) -> Result<Option<u64>, Error> {
fn dna_hash(&self, frame: &ReadingFrame) -> Result<u64, Error> {
let kmer = &frame.fw()[self.kmer_index..self.kmer_index + self.k_size];
let rc = frame.rc();

// Validate the k-mer. Skip if invalid and force is true
match self.validate_dna_kmer(kmer)? {

Check failure on line 426 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / Lints (stable)

you seem to be trying to use `match` for an equality check. Consider using `if`

Check failure on line 426 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / Lints (beta)

you seem to be trying to use `match` for an equality check. Consider using `if`
false => return Ok(None), // Skip this k-mer
false => return Ok(0), // Skip this k-mer
true => {}
}

Expand All @@ -434,7 +435,7 @@ impl SeqToHashes {
let canonical_kmer = std::cmp::min(kmer, krc);
let hash = crate::_hash_murmur(canonical_kmer, self.seed);

Ok(Some(hash))
Ok(hash)
}

fn protein_hash(&self, frame: &ReadingFrame) -> u64 {
Expand All @@ -460,12 +461,7 @@ impl Iterator for SeqToHashes {
// Delegate to DNA or protein processing
let result = match frame {
ReadingFrame::DNA { .. } => match self.dna_hash(frame) {
Ok(Some(hash)) => Ok(hash), // Valid hash
Ok(None) => {
// Skipped invalid k-mer
self.kmer_index += 1;
continue;
}
Ok(hash) => Ok(hash), // Valid hash
Err(err) => Err(err), // Error
},
ReadingFrame::Protein { .. } => Ok(self.protein_hash(frame)),
Expand Down

0 comments on commit 82ff63e

Please sign in to comment.