From 5e2bc10f84f648553a90984d7aa97d7c5a3b73a7 Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Tue, 15 Aug 2017 14:58:11 -0700 Subject: [PATCH] in progress... --- .../src/org/forester/application/cladinator.java | 12 ++-- .../src/org/forester/clade_analysis/Analysis.java | 6 +- .../forester/clade_analysis/CladeAnalysisTest.java | 64 ++++++++++++++++++++ .../src/org/forester/clade_analysis/Result.java | 30 ++++----- .../java/src/org/forester/util/ForesterUtil.java | 17 ++++++ 5 files changed, 105 insertions(+), 24 deletions(-) diff --git a/forester/java/src/org/forester/application/cladinator.java b/forester/java/src/org/forester/application/cladinator.java index 0aef757..ddc1aef 100644 --- a/forester/java/src/org/forester/application/cladinator.java +++ b/forester/java/src/org/forester/application/cladinator.java @@ -121,24 +121,24 @@ public final class cladinator { 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(); diff --git a/forester/java/src/org/forester/clade_analysis/Analysis.java b/forester/java/src/org/forester/clade_analysis/Analysis.java index 99b9439..4803f54 100644 --- a/forester/java/src/org/forester/clade_analysis/Analysis.java +++ b/forester/java/src/org/forester/clade_analysis/Analysis.java @@ -90,18 +90,18 @@ public final class Analysis { 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; } diff --git a/forester/java/src/org/forester/clade_analysis/CladeAnalysisTest.java b/forester/java/src/org/forester/clade_analysis/CladeAnalysisTest.java index a78e8fe..d91e36e 100644 --- a/forester/java/src/org/forester/clade_analysis/CladeAnalysisTest.java +++ b/forester/java/src/org/forester/clade_analysis/CladeAnalysisTest.java @@ -2,6 +2,7 @@ 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; @@ -25,6 +26,10 @@ public class CladeAnalysisTest { 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" ); } @@ -37,6 +42,9 @@ public class CladeAnalysisTest { if ( !testCladeAnalysis2() ) { return false; } + if ( !testCladeAnalysis3() ) { + return false; + } return true; } @@ -582,4 +590,60 @@ public class CladeAnalysisTest { } 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 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; + } } diff --git a/forester/java/src/org/forester/clade_analysis/Result.java b/forester/java/src/org/forester/clade_analysis/Result.java index e7686e1..e11fcd5 100644 --- a/forester/java/src/org/forester/clade_analysis/Result.java +++ b/forester/java/src/org/forester/clade_analysis/Result.java @@ -36,9 +36,9 @@ public final class Result { private final List _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 ); @@ -56,16 +56,16 @@ public final class Result { _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() { @@ -80,16 +80,16 @@ public final class Result { 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 getWarnings() { diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index 971032d..d3d61d9 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -1659,4 +1659,21 @@ public final class ForesterUtil { private ForesterUtil() { } + + public static List spliIntoPrefixes(final String prefix, final String separator ) { + final String[] a = prefix.split( Pattern.quote( separator ) ); + final List l= new ArrayList(); + 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; + } } -- 1.7.10.2