Skip to content

Commit

Permalink
feat: add vcf filter, info and genotypes
Browse files Browse the repository at this point in the history
  • Loading branch information
natir committed Apr 5, 2024
1 parent 8fc300d commit 0a8c285
Show file tree
Hide file tree
Showing 6 changed files with 875 additions and 62 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ biotest_derive = { path = "biotest_derive", optional = true }

[dev-dependencies]
criterion = { version = "0.5" }

# test
tempfile = { version = "3" }
assert_matches = { version = "1" }

# CLI management
clap = { version = "4", features = ["derive"] }
Expand Down
31 changes: 23 additions & 8 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ const fn gen_array<const N: usize, const B: usize>() -> [u8; N] {
}

/// Fixed random seed
pub const SEED: [u8; 32] = [42; 32];
pub static SEED: [u8; 32] = [42; 32];

/// Nucleotides with any case
pub const NUCLEOTIDES: [u8; 8] = *b"ACTGactg";
pub static NUCLEOTIDES: [u8; 8] = *b"ACTGactg";

/// Nucleotides lower
pub const NUCLEOTIDES_LOWER: [u8; 4] = *b"actg";
pub static NUCLEOTIDES_LOWER: [u8; 4] = *b"actg";

/// Nucleotides upper
pub const NUCLEOTIDES_UPPER: [u8; 4] = *b"ACTG";
pub static NUCLEOTIDES_UPPER: [u8; 4] = *b"ACTG";

/// All possible phred 33 value
pub const PHRED33: [u8; 40] = gen_array::<40, 33>();
pub static PHRED33: [u8; 40] = gen_array::<40, 33>();

/// All possible phred 64 value
pub const PHRED64: [u8; 40] = gen_array::<40, 64>();
pub static PHRED64: [u8; 40] = gen_array::<40, 64>();

/// Alphabets with [ \ ] ^ _ `
pub const ALPHABETS: [u8; 58] = gen_array::<58, 65>();
pub static ALPHABETS: [u8; 58] = gen_array::<58, 65>();

/// Some different possible chromosomes name
pub const CHROMOSOMES: [&[u8]; 10] = [
pub static CHROMOSOMES: [&[u8]; 10] = [
b"chr1",
b"23",
b"93",
Expand All @@ -53,6 +53,21 @@ pub const CHROMOSOMES: [&[u8]; 10] = [
b"1",
];

/// All vcf info type
pub static VCF_INFO_TYPE: [&[u8]; 5] = [b"Integer", b"Float", b"Flag", b"Character", b"String"];

/// All vcf info number
pub static VCF_INFO_NUMBER: [&[u8]; 6] = [b"1", b"2", b"A", b"R", b"G", b"."];

/// All vcf info type
pub static VCF_FORMAT_TYPE: [&[u8]; 4] = [b"Integer", b"Float", b"Character", b"String"];

/// All vcf info number
pub static VCF_FORMAT_NUMBER: [&[u8]; 6] = [b"1", b"2", b"A", b"R", b"G", b"."];

/// biotest version
pub static BIOTEST_VERSION: &[u8] = env!("CARGO_PKG_VERSION").as_bytes();

#[cfg(test)]
mod tests {
/* project use */
Expand Down
37 changes: 37 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,47 @@ use thiserror;
/// Enum to manage error
#[derive(std::fmt::Debug, thiserror::Error)]
pub enum Error {
/// unreachable
#[error("Unreachable error from file {file} in line {line}")]
Unreachable {
/// line number
line: u32,
/// file name
file: &'static str,
},

/// std::io::Error error
#[error(transparent)]
StdIo(#[from] std::io::Error),
}

macro_rules! create_unreachable {
() => {
crate::error::Error::Unreachable {
line: std::line!(),
file: std::file!(),
}
};
}

/// Alias of result
pub type Result<T> = core::result::Result<T, Error>;

#[cfg(test)]
mod tests {
#[test]
fn unreachable_macro() {
assert_matches::assert_matches!(
create_unreachable!(),
crate::error::Error::Unreachable {
line: 40,
#[cfg(target_family = "windows")]
file: "src\\error.rs",
#[cfg(target_family = "unix")]
file: "src/error.rs",
#[cfg(target_family = "wasm")]
file: "src/error.rs",
}
);
}
}
Loading

0 comments on commit 0a8c285

Please sign in to comment.