Skip to main content

RecordBuilder

Struct RecordBuilder 

Source
pub struct RecordBuilder { /* private fields */ }
Expand description

Builder for creating individual BAM/SAM records without a parent SamBuilder.

This builder simplifies test record creation by providing a chainable interface for setting all record fields. All fields have sensible defaults. Unlike SamBuilder, this creates records directly without accumulating them.

§Examples

use fgumi_sam::builder::{RecordBuilder, ConsensusTagsBuilder};
use noodles::sam::alignment::record::Flags;

// Create a simple unmapped read
let record = RecordBuilder::new()
    .name("read1")
    .sequence("ACGT")
    .qualities(&[30, 30, 30, 30])
    .build();

// Create a mapped paired-end R1
let r1 = RecordBuilder::new()
    .name("read1")
    .sequence("ACGTACGT")
    .qualities(&[30; 8])
    .paired(true)
    .first_segment(true)
    .reference_sequence_id(0)
    .alignment_start(100)
    .cigar("8M")
    .mapping_quality(60)
    .build();

// Create a record with tags
let record = RecordBuilder::new()
    .name("read1")
    .sequence("ACGT")
    .tag("RG", "A")
    .tag("MI", "AAAA-CCCC/A")
    .build();

Implementations§

Source§

impl RecordBuilder

Source

pub fn new() -> RecordBuilder

Creates a new builder with default values.

Source

pub fn mapped_read() -> RecordBuilder

Creates a new builder pre-configured for a typical mapped read.

Sets common defaults:

  • reference_sequence_id: 0
  • mapping_quality: 60
  • CIGAR will be auto-generated as {len}M if not explicitly set
§Examples
use fgumi_sam::builder::RecordBuilder;
use noodles::sam::alignment::record::Cigar;

let record = RecordBuilder::mapped_read()
    .name("read1")
    .sequence("ACGTACGT")
    .alignment_start(100)
    .build();

assert_eq!(record.reference_sequence_id(), Some(0));
assert!(!record.cigar().is_empty()); // Auto-generated as "8M"
Source

pub fn name(self, name: &str) -> RecordBuilder

Sets the read name.

Source

pub fn sequence(self, seq: &str) -> RecordBuilder

Sets the sequence.

Source

pub fn qualities(self, quals: &[u8]) -> RecordBuilder

Sets the quality scores (Phred+33 ASCII).

Source

pub fn flags(self, flags: Flags) -> RecordBuilder

Sets all flags at once.

Source

pub fn paired(self, paired: bool) -> RecordBuilder

Sets the paired flag.

Source

pub fn first_segment(self, is_first: bool) -> RecordBuilder

Sets the first segment (R1) flag. Implies paired.

Source

pub fn properly_paired(self, properly_paired: bool) -> RecordBuilder

Sets the properly paired flag. Implies paired.

Source

pub fn unmapped(self, unmapped: bool) -> RecordBuilder

Sets the unmapped flag.

Source

pub fn reverse_complement(self, reverse: bool) -> RecordBuilder

Sets the reverse complement flag.

Source

pub fn secondary(self, secondary: bool) -> RecordBuilder

Sets the secondary alignment flag.

Source

pub fn supplementary(self, supplementary: bool) -> RecordBuilder

Sets the supplementary alignment flag.

Source

pub fn reference_sequence_id(self, id: usize) -> RecordBuilder

Sets the reference sequence ID (0-based).

Source

pub fn alignment_start(self, pos: usize) -> RecordBuilder

Sets the alignment start position (1-based).

Source

pub fn mapping_quality(self, mapq: u8) -> RecordBuilder

Sets the mapping quality.

Source

pub fn cigar(self, cigar: &str) -> RecordBuilder

Sets the CIGAR string.

Source

pub fn mate_reference_sequence_id(self, id: usize) -> RecordBuilder

Sets the mate reference sequence ID (0-based).

Source

pub fn mate_alignment_start(self, pos: usize) -> RecordBuilder

Sets the mate alignment start position (1-based).

Source

pub fn template_length(self, tlen: i32) -> RecordBuilder

Sets the template length (insert size).

Source

pub fn mate_reverse_complement(self, reverse: bool) -> RecordBuilder

Sets the mate reverse complement flag.

Source

pub fn mate_unmapped(self, unmapped: bool) -> RecordBuilder

Sets the mate unmapped flag.

Source

pub fn tag<V>(self, tag: &str, value: V) -> RecordBuilder
where V: Into<Value>,

Adds a SAM tag.

§Examples
use fgumi_sam::builder::RecordBuilder;
let record = RecordBuilder::new()
    .name("read1")
    .tag("RG", "A")
    .tag("MI", "AAAA-CCCC/A")
    .build();
Source

pub fn consensus_tags(self, builder: ConsensusTagsBuilder) -> RecordBuilder

Adds consensus tags using a ConsensusTagsBuilder.

§Examples
use fgumi_sam::builder::{RecordBuilder, ConsensusTagsBuilder};
let record = RecordBuilder::new()
    .sequence("ACGT")
    .consensus_tags(
        ConsensusTagsBuilder::new()
            .depth_max(10)
            .depth_min(5)
            .error_rate(0.01)
    )
    .build();
Source

pub fn build(self) -> RecordBuf

Builds the RecordBuf.

§Panics

Panics if CIGAR string parsing fails (should only happen with invalid CIGAR).

Trait Implementations§

Source§

impl Debug for RecordBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for RecordBuilder

Source§

fn default() -> RecordBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.