5 releases (1 stable)
1.0.0 | Sep 29, 2023 |
---|---|
0.1.3 | Jan 18, 2021 |
0.1.2 | Jan 17, 2021 |
0.1.1 | Jan 17, 2021 |
0.1.0 | Jan 17, 2021 |
#240 in Biology
37KB
654 lines
bam-builder
A library for easily building bams for testing.
Example
use bam_builder::{bam_order::BamSortOrder, BamBuilder};
fn main() {
// Create a builder with all defaults except the read_len is 100
let mut builder = BamBuilder::new(
100, // default read length
30, // default base quality
"Pair".to_owned(), // name of sample
None, // optional read group id
BamSortOrder::Unsorted, // how to sort reads when `.sort` is called
None, // optional sequence dictionary
None, // optional seed used for generating random bases
);
// Create a builder for read pair spec
let records = builder
.pair_builder()
.contig(0) // reads are mapped to tid 0
.start1(0) // start pos of read1
.start2(200) // start pos of read2
.unmapped1(false) // override default of unmapped
.unmapped2(false) // override default of unmapped
.bases1("A".repeat(100)) // override default random bases with "A"s
.bases2("C".repeat(100)) // override default random bases with "C"s
.build() // inflate the underlying records and set mate info
.unwrap();
// Add the pair to bam builder
builder.add_pair(records);
// Write records to a file
let tmp_file = builder.to_tmp().unwrap();
}
Attributions
This library is more a less a direct clone of fgbio's SamBuilder, mixed in with some helper methods from htsjdk.
Dependencies
~14–24MB
~413K SLoC