
(*==============================================================================

     topologies.tl

     This file is part of the TREEFINDER software.

                                    COPYRIGHT (C) 1997-2008 BY GANGOLF JOBB
==============================================================================*)

CountTopologies[
 data,
 Rooted->False,
 TopTenOnly->False,
 AsPercentage->False
][

 freqs,

 makeEdgeLengths[topo][sel:={}]:=<<
  For[If[RemoveEdgeLengths[d]==topo,AppendR[sel,d]],(=d,data=)];
  PutEdgeLengths[topo,sel#GetEdgeLengths@Add/Length[sel]]
 >>,

 makeReport[list]:=<<{Weight->list|1,Phylogeny->list|2}>>

]:=<<

 data=AsTreeList[data];

 data=StandardizeTree[RemoveEdgeSupport[data],HoldFirst->Rooted];

 freqs=Sort[Frequencies[RemoveEdgeLengths[data]]#Reverse,Descending->True];

 If[TopTenOnly,
  freqs=Cut[freqs,{1,Min[{10,Length[freqs]}]}]
 ];

 If[IsTreeList[data,WithEdgeLengths->True],
  freqs=Table[{f|1,makeEdgeLengths[f|2]},(=f,freqs=)]
 ];

 If[AsPercentage,
  Scope[{len:=Length[data]},freqs=Table[{f|1/len*100,f|2},(=f,freqs=)]]
 ];

 freqs#makeReport

>>,
SetMask[CountTopologies,"1."], Protect[CountTopologies],

Create[Rooted], Protect[Rooted],
Create[TopTenOnly], Protect[TopTenOnly],
Create[AsPercentage], Protect[AsPercentage]


