morphology.h
1 #pragma once
2 
3 #include <map>
4 #include <memory>
5 #include <string>
6 #include <unordered_map>
7 #include <vector>
8 
9 #include <morphio/errorMessages.h>
10 #include <morphio/exceptions.h>
11 #include <morphio/mut/endoplasmic_reticulum.h>
12 #include <morphio/mut/mitochondria.h>
13 #include <morphio/mut/modifiers.h>
14 #include <morphio/mut/soma.h>
15 #include <morphio/properties.h>
16 #include <morphio/types.h>
17 
18 namespace morphio {
19 namespace mut {
20 // TODO: not sure why this is here
21 bool _checkDuplicatePoint(const std::shared_ptr<Section>& parent,
22  const std::shared_ptr<Section>& current);
23 
26 {
27  public:
28  Morphology()
29  : _soma(std::make_shared<Soma>())
30  , _cellProperties(
31  std::make_shared<morphio::Property::CellLevel>(morphio::Property::CellLevel())) {}
32 
42  explicit Morphology(const std::string& uri, unsigned int options = NO_MODIFIER);
43 
45  explicit Morphology(const HighFive::Group& group, unsigned int options = NO_MODIFIER);
46 
48  Morphology(const morphio::mut::Morphology& morphology, unsigned int options = NO_MODIFIER);
49 
51  explicit Morphology(const morphio::Morphology& morphology, unsigned int options = NO_MODIFIER);
52 
53  virtual ~Morphology();
54 
56  const std::vector<std::shared_ptr<Section>>& rootSections() const noexcept {
57  return _rootSections;
58  }
59 
61  const std::map<uint32_t, std::shared_ptr<Section>>& sections() const noexcept {
62  return _sections;
63  }
64 
70  std::shared_ptr<Soma>& soma() noexcept {
71  return _soma;
72  }
73 
79  const std::shared_ptr<Soma>& soma() const noexcept {
80  return _soma;
81  }
82 
84  Mitochondria& mitochondria() noexcept {
85  return _mitochondria;
86  }
87 
89  const Mitochondria& mitochondria() const noexcept {
90  return _mitochondria;
91  }
92 
95  return _endoplasmicReticulum;
96  }
99  const EndoplasmicReticulum& endoplasmicReticulum() const noexcept {
100  return _endoplasmicReticulum;
101  }
102 
104  const std::vector<Property::Annotation>& annotations() const noexcept {
105  return _cellProperties->_annotations;
106  }
107 
109  const std::vector<Property::Marker>& markers() const noexcept {
110  return _cellProperties->_markers;
111  }
112 
118  const std::shared_ptr<Section>& section(uint32_t id) const {
119  return _sections.at(id);
120  }
121 
127  depth_iterator depth_begin() const;
128  depth_iterator depth_end() const;
129 
137  breadth_iterator breadth_end() const;
138 
147  void deleteSection(std::shared_ptr<Section> section, bool recursive = true);
148 
154  std::shared_ptr<Section> appendRootSection(const morphio::Section&, bool recursive = false);
155 
161  std::shared_ptr<Section> appendRootSection(const std::shared_ptr<Section>& section,
162  bool recursive = false);
163 
165  std::shared_ptr<Section> appendRootSection(const Property::PointLevel&,
166  SectionType sectionType);
167 
168  void applyModifiers(unsigned int modifierFlags);
169 
171  SomaType somaType() const noexcept {
172  return _soma->type();
173  }
174 
176  CellFamily cellFamily() const noexcept {
177  return _cellProperties->_cellFamily;
178  }
179 
181  MorphologyVersion version() const noexcept {
182  return _cellProperties->_version;
183  }
184 
186  void write(const std::string& filename) const;
187 
188  void addAnnotation(const morphio::Property::Annotation& annotation) {
189  _cellProperties->_annotations.push_back(annotation);
190  }
191 
192  void addMarker(const morphio::Property::Marker& marker) {
193  _cellProperties->_markers.push_back(marker);
194  }
195 
197  Property::Properties buildReadOnly() const;
198 
204  std::unordered_map<int, std::vector<unsigned int>> connectivity();
205 
210  void removeUnifurcations();
211  void removeUnifurcations(const morphio::readers::DebugInfo& debugInfo);
212 
213  std::shared_ptr<Soma> _soma;
214  std::shared_ptr<morphio::Property::CellLevel> _cellProperties;
215  EndoplasmicReticulum _endoplasmicReticulum;
216  morphio::Property::DendriticSpine::Level _dendriticSpineLevel;
217 
218  private:
219  std::vector<std::shared_ptr<Section>> _rootSections;
220  std::map<uint32_t, std::shared_ptr<Section>> _sections;
221 
222  Mitochondria _mitochondria;
223 
224  std::map<uint32_t, uint32_t> _parent;
225  std::map<uint32_t, std::vector<std::shared_ptr<Section>>> _children;
226 
227  uint32_t _counter = 0;
228 
229  uint32_t _register(const std::shared_ptr<Section>&);
231 
232  void eraseByValue(std::vector<std::shared_ptr<Section>>& vec,
233  const std::shared_ptr<Section> section);
234 
235  friend class Section;
236  friend void modifiers::nrn_order(morphio::mut::Morphology& morpho);
237  friend bool diff(const Morphology& left,
238  const Morphology& right,
239  morphio::enums::LogLevel verbose);
240 };
241 
242 } // namespace mut
243 } // namespace morphio
morphio::mut::Morphology::mitochondria
const Mitochondria & mitochondria() const noexcept
Return the mitochondria container class.
Definition: morphology.h:89
morphio::enums::SomaType
SomaType
Definition: enums.h:54
morphio::depth_iterator_t
Definition: section_iterators.hpp:82
morphio::enums::SectionType
SectionType
Definition: enums.h:64
morphio::mut::Morphology::sections
const std::map< uint32_t, std::shared_ptr< Section > > & sections() const noexcept
Returns the dictionary id -> Section for this tree.
Definition: morphology.h:61
morphio::mut::Morphology::somaType
SomaType somaType() const noexcept
Return the soma type.
Definition: morphology.h:171
morphio::Section
Definition: section.h:36
morphio::mut::Morphology::endoplasmicReticulum
const EndoplasmicReticulum & endoplasmicReticulum() const noexcept
Return the endoplasmic reticulum container class.
Definition: morphology.h:99
morphio::enums::NO_MODIFIER
@ NO_MODIFIER
Read morphology as is without any modification.
Definition: enums.h:14
morphio::Morphology
Definition: morphology.h:20
morphio::mut::Morphology::depth_begin
depth_iterator depth_begin() const
morphio::Property::Annotation
Definition: properties.h:153
morphio::mut::Morphology::soma
const std::shared_ptr< Soma > & soma() const noexcept
Definition: morphology.h:79
morphio::mut::EndoplasmicReticulum
Definition: endoplasmic_reticulum.h:9
morphio::mut::Morphology::markers
const std::vector< Property::Marker > & markers() const noexcept
Return the markers from the ASC file.
Definition: morphology.h:109
morphio::mut::Morphology::deleteSection
void deleteSection(std::shared_ptr< Section > section, bool recursive=true)
morphio::enums::CellFamily
CellFamily
Definition: enums.h:47
morphio::mut::Morphology::diff
friend bool diff(const Morphology &left, const Morphology &right, morphio::enums::LogLevel verbose)
morphio::mut::Morphology::cellFamily
CellFamily cellFamily() const noexcept
Return the cell family (neuron or glia)
Definition: morphology.h:176
morphio::Property::CellLevel
Definition: properties.h:187
morphio::mut::Morphology::rootSections
const std::vector< std::shared_ptr< Section > > & rootSections() const noexcept
Returns all section ids at the tree root.
Definition: morphology.h:56
morphio::mut::Morphology::section
const std::shared_ptr< Section > & section(uint32_t id) const
Definition: morphology.h:118
morphio::readers::DebugInfo
Definition: errorMessages.h:35
morphio::Property::Marker
Definition: properties.h:177
morphio::mut::Morphology::version
MorphologyVersion version() const noexcept
Return the version.
Definition: morphology.h:181
morphio::mut::Mitochondria
Definition: mitochondria.h:21
morphio::mut::Morphology::mitochondria
Mitochondria & mitochondria() noexcept
Return the mitochondria container class.
Definition: morphology.h:84
morphio::mut::Morphology::endoplasmicReticulum
EndoplasmicReticulum & endoplasmicReticulum() noexcept
Return the endoplasmic reticulum container class.
Definition: morphology.h:94
morphio::mut::Morphology::removeUnifurcations
void removeUnifurcations()
morphio::Property::DendriticSpine::Level
Definition: properties.h:135
morphio::mut::Morphology::buildReadOnly
Property::Properties buildReadOnly() const
Return the data structure used to create read-only morphologies.
morphio::readers::ErrorMessages
Definition: errorMessages.h:83
morphio::breadth_iterator_t
Definition: section_iterators.hpp:53
morphio::mut::Morphology::annotations
const std::vector< Property::Annotation > & annotations() const noexcept
Return the annotation objects.
Definition: morphology.h:104
morphio::mut::Morphology::write
void write(const std::string &filename) const
Write file to H5, SWC, ASC format depending on filename extension.
morphio::mut::Morphology::connectivity
std::unordered_map< int, std::vector< unsigned int > > connectivity()
morphio::mut::Morphology
Definition: morphology.h:25
morphio::mut::Morphology::breadth_begin
breadth_iterator breadth_begin() const
morphio::mut::Morphology::appendRootSection
std::shared_ptr< Section > appendRootSection(const morphio::Section &, bool recursive=false)
morphio::mut::Morphology::soma
std::shared_ptr< Soma > & soma() noexcept
Definition: morphology.h:70
morphio::Property::PointLevel
Definition: properties.h:62