bam-builder

Crates.iobam-builder
lib.rsbam-builder
version1.0.0
sourcesrc
created_at2021-01-17 17:19:21.914515
updated_at2023-09-29 20:12:09.785708
descriptionA library for easily building BAMs for testing.
homepage
repositoryhttps://github.com/sstadick/bam-builder
max_upload_size
id343193
size57,582
Seth (sstadick)

documentation

https://docs.rs/bam-builder

README

Rust API docs Crates.io

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.

Commit count: 21

cargo fmt