System.out.println( "Query : " + query );
System.out.print( "Greatest Common Prefix : " + res.getGreatestCommonPrefix() );
if ( !ForesterUtil.isEmpty( res.getGreatestCommonPrefix() )
- && !ForesterUtil.isEmpty( res.getGreatestCommonCladeConfidence() ) ) {
- System.out.println( "\t(" + res.getGreatestCommonCladeConfidence() + ")" );
+ && !ForesterUtil.isEmpty( res.getGreatestCommonCladeSubtreeConfidence() ) ) {
+ System.out.println( "\t(" + res.getGreatestCommonCladeSubtreeConfidence() + ")" );
}
else {
System.out.println();
}
System.out.print( "Greatest Common Prefix Up : " + res.getGreatestCommonPrefixUp() );
if ( !ForesterUtil.isEmpty( res.getGreatestCommonPrefixUp() )
- && !ForesterUtil.isEmpty( res.getGreatestCommonCladeUpConfidence() ) ) {
- System.out.println( "\t(" + res.getGreatestCommonCladeUpConfidence() + ")" );
+ && !ForesterUtil.isEmpty( res.getGreatestCommonCladeUpSubtreeConfidence() ) ) {
+ System.out.println( "\t(" + res.getGreatestCommonCladeUpSubtreeConfidence() + ")" );
}
else {
System.out.println();
}
System.out.print( "Greatest Common Prefix Down : " + res.getGreatestCommonPrefixDown() );
if ( !ForesterUtil.isEmpty( res.getGreatestCommonPrefixDown() )
- && !ForesterUtil.isEmpty( res.getGreatestCommonCladeDownConfidence() ) ) {
- System.out.println( "\t(" + res.getGreatestCommonCladeDownConfidence() + ")" );
+ && !ForesterUtil.isEmpty( res.getGreatestCommonCladeDownSubtreeConfidence() ) ) {
+ System.out.println( "\t(" + res.getGreatestCommonCladeDownSubtreeConfidence() + ")" );
}
else {
System.out.println();
final String conf = obtainConfidence( qnode_pp );
if ( conf != null ) {
- res.setGreatestCommonCladeConfidence(conf);
+ res.setGreatestCommonCladeSubtreeConfidence(conf);
}
final String greatest_common_prefix_up[] = analyzeSiblings( qnode_p, qnode_pp, separator );
res.setGreatestCommonPrefixUp( greatest_common_prefix_up[ 0 ] );
if ( greatest_common_prefix_up[ 1 ] != null ) {
- res.setGreatestCommonCladeUpConfidence( greatest_common_prefix_up[ 1 ] );
+ res.setGreatestCommonCladeUpSubtreeConfidence( greatest_common_prefix_up[ 1 ] );
}
final String greatest_common_prefix_down[] = analyzeSiblings( qnode, qnode_p, separator );
res.setGreatestCommonPrefixDown( greatest_common_prefix_down[ 0 ] );
if ( greatest_common_prefix_down[ 1 ] != null ) {
- res.setGreatestCommonCladeDownConfidence( greatest_common_prefix_down[ 1 ] );
+ res.setGreatestCommonCladeDownSubtreeConfidence( greatest_common_prefix_down[ 1 ] );
}
return res;
}
package org.forester.clade_analysis;
import java.io.File;
+import java.util.List;
import org.forester.io.parsers.PhylogenyParser;
import org.forester.io.parsers.util.ParserUtils;
System.out.println( "Clade analysis 2 failed" );
failed = true;
}
+ if ( !testCladeAnalysis3() ) {
+ System.out.println( "Clade analysis 3 failed" );
+ failed = true;
+ }
if ( !failed ) {
System.out.println( "OK" );
}
if ( !testCladeAnalysis2() ) {
return false;
}
+ if ( !testCladeAnalysis3() ) {
+ return false;
+ }
return true;
}
}
return true;
}
+
+ private static boolean testCladeAnalysis3() {
+ try {
+ final Result2 res1 = new Result2();
+ res1.addGreatestCommonPrefix( "A.1.1", 0.3 );
+ res1.addGreatestCommonPrefix( "A.1.2", 0.3 );
+ res1.addGreatestCommonPrefix( "A.1.3", 0.3 );
+ res1.addGreatestCommonPrefix( "B.1", 0.1 );
+
+ List<String> x = ForesterUtil.spliIntoPrefixes( "A.1.2.3.4", "." );
+ // System.out.println( x );
+ x =ForesterUtil.spliIntoPrefixes( "A", "." );
+ // System.out.println( x );
+
+
+ res1.analyzeGreatestCommonPrefixes( "." );
+
+ final Result2 res2 = new Result2();
+ res2.addGreatestCommonPrefix( "A.1.1.1", 0.1 );
+ res2.addGreatestCommonPrefix( "A.1", 0.7 );
+ res2.addGreatestCommonPrefix( "A.1.2", 0.1 );
+ res2.addGreatestCommonPrefix( "B.1", 0.1 );
+ res2.analyzeGreatestCommonPrefixes( "." );
+
+ final Result2 res3 = new Result2();
+ res3.addGreatestCommonPrefix( "A.1.1.1", 0.7 );
+ res3.addGreatestCommonPrefix( "A.1", 0.1 );
+ res3.addGreatestCommonPrefix( "A.1.2", 0.1 );
+ res3.addGreatestCommonPrefix( "B.1", 0.1 );
+ res3.analyzeGreatestCommonPrefixes( "." );
+
+
+ final Result2 res4 = new Result2();
+ res4.addGreatestCommonPrefix( "A.1.1.1.1", 0.35);
+ res4.addGreatestCommonPrefix( "A.1.1.1.2", 0.35 );
+ res4.addGreatestCommonPrefix( "A.1", 0.1 );
+ res4.addGreatestCommonPrefix( "A.1.2", 0.1 );
+ res4.addGreatestCommonPrefix( "B.1", 0.1 );
+ res4.analyzeGreatestCommonPrefixes( "." );
+
+ final Result2 res5 = new Result2();
+ res5.addGreatestCommonPrefix( "A.1.1.1.1", 0.2);
+ res5.addGreatestCommonPrefix( "C.2.3", 0.2 );
+ res5.addGreatestCommonPrefix( "A.1.5", 0.1 );
+ res5.addGreatestCommonPrefix( "A.3.1.4", 0.2 );
+ res5.addGreatestCommonPrefix( "B.1.1", 0.2 );
+ res5.addGreatestCommonPrefix( "B.1.2", 0.09 );
+ res5.addGreatestCommonPrefix( "D.1.1.1.1", 0.01 );
+ res5.analyzeGreatestCommonPrefixes( "." );
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
}
private final List<String> _warnings = new ArrayList<>();
private int _lec_ext_nodes = 0;
private int _p_ext_nodes = 0;
- private String _greatest_common_clade_confidence = "";
- private String _greatest_common_clade_confidence_up = "";
- private String _greatest_common_clade_confidence_down = "";
+ private String _greatest_common_clade_subtree_confidence = "";
+ private String _greatest_common_clade_subtree_confidence_up = "";
+ private String _greatest_common_clade_subtree_confidence_down = "";
void addWarning( final String warning ) {
_warnings.add( warning );
_greatest_common_prefix_down = greatest_common_prefix_down;
}
- void setGreatestCommonCladeConfidence( final String greatest_common_clade_confidence ) {
- _greatest_common_clade_confidence = greatest_common_clade_confidence;
+ void setGreatestCommonCladeSubtreeConfidence( final String greatest_common_clade_confidence ) {
+ _greatest_common_clade_subtree_confidence = greatest_common_clade_confidence;
}
- void setGreatestCommonCladeUpConfidence( final String greatest_common_clade_confidence_up ) {
- _greatest_common_clade_confidence_up = greatest_common_clade_confidence_up;
+ void setGreatestCommonCladeUpSubtreeConfidence( final String greatest_common_clade_confidence_up ) {
+ _greatest_common_clade_subtree_confidence_up = greatest_common_clade_confidence_up;
}
- void setGreatestCommonCladeDownConfidence( final String greatest_common_clade_confidence_down ) {
- _greatest_common_clade_confidence_down = greatest_common_clade_confidence_down;
+ void setGreatestCommonCladeDownSubtreeConfidence( final String greatest_common_clade_confidence_down ) {
+ _greatest_common_clade_subtree_confidence_down = greatest_common_clade_confidence_down;
}
public String getGreatestCommonPrefix() {
return _greatest_common_prefix_down;
}
- public String getGreatestCommonCladeConfidence() {
- return _greatest_common_clade_confidence;
+ public String getGreatestCommonCladeSubtreeConfidence() {
+ return _greatest_common_clade_subtree_confidence;
}
- public String getGreatestCommonCladeUpConfidence() {
- return _greatest_common_clade_confidence_up;
+ public String getGreatestCommonCladeUpSubtreeConfidence() {
+ return _greatest_common_clade_subtree_confidence_up;
}
- public String getGreatestCommonCladeDownConfidence() {
- return _greatest_common_clade_confidence_down;
+ public String getGreatestCommonCladeDownSubtreeConfidence() {
+ return _greatest_common_clade_subtree_confidence_down;
}
public List<String> getWarnings() {
private ForesterUtil() {
}
+
+ public static List<String> spliIntoPrefixes(final String prefix, final String separator ) {
+ final String[] a = prefix.split( Pattern.quote( separator ) );
+ final List<String> l= new ArrayList<String>();
+ for( int i = 0; i < a.length; ++i ) {
+ final StringBuilder sb = new StringBuilder();
+ for( int j = 0; j <= i; ++j ) {
+ sb.append( a[ j ] );
+ if ( j < i ) {
+ sb.append( separator );
+ }
+ }
+ //System.out.println( sb.toString() );
+ l.add( sb.toString());
+ }
+ return l;
+ }
}