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
impl Samples
sourcepub fn new(keys: Keys, values: Vec<Vec<Option<Value>>>) -> Self
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());
sourcepub fn is_empty(&self) -> bool
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());
sourcepub fn keys(&self) -> &Keys
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);
sourcepub fn keys_mut(&mut self) -> &mut Keys
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);
sourcepub fn get(&self, header: &Header, sample_name: &str) -> Option<Sample<'_>>
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"))));
sourcepub fn select(&self, name: &str) -> Option<Series<'_>>
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);
Trait Implementations§
source§impl PartialEq for Samples
impl PartialEq for Samples
source§impl Samples for &Samples
impl Samples for &Samples
source§fn column_names<'a, 'h: 'a>(
&'a self,
_: &'h Header,
) -> Box<dyn Iterator<Item = Result<&'a str>> + 'a>
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>>>
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§impl Samples for Samples
impl Samples for Samples
source§fn column_names<'a, 'h: 'a>(
&'a self,
_: &'h Header,
) -> Box<dyn Iterator<Item = Result<&'a str>> + 'a>
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>>>
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.
impl StructuralPartialEq for Samples
Auto Trait Implementations§
impl Freeze for Samples
impl RefUnwindSafe for Samples
impl Send for Samples
impl Sync for Samples
impl Unpin for Samples
impl UnwindSafe for Samples
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
Mutably borrows from an owned value. Read more