336
334
void mydrawstring(double x, double y, char *nom, char option);
337
335
void moveto(double x,double y);
338
336
void lineto(double x,double y);
339
double tree_bal(struct noeud *centre, struct noeud *p1, struct noeud *p2);
340
void get_next_br(struct noeud *pere, struct noeud *fils,
341
double **abdown, double **abup, struct noeud **f1, struct noeud **f2);
337
int calc_brl_for_lengthless(struct noeud *centre, struct noeud *pere);
338
void add_value_downstream(struct noeud *centre, int value);
342
339
void place_midpoint_root(void);
343
340
void parcourir_branches(struct noeud *centre, struct noeud *origine);
344
341
void process_branche(struct noeud *cote1, struct noeud *cote2, double length);
2970
2965
fd_nj_plot->racine = *(fd_nj_plot->tabtax+num_noeud);
2971
2966
fd_nj_plot->root_br_l= fd_nj_plot->racine->l1 + fd_nj_plot->racine->l2;
2972
2967
fd_nj_plot->root_num = num_noeud;
2973
if(!fd_nj_plot->has_br_length) tree_bal(fd_nj_plot->racine,fd_nj_plot->racine->v1,fd_nj_plot->racine->v2);
2968
if(!fd_nj_plot->has_br_length) calc_brl_for_lengthless(fd_nj_plot->racine, NULL);
2974
2969
/* y a-t-il un bootstrap sur l'une des branches racine ? */
2975
2970
i = get_br_from_bouts(fd_nj_plot->racine, fd_nj_plot->racine->v1);
2976
2971
if(i == -1) i = get_br_from_bouts(fd_nj_plot->racine, fd_nj_plot->racine->v2);
3103
3094
if(*deb != '(') { /* une feuille */
3104
3095
virg = strchr(deb, ':');
3105
3096
if(virg != NULL && virg < fin) {
3106
if(fd_nj_plot->has_br_length == 0) goto problem;
3097
// if(fd_nj_plot->has_br_length == 0) goto problem;
3107
3098
sscanf(virg+1, "%le", &brlength);
3108
3099
fd_nj_plot->has_br_length=1;
3111
if(fd_nj_plot->has_br_length == 1) goto problem;
3102
// if(fd_nj_plot->has_br_length == 1) goto problem;
3113
3104
fd_nj_plot->has_br_length=0;
3114
3105
virg = fin + 1;
3151
3142
if(int_br != NULL) { int_br->bouta = p; int_br->boutb = pp; }
3152
3143
virg = strchr(ferme, ':');
3153
3144
if(virg != NULL && virg < fin) { /* traitement longueur */
3154
if(fd_nj_plot->has_br_length == 0) goto problem;
3145
// if(fd_nj_plot->has_br_length == 0) goto problem;
3155
3146
sscanf(virg+1, "%le", &brlength);
3156
3147
fd_nj_plot->has_br_length=1;
3157
3148
if(*fin == ']') { /* bootstrap entre [] apres longueurs */
3347
3335
dir_lineto(px,py);
3350
/* pour un arbre sans longueur de branche, les calculer de facon a ce
3351
que toutes les feuilles arrivent a la meme profondeur */
3352
double tree_bal(struct noeud *centre, struct noeud *p1, struct noeud *p2)
3354
double ld, lg, pg, pd, *abup1, *abup2, *abdown1, *abdown2;
3355
struct noeud *f1, *f2;
3356
get_next_br(centre,p1,&abup1,&abdown1,&f1,&f2);
3357
if(f1!=NULL) lg=tree_bal(p1,f1,f2);
3359
get_next_br(centre,p2,&abup2,&abdown2,&f1,&f2);
3360
if(f1!=NULL) ld=tree_bal(p2,f1,f2);
3365
*abup1 = *abdown1 = pg-lg;
3366
*abup2 = *abdown2 = pd-ld;
3371
void get_next_br(struct noeud *pere, struct noeud *fils,
3372
double **abdown, double **abup, struct noeud **f1, struct noeud **f2)
3373
/* pour une branche pere->fils donnee, calculer dans *f1, *f2 les deux autres
3374
voisins de fils et dans *abdown et *abup les adresses des longeurs de la
3375
branche pere->fils dans les deux sens */
3377
if(pere->v1==fils) *abdown= &(pere->l1);
3378
else if(pere->v2==fils) *abdown=&(pere->l2);
3379
else *abdown=&(pere->l3);
3380
if(fils->v1==pere) {
3385
else if(fils->v2==pere) {
3339
int calc_brl_for_lengthless(struct noeud *centre, struct noeud *pere)
3340
/* Recursively computes branch lengths of a lengthless tree having some branches fixed to 0 to allow
3341
multifurcations so that all tips align to the right of the plot.
3344
int n1 = 0, n2, depth;
3346
if(centre->v1 == NULL && centre->v2 == NULL) return 0;//a leaf
3347
//rearrange with centre->v3 towards root
3348
if(centre->v1 == pere) {
3349
centre->v1 = centre->v3;
3352
centre->l3 = centre->l1;
3355
else if(centre->v2 == pere) {
3356
centre->v2 = centre->v3;
3359
centre->l3 = centre->l2;
3362
n1 = calc_brl_for_lengthless(centre->v1, centre);
3363
n2 = calc_brl_for_lengthless(centre->v2, centre);
3365
if(centre->l1 != 0) depth++;
3366
if(depth < n2) depth = n2;
3367
if(centre->l2 != 0 && n2 + 1 > depth) depth++;
3368
if(centre->l1 != 0) {
3369
centre->l1 = depth - n1;
3370
centre->v1->l3 = depth - n1;
3372
else if(depth - n1 > 0) add_value_downstream(centre->v1, depth - n1);
3373
if(centre->l2 != 0) {
3374
centre->l2 = depth - n2;
3375
centre->v2->l3 = depth - n2;
3377
else if(depth - n2 > 0) add_value_downstream(centre->v2, depth - n2);
3381
void add_value_downstream(struct noeud *centre, int value)
3383
if(centre->l1 != 0) {
3384
centre->l1 += value;
3385
centre->v1->l3 = centre->l1;
3387
else add_value_downstream(centre->v1, value);
3388
if(centre->l2 != 0) {
3389
centre->l2 += value;
3390
centre->v2->l3 = centre->l1;
3392
else add_value_downstream(centre->v2, value);
3398
3396
void place_midpoint_root(void)
3399
3397
/* enraciner l'arbre sans racine en cherchant son centre
3631
3629
fd_nj_plot->racine->l1=b1; fd_nj_plot->racine->l2=b2;
3634
tree_bal(fd_nj_plot->racine,p1,p2);
3632
fd_nj_plot->racine->l1 = p1->l3;
3633
if (p2->v1 == fd_nj_plot->racine )
3634
fd_nj_plot->racine->l2 = p2->l1;
3635
else if (p2->v2 == fd_nj_plot->racine)
3636
fd_nj_plot->racine->l2 = p2->l2;
3638
fd_nj_plot->racine->l2 = p2->l3;
3639
calc_brl_for_lengthless(fd_nj_plot->racine, NULL);
3637
3642
/* initialize leave and node names */
3638
3643
for(i = 0; i <= 2*fd_nj_plot->notu; i++) fd_nj_plot->tabnames[i][0] = 0;
3639
if (fd_nj_plot->choix == depl_racine)
3640
for(i=0; i<=2*fd_nj_plot->notu-1; i++) sprintf(fd_nj_plot->tabnames[i],"# ");
3644
if (fd_nj_plot->choix == depl_racine) {
3645
for(i=0; i <= 2*fd_nj_plot->notu - 1; i++) {
3646
// if(i == fd_nj_plot->root_num) continue;//skip current root
3647
if( !fd_nj_plot->has_br_length) {
3648
if(fd_nj_plot->tabtax[i]->l3 == 0) continue;//skip internal multifurcation nodes that can't be broken by root
3650
sprintf(fd_nj_plot->tabnames[i], "# ");
3641
3653
else if(fd_nj_plot->choix == permutation)
3642
3654
for(i=fd_nj_plot->notu+1; i<=2*fd_nj_plot->notu; i++) sprintf(fd_nj_plot->tabnames[i],"#");
3643
3655
else if(fd_nj_plot->choix == subtree)