This file is indexed.

/usr/lib/perl5/ALTree/Input.pm is in altree 1.3.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
package ALTree::Input;

use strict;

BEGIN {
    use Exporter   ();
    use vars       qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
    
    # set the version for version checking
    #$VERSION     = 1.00;
    # if using RCS/CVS, this may be preferred
    #$VERSION = do { my @r = (q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
    
    @ISA         = qw(Exporter);
    @EXPORT      = qw(); #(&func1 &func2 &func4);
    %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
    
    # your exported package globals go here,
    # as well as any optionally exported functions
    @EXPORT_OK   = qw(&ReadCorrespond &PrepareTree);
}
use vars      @EXPORT_OK;

use ALTree::Utils qw(erreur);
use Data::Dumper;
###########################################
########  Read file fonctions     #########
###########################################


#Read the file correspond.txt and put haplotype ID, nb case and nb
#controle in a hash: $correspondance{$HaploID}->{"case"} and
#$correspondance{$HaploID}->{"controle"}

sub ReadCorrespondQuali
{
    my($name_correspond) =shift;
    my($ligne, @tableau);
    my(%correspondance);
    open (CORRESP, '<', $name_correspond) 
	or erreur("Unable to read file '$name_correspond': $!\n", 0);
    while ($ligne=<CORRESP>) {
	chomp($ligne);
	if ($ligne =~ /^\s*$/) {
	    next;
	}
	# On peut mettre '#' ou ';' pour introduire une ligne de commentaire
	my $di="#";
	if ($ligne =~ /^\s*[$di;]/) {
	    next;
	}
	@tableau=split(/\s+/, $ligne);
	if ($#tableau != 2) {
	    ALTree::Utils::erreur("I do not find 3 columns in $name_correspond at".
		   " line $.:\n$ligne\nPlease, check the syntax.\n",0);
	}

	my $id=shift @tableau;
	if ($id !~ /^[a-zA-Z0-9]+$/) {
	    ALTree::Utils::erreur("The haplotype name '$id' contains unauthorized".
		   " characters\nin $name_correspond at".
		   " line $.:\n$ligne\nPlease, check the syntax.\n",0);
	}
	
	for(my $i=0; $i<2; $i++) {
	    $_=shift @tableau;
	    my $value=0;
	    my $type;
	    if (/^([a-zA-Z]+)_?([0-9]+)$/) {
		$type=$1;
		$value += $2;
	    } else {
		ALTree::Utils::erreur("I do not understand '$_' in $name_correspond at".
		       " line $.:\n$ligne\nPlease, check the syntax.\n", 0);
	    }
	    $_=$type;
	    if (/^(m(alade(s)?)?)|(case(s)?)$/) {
		$type="case";
	    } elsif (/^c(ontrols?)?$/) {
		$type="control";
	    } else {
		ALTree::Utils::erreur("I do not understand '$_' in $name_correspond at".
		       " line $.:\n$ligne\nPlease, check the syntax.\n", 0);
	    }
	    if (defined($correspondance{$id}->{$type})) {
		ALTree::Utils::erreur("For the second time, I read the number of".
		       " ${type}s of '$id'\nin file '$name_correspond' at".
		       " line $.:\n$ligne\nPlease, check the syntax.\n", 0);
	    }
	    $correspondance{$id}->{$type}=$value;
	}
    }
    #my($clefs);
    #DEBUG
    #foreach $clefs (keys %correspondance) {
    #print "$clefs case: ", $correspondance{$clefs}->{"case"}, "\n";
    #	print "$clefs, control: ",$correspondance{$clefs}->{"control"}, "\n";
    #}
    return(\%correspondance);
}
#Read the file correspond.txt and put haplotype ID... (to be continued)
sub ReadCorrespondQuanti
{
    my($name_correspond) =shift;
    my($ligne, @tableau);
    my($correspondance);
    open (CORRESP, '<', $name_correspond) 
	or erreur("Unable to read file '$name_correspond': $!\n", 0);
    my $numhaplo=0;
    while ($ligne=<CORRESP>) {
	chomp($ligne);
	if ($ligne =~ /^\s*$/) {
	    next;
	}
	# On peut mettre '#' ou ';' pour introduire une ligne de commentaire
	my $di="#";
	if ($ligne =~ /^\s*[$di;]/) {
	    next;
	}
	@tableau=split(/\s+/, $ligne);
	$numhaplo++;
	my $id=shift @tableau;
	if ($id !~ /^[a-zA-Z0-9]+$/) {
	    ALTree::Utils::erreur("The haplotype name '$id' contains".
				  "unauthorized characters\n".
				  "in $name_correspond at".
				  " line $.:\n$ligne\nPlease, check the syntax.\n",0);
	}
	
	for(my $i=0; $i<=$#tableau; $i++) {
	    $correspondance->{$id}->[$i]->[0]=$tableau[$i]; 
	    $correspondance->{$id}->[$i]->[1]=$numhaplo; 
	    # $numhaplo sert pour les anova 2 facteurs emboités (2eme facteur)
	}
    }
    #my($clefs);
    #DEBUG
    #foreach my $clefs (keys %{$correspondance}) {
	#for (my $i=0; $i<scalar (@{$correspondance->{$clefs}}); $i++) {
	#    print STDERR "$clefs  ", $correspondance->{$clefs}->[$i]->[1], "\n";
    #}
#}
    return($correspondance);
}

# return :
# Hash of
#   "filename" => String
#   "anctype" => ANC::OutGroup|ANC::Rooted|ANC:Unrooted
#   ["outgroup" => String(leaf name)]
#   "trees" =>
#     Array (size number of trees) of
#       Hash of
#         "index" => Int
#         "line" => Int
#         "file" => ref of first hash
#         "tab_longbranche" =>
#            Array of (son, father, branch length)
#
#         "tab_seq" =>
#           Hash of
#             son => Array of (father, yes|no|maybe, .....1..0..1..)
#
#         "tab_infoapo" =>
#            Array of (father, son, apo number, CI, nb steps, direction of change)
#         "nb_br_non_nulle" =>
#            Int
#         ["has_ambiguity"] => Int
#         ["ancestor" => String(sequence)]
#         "tree" => Tree

sub ReadInputFile1
{
    my($input_file)=shift;
    my($phylo_program)=shift;
    my($datatype)=shift;
    my($ancetre)=shift;
    my($identifiant);
    my(%file)=("filename" => $input_file);

    if ($phylo_program == PhylProg::PAUP) {
	$identifiant="Tree number";
    } elsif  ($phylo_program == PhylProg::PHYLIP) { 
	$identifiant="requires a total of";
    } else {
	$identifiant = "TREE # ";
    }
    my $tab_arbres;
    if ($phylo_program == PhylProg::PAUP) {
	$tab_arbres=ReadPAUP(\%file);
    } elsif  ($phylo_program == PhylProg::PHYLIP) { 
    	if ($datatype != DataType::SNP) {
	    erreur("Datatype DNA not yet implemented\n", 0);
	}
	$tab_arbres=ReadPHYLIP(\%file);
    } else {
	$tab_arbres=ReadPAML(\%file);
    }
    $file{"trees"}=$tab_arbres;

    my $index=0;
    for my $arbre (@{$tab_arbres}) {
	$arbre->{"index"}=$index++;
	$arbre->{"file"}=\%file;
	$arbre->{"tree"}=readTreeOld($phylo_program, $arbre, 
				     $datatype, $ancetre);
    }
    $file{"nb_trees"}=$index;
    if ($index == 0) {
	erreur("No tree in file '$input_file'\nAborting.\n", 0);
    }
    return (\%file);
}

sub setAncType
{
    my $file=shift;
    my $type=shift;
    my $value=shift;

    if (not exists($file->{"anctype"})) {
	$file->{"anctype"}=$type;
	if ($type == ANC::OutGroup) {
	    $file->{"outgroup"}=$value;
	}
	return;
    }
    if ($type != $file->{"anctype"}) {
	erreur("I found a tree '".$ANC::Name[$type].
	       "' where as previous were '".$ANC::Name[$file->{"anctype"}].
	       "'.\nin file '".$file->{"filename"}."'", 0);
    }
    if ($type == ANC::OutGroup) {
	if (defined($file->{"outgroup"}) &&
	    defined($value) &&
	    $file->{"outgroup"} ne $value) {
	    erreur("I found a tree whose outgroup is '".$value.
		   "' where as previous were '".$file->{"outgroup"}.
		   "'.\nin file '".$file->{"filename"}."'", 0);
	} elsif ((defined($file->{"outgroup"})) xor defined($value)) {
	    erreur("I found a tree whose outgroup is '".
		   (defined($value)?$value:"unknown").
		   "' where as previous were '".
		   (defined($file->{"outgroup"})?$file->{"outgroup"}:
		    "unknown").
		   "'.\nin file '".$file->{"filename"}."'", 0);	    
	}
    }
}

sub ReadPAUP
{
    my $file=shift;
    my $filename=$file->{"filename"};
    my($ligne);
    my @trees;
    
    open (INPUT, '<', $filename) 
	or erreur("Unable to read file '$filename': $!\n", 0);
  TREE: 
    {
	my(@tab_longbranche, @tab_infoapo);
	my($nb_br_non_nulle)=0;
	my(%tree);
	my $anctype;
	
      FIND_TREE:
	{
	    while ($ligne=<INPUT>) {
		last FIND_TREE if ($ligne =~ /^Tree number /);
	    }
	    # Fin du fichier
	    last TREE;
	}
	$tree{"line"}=$.;
	
      FIND_LONGBRANCHES:
	{
	    my $dia="#";
	    while ($ligne=<INPUT>) {
		if ($ligne =~ /^Branch lengths and linkages for tree ${dia}[0-9]+ \(unrooted\)/) {
		    setAncType($file, ANC::Unrooted);
		    $anctype++;
		}
		last FIND_LONGBRANCHES if ($ligne =~ /^\s+Node\s+to node/);
	    }
	    next TREE;
	}
      READ_LONGBRANCHE:
	{
	    my $pos = index($ligne, "to node");
	    while ($ligne=<INPUT>) {
		if ($ligne =~ /-------------------------/) {
		    next;
		}		
		if ($ligne =~ /^\s*Sum/) {
		    last READ_LONGBRANCHE;
		}
		chomp($ligne);
		if ($ligne =~ /^\s*[0-9]+\s+root\s+0\s+0\s+0\s*$/) {
		    # On ignore la ligne root qui ne contient aucune mutation
		    next;
		}
		my $son = substr($ligne,0,$pos-1);
		#   print STDERR "son1:$son\n";
		my $other_infos = substr($ligne,$pos);
		$other_infos =~ s/^\s*//;
		#   print STDERR "otherinfos:$other_infos\n";
		if ($son =~ /^\s*([0-9]+)\s*$/) {
		    $son = $1;
		} elsif ($son =~ /\s*([^\s](.*[^\s])?)\s+\([0-9]*\)(\*)?\s*$/) {
		    $son = $1;
		    
		    if (defined($3)) {
			setAncType($file, ANC::OutGroup, $son);
			$anctype++;
		    }
		} else {
		    erreur("Sorry, I am unable to understand:\n$ligne\n".
			   "in file '$filename' at line $.\n".
			   "(bad branch '$son' while reading branch".
			   " lengths)\n", 0);
		}
		my @tableau = split(/\s+/,  $other_infos);
		if ($#tableau != 3) {
		    erreur("Sorry, I am unable to understand:\n$ligne\n".
			   "in file '$filename' at line $.\n".
			   "(bad number of columns while reading branch".
			   " lengths)\n", 0);
		}
		# We add (son, father, branch length)
		push @tab_longbranche, [$tableau[0], $son, $tableau[1]];
		if ($tableau[2] != 0) {
		    $nb_br_non_nulle++;
		}
	    }
	    next TREE;
	}
      FIND_APO:
	{
	    while ($ligne=<INPUT>) {
		if ($ligne =~ /^\s+Branch\s+Character\s+Steps\s+CI\s+Change/) {
		    last FIND_APO;
		}
	    }
	    next TREE;
	}
      READ_APO:
	{
	    my $position = index($ligne, "Character");
	    my $son;
	    my $father;

	    while ($ligne=<INPUT>) {
		chomp($ligne);
		if ($ligne =~ /^\s*$/) {
		    last READ_APO;
		}
		if ($ligne =~ /^\s*------------------/) {
		    next;
		}
		my $name_haplo = substr($ligne,0,$position-1);
		if ($name_haplo =~ /^\s*$/) {
		    if (not defined($son)) {
			erreur("Sorry, I am unable to understand:\n$ligne\n".
			       "in file '$filename' at line $.\n".
			       "(no branch while reading".
			       " apomorphies)\n", 0);
		    }
		} elsif ($name_haplo =~ /^\s*(root|node_[0-9]+) --> (.*[^\s])\s*$/){
		    $father=$1;
		    $son=$2;
		    $father=~ s/^node_//;
		    $son=~ s/^node_//;
		} else {
			erreur("Sorry, I am unable to understand:\n$ligne\n".
			       "in file '$filename' at line $.\n".
			       "(bad branch while reading".
			       " apomorphies)\n", 0);
		}


		my $infos = substr($ligne,$position);
		#print STDERR "infos:$infos\n";
		my @tab_infos=split(/\s+/, $infos);
		if ($#tab_infos != 5) {
		    erreur("Sorry, I am unable to understand:\n$ligne\n".
			   "in file '$filename' at line $.\n".
			   "(bad number of columns while reading".
			   " apomorphies)\n", 0);
		}		

		my $sens_chgt = join(' ', $tab_infos[3], "-->", $tab_infos[5]);

		# (father, son, apo number, CI, nb steps, direction of change)
		push @tab_infoapo, [$father, $son, $tab_infos[0],
				$tab_infos[2], $tab_infos[1],
				ALTree::Sens->New($sens_chgt)];

	    }
	}
	$tree{"tab_longbranche"} = \@tab_longbranche;
	$tree{"tab_infoapo"} = \@tab_infoapo;
	$tree{"nb_br_non_nulle"} = $nb_br_non_nulle;
	if (not $anctype) {
	    setAncType($file, ANC::Rooted);
	}
	push @trees, \%tree;
	redo TREE;
    } continue {
	erreur("Unexpected end of file while reading a tree\n".
	       "in file '$filename' at line $.\n", 0);
    }
    close(INPUT);
    #print STDERR Dumper(@trees);
    return \@trees;
}

sub ReadPHYLIP
{
    my $file=shift;
    my $filename=$file->{"filename"};
    my($ligne);
    my @trees;
    
    open (INPUT, '<', $filename)
	or erreur("Unable to read file '$filename': $!\n", 0);
  TREE: 
    {
	my(@tab_longbranche);
	my(%tab_seq);
	my(%tree);
	
      FIND_TREE:
	{
	  FIND_ANCESTOR:
	    {
		while ($ligne=<INPUT>) {
		    last FIND_TREE if ($ligne =~ /^From\s+To\s+Any\s+Steps/);
		    last FIND_ANCESTOR if ($ligne =~ /^best guesses of ancestral states:/);
		    }
		# Fin du fichier
		last TREE;
	    }
	    my $ancestor="";
	  READ_ANCESTOR:
	    {
		while ($ligne=<INPUT>) {
		    chomp($ligne);
		    if ($ligne =~ /.*0\!\s+([01?\s]+)$/) {
			my @tab=split(/\s+/, $1);
			$ancestor.=join('', @tab);
		    } elsif ($ligne =~ /^[\s]*$/) {
			last READ_ANCESTOR;
		    } elsif ($ligne =~ /^[0-9\s]*$/) {
		    } elsif ($ligne =~ /^\s*\*-+\s*$/) {
		    } else {
			erreur("Sorry, I am unable to understand:\n$ligne\n".
			       "in file '$filename' at line $.\n".
			       "(while reading ancestor)\n", 0);			
		    }
		}
		next TREE;
	    }
	    $tree{"ancestor"}=$ancestor;
	    setAncType($file, ANC::OutGroup, undef);
	    #print STDERR "ancestor=$ancestor\n";
	    while ($ligne=<INPUT>) {
		last FIND_TREE if ($ligne =~ /^From\s+To\s+Any\s+Steps/);
	    }
	    next TREE;
	}
	$tree{"line"}=$.;
	    
      READ_LONGBRANCHE:
	{
	    while ($ligne=<INPUT>) {
		chomp($ligne);

		if ($ligne =~ /^\s*root\s+[0-9]+\s+no\s+[. ]+\s*$/) {
		    # On ignore la ligne root qui ne contient aucune mutation
		    next;
		} elsif ($ligne =~ /^\s*([0-9a-zA-Z_]+)\s+([0-9a-zA-Z_]+)\s+(yes|no|maybe)\s+([01.? ]+)\s*$/) {
		    #print STDERR "trouvé! $ligne\n";
		    my($father)=$1;
		    my($son)=$2;
		    my($step2)=$3;
		    my $seq=join('', split(/\s+/, $4));
		    my $step=$seq;
		    $step =~ s/\.//g;
		    $step=length($step);
		    push @tab_longbranche, [$father, $son, $step];
		    if (defined($tab_seq{$son})) {
			erreur("It is the second time I read an information".
			       "for the branch leading to '$son':\n$ligne\n".
			       "in file '$filename' at line $.\n".
			       "Please, check your data.\n", 0);
		    }
		    $tab_seq{$son}=[$father, $step2, $seq];
		} else {
		    if (scalar(@tab_longbranche)==0) {
			next;
		    } elsif ($ligne =~ /^\s*$/) {
			last READ_LONGBRANCHE;
		    } else {
			erreur("Sorry, I am unable to understand:\n$ligne\n".
			       "in file '$filename' at line $.\n".
			       "(while reading branches)\n", 0);			
		    }
		}
	    }
	    if (scalar(@tab_longbranche)==0) {
		next TREE;
	    }
	}
	$tree{"tab_longbranche"} = \@tab_longbranche;
	$tree{"tab_seq"} = \%tab_seq;
	if (not exists($tree{"ancestor"})) {
	    setAncType($file, ANC::Rooted);
	}
	push @trees, \%tree;
	redo TREE;
    } continue {
	erreur("Unexpected end of file while reading a tree\n".
	       "in file '$filename' at line $.\n", 0);
    }
    close(INPUT);
    #print STDERR Dumper(@trees);
    return \@trees;
}

sub ReadPAML 
{
    my $file=shift;
    my $filename=$file->{"filename"};
    my($ligne);
    my @trees;
    
    open (INPUT, '<', $filename)
	or erreur("Unable to open read '$filename': $!\n", 0);
  TREE: 
    {
	my(@tab_longbranche, @tab_infoapo);
	my($nb_br_non_nulle)=0;
	my(%tree);
	
      FIND_TREE:
	{
	    while ($ligne=<INPUT>) {
		last FIND_TREE if ($ligne =~ /^\s*Summary of changes along branches/);
	    }
	    # Fin du fichier
	    last TREE;
	}
	$tree{"line"}=$.;	
      READ_LONGBRANCHE:
	{
	  READ_BRANCH:
	    while ($ligne=<INPUT>) {
		chomp($ligne);
		if ($ligne =~ /^\s*List of extant and reconstructed sequences/) {
		    last READ_LONGBRANCHE;
		}
		if ($ligne =~ /^\s*$/) {
		    next;
		}
		if ($ligne =~ /^Check root for directions of change./) {
		    next;
		}
		if (($ligne =~ /\s*Branch [0-9]+:\s+([0-9]+)\.\.([0-9]+)\s*$/) || 
		    ($ligne =~ /\s*Branch [0-9]+:\s+([0-9]+)\.\.[0-9]+\s+[(](.*)[)]\s*$/)) {
		    my $father=$1;
		    my $son=$2;
		    my $br_len=0;
		  READ_APO:
		    {
			while ($ligne=<INPUT>) {
			    if ($ligne =~ /^\s*$/) {
				next;
			    }
			    if ($ligne =~ /\s*([0-9]+)\s+([0-9A-Za-z?_-])\s+[0-9.]+\s*->\s*([0-9A-Za-z?_-])\s*([0-9\.]*)?\s*/) {
				# A VERIFIER: NORMALEMENT NE DOIT SE PRODUIRE QU'EN BOUT DE BRANCHES!
				if ($3 eq "?") {
				    next;
				}
				#father
				#son
				# apomorphie number
				# CI
				# nb steps =1 for SNPs 
				# direction of the change 
				$br_len++;
				push @tab_infoapo, [$father, $son, $1, undef,
						    1, ALTree::Sens
						    ->New($2."->".$3)];				
			    } else {
				last READ_APO;
			    }
			}
			next TREE;
		    }

		    # We add (son, father, branch length)
		    push @tab_longbranche, [$father, $son, $br_len];
		    if ($br_len != 0) {
			$nb_br_non_nulle++;
		    }
		    # On boucle : on a déjà trouvé une autre ligne
		    redo READ_BRANCH;
		} else {
		    erreur("Sorry, I am unable to understand:\n$ligne\n".
			   "in file '$filename' at line $.\n", 0);
		}
	    }
	    next TREE;
	}
	$tree{"tab_longbranche"} = \@tab_longbranche;
	$tree{"tab_infoapo"} = \@tab_infoapo;
	$tree{"nb_br_non_nulle"} = $nb_br_non_nulle;
	setAncType($file, ANC::Unrooted);
	push @trees, \%tree;
	redo TREE;
    } continue {
	erreur("Unexpected end of file while reading a tree\n".
	       "in file '$filename' at line $.\n", 0);
    }
    close(INPUT);
    #print STDERR Dumper(@trees);
    return \@trees;
}

sub PrepareTree {
    my $phylo_program=shift;
    my $input_file=shift;
    my $datatype=shift;
    my $ancetre=shift;
    my $number_arbre=shift;

    return $input_file->{"trees"}->[$number_arbre];
}

#use Data::Dumper;
sub readTreeOld {
    my $phylo_program=shift;
    my $tab_arbre=shift;
    my $datatype=shift;
    my $ancetre=shift;
    my $tree;

    my $tab_longbranche=$tab_arbre->{"tab_longbranche"};
    $tree=TreeBuilding($tab_longbranche);
    
    #print STDERR Dumper($tab_arbre);
    #print STDERR Dumper($tree);
    if ($phylo_program == PhylProg::PHYLIP) {
	my $racine=$tree->GetRoot();
	my $ancetre_seq;
	if (not defined($tab_arbre->{"ancestor"})) {
	    if ($ancetre) {
		$ancetre_seq=$ancetre;
	    } else {
		erreur ("You have forgotten the option --anc-seq!\n", 0);
	    }
	} else {
	    $ancetre_seq=$tab_arbre->{"ancestor"};
	    if ($ancetre && $ancetre ne $ancetre_seq) {
		print STDERR "ancestor defined twice, the sequence entered".
		    " with the -anc-seq option will be ignored for the".
		    " tree number ".($tab_arbre->{"index"}+1)."\n";
	    }
	}
	BuildInfoApoPhylip($tab_arbre, $ancetre_seq, $racine);
    }elsif ($phylo_program == PhylProg::PAUP ||
	$phylo_program == PhylProg::PAML) {
	
    } else {
	ALTree::Utils::internal_error("Phylogeny program not supported");
    }
    
    my $tab_infoapo=$tab_arbre->{"tab_infoapo"};
    FillTreeApoInfo($tree, $tab_infoapo);

    if (not defined($tab_arbre->{"has_ambiguity"})) {
	# CheckApoBrlen($tree); Pb avec phylip..
	my $nb_br_non_nulle=$tab_arbre->{"nb_br_non_nulle"};
	$tree->SetNbBrNonNulle($nb_br_non_nulle);

	CheckApoBrlen($tree);
    }

    return $tree;
}

###########################################
#########  BUILDING OF THE TREE  ##########
###########################################


# Build the tree and add the branch length info
sub TreeBuilding{
    my($tab_longbranche)=shift;
    my($i);
    my($tree)=ALTree::Tree->New();

    #print "TreeBuilding\n";
    for ($i=0;$i<=$#$tab_longbranche;$i++) {
	my($pere_id, $fils_id, $long_br); # variables intermédiaires pour 
	# lisibilite du prog
	    
	$pere_id=$tab_longbranche->[$i]->[0];
	$fils_id=$tab_longbranche->[$i]->[1];
	$long_br=$tab_longbranche->[$i]->[2];

	my $pere;
	my $fils;
	if (not $tree->HasNodeIndex($fils_id)) {
	    $fils=ALTree::Node->New($fils_id); #creation de la structure Node
	    $tree->AddNode($fils);     # puis, on la met dans tree
	} else {
	    $fils=$tree->GetNode($fils_id);
	}
	if (not $tree->HasNodeIndex($pere_id)) {
	    $pere=ALTree::Node->New($pere_id); #creation de la structure Node
	    $tree->AddNode($pere);     # puis, on la met dans tree
	} else {
	    $pere=$tree->GetNode($pere_id);
	}
	$pere->AddChild($fils);
#	print "arbre{pere}->{children}->[0]->{id} ", $arbre->{$pere}->{"children"}->[0]->{"id"}, "\n"; 
	if ($fils->HasFather()) {
	    die ($fils->Name()." already have a father: ".$fils->GetFather()->Name().
		 " and I would like ".$pere->Name()." as father\n");
	} else {
	    $fils->SetFather($pere);
	}
	if ($fils->HasBrLen()) {
	    die($fils->Name()." already have a branch length: ".$fils->GetBrLen()."\n");
	} else {
	    $fils->SetBrLen($long_br);
	}
    }
    return($tree);
}

sub FillTreeApoInfo
{
    my($tree)=shift;
    my($tab_infoapo)=shift;
    my($i);
 
    #print "FillTreeApoInfo\n";
    for ($i=0;$i<=$#$tab_infoapo;$i++) {
	my($pere_id, $fils_id, $apo_num, $apo_CI, $apo_steps, $apo_sens)
	    = @{$tab_infoapo->[$i]};
	#print "branche pere($pere) -> fils($fils)\n";
	if (not $tree->HasNodeIndex($pere_id) or
	    not $tree->HasNodeIndex($fils_id)) {
	    my $id;
	    if (not $tree->HasNodeIndex($pere_id)) {
		$id=$pere_id;
	    } else {
		$id=$fils_id;
	    }
	    erreur("For the apomorphy $apo_num ('$pere_id' -> '$fils_id'),".
		   " the node name\n'$id' has not been found in the tree\n".
		   "Please, check your data.", 0);
	}
	my $pere=$tree->GetNode($pere_id);
	#print $pere->Name();
	my $fils=$tree->GetNode($fils_id);
	#print STDERR "fils =  $fils_id, pere=$pere_id\n";
	if ($fils->GetFather() != $pere) {
	    erreur("I read the apomorphy $apo_num ('$pere_id' -> '$fils_id').\n".
		   "However, the node '$fils_id' has '".
		   $fils->GetFather()->Name()."' as father in the tree.\n".
		   "Please, check your data.", 0);
	}
	
	my $site;
	if (not $tree->HasSiteIndex($apo_num)) { 
	    $site=ALTree::SitePerTree->New($apo_num);
	    $tree->AddSite($site);
	    # CI is not used any more
	    #if (defined $apo_CI) { # For PAML trees, CI is not defined
	    #    $site->SetCI($apo_CI);
	    #}
	} else {
	    $site=$tree->GetSite($apo_num);
	}

	my($ref_site_sens)=$site->ProvideSens($apo_sens);
	$ref_site_sens->SetStep($apo_steps); # For PAML, $aposteps=1

	$fils->AddApo($ref_site_sens); # lie arbre et hash_site_sens
    }
}

sub BuildInfoApoPhylip
{
    my($tab_arbre)=shift;
    my($ancetre_seq)=shift;
    my($racine)=shift;
    
    my @tab_infoapo;
    my $nb_br_non_nulle=0;
    my $has_ambiguity=0;
    my($tab_seq)=$tab_arbre->{"tab_seq"};

    my $set_seq;

    my $root=$racine->GetId();

    $set_seq=sub {
	my $son=shift;

	my $branch=$tab_seq->{$son};
	if (scalar(@{$branch})==4) {
	    return;
	}

	my $father=$branch->[0];
	my $fatherseq;
	
	if (not defined($tab_seq->{$father})) {
	    if ($father ne $root) {
		erreur("The node '$son' seems to be a son of '".
		       $father."'\nbut I cannot get info about this branch ".
		       "in the tree number ".($tab_arbre->{"index"}+1).
		       "\nthat begins at line ".$tab_arbre->{"line"}.
		       " in file '".$tab_arbre->{"file"}->{"filename"}.
		       "'\nPlease, check your data.\n", 0);
	    }
	    $fatherseq=$ancetre_seq;
	} else {
	    if (scalar(@{$tab_seq->{$father}}) == 3) {
		$set_seq->($father);
	    }
	    $fatherseq=$tab_seq->{$father}->[3];
	}
	my $childseq=$branch->[2];
	my $longueur=length($childseq);

	if (length($fatherseq) != $longueur) {
	    erreur("Reconstructed sequences have not the same length".
		   " at node '".$father."'\n($fatherseq) and at node '".
		   $son."' ($childseq)\n", 0);
	}
	my($br_len)=0;
	my($newchildseq)="";
	for (my $i=0; $i<$longueur;$i++) {
	    my($fathersite)= substr($fatherseq,$i,1);
	    my($childsite)= substr($childseq, $i,1);
	    if ($childsite eq ".") {
		$childsite=$fathersite;
		
	    } elsif ($fathersite ne $childsite) {
		if ($fathersite eq '?' || $childsite eq '?') {
		    $has_ambiguity++;
		} 
		$br_len++;
		my($apo_num)=$i+1;
		my($apo_sens)=ALTree::Sens->New($fathersite."->".$childsite);
		push @tab_infoapo, [$father, $son, $apo_num,
				    undef, # Pas de CI dans les données avec PHYLIP
				    1, # Pas de gestion des micro sat.
				    $apo_sens];
	    }
	    $newchildseq.=$childsite;
	}
	if ($br_len != 0) {
	    $nb_br_non_nulle++;
	}
	push @{$branch}, $newchildseq;
    };

    for my $son (keys %{$tab_seq}) {
	$set_seq->($son);
    }

    $tab_arbre->{"tab_infoapo"}=\@tab_infoapo;
    $tab_arbre->{"nb_br_non_nulle"}=$nb_br_non_nulle;
    if ($has_ambiguity) {
	$tab_arbre->{"has_ambiguity"}=$has_ambiguity;
    }
    #delete($tab_arbre->{"tab_seq"});
}


sub CheckApoBrlen
{
    my($tree)=shift;
    my($node);

    $tree->GetRoot()->SetBrLen(0); # to prevent "uninitialized value"

    foreach $node ($tree->GetNodesList()) {
	if ($node->GetBrLen() != $node->NbApoStep()) { 
            # check if nb_apo correspond to br_len
	    die "Error in the tree: branch length= ", $node->GetBrLen(),
	    " but ", $node->NbApoStep(),
	    " apomorphies are defined for node ", $node->Name(), "\n";
	}
    }	
}

1;