Commit abce2443c2a7839a7cd8436912960114f5fce426

Authored by pranathivemuri
1 parent 10b95d6e

average branching index of the network statistic added

Showing 1 changed file with 59 additions and 17 deletions   Show diff stats
stim/biomodels/network.h
... ... @@ -126,6 +126,18 @@ public:
126 126 return V;
127 127 }
128 128  
  129 + // Returns an average of branching index in the network
  130 +
  131 + double BranchingIndex(){
  132 + double B=0;
  133 + for(unsigned v=0; v < V.size(); v ++){
  134 + B += ((V[v].e[0].size()) + (V[v].e[1].size()));
  135 + }
  136 + B = B / V.size();
  137 + return B;
  138 +
  139 + }
  140 +
129 141 // Returns an average of fiber/edge lengths in the network
130 142 double Lengths(){
131 143 stim::vec<T> L;double sumLength = 0;
... ... @@ -142,26 +154,11 @@ public:
142 154 double Tortuosities(){
143 155 stim::vec<T> t;
144 156 stim::vec<T> id1, id2; // starting and ending vertices of the edge
145   - //std::vector< stim::vec<T> > vert; // list of visited vertices
146   - //std::vector<stim::vec<T>>::iterator it; //create an iterator for searching the id2vert array
147   - //std::vector<unsigned> daughters; // to count number of daughter vessels at branch points
148   - //stim::vec<T> visitedVert;
149   - //unsigned visited;
150 157 double distance;double tortuosity;double sumTortuosity = 0;
151 158 for(unsigned e = 0; e < E.size(); e++){ //for each edge in the network
152 159 id1 = E[e][0]; //get the edge starting point
153 160 id2 = E[e][E[e].size() - 1]; //get the edge ending point
154 161 distance = (id1 - id2).len(); //displacement between the starting and ending points
155   - //it = find(vert.begin(), vert.end(), id1); //look for the first node has a daughter vessel already
156   - //visitedVert = std::distance(vert.begin(), it); //index where it already exists
157   - //if(visitedVert == id1){
158   - // visited += 1;
159   - // daughters[e] = visited;
160   - //}
161   - //else{
162   - // vert.push_back(id1);
163   - // daughters[e] = 1;
164   - //}
165 162 if(distance > 0){
166 163 tortuosity = E[e].length()/ distance ; // tortuoisty = edge length / edge displacement
167 164 }
... ... @@ -171,7 +168,6 @@ public:
171 168 sumTortuosity += tortuosity;
172 169 }
173 170 double avg = sumTortuosity / E.size();
174   - //std::cout<<"number of unique branch points"<<daughters.size()<<std::endl;
175 171 return avg;
176 172 }
177 173  
... ... @@ -228,7 +224,7 @@ public:
228 224 if(it == id2vert.end()){ //if i[1] hasn't already been used
229 225 vertex new_vertex = new_edge[I-1]; //create a new vertex, assign it a position
230 226 new_vertex.e[1].push_back(E.size()); //add the current edge as incoming
231   - new_edge.v[1] = V.size();
  227 + new_edge.v[1] = V.size(); //add the new vertex to the edge
232 228 V.push_back(new_vertex); //add the new vertex to the vertex list
233 229 id2vert.push_back(i[1]); //add the ID to the ID->vertex conversion list
234 230 }
... ... @@ -427,6 +423,52 @@ public:
427 423 count += atoi(file_contents[count + 1].c_str()) + 2; // Skip number of edge ids + 2 to point to the next vertex
428 424 }
429 425 } // end load_txt function
  426 +
  427 + // strTxt returns a string of edges
  428 + std::string
  429 + strTxt(std::vector< stim::vec<T> > p)
  430 + {
  431 + std::stringstream ss;
  432 + std::stringstream oss;
  433 + for(unsigned int i = 0; i < p.size(); i++){
  434 + ss.str(std::string());
  435 + for(unsigned int d = 0; d < 3; d++){
  436 + ss<<c[i][d];
  437 + }
  438 + ss < "\n"
  439 + }
  440 + return ss.str();
  441 + }
  442 + // removes specified character from string
  443 + void removeCharsFromString(std::string &str, char* charsToRemove ) {
  444 + for ( unsigned int i = 0; i < strlen(charsToRemove); ++i ) {
  445 + str.erase( remove(str.begin(), str.end(), charsToRemove[i]), str.end() );
  446 + }
  447 + }
  448 + //exports network to txt file
  449 + void
  450 + to_txt(std::string filename)
  451 + {
  452 + std::ofstream ofs;
  453 + ofs.open(filename, std::ofstream::out | std::ofstream::app);
  454 + int num;
  455 + ofs << (E.size()).str() << "\n";
  456 + for(unsigned int i = 0; i < E.size(); i++)
  457 + {
  458 + std::string str;
  459 + ofs << (E[i].size()).str() << "\n";
  460 + str = E[i].strTxt();
  461 + ofs << str << "\n";
  462 + }
  463 + for(int i = 0; i < V.size(); i++)
  464 + {
  465 + std::string str;
  466 + str = V[i].str();
  467 + removeCharsFromString(str, "[],");
  468 + ofs << str << "\n";
  469 + }
  470 + ofs.close();
  471 + }
430 472 }; //end stim::network class
431 473 }; //end stim namespace
432 474 #endif
... ...