Struct cgats::Cgats

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

The CGATS data

Implementations§

source§

impl Cgats

source

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

pub fn de_report( &self, other: &Self, method: DEMethod, upper_pct: f32 ) -> Result<DeReport>

Calculate DeltaE and generate a report

source

pub fn can_delta(&self, other: &Self) -> Result<()>

Determine if it is possible to calculate DeltaE between two CGATS data sets.

source§

impl Cgats

source

pub fn new() -> Self

Creates a new empty Cgats object

source

pub fn with_capacity(cap: usize) -> Self

Creates a new empty Cgats object with the specified capacity

source

pub fn summary(&self) -> String

Returns a summary string:

Vendor[ColorTypes; n]

use cgats::Cgats;

let cgats: Cgats =
"CGATS.17
BEGIN_DATA_FORMAT
SAMPLE_ID	RGB_R	RGB_G	RGB_B
END_DATA_FORMAT
BEGIN_DATA
1	0	0	0
2	128	128	128
3	255	255	255
END_DATA"
.parse().unwrap();

assert_eq!(cgats.summary(), "Cgats[Rgb; 3]");
source

pub fn vendor(&self) -> &Vendor

Returns a reference the Vendor

source

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"));
source

pub fn get_metadata_mut(&mut self, key: &str) -> Option<&mut String>

Returns a mutable reference to a metadata value by key

source

pub fn insert_metadata_keyval<S: ToString, T: ToString>( &mut self, key: S, val: T )

Insert a MetaData Key:Value, overwriting if it exists

source

pub fn iter(&self) -> impl Iterator<Item = &DataPoint>

Iterator over the DataPoints in a Cgats object

source

pub fn iter_with_fields(&self) -> impl Iterator<Item = (&Field, &DataPoint)>

Iterator over the DataPoints 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);
source

pub fn iter_mut_with_fields( &mut self ) -> impl Iterator<Item = (Field, &mut DataPoint)>

Mutable iterator over the DataPoints 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));
source

pub fn fields(&self) -> impl Iterator<Item = &Field>

Iterator over the fields of the DataFormat

source

pub fn fields_mut(&mut self) -> impl Iterator<Item = &mut Field>

Mutable iterator over the fields of the DataFormat

source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut DataPoint>

Mutable iterator over the DataPoints in a Cgats object

source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>

Read a file into a Cgats object

source

pub fn to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>

Write a Cgats object to a file

source

pub fn write<W: Write>(&self, writer: &mut W) -> Result<()>

Write a Cgats object to a Write object

source

pub fn len(&self) -> usize

Returns the total number of data points in the set (rows x cols)

source

pub fn is_empty(&self) -> bool

Returns true if self.len() == 0

source

pub fn n_rows(&self) -> usize

Returns the total number of rows (samples) in the set

source

pub fn n_cols(&self) -> usize

Returns the total number of columns (fields) in the set

source

pub fn get_row(&self, row: usize) -> Option<impl Iterator<Item = &DataPoint>>

Iterator over the data points in a given sample row

source

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

source

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

source

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());
}
source

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);
}
source

pub fn transpose_chart(&mut self, chart_width: usize)

Re-order rows to transpose for chart layouts with a given current chart width (LGOROWLENGTH)

source

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

source

pub fn rows(&self) -> impl Iterator<Item = impl Iterator<Item = &DataPoint>>

Iterator over the rows of DataPoints

source

pub fn get_col(&self, col: usize) -> impl Iterator<Item = &DataPoint>

Returns an iterator over the data points in a given column (field)

source

pub fn get_col_by_field( &self, field: &Field ) -> Option<impl Iterator<Item = &DataPoint>>

Find a column by it’s Field. Returns None if the Field does not exist.

source

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)

source

pub fn get_col_mut_by_field( &mut self, field: &Field ) -> Option<impl Iterator<Item = &mut DataPoint>>

Find a mutable column by it’s Field. Returns None if the Field does not exist.

source

pub fn cols(&self) -> impl Iterator<Item = impl Iterator<Item = &DataPoint>>

Iterator over the columns of DataPoints

source

pub fn cols_with_fields( &self ) -> impl Iterator<Item = (&Field, impl Iterator<Item = &DataPoint>)>

Iterator over columns of DataPoints with their corresponding Fields

source

pub fn color_types(&self) -> Vec<ColorType>

Returns a list of ColorTypes based on the contents of the DATA_FORMAT

source

pub fn has_color_type(&self, color_type: &ColorType) -> bool

Determines if the data contains a ColorType

source

pub fn reindex_sample_id(&mut self)

Re-number the SAMPLE_ID field starting from 0

source

pub fn reindex_sample_id_at(&mut self, start: usize)

Re-number the SAMPLE_ID field starting from a given integer

source

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

source

pub fn insert_column( &mut self, index: usize, label: Field, iter: impl Iterator<Item = DataPoint> ) -> Result<()>

Insert a column of DataPoints

source

pub fn push_column( &mut self, field: Field, iter: impl Iterator<Item = DataPoint> ) -> Result<()>

Append a column of DataPoints

source

pub fn insert_row( &mut self, index: usize, iter: impl Iterator<Item = DataPoint> ) -> Result<()>

Insert a row of DataPoints at a row index

source

pub fn push_row(&mut self, iter: impl Iterator<Item = DataPoint>) -> Result<()>

Append a row of DataPoints

source

pub fn append(&mut self, other: &Cgats) -> Result<()>

Append the rows from another Cgats. Returns an error if the DataFormats do not match.

source

pub fn concatenate<'a>( root: &Cgats, other: impl Iterator<Item = &'a Cgats> ) -> Result<Self>

Concatenate the rows from multiple Cgats

source

pub fn to_colorburst(&self) -> Result<Self>

Convert the CGATS to a ColorBurst linearization format.

source

pub fn colorburst_to_cgats(&self) -> Result<Self>

Convert ColorBurst linearization format to a conventional CGATS format

Trait Implementations§

source§

impl CgatsFmt for Cgats

source§

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

Format data to a fmt::Formatter
source§

impl Clone for Cgats

source§

fn clone(&self) -> Cgats

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 Cgats

source§

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

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

impl Default for Cgats

source§

fn default() -> Self

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

impl Display for Cgats

source§

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

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

impl FromStr for Cgats

§

type Err = Box<dyn Error, Global>

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
source§

impl Index<(usize, usize)> for Cgats

source§

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);
§

type Output = DataPoint

The returned type after indexing.
source§

impl Index<usize> for Cgats

source§

fn index(&self, index: usize) -> &Self::Output

Index into Cgats by usize

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);
assert_eq!(cgats[5], 128);
assert_eq!(cgats[8], 255);
§

type Output = DataPoint

The returned type after indexing.
source§

impl IndexMut<(usize, usize)> for Cgats

source§

fn index_mut(&mut self, index: (usize, usize)) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl IndexMut<usize> for Cgats

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl PartialAdd<Cgats> for Cgats

§

type Output = Cgats

The output of a successfull add
source§

fn partial_add(&self, rhs: &Self) -> Option<Self::Output>

Try to add the two values
source§

impl PartialDiv<usize> for Cgats

§

type Output = Cgats

The output of a successful division
source§

fn partial_div(&self, rhs: &usize) -> Option<Self::Output>

Divides the values. Returns None if either value is not a type that can divide.
source§

impl PartialEq<Cgats> for Cgats

source§

fn eq(&self, other: &Cgats) -> 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 Eq for Cgats

source§

impl StructuralEq for Cgats

source§

impl StructuralPartialEq for Cgats

Auto Trait Implementations§

§

impl RefUnwindSafe for Cgats

§

impl Send for Cgats

§

impl Sync for Cgats

§

impl Unpin for Cgats

§

impl UnwindSafe for Cgats

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<'a, T> PartialSum<'a, T> for Twhere T: 'a + Clone + PartialAdd<T, Output = T>,

source§

fn partial_sum<I>(iter: I) -> Option<<T as PartialAdd<T>>::Output>where I: IntoIterator<Item = &'a T>,

Try to sum the values in the iterator
source§

impl<T> ToOwned for Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.