Crates.io | bam-builder |
lib.rs | bam-builder |
version | 1.0.0 |
source | src |
created_at | 2021-01-17 17:19:21.914515 |
updated_at | 2023-09-29 20:12:09.785708 |
description | A library for easily building BAMs for testing. |
homepage | |
repository | https://github.com/sstadick/bam-builder |
max_upload_size | |
id | 343193 |
size | 57,582 |
A library for easily building bams for testing.
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();
}
This library is more a less a direct clone of fgbio's SamBuilder, mixed in with some helper methods from htsjdk.