pub struct BinaryArrayMap {
pub byte_buffer_map: HashMap<ArrayType, DataArray>,
}Expand description
A collection of DataArrays that are identified by name.
§Examples
use mzdata_bindata::{ArrayType, BinaryArrayMap, BinaryDataArrayType, DataArray};
let mut map = BinaryArrayMap::new();
assert!(!map.has_array(&ArrayType::MZArray));
let array = DataArray::from_name_and_type(&ArrayType::MZArray, BinaryDataArrayType::Float64);
map.add(array);
assert!(map.has_array(&ArrayType::MZArray));
assert_eq!(map.len(), 1);Fields§
§byte_buffer_map: HashMap<ArrayType, DataArray>Implementations§
Source§impl BinaryArrayMap
impl BinaryArrayMap
pub fn new() -> BinaryArrayMap
pub fn is_empty(&self) -> bool
Sourcepub fn has_ion_mobility(&self) -> bool
pub fn has_ion_mobility(&self) -> bool
Check if there is an ion mobility array present
Sourcepub fn iter(&self) -> Iter<'_, ArrayType, DataArray> ⓘ
pub fn iter(&self) -> Iter<'_, ArrayType, DataArray> ⓘ
Iterate over references to the key-value pairs of this map
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, ArrayType, DataArray> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, ArrayType, DataArray> ⓘ
Iterate over mutable references to the key-value pairs of this map
Sourcepub fn encode_array(
&mut self,
array_type: &ArrayType,
compression: BinaryCompressionType,
) -> Result<(), ArrayRetrievalError>
pub fn encode_array( &mut self, array_type: &ArrayType, compression: BinaryCompressionType, ) -> Result<(), ArrayRetrievalError>
Sourcepub fn decode_all_arrays(&mut self) -> Result<(), ArrayRetrievalError>
pub fn decode_all_arrays(&mut self) -> Result<(), ArrayRetrievalError>
Decode all DataArray in this map if they have not been decoded already so
that they are ready for use. If there are many arrays and the parallelism feature
is enabled, arrays may be decoded in parallel.
§Examples
use mzdata_bindata::{ArrayType, BinaryArrayMap, BinaryCompressionType, BinaryDataArrayType, DataArray};
let mut mz_array = DataArray::from_name_and_type(&ArrayType::MZArray, BinaryDataArrayType::Float64);
mz_array.extend(&[1.0f64, 2.0, 3.0]).unwrap();
mz_array.store_compressed(BinaryCompressionType::Zlib).unwrap();
let mut map = BinaryArrayMap::new();
map.add(mz_array);
assert_eq!(map.get(&ArrayType::MZArray).unwrap().compression, BinaryCompressionType::Zlib);
map.decode_all_arrays().unwrap();
assert_eq!(map.get(&ArrayType::MZArray).unwrap().compression, BinaryCompressionType::Decoded);Sourcepub fn decode_array(
&mut self,
array_type: &ArrayType,
) -> Result<(), ArrayRetrievalError>
pub fn decode_array( &mut self, array_type: &ArrayType, ) -> Result<(), ArrayRetrievalError>
Decode a specific DataArray if it is present.
This method may fail if decoding fails or if the array type is missing.
Sourcepub fn get(&self, array_type: &ArrayType) -> Option<&DataArray>
pub fn get(&self, array_type: &ArrayType) -> Option<&DataArray>
Get a reference to a specific DataArray if present
Sourcepub fn get_mut(&mut self, array_type: &ArrayType) -> Option<&mut DataArray>
pub fn get_mut(&mut self, array_type: &ArrayType) -> Option<&mut DataArray>
Get a mutable reference to a specific DataArray if present
Sourcepub fn has_array(&self, array_type: &ArrayType) -> bool
pub fn has_array(&self, array_type: &ArrayType) -> bool
Check whether a specific ArrayType is present
Sourcepub fn search(&self, query: f64, error_tolerance: Tolerance) -> Option<usize>
pub fn search(&self, query: f64, error_tolerance: Tolerance) -> Option<usize>
Search for a specific m/z within a specified Tolerance.
This effectively calls BinaryArrayMap::mzs to get the m/z array and then
performs a binary search to find the best index within range, if one exists.
Sourcepub fn mzs(&self) -> Result<Cow<'_, [f64]>, ArrayRetrievalError>
pub fn mzs(&self) -> Result<Cow<'_, [f64]>, ArrayRetrievalError>
Get a reference to the m/z array if it is present
§Examples
use mzdata_bindata::{ArrayType, BinaryArrayMap, BinaryDataArrayType, DataArray};
let mut mz_array = DataArray::from_name_and_type(&ArrayType::MZArray, BinaryDataArrayType::Float64);
mz_array.extend(&[100.0f64, 200.0, 300.0]).unwrap();
let mut map = BinaryArrayMap::new();
map.add(mz_array);
assert_eq!(&*map.mzs().unwrap(), &[100.0f64, 200.0, 300.0][..]);Sourcepub fn sort_from_indices(
&mut self,
mask: Vec<usize>,
) -> Result<(), ArrayRetrievalError>
pub fn sort_from_indices( &mut self, mask: Vec<usize>, ) -> Result<(), ArrayRetrievalError>
Re-order all arrays of matching length with respect to the provided index mask operating
on the decoded native value states.
The mask would be created using an indirect sort from another array:
let vals = self.mzs().unwrap();
let n = vals.len();
let mut mask: Vec<usize> = (0..n).into_iter().collect();
mask.sort_by(|i, j| {
let a = vals[*i];
let b = vals[*j];
a.total_cmp(&b)
});
drop(vals);
self.sort_from_indices(mask)Sourcepub fn sort_by_array(
&mut self,
name: &ArrayType,
) -> Result<(), ArrayRetrievalError>
pub fn sort_by_array( &mut self, name: &ArrayType, ) -> Result<(), ArrayRetrievalError>
Sort all the arrays in the map by name if they are the same length. This operates
on the decoded state directly.
This builds the sorting mask and then leaves Self::sort_from_indices to perform
the re-ordering.
Not supported for BinaryDataArrayType::ASCII and BinaryDataArrayType::Unknown.
Sourcepub fn mzs_mut(&mut self) -> Result<&mut [f64], ArrayRetrievalError>
pub fn mzs_mut(&mut self) -> Result<&mut [f64], ArrayRetrievalError>
Get a mutable reference to the m/z array if it is present.
This method obtains the m/z array, calls DataArray::decode_and_store to force
the data to be stored natively in memory, and forces the storage to be
BinaryDataArrayType::Float64 if not already. Finally it returns a mutable
view of that decoded dataas &mut [f64]
Sourcepub fn intensities(&self) -> Result<Cow<'_, [f32]>, ArrayRetrievalError>
pub fn intensities(&self) -> Result<Cow<'_, [f32]>, ArrayRetrievalError>
Get a reference to the intensity array if it is present
Sourcepub fn intensities_mut(&mut self) -> Result<&mut [f32], ArrayRetrievalError>
pub fn intensities_mut(&mut self) -> Result<&mut [f32], ArrayRetrievalError>
Get a mutable reference to the intensity array if it is present.
See BinaryArrayMap::mzs_mut for an explanation of the intermediate steps,
save that the forced storage type is [BinaryArrayDataType::Float32].
Sourcepub fn charges(&self) -> Result<Cow<'_, [i32]>, ArrayRetrievalError>
pub fn charges(&self) -> Result<Cow<'_, [i32]>, ArrayRetrievalError>
Get a reference to the charge array if it is present
Sourcepub fn charge_mut(&mut self) -> Result<&mut [i32], ArrayRetrievalError>
pub fn charge_mut(&mut self) -> Result<&mut [i32], ArrayRetrievalError>
Get a mutable reference to the charge array if it is present.
See BinaryArrayMap::mzs_mut for an explanation of the intermediate steps,
save that the forced storage type is [BinaryArrayDataType::Int32].
Sourcepub fn ion_mobility(
&self,
) -> Result<(Cow<'_, [f64]>, ArrayType), ArrayRetrievalError>
pub fn ion_mobility( &self, ) -> Result<(Cow<'_, [f64]>, ArrayType), ArrayRetrievalError>
Get a reference to the ion mobility array if it is present
Sourcepub fn ion_mobility_mut(
&mut self,
) -> Result<(&mut [f64], ArrayType), ArrayRetrievalError>
pub fn ion_mobility_mut( &mut self, ) -> Result<(&mut [f64], ArrayType), ArrayRetrievalError>
Get a mutable reference to the ion mobility array if it is present.
See BinaryArrayMap::mzs_mut for an explanation of the intermediate steps.
Sourcepub fn stack_ion_mobility(self) -> Result<BinaryArrayMap3D, ArrayRetrievalError>
pub fn stack_ion_mobility(self) -> Result<BinaryArrayMap3D, ArrayRetrievalError>
Split an array map along the ion mobility dimension if it is present.
This function will fail if there is no ion mobility dimension.
Trait Implementations§
Source§impl Clone for BinaryArrayMap
impl Clone for BinaryArrayMap
Source§impl Debug for BinaryArrayMap
impl Debug for BinaryArrayMap
Source§impl Default for BinaryArrayMap
impl Default for BinaryArrayMap
Source§impl<C: CentroidLike + From<CentroidPeak>> From<&BinaryArrayMap> for MZPeakSetType<C>
impl<C: CentroidLike + From<CentroidPeak>> From<&BinaryArrayMap> for MZPeakSetType<C>
Source§fn from(arrays: &BinaryArrayMap) -> MZPeakSetType<C>
fn from(arrays: &BinaryArrayMap) -> MZPeakSetType<C>
Source§impl From<&BinaryArrayMap> for DeconvolutedPeakSet
impl From<&BinaryArrayMap> for DeconvolutedPeakSet
Source§fn from(arrays: &BinaryArrayMap) -> DeconvolutedPeakSet
fn from(arrays: &BinaryArrayMap) -> DeconvolutedPeakSet
Source§impl From<&PeakSetVec<CentroidPeak, MZ>> for BinaryArrayMap
impl From<&PeakSetVec<CentroidPeak, MZ>> for BinaryArrayMap
Source§fn from(peaks: &PeakSet) -> BinaryArrayMap
fn from(peaks: &PeakSet) -> BinaryArrayMap
Source§impl From<&PeakSetVec<DeconvolutedPeak, Mass>> for BinaryArrayMap
impl From<&PeakSetVec<DeconvolutedPeak, Mass>> for BinaryArrayMap
Source§fn from(peaks: &DeconvolutedPeakSet) -> BinaryArrayMap
fn from(peaks: &DeconvolutedPeakSet) -> BinaryArrayMap
Source§impl<C: CentroidLike + From<CentroidPeak>> From<BinaryArrayMap> for MZPeakSetType<C>
impl<C: CentroidLike + From<CentroidPeak>> From<BinaryArrayMap> for MZPeakSetType<C>
Source§fn from(arrays: BinaryArrayMap) -> MZPeakSetType<C>
fn from(arrays: BinaryArrayMap) -> MZPeakSetType<C>
Source§impl IntoIterator for BinaryArrayMap
impl IntoIterator for BinaryArrayMap
Source§impl TryFrom<&BinaryArrayMap3D> for BinaryArrayMap
A BinaryArrayMap aliases TryFrom on BinaryArrayMap3D with BinaryArrayMap3D::unstack
impl TryFrom<&BinaryArrayMap3D> for BinaryArrayMap
A BinaryArrayMap aliases TryFrom on BinaryArrayMap3D with BinaryArrayMap3D::unstack
Source§type Error = ArrayRetrievalError
type Error = ArrayRetrievalError
Source§impl TryFrom<&BinaryArrayMap> for BinaryArrayMap3D
A BinaryArrayMap3D aliases TryFrom on BinaryArrayMap with BinaryArrayMap3D::stack
impl TryFrom<&BinaryArrayMap> for BinaryArrayMap3D
A BinaryArrayMap3D aliases TryFrom on BinaryArrayMap with BinaryArrayMap3D::stack
Source§type Error = ArrayRetrievalError
type Error = ArrayRetrievalError
Source§impl TryFrom<BinaryArrayMap3D> for BinaryArrayMap
impl TryFrom<BinaryArrayMap3D> for BinaryArrayMap
Source§type Error = ArrayRetrievalError
type Error = ArrayRetrievalError
Source§impl TryFrom<BinaryArrayMap> for BinaryArrayMap3D
impl TryFrom<BinaryArrayMap> for BinaryArrayMap3D
Source§fn try_from(value: BinaryArrayMap) -> Result<Self, Self::Error>
fn try_from(value: BinaryArrayMap) -> Result<Self, Self::Error>
A wrapper around BinaryArrayMap3D::stack