morphology.h
1 #pragma once
2 
3 #include <map>
4 #include <memory>
5 #include <unordered_map>
6 #include <vector>
7 
8 #include <morphio/errorMessages.h>
9 #include <morphio/exceptions.h>
10 #include <morphio/mut/endoplasmic_reticulum.h>
11 #include <morphio/mut/mitochondria.h>
12 #include <morphio/mut/modifiers.h>
13 #include <morphio/mut/soma.h>
14 #include <morphio/properties.h>
15 #include <morphio/types.h>
16 
17 namespace morphio {
18 namespace mut {
19 // TODO: not sure why this is here
20 bool _checkDuplicatePoint(const std::shared_ptr<Section>& parent,
21  const std::shared_ptr<Section>& current);
22 
25 {
26  public:
27  Morphology()
28  : _soma(std::make_shared<Soma>())
29  , _cellProperties(
30  std::make_shared<morphio::Property::CellLevel>(morphio::Property::CellLevel())) {}
31 
41  explicit Morphology(const std::string& uri, unsigned int options = NO_MODIFIER);
42 
46  Morphology(const morphio::mut::Morphology& morphology, unsigned int options = NO_MODIFIER);
47 
51  explicit Morphology(const morphio::Morphology& morphology, unsigned int options = NO_MODIFIER);
52 
53  virtual ~Morphology();
54 
58  inline const std::vector<std::shared_ptr<Section>>& rootSections() const noexcept;
59 
63  inline const std::map<uint32_t, std::shared_ptr<Section>>& sections() const noexcept;
64 
70  inline std::shared_ptr<Soma>& soma() noexcept;
71 
77  inline const std::shared_ptr<Soma>& soma() const noexcept;
78 
82  inline Mitochondria& mitochondria() noexcept;
86  inline const Mitochondria& mitochondria() const noexcept;
87 
91  inline EndoplasmicReticulum& endoplasmicReticulum() noexcept;
95  inline const EndoplasmicReticulum& endoplasmicReticulum() const noexcept;
96 
100  inline const std::vector<Property::Annotation>& annotations() const noexcept;
101 
105  inline const std::vector<Property::Marker>& markers() const noexcept;
106 
112  inline const std::shared_ptr<Section>& section(uint32_t id) const;
113 
119  depth_iterator depth_begin() const;
120  depth_iterator depth_end() const;
121 
129  breadth_iterator breadth_end() const;
130 
132  //
133  // Tree manipulation methods
134  //
136 
145  void deleteSection(std::shared_ptr<Section> section, bool recursive = true);
146 
152  std::shared_ptr<Section> appendRootSection(const morphio::Section&, bool recursive = false);
153 
159  std::shared_ptr<Section> appendRootSection(const std::shared_ptr<Section>& section,
160  bool recursive = false);
161 
165  std::shared_ptr<Section> appendRootSection(const Property::PointLevel&,
166  SectionType sectionType);
167 
168  void applyModifiers(unsigned int modifierFlags);
169 
173  inline SomaType somaType() const noexcept;
174 
178  inline CellFamily cellFamily() const noexcept;
179 
183  inline MorphologyVersion version() const noexcept;
184 
188  void write(const std::string& filename);
189 
190  inline void addAnnotation(const morphio::Property::Annotation& annotation);
191  inline void addMarker(const morphio::Property::Marker& marker);
192 
197 
203  std::unordered_map<int, std::vector<unsigned int>> connectivity();
204 
209  void removeUnifurcations();
210  void removeUnifurcations(const morphio::readers::DebugInfo& debugInfo);
211 
215  void _raiseIfUnifurcations();
216 
217  public:
218  friend class Section;
219  friend void modifiers::nrn_order(morphio::mut::Morphology& morpho);
220  friend bool diff(const Morphology& left,
221  const Morphology& right,
222  morphio::enums::LogLevel verbose);
224 
225  uint32_t _register(const std::shared_ptr<Section>&);
226 
227  uint32_t _counter = 0;
228  std::shared_ptr<Soma> _soma;
229  std::shared_ptr<morphio::Property::CellLevel> _cellProperties;
230  std::vector<std::shared_ptr<Section>> _rootSections;
231  std::map<uint32_t, std::shared_ptr<Section>> _sections;
232 
233  Mitochondria _mitochondria;
234  EndoplasmicReticulum _endoplasmicReticulum;
235  morphio::Property::DendriticSpine::Level _dendriticSpineLevel;
236 
237  std::map<uint32_t, uint32_t> _parent;
238  std::map<uint32_t, std::vector<std::shared_ptr<Section>>> _children;
239 
240  private:
241  void eraseByValue(std::vector<std::shared_ptr<Section>>& vec,
242  const std::shared_ptr<Section> section);
243 };
244 
245 inline const std::vector<std::shared_ptr<Section>>& Morphology::rootSections() const noexcept {
246  return _rootSections;
247 }
248 
249 inline const std::map<uint32_t, std::shared_ptr<Section>>& Morphology::sections() const noexcept {
250  return _sections;
251 }
252 
253 inline std::shared_ptr<Soma>& Morphology::soma() noexcept {
254  return _soma;
255 }
256 
257 inline const std::shared_ptr<Soma>& Morphology::soma() const noexcept {
258  return _soma;
259 }
260 
262  return _mitochondria;
263 }
264 
265 inline const Mitochondria& Morphology::mitochondria() const noexcept {
266  return _mitochondria;
267 }
268 
270  return _endoplasmicReticulum;
271 }
272 
273 inline const EndoplasmicReticulum& Morphology::endoplasmicReticulum() const noexcept {
274  return _endoplasmicReticulum;
275 }
276 
277 inline const std::shared_ptr<Section>& Morphology::section(uint32_t id) const {
278  return _sections.at(id);
279 }
280 
281 inline SomaType Morphology::somaType() const noexcept {
282  return _soma->type();
283 }
284 
285 inline const std::vector<Property::Annotation>& Morphology::annotations() const noexcept {
286  return _cellProperties->_annotations;
287 }
288 
289 inline const std::vector<Property::Marker>& Morphology::markers() const noexcept {
290  return _cellProperties->_markers;
291 }
292 
293 inline CellFamily Morphology::cellFamily() const noexcept {
294  return _cellProperties->_cellFamily;
295 }
296 
297 inline MorphologyVersion Morphology::version() const noexcept {
298  return _cellProperties->_version;
299 }
300 
301 inline void Morphology::addAnnotation(const morphio::Property::Annotation& annotation) {
302  _cellProperties->_annotations.push_back(annotation);
303 }
304 
305 inline void Morphology::addMarker(const morphio::Property::Marker& marker) {
306  _cellProperties->_markers.push_back(marker);
307 }
308 
309 } // namespace mut
310 } // namespace morphio
morphio::mut::Morphology::annotations
const std::vector< Property::Annotation > & annotations() const noexcept
Definition: morphology.h:285
morphio::Property::Properties
Definition: properties.h:210
morphio::enums::SomaType
SomaType
Definition: enums.h:52
morphio::mut::Morphology::markers
const std::vector< Property::Marker > & markers() const noexcept
Definition: morphology.h:289
morphio::depth_iterator_t
Definition: section_iterators.hpp:81
morphio::enums::SectionType
SectionType
Definition: enums.h:62
morphio::mut::Morphology::somaType
SomaType somaType() const noexcept
Definition: morphology.h:281
morphio::Section
Definition: section.h:36
morphio::mut::Morphology::section
const std::shared_ptr< Section > & section(uint32_t id) const
Definition: morphology.h:277
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::mut::Morphology::rootSections
const std::vector< std::shared_ptr< Section > > & rootSections() const noexcept
Definition: morphology.h:245
morphio::Property::Annotation
Definition: properties.h:153
morphio::mut::EndoplasmicReticulum
Definition: endoplasmic_reticulum.h:9
morphio::mut::Morphology::deleteSection
void deleteSection(std::shared_ptr< Section > section, bool recursive=true)
morphio::enums::CellFamily
CellFamily
Definition: enums.h:45
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
Definition: morphology.h:293
morphio::mut::Morphology::mitochondria
Mitochondria & mitochondria() noexcept
Definition: morphology.h:261
morphio::Property::CellLevel
Definition: properties.h:187
morphio::readers::DebugInfo
Definition: errorMessages.h:35
morphio::Property::Marker
Definition: properties.h:177
morphio::mut::Morphology::sections
const std::map< uint32_t, std::shared_ptr< Section > > & sections() const noexcept
Definition: morphology.h:249
morphio::mut::Morphology::version
MorphologyVersion version() const noexcept
Definition: morphology.h:297
morphio::mut::Morphology::write
void write(const std::string &filename)
morphio::mut::Mitochondria
Definition: mitochondria.h:21
morphio::mut::Morphology::removeUnifurcations
void removeUnifurcations()
morphio::Property::DendriticSpine::Level
Definition: properties.h:135
morphio::mut::Morphology::buildReadOnly
Property::Properties buildReadOnly() const
morphio::readers::ErrorMessages
Definition: errorMessages.h:105
morphio::mut::Morphology::_raiseIfUnifurcations
void _raiseIfUnifurcations()
morphio::breadth_iterator_t
Definition: section_iterators.hpp:53
morphio::mut::Morphology::connectivity
std::unordered_map< int, std::vector< unsigned int > > connectivity()
morphio::mut::Morphology::endoplasmicReticulum
EndoplasmicReticulum & endoplasmicReticulum() noexcept
Definition: morphology.h:269
morphio::mut::Morphology
Definition: morphology.h:24
morphio::mut::Morphology::breadth_begin
breadth_iterator breadth_begin() const
morphio::mut::Section
Definition: section.h:19
morphio::mut::Morphology::appendRootSection
std::shared_ptr< Section > appendRootSection(const morphio::Section &, bool recursive=false)
morphio::Property::PointLevel
Definition: properties.h:62
morphio::mut::Morphology::soma
std::shared_ptr< Soma > & soma() noexcept
Definition: morphology.h:253