pub struct SamBuilder {
pub header: Header,
/* private fields */
}Expand description
Builder for creating test SAM/BAM records and files.
This builder simplifies test record creation by providing methods to add paired-end and single-end reads with sensible defaults. Records are accumulated internally and can be written to a file or iterated over.
§Examples
use fgumi_sam::builder::{SamBuilder, Strand};
// Create a builder with defaults
let mut builder = SamBuilder::new();
// Add a mapped pair
let pair = builder.add_pair()
.contig(0)
.start1(100)
.start2(200)
.build();
// Add a fragment
let frag = builder.add_frag()
.name("frag1")
.bases("ACGTACGT")
.contig(0)
.start(150)
.build();
// Write to a temp file
let path = builder.to_temp_file().unwrap();Fields§
§header: HeaderSAM header
Implementations§
Source§impl SamBuilder
impl SamBuilder
Sourcepub fn new() -> SamBuilder
pub fn new() -> SamBuilder
Creates a new builder with default settings.
Default settings:
- Read length: 100
- Base quality: 30
- Read group ID: “A”
- Sample name: “Sample”
- Reference sequences: chr1-chr22, chrX, chrY, chrM (200MB each)
Sourcepub fn with_defaults(read_length: usize, base_quality: u8) -> SamBuilder
pub fn with_defaults(read_length: usize, base_quality: u8) -> SamBuilder
Creates a new builder with specified read length and base quality.
§Panics
Panics if DEFAULT_REFERENCE_LENGTH is zero (impossible in practice).
Sourcepub fn new_unmapped() -> SamBuilder
pub fn new_unmapped() -> SamBuilder
Creates a builder for unmapped reads (no reference sequences in header).
Sourcepub fn with_single_ref(ref_name: &str, ref_length: usize) -> SamBuilder
pub fn with_single_ref(ref_name: &str, ref_length: usize) -> SamBuilder
Sourcepub fn iter(&self) -> impl Iterator<Item = &RecordBuf>
pub fn iter(&self) -> impl Iterator<Item = &RecordBuf>
Returns an iterator over the accumulated records.
Sourcepub fn push_record(&mut self, record: RecordBuf)
pub fn push_record(&mut self, record: RecordBuf)
Pushes a raw record to the collection.
This is useful when you need to add pre-built records to the collection.
Sourcepub fn add_pair(&mut self) -> PairBuilder<'_>
pub fn add_pair(&mut self) -> PairBuilder<'_>
Starts building a paired-end read pair.
Returns a PairBuilder that can be configured and then built.
The resulting records are added to this builder and also returned.
Sourcepub fn add_frag(&mut self) -> FragBuilder<'_>
pub fn add_frag(&mut self) -> FragBuilder<'_>
Starts building a single-end (fragment) read.
Returns a FragBuilder that can be configured and then built.
The resulting record is added to this builder and also returned.
Sourcepub fn write_bam(&self, path: &Path) -> Result<(), Error>
pub fn write_bam(&self, path: &Path) -> Result<(), Error>
Writes accumulated records to a BAM file.
§Errors
Returns an error if the file cannot be created or written.
Sourcepub fn write_sam(&self, path: &Path) -> Result<(), Error>
pub fn write_sam(&self, path: &Path) -> Result<(), Error>
Writes accumulated records to a SAM file.
§Errors
Returns an error if the file cannot be created or written.
Sourcepub fn to_temp_file(&self) -> Result<NamedTempFile, Error>
pub fn to_temp_file(&self) -> Result<NamedTempFile, Error>
Writes to a temporary BAM file and returns the path.
§Errors
Returns an error if the temporary file cannot be created or written.
Source§impl SamBuilder
impl SamBuilder
Sourcepub fn new_mapped() -> SamBuilder
pub fn new_mapped() -> SamBuilder
Creates a new builder for mapped BAM files with a single reference.
Creates a builder with “chr1” as the reference name and REFERENCE_LENGTH as length.
Sourcepub fn add_pair_with_attrs(
&mut self,
name: &str,
start1: Option<usize>,
start2: Option<usize>,
strand1: bool,
strand2: bool,
attrs: &HashMap<&str, Value>,
)
pub fn add_pair_with_attrs( &mut self, name: &str, start1: Option<usize>, start2: Option<usize>, strand1: bool, strand2: bool, attrs: &HashMap<&str, Value>, )
Adds a pair using positional arguments.
A convenience method for adding pairs with common parameters.
§Arguments
name- Read namestart1- Start position for R1 (None = unmapped)start2- Start position for R2 (None = unmapped)strand1- true = Plus, false = Minus for R1strand2- true = Plus, false = Minus for R2attrs- Attributes to add to both reads
Sourcepub fn add_frag_with_attrs(
&mut self,
name: &str,
start: Option<usize>,
strand: bool,
attrs: &HashMap<&str, Value>,
)
pub fn add_frag_with_attrs( &mut self, name: &str, start: Option<usize>, strand: bool, attrs: &HashMap<&str, Value>, )
Adds a fragment using positional arguments.
A convenience method for adding fragments with common parameters.
§Arguments
name- Read namestart- Start position (None = unmapped)strand- true = Plus, false = Minusattrs- Attributes to add
Trait Implementations§
Source§impl Debug for SamBuilder
impl Debug for SamBuilder
Source§impl Default for SamBuilder
impl Default for SamBuilder
Source§fn default() -> SamBuilder
fn default() -> SamBuilder
Auto Trait Implementations§
impl !Freeze for SamBuilder
impl RefUnwindSafe for SamBuilder
impl Send for SamBuilder
impl Sync for SamBuilder
impl Unpin for SamBuilder
impl UnsafeUnpin for SamBuilder
impl UnwindSafe for SamBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more