#!/usr/bin/python from PIPRes.splits import * from PIPRes.wrap.output_parser import * from PIPRes.testing import silentAssertRaises import unittest, re, cStringIO exampleDotParts = cStringIO.StringIO('''[ID: 1828009548] [ ID = Partition ID number] [ PART = Description of partition in .* format] [ NUM = Number of trees sampled with the partition] [ PROB = Posterior probability of the partition] [ STDDEV(s) = Standard deviation of partition probabilities across partitions] [ BRLEN = Mean branch length] [ VAR = Variance of branch length] [ PSRF = Potential scale reduction factor for branch lengths] [ NRUNS = Number of runs with this partition] ID PART NUM PROB STDDEV(s) BRLEN VAR RNRUNS 1 .*.....22 1.000000 0.000000 0.013188 0.000824 0.954 2 2 ......*22 1.000000 0.000000 0.017005 0.000992 0.981 2 3 .....*.22 1.000000 0.000000 0.019782 0.000875 0.957 2 4 .******22 1.000000 0.000000 0.014797 0.000842 0.959 2 5 ..*....22 1.000000 0.000000 0.016381 0.000999 0.973 2 6 ....*..22 1.000000 0.000000 0.055604 0.000679 0.977 2 7 ...*...22 1.000000 0.000000 0.024443 0.000991 1.008 2 8 .**....20 0.909091 inf 0.009747 0.000367 0.964 2 9 ....***20 0.909092 inf 0.039223 0.000068 0.977 2 10 .....**20 0.909093 inf 0.064646 0.000210 0.969 2 11 ...****19 0.863636 inf 0.009294 0.000046 1.054 2 12 .***.**2 0.090909 inf 0.089055 0.000240 N/A 2 ''') exampleDict = { 2L : 1.0, 4L : 1.0, 8L : 1.0, 16L : 1.0, 32L : 1.0, 64L : 1.0, 126L : 1.0, 6L : 0.909091, 112L : 0.909092, 96L : 0.909093, 120L : 0.863636, 110L : 0.090909 } exPaupOut = cStringIO.StringIO('''P A U P * Portable version 4.0b10 for Unix Tue Jan 3 14:00:14 2006 -----------------------------NOTICE----------------------------- This is a beta-test version. Please report any crashes, apparent calculation errors, or other anomalous results. There are no restrictions on publication of results obtained with this version, but you should check the WWW site frequently for bug announcements and/or updated versions. See the README file on the distribution media for details. ---------------------------------------------------------------- paup> execute /Applications/PhylogenetiX/Mr MrBayes_V3.0_mac/ MrBayes_V3.0_mac.sit paup> execute /Applications/PhylogenetiX/MrBayes_V3.0_mac/ad adh.nex adh.nex.p adh.nex.t paup> execute /Applications/PhylogenetiX/MrBayes_V3.0_mac/adh.nex Processing of file "/Applications/PhylogenetiX/MrBayes_V3.0_mac/adh.nex" begins... Data read in DNA format Data matrix has 54 taxa, 771 characters Valid character-state symbols: ACGT Missing data identified by '?' Gaps identified by '-' "Equate" macros in effect: R,r ==> {AG} Y,y ==> {CT} M,m ==> {AC} K,k ==> {GT} S,s ==> {CG} W,w ==> {AT} H,h ==> {ACT} B,b ==> {CGT} V,v ==> {ACG} D,d ==> {AGT} N,n ==> {ACGT} *** Skipping "mrbayes" block Processing of file "/Applications/PhylogenetiX/MrBayes_V3.0_mac/adh.nex" completed. paup> boot Bootstrap method with heuristic search: Number of bootstrap replicates = 100 Starting seed = 1670417052 Optimality criterion = parsimony Character-status summary: Of 771 total characters: All characters are of type 'unord' All characters have equal weight 339 characters are constant 69 variable characters are parsimony-uninformative Number of parsimony-informative characters = 363 Gaps are treated as "missing" Multistate taxa interpreted as uncertainty Starting tree(s) obtained via stepwise addition Addition sequence: simple (reference taxon = D.persimilis) Number of trees held at each step during stepwise addition = 1 Branch-swapping algorithm: tree-bisection-reconnection (TBR) Steepest descent option not in effect Initial 'MaxTrees' setting = 100 Branches collapsed (creating polytomies) if maximum branch length is zero 'MulTrees' option in effect Topological constraints not enforced Trees are unrooted ^C Do you really want to stop the search? (Y/n) y Bootstrap aborted after 3 replicate(s) Time used = 7 sec (CPU time = 3.12 sec) Bootstrap 50% majority-rule consensus tree /------------------------------------------------------------------------------------------------------------------------------------- D.persimilis(1) | +------------------------------------------------------------------------------------------------------------------------------------- D.pseudoobscura1(2) | +------------------------------------------------------------------------------------------------------------------------------------- D.pseudoobscura2(3) | | /----------------------------------------------------------------------------------------------------------------------------- D.miranda(4) | | | | /--------------------------------------------------------------------------------------------------------------------- D.ambigua(5) | | | | | | /-------- D.subobscura(6) | | +----------------------------------------------------100-----------------------------------------------------+ | | | \-------- D.madeirensis(7) | | | | | | /------------------------------------------------------------------------------------------------------ D.willistoni(8) | | | | | | | | /---------------------------------------------------------------------------------------------- D.lebanonensis(9) | | | | | | | | | | /-------- D.crassifemur(18) | | | | | /---------------------100----------------------+ | | | | | | \-------- Sc.albovittata(28) | | | | | | \--100--+ | | | | /-------- D.silvestris(41) | | | | | /--100--+ | | | | | | \-------- D.heteroneura(49) | | | | | /-100--+ | | | | | | | /-------- D.planitibia(48) | | | | | | \--100--+ | | | | | | \-------- D.differens(50) | | | | | | | | | | /-----100------+ | /-------- D.grimshawi(42) | | /--100--+ | | | /--67---+ /--100--+ | | | | | | | | | | \-------- D.hawaiiensis(53) | | | | | | | | +-100--+ | | | | | | | | | \---------------- D.affinidisjunct(43) | | | | | | | /--52---+ | | | | | | | | | | \----------------------- D.picticornis(47) | | | | | | | | | \--100--+ | | | | | /--100--+ \------------------------------- D.mimica(45) | | | | | | | | | | | | | \--100--+ \--------------------------------------- D.adiastola(46) | | | | | | | | | | | \----------------------------------------------- D.nigra(44) | | | | | | | | | | /-------- D.montana(19) | | | | | /--100--+ | | | | | | \-------- D.lacicola(24) | | | | | /-100--+ | | \--67---+ /--100--+ | | /-------- D.borealis(25) | | | | | | \--67---+ | | | | | | \-------- D.flavomontana(26) | | | | | | | | | | | /------------------100------------------+ /---------------- D.texana(22) | | | | | | | | | | | | | | | +---------------- D.lummei(23) | | | | | | | | | | | | | | \-100--+---------------- D.americana(27) | | | | | | | | | | | | | | /-------- D.virilis 1(39) | | | | | | \--100--+ | | | | | | \-------- D.virilis 2(40) | | | | | | | | | | | | /-------- D.buzzatii 1(20) | | | | | | /--100--+ | | | | | | | \-------- D.buzzatii 2(21) | | | | | | /--------------67--------------+ | | | | \--67--+ | | /-------- D.hydei 1(32) | | | | | | \--100--+ \--67--+ | /--100--+ | | \-------- D.hydei 2(33) | | | | | | | | | | | | /-------- D.arizonae 2(31) | | | | | | /--78---+ | | | | | | | \-------- D.mojavensis 2(35) | | | | | | | | | | | | /--67---+ /--67--+ /-------- D.mojavensis 1(34) | | | | | | | | | | | | | | | | | | \--67---+-------- D.mulleri 1(36) | | | | | | | /--67---+ | | | | | | | | | | \-------- D.navojoa(38) | \--67---+ | | | | | | | | | \--100--+ | /--100--+ \----------------------- D.mulleri 2(37) | | | | | | | | | | | \--100--+ \------------------------------- D.wheeleri(51) | | | | | | | | | \--------------------------------------- D.mayaguana(52) | | | | | | | \------------------------------------------------------- D.mettleri(30) | | | | | \------------------------------------------------------------------------------ D.immigrans(29) | | | \-------------------------------------------------------------------------------------- Z.tuberculatus(54) | | /-------- D.melanogaster(10) | | | +-------- D.simulans(11) | /--100--+ | | +-------- D.mauritiana(12) | | | | /--87--+ \-------- D.sechellia(15) | | | | | \---------------- D.orena(14) | /--100--+ | | | /-------- D.teissieri(13) | | \-----100------+ \-------------------------------------100--------------------------------------+ \-------- D.yakuba(16) | \------------------------------- D.tsacasi(17) Bipartitions found in one or more trees and frequency of occurrence (bootstrap support values): 1 2 3 4 5 5 123456789012345678901234567890123456789012345678901234 Freq % ----------------------------------------------------------------------- .....**............................................... 3.00 100.0% ............*..*...................................... 3.00 100.0% ...................**................................. 3.00 100.0% .........***..*....................................... 3.00 100.0% .......**........************************************* 3.00 100.0% .........*******...................................... 3.00 100.0% .........********..................................... 3.00 100.0% ....************************************************** 3.00 100.0% ...*************************************************** 3.00 100.0% .....................**...*...........**.............. 3.00 100.0% ..................*....*.............................. 3.00 100.0% ..............................*..*****............*... 3.00 100.0% ..............................*..*****............**.. 3.00 100.0% ...............................**..................... 3.00 100.0% .........................................*..........*. 3.00 100.0% .........................................**.........*. 3.00 100.0% ........................................*......***.... 3.00 100.0% ...................**........*********............**.. 3.00 100.0% ......................................**.............. 3.00 100.0% ........................................*.......*..... 3.00 100.0% ..................*....***............................ 3.00 100.0% ..................*..******...........**.............. 3.00 100.0% ........................................***.******..*. 3.00 100.0% ........................................**********..*. 3.00 100.0% .................*.........*.......................... 3.00 100.0% .................***********.************************. 3.00 100.0% .................************************************. 3.00 100.0% .................*.........*............**********..*. 3.00 100.0% ...............................................*.*.... 3.00 100.0% .........***.**....................................... 2.61 87.0% ..............................*...*................... 2.33 77.8% ...................**.........********............**.. 2.00 66.7% .................................*.*.*................ 2.00 66.7% ...................**..........**..................... 2.00 66.7% ..............................*..*****................ 2.00 66.7% ........................**............................ 2.00 66.7% ........................................***...****..*. 2.00 66.7% ..............................*..***.*................ 2.00 66.7% ........*........************************************* 2.00 66.7% ..................*********..***********..........**.. 2.00 66.7% .................************************************* 2.00 66.7% .......*********************************************** 2.00 66.7% ........................................***.*.****..*. 1.56 51.9% ........................................***..*****..*. 1.44 48.1% .....................*....*...........**.............. 1.33 44.4% .................................*.*.................. 1.33 44.4% .................**..*******..........************..*. 1.00 33.3% ...........*..*....................................... 1.00 33.3% ........*............................................* 1.00 33.3% ....*....********..................................... 1.00 33.3% ...................................**................. 1.00 33.3% .....****........************************************* 1.00 33.3% .............................*.**..................... 1.00 33.3% ........................................***....***..*. 1.00 33.3% .........***.......................................... 1.00 33.3% ..............................*..**................... 1.00 33.3% ..............................*..**..*................ 1.00 33.3% ....***............................................... 1.00 33.3% ..................*....*.*............................ 1.00 33.3% ..........**..*....................................... 1.00 33.3% .........................................**...*.....*. 1.00 33.3% .....................**...*........................... 1.00 33.3% .........................................**..**.....*. 1.00 33.3% .......**............................................. 1.00 33.3% ....................................*.............*... 1.00 33.3% .........**...*....................................... 1.00 33.3% .........................................**..*......*. 1.00 33.3% ....*..*********************************************** 1.00 33.3% .....................*....*........................... 1.00 33.3% .**................................................... 1.00 33.3% ..............................*..*.*.*................ 0.67 22.2% ......................*...............**.............. 0.67 22.2% .....................**............................... 0.56 18.5% ...................**.........*..*****............**.. 0.50 16.7% ...................**........*.**..................... 0.50 16.7% .........**........................................... 0.44 14.8% ............**.*...................................... 0.39 13.0% ...................................*.*................ 0.33 11.1% .................................*...*................ 0.33 11.1% ..........................*...........**.............. 0.33 11.1% .....................**...............**.............. 0.33 11.1% ..........**.......................................... 0.22 7.4% paup> q ''') exPaupDict = { 36864L: 1.000000, 58982400L: 1.000000, 18014398509481856L: 0.667000, 18253611008L: 0.778000, 1572864L: 1.000000, 6980894720L: 0.167000, 42949672960L: 0.444000, 824637915136L: 0.222000, 986261930115072L: 1.000000, 3377973526265856L: 0.667000, 130576L: 0.333000, 18014398509351296L: 1.000000, 73400320L: 0.333000, 5629224923037696L: 0.333000, 1125968626319360L: 0.333000, 4505798650626048L: 1.000000, 103079215104L: 0.333000, 50331648L: 0.667000, 1126167268556800L: 1.000000, 134348800L: 1.000000, 17920L: 0.333000, 18014398509481968L: 1.000000, 146028888064L: 0.111000, 6442450944L: 1.000000, 26843545600L: 0.333000, 282574488338432L: 1.000000, 18014398509351168L: 0.667000, 5566827371429888L: 0.667000, 180388626432L: 0.667000, 5584419557474304L: 0.519000, 198642237440L: 0.667000, 5602011743518720L: 0.481000, 824700829696L: 0.111000, 6979321856L: 0.333000, 5619603929563136L: 1.000000, 6444023808L: 0.667000, 4545381069225984L: 0.333000, 171798691840L: 0.111000, 6L: 0.333000, 8650752L: 1.000000, 5496458627252224L: 0.333000, 3377974063136768L: 1.000000, 824766103552L: 1.000000, 703687441776640L: 1.000000, 18432L: 0.333000, 9007199254741248L: 0.333000, 19456L: 0.333000, 96L: 1.000000, 267361714176L: 0.667000, 130560L: 1.000000, 5628400022585344L: 1.000000, 1536L: 0.148000, 3584L: 0.333000, 6291456L: 0.185000, 384L: 0.333000, 69206016L: 0.333000, 42205184L: 0.333000, 824640012288L: 0.111000, 18014398509351392L: 0.333000, 18014398509481872L: 0.333000, 19968L: 1.000000, 4580565441314816L: 0.333000, 164282499072L: 0.333000, 3072L: 0.074000, 9007198986174464L: 1.000000, 4615749813403648L: 0.333000, 28160L: 0.870000, 18014398509481976L: 1.000000, 3378798829240320L: 0.667000, 112L: 0.333000, 4510196697137152L: 1.000000, 824707121152L: 1.000000, 181462368256L: 0.222000, 3377967082242048L: 1.000000, 65024L: 1.000000, 18014398509350912L: 0.667000, 3377967083814912L: 0.167000, 45056L: 0.130000, 824633720832L: 1.000000, 824702926848L: 0.444000, 5628400156934144L: 1.000000, 9007199254609920L: 1.000000, } class SplitTest(unittest.TestCase): def testRawMBSplitRepToSplit(self): silentAssertRaises(self, ValueError, rawMBSplitRepToSplit, 'f') silentAssertRaises(self, ValueError, rawMBSplitRepToSplit, '.**. g') self.assertEqual(rawMBSplitRepToSplit('.35134'), 0L) self.assertEqual(rawMBSplitRepToSplit('*35134'), 1L) self.assertEqual(rawMBSplitRepToSplit('.**.'), 6L) def testReadMBSplitFreqs(self): splitDict = readMBSplitFreqs(exampleDotParts, True) self.assertEqual(splitDict, exampleDict) def testReadPAUPLogForSplitFreqs(self): splitDict = readPAUPLogForSplitFreqs(exPaupOut, True) for k, v in splitDict.iteritems(): self.assertEqual(round(v - exPaupDict[k], 6), 0.0) if __name__ == '__main__': unittest.main()