Struct noodles_vcf::record::info::Info
source · pub struct Info(_);
Expand description
VCF record information fields (INFO
).
Implementations§
source§impl Info
impl Info
sourcepub fn try_from_str(s: &str, infos: &Infos) -> Result<Self, ParseError>
pub fn try_from_str(s: &str, infos: &Infos) -> Result<Self, ParseError>
Parses raw VCF record info.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of info fields.
Examples
use noodles_vcf::record::Info;
let info = Info::default();
assert_eq!(info.len(), 0);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether there are any info fields.
Examples
use noodles_vcf::record::Info;
let info = Info::default();
assert!(info.is_empty());
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all field from the info map.
This does not affect the capacity of the map.
Examples
use noodles_vcf::{
header::info::Key,
record::{info::{field::Value, Field}, Info},
};
let ns = Field::new(Key::SamplesWithDataCount, Some(Value::Integer(2)));
let dp = Field::new(Key::TotalDepth, Some(Value::Integer(13)));
let mut info = Info::try_from(vec![ns, dp])?;
assert!(!info.is_empty());
info.clear();
assert!(info.is_empty());
sourcepub fn get(&self, key: &Key) -> Option<&Field>
pub fn get(&self, key: &Key) -> Option<&Field>
Returns a reference to the field with the given key.
Examples
use noodles_vcf::{
header::info::Key,
record::{info::{field::Value, Field}, Info},
};
let ns = Field::new(Key::SamplesWithDataCount, Some(Value::Integer(2)));
let dp = Field::new(Key::TotalDepth, Some(Value::Integer(13)));
let info = Info::try_from(vec![ns, dp.clone()])?;
assert_eq!(info.get(&Key::TotalDepth), Some(&dp));
assert!(info.get(&Key::AlleleFrequencies).is_none());
sourcepub fn get_mut(&mut self, key: &Key) -> Option<&mut Field>
pub fn get_mut(&mut self, key: &Key) -> Option<&mut Field>
Returns a mutable reference to the field with the given key.
Examples
use noodles_vcf::{
header::info::Key,
record::{info::{field::Value, Field}, Info},
};
let ns = Field::new(Key::SamplesWithDataCount, Some(Value::Integer(2)));
let dp = Field::new(Key::TotalDepth, Some(Value::Integer(13)));
let mut info = Info::try_from(vec![ns, dp])?;
if let Some(dp) = info.get_mut(&Key::TotalDepth) {
*dp.value_mut() = Some(Value::Integer(8));
}
assert_eq!(
info.get(&Key::TotalDepth).map(|field| field.value()),
Some(Some(&Value::Integer(8)))
);
sourcepub fn get_index(&self, i: usize) -> Option<&Field>
pub fn get_index(&self, i: usize) -> Option<&Field>
Returns a reference to the field at the given index.
Examples
use noodles_vcf::{
header::info::Key,
record::{info::{field::Value, Field}, Info},
};
let ns = Field::new(Key::SamplesWithDataCount, Some(Value::Integer(2)));
let dp = Field::new(Key::TotalDepth, Some(Value::Integer(13)));
let info = Info::try_from(vec![ns, dp.clone()])?;
assert_eq!(info.get_index(1), Some(&dp));
assert!(info.get_index(5).is_none());
sourcepub fn get_index_mut(&mut self, i: usize) -> Option<&mut Field>
pub fn get_index_mut(&mut self, i: usize) -> Option<&mut Field>
Returns a mutable reference to the field at the given index.
Examples
use noodles_vcf::{
header::info::Key,
record::{info::{field::Value, Field}, Info},
};
let ns = Field::new(Key::SamplesWithDataCount, Some(Value::Integer(2)));
let dp = Field::new(Key::TotalDepth, Some(Value::Integer(13)));
let mut info = Info::try_from(vec![ns, dp])?;
if let Some(dp) = info.get_index_mut(1) {
*dp.value_mut() = Some(Value::Integer(8));
}
assert_eq!(
info.get_index(1).map(|field| field.value()),
Some(Some(&Value::Integer(8)))
);
sourcepub fn insert(&mut self, field: Field) -> Option<Field>
pub fn insert(&mut self, field: Field) -> Option<Field>
Inserts a field into the info.
This uses the field key as the key and field as the value.
If the key already exists in the map, the existing field is replaced by the new one, and the existing field is returned.
Examples
use noodles_vcf::{
header::info::Key,
record::{info::{field::Value, Field}, Info},
};
let ns = Field::new(Key::SamplesWithDataCount, Some(Value::Integer(2)));
let mut info = Info::try_from(vec![ns])?;
assert_eq!(info.len(), 1);
let dp = Field::new(Key::TotalDepth, Some(Value::Integer(13)));
info.insert(dp.clone());
assert_eq!(info.len(), 2);
assert_eq!(info.get(&Key::TotalDepth), Some(&dp));
sourcepub fn keys(&self) -> impl Iterator<Item = &Key>
pub fn keys(&self) -> impl Iterator<Item = &Key>
Returns an iterator over all keys.
Examples
use noodles_vcf::{
header::info::Key,
record::{info::{field::Value, Field}, Info},
};
let ns = Field::new(Key::SamplesWithDataCount, Some(Value::Integer(2)));
let dp = Field::new(Key::TotalDepth, Some(Value::Integer(13)));
let info = Info::try_from(vec![ns, dp.clone()])?;
let mut keys = info.keys();
assert_eq!(keys.next(), Some(&Key::SamplesWithDataCount));
assert_eq!(keys.next(), Some(&Key::TotalDepth));
assert!(keys.next().is_none());
sourcepub fn values(&self) -> impl Iterator<Item = &Field>
pub fn values(&self) -> impl Iterator<Item = &Field>
Returns an iterator over all fields.
Examples
use noodles_vcf::{
header::info::Key,
record::{info::{field::Value, Field}, Info},
};
let ns = Field::new(Key::SamplesWithDataCount, Some(Value::Integer(2)));
let dp = Field::new(Key::TotalDepth, Some(Value::Integer(13)));
let info = Info::try_from(vec![ns.clone(), dp.clone()])?;
let mut values = info.values();
assert_eq!(values.next(), Some(&ns));
assert_eq!(values.next(), Some(&dp));
assert!(values.next().is_none());