-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name = "biotest" | |
version = "0.1.0" | ||
authors = ["Pierre Marijon <[email protected]>"] | ||
edition = "2021" | ||
description = "Many function to generate test data for bioinformatics data" | ||
description = "Generate random test data for bioinformatics" | ||
rust-version = "1.75" | ||
|
||
homepage = "https://github.com/natir/biotest" | ||
|
@@ -15,12 +15,11 @@ license-file = "LICENSE" | |
|
||
|
||
[dependencies] | ||
|
||
rand = { version = "0.8" } | ||
|
||
# Error management | ||
thiserror = { version = "1" } | ||
|
||
|
||
# Logging and error management | ||
log = { version = "0.4" } | ||
|
||
|
@@ -30,12 +29,15 @@ biotest_derive = { path = "biotest_derive", optional = true } | |
|
||
[dev-dependencies] | ||
criterion = { version = "0.5" } | ||
tempfile = { version = "3" } | ||
|
||
# CLI management | ||
clap = { version = "4", features = ["derive"] } | ||
|
||
# Logging management | ||
stderrlog = { version = "0.5" } | ||
|
||
|
||
[profile.release] | ||
lto = 'thin' | ||
opt-level = 3 | ||
|
@@ -46,4 +48,4 @@ incremental = false | |
|
||
[profile.profiling] | ||
inherits = "release" | ||
debug = true | ||
debug = true |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//! Declarations of some constants value | ||
/* std use */ | ||
|
||
/* crates use */ | ||
|
||
/* projet use */ | ||
|
||
const fn gen_array<const N: usize, const B: usize>() -> [u8; N] { | ||
let mut array = [0; N]; | ||
|
||
let mut i = 0; | ||
while i < N { | ||
array[i] = (B + i) as u8; | ||
i += 1; | ||
} | ||
|
||
array | ||
} | ||
|
||
/// Fixed random seed | ||
pub const SEED: [u8; 32] = [42; 32]; | ||
|
||
/// Nucleotides with any case | ||
pub const NUCLEOTIDES: [u8; 8] = *b"ACTGactg"; | ||
|
||
/// Nucleotides lower | ||
pub const NUCLEOTIDES_LOWER: [u8; 4] = *b"actg"; | ||
|
||
/// Nucleotides upper | ||
pub const NUCLEOTIDES_UPPER: [u8; 4] = *b"ACTG"; | ||
|
||
/// All possible phred 33 value | ||
pub const PHRED33: [u8; 40] = gen_array::<40, 33>(); | ||
|
||
/// All possible phred 64 value | ||
pub const PHRED64: [u8; 40] = gen_array::<40, 64>(); | ||
|
||
/// Alphabets with [ \ ] ^ _ ` | ||
pub const ALPHABETS: [u8; 58] = gen_array::<58, 65>(); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
/* project use */ | ||
use super::*; | ||
|
||
#[test] | ||
fn phred33() { | ||
assert_eq!( | ||
gen_array::<40, 33>().to_vec(), | ||
b"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGH".to_vec() | ||
); | ||
} | ||
|
||
#[test] | ||
fn phred64() { | ||
assert_eq!( | ||
gen_array::<40, 64>().to_vec(), | ||
b"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefg".to_vec() | ||
); | ||
} | ||
|
||
#[test] | ||
fn alphapets() { | ||
assert_eq!( | ||
gen_array::<58, 65>().to_vec(), | ||
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz".to_vec() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! Format data generation | ||
/* std use */ | ||
|
||
/* crates use */ | ||
|
||
/* module declaration */ | ||
pub mod fasta; | ||
pub mod fastq; | ||
|
||
/* projet use */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
//! Fasta generation | ||
/* std use */ | ||
use std::io::Write; | ||
Check warning on line 4 in src/format/fasta.rs GitHub Actions / check
Check warning on line 4 in src/format/fasta.rs GitHub Actions / test (stable)
Check failure on line 4 in src/format/fasta.rs GitHub Actions / lints
Check warning on line 4 in src/format/fasta.rs GitHub Actions / minimum_rust_version
Check warning on line 4 in src/format/fasta.rs GitHub Actions / test (beta)
Check warning on line 4 in src/format/fasta.rs GitHub Actions / test (macos)
Check warning on line 4 in src/format/fasta.rs GitHub Actions / test (windows)
|
||
|
||
/* crates use */ | ||
|
||
/* projet use */ | ||
use crate::constants; | ||
Check warning on line 9 in src/format/fasta.rs GitHub Actions / check
Check warning on line 9 in src/format/fasta.rs GitHub Actions / test (stable)
Check failure on line 9 in src/format/fasta.rs GitHub Actions / lints
Check warning on line 9 in src/format/fasta.rs GitHub Actions / minimum_rust_version
Check warning on line 9 in src/format/fasta.rs GitHub Actions / test (beta)
Check warning on line 9 in src/format/fasta.rs GitHub Actions / test (macos)
Check warning on line 9 in src/format/fasta.rs GitHub Actions / test (windows)
|
||
use crate::error; | ||
|
||
fn description<W>( | ||
output: &mut W, | ||
rng: &mut rand::rngs::StdRng, | ||
id: usize, | ||
comment: usize, | ||
) -> error::Result<()> | ||
where | ||
W: std::io::Write, | ||
{ | ||
output.write_all(&[b'>'])?; | ||
crate::text(output, rng, id)?; | ||
output.write_all(&[b' '])?; | ||
crate::text(output, rng, comment)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Write record | ||
pub fn record<W>( | ||
output: &mut W, | ||
rng: &mut rand::rngs::StdRng, | ||
id: usize, | ||
comment: usize, | ||
seq_len: usize, | ||
) -> error::Result<()> | ||
where | ||
W: std::io::Write, | ||
{ | ||
description(output, rng, id, comment)?; | ||
output.write_all(&[b'\n'])?; | ||
crate::sequence(output, rng, seq_len)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Write multiple record | ||
pub fn records<W>( | ||
output: &mut W, | ||
rng: &mut rand::rngs::StdRng, | ||
id: usize, | ||
comment: usize, | ||
seq_len: usize, | ||
num_record: usize, | ||
) -> error::Result<()> | ||
where | ||
W: std::io::Write, | ||
{ | ||
for _ in 0..num_record { | ||
record(output, rng, id, comment, seq_len)?; | ||
output.write_all(&[b'\n'])?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Create a fasta file | ||
pub fn create<P>( | ||
path: P, | ||
rng: &mut rand::rngs::StdRng, | ||
id: usize, | ||
comment: usize, | ||
seq_len: usize, | ||
num_record: usize, | ||
) -> error::Result<()> | ||
where | ||
P: std::convert::AsRef<std::path::Path>, | ||
{ | ||
let mut output = std::fs::File::create(&path)?; | ||
|
||
records(&mut output, rng, id, comment, seq_len, num_record)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
/* std use */ | ||
use std::io::Read; | ||
|
||
/* project use */ | ||
use super::*; | ||
|
||
const TRUTH: &[u8] = b">oNi_P dzwC[tBTlD | ||
tCGCgtGTTAGTTAagccAcggtAatGcTtgtaCgcAGgAtaTcgAAtTa | ||
>rQ_[V S^RtSvzMeT | ||
ttGCtCatGtctgCTGGTACtgTgcaaaagggGAGacAtgCtGCAAtTac | ||
>HYNm[ QBCgL`Scxx | ||
GGtatTCaTCctcTGgAActTgCGAcaAgaAAtaTCCcAgagggaCcttC | ||
>gNXcb hRd]QWyFOg | ||
gAACcTtCttAacGtTtAtGTgACAGCCaCGctGagattTGtgCttaAGg | ||
>ppugI LwOFhYRxBZ | ||
CTGTCCACgTTTGagtGaGCatAGGACAAaacTaTTagagGtatAGCcTa | ||
"; | ||
|
||
#[test] | ||
fn record_() -> error::Result<()> { | ||
let mut output = Vec::new(); | ||
let mut rng = crate::rand(); | ||
|
||
record(&mut output, &mut rng, 5, 10, 50)?; | ||
|
||
assert_eq!(output, TRUTH.to_vec()[..68]); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn records_() -> error::Result<()> { | ||
let mut output = Vec::new(); | ||
let mut rng = crate::rand(); | ||
|
||
records(&mut output, &mut rng, 5, 10, 50, 5)?; | ||
|
||
assert_eq!(output, TRUTH); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn create_() -> error::Result<()> { | ||
let mut rng = crate::rand(); | ||
|
||
let temp_dir = tempfile::tempdir()?; | ||
let temp_path = temp_dir.path(); | ||
|
||
let temp_file = temp_path.join("tmp.fasta"); | ||
|
||
create(&temp_file, &mut rng, 5, 10, 50, 5)?; | ||
|
||
let mut data = Vec::new(); | ||
let mut input = std::fs::File::open(&temp_file)?; | ||
input.read_to_end(&mut data)?; | ||
|
||
assert_eq!(data, TRUTH); | ||
|
||
Ok(()) | ||
} | ||
} |