pub struct Metadata {
pub keywords: KeywordMap,
pub delimiter: char,
}Expand description
Contains keyword-value pairs and delimiter from the TEXT segment of an FCS file
The TEXT segment contains all metadata about the FCS file, including:
- File information (GUID, filename, cytometer type)
- Data structure information (number of events, parameters, data type, byte order)
- Parameter metadata (names, labels, ranges, transforms)
- Optional information (compensation matrices, timestamps, etc.)
Keywords are stored in a hashmap for fast lookup, with type-safe accessors for different keyword types (integer, float, string, byte, mixed).
Fields§
§keywords: KeywordMap§delimiter: charImplementations§
Source§impl Metadata
impl Metadata
pub fn new() -> Self
Sourcepub fn print_sorted_by_keyword(&self)
pub fn print_sorted_by_keyword(&self)
Prints all keywords sorted alphabetically by key name
This is a debugging utility that displays all keyword-value pairs in the metadata, sorted for easy reading.
Sourcepub fn from_mmap(mmap: &Mmap, header: &Header) -> Self
pub fn from_mmap(mmap: &Mmap, header: &Header) -> Self
Reads the text segment of the fcs file and returns an Metadata struct
Uses memchr for fast delimiter finding (5-10x faster than byte-by-byte iteration)
Sourcepub fn validate_text_segment_keywords(&self, header: &Header) -> Result<()>
pub fn validate_text_segment_keywords(&self, header: &Header) -> Result<()>
Check that required keys are present in the TEXT segment of the metadata
§Errors
Will return Err if:
- any of the required keywords are missing from the keywords hashmap
- the number of parameters can’t be obtained from the $PAR keyword in the TEXT section
- any keyword has a Pn[X] value where n is greater than the number of parameters indicated by the $PAR keyword
Sourcepub fn validate_guid(&mut self)
pub fn validate_guid(&mut self)
Validates if a GUID is present in the file’s metadata, and if not, generates a new one.
Sourcepub fn get_number_of_parameters(&self) -> Result<&usize>
pub fn get_number_of_parameters(&self) -> Result<&usize>
Return the number of parameters in the file from the $PAR keyword in the metadata TEXT section
§Errors
Will return Err if the $PAR keyword is not present in the metadata keywords hashmap
Sourcepub fn get_number_of_events(&self) -> Result<&usize>
pub fn get_number_of_events(&self) -> Result<&usize>
Return the number of events in the file from the $TOT keyword in the metadata TEXT section
§Errors
Will return Err if the $TOT keyword is not present in the metadata keywords hashmap
Sourcepub fn get_data_type(&self) -> Result<&FcsDataType>
pub fn get_data_type(&self) -> Result<&FcsDataType>
Return the data type from the $DATATYPE keyword in the metadata TEXT section, unwraps and returns it if it exists.
§Errors
Will return Err if the $DATATYPE keyword is not present in the metadata keywords hashmap
Sourcepub fn get_data_type_for_channel(
&self,
parameter_number: usize,
) -> Result<FcsDataType>
pub fn get_data_type_for_channel( &self, parameter_number: usize, ) -> Result<FcsDataType>
Get the data type for a specific channel/parameter (FCS 3.2+)
First checks for $PnDATATYPE keyword to see if this parameter has a specific data type override.
If not found, falls back to the default $DATATYPE keyword.
§Arguments
parameter_number- 1-based parameter index
§Errors
Will return Err if neither $PnDATATYPE nor $DATATYPE is present
Sourcepub fn calculate_bytes_per_event(&self) -> Result<usize>
pub fn calculate_bytes_per_event(&self) -> Result<usize>
Calculate the total bytes per event by summing bytes per parameter
Uses $PnB (bits per parameter) divided by 8 to get bytes per parameter,
then sums across all parameters. This is more accurate than using $DATATYPE
which only provides a default value.
§Errors
Will return Err if the number of parameters cannot be determined or
if any required $PnB keyword is missing
Sourcepub fn get_bytes_per_parameter(&self, parameter_number: usize) -> Result<usize>
pub fn get_bytes_per_parameter(&self, parameter_number: usize) -> Result<usize>
Sourcepub fn get_byte_order(&self) -> Result<&ByteOrder>
pub fn get_byte_order(&self) -> Result<&ByteOrder>
Return the byte order from the $BYTEORD keyword in the metadata TEXT section, unwraps and returns it if it exists.
§Errors
Will return Err if the $BYTEORD keyword is not present in the keywords hashmap
Sourcepub fn get_integer_keyword(&self, keyword: &str) -> Result<&IntegerKeyword>
pub fn get_integer_keyword(&self, keyword: &str) -> Result<&IntegerKeyword>
Returns a keyword that holds numeric data from the keywords hashmap, if it exists
§Errors
Will return Err if the keyword is not present in the keywords hashmap
Sourcepub fn get_float_keyword(&self, keyword: &str) -> Result<&FloatKeyword>
pub fn get_float_keyword(&self, keyword: &str) -> Result<&FloatKeyword>
Returns a keyword that holds numeric data from the keywords hashmap, if it exists
§Errors
Will return Err if the keyword is not present in the keywords hashmap
Sourcepub fn get_string_keyword(&self, keyword: &str) -> Result<&StringKeyword>
pub fn get_string_keyword(&self, keyword: &str) -> Result<&StringKeyword>
Returns a keyword that holds string data from the keywords hashmap, if it exists
§Errors
Will return Err if the keyword is not present in the keywords hashmap
Sourcepub fn get_byte_keyword(&self, keyword: &str) -> Result<&ByteKeyword>
pub fn get_byte_keyword(&self, keyword: &str) -> Result<&ByteKeyword>
Returns a keyword that holds byte-orientation data from the keywords hashmap, if it exists
§Errors
Will return Err if the keyword is not present in the keywords hashmap
Sourcepub fn get_mixed_keyword(&self, keyword: &str) -> Result<&MixedKeyword>
pub fn get_mixed_keyword(&self, keyword: &str) -> Result<&MixedKeyword>
Returns a keyword that holds mixed data from the keywords hashmap, if it exists
§Errors
Will return Err if the keyword is not present in the keywords hashmap
Sourcepub fn get_parameter_string_metadata(
&self,
parameter_number: usize,
suffix: &str,
) -> Result<&StringKeyword>
pub fn get_parameter_string_metadata( &self, parameter_number: usize, suffix: &str, ) -> Result<&StringKeyword>
General function to get a given parameter’s string keyword from the file’s metadata (e.g. $PnN or $PnS)
§Errors
Will return Err if the keyword is not present in the keywords hashmap
Sourcepub fn get_parameter_numeric_metadata(
&self,
parameter_number: usize,
suffix: &str,
) -> Result<&IntegerKeyword>
pub fn get_parameter_numeric_metadata( &self, parameter_number: usize, suffix: &str, ) -> Result<&IntegerKeyword>
Generic function to get a given parameter’s integer keyword from the file’s metadata (e.g. $PnN, $PnS, $PnDATATYPE)
§Errors
Will return Err if the keyword is not present in the keywords hashmap
Sourcepub fn get_parameter_excitation_wavelength(
&self,
parameter_number: usize,
) -> Result<Option<usize>>
pub fn get_parameter_excitation_wavelength( &self, parameter_number: usize, ) -> Result<Option<usize>>
Get excitation wavelength(s) for a parameter from $PnL keyword
Returns the first wavelength if multiple are present (for co-axial lasers)
§Errors
Will return Err if the keyword is not present in the keywords hashmap
Sourcepub fn get_parameter_channel_name(
&self,
parameter_number: usize,
) -> Result<&str>
pub fn get_parameter_channel_name( &self, parameter_number: usize, ) -> Result<&str>
Return the name of the parameter’s channel from the $PnN keyword in the metadata TEXT section, where n is the provided parameter index (1-based)
§Errors
Will return Err if the keyword is not present in the keywords hashmap
Sourcepub fn get_parameter_label(&self, parameter_number: usize) -> Result<&str>
pub fn get_parameter_label(&self, parameter_number: usize) -> Result<&str>
Return the label name of the parameter from the $PnS keyword in the metadata TEXT section, where n is the provided parameter number
§Errors
Will return Err if the keyword is not present in the keywords hashmap
Sourcepub fn get_metadata_as_json_string(&self) -> Result<String>
pub fn get_metadata_as_json_string(&self) -> Result<String>
Transform the metadata keywords hashmap into a JSON object via serde
§Errors
Will return Err if the metadata keywords hashmap is empty
Sourcepub fn insert_string_keyword(&mut self, key: String, value: String)
pub fn insert_string_keyword(&mut self, key: String, value: String)
Insert or update a string keyword in the metadata
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Metadata
impl<'de> Deserialize<'de> for Metadata
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Metadata
impl RefUnwindSafe for Metadata
impl Send for Metadata
impl Sync for Metadata
impl Unpin for Metadata
impl UnwindSafe for Metadata
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more