Skip to content

Commit

Permalink
fixing simple things like removing unused code and imports before I t…
Browse files Browse the repository at this point in the history
…ry to merge encode/decode kmers and reverse_comp between the ska and skalo code
  • Loading branch information
jhellewell14 committed Jan 28, 2025
1 parent 5f9ace1 commit 9e4ccf4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 98 deletions.
1 change: 1 addition & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ pub enum Commands {
#[arg(long, default_value_t = DEFAULT_STRAND)]
single_strand: bool,
},
/// Finds 'left out' SNPs and INDELs using a graph
Lo {
/// input SKA2 file
#[arg(short = 'i', long, help_heading = "input")]
Expand Down
6 changes: 3 additions & 3 deletions src/ska_dict/bit_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub trait UInt<'a>:
fn hash_val(self, hash_fn: &RandomState) -> u64;
}

impl<'a> UInt<'a> for u64 {
impl UInt<'_> for u64 {
#[inline(always)]
fn rev_comp(mut self, k_size: usize) -> Self {
// This part reverses the bases by shuffling them using an on/off pattern
Expand Down Expand Up @@ -327,7 +327,7 @@ impl<'a> UInt<'a> for u64 {
}
}

impl<'a> UInt<'a> for u128 {
impl UInt<'_> for u128 {
#[inline(always)]
fn rev_comp(mut self, k_size: usize) -> u128 {
// This part reverses the bases by shuffling them using an on/off pattern
Expand Down Expand Up @@ -397,7 +397,7 @@ impl<'a> UInt<'a> for u128 {
result = (result << 2) | (nucleotide_to_bits[index] as Self);
}

result
result as Self
}

#[inline(always)]
Expand Down
95 changes: 0 additions & 95 deletions src/skalo/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,101 +36,6 @@ pub fn rev_compl(seq: &str) -> String {
complemented_seq
}

// pub fn rev_compl_u128(kmer: u128, k: usize) -> u128 {
// // mask for the last 2 bits (representing one nucleotide)
// let mask = 0b11u128;

// // initialize reverse complement result
// let mut rc_u128 = 0u128;

// // for each nucleotide in the k-mer
// for i in 0..k {
// // get the last 2 bits (current nucleotide)
// let nucleotide = (kmer >> (2 * i)) & mask;

// // complement the nucleotide:
// let complement = match nucleotide {
// 0b00 => 0b11, // A -> T
// 0b01 => 0b10, // C -> G
// 0b10 => 0b01, // G -> C
// 0b11 => 0b00, // T -> A
// _ => unreachable!(),
// };

// // shift the complemented nucleotide to its reverse position
// rc_u128 |= complement << (2 * (k - i - 1));
// }
// rc_u128
// }

// pub fn encode_kmer<IntT: for<'a> UInt<'a>>(kmer: &str) -> IntT {
// let nucleotide_to_bits: [u8; 4] = [
// 0b00, // A
// 0b01, // C
// 0b10, // G
// 0b11, // T
// ];

// let mut result: IntT = 0 as InT;

// for nucleotide in kmer.chars() {
// let index = match nucleotide {
// 'A' => 0,
// 'C' => 1,
// 'G' => 2,
// 'T' => 3,
// _ => panic!("Invalid nucleotide"),
// };
// result = (result << 2) | (nucleotide_to_bits[index] as u128);
// }
// result
// }

pub fn encode_u8_kmer(dna: &[u8]) -> u128 {
let mut encoded: u128 = 0;
for &nucleotide in dna {
encoded <<= 2; // Shift left by 2 bits
encoded |= match nucleotide {
b'A' => 0b00,
b'C' => 0b01,
b'G' => 0b10,
b'T' => 0b11,
_ => panic!("Invalid nucleotide: {}", nucleotide as char),
};
}
encoded
}

pub fn decode_kmer(encoded: u128, k: usize) -> String {
let bits_to_nucleotide: [char; 4] = ['A', 'C', 'G', 'T'];
let mut kmer = String::with_capacity(k);

let mask = (1u128 << (2 * k)) - 1;
let mut value = encoded & mask;

for _ in 0..k {
let index = (value & 0b11) as usize;
let nucleotide = bits_to_nucleotide[index];
kmer.insert(0, nucleotide);
value >>= 2;
}
kmer
}

// extract last nucleotide from an encoded k-mer
// pub fn get_last_nucl<IntT: for<'a> UInt<'a>>(encoded_kmer: IntT) -> char {
// // mask the last 2 bits to get the encoded nucleotide
// let last_bits = (encoded_kmer & 0b11) as u8;
// // decode the nucleotide based on the 2-bit pattern
// match last_bits {
// 0b00 => 'A',
// 0b01 => 'C',
// 0b10 => 'G',
// 0b11 => 'T',
// _ => unreachable!(),
// }
// }

#[derive(Clone)]
pub struct VariantInfo {

Check warning on line 40 in src/skalo/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct

warning: missing documentation for a struct --> src/skalo/utils.rs:40:1 | 40 | pub struct VariantInfo { | ^^^^^^^^^^^^^^^^^^^^^^
pub sequence: DnaSequence,

Check warning on line 41 in src/skalo/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> src/skalo/utils.rs:41:5 | 41 | pub sequence: DnaSequence, | ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit 9e4ccf4

Please sign in to comment.