Struct noodles_vcf::variant::record_buf::samples::Samples

source ·
pub struct Samples { /* private fields */ }
Expand description

A variant record samples buffer.

Implementations§

source§

impl Samples

source

pub fn new(keys: Keys, values: Vec<Vec<Option<Value>>>) -> Self

Creates a variant record samples buffer.

§Examples
use noodles_vcf::variant::record_buf::{samples::Keys, Samples};
let genotypes = Samples::new(Keys::default(), Vec::new());
source

pub fn is_empty(&self) -> bool

Returns whether there are any samples.

§Examples
use noodles_vcf::variant::record_buf::Samples;
let samples = Samples::default();
assert!(samples.is_empty());
source

pub fn keys(&self) -> &Keys

Returns the keys.

§Examples
use noodles_vcf::variant::{
    record::samples::keys::key,
    record_buf::{samples::Keys, Samples},
};

let samples = Samples::default();
assert!(samples.keys().as_ref().is_empty());

let keys: Keys = [String::from(key::GENOTYPE)].into_iter().collect();
let samples = Samples::new(keys.clone(), Vec::new());
assert_eq!(samples.keys(), &keys);
source

pub fn keys_mut(&mut self) -> &mut Keys

Returns a mutable reference to the keys.

§Examples
use noodles_vcf::variant::{
    record::samples::keys::key,
    record_buf::{samples::Keys, Samples},
};

let keys: Keys = [String::from(key::GENOTYPE)].into_iter().collect();

let mut samples = Samples::default();
*samples.keys_mut() = keys.clone();

assert_eq!(samples.keys(), &keys);
source

pub fn values(&self) -> impl Iterator<Item = Sample<'_>>

Returns samples.

source

pub fn get(&self, header: &Header, sample_name: &str) -> Option<Sample<'_>>

Returns the sample with the given sample name.

§Examples
use noodles_vcf::{
    self as vcf,
    variant::{
        record::samples::keys::key,
        record_buf::{samples::sample::Value, Samples},
    },
};

let header = vcf::Header::builder()
    .add_sample_name("sample0")
    .add_sample_name("sample1")
    .add_sample_name("sample2")
    .build();

let keys = [String::from(key::GENOTYPE)].into_iter().collect();
let samples = Samples::new(
    keys,
    vec![
        vec![Some(Value::from("0|0"))],
        vec![Some(Value::from("1/1"))],
        vec![],
    ],
);

let sample = samples.get(&header, "sample0");
assert_eq!(sample.and_then(|s| s.values().get(0)), Some(&Some(Value::from("0|0"))));
source

pub fn get_index(&self, i: usize) -> Option<Sample<'_>>

Returns the sample at the given index.

source

pub fn select(&self, name: &str) -> Option<Series<'_>>

Returns the series with the given column name.

§Examples
use noodles_vcf::variant::{
    record::samples::keys::key,
    record_buf::{samples::sample::Value, Samples},
};

let keys = [String::from(key::GENOTYPE)].into_iter().collect();
let samples = Samples::new(
    keys,
    vec![
        vec![Some(Value::from("0|0"))],
        vec![Some(Value::from("1/1"))],
        vec![],
    ],
);

let series = samples.select(key::GENOTYPE).expect("missing genotype column");
assert_eq!(series.get(0), Some(Some(&Value::from("0|0"))));
assert_eq!(series.get(1), Some(Some(&Value::from("1/1"))));
assert_eq!(series.get(2), Some(None));
assert_eq!(series.get(3), None);
source

pub fn series(&self) -> impl Iterator<Item = Series<'_>>

Returns an iterator over series.

Trait Implementations§

source§

impl Clone for Samples

source§

fn clone(&self) -> Samples

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Samples

source§

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

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

impl Default for Samples

source§

fn default() -> Samples

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

impl From<Samples> for (Keys, Vec<Vec<Option<Value>>>)

source§

fn from(samples: Samples) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Samples

source§

fn eq(&self, other: &Samples) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Samples for &Samples

source§

fn is_empty(&self) -> bool

Returns whether there are any samples.
source§

fn len(&self) -> usize

Returns the number of samples.
source§

fn column_names<'a, 'h: 'a>( &'a self, _: &'h Header, ) -> Box<dyn Iterator<Item = Result<&'a str>> + 'a>

Returns the column names.
source§

fn select<'a, 'h: 'a>( &'a self, _: &'h Header, column_name: &str, ) -> Option<Result<Box<dyn Series + 'a>>>

Returns the series with the given column name.
source§

fn series(&self) -> Box<dyn Iterator<Item = Result<Box<dyn Series + '_>>> + '_>

Returns an iterator over series.
source§

fn iter(&self) -> Box<dyn Iterator<Item = Box<dyn Sample + '_>> + '_>

Returns an iterator over samples.
source§

impl Samples for Samples

source§

fn is_empty(&self) -> bool

Returns whether there are any samples.
source§

fn len(&self) -> usize

Returns the number of samples.
source§

fn column_names<'a, 'h: 'a>( &'a self, _: &'h Header, ) -> Box<dyn Iterator<Item = Result<&'a str>> + 'a>

Returns the column names.
source§

fn select<'a, 'h: 'a>( &'a self, _: &'h Header, column_name: &str, ) -> Option<Result<Box<dyn Series + 'a>>>

Returns the series with the given column name.
source§

fn series(&self) -> Box<dyn Iterator<Item = Result<Box<dyn Series + '_>>> + '_>

Returns an iterator over series.
source§

fn iter(&self) -> Box<dyn Iterator<Item = Box<dyn Sample + '_>> + '_>

Returns an iterator over samples.
source§

impl StructuralPartialEq for Samples

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

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

§

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>,

§

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.