+ s3.asSimpleText();
+ s3.asText();
+ // Taxonomy
+ // ----------
+ final Taxonomy t1 = new Taxonomy();
+ final Taxonomy t2 = new Taxonomy();
+ final Taxonomy t3 = new Taxonomy();
+ final Taxonomy t4 = new Taxonomy();
+ final Taxonomy t5 = new Taxonomy();
+ t1.setIdentifier( new Identifier( "ecoli" ) );
+ t1.setTaxonomyCode( "ECOLI" );
+ t1.setScientificName( "E. coli" );
+ t1.setCommonName( "coli" );
+ final Taxonomy t0 = ( Taxonomy ) t1.copy();
+ if ( !t1.isEqual( t0 ) ) {
+ return false;
+ }
+ t2.setIdentifier( new Identifier( "ecoli" ) );
+ t2.setTaxonomyCode( "OTHER" );
+ t2.setScientificName( "what" );
+ t2.setCommonName( "something" );
+ if ( !t1.isEqual( t2 ) ) {
+ return false;
+ }
+ t2.setIdentifier( new Identifier( "nemve" ) );
+ if ( t1.isEqual( t2 ) ) {
+ return false;
+ }
+ t1.setIdentifier( null );
+ t3.setTaxonomyCode( "ECOLI" );
+ t3.setScientificName( "what" );
+ t3.setCommonName( "something" );
+ if ( !t1.isEqual( t3 ) ) {
+ return false;
+ }
+ t1.setIdentifier( null );
+ t1.setTaxonomyCode( "" );
+ t4.setScientificName( "E. ColI" );
+ t4.setCommonName( "something" );
+ if ( !t1.isEqual( t4 ) ) {
+ return false;
+ }
+ t4.setScientificName( "B. subtilis" );
+ t4.setCommonName( "something" );
+ if ( t1.isEqual( t4 ) ) {
+ return false;
+ }
+ t1.setIdentifier( null );
+ t1.setTaxonomyCode( "" );
+ t1.setScientificName( "" );
+ t5.setCommonName( "COLI" );
+ if ( !t1.isEqual( t5 ) ) {
+ return false;
+ }
+ t5.setCommonName( "vibrio" );
+ if ( t1.isEqual( t5 ) ) {
+ return false;
+ }
+ // Identifier
+ // ----------
+ final Identifier id0 = new Identifier( "123", "pfam" );
+ final Identifier id1 = ( Identifier ) id0.copy();
+ if ( !id1.isEqual( id1 ) ) {
+ return false;
+ }
+ if ( !id1.isEqual( id0 ) ) {
+ return false;
+ }
+ if ( !id0.isEqual( id1 ) ) {
+ return false;
+ }
+ id1.asSimpleText();
+ id1.asText();
+ // ProteinDomain
+ // ---------------
+ final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
+ final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
+ if ( !pd1.isEqual( pd1 ) ) {
+ return false;
+ }
+ if ( !pd1.isEqual( pd0 ) ) {
+ return false;
+ }
+ pd1.asSimpleText();
+ pd1.asText();
+ final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
+ final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
+ if ( !pd3.isEqual( pd3 ) ) {
+ return false;
+ }
+ if ( !pd2.isEqual( pd3 ) ) {
+ return false;
+ }
+ if ( !pd0.isEqual( pd3 ) ) {
+ return false;
+ }
+ pd3.asSimpleText();
+ pd3.asText();
+ // DomainArchitecture
+ // ------------------
+ final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
+ final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
+ final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
+ final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
+ final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
+ final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
+ domains0.add( d2 );
+ domains0.add( d0 );
+ domains0.add( d3 );
+ domains0.add( d1 );
+ final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
+ if ( ds0.getNumberOfDomains() != 4 ) {
+ return false;
+ }
+ final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
+ if ( !ds0.isEqual( ds0 ) ) {
+ return false;
+ }
+ if ( !ds0.isEqual( ds1 ) ) {
+ return false;
+ }
+ if ( ds1.getNumberOfDomains() != 4 ) {
+ return false;
+ }
+ final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
+ domains1.add( d1 );
+ domains1.add( d2 );
+ domains1.add( d4 );
+ domains1.add( d0 );
+ final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
+ if ( ds0.isEqual( ds2 ) ) {
+ return false;
+ }
+ ds1.asSimpleText();
+ ds1.asText();
+ ds1.toNHX();
+ final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
+ if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
+ System.out.println( ds3.toNHX() );
+ return false;
+ }
+ if ( ds3.getNumberOfDomains() != 3 ) {
+ return false;
+ }
+ // Event
+ // -----
+ final Event e1 = new Event( Event.EventType.fusion );
+ if ( e1.isDuplication() ) {
+ return false;
+ }
+ if ( !e1.isFusion() ) {
+ return false;
+ }
+ if ( !e1.asText().toString().equals( "fusion" ) ) {
+ return false;
+ }
+ if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
+ return false;
+ }
+ final Event e11 = new Event( Event.EventType.fusion );
+ if ( !e11.isEqual( e1 ) ) {
+ return false;
+ }
+ if ( !e11.toNHX().toString().equals( "" ) ) {
+ return false;
+ }
+ final Event e2 = new Event( Event.EventType.speciation_or_duplication );
+ if ( e2.isDuplication() ) {
+ return false;
+ }
+ if ( !e2.isSpeciationOrDuplication() ) {
+ return false;
+ }
+ if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
+ return false;
+ }
+ if ( !e2.asSimpleText().toString().equals( "?" ) ) {
+ return false;
+ }
+ if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
+ return false;
+ }
+ if ( e11.isEqual( e2 ) ) {
+ return false;
+ }
+ final Event e2c = ( Event ) e2.copy();
+ if ( !e2c.isEqual( e2 ) ) {
+ return false;
+ }
+ Event e3 = new Event( 1, 2, 3 );
+ if ( e3.isDuplication() ) {
+ return false;
+ }
+ if ( e3.isSpeciation() ) {
+ return false;
+ }
+ if ( e3.isGeneLoss() ) {
+ return false;
+ }
+ if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
+ return false;
+ }
+ final Event e3c = ( Event ) e3.copy();
+ final Event e3cc = ( Event ) e3c.copy();
+ if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
+ return false;
+ }
+ e3 = null;
+ if ( !e3c.isEqual( e3cc ) ) {
+ return false;
+ }
+ Event e4 = new Event( 1, 2, 3 );
+ if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
+ return false;
+ }
+ if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
+ return false;
+ }
+ final Event e4c = ( Event ) e4.copy();
+ e4 = null;
+ final Event e4cc = ( Event ) e4c.copy();
+ if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
+ return false;
+ }
+ if ( !e4c.isEqual( e4cc ) ) {
+ return false;
+ }
+ final Event e5 = new Event();
+ if ( !e5.isUnassigned() ) {
+ return false;
+ }
+ if ( !e5.asText().toString().equals( "unassigned" ) ) {
+ return false;
+ }
+ if ( !e5.asSimpleText().toString().equals( "" ) ) {
+ return false;
+ }
+ final Event e6 = new Event( 1, 0, 0 );
+ if ( !e6.asText().toString().equals( "duplication" ) ) {
+ return false;
+ }
+ if ( !e6.asSimpleText().toString().equals( "D" ) ) {
+ return false;
+ }
+ final Event e7 = new Event( 0, 1, 0 );
+ if ( !e7.asText().toString().equals( "speciation" ) ) {
+ return false;
+ }
+ if ( !e7.asSimpleText().toString().equals( "S" ) ) {
+ return false;
+ }
+ final Event e8 = new Event( 0, 0, 1 );
+ if ( !e8.asText().toString().equals( "gene-loss" ) ) {
+ return false;
+ }
+ if ( !e8.asSimpleText().toString().equals( "L" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testDeletionOfExternalNodes() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
+ final PhylogenyWriter w = new PhylogenyWriter();
+ if ( t0.isEmpty() ) {
+ return false;
+ }
+ if ( t0.getNumberOfExternalNodes() != 1 ) {
+ return false;
+ }
+ t0.deleteSubtree( t0.getNode( "A" ), false );
+ if ( t0.getNumberOfExternalNodes() != 0 ) {
+ return false;
+ }
+ if ( !t0.isEmpty() ) {
+ return false;
+ }
+ final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
+ if ( t1.getNumberOfExternalNodes() != 2 ) {
+ return false;
+ }
+ t1.deleteSubtree( t1.getNode( "A" ), false );
+ if ( t1.getNumberOfExternalNodes() != 1 ) {
+ return false;
+ }
+ if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
+ return false;
+ }
+ t1.deleteSubtree( t1.getNode( "B" ), false );
+ if ( t1.getNumberOfExternalNodes() != 1 ) {
+ return false;
+ }
+ t1.deleteSubtree( t1.getNode( "r" ), false );
+ if ( !t1.isEmpty() ) {
+ return false;
+ }
+ final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
+ if ( t2.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ t2.deleteSubtree( t2.getNode( "B" ), false );
+ if ( t2.getNumberOfExternalNodes() != 2 ) {
+ return false;
+ }
+ t2.toNewHampshireX();
+ PhylogenyNode n = t2.getNode( "A" );
+ if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
+ return false;
+ }
+ t2.deleteSubtree( t2.getNode( "A" ), false );
+ if ( t2.getNumberOfExternalNodes() != 2 ) {
+ return false;
+ }
+ t2.deleteSubtree( t2.getNode( "C" ), true );
+ if ( t2.getNumberOfExternalNodes() != 1 ) {
+ return false;
+ }
+ final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
+ if ( t3.getNumberOfExternalNodes() != 4 ) {
+ return false;
+ }
+ t3.deleteSubtree( t3.getNode( "B" ), true );
+ if ( t3.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ n = t3.getNode( "A" );
+ if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
+ return false;
+ }
+ t3.deleteSubtree( t3.getNode( "A" ), true );
+ if ( t3.getNumberOfExternalNodes() != 2 ) {
+ return false;
+ }
+ n = t3.getNode( "C" );
+ if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
+ return false;
+ }
+ t3.deleteSubtree( t3.getNode( "C" ), true );
+ if ( t3.getNumberOfExternalNodes() != 1 ) {
+ return false;
+ }
+ t3.deleteSubtree( t3.getNode( "D" ), true );
+ if ( t3.getNumberOfExternalNodes() != 0 ) {
+ return false;
+ }
+ final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
+ if ( t4.getNumberOfExternalNodes() != 6 ) {
+ return false;
+ }
+ t4.deleteSubtree( t4.getNode( "B2" ), true );
+ if ( t4.getNumberOfExternalNodes() != 5 ) {
+ return false;
+ }
+ String s = w.toNewHampshire( t4, true ).toString();
+ if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
+ return false;
+ }
+ t4.deleteSubtree( t4.getNode( "B11" ), true );
+ if ( t4.getNumberOfExternalNodes() != 4 ) {
+ return false;
+ }
+ t4.deleteSubtree( t4.getNode( "C" ), true );
+ if ( t4.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ n = t4.getNode( "A" );
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "B12" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "D" ) ) {
+ return false;
+ }
+ s = w.toNewHampshire( t4, true ).toString();
+ if ( !s.equals( "((A,B12),D);" ) ) {
+ return false;
+ }
+ final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
+ t5.deleteSubtree( t5.getNode( "A" ), true );
+ if ( t5.getNumberOfExternalNodes() != 5 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t5, true ).toString();
+ if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
+ return false;
+ }
+ final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
+ t6.deleteSubtree( t6.getNode( "B11" ), true );
+ if ( t6.getNumberOfExternalNodes() != 5 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t6, false ).toString();
+ if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
+ return false;
+ }
+ final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
+ t7.deleteSubtree( t7.getNode( "B12" ), true );
+ if ( t7.getNumberOfExternalNodes() != 5 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t7, true ).toString();
+ if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
+ return false;
+ }
+ final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
+ t8.deleteSubtree( t8.getNode( "B2" ), true );
+ if ( t8.getNumberOfExternalNodes() != 5 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t8, false ).toString();
+ if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
+ return false;
+ }
+ final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
+ t9.deleteSubtree( t9.getNode( "C" ), true );
+ if ( t9.getNumberOfExternalNodes() != 5 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t9, true ).toString();
+ if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
+ return false;
+ }
+ final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
+ t10.deleteSubtree( t10.getNode( "D" ), true );
+ if ( t10.getNumberOfExternalNodes() != 5 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t10, true ).toString();
+ if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
+ return false;
+ }
+ final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
+ t11.deleteSubtree( t11.getNode( "A" ), true );
+ if ( t11.getNumberOfExternalNodes() != 2 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t11, true ).toString();
+ if ( !s.equals( "(B,C);" ) ) {
+ return false;
+ }
+ t11.deleteSubtree( t11.getNode( "C" ), true );
+ if ( t11.getNumberOfExternalNodes() != 1 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t11, false ).toString();
+ if ( !s.equals( "B;" ) ) {
+ return false;
+ }
+ final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
+ t12.deleteSubtree( t12.getNode( "B2" ), true );
+ if ( t12.getNumberOfExternalNodes() != 8 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t12, true ).toString();
+ if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
+ return false;
+ }
+ t12.deleteSubtree( t12.getNode( "B3" ), true );
+ if ( t12.getNumberOfExternalNodes() != 7 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t12, true ).toString();
+ if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
+ return false;
+ }
+ t12.deleteSubtree( t12.getNode( "C3" ), true );
+ if ( t12.getNumberOfExternalNodes() != 6 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t12, true ).toString();
+ if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
+ return false;
+ }
+ t12.deleteSubtree( t12.getNode( "A1" ), true );
+ if ( t12.getNumberOfExternalNodes() != 5 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t12, true ).toString();
+ if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
+ return false;
+ }
+ t12.deleteSubtree( t12.getNode( "B1" ), true );
+ if ( t12.getNumberOfExternalNodes() != 4 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t12, true ).toString();
+ if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
+ return false;
+ }
+ t12.deleteSubtree( t12.getNode( "A3" ), true );
+ if ( t12.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t12, true ).toString();
+ if ( !s.equals( "(A2,(C1,C2));" ) ) {
+ return false;
+ }
+ t12.deleteSubtree( t12.getNode( "A2" ), true );
+ if ( t12.getNumberOfExternalNodes() != 2 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t12, true ).toString();
+ if ( !s.equals( "(C1,C2);" ) ) {
+ return false;
+ }
+ final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
+ t13.deleteSubtree( t13.getNode( "D" ), true );
+ if ( t13.getNumberOfExternalNodes() != 4 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t13, true ).toString();
+ if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
+ return false;
+ }
+ final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
+ t14.deleteSubtree( t14.getNode( "E" ), true );
+ if ( t14.getNumberOfExternalNodes() != 5 ) {
+ return false;
+ }
+ s = w.toNewHampshire( t14, true ).toString();
+ if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
+ return false;
+ }
+ final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
+ t15.deleteSubtree( t15.getNode( "B2" ), true );
+ if ( t15.getNumberOfExternalNodes() != 11 ) {
+ return false;
+ }
+ t15.deleteSubtree( t15.getNode( "B1" ), true );
+ if ( t15.getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ t15.deleteSubtree( t15.getNode( "B3" ), true );
+ if ( t15.getNumberOfExternalNodes() != 9 ) {
+ return false;
+ }
+ t15.deleteSubtree( t15.getNode( "B4" ), true );
+ if ( t15.getNumberOfExternalNodes() != 8 ) {
+ return false;
+ }
+ t15.deleteSubtree( t15.getNode( "A1" ), true );
+ if ( t15.getNumberOfExternalNodes() != 7 ) {
+ return false;
+ }
+ t15.deleteSubtree( t15.getNode( "C4" ), true );
+ if ( t15.getNumberOfExternalNodes() != 6 ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testDescriptiveStatistics() {
+ try {
+ final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
+ dss1.addValue( 82 );
+ dss1.addValue( 78 );
+ dss1.addValue( 70 );
+ dss1.addValue( 58 );
+ dss1.addValue( 42 );
+ if ( dss1.getN() != 5 ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.median(), 70 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
+ return false;
+ }
+ dss1.addValue( 123 );
+ if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
+ return false;
+ }
+ final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
+ dss2.addValue( -1.85 );
+ dss2.addValue( 57.5 );
+ dss2.addValue( 92.78 );
+ dss2.addValue( 57.78 );
+ if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
+ return false;
+ }
+ final double[] a = dss2.getDataAsDoubleArray();
+ if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
+ return false;
+ }
+ dss2.addValue( -100 );
+ if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
+ return false;
+ }
+ final double[] ds = new double[ 14 ];
+ ds[ 0 ] = 34;
+ ds[ 1 ] = 23;
+ ds[ 2 ] = 1;
+ ds[ 3 ] = 32;
+ ds[ 4 ] = 11;
+ ds[ 5 ] = 2;
+ ds[ 6 ] = 12;
+ ds[ 7 ] = 33;
+ ds[ 8 ] = 13;
+ ds[ 9 ] = 22;
+ ds[ 10 ] = 21;
+ ds[ 11 ] = 35;
+ ds[ 12 ] = 24;
+ ds[ 13 ] = 31;
+ final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
+ if ( bins.length != 4 ) {
+ return false;
+ }
+ if ( bins[ 0 ] != 2 ) {
+ return false;
+ }
+ if ( bins[ 1 ] != 3 ) {
+ return false;
+ }
+ if ( bins[ 2 ] != 4 ) {
+ return false;
+ }
+ if ( bins[ 3 ] != 5 ) {
+ return false;
+ }
+ final double[] ds1 = new double[ 9 ];
+ ds1[ 0 ] = 10.0;
+ ds1[ 1 ] = 19.0;
+ ds1[ 2 ] = 9.999;
+ ds1[ 3 ] = 0.0;
+ ds1[ 4 ] = 39.9;
+ ds1[ 5 ] = 39.999;
+ ds1[ 6 ] = 30.0;
+ ds1[ 7 ] = 19.999;
+ ds1[ 8 ] = 30.1;
+ final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
+ if ( bins1.length != 4 ) {
+ return false;
+ }
+ if ( bins1[ 0 ] != 2 ) {
+ return false;
+ }
+ if ( bins1[ 1 ] != 3 ) {
+ return false;
+ }
+ if ( bins1[ 2 ] != 0 ) {
+ return false;
+ }
+ if ( bins1[ 3 ] != 4 ) {
+ return false;
+ }
+ final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
+ if ( bins1_1.length != 3 ) {
+ return false;
+ }
+ if ( bins1_1[ 0 ] != 3 ) {
+ return false;
+ }
+ if ( bins1_1[ 1 ] != 2 ) {
+ return false;
+ }
+ if ( bins1_1[ 2 ] != 4 ) {
+ return false;
+ }
+ final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
+ if ( bins1_2.length != 3 ) {
+ return false;
+ }
+ if ( bins1_2[ 0 ] != 2 ) {
+ return false;
+ }
+ if ( bins1_2[ 1 ] != 2 ) {
+ return false;
+ }
+ if ( bins1_2[ 2 ] != 2 ) {
+ return false;
+ }
+ final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
+ dss3.addValue( 1 );
+ dss3.addValue( 1 );
+ dss3.addValue( 1 );
+ dss3.addValue( 2 );
+ dss3.addValue( 3 );
+ dss3.addValue( 4 );
+ dss3.addValue( 5 );
+ dss3.addValue( 5 );
+ dss3.addValue( 5 );
+ dss3.addValue( 6 );
+ dss3.addValue( 7 );
+ dss3.addValue( 8 );
+ dss3.addValue( 9 );
+ dss3.addValue( 10 );
+ dss3.addValue( 10 );
+ dss3.addValue( 10 );
+ final AsciiHistogram histo = new AsciiHistogram( dss3 );
+ histo.toStringBuffer( 10, '=', 40, 5 );
+ histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testDir( final String file ) {
+ try {
+ final File f = new File( file );
+ if ( !f.exists() ) {
+ return false;
+ }
+ if ( !f.isDirectory() ) {
+ return false;
+ }
+ if ( !f.canRead() ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testEbiEntryRetrieval() {
+ try {
+ final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
+ if ( !entry.getAccession().equals( "AAK41263" ) ) {
+ System.out.println( entry.getAccession() );
+ return false;
+ }
+ if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
+ System.out.println( entry.getTaxonomyScientificName() );
+ return false;
+ }
+ if ( !entry.getSequenceName()
+ .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
+ System.out.println( entry.getSequenceName() );
+ return false;
+ }
+ if ( !entry.getGeneName().equals( "treX-like" ) ) {
+ System.out.println( entry.getGeneName() );
+ return false;
+ }
+ if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
+ System.out.println( entry.getTaxonomyIdentifier() );
+ return false;
+ }
+ if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
+ System.out.println( entry.getAnnotations().first().getRefValue() );
+ return false;
+ }
+ if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
+ System.out.println( entry.getAnnotations().first().getRefSource() );
+ return false;
+ }
+ if ( entry.getCrossReferences().size() < 1 ) {
+ return false;
+ }
+ final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
+ if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
+ return false;
+ }
+ if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
+ System.out.println( entry1.getTaxonomyScientificName() );
+ return false;
+ }
+ if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
+ System.out.println( entry1.getSequenceName() );
+ return false;
+ }
+ if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
+ System.out.println( entry1.getTaxonomyIdentifier() );
+ return false;
+ }
+ if ( !entry1.getGeneName().equals( "BCL2" ) ) {
+ System.out.println( entry1.getGeneName() );
+ return false;
+ }
+ if ( entry1.getCrossReferences().size() < 1 ) {
+ return false;
+ }
+ final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
+ if ( !entry2.getAccession().equals( "NM_184234" ) ) {
+ return false;
+ }
+ if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
+ System.out.println( entry2.getTaxonomyScientificName() );
+ return false;
+ }
+ if ( !entry2.getSequenceName()
+ .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
+ System.out.println( entry2.getSequenceName() );
+ return false;
+ }
+ if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
+ System.out.println( entry2.getTaxonomyIdentifier() );
+ return false;
+ }
+ if ( !entry2.getGeneName().equals( "RBM39" ) ) {
+ System.out.println( entry2.getGeneName() );
+ return false;
+ }
+ if ( entry2.getCrossReferences().size() < 1 ) {
+ return false;
+ }
+ if ( !entry2.getChromosome().equals( "20" ) ) {
+ return false;
+ }
+ if ( !entry2.getMap().equals( "20q11.22" ) ) {
+ return false;
+ }
+ final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
+ if ( !entry3.getAccession().equals( "HM043801" ) ) {
+ return false;
+ }
+ if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
+ System.out.println( entry3.getTaxonomyScientificName() );
+ return false;
+ }
+ if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
+ System.out.println( entry3.getSequenceName() );
+ return false;
+ }
+ if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
+ System.out.println( entry3.getTaxonomyIdentifier() );
+ return false;
+ }
+ if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
+ System.out.println( entry3.getSequenceSymbol() );
+ return false;
+ }
+ if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
+ return false;
+ }
+ if ( entry3.getCrossReferences().size() < 1 ) {
+ return false;
+ }
+ final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
+ if ( !entry4.getAccession().equals( "AAA36557" ) ) {
+ return false;
+ }
+ if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
+ System.out.println( entry4.getTaxonomyScientificName() );
+ return false;
+ }
+ if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
+ System.out.println( entry4.getSequenceName() );
+ return false;
+ }
+ if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
+ System.out.println( entry4.getTaxonomyIdentifier() );
+ return false;
+ }
+ if ( !entry4.getGeneName().equals( "ras" ) ) {
+ System.out.println( entry4.getGeneName() );
+ return false;
+ }
+ final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
+ if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
+ return false;
+ }
+ if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
+ System.out.println( entry5.getTaxonomyScientificName() );
+ return false;
+ }
+ if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
+ System.out.println( entry5.getSequenceName() );
+ return false;
+ }
+ if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
+ System.out.println( entry5.getTaxonomyIdentifier() );
+ return false;
+ }
+ final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
+ if ( !entry6.getAccession().equals( "M30539" ) ) {
+ return false;
+ }
+ if ( !entry6.getGeneName().equals( "ras" ) ) {
+ return false;
+ }
+ if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
+ return false;
+ }
+ if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
+ return false;
+ }
+ if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
+ return false;
+ }
+ if ( entry6.getCrossReferences().size() < 1 ) {
+ return false;
+ }
+ }
+ catch ( final IOException e ) {
+ System.out.println();
+ System.out.println( "the following might be due to absence internet connection:" );
+ e.printStackTrace( System.out );
+ return true;
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testExternalNodeRelatedMethods() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
+ PhylogenyNode n = t1.getNode( "A" );
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "B" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "C" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "D" ) ) {
+ return false;
+ }
+ n = t1.getNode( "B" );
+ while ( !n.isLastExternalNode() ) {
+ n = n.getNextExternalNode();
+ }
+ final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
+ n = t2.getNode( "A" );
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "B" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "C" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "D" ) ) {
+ return false;
+ }
+ n = t2.getNode( "B" );
+ while ( !n.isLastExternalNode() ) {
+ n = n.getNextExternalNode();
+ }
+ final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
+ n = t3.getNode( "A" );
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "B" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "C" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "D" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "E" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "F" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "G" ) ) {
+ return false;
+ }
+ n = n.getNextExternalNode();
+ if ( !n.getName().equals( "H" ) ) {
+ return false;
+ }
+ n = t3.getNode( "B" );
+ while ( !n.isLastExternalNode() ) {
+ n = n.getNextExternalNode();
+ }
+ final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
+ for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
+ final PhylogenyNode node = iter.next();
+ }
+ final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
+ for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
+ final PhylogenyNode node = iter.next();
+ }
+ final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
+ final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
+ if ( !iter.next().getName().equals( "A" ) ) {
+ return false;
+ }
+ if ( !iter.next().getName().equals( "B" ) ) {
+ return false;
+ }
+ if ( !iter.next().getName().equals( "C" ) ) {
+ return false;
+ }
+ if ( !iter.next().getName().equals( "D" ) ) {
+ return false;
+ }
+ if ( !iter.next().getName().equals( "E" ) ) {
+ return false;
+ }
+ if ( !iter.next().getName().equals( "F" ) ) {
+ return false;
+ }
+ if ( iter.hasNext() ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testExtractSNFromNodeName() {
+ try {
+ if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
+ .equals( "Mus musculus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
+ .equals( "Mus musculus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
+ .equals( "Mus musculus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
+ .equals( "Mus musculus musculus" ) ) {
+ return false;
+ }
+ if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
+ .equals( "Mus musculus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
+ .equals( "Mus musculus musculus" ) ) {
+ return false;
+ }
+ if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
+ return false;
+ }
+ if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
+ return false;
+ }
+ if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
+ return false;
+ }
+ if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
+ .equals( "Mus musculus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
+ .equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
+ .equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
+ .equals( "Mus musculus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
+ .equals( "Mus musculus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
+ .equals( "Mus musculus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
+ .equals( "Pilostyles mexicana" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
+ .equals( "Escherichia coli strain K12/DH10B" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
+ .equals( "Escherichia coli str. K12/DH10B" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
+ .equals( "Escherichia coli str. K12/DH10B" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
+ .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
+ .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
+ .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
+ .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
+ .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
+ .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
+ .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
+ .equals( "Escherichia coli (strain K12)" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
+ .equals( "Escherichia coli (strain K12)" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
+ .equals( "Escherichia coli (str. K12)" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
+ .equals( "Escherichia coli (str. K12)" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
+ .equals( "Escherichia coli (str. K12)" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
+ .equals( "Escherichia coli (var. K12)" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
+ .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
+ .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
+ return false;
+ }
+ if ( !ParserUtils
+ .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
+ .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
+ .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
+ return false;
+ }
+ if ( !ParserUtils
+ .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
+ .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
+ .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
+ .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
+ .equals( "Macrocera sp." ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
+ .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
+ .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
+ .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
+ .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testExtractTaxonomyDataFromNodeName() {
+ try {
+ PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
+ if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
+ if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
+ if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
+ if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
+ if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode( "HNRPR_HUMAN" );
+ if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode( "HNRPR_HUMAN_X" );
+ if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testExtractTaxonomyCodeFromNodeName() {
+ try {
+ if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "SOYBN" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "ARATH" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "ARATH" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
+ return false;
+ }
+ if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "SOYBN" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "SOYBN" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "SOYBN" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "SOYBN" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
+ .equals( "SOYBN" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "SOYBN" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "SOYBN" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "SOYBN" ) ) {
+ return false;
+ }
+ if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "SOYBN" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
+ .equals( "9YX45" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
+ .equals( "MOUSE" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
+ .equals( "MOUSE" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
+ .equals( "MOUSE" ) ) {
+ return false;
+ }
+ if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
+ return false;
+ }
+ if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
+ return false;
+ }
+ if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
+ return false;
+ }
+ if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
+ TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
+ .equals( "RAT" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
+ .equals( "PIG" ) ) {
+ return false;
+ }
+ if ( !ParserUtils
+ .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
+ .equals( "MOUSE" ) ) {
+ return false;
+ }
+ if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
+ .equals( "MOUSE" ) ) {
+ return false;
+ }
+ if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testExtractUniProtKbProteinSeqIdentifier() {
+ try {
+ PhylogenyNode n = new PhylogenyNode();
+ n.setName( "tr|B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "tr.B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "tr=B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "tr-B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "tr/B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "tr\\B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "tr_B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( " tr|B3RJ64 " );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "-tr|B3RJ64-" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "-tr=B3RJ64-" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "_tr=B3RJ64_" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( " tr_tr|B3RJ64_sp|123 " );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "sp|B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "sp|B3RJ64C" );
+ if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
+ return false;
+ }
+ n.setName( "sp B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n.setName( "sp|B3RJ6X" );
+ if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
+ return false;
+ }
+ n.setName( "sp|B3RJ6" );
+ if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
+ return false;
+ }
+ n.setName( "K1PYK7_CRAGI" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
+ return false;
+ }
+ n.setName( "K1PYK7_PEA" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
+ return false;
+ }
+ n.setName( "K1PYK7_RAT" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
+ return false;
+ }
+ n.setName( "K1PYK7_PIG" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
+ return false;
+ }
+ n.setName( "~K1PYK7_PIG~" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
+ return false;
+ }
+ n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
+ return false;
+ }
+ n.setName( "K1PYKX_CRAGI" );
+ if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
+ return false;
+ }
+ n.setName( "XXXXX_CRAGI" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
+ return false;
+ }
+ n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
+ return false;
+ }
+ n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
+ if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
+ return false;
+ }
+ n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode();
+ org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
+ seq.setSymbol( "K1PYK7_CRAGI" );
+ n.getNodeData().addSequence( seq );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
+ return false;
+ }
+ seq.setSymbol( "tr|B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode();
+ seq = new org.forester.phylogeny.data.Sequence();
+ seq.setName( "K1PYK7_CRAGI" );
+ n.getNodeData().addSequence( seq );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
+ return false;
+ }
+ seq.setName( "tr|B3RJ64" );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode();
+ seq = new org.forester.phylogeny.data.Sequence();
+ seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
+ n.getNodeData().addSequence( seq );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode();
+ seq = new org.forester.phylogeny.data.Sequence();
+ seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
+ n.getNodeData().addSequence( seq );
+ if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
+ return false;
+ }
+ //
+ n = new PhylogenyNode();
+ n.setName( "ACP19736" );
+ if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
+ return false;
+ }
+ n = new PhylogenyNode();
+ n.setName( "|ACP19736|" );
+ if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testFastaParser() {
+ try {
+ FileInputStream fis1 = new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" );
+ if ( !FastaParser.isLikelyFasta( fis1 ) ) {
+ fis1.close();
+ return false;
+ }
+ else {
+ fis1.close();
+ }
+ FileInputStream fis2 = new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" );
+ if ( FastaParser.isLikelyFasta( fis2 ) ) {
+ fis2.close();
+ return false;
+ }
+ else {
+ fis2.close();
+ }
+ final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
+ if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
+ return false;
+ }
+ if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
+ return false;
+ }
+ if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
+ return false;
+ }
+ if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
+ return false;
+ }
+ if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
+ return false;
+ }
+ if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testGenbankAccessorParsing() {
+ //The format for GenBank Accession numbers are:
+ //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
+ //Protein: 3 letters + 5 numerals
+ //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
+ if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
+ return false;
+ }
+ if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
+ return false;
+ }
+ if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
+ return false;
+ }
+ if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
+ return false;
+ }
+ if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
+ return false;
+ }
+ if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
+ return false;
+ }
+ if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
+ return false;
+ }
+ if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
+ return false;
+ }
+ if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
+ return false;
+ }
+ if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
+ return false;
+ }
+ if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
+ return false;
+ }
+ if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
+ return false;
+ }
+ if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
+ return false;
+ }
+ if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testGeneralMsaParser() {
+ try {
+ final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
+ final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
+ final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
+ final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
+ final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
+ final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
+ final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
+ final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
+ if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
+ return false;
+ }
+ if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
+ return false;
+ }
+ if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
+ return false;
+ }
+ if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
+ return false;
+ }
+ if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
+ return false;
+ }
+ if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
+ return false;
+ }
+ if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
+ return false;
+ }
+ if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
+ return false;
+ }
+ if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
+ return false;
+ }
+ if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
+ return false;
+ }
+ if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
+ return false;
+ }
+ if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
+ return false;
+ }
+ final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
+ if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
+ return false;
+ }
+ if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
+ return false;
+ }
+ if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
+ return false;
+ }
+ final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
+ if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
+ return false;
+ }
+ if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
+ return false;
+ }
+ if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
+ return false;
+ }
+ final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
+ if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
+ return false;
+ }
+ if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
+ return false;
+ }
+ if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testGeneralTable() {
+ try {
+ final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
+ t0.setValue( 3, 2, "23" );
+ t0.setValue( 10, 1, "error" );
+ t0.setValue( 10, 1, "110" );
+ t0.setValue( 9, 1, "19" );
+ t0.setValue( 1, 10, "101" );
+ t0.setValue( 10, 10, "1010" );
+ t0.setValue( 100, 10, "10100" );
+ t0.setValue( 0, 0, "00" );
+ if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
+ return false;
+ }
+ if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
+ return false;
+ }
+ if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
+ return false;
+ }
+ if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
+ return false;
+ }
+ if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
+ return false;
+ }
+ if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
+ return false;
+ }
+ if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
+ return false;
+ }
+ if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
+ return false;
+ }
+ if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
+ return false;
+ }
+ final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
+ t1.setValue( "3", "2", "23" );
+ t1.setValue( "10", "1", "error" );
+ t1.setValue( "10", "1", "110" );
+ t1.setValue( "9", "1", "19" );
+ t1.setValue( "1", "10", "101" );
+ t1.setValue( "10", "10", "1010" );
+ t1.setValue( "100", "10", "10100" );
+ t1.setValue( "0", "0", "00" );
+ t1.setValue( "qwerty", "zxcvbnm", "asdef" );
+ if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
+ return false;
+ }
+ if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
+ return false;
+ }
+ if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
+ return false;
+ }
+ if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
+ return false;
+ }
+ if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
+ return false;
+ }
+ if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
+ return false;
+ }
+ if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
+ return false;
+ }
+ if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
+ return false;
+ }
+ if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
+ return false;
+ }
+ if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testGetDistance() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final Phylogeny p1 = factory.create( "(((A:1,B:2,X:100)ab:3,C:4)abc:5,(D:7,(E:9,F:10)ef:8)def:6)r",
+ new NHXParser() )[ 0 ];
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
+ return false;
+ }
+ final Phylogeny p2 = factory.create( "((A:4,B:5,C:6)abc:1,(D:7,E:8,F:9)def:2,(G:10,H:11,I:12)ghi:3)r",
+ new NHXParser() )[ 0 ];
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
+ return false;
+ }
+ if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testGetLCA() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
+ new NHXParser() )[ 0 ];
+ final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
+ if ( !A.getName().equals( "A" ) ) {
+ return false;
+ }
+ final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
+ if ( !gh.getName().equals( "gh" ) ) {
+ return false;
+ }
+ final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
+ if ( !ab.getName().equals( "ab" ) ) {
+ return false;
+ }
+ final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
+ if ( !ab2.getName().equals( "ab" ) ) {
+ return false;
+ }
+ final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
+ if ( !gh2.getName().equals( "gh" ) ) {
+ return false;
+ }
+ final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
+ if ( !gh3.getName().equals( "gh" ) ) {
+ return false;
+ }
+ final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
+ if ( !abc.getName().equals( "abc" ) ) {
+ return false;
+ }
+ final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
+ if ( !abc2.getName().equals( "abc" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
+ if ( !abcd.getName().equals( "abcd" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
+ if ( !abcd2.getName().equals( "abcd" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
+ if ( !abcdef.getName().equals( "abcdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
+ if ( !abcdef2.getName().equals( "abcdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
+ if ( !abcdef3.getName().equals( "abcdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
+ if ( !abcdef4.getName().equals( "abcdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
+ if ( !abcde.getName().equals( "abcde" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
+ if ( !abcde2.getName().equals( "abcde" ) ) {
+ return false;
+ }
+ final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
+ if ( !r.getName().equals( "abcdefgh" ) ) {
+ return false;
+ }
+ final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
+ if ( !r2.getName().equals( "abcdefgh" ) ) {
+ return false;
+ }
+ final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
+ if ( !r3.getName().equals( "abcdefgh" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
+ if ( !abcde3.getName().equals( "abcde" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
+ if ( !abcde4.getName().equals( "abcde" ) ) {
+ return false;
+ }
+ final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
+ if ( !ab3.getName().equals( "ab" ) ) {
+ return false;
+ }
+ final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
+ if ( !ab4.getName().equals( "ab" ) ) {
+ return false;
+ }
+ final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
+ final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
+ if ( !cd.getName().equals( "cd" ) ) {
+ return false;
+ }
+ final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
+ if ( !cd2.getName().equals( "cd" ) ) {
+ return false;
+ }
+ final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
+ if ( !cde.getName().equals( "cde" ) ) {
+ return false;
+ }
+ final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
+ if ( !cde2.getName().equals( "cde" ) ) {
+ return false;
+ }
+ final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
+ if ( !cdef.getName().equals( "cdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
+ if ( !cdef2.getName().equals( "cdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
+ if ( !cdef3.getName().equals( "cdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
+ if ( !rt.getName().equals( "r" ) ) {
+ return false;
+ }
+ final Phylogeny p3 = factory
+ .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
+ new NHXParser() )[ 0 ];
+ final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
+ if ( !bc_3.getName().equals( "bc" ) ) {
+ return false;
+ }
+ final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
+ if ( !ac_3.getName().equals( "abc" ) ) {
+ return false;
+ }
+ final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
+ if ( !ad_3.getName().equals( "abcde" ) ) {
+ return false;
+ }
+ final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
+ if ( !af_3.getName().equals( "abcdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
+ if ( !ag_3.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !ag_3.isRoot() ) {
+ return false;
+ }
+ final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
+ if ( !al_3.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !al_3.isRoot() ) {
+ return false;
+ }
+ final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
+ if ( !kl_3.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !kl_3.isRoot() ) {
+ return false;
+ }
+ final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
+ if ( !fl_3.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !fl_3.isRoot() ) {
+ return false;
+ }
+ final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
+ if ( !gk_3.getName().equals( "ghijk" ) ) {
+ return false;
+ }
+ final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
+ final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
+ if ( !r_4.getName().equals( "r" ) ) {
+ return false;
+ }
+ final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
+ final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
+ if ( !r_5.getName().equals( "root" ) ) {
+ return false;
+ }
+ final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
+ final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
+ if ( !r_6.getName().equals( "rot" ) ) {
+ return false;
+ }
+ final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
+ final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
+ if ( !r_7.getName().equals( "rott" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testGetLCA2() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
+ final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
+ PhylogenyMethods.preOrderReId( p_a );
+ final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
+ p_a.getNode( "a" ) );
+ if ( !p_a_1.getName().equals( "a" ) ) {
+ return false;
+ }
+ final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
+ PhylogenyMethods.preOrderReId( p_b );
+ final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
+ p_b.getNode( "a" ) );
+ if ( !p_b_1.getName().equals( "b" ) ) {
+ return false;
+ }
+ final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
+ p_b.getNode( "b" ) );
+ if ( !p_b_2.getName().equals( "b" ) ) {
+ return false;
+ }
+ final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
+ PhylogenyMethods.preOrderReId( p_c );
+ final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
+ p_c.getNode( "a" ) );
+ if ( !p_c_1.getName().equals( "b" ) ) {
+ return false;
+ }
+ final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
+ p_c.getNode( "c" ) );
+ if ( !p_c_2.getName().equals( "c" ) ) {
+ System.out.println( p_c_2.getName() );
+ System.exit( -1 );
+ return false;
+ }
+ final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
+ p_c.getNode( "b" ) );
+ if ( !p_c_3.getName().equals( "b" ) ) {
+ return false;
+ }
+ final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
+ p_c.getNode( "a" ) );
+ if ( !p_c_4.getName().equals( "c" ) ) {
+ return false;
+ }
+ final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
+ new NHXParser() )[ 0 ];
+ PhylogenyMethods.preOrderReId( p1 );
+ final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
+ p1.getNode( "A" ) );
+ if ( !A.getName().equals( "A" ) ) {
+ return false;
+ }
+ final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
+ p1.getNode( "gh" ) );
+ if ( !gh.getName().equals( "gh" ) ) {
+ return false;
+ }
+ final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
+ p1.getNode( "B" ) );
+ if ( !ab.getName().equals( "ab" ) ) {
+ return false;
+ }
+ final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
+ p1.getNode( "A" ) );
+ if ( !ab2.getName().equals( "ab" ) ) {
+ return false;
+ }
+ final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
+ p1.getNode( "G" ) );
+ if ( !gh2.getName().equals( "gh" ) ) {
+ return false;
+ }
+ final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
+ p1.getNode( "H" ) );
+ if ( !gh3.getName().equals( "gh" ) ) {
+ return false;
+ }
+ final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
+ p1.getNode( "A" ) );
+ if ( !abc.getName().equals( "abc" ) ) {
+ return false;
+ }
+ final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
+ p1.getNode( "C" ) );
+ if ( !abc2.getName().equals( "abc" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
+ p1.getNode( "D" ) );
+ if ( !abcd.getName().equals( "abcd" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
+ p1.getNode( "A" ) );
+ if ( !abcd2.getName().equals( "abcd" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
+ p1.getNode( "F" ) );
+ if ( !abcdef.getName().equals( "abcdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
+ p1.getNode( "A" ) );
+ if ( !abcdef2.getName().equals( "abcdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
+ p1.getNode( "F" ) );
+ if ( !abcdef3.getName().equals( "abcdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
+ p1.getNode( "ab" ) );
+ if ( !abcdef4.getName().equals( "abcdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
+ p1.getNode( "E" ) );
+ if ( !abcde.getName().equals( "abcde" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
+ p1.getNode( "A" ) );
+ if ( !abcde2.getName().equals( "abcde" ) ) {
+ return false;
+ }
+ final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
+ p1.getNode( "abcdefgh" ) );
+ if ( !r.getName().equals( "abcdefgh" ) ) {
+ return false;
+ }
+ final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
+ p1.getNode( "H" ) );
+ if ( !r2.getName().equals( "abcdefgh" ) ) {
+ return false;
+ }
+ final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
+ p1.getNode( "A" ) );
+ if ( !r3.getName().equals( "abcdefgh" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
+ p1.getNode( "abcde" ) );
+ if ( !abcde3.getName().equals( "abcde" ) ) {
+ return false;
+ }
+ final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
+ p1.getNode( "E" ) );
+ if ( !abcde4.getName().equals( "abcde" ) ) {
+ return false;
+ }
+ final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
+ p1.getNode( "B" ) );
+ if ( !ab3.getName().equals( "ab" ) ) {
+ return false;
+ }
+ final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
+ p1.getNode( "ab" ) );
+ if ( !ab4.getName().equals( "ab" ) ) {
+ return false;
+ }
+ final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
+ PhylogenyMethods.preOrderReId( p2 );
+ final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
+ p2.getNode( "d" ) );
+ if ( !cd.getName().equals( "cd" ) ) {
+ return false;
+ }
+ final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
+ p2.getNode( "c" ) );
+ if ( !cd2.getName().equals( "cd" ) ) {
+ return false;
+ }
+ final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
+ p2.getNode( "e" ) );
+ if ( !cde.getName().equals( "cde" ) ) {
+ return false;
+ }
+ final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
+ p2.getNode( "c" ) );
+ if ( !cde2.getName().equals( "cde" ) ) {
+ return false;
+ }
+ final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
+ p2.getNode( "f" ) );
+ if ( !cdef.getName().equals( "cdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
+ p2.getNode( "f" ) );
+ if ( !cdef2.getName().equals( "cdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
+ p2.getNode( "d" ) );
+ if ( !cdef3.getName().equals( "cdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
+ p2.getNode( "a" ) );
+ if ( !rt.getName().equals( "r" ) ) {
+ return false;
+ }
+ final Phylogeny p3 = factory
+ .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
+ new NHXParser() )[ 0 ];
+ PhylogenyMethods.preOrderReId( p3 );
+ final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
+ p3.getNode( "c" ) );
+ if ( !bc_3.getName().equals( "bc" ) ) {
+ return false;
+ }
+ final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
+ p3.getNode( "c" ) );
+ if ( !ac_3.getName().equals( "abc" ) ) {
+ return false;
+ }
+ final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
+ p3.getNode( "d" ) );
+ if ( !ad_3.getName().equals( "abcde" ) ) {
+ return false;
+ }
+ final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
+ p3.getNode( "f" ) );
+ if ( !af_3.getName().equals( "abcdef" ) ) {
+ return false;
+ }
+ final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
+ p3.getNode( "g" ) );
+ if ( !ag_3.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !ag_3.isRoot() ) {
+ return false;
+ }
+ final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
+ p3.getNode( "l" ) );
+ if ( !al_3.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !al_3.isRoot() ) {
+ return false;
+ }
+ final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
+ p3.getNode( "l" ) );
+ if ( !kl_3.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !kl_3.isRoot() ) {
+ return false;
+ }
+ final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
+ p3.getNode( "l" ) );
+ if ( !fl_3.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !fl_3.isRoot() ) {
+ return false;
+ }
+ final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
+ p3.getNode( "k" ) );
+ if ( !gk_3.getName().equals( "ghijk" ) ) {
+ return false;
+ }
+ final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
+ PhylogenyMethods.preOrderReId( p4 );
+ final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
+ p4.getNode( "c" ) );
+ if ( !r_4.getName().equals( "r" ) ) {
+ return false;
+ }
+ final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
+ PhylogenyMethods.preOrderReId( p5 );
+ final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
+ p5.getNode( "c" ) );
+ if ( !r_5.getName().equals( "root" ) ) {
+ return false;
+ }
+ final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
+ PhylogenyMethods.preOrderReId( p6 );
+ final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
+ p6.getNode( "a" ) );
+ if ( !r_6.getName().equals( "rot" ) ) {
+ return false;
+ }
+ final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
+ PhylogenyMethods.preOrderReId( p7 );
+ final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
+ p7.getNode( "e" ) );
+ if ( !r_7.getName().equals( "rott" ) ) {
+ return false;
+ }
+ final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
+ p7.getNode( "a" ) );
+ if ( !r_71.getName().equals( "rott" ) ) {
+ return false;
+ }
+ final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
+ p7.getNode( "rott" ) );
+ if ( !r_72.getName().equals( "rott" ) ) {
+ return false;
+ }
+ final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
+ p7.getNode( "a" ) );
+ if ( !r_73.getName().equals( "rott" ) ) {
+ return false;
+ }
+ final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
+ p7.getNode( "rott" ) );
+ if ( !r_74.getName().equals( "rott" ) ) {
+ return false;
+ }
+ final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
+ p7.getNode( "e" ) );
+ if ( !r_75.getName().equals( "e" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testHmmscanOutputParser() {
+ final String test_dir = Test.PATH_TO_TEST_DATA;
+ try {
+ final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
+ + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
+ parser1.parse();
+ final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
+ + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
+ final List<Protein> proteins = parser2.parse();
+ if ( parser2.getProteinsEncountered() != 4 ) {
+ return false;
+ }
+ if ( proteins.size() != 4 ) {
+ return false;
+ }
+ if ( parser2.getDomainsEncountered() != 69 ) {
+ return false;
+ }
+ if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
+ return false;
+ }
+ if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
+ return false;
+ }
+ if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
+ return false;
+ }
+ final Protein p1 = proteins.get( 0 );
+ if ( p1.getNumberOfProteinDomains() != 15 ) {
+ return false;
+ }
+ if ( p1.getLength() != 850 ) {
+ return false;
+ }
+ final Protein p2 = proteins.get( 1 );
+ if ( p2.getNumberOfProteinDomains() != 51 ) {
+ return false;
+ }
+ if ( p2.getLength() != 1291 ) {
+ return false;
+ }
+ final Protein p3 = proteins.get( 2 );
+ if ( p3.getNumberOfProteinDomains() != 2 ) {
+ return false;
+ }
+ final Protein p4 = proteins.get( 3 );
+ if ( p4.getNumberOfProteinDomains() != 1 ) {
+ return false;
+ }
+ if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
+ return false;
+ }
+ if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
+ return false;
+ }
+ if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
+ return false;
+ }
+ if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
+ return false;
+ }
+ if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testLastExternalNodeMethods() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
+ final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
+ final PhylogenyNode n1 = t0.getNode( "A" );
+ if ( n1.isLastExternalNode() ) {
+ return false;
+ }
+ final PhylogenyNode n2 = t0.getNode( "B" );
+ if ( n2.isLastExternalNode() ) {
+ return false;
+ }
+ final PhylogenyNode n3 = t0.getNode( "C" );
+ if ( n3.isLastExternalNode() ) {
+ return false;
+ }
+ final PhylogenyNode n4 = t0.getNode( "D" );
+ if ( !n4.isLastExternalNode() ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testLevelOrderIterator() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
+ PhylogenyNodeIterator it0;
+ for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
+ it0.next();
+ }
+ for( it0.reset(); it0.hasNext(); ) {
+ it0.next();
+ }
+ final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
+ if ( !it.next().getName().equals( "r" ) ) {
+ return false;
+ }
+ if ( !it.next().getName().equals( "ab" ) ) {
+ return false;
+ }
+ if ( !it.next().getName().equals( "cd" ) ) {
+ return false;
+ }
+ if ( !it.next().getName().equals( "A" ) ) {
+ return false;
+ }
+ if ( !it.next().getName().equals( "B" ) ) {
+ return false;
+ }
+ if ( !it.next().getName().equals( "C" ) ) {
+ return false;
+ }
+ if ( !it.next().getName().equals( "D" ) ) {
+ return false;
+ }
+ if ( it.hasNext() ) {
+ return false;
+ }
+ final Phylogeny t2 = factory.create( "(((1,2,(a,(X,Y,Z)b)3,4,5,6)A,B,C)abc,(D,E,(f1,(f21)f2,f3)F,G)defg)r",
+ new NHXParser() )[ 0 ];
+ PhylogenyNodeIterator it2;
+ for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
+ it2.next();
+ }
+ for( it2.reset(); it2.hasNext(); ) {
+ it2.next();
+ }
+ final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
+ if ( !it3.next().getName().equals( "r" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "abc" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "defg" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "A" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "B" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "C" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "D" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "E" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "F" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "G" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "1" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "2" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "3" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "4" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "5" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "6" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "f1" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "f2" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "f3" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "a" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "b" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "f21" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "X" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "Y" ) ) {
+ return false;
+ }
+ if ( !it3.next().getName().equals( "Z" ) ) {
+ return false;
+ }
+ if ( it3.hasNext() ) {
+ return false;
+ }
+ final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
+ PhylogenyNodeIterator it4;
+ for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
+ it4.next();
+ }
+ for( it4.reset(); it4.hasNext(); ) {
+ it4.next();
+ }
+ final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
+ if ( !it5.next().getName().equals( "r" ) ) {
+ return false;
+ }
+ if ( !it5.next().getName().equals( "A" ) ) {
+ return false;
+ }
+ if ( !it5.next().getName().equals( "B" ) ) {
+ return false;
+ }
+ if ( !it5.next().getName().equals( "C" ) ) {
+ return false;
+ }
+ if ( !it5.next().getName().equals( "D" ) ) {
+ return false;
+ }
+ final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
+ PhylogenyNodeIterator it6;
+ for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
+ it6.next();
+ }
+ for( it6.reset(); it6.hasNext(); ) {
+ it6.next();
+ }
+ final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
+ if ( !it7.next().getName().equals( "A" ) ) {
+ return false;
+ }
+ if ( it.hasNext() ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testMafft( final String path ) {
+ try {
+ final List<String> opts = new ArrayList<String>();
+ opts.add( "--maxiterate" );
+ opts.add( "1000" );
+ opts.add( "--localpair" );
+ opts.add( "--quiet" );
+ Msa msa = null;
+ final MsaInferrer mafft = Mafft.createInstance( path );
+ msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
+ if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
+ return false;
+ }
+ if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testMidpointrooting() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
+ PhylogenyMethods.midpointRoot( t0 );
+ if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
+ return false;
+ }
+ if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
+ return false;
+ }
+ if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
+ 1 ) ) {
+ return false;
+ }
+ final Phylogeny t1 = factory.create( "((A:1,B:2)AB:1[&&NHX:B=55],(C:3,D:4)CD:3[&&NHX:B=10])ABCD:0.5",
+ new NHXParser() )[ 0 ];
+ if ( !t1.isRooted() ) {
+ return false;
+ }
+ PhylogenyMethods.midpointRoot( t1 );
+ if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
+ return false;
+ }
+ if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
+ return false;
+ }
+ if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
+ return false;
+ }
+ if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
+ return false;
+ }
+ if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
+ return false;
+ }
+ if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
+ return false;
+ }
+ t1.reRoot( t1.getNode( "A" ) );
+ PhylogenyMethods.midpointRoot( t1 );
+ if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
+ return false;
+ }
+ if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
+ return false;
+ }
+ if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
+ return false;
+ }
+ if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
+ return false;
+ }
+ if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
+ System.exit( -1 );
+ return false;
+ }
+ if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testMsaQualityMethod() {
+ try {
+ final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
+ final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
+ final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
+ final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
+ final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
+ l.add( s0 );
+ l.add( s1 );
+ l.add( s2 );
+ l.add( s3 );
+ final Msa msa = BasicMsa.createInstance( l );
+ if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testMsaEntropy() {
+ try {
+ final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
+ final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
+ final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
+ final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
+ final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
+ l.add( s0 );
+ l.add( s1 );
+ l.add( s2 );
+ l.add( s3 );
+ final Msa msa = BasicMsa.createInstance( l );
+ //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ //FIXME
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
+ // System.out.println();
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
+ final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
+ l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
+ l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
+ l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
+ l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
+ l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
+ l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
+ l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
+ l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
+ l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
+ l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
+ l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
+ l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
+ l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
+ l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
+ l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
+ l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
+ l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
+ l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
+ l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
+ l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
+ l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
+ l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
+ final Msa msa2 = BasicMsa.createInstance( l2 );
+ // System.out.println();
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
+ // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testDeleteableMsa() {
+ try {
+ final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
+ final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
+ final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
+ final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
+ final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
+ final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
+ final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
+ l0.add( s0 );
+ l0.add( s1 );
+ l0.add( s2 );
+ l0.add( s3 );
+ l0.add( s4 );
+ l0.add( s5 );
+ final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
+ dmsa0.deleteRow( "b", false );
+ if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
+ return false;
+ }
+ dmsa0.deleteRow( "e", false );
+ dmsa0.deleteRow( "a", false );
+ dmsa0.deleteRow( "f", false );
+ if ( dmsa0.getLength() != 4 ) {
+ return false;
+ }
+ if ( dmsa0.getNumberOfSequences() != 2 ) {
+ return false;
+ }
+ if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
+ return false;
+ }
+ if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
+ return false;
+ }
+ if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
+ return false;
+ }
+ if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
+ return false;
+ }
+ if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
+ return false;
+ }
+ dmsa0.deleteRow( "c", false );
+ dmsa0.deleteRow( "d", false );
+ if ( dmsa0.getNumberOfSequences() != 0 ) {
+ return false;
+ }
+ //
+ final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
+ final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
+ final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
+ final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
+ final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
+ final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
+ final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
+ l1.add( s_0 );
+ l1.add( s_1 );
+ l1.add( s_2 );
+ l1.add( s_3 );
+ l1.add( s_4 );
+ l1.add( s_5 );
+ final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
+ dmsa1.deleteGapOnlyColumns();
+ dmsa1.deleteRow( "a", false );
+ dmsa1.deleteRow( "f", false );
+ dmsa1.deleteRow( "d", false );
+ dmsa1.deleteGapOnlyColumns();
+ if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
+ return false;
+ }
+ if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
+ return false;
+ }
+ if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
+ return false;
+ }
+ dmsa1.deleteRow( "c", false );
+ dmsa1.deleteGapOnlyColumns();
+ final Writer w0 = new StringWriter();
+ dmsa1.write( w0, MSA_FORMAT.FASTA );
+ final Writer w1 = new StringWriter();
+ dmsa1.write( w1, MSA_FORMAT.PHYLIP );
+ if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
+ return false;
+ }
+ if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
+ return false;
+ }
+ final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
+ final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
+ final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
+ final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
+ final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
+ final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
+ final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
+ l2.add( s__0 );
+ l2.add( s__1 );
+ l2.add( s__2 );
+ l2.add( s__3 );
+ l2.add( s__4 );
+ l2.add( s__5 );
+ final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
+ dmsa2.deleteGapColumns( 0.5 );
+ if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
+ return false;
+ }
+ if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
+ return false;
+ }
+ if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
+ return false;
+ }
+ dmsa2.deleteGapColumns( 0.2 );
+ if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
+ return false;
+ }
+ if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
+ return false;
+ }
+ if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
+ return false;
+ }
+ dmsa2.deleteGapColumns( 0 );
+ dmsa2.deleteRow( "a", false );
+ dmsa2.deleteRow( "b", false );
+ dmsa2.deleteRow( "f", false );
+ dmsa2.deleteRow( "e", false );
+ dmsa2.setIdentifier( 0, "new_c" );
+ dmsa2.setIdentifier( 1, "new_d" );
+ dmsa2.setResidueAt( 0, 0, 'x' );
+ final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
+ if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
+ return false;
+ }
+ final Writer w = new StringWriter();
+ dmsa2.write( w, MSA_FORMAT.PHYLIP );
+ final String phylip = w.toString();
+ if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
+ System.out.println( phylip );
+ return false;
+ }
+ final Writer w2 = new StringWriter();
+ dmsa2.write( w2, MSA_FORMAT.FASTA );
+ final String fasta = w2.toString();
+ if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
+ System.out.println( fasta );
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testNextNodeWithCollapsing() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ PhylogenyNode n;
+ List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
+ final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
+ final Phylogeny t0 = factory.create( sb0.toString(), new NHXParser() )[ 0 ];
+ t0.getNode( "cd" ).setCollapse( true );
+ t0.getNode( "cde" ).setCollapse( true );
+ n = t0.getFirstExternalNode();
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( !ext.get( 0 ).getName().equals( "a" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "b" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
+ return false;
+ }
+ if ( !ext.get( 3 ).getName().equals( "f" ) ) {
+ return false;
+ }
+ if ( !ext.get( 4 ).getName().equals( "g" ) ) {
+ return false;
+ }
+ if ( !ext.get( 5 ).getName().equals( "h" ) ) {
+ return false;
+ }
+ ext.clear();
+ final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
+ final Phylogeny t1 = factory.create( sb1.toString(), new NHXParser() )[ 0 ];
+ t1.getNode( "ab" ).setCollapse( true );
+ t1.getNode( "cd" ).setCollapse( true );
+ t1.getNode( "cde" ).setCollapse( true );
+ n = t1.getNode( "ab" );
+ ext = new ArrayList<PhylogenyNode>();
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "f" ) ) {
+ return false;
+ }
+ if ( !ext.get( 3 ).getName().equals( "g" ) ) {
+ return false;
+ }
+ if ( !ext.get( 4 ).getName().equals( "h" ) ) {
+ return false;
+ }
+ ext.clear();
+ final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t2 = factory.create( sb2.toString(), new NHXParser() )[ 0 ];
+ t2.getNode( "ab" ).setCollapse( true );
+ t2.getNode( "cd" ).setCollapse( true );
+ t2.getNode( "cde" ).setCollapse( true );
+ t2.getNode( "c" ).setCollapse( true );
+ t2.getNode( "d" ).setCollapse( true );
+ t2.getNode( "e" ).setCollapse( true );
+ t2.getNode( "gh" ).setCollapse( true );
+ n = t2.getNode( "ab" );
+ ext = new ArrayList<PhylogenyNode>();
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "f" ) ) {
+ return false;
+ }
+ if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
+ return false;
+ }
+ ext.clear();
+ final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t3 = factory.create( sb3.toString(), new NHXParser() )[ 0 ];
+ t3.getNode( "ab" ).setCollapse( true );
+ t3.getNode( "cd" ).setCollapse( true );
+ t3.getNode( "cde" ).setCollapse( true );
+ t3.getNode( "c" ).setCollapse( true );
+ t3.getNode( "d" ).setCollapse( true );
+ t3.getNode( "e" ).setCollapse( true );
+ t3.getNode( "gh" ).setCollapse( true );
+ t3.getNode( "fgh" ).setCollapse( true );
+ n = t3.getNode( "ab" );
+ ext = new ArrayList<PhylogenyNode>();
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
+ return false;
+ }
+ ext.clear();
+ final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t4 = factory.create( sb4.toString(), new NHXParser() )[ 0 ];
+ t4.getNode( "ab" ).setCollapse( true );
+ t4.getNode( "cd" ).setCollapse( true );
+ t4.getNode( "cde" ).setCollapse( true );
+ t4.getNode( "c" ).setCollapse( true );
+ t4.getNode( "d" ).setCollapse( true );
+ t4.getNode( "e" ).setCollapse( true );
+ t4.getNode( "gh" ).setCollapse( true );
+ t4.getNode( "fgh" ).setCollapse( true );
+ t4.getNode( "abcdefgh" ).setCollapse( true );
+ n = t4.getNode( "abcdefgh" );
+ if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
+ return false;
+ }
+ final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
+ final Phylogeny t5 = factory.create( sb5.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ n = t5.getFirstExternalNode();
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 8 ) {
+ return false;
+ }
+ if ( !ext.get( 0 ).getName().equals( "a" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "b" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "c" ) ) {
+ return false;
+ }
+ if ( !ext.get( 3 ).getName().equals( "d" ) ) {
+ return false;
+ }
+ if ( !ext.get( 4 ).getName().equals( "e" ) ) {
+ return false;
+ }
+ if ( !ext.get( 5 ).getName().equals( "f" ) ) {
+ return false;
+ }
+ if ( !ext.get( 6 ).getName().equals( "g" ) ) {
+ return false;
+ }
+ if ( !ext.get( 7 ).getName().equals( "h" ) ) {
+ return false;
+ }
+ final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
+ final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t6.getNode( "ab" ).setCollapse( true );
+ n = t6.getNode( "ab" );
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 7 ) {
+ return false;
+ }
+ if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "c" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "d" ) ) {
+ return false;
+ }
+ if ( !ext.get( 3 ).getName().equals( "e" ) ) {
+ return false;
+ }
+ if ( !ext.get( 4 ).getName().equals( "f" ) ) {
+ return false;
+ }
+ if ( !ext.get( 5 ).getName().equals( "g" ) ) {
+ return false;
+ }
+ if ( !ext.get( 6 ).getName().equals( "h" ) ) {
+ return false;
+ }
+ final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
+ final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t7.getNode( "cd" ).setCollapse( true );
+ n = t7.getNode( "a" );
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 7 ) {
+ return false;
+ }
+ if ( !ext.get( 0 ).getName().equals( "a" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "b" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
+ return false;
+ }
+ if ( !ext.get( 3 ).getName().equals( "e" ) ) {
+ return false;
+ }
+ if ( !ext.get( 4 ).getName().equals( "f" ) ) {
+ return false;
+ }
+ if ( !ext.get( 5 ).getName().equals( "g" ) ) {
+ return false;
+ }
+ if ( !ext.get( 6 ).getName().equals( "h" ) ) {
+ return false;
+ }
+ final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
+ final Phylogeny t8 = factory.create( sb8.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t8.getNode( "cd" ).setCollapse( true );
+ t8.getNode( "c" ).setCollapse( true );
+ t8.getNode( "d" ).setCollapse( true );
+ n = t8.getNode( "a" );
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 7 ) {
+ return false;
+ }
+ if ( !ext.get( 0 ).getName().equals( "a" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "b" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
+ System.out.println( "2 fail" );
+ return false;
+ }
+ if ( !ext.get( 3 ).getName().equals( "e" ) ) {
+ return false;
+ }
+ if ( !ext.get( 4 ).getName().equals( "f" ) ) {
+ return false;
+ }
+ if ( !ext.get( 5 ).getName().equals( "g" ) ) {
+ return false;
+ }
+ if ( !ext.get( 6 ).getName().equals( "h" ) ) {
+ return false;
+ }
+ final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t9 = factory.create( sb9.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t9.getNode( "gh" ).setCollapse( true );
+ n = t9.getNode( "a" );
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 7 ) {
+ return false;
+ }
+ if ( !ext.get( 0 ).getName().equals( "a" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "b" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "c" ) ) {
+ return false;
+ }
+ if ( !ext.get( 3 ).getName().equals( "d" ) ) {
+ return false;
+ }
+ if ( !ext.get( 4 ).getName().equals( "e" ) ) {
+ return false;
+ }
+ if ( !ext.get( 5 ).getName().equals( "f" ) ) {
+ return false;
+ }
+ if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
+ return false;
+ }
+ final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t10 = factory.create( sb10.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t10.getNode( "gh" ).setCollapse( true );
+ t10.getNode( "g" ).setCollapse( true );
+ t10.getNode( "h" ).setCollapse( true );
+ n = t10.getNode( "a" );
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 7 ) {
+ return false;
+ }
+ if ( !ext.get( 0 ).getName().equals( "a" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "b" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "c" ) ) {
+ return false;
+ }
+ if ( !ext.get( 3 ).getName().equals( "d" ) ) {
+ return false;
+ }
+ if ( !ext.get( 4 ).getName().equals( "e" ) ) {
+ return false;
+ }
+ if ( !ext.get( 5 ).getName().equals( "f" ) ) {
+ return false;
+ }
+ if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
+ return false;
+ }
+ final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t11 = factory.create( sb11.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t11.getNode( "gh" ).setCollapse( true );
+ t11.getNode( "fgh" ).setCollapse( true );
+ n = t11.getNode( "a" );
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 6 ) {
+ return false;
+ }
+ if ( !ext.get( 0 ).getName().equals( "a" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "b" ) ) {