Skip to content

Commit bc206db

Browse files
author
Your Name
committed
rank of clade is now shifted to first noneclade. @nicolaavogel @bdesanctis
1 parent c7e84f8 commit bc206db

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

shared.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,28 @@ int2char parse_names(const char *fname) {
173173
delete[] toks;
174174
return name_map;
175175
}
176+
const char *find_nearest_non_clade_rank(int node, int2char &rank, int2int &parent) {
177+
int cur = node;
178+
179+
while (1) {
180+
int2int::iterator pit = parent.find(cur);
181+
if (pit == parent.end())
182+
return NULL;
183+
184+
int par = pit->second;
185+
if (par == cur)
186+
return NULL;
187+
188+
int2char::iterator rit = rank.find(par);
189+
if (rit == rank.end())
190+
return NULL;
191+
192+
if (strcmp(rit->second, "clade") != 0)
193+
return rit->second;
194+
195+
cur = par;
196+
}
197+
}
176198

177199
void parse_nodes(const char *fname, int2char &rank, int2int &parent, int2intvec &child, int dochild) {
178200
// fprintf(stderr,"Parsing: %s\n",fname);
@@ -223,6 +245,17 @@ void parse_nodes(const char *fname, int2char &rank, int2int &parent, int2intvec
223245
// fprintf(stderr,"%d->%lu\n",it->first,it->second.size());
224246
// exit(0);
225247
gzclose(gz);
248+
249+
// fix clade -> nearest non-clade ancestor
250+
for (int2char::iterator it = rank.begin(); it != rank.end(); it++) {
251+
if (strcmp(it->second, "clade") == 0) {
252+
const char *newrank = find_nearest_non_clade_rank(it->first, rank, parent);
253+
if (newrank != NULL) {
254+
free(it->second);
255+
it->second = strdup(newrank);
256+
}
257+
}
258+
}
226259
delete[] toks;
227260
}
228261

0 commit comments

Comments
 (0)