/// Re-index the neuron's samples in order of occurrence, starting at 1.
/// Returns error if the SWC is missing a parent sample
Re-index the neuron's samples in order of occurrence, starting at 1.
Returns error if the SWC is missing a parent sample
Re - index the neuron ' s samples in order of occurrence starting at 1 . Returns error if the SWC is missing a parent sample
pub fn reindex(self) -> Result<Self, MissingSampleError> {
        let old_to_new: HashMap<SampleId, SampleId> = self
            .samples
            .iter()
            .enumerate()
            .map(|(idx, row)| (row.sample_id, idx + 1))
            .collect();
        let mut samples = Vec::with_capacity(self.samples.len());
        for (idx, row) in self.samples.into_iter().enumerate() {
            let parent;
            if let Some(old) = row.parent_id {
                parent = Some(
                    *old_to_new
                        .get(&old)
                        .ok_or_else(|| MissingSampleError { parent_sample: old })?,
                );
            } else {
                parent = None;
            }
            samples.push(row.with_ids(idx + 1, parent));
        }
        Ok(Self {
            samples,
            header: self.header,
        })
    }
pub fn reindex ( self ) -> Result < Self , MissingSampleError > { let old_to_new : HashMap < SampleId , SampleId > = self . samples . iter ( ) . enumerate ( ) . map ( | ( idx , row ) | ( row . sample_id , idx + 1 ) ) . collect ( ) ; let mut samples = Vec :: with_capacity ( self . samples . len ( ) ) ; for ( idx , row ) in self . samples . into_iter ( ) . enumerate ( ) { let parent ; if let Some ( old ) = row . parent_id { parent = Some ( * old_to_new . get ( & old ) . ok_or_else ( | | MissingSampleError { parent_sample : old } ) ? , ) ; } else { parent = None ; } samples . push ( row . with_ids ( idx + 1 , parent ) ) ; } Ok ( Self { samples , header : self . header , } ) }
Re-index the neuron's samples in order of occurrence, starting at 1.
Re - index the neuron ' s samples in order of occurrence starting at 1 .
self