7.4 Test the TreeSummary class

(Win version)

< 7.3 | 7.4 | 8.0 >

To test the TreeSummary class, we need for the main function to create a TreeSummary object and call its readTreeFile and showSummary functions. We also need a tree file to read, and need to link in the Nexus Class Library to do the work of parsing this tree file.

Create a tree file

Create a new filter in your Solution Explorer named Data Files by right-clicking on the strom solution, then choosing Add > New Filter. Filters in VSC19 are folder aliases that help you organize files.

Create a file named test.tre by right-clicking on your new Data Files filter and choosing Add > New Item… > Utility > Test file (.txt). Fill your new test.tre file with the following text:

#NEXUS
[ID: 1234567]
begin taxa;
  dimensions ntax=33;
  taxlabels
    'Bracteacoccus minor UTEX66'
    'Bracteacoccus aerius UTEX1250'
    'Pseudomuriella engadinensis UTEX58'
    'Pseudomuriella schumacherensis SAG2137'
    'Bracteamorpha trainori CC1VF5A'
    'Radiococcus polycoccus SAG217 1c'
    'Planktosphaeria gelatinosa SAG262 1b'
    'Planktosphaeria texensis UTEX1241'
    'Planktosphaeria botryoides UTEXLB951'
    'Chromochloris zofingiensis UTEX56'
    'Pediastrum duplex UTEX1364'
    'Parapediastrum biradiatum UTEX37'
    'Ankistrodesmus falcatus UTEX101'
    'Neochloris aquatica UTEX138'
    'Botryococcus sudeticus'
    'Characiopodium hindakii'
    'Scenedesmus obliquus UTEX393'
    'Scenedesmus rotundus SEV3VF49'
    'Hariotina reticulata UTEX1365'
    'Schizochlamys gelatinosa SAG66 94'
    'Dictyococcus varians UTEXLB62'
    'Dictyochloris fragrans UTEX127'
    'Mychonastes homosphaera CAUPH6502'
    'Mychonastes jurisii SAG3798'
    'Schroederia setigera UTEXLB2454'
    'Chlorotetraedron incus SAG4381'
    'Kirchneriella aperta SAG2004'
    'Sphaeroplea robusta UTEX2350'
    'Ankyra judai SAG17 84'
    'Tumidella tumida SAG2265'
    'Rotundella rotunda WJT54VFNP11'
    'Rotundella sp ZNP1VF31'
    'Ourococcus multisporus';
end;

begin trees;
	translate
		1 'Bracteacoccus minor UTEX66',
		2 'Bracteacoccus aerius UTEX1250',
		3 'Pseudomuriella engadinensis UTEX58',
		4 'Pseudomuriella schumacherensis SAG2137',
		5 'Bracteamorpha trainori CC1VF5A',
		6 'Radiococcus polycoccus SAG217 1c',
		7 'Planktosphaeria gelatinosa SAG262 1b',
		8 'Planktosphaeria texensis UTEX1241',
		9 'Planktosphaeria botryoides UTEXLB951',
		10 'Chromochloris zofingiensis UTEX56',
		11 'Pediastrum duplex UTEX1364',
		12 'Parapediastrum biradiatum UTEX37',
		13 'Ankistrodesmus falcatus UTEX101',
		14 'Neochloris aquatica UTEX138',
		15 'Botryococcus sudeticus',
		16 'Characiopodium hindakii',
		17 'Scenedesmus obliquus UTEX393',
		18 'Scenedesmus rotundus SEV3VF49',
		19 'Hariotina reticulata UTEX1365',
		20 'Schizochlamys gelatinosa SAG66 94',
		21 'Dictyococcus varians UTEXLB62',
		22 'Dictyochloris fragrans UTEX127',
		23 'Mychonastes homosphaera CAUPH6502',
		24 'Mychonastes jurisii SAG3798',
		25 'Schroederia setigera UTEXLB2454',
		26 'Chlorotetraedron incus SAG4381',
		27 'Kirchneriella aperta SAG2004',
		28 'Sphaeroplea robusta UTEX2350',
		29 'Ankyra judai SAG17 84',
		30 'Tumidella tumida SAG2265',
		31 'Rotundella rotunda WJT54VFNP11',
		32 'Rotundella sp ZNP1VF31',
		33 'Ourococcus multisporus';
	tree   2topo212 = (1:0.15627210,(30:0.17162998,(((5:0.25666877,((6:0.25918524,(8:0.04890046,9:0.02103898):0.16393496):0.07744044,(((13:0.24662238,27:0.17921628):0.03452417,33:0.21951314):0.12422514,(24:0.05135497,23:0.08634639):0.29672639):0.02603509):0.04301592):0.02147069,((((17:0.11304779,(19:0.19230870,18:0.17106424):0.04876048):0.06024803,(((26:0.12528321,(12:0.14811074,11:0.10159416):0.12450103):0.11574026,(14:0.17432556,(15:0.14378088,16:0.16952013):0.07100215):0.11501679):0.06325832,(32:0.05236326,31:0.03443277):0.35846911):0.01210282):0.05449317,(((28:0.11725934,29:0.10772249):0.27946445,25:0.38458363):0.00596258,22:0.37338675):0.04813972):0.03168543,(10:0.34204294,(4:0.06438535,3:0.05207162):0.17721564):0.09167346):0.03102114):0.05358973,((7:0.21563145,20:0.25535189):0.04878285,21:0.45456205):0.10424236):0.04005845):0.13566845,2:0.15577441);
	tree  37topo212 = (1:0.19535319,(30:0.21396159,(((((4:0.06681961,3:0.05541859):0.20988915,10:0.33177384):0.07063769,(((17:0.10503839,(19:0.18486713,18:0.13774763):0.07906941):0.05218904,((32:0.04101216,31:0.02770287):0.34559869,((14:0.21037724,(15:0.14385916,16:0.20516275):0.03494270):0.14087560,((12:0.15299548,11:0.09111928):0.15599325,26:0.12149992):0.03630639):0.05173516):0.00399992):0.07032845,((25:0.40721998,(28:0.10814417,29:0.13006267):0.35070553):0.00810781,22:0.48605529):0.02915788):0.00443725):0.03465077,(((6:0.33026531,(8:0.03452133,9:0.03577985):0.14055156):0.07528730,((24:0.07724682,23:0.04864349):0.26668853,((13:0.25391435,27:0.14815373):0.03760906,33:0.17433277):0.11920613):0.01382651):0.04943612,5:0.26938200):0.04605544):0.05798100,(21:0.45881190,(20:0.25293709,7:0.13093373):0.02727468):0.14226066):0.01826858):0.15905419,2:0.12223918);
	tree 177topo212 = (1:0.17263901,(30:0.20992067,(((20:0.18697491,7:0.20783012):0.02022342,21:0.55912126):0.15786325,((5:0.32191893,((((13:0.22120673,27:0.14088151):0.12466135,33:0.20099223):0.10429643,(24:0.04519368,23:0.10657649):0.26923351):0.04840972,(6:0.34311725,(8:0.06647765,9:0.02513638):0.12167059):0.09308608):0.03699157):0.03553243,(((22:0.41515488,(25:0.40934369,(28:0.07315304,29:0.14252246):0.28599405):0.02714662):0.04648712,((17:0.10241118,(19:0.15187746,18:0.13872898):0.07522029):0.07677836,(((14:0.21666447,(16:0.17464475,15:0.10474928):0.03565734):0.14916653,((12:0.12576209,11:0.09283544):0.12182421,26:0.10155592):0.06173464):0.07438984,(32:0.03727526,31:0.00825297):0.40050603):0.02452030):0.06175045):0.01611106,(10:0.30285524,(4:0.09298016,3:0.06285482):0.21244857):0.05596027):0.02822623):0.02385617):0.03964512):0.12164953,2:0.13314206);
	tree 817topo212 = (1:0.19215872,(((((((((26:0.20396310,(12:0.17477873,11:0.10084075):0.13460141):0.08771374,(14:0.21573087,(15:0.18461346,16:0.15407304):0.08978479):0.15596104):0.04588627,(32:0.06028829,31:0.01004081):0.41204051):0.00982853,((19:0.21149271,18:0.17387892):0.05163667,17:0.14656430):0.08237560):0.08025059,(22:0.52381962,(25:0.40330052,(28:0.10940880,29:0.15724750):0.26358713):0.05715116):0.03890461):0.01082136,((4:0.09774546,3:0.04765817):0.21833378,10:0.39081571):0.06929534):0.04574448,((((33:0.22267066,(27:0.13682667,13:0.25232487):0.10200532):0.18416847,(24:0.05246640,23:0.08160045):0.31519901):0.06970887,(6:0.35894655,(8:0.03974742,9:0.04956770):0.16531089):0.08256358):0.05406209,5:0.33414002):0.03053482):0.03697446,((7:0.20220552,20:0.29151778):0.04382592,21:0.74201221):0.11221562):0.01333178,30:0.22124048):0.18243369,2:0.14916207);
	tree 846topo212 = (1:0.21513445,(30:0.26663916,(((7:0.20473226,20:0.25328580):0.05298203,21:0.57646513):0.10292079,((((4:0.09780566,3:0.07558274):0.17260496,10:0.35684935):0.11017788,((22:0.50524527,((28:0.10958918,29:0.09536010):0.26691263,25:0.49841657):0.03391956):0.05696541,(((32:0.03023503,31:0.05170754):0.49718552,((14:0.21218183,(15:0.08765387,16:0.25747977):0.07087899):0.16581063,(26:0.11473012,(12:0.11632502,11:0.07317669):0.21865315):0.06720179):0.09504242):0.00639096,((19:0.21159655,18:0.16062796):0.06147523,17:0.17146503):0.06865098):0.06735468):0.02290002):0.02864395,(((((27:0.12371550,13:0.26241311):0.09760657,33:0.17976275):0.15376519,(24:0.06420439,23:0.06113029):0.23022214):0.03430232,(6:0.31306236,(8:0.05328654,9:0.04046049):0.21189102):0.11170889):0.02112370,5:0.25643529):0.05138383):0.03807838):0.02579456):0.16665911,2:0.10958482);
	tree 898topo212 = (1:0.16198847,((((20:0.26670432,7:0.22141509):0.05276667,21:0.52255443):0.08155109,((((4:0.09432053,3:0.05247520):0.16683187,10:0.36310306):0.05592855,(((25:0.38402025,(28:0.10044142,29:0.08872256):0.28362652):0.03888522,22:0.46054441):0.06647122,(((32:0.03010925,31:0.03149605):0.47312032,(((12:0.11790036,11:0.08874953):0.16495361,26:0.13870705):0.04269158,((16:0.19041063,15:0.11657282):0.03856503,14:0.21286280):0.16520670):0.06191210):0.02670160,((19:0.18325572,18:0.16495378):0.05088473,17:0.13629704):0.05781484):0.04884538):0.00534596):0.03356130,(((6:0.29267279,(8:0.04113496,9:0.03650958):0.11176421):0.09883280,(((27:0.19591516,13:0.32002223):0.04389872,33:0.19269516):0.18094088,(24:0.08522457,23:0.04779144):0.25657281):0.01681926):0.04264673,5:0.26109259):0.02740096):0.03792393):0.04607720,30:0.20333768):0.09994832,2:0.14568199);
	tree 907topo212 = (1:0.20461837,((((7:0.23776249,20:0.25434065):0.02509091,21:0.90916260):0.17338878,((((6:0.38239503,(8:0.06381691,9:0.04168967):0.19944817):0.09643838,((24:0.04687438,23:0.07277379):0.41477468,((27:0.15245821,13:0.30907069):0.08394772,33:0.25676649):0.14788194):0.04833612):0.05490340,5:0.28519098):0.02167413,(((22:0.53790470,(25:0.47408819,(28:0.11004475,29:0.12790169):0.33528429):0.05567563):0.04519669,(((19:0.23449678,18:0.21631034):0.07767688,17:0.22290284):0.10064774,((((12:0.14072866,11:0.13139114):0.15031812,26:0.15025778):0.10488677,((16:0.20172241,15:0.10584334):0.04099575,14:0.24466104):0.20382049):0.06271032,(32:0.03650932,31:0.03375336):0.48832468):0.03467965):0.05204606):0.04022710,(10:0.44932193,(4:0.07760529,3:0.06515857):0.22255570):0.08206779):0.03658961):0.04350243):0.04258045,30:0.29612509):0.17567765,2:0.19394228);
	tree 961topo212 = (1:0.17386767,(30:0.20096556,(((7:0.24838722,20:0.24967932):0.04924312,21:0.67176924):0.14161764,((5:0.31260921,((6:0.34205844,(8:0.04105908,9:0.03081368):0.15106287):0.10216270,(((27:0.12911654,13:0.32517888):0.12379905,33:0.24448261):0.22659492,(24:0.04748320,23:0.09031660):0.36680677):0.06703485):0.06555158):0.01726319,(((4:0.07427326,3:0.07296012):0.23644957,10:0.47937271):0.04292213,((((((15:0.14725263,16:0.23261244):0.04392687,14:0.16615839):0.22699258,(26:0.15460844,(12:0.15914763,11:0.09769891):0.19641188):0.02518916):0.05332953,(32:0.04194514,31:0.02829988):0.48827767):0.01147546,((19:0.28408934,18:0.14871767):0.06437906,17:0.12320983):0.06744618):0.10383004,(22:0.40866296,(25:0.41413100,(28:0.10463571,29:0.11786032):0.37944233):0.02072903):0.08122673):0.01002759):0.00599986):0.05123263):0.05585731):0.12454454,2:0.20340308);
	tree 143topo213 = (1:0.26112860,((5:0.31220582,((((25:0.51550560,(22:0.52353006,(28:0.14324520,29:0.14053730):0.34603630):0.02779240):0.03445346,((17:0.12387663,(19:0.22469310,18:0.15472169):0.04509815):0.11084823,((((15:0.11388810,16:0.22559712):0.06600357,14:0.25840723):0.20119355,((12:0.14685851,11:0.09607501):0.14959120,26:0.16966399):0.06829334):0.04224642,(32:0.04024682,31:0.03885332):0.40575374):0.02040799):0.09369484):0.05579514,(((6:0.41872582,(8:0.05164389,9:0.03771417):0.16775113):0.10410476,(((13:0.31823795,27:0.15018413):0.01891399,33:0.30915845):0.18292721,(24:0.08658377,23:0.06140332):0.32865726):0.05925033):0.03666646,(10:0.49113002,(4:0.08933284,3:0.06760523):0.22461695):0.08519352):0.00107753):0.00892563,(21:0.58770471,(20:0.26302490,7:0.26473277):0.05966628):0.15178740):0.10644283):0.02041923,30:0.24014992):0.21024026,2:0.18633689);
	tree 741topo213 = (1:0.22171991,(30:0.25900641,((((20:0.30264240,7:0.24147233):0.07246882,21:0.56271716):0.16066237,(((((24:0.09299165,23:0.07584903):0.34500827,((13:0.22788123,27:0.16234166):0.14454174,33:0.26405592):0.12990463):0.03216220,(6:0.30613896,(8:0.05594103,9:0.03516623):0.23076364):0.08236131):0.06536683,(10:0.42464789,(4:0.10089239,3:0.07295535):0.19186868):0.09356935):0.02523984,(((22:0.59034781,(28:0.13156961,29:0.08483917):0.30973904):0.03177155,25:0.49933021):0.09034257,((((26:0.15910998,(12:0.16611627,11:0.10336010):0.21657205):0.08282432,((15:0.12929642,16:0.20443772):0.04498545,14:0.22750064):0.22144510):0.06868404,(32:0.05119722,31:0.02384305):0.45287767):0.01412821,(17:0.18654944,(19:0.18861905,18:0.15140115):0.06067833):0.08812682):0.07782974):0.05937663):0.02205317):0.02471975,5:0.28963780):0.04931392):0.17534565,2:0.15879502);
	tree  78topo218 = (1:0.15522631,((((21:0.63937305,(7:0.29676164,20:0.26716385):0.01476052):0.22954033,((((4:0.11532201,3:0.07025891):0.21653955,10:0.44953101):0.14528780,((25:0.49466480,(22:0.58175930,(28:0.13780585,29:0.12603872):0.43663687):0.00844292):0.07533226,((17:0.17007284,(19:0.23223558,18:0.17873777):0.11473854):0.13444985,(((14:0.18674691,(15:0.16190401,16:0.20953263):0.07782970):0.25646314,((12:0.17044354,11:0.13048074):0.12871179,26:0.17921157):0.08045630):0.10115642,(32:0.03075485,31:0.04137420):0.50088434):0.02679635):0.06375535):0.03949351):0.04729054,((6:0.49065892,(8:0.07437414,9:0.01897836):0.25540707):0.08367898,((24:0.05263214,23:0.07925182):0.36175905,(33:0.23888496,(27:0.22637010,13:0.30307719):0.12722799):0.19726319):0.05587274):0.06519122):0.01583947):0.03829454,5:0.31514653):0.09045467,30:0.24889322):0.17176337,2:0.16431228);
	tree 181topo218 = (1:0.21964821,(30:0.27363100,((((((33:0.24762730,(27:0.20385353,13:0.29958118):0.06762098):0.10210317,(24:0.06782967,23:0.06699537):0.28583354):0.06685218,(6:0.35643154,(8:0.06918355,9:0.02062018):0.19556919):0.06974259):0.07027374,(((4:0.12631969,3:0.06463356):0.17474300,10:0.33499744):0.06093443,((25:0.43545684,(22:0.40373512,(28:0.09904870,29:0.12819919):0.27599699):0.04636438):0.03631356,(((((12:0.11493983,11:0.07465273):0.16300252,26:0.17871081):0.05881028,(14:0.19629105,(16:0.20683871,15:0.14839281):0.06470277):0.16790528):0.06855440,(32:0.03751764,31:0.04360540):0.44400476):0.00648923,(17:0.13897113,(19:0.22368314,18:0.17822496):0.09479475):0.07382450):0.09096026):0.02086107):0.01598582):0.04150429,(21:0.61629981,(20:0.26123912,7:0.26226663):0.05685599):0.12688860):0.01280565,5:0.25337869):0.02665355):0.12477771,2:0.17934048);
	tree 770topo218 = (1:0.24683995,(30:0.23499262,(5:0.29182290,(((20:0.28526547,7:0.20545052):0.11577018,21:0.55003228):0.14414435,(((6:0.31471083,(8:0.06555849,9:0.04108222):0.12079612):0.10432817,((24:0.06852803,23:0.07649896):0.30656467,(33:0.21687230,(27:0.15343279,13:0.34449458):0.09761427):0.15844681):0.02787049):0.05700115,(((25:0.47865528,((28:0.12203615,29:0.11872703):0.37324123,22:0.51644453):0.01738390):0.01553634,((17:0.12362208,(19:0.23597518,18:0.22705861):0.05786148):0.11534667,(((14:0.19408493,(15:0.13251694,16:0.23517370):0.06014407):0.19660936,(26:0.19105958,(12:0.12787843,11:0.11116912):0.13330968):0.01395272):0.08336366,(32:0.04532188,31:0.02779489):0.45442555):0.01338702):0.07440054):0.02111174,(10:0.41687095,(4:0.08593922,3:0.06383540):0.18327578):0.06307708):0.01822460):0.03213461):0.02492279):0.05835069):0.16422981,2:0.13747389);
	tree 816topo218 = (1:0.19037066,(30:0.27962058,(5:0.34820923,(((20:0.33568596,7:0.12588165):0.02689698,21:0.61142091):0.19723424,(((((22:0.40512882,(28:0.14881953,29:0.11329904):0.29764565):0.01775492,25:0.42212569):0.04609111,((((26:0.19713142,(12:0.10971368,11:0.10479760):0.14713900):0.02758304,(14:0.25032452,(15:0.15117264,16:0.16866836):0.07906727):0.19041807):0.04732945,(32:0.05177143,31:0.04051608):0.37330425):0.01624963,((19:0.22631626,18:0.16409233):0.06442115,17:0.12726306):0.07221645):0.06752339):0.02170407,((4:0.07773644,3:0.06579250):0.13552964,10:0.39817844):0.11136795):0.03268384,((((13:0.23728602,27:0.14842231):0.11460138,33:0.23859964):0.15758011,(24:0.04437028,23:0.07482049):0.26098719):0.10172317,(6:0.37061080,(8:0.05306116,9:0.05018997):0.18335257):0.06972578):0.03051827):0.01956732):0.00497875):0.04248373):0.12778280,2:0.16254617);
end;

Modify the main function

Modify the main.cpp file to look like this:

#include &lt;iostream&gt; 
#include "tree_summary.hpp"

using namespace strom;

const double Node::_smallest_edge_length = 1.0e-12;

int main(int argc, const char * argv[]) {
    std::cout &lt;&lt; "Starting..." &lt;&lt; std::endl;

    TreeSummary sumt;
    try {
        sumt.readTreefile("test.tre", 1);
        }
    catch(NxsException x) {
        std::cerr &lt;&lt; "Program aborting due to errors encountered reading tree file." &lt;&lt; std::endl;
        std::cerr &lt;&lt; x.what() &lt;&lt; std::endl;
        std::exit(0);
        }
    sumt.showSummary();

    std::cout &lt;&lt; "\nFinished!" &lt;&lt; std::endl;

    return 0;
} 

Note that a try...catch combination is used to catch and report any exceptions raised by the Nexus Class Library when it attempts to read and interpret the tree file. For example, if the file test.tre is missing, the program will say

"test.tre" does not refer to a valid file.
Program aborted due to errors encountered reading tree file.

Exceptions are small objects that are “thrown” when something unexpected happens within the try block. The catch block specifies what particular exceptions it is prepared to handle (in this case an object of type NxsException). The NxsException object is stored in the variable x, and the what() member function of x returns the message string stored when the exception was generated. Because exceptions normally represent situations from which recovery is impossible, the catch block calls the std::exit function in order to terminate the program after the message is output on the standard error stream.

Installing the Nexus Class Library

Download the Nexus Class Library (NCL) zip archive using the green download button at the NCL SourceForge site. Unzip the ncl-2.1.18.zip file into your libraries directory. (Again, I strongly recommend using the program 7-zip to unzip the downloaded zip file. Move the zip file into your libraries directory, right-click it, then choose 7-zip > Extract Here. Afterwards, delete the zip file - the icon with zipper - to avoid confusion.)

On my machine, the directory path now looks like this:

C:\Users\Paul Lewis\Documents\libraries\ncl-2.1.18

In the navigation bar of Windows Explorer, the path looks like this:

This PC > Documents > libraries > ncl-2.1.18

There is no batch file or VSC19 project for building NCL in Windows, so we will just add it directly to our strom solution as a project named ncl.

Expected output

The expected output is shown below. Keep in mind that tree topologies are ordered arbitrarily; the important thing to note is whether 7 of the trees in the file have one topology, 4 have a distinctly different topology, and the final 2 trees have a third topology distinct from the first two.

Starting...
storing read block: TAXA
storing read block: TREES

Read 13 trees from file
Topology 1 seen in these 4 trees:
  9 10 11 12 
Topology 2 seen in these 2 trees:
  7 8 
Topology 3 seen in these 7 trees:
  0 1 2 3 4 5 6 

Topologies sorted by sample frequency:
            topology            frequency
                   3                    7
                   1                    4
                   2                    2

Finished!

“test.tre” does not refer to a valid file

If you get the error message above, it means that you have tried to run strom from a directory other than the directory containing the tree file (test.tre). The test.tre file should have been installed in the same directory as the strom executable when you issued the command meson install. If you used a command like this to run strom:

../../distr/strom

then you will get the error because strom will look for the test.tre file in the current working directory, which differs from the directory where test.tre resides.

Lost at sea

Important! The lines of output above will be lost in a sea of constructor and destructor notifications unless you comment those out. Visit the Node, Tree, Split, TreeManip, and TreeSummary classes and use // to comment out the std::cout << "Constructing a XXXX" << std::endl; statement inside the constructor and the std::cout << "Destroying a XXXX" << std::endl; statement inside the destructor. In future steps, these “reporter” output lines will be created already commented out so that they can be easily turned on if needed during debugging but not clutter the output during normal operation.

< 7.3 | 7.4 | 8.0 >