-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::collections::HashSet; | ||
|
||
lazy_static! { | ||
static ref BASES: HashSet<u8> = vec![b'a', b'g', b'c', b't', b'A', b'G', b'C', b'T',] | ||
.into_iter() | ||
.collect(); | ||
} | ||
|
||
/// Distance (D) between two sequences | ||
/// | ||
/// ``` | ||
/// // * ** ** | ||
/// let seq1 = b"GTCTGCATGCN"; | ||
/// let seq2 = b"TTTAGCTAgc-"; | ||
/// // difference 5 | ||
/// // comparable 10 | ||
/// assert_eq!(intspan::pair_d(seq1, seq2), 0.5); | ||
/// ``` | ||
pub fn pair_d(seq1: &[u8], seq2: &[u8]) -> f32 { | ||
assert_eq!( | ||
seq1.len(), | ||
seq2.len(), | ||
"Two sequences of different length ({}!={})", | ||
seq1.len(), | ||
seq2.len() | ||
); | ||
|
||
let mut comparable = 0; | ||
let mut difference = 0; | ||
|
||
for (base1, base2) in seq1.iter().zip(seq2) { | ||
if BASES.contains(base1) && BASES.contains(base2) { | ||
comparable += 1; | ||
if base1.to_ascii_uppercase() != base2.to_ascii_uppercase() { | ||
difference += 1; | ||
} | ||
} | ||
} | ||
|
||
assert_ne!(comparable, 0, "Comparable bases shouldn't be zero"); | ||
|
||
// eprintln!("{} {}", difference, comparable); | ||
|
||
difference as f32 / comparable as f32 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod alignment; | ||
pub mod coverage; | ||
pub mod fas; | ||
pub mod intspan; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters