+ 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" ) ) {
+ 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( "fgh" ) ) {
+ return false;
+ }
+ final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t12 = factory.create( sb12.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t12.getNode( "gh" ).setCollapse( true );
+ t12.getNode( "fgh" ).setCollapse( true );
+ t12.getNode( "g" ).setCollapse( true );
+ t12.getNode( "h" ).setCollapse( true );
+ t12.getNode( "f" ).setCollapse( true );
+ n = t12.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" ) ) {
+ 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( "fgh" ) ) {
+ return false;
+ }
+ final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t13 = factory.create( sb13.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t13.getNode( "ab" ).setCollapse( true );
+ t13.getNode( "b" ).setCollapse( true );
+ t13.getNode( "fgh" ).setCollapse( true );
+ t13.getNode( "gh" ).setCollapse( true );
+ n = t13.getNode( "ab" );
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 5 ) {
+ 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( "fgh" ) ) {
+ return false;
+ }
+ final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t14 = factory.create( sb14.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t14.getNode( "ab" ).setCollapse( true );
+ t14.getNode( "a" ).setCollapse( true );
+ t14.getNode( "fgh" ).setCollapse( true );
+ t14.getNode( "gh" ).setCollapse( true );
+ n = t14.getNode( "ab" );
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 5 ) {
+ 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( "fgh" ) ) {
+ return false;
+ }
+ final StringBuffer sb15 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,x,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t15 = factory.create( sb15.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t15.getNode( "ab" ).setCollapse( true );
+ t15.getNode( "a" ).setCollapse( true );
+ t15.getNode( "fgh" ).setCollapse( true );
+ t15.getNode( "gh" ).setCollapse( true );
+ n = t15.getNode( "ab" );
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 6 ) {
+ 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( "x" ) ) {
+ return false;
+ }
+ if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
+ return false;
+ }
+ //
+ //
+ final StringBuffer sb16 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,x,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
+ final Phylogeny t16 = factory.create( sb16.toString(), new NHXParser() )[ 0 ];
+ ext.clear();
+ t16.getNode( "ab" ).setCollapse( true );
+ t16.getNode( "a" ).setCollapse( true );
+ t16.getNode( "fgh" ).setCollapse( true );
+ t16.getNode( "gh" ).setCollapse( true );
+ t16.getNode( "cd" ).setCollapse( true );
+ t16.getNode( "cde" ).setCollapse( true );
+ t16.getNode( "d" ).setCollapse( true );
+ t16.getNode( "x" ).setCollapse( true );
+ n = t16.getNode( "ab" );
+ while ( n != null ) {
+ ext.add( n );
+ n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
+ }
+ if ( ext.size() != 4 ) {
+ return false;
+ }
+ if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
+ return false;
+ }
+ if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
+ return false;
+ }
+ if ( !ext.get( 2 ).getName().equals( "x" ) ) {
+ return false;
+ }
+ if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testNexusCharactersParsing() {
+ try {
+ final NexusCharactersParser parser = new NexusCharactersParser();
+ parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
+ parser.parse();
+ String[] labels = parser.getCharStateLabels();
+ if ( labels.length != 7 ) {
+ return false;
+ }
+ if ( !labels[ 0 ].equals( "14-3-3" ) ) {
+ return false;
+ }
+ if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
+ return false;
+ }
+ if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
+ return false;
+ }
+ if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
+ return false;
+ }
+ if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
+ return false;
+ }
+ if ( !labels[ 5 ].equals( "3-HAO" ) ) {
+ return false;
+ }
+ if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
+ return false;
+ }
+ parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
+ parser.parse();
+ labels = parser.getCharStateLabels();
+ if ( labels.length != 7 ) {
+ return false;
+ }
+ if ( !labels[ 0 ].equals( "14-3-3" ) ) {
+ return false;
+ }
+ if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
+ return false;
+ }
+ if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
+ return false;
+ }
+ if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
+ return false;
+ }
+ if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
+ return false;
+ }
+ if ( !labels[ 5 ].equals( "3-HAO" ) ) {
+ return false;
+ }
+ if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testNexusMatrixParsing() {
+ try {
+ final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
+ parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
+ parser.parse();
+ final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
+ if ( m.getNumberOfCharacters() != 9 ) {
+ return false;
+ }
+ if ( m.getNumberOfIdentifiers() != 5 ) {
+ return false;
+ }
+ if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
+ return false;
+ }
+ if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
+ return false;
+ }
+ if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
+ return false;
+ }
+ if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
+ return false;
+ }
+ if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
+ return false;
+ }
+ if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
+ return false;
+ }
+ if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
+ return false;
+ }
+ // if ( labels.length != 7 ) {
+ // return false;
+ // }
+ // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
+ // return false;
+ // }
+ // parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
+ // parser.parse();
+ // labels = parser.getCharStateLabels();
+ // if ( labels.length != 7 ) {
+ // return false;
+ // }
+ // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
+ // return false;
+ // }
+ // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
+ // return false;
+ // }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testNexusTreeParsing() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
+ Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
+ if ( phylogenies.length != 1 ) {
+ return false;
+ }
+ if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
+ return false;
+ }
+ phylogenies = null;
+ phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
+ if ( phylogenies.length != 1 ) {
+ return false;
+ }
+ if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
+ return false;
+ }
+ phylogenies = null;
+ phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
+ if ( phylogenies.length != 1 ) {
+ return false;
+ }
+ if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 0 ].isRooted() ) {
+ return false;
+ }
+ phylogenies = null;
+ phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
+ if ( phylogenies.length != 18 ) {
+ return false;
+ }
+ if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 8 ].isRooted() ) {
+ return false;
+ }
+ if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 9 ].isRooted() ) {
+ return false;
+ }
+ if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 10 ].isRooted() ) {
+ return false;
+ }
+ if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 11 ].isRooted() ) {
+ return false;
+ }
+ if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 12 ].isRooted() ) {
+ return false;
+ }
+ if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 13 ].isRooted() ) {
+ return false;
+ }
+ if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 14 ].isRooted() ) {
+ return false;
+ }
+ if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 15 ].isRooted() ) {
+ return false;
+ }
+ if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 16 ].isRooted() ) {
+ return false;
+ }
+ if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 17 ].isRooted() ) {
+ return false;
+ }
+ if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
+ phylogenies = null;
+ phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
+ if ( phylogenies.length != 9 ) {
+ return false;
+ }
+ if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
+ .getDistanceToParent() ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
+ .getDistanceToParent() ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testNexusTreeParsingIterating() {
+ try {
+ final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
+ p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ Phylogeny phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 25 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy != null ) {
+ return false;
+ }
+ p.reset();
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 25 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy != null ) {
+ return false;
+ }
+ p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "name" ) ) {
+ return false;
+ }
+ if ( p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy != null ) {
+ return false;
+ }
+ p.reset();
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "name" ) ) {
+ return false;
+ }
+ if ( p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy != null ) {
+ return false;
+ }
+ p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( phy.isRooted() ) {
+ return false;
+ }
+ if ( p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy != null ) {
+ return false;
+ }
+ //
+ p.reset();
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy != null ) {
+ return false;
+ }
+ //
+ p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ //0
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 0" ) ) {
+ return false;
+ }
+ //1
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 1" ) ) {
+ return false;
+ }
+ //2
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ System.out.println( phy.toString() );
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( phy.isRooted() ) {
+ return false;
+ }
+ //3
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 4 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //4
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 5 ) {
+ System.out.println( phy.getNumberOfExternalNodes() );
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //5
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( phy.isRooted() ) {
+ return false;
+ }
+ //6
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 2 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //7
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //8
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 8" ) ) {
+ return false;
+ }
+ //9
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 9" ) ) {
+ return false;
+ }
+ //10
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 10" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //11
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 11" ) ) {
+ return false;
+ }
+ if ( phy.isRooted() ) {
+ return false;
+ }
+ //12
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 12" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //13
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 13" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //14
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 10 ) {
+ System.out.println( phy.getNumberOfExternalNodes() );
+ return false;
+ }
+ if ( !phy
+ .toNewHampshire()
+ .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
+ System.out.println( phy.toNewHampshire() );
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 14" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //15
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 10 ) {
+ System.out.println( phy.getNumberOfExternalNodes() );
+ return false;
+ }
+ if ( !phy
+ .toNewHampshire()
+ .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
+ System.out.println( phy.toNewHampshire() );
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 15" ) ) {
+ return false;
+ }
+ if ( phy.isRooted() ) {
+ return false;
+ }
+ //16
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 10 ) {
+ System.out.println( phy.getNumberOfExternalNodes() );
+ return false;
+ }
+ if ( !phy
+ .toNewHampshire()
+ .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
+ System.out.println( phy.toNewHampshire() );
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 16" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //17
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy.getNumberOfExternalNodes() != 10 ) {
+ System.out.println( phy.getNumberOfExternalNodes() );
+ return false;
+ }
+ if ( !phy
+ .toNewHampshire()
+ .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
+ System.out.println( phy.toNewHampshire() );
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 17" ) ) {
+ return false;
+ }
+ if ( phy.isRooted() ) {
+ return false;
+ }
+ //
+ if ( p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy != null ) {
+ return false;
+ }
+ p.reset();
+ //0
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 0" ) ) {
+ return false;
+ }
+ //1
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 10 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "tree 1" ) ) {
+ return false;
+ }
+ //2
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( phy.isRooted() ) {
+ return false;
+ }
+ //3
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 4 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //4
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 5 ) {
+ System.out.println( phy.getNumberOfExternalNodes() );
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( !phy.isRooted() ) {
+ return false;
+ }
+ //5
+ if ( !p.hasNext() ) {
+ return false;
+ }
+ phy = p.next();
+ if ( phy == null ) {
+ return false;
+ }
+ if ( phy.getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phy.getName().equals( "" ) ) {
+ return false;
+ }
+ if ( phy.isRooted() ) {
+ return false;
+ }
+ //
+ final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
+ p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
+ // 0
+ if ( !p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
+ return false;
+ }
+ // 1
+ if ( !p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ // 2
+ if ( !p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ // 3
+ if ( !p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ // 4
+ if ( !p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ // 5
+ if ( !p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ // 6
+ if ( !p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ // 7
+ if ( !p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ // 8
+ if ( !p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
+ return false;
+ }
+ if ( p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ if ( phy != null ) {
+ return false;
+ }
+ // 0
+ p2.reset();
+ if ( !p2.hasNext() ) {
+ return false;
+ }
+ phy = p2.next();
+ if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
+ return false;
+ }
+ if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testNexusTreeParsingTranslating() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
+ Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
+ if ( phylogenies.length != 1 ) {
+ return false;
+ }
+ if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
+ .equals( "Aranaeus" ) ) {
+ return false;
+ }
+ phylogenies = null;
+ phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
+ if ( phylogenies.length != 3 ) {
+ return false;
+ }
+ if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 0 ].isRooted() ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
+ .equals( "Aranaeus" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 1 ].isRooted() ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
+ .equals( "Aranaeus" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].isRooted() ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
+ .equals( "Aranaeus" ) ) {
+ return false;
+ }
+ phylogenies = null;
+ phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
+ if ( phylogenies.length != 3 ) {
+ return false;
+ }
+ if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 0 ].isRooted() ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
+ .equals( "Aranaeus" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 1 ].isRooted() ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
+ .equals( "Aranaeus" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].isRooted() ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
+ .equals( "Aranaeus" ) ) {
+ return false;
+ }
+ phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
+ if ( phylogenies.length != 3 ) {
+ return false;
+ }
+ if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
+ 0.00100049 ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testNHParsing() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
+ if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
+ return false;
+ }
+ final NHXParser nhxp = new NHXParser();
+ nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
+ nhxp.setReplaceUnderscores( true );
+ final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
+ if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
+ return false;
+ }
+ if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
+ return false;
+ }
+ final Phylogeny p1b = factory
+ .create( " \n \t \b \r \f ; ( \n \t \b \r \f; A ; \n \t \b \r \f, \n \t \b \r \f; B ; \n \t \b \r \f 1 \n \t \b \r \f ; \n \t \b \r \f );;;;; \n \t \b \r \f;;; \n \t \b \r \f ",
+ new NHXParser() )[ 0 ];
+ if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
+ return false;
+ }
+ if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
+ return false;
+ }
+ final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ).toString(), new NHXParser() )[ 0 ];
+ final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
+ final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
+ final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ).toString(), new NHXParser() )[ 0 ];
+ final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
+ final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
+ final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
+ final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
+ final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
+ final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
+ final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
+ + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
+ + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
+ new NHXParser() );
+ if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
+ return false;
+ }
+ if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
+ return false;
+ }
+ if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
+ return false;
+ }
+ if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
+ return false;
+ }
+ final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
+ final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
+ final String p16_S = "((A,B),C)";
+ final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
+ if ( p16.length != 1 ) {
+ return false;
+ }
+ if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
+ return false;
+ }
+ final String p17_S = "(C,(A,B))";
+ final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
+ if ( p17.length != 1 ) {
+ return false;
+ }
+ if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
+ return false;
+ }
+ final String p18_S = "((A,B),(C,D))";
+ final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
+ if ( p18.length != 1 ) {
+ return false;
+ }
+ if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
+ return false;
+ }
+ final String p19_S = "(((A,B),C),D)";
+ final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
+ if ( p19.length != 1 ) {
+ return false;
+ }
+ if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
+ return false;
+ }
+ final String p20_S = "(A,(B,(C,D)))";
+ final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
+ if ( p20.length != 1 ) {
+ return false;
+ }
+ if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
+ return false;
+ }
+ final String p21_S = "(A,(B,(C,(D,E))))";
+ final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
+ if ( p21.length != 1 ) {
+ return false;
+ }
+ if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
+ return false;
+ }
+ final String p22_S = "((((A,B),C),D),E)";
+ final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
+ if ( p22.length != 1 ) {
+ return false;
+ }
+ if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
+ return false;
+ }
+ final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
+ final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
+ if ( p23.length != 1 ) {
+ System.out.println( "xl=" + p23.length );
+ System.exit( -1 );
+ return false;
+ }
+ if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
+ return false;
+ }
+ final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
+ final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
+ if ( p24.length != 1 ) {
+ return false;
+ }
+ if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
+ return false;
+ }
+ final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
+ final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
+ final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
+ if ( p241.length != 2 ) {
+ return false;
+ }
+ if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
+ return false;
+ }
+ if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
+ return false;
+ }
+ final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
+ + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
+ + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
+ + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
+ + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
+ + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
+ + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
+ + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
+ final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
+ if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
+ return false;
+ }
+ final String p26_S = "(A,B)ab";
+ final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
+ if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
+ return false;
+ }
+ final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
+ final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
+ if ( p27s.length != 1 ) {
+ System.out.println( "xxl=" + p27s.length );
+ System.exit( -1 );
+ return false;
+ }
+ if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
+ System.out.println( p27s[ 0 ].toNewHampshireX() );
+ System.exit( -1 );
+ return false;
+ }
+ final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
+ new NHXParser() );
+ if ( p27.length != 1 ) {
+ System.out.println( "yl=" + p27.length );
+ System.exit( -1 );
+ return false;
+ }
+ if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
+ System.out.println( p27[ 0 ].toNewHampshireX() );
+ System.exit( -1 );
+ return false;
+ }
+ final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
+ final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
+ final String p28_S3 = "(A,B)ab";
+ final String p28_S4 = "((((A,B),C),D),;E;)";
+ final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
+ new NHXParser() );
+ if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
+ return false;
+ }
+ if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
+ return false;
+ }
+ if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
+ return false;
+ }
+ if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
+ return false;
+ }
+ if ( p28.length != 4 ) {
+ return false;
+ }
+ final String p29_S = "((((A:0.01,B:0.684)ab:0.345,C:0.3451)abc:0.3451,D:1.5)abcd:0.134,E:0.32)abcde:0.1345";
+ final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
+ if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
+ return false;
+ }
+ final String p30_S = "((((A:0.01,B:0.02):0.93,C:0.04):0.05,D:1.4):0.06,E):0.72";
+ final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
+ if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
+ return false;
+ }
+ final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
+ final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
+ if ( ( p32.length != 0 ) ) {
+ return false;
+ }
+ final String p33_S = "A";
+ final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
+ if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
+ return false;
+ }
+ final String p34_S = "B;";
+ final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
+ if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
+ return false;
+ }
+ final String p35_S = "B:0.2";
+ final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
+ if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
+ return false;
+ }
+ final String p36_S = "(A)";
+ final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
+ if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
+ return false;
+ }
+ final String p37_S = "((A))";
+ final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
+ if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
+ return false;
+ }
+ final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
+ final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
+ if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
+ return false;
+ }
+ final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
+ final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
+ if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
+ return false;
+ }
+ final String p40_S = "(A,B,C)";
+ final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
+ if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
+ return false;
+ }
+ final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
+ final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
+ if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
+ return false;
+ }
+ final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
+ final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
+ if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {