pub struct Cgats { /* private fields */ }
Expand description
The CGATS data
Implementations§
source§impl Cgats
impl Cgats
sourcepub fn delta(&self, other: &Self, method: DEMethod) -> Result<Self>
pub fn delta(&self, other: &Self, method: DEMethod) -> Result<Self>
Calculate the DeltaE between each value of two CGATS data sets.
Returns an error if either of the two sets do not contain Lab
data.
source§impl Cgats
impl Cgats
sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates a new empty Cgats
object with the specified capacity
sourcepub fn get_metadata<'a>(&'a self, key: &str) -> Option<&'a str>
pub fn get_metadata<'a>(&'a self, key: &str) -> Option<&'a str>
Find the MetaData
value by key
use cgats::Cgats;
let cgats: Cgats =
"CGATS.17
NUMBER_OF_FIELDS 4
BEGIN_DATA_FORMAT
SAMPLE_ID RGB_R RGB_G RGB_B
END_DATA_FORMAT
NUMBER_OF_SETS 3
BEGIN_DATA
1 0 0 0
2 128 128 128
3 255 255 255
END_DATA"
.parse().unwrap();
assert_eq!(cgats.get_metadata("NUMBER_OF_FIELDS"), Some("4"));
assert_eq!(cgats.get_metadata("NUMBER_OF_SETS"), Some("3"));
sourcepub fn get_metadata_mut(&mut self, key: &str) -> Option<&mut String>
pub fn get_metadata_mut(&mut self, key: &str) -> Option<&mut String>
Returns a mutable reference to a metadata value by key
sourcepub fn insert_metadata_keyval<S: ToString, T: ToString>(
&mut self,
key: S,
val: T
)
pub fn insert_metadata_keyval<S: ToString, T: ToString>( &mut self, key: S, val: T )
Insert a MetaData Key:Value, overwriting if it exists
sourcepub fn iter_with_fields(&self) -> impl Iterator<Item = (&Field, &DataPoint)>
pub fn iter_with_fields(&self) -> impl Iterator<Item = (&Field, &DataPoint)>
Iterator over the DataPoint
s with their corresponding Field
keys
use cgats::{Cgats, Field::*, DataPoint::*};
let cgats: Cgats =
"CGATS.17
BEGIN_DATA_FORMAT
SAMPLE_ID DE2000
END_DATA_FORMAT
BEGIN_DATA
1 1.23
2 3.21
END_DATA"
.parse().unwrap();
let mut iter = cgats.iter_with_fields();
assert_eq!(iter.next(), Some((&SAMPLE_ID, &Int(1))));
assert_eq!(iter.next(), Some((&DE_2000, &Float(1.23))));
assert_eq!(iter.next(), Some((&SAMPLE_ID, &Int(2))));
assert_eq!(iter.next(), Some((&DE_2000, &Float(3.21))));
assert_eq!(iter.next(), None);
sourcepub fn iter_mut_with_fields(
&mut self
) -> impl Iterator<Item = (Field, &mut DataPoint)>
pub fn iter_mut_with_fields( &mut self ) -> impl Iterator<Item = (Field, &mut DataPoint)>
Mutable iterator over the DataPoint
s with their corresponding Field
keys.
Field
values are cloned.
use cgats::{Cgats, Field::*, DataPoint::*};
let mut cgats: Cgats =
"CGATS.17
BEGIN_DATA_FORMAT
SAMPLE_ID DE2000
END_DATA_FORMAT
BEGIN_DATA
1 1.23
2 3.21
END_DATA"
.parse().unwrap();
{
let mut iter = cgats.iter_mut_with_fields();
assert_eq!(iter.next(), Some((SAMPLE_ID, &mut Int(1))));
assert_eq!(iter.next(), Some((DE_2000, &mut Float(1.23))));
assert_eq!(iter.next(), Some((SAMPLE_ID, &mut Int(2))));
if let Some((_field, data_point)) = iter.next() {
*data_point = Float(4.56);
}
assert_eq!(iter.next(), None);
}
assert_eq!(cgats[3], Float(4.56));
sourcepub fn fields(&self) -> impl Iterator<Item = &Field>
pub fn fields(&self) -> impl Iterator<Item = &Field>
Iterator over the fields of the DataFormat
sourcepub fn fields_mut(&mut self) -> impl Iterator<Item = &mut Field>
pub fn fields_mut(&mut self) -> impl Iterator<Item = &mut Field>
Mutable iterator over the fields of the DataFormat
sourcepub fn get_row(&self, row: usize) -> Option<impl Iterator<Item = &DataPoint>>
pub fn get_row(&self, row: usize) -> Option<impl Iterator<Item = &DataPoint>>
Iterator over the data points in a given sample row
sourcepub fn get_row_by_values<F: AsRef<Field>, D: AsRef<DataPoint>>(
&self,
fields_values: &[(F, D)]
) -> Option<impl Iterator<Item = &DataPoint>>
pub fn get_row_by_values<F: AsRef<Field>, D: AsRef<DataPoint>>( &self, fields_values: &[(F, D)] ) -> Option<impl Iterator<Item = &DataPoint>>
Returns the first row containing the given values
sourcepub fn get_row_index_by_values<F: AsRef<Field>, D: AsRef<DataPoint>>(
&self,
fields_values: &[(F, D)]
) -> Option<usize>
pub fn get_row_index_by_values<F: AsRef<Field>, D: AsRef<DataPoint>>( &self, fields_values: &[(F, D)] ) -> Option<usize>
Returns a row index to the first row containing the given values
sourcepub fn remove_row(
&mut self,
row: usize
) -> Option<impl Iterator<Item = DataPoint> + '_>
pub fn remove_row( &mut self, row: usize ) -> Option<impl Iterator<Item = DataPoint> + '_>
Remove a row from a sample set by row index and return the row. Returns none if the row index is greater than or equal to the number of rows.
use cgats::Cgats;
let mut cgats: Cgats =
"CGATS.17
BEGIN_DATA_FORMAT
SAMPLE_ID DE2000
END_DATA_FORMAT
BEGIN_DATA
1 1.23
2 3.21
3 4.56
END_DATA"
.parse().unwrap();
{
let mut row = cgats.remove_row(1).unwrap();
assert_eq!(row.next().unwrap(), 2);
assert_eq!(row.next().unwrap(), 3.21);
assert_eq!(row.next(), None);
}
{
let mut row = cgats.remove_row(1).unwrap();
assert_eq!(row.next().unwrap(), 3);
assert_eq!(row.next().unwrap(), 4.56);
assert_eq!(row.next(), None);
}
{
assert!(cgats.remove_row(1).is_none());
}
sourcepub fn move_row(&mut self, from_row: usize, to_row: usize) -> Result<()>
pub fn move_row(&mut self, from_row: usize, to_row: usize) -> Result<()>
Move a row from one row index to another. Returns an error if the indices are out of range
use cgats::Cgats;
let mut cgats: Cgats =
"CGATS.17
BEGIN_DATA_FORMAT
SAMPLE_ID DE2000
END_DATA_FORMAT
BEGIN_DATA
1 1.23
2 3.21
3 4.56
END_DATA"
.parse().unwrap();
cgats.move_row(2, 1).unwrap();
{
let mut last_row = cgats.get_row(2).unwrap();
assert_eq!(last_row.next().unwrap(), &2);
assert_eq!(last_row.next().unwrap(), &3.21);
assert_eq!(last_row.next(), None);
}
cgats.move_row(0, 2).unwrap();
{
let mut last_row = cgats.get_row(2).unwrap();
assert_eq!(last_row.next().unwrap(), &1);
assert_eq!(last_row.next().unwrap(), &1.23);
assert_eq!(last_row.next(), None);
}
sourcepub fn transpose_chart(&mut self, chart_width: usize)
pub fn transpose_chart(&mut self, chart_width: usize)
Re-order rows to transpose for chart layouts with a given current chart width (LGOROWLENGTH
)
sourcepub fn get_row_mut(
&mut self,
row: usize
) -> impl Iterator<Item = &mut DataPoint>
pub fn get_row_mut( &mut self, row: usize ) -> impl Iterator<Item = &mut DataPoint>
Iterator of mutable references to data points in a given sample row
sourcepub fn rows(&self) -> impl Iterator<Item = impl Iterator<Item = &DataPoint>>
pub fn rows(&self) -> impl Iterator<Item = impl Iterator<Item = &DataPoint>>
Iterator over the rows of DataPoint
s
sourcepub fn get_col(&self, col: usize) -> impl Iterator<Item = &DataPoint>
pub fn get_col(&self, col: usize) -> impl Iterator<Item = &DataPoint>
Returns an iterator over the data points in a given column (field)
sourcepub fn get_col_mut(
&mut self,
col: usize
) -> impl Iterator<Item = &mut DataPoint>
pub fn get_col_mut( &mut self, col: usize ) -> impl Iterator<Item = &mut DataPoint>
Iterator of mutable references to data points in a given column (field)
sourcepub fn get_col_mut_by_field(
&mut self,
field: &Field
) -> Option<impl Iterator<Item = &mut DataPoint>>
pub fn get_col_mut_by_field( &mut self, field: &Field ) -> Option<impl Iterator<Item = &mut DataPoint>>
sourcepub fn cols(&self) -> impl Iterator<Item = impl Iterator<Item = &DataPoint>>
pub fn cols(&self) -> impl Iterator<Item = impl Iterator<Item = &DataPoint>>
Iterator over the columns of DataPoint
s
sourcepub fn cols_with_fields(
&self
) -> impl Iterator<Item = (&Field, impl Iterator<Item = &DataPoint>)>
pub fn cols_with_fields( &self ) -> impl Iterator<Item = (&Field, impl Iterator<Item = &DataPoint>)>
sourcepub fn color_types(&self) -> Vec<ColorType>
pub fn color_types(&self) -> Vec<ColorType>
Returns a list of ColorType
s based on the contents of the DATA_FORMAT
sourcepub fn has_color_type(&self, color_type: &ColorType) -> bool
pub fn has_color_type(&self, color_type: &ColorType) -> bool
Determines if the data contains a ColorType
sourcepub fn reindex_sample_id(&mut self)
pub fn reindex_sample_id(&mut self)
Re-number the SAMPLE_ID
field starting from 0
sourcepub fn reindex_sample_id_at(&mut self, start: usize)
pub fn reindex_sample_id_at(&mut self, start: usize)
Re-number the SAMPLE_ID
field starting from a given integer
sourcepub fn index_by_field(&self, field: &Field) -> Option<usize>
pub fn index_by_field(&self, field: &Field) -> Option<usize>
Returns the position of a column with a given Field
Returns None
if the DataFormat
does not contain the Field
sourcepub fn insert_column(
&mut self,
index: usize,
label: Field,
iter: impl Iterator<Item = DataPoint>
) -> Result<()>
pub fn insert_column( &mut self, index: usize, label: Field, iter: impl Iterator<Item = DataPoint> ) -> Result<()>
Insert a column of DataPoint
s
sourcepub fn push_column(
&mut self,
field: Field,
iter: impl Iterator<Item = DataPoint>
) -> Result<()>
pub fn push_column( &mut self, field: Field, iter: impl Iterator<Item = DataPoint> ) -> Result<()>
Append a column of DataPoint
s
sourcepub fn insert_row(
&mut self,
index: usize,
iter: impl Iterator<Item = DataPoint>
) -> Result<()>
pub fn insert_row( &mut self, index: usize, iter: impl Iterator<Item = DataPoint> ) -> Result<()>
Insert a row of DataPoint
s at a row index
sourcepub fn push_row(&mut self, iter: impl Iterator<Item = DataPoint>) -> Result<()>
pub fn push_row(&mut self, iter: impl Iterator<Item = DataPoint>) -> Result<()>
Append a row of DataPoint
s
sourcepub fn append(&mut self, other: &Cgats) -> Result<()>
pub fn append(&mut self, other: &Cgats) -> Result<()>
Append the rows from another Cgats
. Returns an error if the DataFormat
s do not
match.
sourcepub fn concatenate<'a>(
root: &Cgats,
other: impl Iterator<Item = &'a Cgats>
) -> Result<Self>
pub fn concatenate<'a>( root: &Cgats, other: impl Iterator<Item = &'a Cgats> ) -> Result<Self>
Concatenate the rows from multiple Cgats
sourcepub fn to_colorburst(&self) -> Result<Self>
pub fn to_colorburst(&self) -> Result<Self>
Convert the CGATS to a ColorBurst linearization format.
sourcepub fn colorburst_to_cgats(&self) -> Result<Self>
pub fn colorburst_to_cgats(&self) -> Result<Self>
Convert ColorBurst linearization format to a conventional CGATS format
Trait Implementations§
source§impl Index<(usize, usize)> for Cgats
impl Index<(usize, usize)> for Cgats
source§fn index(&self, index: (usize, usize)) -> &Self::Output
fn index(&self, index: (usize, usize)) -> &Self::Output
Index into Cgats
by (column, row)
use cgats::Cgats;
let mut cgats: Cgats =
"CGATS.17
BEGIN_DATA_FORMAT
RGB_R RGB_G RGB_B
END_DATA_FORMAT
BEGIN_DATA
0 1 2
126 127 128
253 254 255
END_DATA"
.parse().unwrap();
assert_eq!(cgats[(0, 0)], 0);
assert_eq!(cgats[(2, 1)], 128);
assert_eq!(cgats[(2, 2)], 255);