pub struct Data { /* private fields */ }
Expand description

BAM record data.

This is also called optional fields.

Implementations

Returns the number of data fields.

Examples
use noodles_bam::record::Data;
let data = Data::default();
assert_eq!(data.len(), 0);

Returns whether there are any data fields.

Examples
use noodles_bam::record::Data;
let data = Data::default();
assert!(data.is_empty());

Removes all fields from the data map.

This does not affect the capacity of the map.

Examples
use noodles_bam::record::Data;

let mut data = Data::try_from(vec![
    b'N', b'H', b'i', 0x01, 0x00, 0x00, 0x00, // NH:i:1
    b'R', b'G', b'Z', b'r', b'g', b'0', 0x00, // RG:Z:rg0
])?;

assert_eq!(data.len(), 2);

data.clear();

assert!(data.is_empty());

Returns a field by the given tag.

Examples
use noodles_bam::record::{data::{field::Value, Field}, Data};
use noodles_sam::record::data::field::Tag;

let data = Data::try_from(vec![
    b'N', b'H', b'i', 0x01, 0x00, 0x00, 0x00, // NH:i:1
    b'R', b'G', b'Z', b'r', b'g', b'0', 0x00, // RG:Z:rg0
])?;

let rg = data.get(Tag::ReadGroup).transpose()?;
assert_eq!(rg, Some(Field::new(Tag::ReadGroup, Value::String(String::from("rg0")))));

assert!(data.get(Tag::AlignmentScore).is_none());

Returns a field by an index.

Examples
use noodles_bam::record::{data::{field::Value, Field}, Data};
use noodles_sam::record::data::field::Tag;

let data = Data::try_from(vec![
    b'N', b'H', b'i', 0x01, 0x00, 0x00, 0x00, // NH:i:1
    b'R', b'G', b'Z', b'r', b'g', b'0', 0x00, // RG:Z:rg0
])?;

let rg = data.get_index(1).transpose()?;
assert_eq!(rg, Some(Field::new(Tag::ReadGroup, Value::String(String::from("rg0")))));

assert!(data.get_index(2).is_none());

Inserts a field into the data map.

This uses the field tag as the key and field as the value.

If the tag already exists in the map, the existing field is replaced by the new one, and the existing field is returned.

Examples
use noodles_bam::record::{data::{field::Value, Field}, Data};
use noodles_sam::record::data::field::Tag;

let mut data = Data::default();

let nh = Field::new(Tag::AlignmentHitCount, Value::UInt8(1));
data.insert(nh.clone()).transpose()?;

assert_eq!(data.len(), 1);
assert_eq!(data.get_index(0).transpose()?, Some(nh));
👎 Deprecated since 0.8.0:

Use Data::values instead.

Returns an iterator over data fields.

Examples
use noodles_bam::record::{data::{field::Value, Field}, Data};
use noodles_sam::record::data::field::Tag;

let data = Data::try_from(vec![
    b'N', b'H', b'i', 0x01, 0x00, 0x00, 0x00, // NH:i:1
    b'R', b'G', b'Z', b'r', b'g', b'0', 0x00, // RG:Z:rg0
])?;

let mut fields = data.values();

assert_eq!(
    fields.next().transpose()?,
    Some(Field::new(Tag::AlignmentHitCount, Value::Int32(1)))
);

assert_eq!(
    fields.next().transpose()?,
    Some(Field::new(Tag::ReadGroup, Value::String(String::from("rg0"))))
);

assert!(fields.next().is_none());

Returns an iterator over all tags.

Examples
use noodles_bam::record::Data;
use noodles_sam::record::data::field::Tag;

let data = Data::try_from(vec![
    b'N', b'H', b'i', 0x01, 0x00, 0x00, 0x00, // NH:i:1
    b'R', b'G', b'Z', b'r', b'g', b'0', 0x00, // RG:Z:rg0
])?;

let mut keys = data.keys();

assert_eq!(keys.next().transpose()?, Some(Tag::AlignmentHitCount));
assert_eq!(keys.next().transpose()?, Some(Tag::ReadGroup));
assert!(keys.next().is_none());

Returns an iterator over all fields.

Examples
use noodles_bam::record::{data::{field::Value, Field}, Data};
use noodles_sam::record::data::field::Tag;

let data = Data::try_from(vec![
    b'N', b'H', b'i', 0x01, 0x00, 0x00, 0x00, // NH:i:1
    b'R', b'G', b'Z', b'r', b'g', b'0', 0x00, // RG:Z:rg0
])?;

let mut values = data.values();

assert_eq!(
    values.next().transpose()?,
    Some(Field::new(Tag::AlignmentHitCount, Value::Int32(1)))
);

assert_eq!(
    values.next().transpose()?,
    Some(Field::new(Tag::ReadGroup, Value::String(String::from("rg0"))))
);

assert!(values.next().is_none());

Trait Implementations

Performs the conversion.

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.