X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Ftest%2FTest.java;h=adcbac9e48a9d51d1c95b682f5c3af3f2d326d8b;hb=d4af4e66f7aee7d99deecc7b3a3125eb3748884e;hp=05d17ac8e64e4e221242b4a44c7ea7cbc17f4769;hpb=780b50a029ad352bd7b309eab711c48c6bce3ef0;p=jalview.git diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 05d17ac..adcbac9 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -54,9 +54,11 @@ import org.forester.io.parsers.nhx.NHXParser; import org.forester.io.parsers.phyloxml.PhyloXmlParser; import org.forester.io.parsers.tol.TolParser; import org.forester.io.writers.PhylogenyWriter; +import org.forester.msa.BasicMsa; import org.forester.msa.Mafft; import org.forester.msa.Msa; import org.forester.msa.MsaInferrer; +import org.forester.msa.MsaMethods; import org.forester.pccx.TestPccx; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyBranch; @@ -81,6 +83,7 @@ import org.forester.phylogeny.data.Taxonomy; import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; +import org.forester.protein.Protein; import org.forester.sdi.SDI; import org.forester.sdi.SDIR; import org.forester.sdi.SDIse; @@ -88,7 +91,6 @@ import org.forester.sdi.TaxonomyAssigner; import org.forester.sdi.TestGSDI; import org.forester.sequence.BasicSequence; import org.forester.sequence.Sequence; -import org.forester.surfacing.Protein; import org.forester.surfacing.TestSurfacing; import org.forester.tools.ConfidenceAssessor; import org.forester.tools.SupportCount; @@ -704,6 +706,15 @@ public final class Test { System.out.println( "failed." ); failed++; } + System.out.print( "Simple MSA quality: " ); + if ( Test.testMsaQualityMethod() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } // System.out.print( "WABI TxSearch: " ); // if ( Test.testWabiTxSearch() ) { // System.out.println( "OK." ); @@ -2850,7 +2861,7 @@ public final class Test { dss3.addValue( 10 ); final AsciiHistogram histo = new AsciiHistogram( dss3 ); histo.toStringBuffer( 10, '=', 40, 5 ); - histo.toStringBuffer( 3, 8, 10, '=', 40, 5 ); + histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null ); } catch ( final Exception e ) { e.printStackTrace( System.out ); @@ -3433,10 +3444,16 @@ public final class Test { 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; @@ -4473,14 +4490,14 @@ public final class Test { return false; } if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) - .equals( "((A,B)ab:2.0[88.0],C);" ) ) { + .equals( "((A,B)ab:2.0[88],C);" ) ) { return false; } if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) { return false; } if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ) - .equals( "((A,B)88.0:2.0,C);" ) ) { + .equals( "((A,B)88:2.0,C);" ) ) { return false; } final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; @@ -4497,6 +4514,15 @@ public final class Test { if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) { return false; } + // + final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ]; + if ( p54.getNode( "A" ) == null ) { + return false; + } + if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) + .equals( "((A,B)[88],C);" ) ) { + return false; + } } catch ( final Exception e ) { e.printStackTrace( System.out ); @@ -4528,11 +4554,10 @@ public final class Test { return false; } if ( !n5.toNewHampshireX() - .equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:XN=S=tag1=value1=unit1:B=56.0:W=2.0:C=10.20.30]" ) ) { + .equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:XN=S=tag1=value1=unit1:B=56:W=2.0:C=10.20.30]" ) ) { return false; } - if ( !n6.toNewHampshireX() - .equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:XN=B=bool_tag=T:B=100.0:W=2.0:C=0.0.0]" ) ) { + if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:XN=B=bool_tag=T:B=100:W=2.0:C=0.0.0]" ) ) { return false; } } @@ -4707,7 +4732,7 @@ public final class Test { if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) { return false; } - if ( !PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) { + if ( !PhylogenyMethods.getSpecies( b ).equals( "" ) ) { return false; } final PhylogenyNode c = PhylogenyNode @@ -4716,7 +4741,25 @@ public final class Test { if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) { return false; } - if ( !PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) { + if ( !PhylogenyMethods.getSpecies( c ).equals( "" ) ) { + return false; + } + final PhylogenyNode c1 = PhylogenyNode + .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000", + PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) { + return false; + } + final PhylogenyNode c2 = PhylogenyNode + .createInstanceFromNhxString( "n10_Bovin_1/1000-2000", + PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) { return false; } final PhylogenyNode d = PhylogenyNode @@ -4963,13 +5006,13 @@ public final class Test { return false; } final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ]; - if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91.0],C:0.1)root:0.1[&&NHX:B=100.0]" ) ) { + if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) { return false; } final Phylogeny p10 = factory .create( " [79] ( (A [co mment] :0 .2[comment],B:0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],C: 0.1)[comment]root:0.1[100] [comment]", new NHXParser() )[ 0 ]; - if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91.0],C:0.1)root:0.1[&&NHX:B=100.0]" ) ) { + if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) { return false; } } @@ -5044,7 +5087,7 @@ public final class Test { final Phylogeny p10 = factory .create( " [79] ( (\"A \n\tB \" [co mment] :0 .2[comment],'B':0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],'C (or D?\\//;,))': 0.1)[comment]'\nroot is here (cool, was! ) ':0.1[100] [comment]", new NHXParser() )[ 0 ]; - final String p10_clean_str = "(('A B':0.2,B:0.3):0.5[&&NHX:B=91.0],'C (or D?\\//;,))':0.1)'root is here (cool, was! )':0.1[&&NHX:B=100.0]"; + final String p10_clean_str = "(('A B':0.2,B:0.3):0.5[&&NHX:B=91],'C (or D?\\//;,))':0.1)'root is here (cool, was! )':0.1[&&NHX:B=100]"; if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) { return false; } @@ -5056,7 +5099,7 @@ public final class Test { final Phylogeny p12 = factory .create( " [79] ( (\"A \n\tB \" [[][] :0 .2[comment][\t&\t&\n N\tH\tX:S=mo\tnkey !],'\tB\t\b\t\n\f\rB B ':0.0\b3[])\t[com ment]: 0. 5 \t[ 9 1 ][ \ncomment],'C\t (or D?\\//;,))': 0.\b1)[comment]'\nroot \tis here (cool, \b\t\n\f\r was! ) ':0.1[100] [comment]", new NHXParser() )[ 0 ]; - final String p12_clean_str = "(('A B':0.2[&&NHX:S=monkey!],'BB B':0.03):0.5[&&NHX:B=91.0],'C (or D?\\//;,))':0.1)'root is here (cool, was! )':0.1[&&NHX:B=100.0]"; + final String p12_clean_str = "(('A B':0.2[&&NHX:S=monkey!],'BB B':0.03):0.5[&&NHX:B=91],'C (or D?\\//;,))':0.1)'root is here (cool, was! )':0.1[&&NHX:B=100]"; if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) { return false; } @@ -8168,12 +8211,48 @@ public final class Test { 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 = "seq_1 abc\nseq2 ghi\nseq_1 def\nseq2 jkm\n"; + 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; @@ -8221,8 +8300,11 @@ public final class Test { opts.add( "--quiet" ); Msa msa = null; final MsaInferrer mafft = Mafft.createInstance(); - msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi.fasta" ), opts ); - if ( ( msa == null ) || ( msa.getLength() < 10 ) || ( msa.getNumberOfSequences() != 19 ) ) { + 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; } } @@ -8793,4 +8875,36 @@ public final class Test { } return true; } + + private static boolean testMsaQualityMethod() { + try { + final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" ); + final Sequence s1 = BasicSequence.createAaSequence( "a", "ABBXEFGHIJ" ); + final Sequence s2 = BasicSequence.createAaSequence( "a", "AXCXEFGHIJ" ); + final Sequence s3 = BasicSequence.createAaSequence( "a", "AXDDEFGHIJ" ); + final List l = new ArrayList(); + 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; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } }