4 // FORESTER -- software libraries and applications
5 // for evolutionary biology research and applications.
7 // Copyright (C) 2008-2009 Christian M. Zmasek
8 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 // Contact: phylosoft @ gmail . com
26 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
28 package org.forester.evoinference;
31 import java.io.FileInputStream;
32 import java.io.StringWriter;
33 import java.util.Date;
34 import java.util.List;
35 import java.util.SortedSet;
37 import org.forester.evoinference.distance.NeighborJoining;
38 import org.forester.evoinference.distance.NeighborJoiningF;
39 import org.forester.evoinference.distance.NeighborJoiningR;
40 import org.forester.evoinference.distance.PairwiseDistanceCalculator;
41 import org.forester.evoinference.distance.S;
42 import org.forester.evoinference.matrix.character.BasicCharacterStateMatrix;
43 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
44 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix.GainLossStates;
46 import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix;
47 import org.forester.evoinference.matrix.distance.DistanceMatrix;
48 import org.forester.evoinference.parsimony.DolloParsimony;
49 import org.forester.evoinference.parsimony.FitchParsimony;
50 import org.forester.io.parsers.GeneralMsaParser;
51 import org.forester.io.parsers.SymmetricalDistanceMatrixParser;
52 import org.forester.io.parsers.nhx.NHXParser;
53 import org.forester.msa.Msa;
54 import org.forester.phylogeny.Phylogeny;
55 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
56 import org.forester.phylogeny.factories.PhylogenyFactory;
57 import org.forester.util.ForesterUtil;
59 public class TestPhylogenyReconstruction {
61 private final static double ZERO_DIFF = 1.0E-9;
63 public static boolean isEqual( final double a, final double b ) {
64 return ( ( Math.abs( a - b ) ) < ZERO_DIFF );
67 public static boolean isUnequal( final double a, final double b ) {
68 return !isEqual( a, b );
71 public static void main( final String[] args ) {
72 System.out.println( "NJ" );
73 if ( testNeighborJoining() ) {
74 System.out.println( " OK." );
77 System.out.println( " failed." );
79 System.out.println( "S" );
81 System.out.println( " OK." );
84 System.out.println( " failed." );
86 System.out.println( "NJR" );
87 if ( testNeighborJoiningR() ) {
88 System.out.println( " OK." );
91 System.out.println( " failed." );
93 //timeNeighborJoining();
96 public static boolean test( final File test_dir ) {
97 System.out.print( " Basic symmetrical distance matrix: " );
98 if ( !testBasicSymmetricalDistanceMatrix() ) {
99 System.out.println( "failed." );
102 System.out.println( "OK." );
103 System.out.print( " Basic character state matrix: " );
104 if ( !testBasicCharacterStateMatrix() ) {
105 System.out.println( "failed." );
108 System.out.println( "OK." );
109 System.out.print( " Symmetrical distance matrix parser: " );
110 if ( !testSymmetricalDistanceMatrixParser() ) {
111 System.out.println( "failed." );
114 System.out.println( "OK." );
115 System.out.print( " Distance Calculation: " );
116 if ( !testDistanceCalculationMethods( test_dir ) ) {
117 System.out.println( "failed." );
120 System.out.println( "OK." );
121 System.out.print( " Datastructure S: " );
123 System.out.println( "failed." );
126 System.out.println( "OK." );
127 System.out.print( " Neighbor Joining: " );
128 if ( !testNeighborJoining() ) {
129 System.out.println( "failed." );
132 System.out.println( "OK." );
133 System.out.print( " Dollo Parsimony: " );
134 if ( !testDolloParsimony() ) {
135 System.out.println( "failed." );
138 System.out.println( "OK." );
139 System.out.print( " Dollo Parsimony on non binary trees: " );
140 if ( !testDolloParsimonyOnNonBinaryTree() ) {
141 System.out.println( "failed." );
144 System.out.println( "OK." );
145 System.out.print( " Fitch Parsimony: " );
146 if ( !testFitchParsimony() ) {
147 System.out.println( "failed." );
150 System.out.println( "OK." );
154 private static boolean testBasicCharacterStateMatrix() {
156 final CharacterStateMatrix<String> matrix_0 = new BasicCharacterStateMatrix<String>( 4, 8 );
157 final CharacterStateMatrix<String> matrix_00 = new BasicCharacterStateMatrix<String>( 4, 8 );
158 matrix_0.setIdentifier( 0, "A" );
159 matrix_0.setIdentifier( 1, "B" );
160 matrix_0.setIdentifier( 2, "C" );
161 matrix_0.setIdentifier( 3, "D" );
162 matrix_0.setCharacter( 0, "0" );
163 matrix_0.setCharacter( 1, "1" );
164 matrix_0.setCharacter( 2, "2" );
165 matrix_0.setCharacter( 3, "3" );
166 matrix_0.setCharacter( 4, "4" );
167 matrix_0.setCharacter( 5, "5" );
168 matrix_0.setCharacter( 6, "6" );
169 matrix_0.setCharacter( 7, "7" );
170 matrix_00.setIdentifier( 0, "A" );
171 matrix_00.setIdentifier( 1, "B" );
172 matrix_00.setIdentifier( 2, "C" );
173 matrix_00.setIdentifier( 3, "D" );
174 matrix_00.setCharacter( 3, "3" );
175 matrix_00.setCharacter( 4, "4" );
176 if ( !matrix_0.getCharacter( 1 ).equals( "1" ) ) {
179 if ( !matrix_0.getIdentifier( 0 ).equals( "A" ) ) {
182 matrix_0.setState( 0, 0, "00" );
183 matrix_00.setState( 0, 0, "00" );
184 if ( !matrix_0.getState( 0, 0 ).equals( "00" ) ) {
187 matrix_0.setState( 0, 1, "01" );
188 matrix_00.setState( 0, 1, "01" );
189 if ( !matrix_0.getState( 0, 1 ).equals( "01" ) ) {
192 matrix_0.setState( 1, 1, "11" );
193 matrix_00.setState( 1, 1, "11" );
194 if ( !matrix_0.getState( 1, 1 ).equals( "11" ) ) {
197 matrix_0.setState( 1, 0, "10" );
198 matrix_00.setState( 1, 0, "10" );
199 if ( !matrix_0.getState( 1, 0 ).equals( "10" ) ) {
202 matrix_0.setState( 1, 2, "12" );
203 matrix_00.setState( 1, 2, "12" );
204 if ( !matrix_0.getState( 1, 2 ).equals( "12" ) ) {
207 matrix_0.setState( 3, 7, "37" );
208 matrix_00.setState( 3, 7, "37" );
209 if ( !matrix_0.getState( 3, 7 ).equals( "37" ) ) {
212 matrix_0.setState( 2, 6, "26" );
213 matrix_00.setState( 2, 6, "26" );
214 if ( !matrix_0.getState( 2, 6 ).equals( "26" ) ) {
217 matrix_0.setState( "D", "3", "33" );
218 matrix_00.setState( "D", "3", "33" );
219 if ( !matrix_0.getState( 3, 3 ).equals( "33" ) ) {
222 if ( !matrix_0.getState( "D", "3" ).equals( "33" ) ) {
225 matrix_0.setState( "C", "4", "24" );
226 matrix_00.setState( "C", "4", "24" );
227 if ( !matrix_0.getState( 2, 4 ).equals( "24" ) ) {
230 if ( !matrix_0.getState( "C", "4" ).equals( "24" ) ) {
233 if ( matrix_0.isEmpty() ) {
236 if ( matrix_0.getNumberOfIdentifiers() != 4 ) {
239 if ( matrix_0.getNumberOfCharacters() != 8 ) {
242 if ( !matrix_0.equals( matrix_0 ) ) {
245 if ( !matrix_0.equals( matrix_00 ) ) {
248 matrix_00.setState( "C", "4", "123" );
249 if ( matrix_0.equals( matrix_00 ) ) {
252 final Integer[][] ints = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };
253 final CharacterStateMatrix<Integer> matrix_000 = new BasicCharacterStateMatrix<Integer>( ints );
254 matrix_000.toString();
255 if ( matrix_000.getNumberOfCharacters() != 4 ) {
258 if ( matrix_000.getNumberOfIdentifiers() != 3 ) {
261 if ( matrix_000.getState( 0, 1 ) != 2 ) {
264 if ( matrix_000.getState( 2, 3 ) != 12 ) {
267 final Integer[][] ints0 = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };
268 final CharacterStateMatrix<Integer> matrix_0000 = new BasicCharacterStateMatrix<Integer>( ints0 );
269 if ( !matrix_000.equals( matrix_0000 ) ) {
272 final Integer[][] ints00 = { { 1, 2, 3, -4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };
273 final CharacterStateMatrix<Integer> matrix_00000 = new BasicCharacterStateMatrix<Integer>( ints00 );
274 if ( matrix_000.equals( matrix_00000 ) ) {
277 final CharacterStateMatrix<String> clone0 = matrix_0.copy();
278 final CharacterStateMatrix<String> clone00 = matrix_00.copy();
279 if ( !clone0.equals( matrix_0 ) ) {
282 if ( !clone00.equals( matrix_00 ) ) {
285 if ( clone00.equals( clone0 ) ) {
288 final CharacterStateMatrix<String> pivot0 = matrix_0.pivot();
289 final CharacterStateMatrix<String> pivot00 = matrix_00.pivot();
290 if ( !pivot0.getState( 1, 0 ).equals( "01" ) ) {
293 if ( !pivot0.getState( 6, 2 ).equals( "26" ) ) {
296 if ( !matrix_0.getState( 2, 6 ).equals( "26" ) ) {
299 final CharacterStateMatrix<String> pivotpivot00 = pivot00.pivot();
300 if ( !pivotpivot00.equals( matrix_00 ) ) {
303 final CharacterStateMatrix<BinaryStates> nex = new BasicCharacterStateMatrix<BinaryStates>( 4, 3 );
304 nex.setIdentifier( 0, "amphioxus" );
305 nex.setIdentifier( 1, "sponge" );
306 nex.setIdentifier( 2, "sea_anemone" );
307 nex.setIdentifier( 3, "cobra" );
308 nex.setCharacter( 0, "notch" );
309 nex.setCharacter( 1, "homeobox" );
310 nex.setCharacter( 2, "wnt" );
311 nex.setState( 0, 0, BinaryStates.ABSENT );
312 nex.setState( 0, 1, BinaryStates.ABSENT );
313 nex.setState( 0, 2, BinaryStates.ABSENT );
314 nex.setState( 1, 0, BinaryStates.PRESENT );
315 nex.setState( 1, 1, BinaryStates.PRESENT );
316 nex.setState( 1, 2, BinaryStates.ABSENT );
317 nex.setState( 2, 0, BinaryStates.PRESENT );
318 nex.setState( 2, 1, BinaryStates.PRESENT );
319 nex.setState( 2, 2, BinaryStates.PRESENT );
320 nex.setState( 3, 0, BinaryStates.PRESENT );
321 nex.setState( 3, 1, BinaryStates.ABSENT );
322 nex.setState( 3, 2, BinaryStates.ABSENT );
323 StringWriter w = new StringWriter();
324 nex.toWriter( w, CharacterStateMatrix.Format.NEXUS_BINARY );
325 //System.out.println( w.getBuffer().toString() );
326 w = new StringWriter();
327 nex.pivot().toWriter( w, CharacterStateMatrix.Format.NEXUS_BINARY );
328 //System.out.println( w.getBuffer().toString() );
330 catch ( final Exception e ) {
331 e.printStackTrace( System.out );
337 private static boolean testBasicSymmetricalDistanceMatrix() {
339 final DistanceMatrix matrix_0 = new BasicSymmetricalDistanceMatrix( 4 );
340 matrix_0.setIdentifier( 0, "A" );
341 matrix_0.setIdentifier( 1, "B" );
342 matrix_0.setIdentifier( 2, "C" );
343 matrix_0.setIdentifier( 3, "0123456789012" );
344 matrix_0.setValue( 1, 0, 0.00001 );
345 matrix_0.setValue( 0, 2, 0.0000009 );
346 matrix_0.setValue( 3, 0, 3.0 );
347 matrix_0.setValue( 1, 2, 4.0 );
348 matrix_0.setValue( 3, 1, 5.0 );
349 matrix_0.setValue( 2, 3, 6.0 );
350 if ( !matrix_0.getIdentifier( 0 ).equals( "A" ) ) {
353 if ( !matrix_0.getIdentifier( 1 ).equals( "B" ) ) {
356 if ( !matrix_0.getIdentifier( 2 ).equals( "C" ) ) {
359 if ( !matrix_0.getIdentifier( 3 ).equals( "0123456789012" ) ) {
362 if ( matrix_0.getSize() != 4 ) {
365 if ( !isEqual( matrix_0.getValue( 0, 0 ), 0.0 ) ) {
368 if ( !isEqual( matrix_0.getValue( 3, 3 ), 0.0 ) ) {
371 if ( !isEqual( matrix_0.getValue( 0, 1 ), 0.00001 ) ) {
374 if ( !isEqual( matrix_0.getValue( 0, 2 ), 0.0000009 ) ) {
377 if ( !isEqual( matrix_0.getValue( 0, 3 ), 3 ) ) {
380 if ( !isEqual( matrix_0.getValue( 1, 0 ), 0.00001 ) ) {
383 if ( !isEqual( matrix_0.getValue( 1, 2 ), 4 ) ) {
386 if ( !isEqual( matrix_0.getValue( 1, 3 ), 5 ) ) {
389 if ( !isEqual( matrix_0.getValue( 2, 0 ), 0.0000009 ) ) {
392 if ( !isEqual( matrix_0.getValue( 2, 1 ), 4 ) ) {
395 if ( !isEqual( matrix_0.getValue( 2, 3 ), 6 ) ) {
398 if ( !isEqual( matrix_0.getValue( 3, 0 ), 3 ) ) {
401 if ( !isEqual( matrix_0.getValue( 3, 1 ), 5 ) ) {
404 if ( !isEqual( matrix_0.getValue( 3, 2 ), 6 ) ) {
407 final StringBuffer matrix_0_phylip = new StringBuffer();
408 matrix_0_phylip.append( " 4" );
409 matrix_0_phylip.append( ForesterUtil.LINE_SEPARATOR );
410 matrix_0_phylip.append( "A 0.000000 0.000010 0.000001 3.000000" );
411 matrix_0_phylip.append( ForesterUtil.LINE_SEPARATOR );
412 matrix_0_phylip.append( "B 0.000010 0.000000 4.000000 5.000000" );
413 matrix_0_phylip.append( ForesterUtil.LINE_SEPARATOR );
414 matrix_0_phylip.append( "C 0.000001 4.000000 0.000000 6.000000" );
415 matrix_0_phylip.append( ForesterUtil.LINE_SEPARATOR );
416 matrix_0_phylip.append( "0123456789 3.000000 5.000000 6.000000 0.000000" );
417 if ( !matrix_0_phylip.toString()
418 .equals( matrix_0.toStringBuffer( DistanceMatrix.Format.PHYLIP ).toString() ) ) {
422 catch ( final Exception e ) {
423 e.printStackTrace( System.out );
429 private static boolean testDistanceCalculationMethods( final File test_dir ) {
431 final Msa msa0 = GeneralMsaParser.parse( new FileInputStream( test_dir + ForesterUtil.FILE_SEPARATOR
433 final BasicSymmetricalDistanceMatrix pwd0 = PairwiseDistanceCalculator.calcKimuraDistances( msa0 );
434 if ( pwd0.getSize() != 120 ) {
437 for( int i = 0; i < pwd0.getSize(); ++i ) {
438 if ( !isEqual( pwd0.getValue( i, i ), 0.0 ) ) {
443 catch ( final Exception e ) {
444 e.printStackTrace( System.out );
450 private static boolean testDolloParsimony() {
452 final BinaryStates PRESENT = BinaryStates.PRESENT;
453 final BinaryStates ABSENT = BinaryStates.ABSENT;
454 final GainLossStates UNCHANGED_PRESENT = GainLossStates.UNCHANGED_PRESENT;
455 final DolloParsimony dollo1 = DolloParsimony.createInstance();
456 final PhylogenyFactory factory1 = ParserBasedPhylogenyFactory.getInstance();
457 final String p1_str = "((((((a,b)ab,c)ac,d)ad,(e,f)ef)af,(g,h)gh)ah,i)r";
458 final Phylogeny p1 = factory1.create( p1_str, new NHXParser() )[ 0 ];
459 CharacterStateMatrix<CharacterStateMatrix.BinaryStates> m1 = new BasicCharacterStateMatrix<CharacterStateMatrix.BinaryStates>( 9,
461 m1.setIdentifier( 0, "a" );
462 m1.setIdentifier( 1, "b" );
463 m1.setIdentifier( 2, "c" );
464 m1.setIdentifier( 3, "d" );
465 m1.setIdentifier( 4, "e" );
466 m1.setIdentifier( 5, "f" );
467 m1.setIdentifier( 6, "g" );
468 m1.setIdentifier( 7, "h" );
469 m1.setIdentifier( 8, "i" );
470 m1.setCharacter( 0, "0" );
471 m1.setState( "a", "0", PRESENT );
472 m1.setState( "b", "0", ABSENT );
473 m1.setState( "c", "0", PRESENT );
474 m1.setState( "d", "0", ABSENT );
475 m1.setState( "e", "0", ABSENT );
476 m1.setState( "f", "0", ABSENT );
477 m1.setState( "g", "0", ABSENT );
478 m1.setState( "h", "0", ABSENT );
479 m1.setState( "i", "0", ABSENT );
480 dollo1.execute( p1, m1 );
481 if ( dollo1.getTotalGains() != 1 ) {
484 if ( dollo1.getTotalLosses() != 1 ) {
487 if ( dollo1.getTotalUnchanged() != 15 ) {
490 m1.setState( "b", "0", PRESENT );
491 dollo1.execute( p1, m1 );
492 if ( dollo1.getTotalGains() != 1 ) {
495 if ( dollo1.getTotalLosses() != 0 ) {
498 if ( dollo1.getTotalUnchanged() != 16 ) {
501 m1.setState( "b", "0", ABSENT );
502 m1.setState( "e", "0", PRESENT );
503 dollo1.execute( p1, m1 );
504 if ( dollo1.getTotalGains() != 1 ) {
507 if ( dollo1.getTotalLosses() != 3 ) {
510 if ( dollo1.getTotalUnchanged() != 13 ) {
513 m1.setState( "a", "0", ABSENT );
514 m1.setState( "c", "0", ABSENT );
515 m1.setState( "g", "0", PRESENT );
516 dollo1.setReturnInternalStates( true );
517 dollo1.setReturnGainLossMatrix( true );
518 dollo1.execute( p1, m1 );
519 if ( dollo1.getTotalGains() != 1 ) {
522 if ( dollo1.getTotalLosses() != 3 ) {
525 if ( dollo1.getTotalUnchanged() != 13 ) {
528 final DolloParsimony dollo2 = DolloParsimony.createInstance();
529 final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
530 final String p2_str = "((((((a,b)ab,c)ac,d)ad,(e,f)ef)af,(g,h,i)gi)ai,((j,k,l)jl,(m,n,o)mo,(p,q,r)pr)jr)root";
531 final Phylogeny p2 = factory2.create( p2_str, new NHXParser() )[ 0 ];
532 final CharacterStateMatrix<CharacterStateMatrix.BinaryStates> m2 = new BasicCharacterStateMatrix<CharacterStateMatrix.BinaryStates>( 18,
534 m2.setIdentifier( 0, "a" );
535 m2.setIdentifier( 1, "b" );
536 m2.setIdentifier( 2, "c" );
537 m2.setIdentifier( 3, "d" );
538 m2.setIdentifier( 4, "e" );
539 m2.setIdentifier( 5, "f" );
540 m2.setIdentifier( 6, "g" );
541 m2.setIdentifier( 7, "h" );
542 m2.setIdentifier( 8, "i" );
543 m2.setIdentifier( 9, "j" );
544 m2.setIdentifier( 10, "k" );
545 m2.setIdentifier( 11, "l" );
546 m2.setIdentifier( 12, "m" );
547 m2.setIdentifier( 13, "n" );
548 m2.setIdentifier( 14, "o" );
549 m2.setIdentifier( 15, "p" );
550 m2.setIdentifier( 16, "q" );
551 m2.setIdentifier( 17, "r" );
552 m2.setCharacter( 0, "0" );
553 m2.setCharacter( 1, "1" );
554 m2.setCharacter( 2, "2" );
555 m2.setCharacter( 3, "3" );
556 m2.setState( "a", "0", PRESENT );
557 m2.setState( "b", "0", ABSENT );
558 m2.setState( "c", "0", PRESENT );
559 m2.setState( "d", "0", ABSENT );
560 m2.setState( "e", "0", ABSENT );
561 m2.setState( "f", "0", ABSENT );
562 m2.setState( "g", "0", ABSENT );
563 m2.setState( "h", "0", ABSENT );
564 m2.setState( "i", "0", ABSENT );
565 m2.setState( "j", "0", ABSENT );
566 m2.setState( "k", "0", ABSENT );
567 m2.setState( "l", "0", ABSENT );
568 m2.setState( "m", "0", ABSENT );
569 m2.setState( "n", "0", ABSENT );
570 m2.setState( "o", "0", ABSENT );
571 m2.setState( "p", "0", ABSENT );
572 m2.setState( "q", "0", ABSENT );
573 m2.setState( "r", "0", ABSENT );
574 m2.setState( "a", "1", PRESENT );
575 m2.setState( "b", "1", ABSENT );
576 m2.setState( "c", "1", PRESENT );
577 m2.setState( "d", "1", ABSENT );
578 m2.setState( "e", "1", ABSENT );
579 m2.setState( "f", "1", ABSENT );
580 m2.setState( "g", "1", PRESENT );
581 m2.setState( "h", "1", ABSENT );
582 m2.setState( "i", "1", ABSENT );
583 m2.setState( "j", "1", PRESENT );
584 m2.setState( "k", "1", ABSENT );
585 m2.setState( "l", "1", ABSENT );
586 m2.setState( "m", "1", PRESENT );
587 m2.setState( "n", "1", ABSENT );
588 m2.setState( "o", "1", ABSENT );
589 m2.setState( "p", "1", ABSENT );
590 m2.setState( "q", "1", ABSENT );
591 m2.setState( "r", "1", ABSENT );
592 m2.setState( "a", "2", ABSENT );
593 m2.setState( "b", "2", ABSENT );
594 m2.setState( "c", "2", ABSENT );
595 m2.setState( "d", "2", ABSENT );
596 m2.setState( "e", "2", ABSENT );
597 m2.setState( "f", "2", ABSENT );
598 m2.setState( "g", "2", ABSENT );
599 m2.setState( "h", "2", ABSENT );
600 m2.setState( "i", "2", ABSENT );
601 m2.setState( "j", "2", PRESENT );
602 m2.setState( "k", "2", ABSENT );
603 m2.setState( "l", "2", ABSENT );
604 m2.setState( "m", "2", PRESENT );
605 m2.setState( "n", "2", ABSENT );
606 m2.setState( "o", "2", ABSENT );
607 m2.setState( "p", "2", PRESENT );
608 m2.setState( "q", "2", ABSENT );
609 m2.setState( "r", "2", ABSENT );
610 m2.setState( "a", "3", ABSENT );
611 m2.setState( "b", "3", ABSENT );
612 m2.setState( "c", "3", PRESENT );
613 m2.setState( "d", "3", ABSENT );
614 m2.setState( "e", "3", ABSENT );
615 m2.setState( "f", "3", ABSENT );
616 m2.setState( "g", "3", PRESENT );
617 m2.setState( "h", "3", ABSENT );
618 m2.setState( "i", "3", ABSENT );
619 m2.setState( "j", "3", ABSENT );
620 m2.setState( "k", "3", ABSENT );
621 m2.setState( "l", "3", ABSENT );
622 m2.setState( "m", "3", ABSENT );
623 m2.setState( "n", "3", ABSENT );
624 m2.setState( "o", "3", ABSENT );
625 m2.setState( "p", "3", ABSENT );
626 m2.setState( "q", "3", ABSENT );
627 m2.setState( "r", "3", ABSENT );
628 dollo2.setReturnInternalStates( true );
629 dollo2.setReturnGainLossMatrix( true );
630 dollo2.execute( p2, m2 );
631 final CharacterStateMatrix<BinaryStates> i_m = dollo2.getInternalStatesMatrix();
632 final CharacterStateMatrix<GainLossStates> gl_m = dollo2.getGainLossMatrix();
633 if ( dollo2.getTotalGains() != 3 ) {
636 if ( dollo2.getTotalLosses() != 22 ) {
639 if ( dollo2.getTotalUnchanged() != 95 ) {
642 if ( i_m.getState( "ab", "0" ) != PRESENT ) {
645 if ( i_m.getState( "ac", "0" ) != PRESENT ) {
648 if ( i_m.getState( "ad", "0" ) != ABSENT ) {
651 if ( i_m.getState( "af", "0" ) != ABSENT ) {
654 if ( i_m.getState( "ef", "0" ) != ABSENT ) {
657 if ( i_m.getState( "ai", "0" ) != ABSENT ) {
660 if ( i_m.getState( "gi", "0" ) != ABSENT ) {
663 if ( i_m.getState( "jl", "0" ) != ABSENT ) {
666 if ( i_m.getState( "mo", "0" ) != ABSENT ) {
669 if ( i_m.getState( "pr", "0" ) != ABSENT ) {
672 if ( i_m.getState( "jr", "0" ) != ABSENT ) {
675 if ( i_m.getState( "root", "0" ) != ABSENT ) {
678 if ( i_m.getState( "ab", "1" ) != PRESENT ) {
681 if ( i_m.getState( "ac", "1" ) != PRESENT ) {
684 if ( i_m.getState( "ad", "1" ) != PRESENT ) {
687 if ( i_m.getState( "af", "1" ) != PRESENT ) {
690 if ( i_m.getState( "ef", "1" ) != ABSENT ) {
693 if ( i_m.getState( "ai", "1" ) != PRESENT ) {
696 if ( i_m.getState( "gi", "1" ) != PRESENT ) {
699 if ( i_m.getState( "jl", "1" ) != PRESENT ) {
702 if ( i_m.getState( "mo", "1" ) != PRESENT ) {
705 if ( i_m.getState( "pr", "1" ) != ABSENT ) {
708 if ( i_m.getState( "jr", "1" ) != PRESENT ) {
711 if ( i_m.getState( "root", "1" ) != PRESENT ) {
714 if ( i_m.getState( "ab", "2" ) != ABSENT ) {
717 if ( i_m.getState( "ac", "2" ) != ABSENT ) {
720 if ( i_m.getState( "ad", "2" ) != ABSENT ) {
723 if ( i_m.getState( "af", "2" ) != ABSENT ) {
726 if ( i_m.getState( "ef", "2" ) != ABSENT ) {
729 if ( i_m.getState( "ai", "2" ) != ABSENT ) {
732 if ( i_m.getState( "gi", "2" ) != ABSENT ) {
735 if ( i_m.getState( "jl", "2" ) != PRESENT ) {
738 if ( i_m.getState( "mo", "2" ) != PRESENT ) {
741 if ( i_m.getState( "pr", "2" ) != PRESENT ) {
744 if ( i_m.getState( "jr", "2" ) != PRESENT ) {
747 if ( i_m.getState( "root", "2" ) != ABSENT ) {
750 if ( i_m.getState( "ab", "3" ) != ABSENT ) {
753 if ( i_m.getState( "ac", "3" ) != PRESENT ) {
756 if ( i_m.getState( "ad", "3" ) != PRESENT ) {
759 if ( i_m.getState( "af", "3" ) != PRESENT ) {
762 if ( i_m.getState( "ef", "3" ) != ABSENT ) {
765 if ( i_m.getState( "ai", "3" ) != PRESENT ) {
768 if ( i_m.getState( "gi", "3" ) != PRESENT ) {
771 if ( i_m.getState( "jl", "3" ) != ABSENT ) {
774 if ( i_m.getState( "mo", "3" ) != ABSENT ) {
777 if ( i_m.getState( "pr", "3" ) != ABSENT ) {
780 if ( i_m.getState( "jr", "3" ) != ABSENT ) {
783 if ( i_m.getState( "root", "3" ) != ABSENT ) {
786 if ( gl_m.getState( "a", "0" ) != UNCHANGED_PRESENT ) {
789 final DolloParsimony dollo9 = DolloParsimony.createInstance();
790 final PhylogenyFactory factory9 = ParserBasedPhylogenyFactory.getInstance();
791 final String p9_str = "((((((a,b)ab,c)ac,d)ad,(e,f)ef)af,(g,h)gh)ah,i)r";
792 final Phylogeny p9 = factory9.create( p9_str, new NHXParser() )[ 0 ];
793 m1 = new BasicCharacterStateMatrix<CharacterStateMatrix.BinaryStates>( 9, 3 );
794 m1.setIdentifier( 0, "a" );
795 m1.setIdentifier( 1, "b" );
796 m1.setIdentifier( 2, "c" );
797 m1.setIdentifier( 3, "d" );
798 m1.setIdentifier( 4, "e" );
799 m1.setIdentifier( 5, "f" );
800 m1.setIdentifier( 6, "g" );
801 m1.setIdentifier( 7, "h" );
802 m1.setIdentifier( 8, "i" );
803 m1.setState( 0, 0, PRESENT );
804 m1.setState( 1, 0, ABSENT );
805 m1.setState( 2, 0, PRESENT );
806 m1.setState( 3, 0, ABSENT );
807 m1.setState( 4, 0, ABSENT );
808 m1.setState( 5, 0, ABSENT );
809 m1.setState( 6, 0, ABSENT );
810 m1.setState( 7, 0, ABSENT );
811 m1.setState( 8, 0, ABSENT );
812 m1.setState( 0, 1, PRESENT );
813 m1.setState( 1, 1, PRESENT );
814 m1.setState( 2, 1, PRESENT );
815 m1.setState( 3, 1, PRESENT );
816 m1.setState( 4, 1, ABSENT );
817 m1.setState( 5, 1, ABSENT );
818 m1.setState( 6, 1, ABSENT );
819 m1.setState( 7, 1, ABSENT );
820 m1.setState( 8, 1, ABSENT );
821 m1.setState( 0, 2, PRESENT );
822 m1.setState( 1, 2, ABSENT );
823 m1.setState( 2, 2, ABSENT );
824 m1.setState( 3, 2, ABSENT );
825 m1.setState( 4, 2, ABSENT );
826 m1.setState( 5, 2, ABSENT );
827 m1.setState( 6, 2, ABSENT );
828 m1.setState( 7, 2, PRESENT );
829 m1.setState( 8, 2, ABSENT );
830 dollo9.execute( p9, m1 );
831 if ( dollo9.getTotalGains() != 3 ) {
834 if ( dollo9.getTotalLosses() != 6 ) {
837 final DolloParsimony dollo10 = DolloParsimony.createInstance();
838 final PhylogenyFactory factory10 = ParserBasedPhylogenyFactory.getInstance();
839 final String p10_str = "((((((a,b)ab,c)ac,d)ad,(e,f)ef)af,(g,h)gh)ah,i)r";
840 final Phylogeny p10 = factory10.create( p10_str, new NHXParser() )[ 0 ];
841 final CharacterStateMatrix<CharacterStateMatrix.BinaryStates> m10 = new BasicCharacterStateMatrix<CharacterStateMatrix.BinaryStates>( 9,
843 m10.setIdentifier( 0, "a" );
844 m10.setIdentifier( 1, "b" );
845 m10.setIdentifier( 2, "c" );
846 m10.setIdentifier( 3, "d" );
847 m10.setIdentifier( 4, "e" );
848 m10.setIdentifier( 5, "f" );
849 m10.setIdentifier( 6, "g" );
850 m10.setIdentifier( 7, "h" );
851 m10.setIdentifier( 8, "i" );
852 m10.setState( 0, 0, PRESENT );
853 m10.setState( 1, 0, ABSENT );
854 m10.setState( 2, 0, PRESENT );
855 m10.setState( 3, 0, ABSENT );
856 m10.setState( 4, 0, ABSENT );
857 m10.setState( 5, 0, ABSENT );
858 m10.setState( 6, 0, ABSENT );
859 m10.setState( 7, 0, ABSENT );
860 m10.setState( 8, 0, ABSENT );
861 dollo10.execute( p10, m10 );
862 if ( dollo10.getTotalGains() != 1 ) {
865 if ( dollo10.getTotalLosses() != 1 ) {
869 catch ( final Exception e ) {
870 e.printStackTrace( System.out );
876 private static boolean testDolloParsimonyOnNonBinaryTree() {
878 final BinaryStates PRESENT = BinaryStates.PRESENT;
879 final BinaryStates ABSENT = BinaryStates.ABSENT;
880 final DolloParsimony dollo1 = DolloParsimony.createInstance();
881 final PhylogenyFactory factory1 = ParserBasedPhylogenyFactory.getInstance();
882 final String p1_str = "((((((a,b,y)aby,c)ac,d)ad,(e,f)ef)af,(g,h)gh)ah,i)r";
883 final Phylogeny p1 = factory1.create( p1_str, new NHXParser() )[ 0 ];
884 final CharacterStateMatrix<CharacterStateMatrix.BinaryStates> m1 = new BasicCharacterStateMatrix<CharacterStateMatrix.BinaryStates>( 10,
886 m1.setIdentifier( 0, "a" );
887 m1.setIdentifier( 1, "b" );
888 m1.setIdentifier( 2, "y" );
889 m1.setIdentifier( 3, "c" );
890 m1.setIdentifier( 4, "d" );
891 m1.setIdentifier( 5, "e" );
892 m1.setIdentifier( 6, "f" );
893 m1.setIdentifier( 7, "g" );
894 m1.setIdentifier( 8, "h" );
895 m1.setIdentifier( 9, "i" );
896 m1.setCharacter( 0, "0" );
897 m1.setState( "a", "0", PRESENT );
898 m1.setState( "b", "0", ABSENT );
899 m1.setState( "y", "0", PRESENT );
900 m1.setState( "c", "0", PRESENT );
901 m1.setState( "d", "0", ABSENT );
902 m1.setState( "e", "0", ABSENT );
903 m1.setState( "f", "0", ABSENT );
904 m1.setState( "g", "0", ABSENT );
905 m1.setState( "h", "0", ABSENT );
906 m1.setState( "i", "0", ABSENT );
907 dollo1.execute( p1, m1 );
908 if ( dollo1.getTotalGains() != 1 ) {
911 if ( dollo1.getTotalLosses() != 1 ) {
914 if ( dollo1.getTotalUnchanged() != 16 ) {
917 m1.setState( "b", "0", PRESENT );
918 dollo1.execute( p1, m1 );
919 if ( dollo1.getTotalGains() != 1 ) {
922 if ( dollo1.getTotalLosses() != 0 ) {
925 if ( dollo1.getTotalUnchanged() != 17 ) {
928 m1.setState( "a", "0", ABSENT );
929 m1.setState( "b", "0", ABSENT );
930 dollo1.execute( p1, m1 );
931 if ( dollo1.getTotalGains() != 1 ) {
934 if ( dollo1.getTotalLosses() != 2 ) {
937 if ( dollo1.getTotalUnchanged() != 15 ) {
940 m1.setState( "y", "0", ABSENT );
941 dollo1.execute( p1, m1 );
942 if ( dollo1.getTotalGains() != 1 ) {
945 if ( dollo1.getTotalLosses() != 0 ) {
948 if ( dollo1.getTotalUnchanged() != 17 ) {
951 final DolloParsimony dollo2 = DolloParsimony.createInstance();
952 final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
953 final String p2_str = "((((((a,b,y)aby,c,d)cad,e,f)af,(g,h)gh)ah,i))r";
954 final Phylogeny p2 = factory2.create( p2_str, new NHXParser() )[ 0 ];
955 final CharacterStateMatrix<CharacterStateMatrix.BinaryStates> m2 = new BasicCharacterStateMatrix<CharacterStateMatrix.BinaryStates>( 10,
957 m2.setIdentifier( 0, "a" );
958 m2.setIdentifier( 1, "b" );
959 m2.setIdentifier( 2, "y" );
960 m2.setIdentifier( 3, "c" );
961 m2.setIdentifier( 4, "d" );
962 m2.setIdentifier( 5, "e" );
963 m2.setIdentifier( 6, "f" );
964 m2.setIdentifier( 7, "g" );
965 m2.setIdentifier( 8, "h" );
966 m2.setIdentifier( 9, "i" );
967 m2.setCharacter( 0, "0" );
968 m2.setState( "a", "0", PRESENT );
969 m2.setState( "b", "0", ABSENT );
970 m2.setState( "y", "0", PRESENT );
971 m2.setState( "c", "0", PRESENT );
972 m2.setState( "d", "0", ABSENT );
973 m2.setState( "e", "0", ABSENT );
974 m2.setState( "f", "0", ABSENT );
975 m2.setState( "g", "0", ABSENT );
976 m2.setState( "h", "0", ABSENT );
977 m2.setState( "i", "0", ABSENT );
978 dollo2.setReturnInternalStates( true );
979 dollo2.execute( p2, m2 );
980 CharacterStateMatrix<BinaryStates> i_m2 = dollo2.getInternalStatesMatrix();
981 if ( i_m2.getState( "aby", "0" ) != PRESENT ) {
984 if ( i_m2.getState( "cad", "0" ) != PRESENT ) {
987 if ( i_m2.getState( "af", "0" ) != ABSENT ) {
990 if ( i_m2.getState( "gh", "0" ) != ABSENT ) {
993 if ( i_m2.getState( "ah", "0" ) != ABSENT ) {
996 if ( i_m2.getState( "r", "0" ) != ABSENT ) {
999 if ( dollo2.getTotalGains() != 1 ) {
1002 if ( dollo2.getTotalLosses() != 2 ) {
1005 if ( dollo2.getTotalUnchanged() != 14 ) {
1008 m2.setState( "b", "0", PRESENT );
1009 dollo2.execute( p2, m2 );
1010 if ( dollo2.getTotalGains() != 1 ) {
1013 if ( dollo2.getTotalLosses() != 1 ) {
1016 if ( dollo2.getTotalUnchanged() != 15 ) {
1019 m2.setState( "a", "0", ABSENT );
1020 m2.setState( "b", "0", ABSENT );
1021 dollo2.execute( p2, m2 );
1022 if ( dollo2.getTotalGains() != 1 ) {
1025 if ( dollo2.getTotalLosses() != 3 ) {
1028 if ( dollo2.getTotalUnchanged() != 13 ) {
1031 m2.setState( "y", "0", ABSENT );
1032 dollo2.execute( p2, m2 );
1033 if ( dollo2.getTotalGains() != 1 ) {
1036 if ( dollo2.getTotalLosses() != 0 ) {
1039 if ( dollo2.getTotalUnchanged() != 16 ) {
1042 m2.setState( "c", "0", ABSENT );
1043 dollo2.execute( p2, m2 );
1044 if ( dollo2.getTotalGains() != 0 ) {
1047 if ( dollo2.getTotalLosses() != 0 ) {
1050 if ( dollo2.getTotalUnchanged() != 17 ) {
1053 m2.setState( "y", "0", PRESENT );
1054 m2.setState( "e", "0", PRESENT );
1055 dollo2.execute( p2, m2 );
1056 if ( dollo2.getTotalGains() != 1 ) {
1059 if ( dollo2.getTotalLosses() != 5 ) {
1062 if ( dollo2.getTotalUnchanged() != 11 ) {
1065 i_m2 = dollo2.getInternalStatesMatrix();
1066 if ( i_m2.getState( "aby", "0" ) != PRESENT ) {
1069 if ( i_m2.getState( "cad", "0" ) != PRESENT ) {
1072 if ( i_m2.getState( "af", "0" ) != PRESENT ) {
1075 if ( i_m2.getState( "gh", "0" ) != ABSENT ) {
1078 if ( i_m2.getState( "ah", "0" ) != ABSENT ) {
1081 if ( i_m2.getState( "r", "0" ) != ABSENT ) {
1085 catch ( final Exception e ) {
1086 e.printStackTrace( System.out );
1092 private static boolean testFitchParsimony() {
1094 final BinaryStates PRESENT = BinaryStates.PRESENT;
1095 final BinaryStates ABSENT = BinaryStates.ABSENT;
1096 final GainLossStates GAIN = GainLossStates.GAIN;
1097 final GainLossStates LOSS = GainLossStates.LOSS;
1098 final GainLossStates UNCHANGED_PRESENT = GainLossStates.UNCHANGED_PRESENT;
1099 final GainLossStates UNCHANGED_ABSENT = GainLossStates.UNCHANGED_ABSENT;
1100 final FitchParsimony<String> fitch1 = new FitchParsimony<String>();
1101 final PhylogenyFactory factory1 = ParserBasedPhylogenyFactory.getInstance();
1102 final String p1_str = "((((((a,b)ab,c)ac,d)ad,(e,f)ef)af,(g,h,i)gi)ai,((j,k,l)jl,(m,n,o)mo,(p,q,r)pr)jr)root";
1103 final Phylogeny p1 = factory1.create( p1_str, new NHXParser() )[ 0 ];
1104 final CharacterStateMatrix<String> m1 = new BasicCharacterStateMatrix<String>( 18, 1 );
1105 m1.setIdentifier( 0, "a" );
1106 m1.setIdentifier( 1, "b" );
1107 m1.setIdentifier( 2, "c" );
1108 m1.setIdentifier( 3, "d" );
1109 m1.setIdentifier( 4, "e" );
1110 m1.setIdentifier( 5, "f" );
1111 m1.setIdentifier( 6, "g" );
1112 m1.setIdentifier( 7, "h" );
1113 m1.setIdentifier( 8, "i" );
1114 m1.setIdentifier( 9, "j" );
1115 m1.setIdentifier( 10, "k" );
1116 m1.setIdentifier( 11, "l" );
1117 m1.setIdentifier( 12, "m" );
1118 m1.setIdentifier( 13, "n" );
1119 m1.setIdentifier( 14, "o" );
1120 m1.setIdentifier( 15, "p" );
1121 m1.setIdentifier( 16, "q" );
1122 m1.setIdentifier( 17, "r" );
1123 m1.setCharacter( 0, "0" );
1124 m1.setState( "a", "0", "A" );
1125 m1.setState( "b", "0", "A" );
1126 m1.setState( "c", "0", "B" );
1127 m1.setState( "d", "0", "C" );
1128 m1.setState( "e", "0", "D" );
1129 m1.setState( "f", "0", "A" );
1130 m1.setState( "g", "0", "A" );
1131 m1.setState( "h", "0", "B" );
1132 m1.setState( "i", "0", "C" );
1133 m1.setState( "j", "0", "A" );
1134 m1.setState( "k", "0", "B" );
1135 m1.setState( "l", "0", "C" );
1136 m1.setState( "m", "0", "B" );
1137 m1.setState( "n", "0", "B" );
1138 m1.setState( "o", "0", "B" );
1139 m1.setState( "p", "0", "A" );
1140 m1.setState( "q", "0", "C" );
1141 m1.setState( "r", "0", "D" );
1142 fitch1.setReturnInternalStates( true );
1143 fitch1.setReturnGainLossMatrix( false );
1144 fitch1.setRandomize( false );
1145 fitch1.execute( p1, m1 );
1146 final CharacterStateMatrix<String> i_m = fitch1.getInternalStatesMatrix();
1147 final CharacterStateMatrix<List<String>> i_m_all = fitch1.getInternalStatesMatrixPriorToTraceback();
1148 if ( fitch1.getCost() != 10 ) {
1151 if ( !i_m.getState( "ab", "0" ).equals( "A" ) ) {
1154 if ( !i_m.getState( "ac", "0" ).equals( "A" ) ) {
1157 if ( !i_m.getState( "ad", "0" ).equals( "A" ) ) {
1160 if ( !i_m.getState( "ef", "0" ).equals( "A" ) ) {
1163 if ( !i_m.getState( "ai", "0" ).equals( "A" ) ) {
1166 if ( !i_m.getState( "gi", "0" ).equals( "A" ) ) {
1169 if ( !i_m.getState( "jl", "0" ).equals( "A" ) ) {
1172 if ( !i_m.getState( "mo", "0" ).equals( "B" ) ) {
1175 if ( !i_m.getState( "pr", "0" ).equals( "A" ) ) {
1178 if ( i_m_all.getState( "ab", "0" ).size() != 1 ) {
1181 if ( !i_m_all.getState( "ab", "0" ).contains( "A" ) ) {
1184 if ( i_m_all.getState( "ac", "0" ).size() != 2 ) {
1187 if ( !i_m_all.getState( "ac", "0" ).contains( "A" ) ) {
1190 if ( !i_m_all.getState( "ac", "0" ).contains( "B" ) ) {
1193 if ( i_m_all.getState( "ad", "0" ).size() != 3 ) {
1196 if ( !i_m_all.getState( "ad", "0" ).contains( "A" ) ) {
1199 if ( !i_m_all.getState( "ad", "0" ).contains( "B" ) ) {
1202 if ( !i_m_all.getState( "ad", "0" ).contains( "C" ) ) {
1205 if ( i_m_all.getState( "af", "0" ).size() != 1 ) {
1208 if ( !i_m_all.getState( "af", "0" ).contains( "A" ) ) {
1211 if ( i_m_all.getState( "ef", "0" ).size() != 2 ) {
1214 if ( !i_m_all.getState( "ef", "0" ).contains( "A" ) ) {
1217 if ( !i_m_all.getState( "ef", "0" ).contains( "D" ) ) {
1220 if ( i_m_all.getState( "gi", "0" ).size() != 3 ) {
1223 if ( !i_m_all.getState( "gi", "0" ).contains( "A" ) ) {
1226 if ( !i_m_all.getState( "gi", "0" ).contains( "B" ) ) {
1229 if ( !i_m_all.getState( "gi", "0" ).contains( "C" ) ) {
1232 if ( i_m_all.getState( "ai", "0" ).size() != 1 ) {
1235 if ( !i_m_all.getState( "ai", "0" ).contains( "A" ) ) {
1238 if ( i_m_all.getState( "jl", "0" ).size() != 3 ) {
1241 if ( !i_m_all.getState( "jl", "0" ).contains( "A" ) ) {
1244 if ( !i_m_all.getState( "jl", "0" ).contains( "B" ) ) {
1247 if ( !i_m_all.getState( "jl", "0" ).contains( "C" ) ) {
1250 if ( i_m_all.getState( "mo", "0" ).size() != 1 ) {
1253 if ( !i_m_all.getState( "mo", "0" ).contains( "B" ) ) {
1256 if ( i_m_all.getState( "pr", "0" ).size() != 3 ) {
1259 if ( !i_m_all.getState( "pr", "0" ).contains( "A" ) ) {
1262 if ( !i_m_all.getState( "pr", "0" ).contains( "C" ) ) {
1265 if ( !i_m_all.getState( "pr", "0" ).contains( "D" ) ) {
1268 if ( i_m_all.getState( "jr", "0" ).size() != 4 ) {
1271 if ( !i_m_all.getState( "jr", "0" ).contains( "A" ) ) {
1274 if ( !i_m_all.getState( "jr", "0" ).contains( "B" ) ) {
1277 if ( !i_m_all.getState( "jr", "0" ).contains( "C" ) ) {
1280 if ( !i_m_all.getState( "jr", "0" ).contains( "D" ) ) {
1283 final FitchParsimony<String> fitch2 = new FitchParsimony<String>();
1284 final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1285 final String p2_str = "((a,b)ab,(c,(d,e)de)cde)r";
1286 final Phylogeny p2 = factory2.create( p2_str, new NHXParser() )[ 0 ];
1287 final CharacterStateMatrix<String> m2 = new BasicCharacterStateMatrix<String>( 5, 1 );
1288 m2.setIdentifier( 0, "a" );
1289 m2.setIdentifier( 1, "b" );
1290 m2.setIdentifier( 2, "c" );
1291 m2.setIdentifier( 3, "d" );
1292 m2.setIdentifier( 4, "e" );
1293 m2.setCharacter( 0, "0" );
1294 m2.setState( "a", "0", "C" );
1295 m2.setState( "b", "0", "A" );
1296 m2.setState( "c", "0", "C" );
1297 m2.setState( "d", "0", "A" );
1298 m2.setState( "e", "0", "G" );
1299 fitch2.setReturnInternalStates( true );
1300 fitch2.setReturnGainLossMatrix( false );
1301 fitch2.execute( p2, m2 );
1302 final CharacterStateMatrix<String> i_m2 = fitch2.getInternalStatesMatrix();
1303 final CharacterStateMatrix<List<String>> i_m_all2 = fitch2.getInternalStatesMatrixPriorToTraceback();
1304 if ( fitch2.getCost() != 3 ) {
1307 if ( !i_m2.getState( "ab", "0" ).equals( "A" ) ) {
1310 if ( !i_m2.getState( "de", "0" ).equals( "A" ) ) {
1313 if ( !i_m2.getState( "cde", "0" ).equals( "A" ) ) {
1316 if ( !i_m2.getState( "r", "0" ).equals( "A" ) ) {
1319 if ( i_m_all2.getState( "cde", "0" ).size() != 3 ) {
1322 if ( !i_m_all2.getState( "cde", "0" ).contains( "A" ) ) {
1325 if ( !i_m_all2.getState( "cde", "0" ).contains( "C" ) ) {
1328 if ( !i_m_all2.getState( "cde", "0" ).contains( "G" ) ) {
1331 if ( i_m_all2.getState( "ab", "0" ).size() != 2 ) {
1334 if ( !i_m_all2.getState( "ab", "0" ).contains( "A" ) ) {
1337 if ( !i_m_all2.getState( "ab", "0" ).contains( "C" ) ) {
1340 fitch2.setReturnInternalStates( true );
1341 fitch2.setReturnGainLossMatrix( false );
1342 fitch2.setUseLast( true );
1343 fitch2.execute( p2, m2 );
1344 final CharacterStateMatrix<String> i_m21 = fitch2.getInternalStatesMatrix();
1345 final CharacterStateMatrix<List<String>> i_m_all21 = fitch2.getInternalStatesMatrixPriorToTraceback();
1346 if ( fitch2.getCost() != 3 ) {
1349 if ( !i_m21.getState( "ab", "0" ).equals( "C" ) ) {
1352 if ( !i_m21.getState( "de", "0" ).equals( "G" ) ) {
1355 if ( !i_m21.getState( "cde", "0" ).equals( "C" ) ) {
1358 if ( !i_m21.getState( "r", "0" ).equals( "C" ) ) {
1361 if ( i_m_all21.getState( "cde", "0" ).size() != 3 ) {
1364 if ( !i_m_all21.getState( "cde", "0" ).contains( "A" ) ) {
1367 if ( !i_m_all21.getState( "cde", "0" ).contains( "C" ) ) {
1370 if ( !i_m_all21.getState( "cde", "0" ).contains( "G" ) ) {
1373 final FitchParsimony<String> fitch3 = new FitchParsimony<String>();
1374 final PhylogenyFactory factory3 = ParserBasedPhylogenyFactory.getInstance();
1375 final String p3_str = "(((a,b)ab,((c,d)cd,e)cde)abcde,f)r";
1376 final Phylogeny p3 = factory3.create( p3_str, new NHXParser() )[ 0 ];
1377 final CharacterStateMatrix<String> m3 = new BasicCharacterStateMatrix<String>( 6, 1 );
1378 m3.setIdentifier( 0, "a" );
1379 m3.setIdentifier( 1, "b" );
1380 m3.setIdentifier( 2, "c" );
1381 m3.setIdentifier( 3, "d" );
1382 m3.setIdentifier( 4, "e" );
1383 m3.setIdentifier( 5, "f" );
1384 m3.setCharacter( 0, "0" );
1385 m3.setState( "a", "0", "C" );
1386 m3.setState( "b", "0", "U" );
1387 m3.setState( "c", "0", "G" );
1388 m3.setState( "d", "0", "U" );
1389 m3.setState( "e", "0", "A" );
1390 m3.setState( "f", "0", "A" );
1391 fitch3.setReturnInternalStates( true );
1392 fitch3.setReturnGainLossMatrix( false );
1393 fitch3.execute( p3, m3 );
1394 final CharacterStateMatrix<String> i_m3 = fitch3.getInternalStatesMatrix();
1395 final CharacterStateMatrix<List<String>> i_m_all3 = fitch3.getInternalStatesMatrixPriorToTraceback();
1396 if ( fitch3.getCost() != 4 ) {
1399 if ( !i_m3.getState( "ab", "0" ).equals( "U" ) ) {
1402 if ( !i_m3.getState( "cd", "0" ).equals( "U" ) ) {
1405 if ( !i_m3.getState( "cde", "0" ).equals( "U" ) ) {
1408 if ( !i_m3.getState( "abcde", "0" ).equals( "U" ) ) {
1411 if ( !i_m3.getState( "r", "0" ).equals( "A" ) ) {
1414 if ( i_m_all3.getState( "cde", "0" ).size() != 3 ) {
1417 if ( !i_m_all3.getState( "cde", "0" ).contains( "A" ) ) {
1420 if ( !i_m_all3.getState( "cde", "0" ).contains( "G" ) ) {
1423 if ( !i_m_all3.getState( "cde", "0" ).contains( "U" ) ) {
1426 if ( i_m_all3.getState( "ab", "0" ).size() != 2 ) {
1429 if ( !i_m_all3.getState( "ab", "0" ).contains( "C" ) ) {
1432 if ( !i_m_all3.getState( "ab", "0" ).contains( "U" ) ) {
1435 if ( i_m_all3.getState( "cd", "0" ).size() != 2 ) {
1438 if ( !i_m_all3.getState( "cd", "0" ).contains( "G" ) ) {
1441 if ( !i_m_all3.getState( "cd", "0" ).contains( "U" ) ) {
1444 if ( i_m_all3.getState( "abcde", "0" ).size() != 1 ) {
1447 if ( !i_m_all3.getState( "abcde", "0" ).contains( "U" ) ) {
1450 if ( i_m_all3.getState( "r", "0" ).size() != 2 ) {
1453 if ( !i_m_all3.getState( "r", "0" ).contains( "A" ) ) {
1456 if ( !i_m_all3.getState( "r", "0" ).contains( "U" ) ) {
1459 final FitchParsimony<BinaryStates> fitch4 = new FitchParsimony<BinaryStates>();
1460 final PhylogenyFactory factory4 = ParserBasedPhylogenyFactory.getInstance();
1461 final String p4_str = "(((a,b)ab,((c,d)cd,e)cde)abcde,f)r";
1462 final Phylogeny p4 = factory4.create( p4_str, new NHXParser() )[ 0 ];
1463 final CharacterStateMatrix<BinaryStates> m4 = new BasicCharacterStateMatrix<BinaryStates>( 6, 1 );
1464 m4.setIdentifier( 0, "a" );
1465 m4.setIdentifier( 1, "b" );
1466 m4.setIdentifier( 2, "c" );
1467 m4.setIdentifier( 3, "d" );
1468 m4.setIdentifier( 4, "e" );
1469 m4.setIdentifier( 5, "f" );
1470 m4.setCharacter( 0, "0" );
1471 m4.setState( "a", "0", PRESENT );
1472 m4.setState( "b", "0", ABSENT );
1473 m4.setState( "c", "0", PRESENT );
1474 m4.setState( "d", "0", PRESENT );
1475 m4.setState( "e", "0", ABSENT );
1476 m4.setState( "f", "0", ABSENT );
1477 fitch4.setReturnInternalStates( true );
1478 fitch4.setReturnGainLossMatrix( true );
1479 fitch4.execute( p4, m4 );
1480 final CharacterStateMatrix<GainLossStates> gl_m_4 = fitch4.getGainLossMatrix();
1481 if ( fitch4.getCost() != 2 ) {
1484 if ( fitch4.getTotalLosses() != 0 ) {
1487 if ( fitch4.getTotalGains() != 2 ) {
1490 if ( fitch4.getTotalUnchanged() != 9 ) {
1493 if ( gl_m_4.getState( "a", "0" ) != GAIN ) {
1496 if ( gl_m_4.getState( "b", "0" ) != UNCHANGED_ABSENT ) {
1499 if ( gl_m_4.getState( "ab", "0" ) != UNCHANGED_ABSENT ) {
1502 if ( gl_m_4.getState( "cd", "0" ) != GAIN ) {
1505 if ( gl_m_4.getState( "r", "0" ) != UNCHANGED_ABSENT ) {
1508 final FitchParsimony<BinaryStates> fitch5 = new FitchParsimony<BinaryStates>();
1509 final PhylogenyFactory factory5 = ParserBasedPhylogenyFactory.getInstance();
1510 final String p5_str = "(((a,b)ab,((c,d)cd,e)cde)abcde,f)r";
1511 final Phylogeny p5 = factory5.create( p5_str, new NHXParser() )[ 0 ];
1512 final CharacterStateMatrix<BinaryStates> m5 = new BasicCharacterStateMatrix<BinaryStates>( 6, 1 );
1513 m5.setIdentifier( 0, "a" );
1514 m5.setIdentifier( 1, "b" );
1515 m5.setIdentifier( 2, "c" );
1516 m5.setIdentifier( 3, "d" );
1517 m5.setIdentifier( 4, "e" );
1518 m5.setIdentifier( 5, "f" );
1519 m5.setCharacter( 0, "0" );
1520 m5.setState( "a", "0", PRESENT );
1521 m5.setState( "b", "0", ABSENT );
1522 m5.setState( "c", "0", PRESENT );
1523 m5.setState( "d", "0", ABSENT );
1524 m5.setState( "e", "0", PRESENT );
1525 m5.setState( "f", "0", ABSENT );
1526 fitch5.setReturnInternalStates( true );
1527 fitch5.setReturnGainLossMatrix( true );
1528 fitch5.execute( p5, m5 );
1529 final CharacterStateMatrix<GainLossStates> gl_m_5 = fitch5.getGainLossMatrix();
1530 if ( fitch5.getCost() != 3 ) {
1533 if ( fitch5.getTotalLosses() != 2 ) {
1536 if ( fitch5.getTotalGains() != 1 ) {
1539 if ( fitch5.getTotalUnchanged() != 8 ) {
1542 if ( gl_m_5.getState( "abcde", "0" ) != GAIN ) {
1545 if ( gl_m_5.getState( "a", "0" ) != UNCHANGED_PRESENT ) {
1548 if ( gl_m_5.getState( "b", "0" ) != LOSS ) {
1551 if ( gl_m_5.getState( "d", "0" ) != LOSS ) {
1554 if ( gl_m_5.getState( "r", "0" ) != UNCHANGED_ABSENT ) {
1557 final FitchParsimony<BinaryStates> fitch6 = new FitchParsimony<BinaryStates>();
1558 final PhylogenyFactory factory6 = ParserBasedPhylogenyFactory.getInstance();
1559 final String p6_str = "(((a,b)ab,((c,d)cd,e)cde)abcde,f)r";
1560 final Phylogeny p6 = factory6.create( p6_str, new NHXParser() )[ 0 ];
1561 final CharacterStateMatrix<BinaryStates> m6 = new BasicCharacterStateMatrix<BinaryStates>( 6, 1 );
1562 m6.setIdentifier( 0, "a" );
1563 m6.setIdentifier( 1, "b" );
1564 m6.setIdentifier( 2, "c" );
1565 m6.setIdentifier( 3, "d" );
1566 m6.setIdentifier( 4, "e" );
1567 m6.setIdentifier( 5, "f" );
1568 m6.setCharacter( 0, "0" );
1569 m6.setState( "a", "0", PRESENT );
1570 m6.setState( "b", "0", ABSENT );
1571 m6.setState( "c", "0", PRESENT );
1572 m6.setState( "d", "0", PRESENT );
1573 m6.setState( "e", "0", ABSENT );
1574 m6.setState( "f", "0", PRESENT );
1575 fitch6.setReturnInternalStates( true );
1576 fitch6.setReturnGainLossMatrix( true );
1577 fitch6.execute( p6, m6 );
1578 final CharacterStateMatrix<GainLossStates> gl_m_6 = fitch6.getGainLossMatrix();
1579 if ( fitch6.getCost() != 2 ) {
1582 if ( fitch6.getTotalLosses() != 2 ) {
1585 if ( fitch6.getTotalGains() != 0 ) {
1588 if ( fitch6.getTotalUnchanged() != 9 ) {
1591 if ( gl_m_6.getState( "abcde", "0" ) != UNCHANGED_PRESENT ) {
1594 if ( gl_m_6.getState( "r", "0" ) != UNCHANGED_PRESENT ) {
1597 if ( gl_m_6.getState( "b", "0" ) != LOSS ) {
1600 if ( gl_m_6.getState( "e", "0" ) != LOSS ) {
1603 final FitchParsimony<BinaryStates> fitch7 = new FitchParsimony<BinaryStates>();
1604 final PhylogenyFactory factory7 = ParserBasedPhylogenyFactory.getInstance();
1605 final String p7_str = "(((a,b)ab,(c,d)cd)abcd,((e,f)ef,(g,h)gh)efgh)r";
1606 final Phylogeny p7 = factory7.create( p7_str, new NHXParser() )[ 0 ];
1607 final CharacterStateMatrix<BinaryStates> m7 = new BasicCharacterStateMatrix<BinaryStates>( 8, 1 );
1608 m7.setIdentifier( 0, "a" );
1609 m7.setIdentifier( 1, "b" );
1610 m7.setIdentifier( 2, "c" );
1611 m7.setIdentifier( 3, "d" );
1612 m7.setIdentifier( 4, "e" );
1613 m7.setIdentifier( 5, "f" );
1614 m7.setIdentifier( 6, "g" );
1615 m7.setIdentifier( 7, "h" );
1616 m7.setCharacter( 0, "0" );
1617 m7.setState( "a", "0", PRESENT );
1618 m7.setState( "b", "0", ABSENT );
1619 m7.setState( "c", "0", PRESENT );
1620 m7.setState( "d", "0", ABSENT );
1621 m7.setState( "e", "0", PRESENT );
1622 m7.setState( "f", "0", ABSENT );
1623 m7.setState( "g", "0", PRESENT );
1624 m7.setState( "h", "0", ABSENT );
1625 fitch7.setReturnInternalStates( true );
1626 fitch7.setReturnGainLossMatrix( true );
1627 fitch7.execute( p7, m7 );
1628 final CharacterStateMatrix<GainLossStates> gl_m_7 = fitch7.getGainLossMatrix();
1629 if ( fitch7.getCost() != 4 ) {
1632 if ( fitch7.getTotalLosses() != 0 ) {
1635 if ( fitch7.getTotalGains() != 4 ) {
1638 if ( fitch7.getTotalUnchanged() != 11 ) {
1641 if ( gl_m_7.getState( "a", "0" ) != GAIN ) {
1644 if ( gl_m_7.getState( "c", "0" ) != GAIN ) {
1647 if ( gl_m_7.getState( "e", "0" ) != GAIN ) {
1650 if ( gl_m_7.getState( "g", "0" ) != GAIN ) {
1653 if ( gl_m_7.getState( "r", "0" ) != UNCHANGED_ABSENT ) {
1656 fitch7.setReturnInternalStates( true );
1657 fitch7.setReturnGainLossMatrix( true );
1658 fitch7.setUseLast( true );
1659 fitch7.execute( p7, m7 );
1660 final CharacterStateMatrix<GainLossStates> gl_m_71 = fitch7.getGainLossMatrix();
1661 if ( fitch7.getCost() != 4 ) {
1664 if ( fitch7.getTotalLosses() != 4 ) {
1667 if ( fitch7.getTotalGains() != 0 ) {
1670 if ( fitch7.getTotalUnchanged() != 11 ) {
1673 if ( gl_m_71.getState( "b", "0" ) != LOSS ) {
1676 if ( gl_m_71.getState( "d", "0" ) != LOSS ) {
1679 if ( gl_m_71.getState( "f", "0" ) != LOSS ) {
1682 if ( gl_m_71.getState( "h", "0" ) != LOSS ) {
1685 if ( gl_m_71.getState( "r", "0" ) != UNCHANGED_PRESENT ) {
1688 final FitchParsimony<BinaryStates> fitch8 = new FitchParsimony<BinaryStates>();
1689 final PhylogenyFactory factory8 = ParserBasedPhylogenyFactory.getInstance();
1690 final String p8_str = "(((a,b)ab,(c,d)cd)abcd,((e,f)ef,(g,h)gh)efgh)r";
1691 final Phylogeny p8 = factory8.create( p8_str, new NHXParser() )[ 0 ];
1692 final CharacterStateMatrix<BinaryStates> m8 = new BasicCharacterStateMatrix<BinaryStates>( 8, 1 );
1693 m8.setIdentifier( 0, "a" );
1694 m8.setIdentifier( 1, "b" );
1695 m8.setIdentifier( 2, "c" );
1696 m8.setIdentifier( 3, "d" );
1697 m8.setIdentifier( 4, "e" );
1698 m8.setIdentifier( 5, "f" );
1699 m8.setIdentifier( 6, "g" );
1700 m8.setIdentifier( 7, "h" );
1701 m8.setCharacter( 0, "0" );
1702 m8.setState( "a", "0", PRESENT );
1703 m8.setState( "b", "0", PRESENT );
1704 m8.setState( "c", "0", PRESENT );
1705 m8.setState( "d", "0", ABSENT );
1706 m8.setState( "e", "0", ABSENT );
1707 m8.setState( "f", "0", ABSENT );
1708 m8.setState( "g", "0", ABSENT );
1709 m8.setState( "h", "0", ABSENT );
1710 fitch8.setReturnInternalStates( true );
1711 fitch8.setReturnGainLossMatrix( true );
1712 fitch8.execute( p8, m8 );
1713 final CharacterStateMatrix<GainLossStates> gl_m_8 = fitch8.getGainLossMatrix();
1714 if ( fitch8.getCost() != 2 ) {
1717 if ( fitch8.getTotalLosses() != 1 ) {
1720 if ( fitch8.getTotalGains() != 1 ) {
1723 if ( fitch8.getTotalUnchanged() != 13 ) {
1726 if ( gl_m_8.getState( "d", "0" ) != LOSS ) {
1729 if ( gl_m_8.getState( "abcd", "0" ) != GAIN ) {
1732 final FitchParsimony<BinaryStates> fitch9 = new FitchParsimony<BinaryStates>();
1733 final PhylogenyFactory factory9 = ParserBasedPhylogenyFactory.getInstance();
1734 final String p9_str = "(((a,b)ab,c)abc,d)abcd";
1735 final Phylogeny p9 = factory9.create( p9_str, new NHXParser() )[ 0 ];
1736 final CharacterStateMatrix<BinaryStates> m9 = new BasicCharacterStateMatrix<BinaryStates>( 4, 1 );
1737 m9.setIdentifier( 0, "a" );
1738 m9.setIdentifier( 1, "b" );
1739 m9.setIdentifier( 2, "c" );
1740 m9.setIdentifier( 3, "d" );
1741 m9.setCharacter( 0, "0" );
1742 m9.setState( "a", "0", PRESENT );
1743 m9.setState( "b", "0", ABSENT );
1744 m9.setState( "c", "0", PRESENT );
1745 m9.setState( "d", "0", ABSENT );
1746 fitch9.setReturnInternalStates( true );
1747 fitch9.setReturnGainLossMatrix( true );
1748 fitch9.setUseLast( false );
1749 fitch9.execute( p9, m9 );
1750 final CharacterStateMatrix<GainLossStates> gl_m_9a = fitch9.getGainLossMatrix();
1751 if ( fitch9.getCost() != 2 ) {
1754 if ( fitch9.getTotalLosses() != 1 ) {
1757 if ( fitch9.getTotalGains() != 1 ) {
1760 if ( fitch9.getTotalUnchanged() != 5 ) {
1763 if ( gl_m_9a.getState( "a", "0" ) != UNCHANGED_PRESENT ) {
1766 if ( gl_m_9a.getState( "b", "0" ) != LOSS ) {
1769 if ( gl_m_9a.getState( "c", "0" ) != UNCHANGED_PRESENT ) {
1772 if ( gl_m_9a.getState( "d", "0" ) != UNCHANGED_ABSENT ) {
1775 if ( gl_m_9a.getState( "ab", "0" ) != UNCHANGED_PRESENT ) {
1778 if ( gl_m_9a.getState( "abc", "0" ) != GAIN ) {
1781 if ( gl_m_9a.getState( "abcd", "0" ) != UNCHANGED_ABSENT ) {
1784 fitch9.setUseLast( true );
1785 fitch9.execute( p9, m9 );
1786 final CharacterStateMatrix<GainLossStates> gl_m_9b = fitch9.getGainLossMatrix();
1787 if ( fitch9.getCost() != 2 ) {
1790 if ( fitch9.getTotalLosses() != 2 ) {
1793 if ( fitch9.getTotalGains() != 0 ) {
1796 if ( fitch9.getTotalUnchanged() != 5 ) {
1799 if ( gl_m_9b.getState( "a", "0" ) != UNCHANGED_PRESENT ) {
1802 if ( gl_m_9b.getState( "b", "0" ) != LOSS ) {
1805 if ( gl_m_9b.getState( "c", "0" ) != UNCHANGED_PRESENT ) {
1808 if ( gl_m_9b.getState( "d", "0" ) != LOSS ) {
1811 if ( gl_m_9b.getState( "ab", "0" ) != UNCHANGED_PRESENT ) {
1814 if ( gl_m_9b.getState( "abc", "0" ) != UNCHANGED_PRESENT ) {
1817 if ( gl_m_9b.getState( "abcd", "0" ) != UNCHANGED_PRESENT ) {
1820 fitch9.setUseLast( false );
1821 fitch9.setRandomize( true );
1822 fitch9.setRandomNumberSeed( 8722445 );
1823 fitch9.execute( p9, m9 );
1824 fitch9.getGainLossMatrix();
1825 if ( fitch9.getCost() != 2 ) {
1828 if ( fitch9.getTotalLosses() != 1 ) {
1831 if ( fitch9.getTotalGains() != 1 ) {
1834 if ( fitch9.getTotalUnchanged() != 5 ) {
1837 final FitchParsimony<BinaryStates> fitch10 = new FitchParsimony<BinaryStates>();
1838 final PhylogenyFactory factory10 = ParserBasedPhylogenyFactory.getInstance();
1839 final String p10_str = "((((a,b)ab,c)abc,d)abcd,e)abcde";
1840 final Phylogeny p10 = factory10.create( p10_str, new NHXParser() )[ 0 ];
1841 final CharacterStateMatrix<BinaryStates> m10 = new BasicCharacterStateMatrix<BinaryStates>( 5, 1 );
1842 m10.setIdentifier( 0, "a" );
1843 m10.setIdentifier( 1, "b" );
1844 m10.setIdentifier( 2, "c" );
1845 m10.setIdentifier( 3, "d" );
1846 m10.setIdentifier( 4, "e" );
1847 m10.setCharacter( 0, "0" );
1848 m10.setState( "a", "0", PRESENT );
1849 m10.setState( "b", "0", ABSENT );
1850 m10.setState( "c", "0", ABSENT );
1851 m10.setState( "d", "0", PRESENT );
1852 m10.setState( "e", "0", ABSENT );
1853 fitch10.setReturnInternalStates( true );
1854 fitch10.setReturnGainLossMatrix( true );
1855 fitch10.setUseLast( false );
1856 fitch10.execute( p10, m10 );
1857 final CharacterStateMatrix<GainLossStates> gl_m_10a = fitch10.getGainLossMatrix();
1858 if ( fitch10.getCost() != 2 ) {
1861 if ( fitch10.getTotalLosses() != 0 ) {
1864 if ( fitch10.getTotalGains() != 2 ) {
1867 if ( fitch10.getTotalUnchanged() != 7 ) {
1870 if ( gl_m_10a.getState( "a", "0" ) != GAIN ) {
1873 if ( gl_m_10a.getState( "b", "0" ) != UNCHANGED_ABSENT ) {
1876 if ( gl_m_10a.getState( "c", "0" ) != UNCHANGED_ABSENT ) {
1879 if ( gl_m_10a.getState( "d", "0" ) != GAIN ) {
1882 if ( gl_m_10a.getState( "e", "0" ) != UNCHANGED_ABSENT ) {
1885 if ( gl_m_10a.getState( "ab", "0" ) != UNCHANGED_ABSENT ) {
1888 if ( gl_m_10a.getState( "abc", "0" ) != UNCHANGED_ABSENT ) {
1891 if ( gl_m_10a.getState( "abcd", "0" ) != UNCHANGED_ABSENT ) {
1894 if ( gl_m_10a.getState( "abcde", "0" ) != UNCHANGED_ABSENT ) {
1897 fitch10.setUseLast( true );
1898 fitch10.execute( p10, m10 );
1899 final CharacterStateMatrix<GainLossStates> gl_m_10b = fitch10.getGainLossMatrix();
1900 if ( fitch10.getCost() != 2 ) {
1903 if ( fitch10.getTotalLosses() != 0 ) {
1906 if ( fitch10.getTotalGains() != 2 ) {
1909 if ( fitch10.getTotalUnchanged() != 7 ) {
1912 if ( gl_m_10b.getState( "a", "0" ) != GAIN ) {
1915 if ( gl_m_10b.getState( "b", "0" ) != UNCHANGED_ABSENT ) {
1918 if ( gl_m_10b.getState( "c", "0" ) != UNCHANGED_ABSENT ) {
1921 if ( gl_m_10b.getState( "d", "0" ) != GAIN ) {
1924 if ( gl_m_10b.getState( "e", "0" ) != UNCHANGED_ABSENT ) {
1927 if ( gl_m_10b.getState( "ab", "0" ) != UNCHANGED_ABSENT ) {
1930 if ( gl_m_10b.getState( "abc", "0" ) != UNCHANGED_ABSENT ) {
1933 if ( gl_m_10b.getState( "abcd", "0" ) != UNCHANGED_ABSENT ) {
1936 if ( gl_m_10b.getState( "abcde", "0" ) != UNCHANGED_ABSENT ) {
1940 catch ( final Exception e ) {
1941 e.printStackTrace( System.out );
1947 private static boolean testNeighborJoining() {
1949 NeighborJoining nj = NeighborJoining.createInstance();
1950 final BasicSymmetricalDistanceMatrix m0 = new BasicSymmetricalDistanceMatrix( 4 );
1951 m0.setIdentifier( 0, "A" );
1952 m0.setIdentifier( 1, "B" );
1953 m0.setIdentifier( 2, "C" );
1954 m0.setIdentifier( 3, "D" );
1955 m0.setRow( "5 ", 1 );
1956 m0.setRow( "3 6 ", 2 );
1957 m0.setRow( "7.5 10.5 5.5", 3 );
1958 final Phylogeny p0 = nj.execute( m0 );
1959 p0.reRoot( p0.getNode( "D" ) );
1960 if ( isUnequal( p0.getNode( "A" ).getDistanceToParent(), 1 ) ) {
1963 if ( isUnequal( p0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
1966 if ( isUnequal( p0.getNode( "C" ).getDistanceToParent(), 0.5 ) ) {
1969 if ( isUnequal( p0.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
1972 if ( isUnequal( p0.getNode( "A" ).getParent().getDistanceToParent(), 1.5 ) ) {
1975 if ( isUnequal( p0.getNode( "A" ).getParent().getParent().getDistanceToParent(), 2.5 ) ) {
1978 nj = NeighborJoining.createInstance();
1979 final BasicSymmetricalDistanceMatrix m00 = new BasicSymmetricalDistanceMatrix( 4 );
1980 m00.setIdentifier( 0, "A" );
1981 m00.setIdentifier( 1, "B" );
1982 m00.setIdentifier( 2, "C" );
1983 m00.setIdentifier( 3, "D" );
1984 m00.setRow( "2.01 ", 1 );
1985 m00.setRow( "3 3.01 ", 2 );
1986 m00.setRow( "3.01 3.02 1.01", 3 );
1987 final Phylogeny p00 = nj.execute( m00 );
1988 p00.reRoot( p00.getNode( "D" ) );
1989 if ( isUnequal( p00.getNode( "A" ).getDistanceToParent(), 1 ) ) {
1992 if ( isUnequal( p00.getNode( "B" ).getDistanceToParent(), 1.01 ) ) {
1995 if ( isUnequal( p00.getNode( "C" ).getDistanceToParent(), 0.5 ) ) {
1998 if ( isUnequal( p00.getNode( "D" ).getDistanceToParent(), 0.255 ) ) {
2001 if ( isUnequal( p00.getNode( "A" ).getParent().getDistanceToParent(), 1.5 ) ) {
2004 if ( isUnequal( p00.getNode( "A" ).getParent().getParent().getDistanceToParent(), 0.255 ) ) {
2007 BasicSymmetricalDistanceMatrix m = new BasicSymmetricalDistanceMatrix( 6 );
2009 m.setRow( "4 7", 2 );
2010 m.setRow( "7 10 7", 3 );
2011 m.setRow( "6 9 6 5", 4 );
2012 m.setRow( "8 11 8 9 8", 5 );
2013 m.setIdentifier( 0, "A" );
2014 m.setIdentifier( 1, "B" );
2015 m.setIdentifier( 2, "C" );
2016 m.setIdentifier( 3, "D" );
2017 m.setIdentifier( 4, "E" );
2018 m.setIdentifier( 5, "F" );
2019 nj = NeighborJoining.createInstance();
2020 final Phylogeny p1 = nj.execute( m );
2021 p1.reRoot( p1.getNode( "F" ) );
2022 if ( isUnequal( p1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
2025 if ( isUnequal( p1.getNode( "B" ).getDistanceToParent(), 4 ) ) {
2028 if ( isUnequal( p1.getNode( "C" ).getDistanceToParent(), 2 ) ) {
2031 if ( isUnequal( p1.getNode( "D" ).getDistanceToParent(), 3 ) ) {
2034 if ( isUnequal( p1.getNode( "E" ).getDistanceToParent(), 2 ) ) {
2037 if ( isUnequal( p1.getNode( "F" ).getDistanceToParent(), 2.5 ) ) {
2040 if ( isUnequal( p1.getNode( "A" ).getParent().getDistanceToParent(), 1 ) ) {
2043 if ( isUnequal( p1.getNode( "A" ).getParent().getParent().getDistanceToParent(), 1 ) ) {
2046 if ( isUnequal( p1.getNode( "A" ).getParent().getParent().getParent().getDistanceToParent(), 2.5 ) ) {
2049 if ( isUnequal( p1.getNode( "B" ).getParent().getDistanceToParent(), 1 ) ) {
2052 if ( isUnequal( p1.getNode( "D" ).getParent().getDistanceToParent(), 1 ) ) {
2055 if ( isUnequal( p1.getNode( "E" ).getParent().getDistanceToParent(), 1 ) ) {
2058 m = new BasicSymmetricalDistanceMatrix( 7 );
2059 m.setIdentifier( 0, "Bovine" );
2060 m.setIdentifier( 1, "Mouse" );
2061 m.setIdentifier( 2, "Gibbon" );
2062 m.setIdentifier( 3, "Orang" );
2063 m.setIdentifier( 4, "Gorilla" );
2064 m.setIdentifier( 5, "Chimp" );
2065 m.setIdentifier( 6, "Human" );
2066 m.setRow( "0.00000 1.68660 1.71980 1.66060 1.52430 1.60430 1.59050", 0 );
2067 m.setRow( "1.68660 0.00000 1.52320 1.48410 1.44650 1.43890 1.46290", 1 );
2068 m.setRow( "1.71980 1.52320 0.00000 0.71150 0.59580 0.61790 0.55830", 2 );
2069 m.setRow( "1.66060 1.48410 0.71150 0.00000 0.46310 0.50610 0.47100", 3 );
2070 m.setRow( "1.52430 1.44650 0.59580 0.46310 0.00000 0.34840 0.30830", 4 );
2071 m.setRow( "1.60430 1.43890 0.61790 0.50610 0.34840 0.00000 0.26920", 5 );
2072 m.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 );
2073 //NeighborJoiningR njr = NeighborJoiningR.createInstance( true, 6 );
2074 nj = NeighborJoining.createInstance( true, 6 );
2075 final Phylogeny p2 = nj.execute( m );
2076 // Archaeopteryx.createApplication( p2 );
2077 p2.reRoot( p2.getNode( "Bovine" ) );
2078 if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) {
2081 if ( isUnequal( p2.getNode( "Human" ).getDistanceToParent(), 0.117525 ) ) {
2084 if ( isUnequal( p2.getNode( "Gorilla" ).getDistanceToParent(), 0.153932 ) ) {
2087 if ( isUnequal( p2.getNode( "Orang" ).getDistanceToParent(), 0.284694 ) ) {
2090 if ( isUnequal( p2.getNode( "Gibbon" ).getDistanceToParent(), 0.357931 ) ) {
2093 if ( isUnequal( p2.getNode( "Mouse" ).getDistanceToParent(), 0.76891 ) ) {
2096 if ( isUnequal( p2.getNode( "Bovine" ).getDistanceToParent(), 0.458845 ) ) {
2099 if ( isUnequal( p2.getNode( "Chimp" ).getParent().getDistanceToParent(), 0.039819 ) ) {
2102 if ( isUnequal( p2.getNode( "Human" ).getParent().getDistanceToParent(), 0.039819 ) ) {
2105 if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getDistanceToParent(), 0.026956 ) ) {
2108 if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getParent().getDistanceToParent(), 0.046481 ) ) {
2111 if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getParent().getParent().getDistanceToParent(),
2115 if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getParent().getParent().getParent()
2116 .getDistanceToParent(), 0.458845 ) ) {
2119 m = new BasicSymmetricalDistanceMatrix( 4 );
2120 m.setIdentifier( 0, "A" );
2121 m.setIdentifier( 1, "B" );
2122 m.setIdentifier( 2, "C" );
2123 m.setIdentifier( 3, "D" );
2124 m.setRow( "0.00 0.95 0.17 0.98", 0 );
2125 m.setRow( "0.95 0.00 1.02 1.83", 1 );
2126 m.setRow( "0.17 1.02 0.00 1.01", 2 );
2127 m.setRow( "0.98 1.83 1.01 0.00", 3 );
2128 final Phylogeny p3 = nj.execute( m );
2129 p3.reRoot( p3.getNode( "C" ) );
2130 if ( isUnequal( p3.getNode( "A" ).getDistanceToParent(), 0.05 ) ) {
2133 if ( isUnequal( p3.getNode( "B" ).getDistanceToParent(), 0.90 ) ) {
2136 if ( !isEqual( p3.getNode( "C" ).getDistanceToParent(), 0.05 ) ) {
2139 if ( !isEqual( p3.getNode( "D" ).getDistanceToParent(), 0.91 ) ) {
2142 if ( isUnequal( p3.getNode( "A" ).getParent().getDistanceToParent(), 0.02 ) ) {
2145 if ( isUnequal( p3.getNode( "A" ).getParent().getParent().getDistanceToParent(), 0.05 ) ) {
2149 NeighborJoiningF njf = NeighborJoiningF.createInstance();
2150 final BasicSymmetricalDistanceMatrix m0f = new BasicSymmetricalDistanceMatrix( 4 );
2151 m0f.setIdentifier( 0, "A" );
2152 m0f.setIdentifier( 1, "B" );
2153 m0f.setIdentifier( 2, "C" );
2154 m0f.setIdentifier( 3, "D" );
2155 m0f.setRow( "5 ", 1 );
2156 m0f.setRow( "3 6 ", 2 );
2157 m0f.setRow( "7.5 10.5 5.5", 3 );
2158 final Phylogeny p0f = njf.execute( m0f );
2159 p0f.reRoot( p0f.getNode( "D" ) );
2160 if ( isUnequal( p0f.getNode( "A" ).getDistanceToParent(), 1 ) ) {
2163 if ( isUnequal( p0f.getNode( "B" ).getDistanceToParent(), 4 ) ) {
2166 if ( isUnequal( p0f.getNode( "C" ).getDistanceToParent(), 0.5 ) ) {
2169 if ( isUnequal( p0f.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
2172 if ( isUnequal( p0f.getNode( "A" ).getParent().getDistanceToParent(), 1.5 ) ) {
2175 if ( isUnequal( p0f.getNode( "A" ).getParent().getParent().getDistanceToParent(), 2.5 ) ) {
2179 m = new BasicSymmetricalDistanceMatrix( 7 );
2180 m.setIdentifier( 0, "Bovine" );
2181 m.setIdentifier( 1, "Mouse" );
2182 m.setIdentifier( 2, "Gibbon" );
2183 m.setIdentifier( 3, "Orang" );
2184 m.setIdentifier( 4, "Gorilla" );
2185 m.setIdentifier( 5, "Chimp" );
2186 m.setIdentifier( 6, "Human" );
2187 m.setRow( "0.00000 1.68660 1.71980 1.66060 1.52430 1.60430 1.59050", 0 );
2188 m.setRow( "1.68660 0.00000 1.52320 1.48410 1.44650 1.43890 1.46290", 1 );
2189 m.setRow( "1.71980 1.52320 0.00000 0.71150 0.59580 0.61790 0.55830", 2 );
2190 m.setRow( "1.66060 1.48410 0.71150 0.00000 0.46310 0.50610 0.47100", 3 );
2191 m.setRow( "1.52430 1.44650 0.59580 0.46310 0.00000 0.34840 0.30830", 4 );
2192 m.setRow( "1.60430 1.43890 0.61790 0.50610 0.34840 0.00000 0.26920", 5 );
2193 m.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 );
2194 njf = NeighborJoiningF.createInstance( true, 5 );
2195 final Phylogeny p2f = njf.execute( m );
2196 p2f.reRoot( p2f.getNode( "Bovine" ) );
2197 if ( isUnequal( p2f.getNode( "Chimp" ).getDistanceToParent(), 0.15168 ) ) {
2200 if ( isUnequal( p2f.getNode( "Human" ).getDistanceToParent(), 0.11752 ) ) {
2203 if ( isUnequal( p2f.getNode( "Gorilla" ).getDistanceToParent(), 0.15393 ) ) {
2206 if ( isUnequal( p2f.getNode( "Orang" ).getDistanceToParent(), 0.28469 ) ) {
2209 if ( isUnequal( p2f.getNode( "Gibbon" ).getDistanceToParent(), 0.35793 ) ) {
2212 if ( isUnequal( p2f.getNode( "Mouse" ).getDistanceToParent(), 0.76891 ) ) {
2215 if ( isUnequal( p2f.getNode( "Bovine" ).getDistanceToParent(), 0.458845 ) ) {
2218 if ( isUnequal( p2f.getNode( "Chimp" ).getParent().getDistanceToParent(), 0.03982 ) ) {
2221 if ( isUnequal( p2f.getNode( "Human" ).getParent().getDistanceToParent(), 0.03982 ) ) {
2224 if ( isUnequal( p2f.getNode( "Chimp" ).getParent().getParent().getDistanceToParent(), 0.02696 ) ) {
2227 if ( isUnequal( p2f.getNode( "Chimp" ).getParent().getParent().getParent().getDistanceToParent(), 0.04648 ) ) {
2230 if ( isUnequal( p2f.getNode( "Chimp" ).getParent().getParent().getParent().getParent()
2231 .getDistanceToParent(), 0.42027 ) ) {
2234 if ( isUnequal( p2f.getNode( "Chimp" ).getParent().getParent().getParent().getParent().getParent()
2235 .getDistanceToParent(), 0.458845 ) ) {
2239 catch ( final Exception e ) {
2240 e.printStackTrace( System.out );
2246 private static boolean testS() {
2248 final S s0 = new S();
2250 s0.addPairing( 0, 1, 0 );
2251 s0.addPairing( 7, 8, 0 );
2252 s0.addPairing( 4, 55, 0 );
2253 s0.addPairing( 2, 3, 0 );
2254 s0.addPairing( 4, 5, 0 );
2255 s0.addPairing( 5, 6666, 0 );
2256 s0.addPairing( 5, 666, 0 );
2257 s0.addPairing( 5, 66, 0 );
2258 s0.addPairing( 5, 6, 0 );
2259 s0.addPairing( 6, 7, 0 );
2260 s0.addPairing( 3, 4, 0 );
2261 s0.addPairing( 1, 2, 0 );
2262 if ( s0.size() != 1 ) {
2265 if ( s0.getS( 0 ).size() != 8 ) {
2268 if ( s0.getValues( 0, 0 ).size() != 1 ) {
2271 if ( s0.getValues( 1, 0 ).size() != 1 ) {
2274 if ( s0.getValues( 2, 0 ).size() != 1 ) {
2277 if ( s0.getValues( 3, 0 ).size() != 1 ) {
2280 if ( s0.getValues( 4, 0 ).size() != 2 ) {
2283 if ( s0.getValues( 5, 0 ).size() != 4 ) {
2286 if ( s0.getValues( 6, 0 ).size() != 1 ) {
2289 if ( s0.getValues( 7, 0 ).size() != 1 ) {
2292 if ( !s0.getValues( 0, 0 ).contains( 1 ) ) {
2295 if ( !s0.getValues( 5, 0 ).contains( 6 ) ) {
2298 if ( !s0.getValues( 5, 0 ).contains( 66 ) ) {
2301 if ( !s0.getValues( 5, 0 ).contains( 666 ) ) {
2304 if ( !s0.getValues( 5, 0 ).contains( 6666 ) ) {
2307 s0.removePairing( 5, 6666, 0 );
2308 if ( s0.getValues( 5, 0 ).contains( 6666 ) ) {
2311 s0.removePairing( 5, 666, 0 );
2312 if ( s0.getValues( 5, 0 ).contains( 666 ) ) {
2315 s0.removePairing( 5, 66, 0 );
2316 if ( s0.getValues( 5, 0 ).contains( 66 ) ) {
2319 if ( s0.getValues( 5, 0 ).size() != 1 ) {
2322 if ( s0.getS( 0 ).size() != 8 ) {
2325 s0.removePairing( 5, 6, 0 );
2326 if ( s0.getS( 0 ).size() != 7 ) {
2329 s0.addPairing( 5, 6, 0 );
2330 if ( s0.getS( 0 ).size() != 8 ) {
2333 if ( s0.getValues( 5, 0 ).size() != 1 ) {
2336 if ( !s0.getValues( 5, 0 ).contains( 6 ) ) {
2339 s0.addPairing( 5, 403, 0 );
2340 if ( s0.getValues( 5, 0 ).size() != 2 ) {
2343 if ( !s0.getValues( 5, 0 ).contains( 403 ) ) {
2346 s0.addPairing( 693, 100, 0 );
2347 s0.addPairing( 693, 101, 0 );
2348 if ( s0.getValues( 693, 0 ).size() != 2 ) {
2351 s0.addPairing( 2, 33, 0 );
2352 s0.addPairing( 2, 333, 0 );
2353 final SortedSet<Integer>[] a = s0.toArray( 0 );
2354 if ( !a[ 0 ].contains( 1 ) ) {
2357 if ( a[ 0 ].size() != 1 ) {
2360 if ( !a[ 1 ].contains( 2 ) ) {
2363 if ( a[ 1 ].size() != 1 ) {
2366 if ( !a[ 2 ].contains( 3 ) ) {
2369 if ( !a[ 2 ].contains( 33 ) ) {
2372 if ( !a[ 2 ].contains( 333 ) ) {
2376 catch ( final Exception e ) {
2377 e.printStackTrace( System.out );
2383 private static boolean testNeighborJoiningR() {
2385 final NeighborJoiningR nj0 = NeighborJoiningR.createInstance();
2386 final BasicSymmetricalDistanceMatrix m0 = new BasicSymmetricalDistanceMatrix( 4 );
2387 m0.setIdentifier( 0, "A" );
2388 m0.setIdentifier( 1, "B" );
2389 m0.setIdentifier( 2, "C" );
2390 m0.setIdentifier( 3, "D" );
2391 m0.setRow( "5 ", 1 );
2392 m0.setRow( "3 6 ", 2 );
2393 m0.setRow( "7.5 10.5 5.5", 3 );
2394 final Phylogeny p0 = nj0.execute( m0 );
2395 p0.reRoot( p0.getNode( "D" ) );
2396 if ( isUnequal( p0.getNode( "A" ).getDistanceToParent(), 1 ) ) {
2399 if ( isUnequal( p0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
2402 if ( isUnequal( p0.getNode( "C" ).getDistanceToParent(), 0.5 ) ) {
2405 if ( isUnequal( p0.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
2408 if ( isUnequal( p0.getNode( "A" ).getParent().getDistanceToParent(), 1.5 ) ) {
2411 if ( isUnequal( p0.getNode( "A" ).getParent().getParent().getDistanceToParent(), 2.5 ) ) {
2414 final BasicSymmetricalDistanceMatrix m1 = new BasicSymmetricalDistanceMatrix( 6 );
2415 m1.setRow( "5", 1 );
2416 m1.setRow( "4 7", 2 );
2417 m1.setRow( "7 10 7", 3 );
2418 m1.setRow( "6 9 6 5", 4 );
2419 m1.setRow( "8 11 8 9 8", 5 );
2420 m1.setIdentifier( 0, "A" );
2421 m1.setIdentifier( 1, "B" );
2422 m1.setIdentifier( 2, "C" );
2423 m1.setIdentifier( 3, "D" );
2424 m1.setIdentifier( 4, "E" );
2425 m1.setIdentifier( 5, "F" );
2426 final NeighborJoiningR nj1 = NeighborJoiningR.createInstance();
2427 final Phylogeny p1 = nj1.execute( m1 );
2428 p1.reRoot( p1.getNode( "F" ) );
2429 if ( isUnequal( p1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
2432 if ( isUnequal( p1.getNode( "B" ).getDistanceToParent(), 4 ) ) {
2435 if ( isUnequal( p1.getNode( "C" ).getDistanceToParent(), 2 ) ) {
2438 if ( isUnequal( p1.getNode( "D" ).getDistanceToParent(), 3 ) ) {
2441 if ( isUnequal( p1.getNode( "E" ).getDistanceToParent(), 2 ) ) {
2444 if ( isUnequal( p1.getNode( "F" ).getDistanceToParent(), 2.5 ) ) {
2447 if ( isUnequal( p1.getNode( "A" ).getParent().getDistanceToParent(), 1 ) ) {
2450 if ( isUnequal( p1.getNode( "A" ).getParent().getParent().getDistanceToParent(), 1 ) ) {
2453 if ( isUnequal( p1.getNode( "A" ).getParent().getParent().getParent().getDistanceToParent(), 2.5 ) ) {
2456 if ( isUnequal( p1.getNode( "B" ).getParent().getDistanceToParent(), 1 ) ) {
2459 if ( isUnequal( p1.getNode( "D" ).getParent().getDistanceToParent(), 1 ) ) {
2462 if ( isUnequal( p1.getNode( "E" ).getParent().getDistanceToParent(), 1 ) ) {
2465 final BasicSymmetricalDistanceMatrix m2 = new BasicSymmetricalDistanceMatrix( 7 );
2466 m2.setIdentifier( 0, "Bovine" );
2467 m2.setIdentifier( 1, "Mouse" );
2468 m2.setIdentifier( 2, "Gibbon" );
2469 m2.setIdentifier( 3, "Orang" );
2470 m2.setIdentifier( 4, "Gorilla" );
2471 m2.setIdentifier( 5, "Chimp" );
2472 m2.setIdentifier( 6, "Human" );
2473 m2.setRow( "0.00000 1.68660 1.71980 1.66060 1.52430 1.60430 1.59050", 0 );
2474 m2.setRow( "1.68660 0.00000 1.52320 1.48410 1.44650 1.43890 1.46290", 1 );
2475 m2.setRow( "1.71980 1.52320 0.00000 0.71150 0.59580 0.61790 0.55830", 2 );
2476 m2.setRow( "1.66060 1.48410 0.71150 0.00000 0.46310 0.50610 0.47100", 3 );
2477 m2.setRow( "1.52430 1.44650 0.59580 0.46310 0.00000 0.34840 0.30830", 4 );
2478 m2.setRow( "1.60430 1.43890 0.61790 0.50610 0.34840 0.00000 0.26920", 5 );
2479 m2.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 );
2480 final NeighborJoiningR nj2 = NeighborJoiningR.createInstance( true, 6 );
2481 final Phylogeny p2 = nj2.execute( m2 );
2482 p2.reRoot( p2.getNode( "Bovine" ) );
2483 if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) {
2486 if ( isUnequal( p2.getNode( "Human" ).getDistanceToParent(), 0.117525 ) ) {
2489 if ( isUnequal( p2.getNode( "Gorilla" ).getDistanceToParent(), 0.153931 ) ) {
2492 if ( isUnequal( p2.getNode( "Orang" ).getDistanceToParent(), 0.284694 ) ) {
2495 if ( isUnequal( p2.getNode( "Gibbon" ).getDistanceToParent(), 0.357931 ) ) {
2498 if ( isUnequal( p2.getNode( "Mouse" ).getDistanceToParent(), 0.76891 ) ) {
2501 if ( isUnequal( p2.getNode( "Bovine" ).getDistanceToParent(), 0.458845 ) ) {
2504 if ( isUnequal( p2.getNode( "Chimp" ).getParent().getDistanceToParent(), 0.039819 ) ) {
2507 if ( isUnequal( p2.getNode( "Human" ).getParent().getDistanceToParent(), 0.039819 ) ) {
2510 if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getDistanceToParent(), 0.026956 ) ) {
2513 if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getParent().getDistanceToParent(), 0.046481 ) ) {
2516 if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getParent().getParent().getDistanceToParent(),
2520 if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getParent().getParent().getParent()
2521 .getDistanceToParent(), 0.458845 ) ) {
2525 final BasicSymmetricalDistanceMatrix m3 = new BasicSymmetricalDistanceMatrix( 20 );
2526 m3.setIdentifier( 0, "F_MOUSE" );
2527 m3.setIdentifier( 1, "11_RAT" );
2528 m3.setIdentifier( 2, "A_CAVPO" );
2529 m3.setIdentifier( 3, "D_HUMAN" );
2530 m3.setIdentifier( 4, "E_HUMAN" );
2531 m3.setIdentifier( 5, "F_HUMAN" );
2532 m3.setIdentifier( 6, "C_HUMAN" );
2533 m3.setIdentifier( 7, "6_FELCA" );
2534 m3.setIdentifier( 8, "D_MOUSE" );
2535 m3.setIdentifier( 9, "E_MOUSE" );
2536 m3.setIdentifier( 10, "E_RAT " );
2537 m3.setIdentifier( 11, "C_MOUSE" );
2538 m3.setIdentifier( 12, "10_RAT" );
2539 m3.setIdentifier( 13, "3_TAEGU" );
2540 m3.setIdentifier( 14, "2_SACKO" );
2541 m3.setIdentifier( 15, "2_PANTR" );
2542 m3.setIdentifier( 16, "3_CANFA" );
2543 m3.setIdentifier( 17, "9_HUMAN" );
2544 m3.setIdentifier( 18, "A_HUMAN" );
2545 m3.setIdentifier( 19, "B_HUMAN" );
2546 m3.setRow( "0.000000 0.000010 0.020875 0.010376 0.010376 0.010376 0.010376 0.010368 0.000010 0.000010 0.000010 0.000010 0.000010 0.087165 0.743570 0.010376 0.010376 0.010376 0.010376 0.010376 ",
2548 m3.setRow( "0.000010 0.000000 0.020875 0.010376 0.010376 0.010376 0.010376 0.010368 0.000010 0.000010 0.000010 0.000010 0.000010 0.087165 0.743570 0.010376 0.010376 0.010376 0.010376 0.010376",
2550 m3.setRow( "0.020875 0.020875 0.000000 0.031503 0.031503 0.031503 0.031503 0.031477 0.020875 0.020875 0.020875 0.020875 0.020875 0.096983 0.768150 0.031503 0.031503 0.031503 0.031503 0.031503",
2552 m3.setRow( "0.010376 0.010376 0.031503 0.000000 0.000010 0.000010 0.000010 0.010375 0.010376 0.010376 0.010376 0.010376 0.010376 0.098678 0.741282 0.000010 0.000010 0.000010 0.000010 0.000010",
2554 m3.setRow( "0.010376 0.010376 0.031503 0.000010 0.000000 0.000010 0.000010 0.010375 0.010376 0.010376 0.010376 0.010376 0.010376 0.098678 0.741282 0.000010 0.000010 0.000010 0.000010 0.000010",
2556 m3.setRow( "0.010376 0.010376 0.031503 0.000010 0.000010 0.000000 0.000010 0.010375 0.010376 0.010376 0.010376 0.010376 0.010376 0.098678 0.741282 0.000010 0.000010 0.000010 0.000010 0.000010",
2558 m3.setRow( "0.010376 0.010376 0.031503 0.000010 0.000010 0.000010 0.000000 0.010375 0.010376 0.010376 0.010376 0.010376 0.010376 0.098678 0.741282 0.000010 0.000010 0.000010 0.000010 0.000010",
2560 m3.setRow( "0.010368 0.010368 0.031477 0.010375 0.010375 0.010375 0.010375 0.000000 0.010368 0.010368 0.010368 0.010368 0.010368 0.098591 0.745047 0.010375 0.010375 0.010375 0.010375 0.010375",
2562 m3.setRow( "0.000010 0.000010 0.020875 0.010376 0.010376 0.010376 0.010376 0.010368 0.000000 0.000010 0.000010 0.000010 0.000010 0.087165 0.743570 0.010376 0.010376 0.010376 0.010376 0.010376",
2564 m3.setRow( "0.000010 0.000010 0.020875 0.010376 0.010376 0.010376 0.010376 0.010368 0.000010 0.000000 0.000010 0.000010 0.000010 0.087165 0.743570 0.010376 0.010376 0.010376 0.010376 0.010376",
2566 m3.setRow( "0.000010 0.000010 0.020875 0.010376 0.010376 0.010376 0.010376 0.010368 0.000010 0.000010 0.000000 0.000010 0.000010 0.087165 0.743570 0.010376 0.010376 0.010376 0.010376 0.010376",
2568 m3.setRow( "0.000010 0.000010 0.020875 0.010376 0.010376 0.010376 0.010376 0.010368 0.000010 0.000010 0.000010 0.000000 0.000010 0.087165 0.743570 0.010376 0.010376 0.010376 0.010376 0.010376",
2570 m3.setRow( "0.000010 0.000010 0.020875 0.010376 0.010376 0.010376 0.010376 0.010368 0.000010 0.000010 0.000010 0.000010 0.000000 0.087165 0.743570 0.010376 0.010376 0.010376 0.010376 0.010376",
2572 m3.setRow( "0.087165 0.087165 0.096983 0.098678 0.098678 0.098678 0.098678 0.098591 0.087165 0.087165 0.087165 0.087165 0.087165 0.000000 0.720387 0.098678 0.098678 0.098678 0.098678 0.098678",
2574 m3.setRow( "0.743570 0.743570 0.768150 0.741282 0.741282 0.741282 0.741282 0.745047 0.743570 0.743570 0.743570 0.743570 0.743570 0.720387 0.000000 0.741282 0.741282 0.741282 0.741282 0.741282",
2576 m3.setRow( "0.010376 0.010376 0.031503 0.000010 0.000010 0.000010 0.000010 0.010375 0.010376 0.010376 0.010376 0.010376 0.010376 0.098678 0.741282 0.000000 0.000010 0.000010 0.000010 0.000010",
2578 m3.setRow( "0.010376 0.010376 0.031503 0.000010 0.000010 0.000010 0.000010 0.010375 0.010376 0.010376 0.010376 0.010376 0.010376 0.098678 0.741282 0.000010 0.000000 0.000010 0.000010 0.000010",
2580 m3.setRow( "0.010376 0.010376 0.031503 0.000010 0.000010 0.000010 0.000010 0.010375 0.010376 0.010376 0.010376 0.010376 0.010376 0.098678 0.741282 0.000010 0.000010 0.000000 0.000010 0.000010",
2582 m3.setRow( "0.010376 0.010376 0.031503 0.000010 0.000010 0.000010 0.000010 0.010375 0.010376 0.010376 0.010376 0.010376 0.010376 0.098678 0.741282 0.000010 0.000010 0.000010 0.000000 0.000010",
2584 m3.setRow( "0.010376 0.010376 0.031503 0.000010 0.000010 0.000010 0.000010 0.010375 0.010376 0.010376 0.010376 0.010376 0.010376 0.098678 0.741282 0.000010 0.000010 0.000010 0.000010 0.000000",
2586 final NeighborJoiningR nj3 = NeighborJoiningR.createInstance( true, 6 );
2587 final Phylogeny p3 = nj3.execute( m3 );
2589 catch ( final Exception e ) {
2590 e.printStackTrace( System.out );
2596 private static boolean testSymmetricalDistanceMatrixParser() {
2598 final String l = ForesterUtil.getLineSeparator();
2599 StringBuffer source = new StringBuffer();
2600 source.append( " 4" + l );
2601 source.append( "A 0 0 0 0" + l );
2602 source.append( "B 1 0 0 0" + l );
2603 source.append( "C 2 4 0 0" + l );
2604 source.append( "D 3 5 6 0" + l );
2606 source.append( " 4" + l );
2607 source.append( "A 0 11 12 13" + l );
2608 source.append( "B 11 0 14 15" + l );
2609 source.append( "C 12 14 0 16" + l );
2610 source.append( "D 13 15 16 0" + l );
2613 source.append( " " + l );
2614 source.append( " 4" + l );
2615 source.append( " A 0 " + l );
2616 source.append( " B 21 0" + l );
2617 source.append( " C 22 24 0 " + l );
2618 source.append( " # 2 222 2 2 " + l );
2619 source.append( " D 23 25 26 0" + l );
2622 source.append( " " + l );
2623 final SymmetricalDistanceMatrixParser p0 = SymmetricalDistanceMatrixParser.createInstance();
2624 final DistanceMatrix[] ma0 = p0.parse( source.toString() );
2625 if ( ma0.length != 3 ) {
2628 if ( !isEqual( ma0[ 0 ].getValue( 0, 0 ), 0 ) ) {
2631 if ( !isEqual( ma0[ 0 ].getValue( 1, 0 ), 1 ) ) {
2634 if ( !isEqual( ma0[ 0 ].getValue( 2, 0 ), 2 ) ) {
2637 if ( !isEqual( ma0[ 0 ].getValue( 3, 0 ), 3 ) ) {
2640 if ( !isEqual( ma0[ 0 ].getValue( 0, 1 ), 1 ) ) {
2643 if ( !isEqual( ma0[ 0 ].getValue( 1, 1 ), 0 ) ) {
2646 if ( !isEqual( ma0[ 0 ].getValue( 2, 1 ), 4 ) ) {
2649 if ( !isEqual( ma0[ 0 ].getValue( 3, 1 ), 5 ) ) {
2652 if ( !isEqual( ma0[ 1 ].getValue( 0, 0 ), 0 ) ) {
2655 if ( !isEqual( ma0[ 1 ].getValue( 1, 0 ), 11 ) ) {
2658 if ( !isEqual( ma0[ 1 ].getValue( 2, 0 ), 12 ) ) {
2661 if ( !isEqual( ma0[ 1 ].getValue( 3, 0 ), 13 ) ) {
2664 if ( !isEqual( ma0[ 1 ].getValue( 0, 1 ), 11 ) ) {
2667 if ( !isEqual( ma0[ 1 ].getValue( 1, 1 ), 0 ) ) {
2670 if ( !isEqual( ma0[ 1 ].getValue( 2, 1 ), 14 ) ) {
2673 if ( !isEqual( ma0[ 1 ].getValue( 3, 1 ), 15 ) ) {
2676 if ( !isEqual( ma0[ 2 ].getValue( 0, 0 ), 0 ) ) {
2679 if ( !isEqual( ma0[ 2 ].getValue( 1, 0 ), 21 ) ) {
2682 if ( !isEqual( ma0[ 2 ].getValue( 2, 0 ), 22 ) ) {
2685 if ( !isEqual( ma0[ 2 ].getValue( 3, 0 ), 23 ) ) {
2688 if ( !isEqual( ma0[ 2 ].getValue( 0, 1 ), 21 ) ) {
2691 if ( !isEqual( ma0[ 2 ].getValue( 1, 1 ), 0 ) ) {
2694 if ( !isEqual( ma0[ 2 ].getValue( 2, 1 ), 24 ) ) {
2697 if ( !isEqual( ma0[ 2 ].getValue( 3, 1 ), 25 ) ) {
2700 source = new StringBuffer();
2701 source.append( "A 0 0 0 0" + l );
2702 source.append( "B 1 0 0 0" + l );
2703 source.append( "C 2 4 0 0" + l );
2704 source.append( "D 3 5 6 0" + l );
2705 source.append( " " + l );
2706 source.append( "A 0 11 12 13" + l );
2707 source.append( "B 11 0 14 15" + l );
2708 source.append( "C 12 14 0 16" + l );
2709 source.append( "D 13 15 16 0" + l );
2711 source.append( " A 0 " + l );
2712 source.append( " B 21 0" + l );
2713 source.append( " C 22 24 0 " + l );
2714 source.append( " # 2 222 2 2 " + l );
2715 source.append( " D 23 25 26 0" + l );
2716 final DistanceMatrix[] ma1 = p0.parse( source.toString() );
2717 if ( ma1.length != 3 ) {
2720 if ( !isEqual( ma1[ 0 ].getValue( 0, 0 ), 0 ) ) {
2723 if ( !isEqual( ma1[ 0 ].getValue( 1, 0 ), 1 ) ) {
2726 if ( !isEqual( ma1[ 0 ].getValue( 2, 0 ), 2 ) ) {
2729 if ( !isEqual( ma1[ 0 ].getValue( 3, 0 ), 3 ) ) {
2732 if ( !isEqual( ma1[ 0 ].getValue( 0, 1 ), 1 ) ) {
2735 if ( !isEqual( ma1[ 0 ].getValue( 1, 1 ), 0 ) ) {
2738 if ( !isEqual( ma1[ 0 ].getValue( 2, 1 ), 4 ) ) {
2741 if ( !isEqual( ma1[ 0 ].getValue( 3, 1 ), 5 ) ) {
2744 if ( !isEqual( ma1[ 1 ].getValue( 0, 0 ), 0 ) ) {
2747 if ( !isEqual( ma1[ 1 ].getValue( 1, 0 ), 11 ) ) {
2750 if ( !isEqual( ma1[ 1 ].getValue( 2, 0 ), 12 ) ) {
2753 if ( !isEqual( ma1[ 1 ].getValue( 3, 0 ), 13 ) ) {
2756 if ( !isEqual( ma1[ 1 ].getValue( 0, 1 ), 11 ) ) {
2759 if ( !isEqual( ma1[ 1 ].getValue( 1, 1 ), 0 ) ) {
2762 if ( !isEqual( ma1[ 1 ].getValue( 2, 1 ), 14 ) ) {
2765 if ( !isEqual( ma1[ 1 ].getValue( 3, 1 ), 15 ) ) {
2768 if ( !isEqual( ma1[ 2 ].getValue( 0, 0 ), 0 ) ) {
2771 if ( !isEqual( ma1[ 2 ].getValue( 1, 0 ), 21 ) ) {
2774 if ( !isEqual( ma1[ 2 ].getValue( 2, 0 ), 22 ) ) {
2777 if ( !isEqual( ma1[ 2 ].getValue( 3, 0 ), 23 ) ) {
2780 if ( !isEqual( ma1[ 2 ].getValue( 0, 1 ), 21 ) ) {
2783 if ( !isEqual( ma1[ 2 ].getValue( 1, 1 ), 0 ) ) {
2786 if ( !isEqual( ma1[ 2 ].getValue( 2, 1 ), 24 ) ) {
2789 if ( !isEqual( ma1[ 2 ].getValue( 3, 1 ), 25 ) ) {
2792 source = new StringBuffer();
2793 source.append( "A 0" + l );
2794 source.append( "B 10 0" + l );
2795 final DistanceMatrix[] ma2 = p0.parse( source.toString() );
2796 if ( ma2.length != 1 ) {
2799 if ( !isEqual( ma2[ 0 ].getValue( 0, 1 ), 10 ) ) {
2802 source = new StringBuffer();
2803 source.append( " " + l );
2804 source.append( "#" + l );
2805 final DistanceMatrix[] ma3 = p0.parse( source.toString() );
2806 if ( ma3.length != 0 ) {
2809 source = new StringBuffer();
2810 source.append( " " + l );
2811 source.append( "A 0 11 12 13" + l );
2812 source.append( "B 0 14 15" + l );
2813 source.append( "C 0 16" + l );
2814 source.append( "D 0" + l );
2816 source.append( "A 0 21 22 23" + l );
2817 source.append( "B 0 24 25" + l );
2818 source.append( "C 0 26" + l );
2819 source.append( "D 0" + l );
2820 p0.setInputMatrixType( SymmetricalDistanceMatrixParser.InputMatrixType.UPPER_TRIANGLE );
2821 final DistanceMatrix[] ma4 = p0.parse( source );
2822 if ( ma4.length != 2 ) {
2825 if ( !isEqual( ma4[ 0 ].getValue( 0, 0 ), 0 ) ) {
2828 if ( !isEqual( ma4[ 0 ].getValue( 1, 0 ), 11 ) ) {
2831 if ( !isEqual( ma4[ 0 ].getValue( 2, 0 ), 12 ) ) {
2834 if ( !isEqual( ma4[ 0 ].getValue( 3, 0 ), 13 ) ) {
2837 if ( !isEqual( ma4[ 0 ].getValue( 0, 1 ), 11 ) ) {
2840 if ( !isEqual( ma4[ 0 ].getValue( 1, 1 ), 0 ) ) {
2843 if ( !isEqual( ma4[ 0 ].getValue( 2, 1 ), 14 ) ) {
2846 if ( !isEqual( ma4[ 0 ].getValue( 3, 1 ), 15 ) ) {
2849 if ( !isEqual( ma4[ 0 ].getValue( 0, 2 ), 12 ) ) {
2852 if ( !isEqual( ma4[ 0 ].getValue( 1, 2 ), 14 ) ) {
2855 if ( !isEqual( ma4[ 0 ].getValue( 2, 2 ), 0 ) ) {
2858 if ( !isEqual( ma4[ 0 ].getValue( 3, 2 ), 16 ) ) {
2861 if ( !isEqual( ma4[ 0 ].getValue( 0, 3 ), 13 ) ) {
2864 if ( !isEqual( ma4[ 0 ].getValue( 1, 3 ), 15 ) ) {
2867 if ( !isEqual( ma4[ 0 ].getValue( 2, 3 ), 16 ) ) {
2870 if ( !isEqual( ma4[ 0 ].getValue( 3, 3 ), 0 ) ) {
2873 source = new StringBuffer();
2874 source.append( " 4 " + l );
2875 source.append( "A 0 11 12 13" + l );
2876 source.append( "B 0 14 15" + l );
2877 source.append( "C 0 16" + l );
2878 source.append( "D 0" + l );
2879 source.append( " 4" + l );
2880 source.append( "A 0 21 22 23" + l );
2881 source.append( "B 0 24 25" + l );
2882 source.append( "C 0 26" + l );
2883 source.append( "D 0" + l );
2884 source.append( " " + l );
2885 source.append( " 4" + l );
2886 source.append( "A 0 21 22 23" + l );
2887 source.append( "B 0 24 25" + l );
2888 source.append( "C 0 26" + l );
2889 source.append( "D 0" + l );
2891 source.append( "A 0 21 22 23" + l );
2892 source.append( "B 0 24 25" + l );
2893 source.append( "C 0 26" + l );
2894 source.append( "D 0" + l );
2895 p0.setInputMatrixType( SymmetricalDistanceMatrixParser.InputMatrixType.UPPER_TRIANGLE );
2896 final DistanceMatrix[] ma5 = p0.parse( source );
2897 if ( ma5.length != 4 ) {
2900 if ( !isEqual( ma5[ 0 ].getValue( 0, 0 ), 0 ) ) {
2903 if ( !isEqual( ma5[ 0 ].getValue( 1, 0 ), 11 ) ) {
2906 if ( !isEqual( ma5[ 0 ].getValue( 2, 0 ), 12 ) ) {
2909 if ( !isEqual( ma5[ 0 ].getValue( 3, 0 ), 13 ) ) {
2912 if ( !isEqual( ma5[ 0 ].getValue( 0, 1 ), 11 ) ) {
2915 if ( !isEqual( ma5[ 0 ].getValue( 1, 1 ), 0 ) ) {
2918 if ( !isEqual( ma5[ 0 ].getValue( 2, 1 ), 14 ) ) {
2921 if ( !isEqual( ma5[ 0 ].getValue( 3, 1 ), 15 ) ) {
2924 if ( !isEqual( ma5[ 0 ].getValue( 0, 2 ), 12 ) ) {
2927 if ( !isEqual( ma5[ 0 ].getValue( 1, 2 ), 14 ) ) {
2930 if ( !isEqual( ma5[ 0 ].getValue( 2, 2 ), 0 ) ) {
2933 if ( !isEqual( ma5[ 0 ].getValue( 3, 2 ), 16 ) ) {
2936 if ( !isEqual( ma5[ 0 ].getValue( 0, 3 ), 13 ) ) {
2939 if ( !isEqual( ma5[ 0 ].getValue( 1, 3 ), 15 ) ) {
2942 if ( !isEqual( ma5[ 0 ].getValue( 2, 3 ), 16 ) ) {
2945 if ( !isEqual( ma5[ 0 ].getValue( 3, 3 ), 0 ) ) {
2949 catch ( final Exception e ) {
2950 e.printStackTrace( System.out );
2956 private static void timeNeighborJoining() {
2957 final NeighborJoiningR njr = NeighborJoiningR.createInstance();
2958 for( int n = 3; n <= 9; ++n ) {
2959 final int x = ( int ) Math.pow( 2, n );
2960 final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( x );
2961 mt.randomize( new Date().getTime() );
2962 final long start_time = new Date().getTime();
2964 System.out.println( "Size: " + x + " -> " + ( new Date().getTime() - start_time ) + "ms" );
2966 final NeighborJoiningF njf = NeighborJoiningF.createInstance();
2967 for( int n = 3; n <= 9; ++n ) {
2968 final int x = ( int ) Math.pow( 2, n );
2969 final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( x );
2970 mt.randomize( new Date().getTime() );
2971 final long start_time = new Date().getTime();
2973 System.out.println( "Size: " + x + " -> " + ( new Date().getTime() - start_time ) + "ms" );
2975 final NeighborJoining nj = NeighborJoining.createInstance();
2976 for( int n = 3; n <= 9; ++n ) {
2977 final int x = ( int ) Math.pow( 2, n );
2978 final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( x );
2979 mt.randomize( new Date().getTime() );
2980 final long start_time = new Date().getTime();
2982 System.out.println( "Size: " + x + " -> " + ( new Date().getTime() - start_time ) + "ms" );