This is a modificated, parallel version of noodles BAM reader written in Rust. The library also includes Rust rewrite of sambamba parallel sort. It currently supports 3 modes: sort by name, sort by name and match mates, sort by coordinate and strand.
Currently sort just dumps sorted stream records bytes into file. One can direct sorted stream into any other BAM writer and obtain sorted BAM file.
Add this to Cargo.toml
:
[dependencies]
bam_parallel = { git = "https://github.com/NickRoz1/bam_parallel" }
bam_tools crate utilizes python script to do testing. To test bam_tools:
cargo build --release
python3 test.py
To read all records in BAM file and print them into stdout
:
use bam_tools::Reader;
let mut bgzf_reader = Reader::new(reader, std::cmp::min(num_cpus::get(), 20));
bgzf_reader.read_header().unwrap();
let mut records = bgzf_reader.records();
while let Some(Ok(rec)) = records.next_rec() {
println!("{:?}", rec);
}
To sort:
cargo build --release
# sort by name
./target/release/bam_binary -i -n test_files/input.bam -o test_files/out.bam
# sort by name and match mates
./target/release/bam_binary -i -n -M test_files/input.bam -o test_files/out.bam
# sort by coordinate and strand
./target/release/bam_binary -i test_files/input.bam -o test_files/out.bam