This repository was archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathnrnsection_mapping.hpp
More file actions
204 lines (172 loc) · 5.69 KB
/
nrnsection_mapping.hpp
File metadata and controls
204 lines (172 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
# =============================================================================
# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
#
# See top-level LICENSE file for details.
# =============================================================================
*/
#pragma once
#include <numeric>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <iostream>
#include <unordered_map>
namespace coreneuron {
/** type to store every section and associated segments */
using segvec_type = std::vector<int>;
using secseg_map_type = std::map<int, segvec_type>;
using secseg_it_type = secseg_map_type::iterator;
/** @brief Section to segment mapping
*
* For a section list (of a particulat type), store mapping
* of section to segments
* a section is a arbitrary user classification to recognize some segments (ex: api, soma, dend,
* axon)
*
*/
struct SecMapping {
/** name of section list */
std::string name;
/** map of section and associated segments */
secseg_map_type secmap;
SecMapping() = default;
explicit SecMapping(std::string s)
: name(std::move(s)) {}
/** @brief return total number of sections in section list */
size_t num_sections() const noexcept {
return secmap.size();
}
/** @brief return number of segments in section list */
size_t num_segments() const {
return std::accumulate(secmap.begin(), secmap.end(), 0, [](int psum, const auto& item) {
return psum + item.second.size();
});
}
/** @brief add section to associated segment */
void add_segment(int sec, int seg) {
secmap[sec].push_back(seg);
}
};
/** @brief Compartment mapping information for a cell
*
* A cell can have multiple section list types like
* soma, axon, apic, dend etc. User will add these
* section lists using HOC interface.
*/
struct CellMapping {
/** gid of a cell */
int gid;
/** list of section lists (like soma, axon, apic) */
std::vector<SecMapping*> secmapvec;
/** map containing segment ids an its respective lfp factors */
std::unordered_map<int, double> lfp_factors;
CellMapping(int g)
: gid(g) {}
/** @brief total number of sections in a cell */
int num_sections() const {
return std::accumulate(secmapvec.begin(),
secmapvec.end(),
0,
[](int psum, const auto& secmap) {
return psum + secmap->num_sections();
});
}
/** @brief return number of segments in a cell */
int num_segments() const {
return std::accumulate(secmapvec.begin(),
secmapvec.end(),
0,
[](int psum, const auto& secmap) {
return psum + secmap->num_segments();
});
}
/** @brief number of section lists */
size_t size() const noexcept {
return secmapvec.size();
}
/** @brief add new SecMapping */
void add_sec_map(SecMapping* s) {
secmapvec.push_back(s);
}
/** @brief return section list mapping with given name */
SecMapping* get_seclist_mapping(const std::string& name) const {
for (auto& secmap: secmapvec) {
if (name == secmap->name) {
return secmap;
}
}
std::cout << "Warning: Section mapping list " << name << " doesn't exist! \n";
return nullptr;
}
/** @brief return segment count for specific section list with given name */
size_t get_seclist_segment_count(const std::string& name) const {
SecMapping* s = get_seclist_mapping(name);
size_t count = 0;
if (s) {
count = s->num_segments();
}
return count;
}
/** @brief return segment count for specific section list with given name */
size_t get_seclist_section_count(const std::string& name) const {
SecMapping* s = get_seclist_mapping(name);
size_t count = 0;
if (s) {
count = s->num_sections();
}
return count;
}
/** @brief add the lfp factor of a segment_id */
void add_segment_lfp_factor(const int segment_id, double factor) {
lfp_factors.insert({segment_id, factor});
}
~CellMapping() {
for (size_t i = 0; i < secmapvec.size(); i++) {
delete secmapvec[i];
}
}
};
/** @brief Compartment mapping information for NrnThread
*
* NrnThread could have more than one cell in cellgroup
* and we store this in vector.
*/
struct NrnThreadMappingInfo {
/** list of cells mapping */
std::vector<CellMapping*> mappingvec;
/** list of segment ids */
std::vector<int> segment_ids;
std::vector<double> _lfp;
/** @brief number of cells */
size_t size() const {
return mappingvec.size();
}
/** @brief memory cleanup */
~NrnThreadMappingInfo() {
for (size_t i = 0; i < mappingvec.size(); i++) {
delete mappingvec[i];
}
}
/** @brief get cell mapping information for given gid
* if exist otherwise return nullptr.
*/
CellMapping* get_cell_mapping(int gid) const {
for (const auto& mapping: mappingvec) {
if (mapping->gid == gid) {
return mapping;
}
}
return nullptr;
}
/** @brief add mapping information of new cell */
void add_cell_mapping(CellMapping* c) {
mappingvec.push_back(c);
}
/** @brief add a new segment */
void add_segment_id(const int segment_id) {
segment_ids.push_back(segment_id);
}
};
} // namespace coreneuron