Skip to content

Commit

Permalink
sort by single nts
Browse files Browse the repository at this point in the history
  • Loading branch information
lskatz committed Feb 20, 2024
1 parent 38b9c11 commit 97e4e9b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/bin/fasten_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn sort_entries (unsorted:Vec<Seq>, which_field:&str, reverse_sort:bool) -> Vec<
a_seq.cmp(&b_seq)
});
},
"GC" => {
"GC" | "CG" => {
sorted.sort_by(|a,b| {
let a_seq = format!("{}{}", a.seq1, a.seq2);
let b_seq = format!("{}{}", b.seq1, b.seq2);
Expand All @@ -257,6 +257,34 @@ fn sort_entries (unsorted:Vec<Seq>, which_field:&str, reverse_sort:bool) -> Vec<
a_gc.partial_cmp(&b_gc).unwrap()
});
},
"A" | "C" | "G" | "T" | "N" => {
let nt_lowercase = which_field.to_lowercase().chars().next().unwrap_or('\0');
let nt_uppercase = which_field.to_uppercase().chars().next().unwrap_or('\0');
let my_nts = vec![nt_uppercase, nt_lowercase];

sorted.sort_by(|a,b| {
let a_seq = format!("{}{}", a.seq1, a.seq2);
let b_seq = format!("{}{}", b.seq1, b.seq2);

let mut a_count: usize = 0;
let mut b_count: usize = 0;

for nt in &my_nts {
for c in a_seq.chars() {
if nt == &c {
a_count += 1;
}
}
for c in b_seq.chars() {
if nt == &c {
b_count += 1;
}
}
}

a_count.cmp(&b_count)
});
},
_ => {
panic!("Tried to sort by {} which is not implemented", which_field);
}
Expand Down

0 comments on commit 97e4e9b

Please sign in to comment.