From 0d0b9cde030d50b153eb6d1ff7ce13bc273edc17 Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Fri, 15 Sep 2017 11:46:39 -0700 Subject: [PATCH] in progress... --- .../src/org/forester/application/cladinator.java | 57 +++- .../org/forester/clade_analysis/AnalysisMulti.java | 76 ++--- .../forester/clade_analysis/AnalysisSingle.java | 10 +- .../forester/clade_analysis/CladeAnalysisTest.java | 6 +- .../src/org/forester/clade_analysis/Prefix.java | 4 +- .../org/forester/clade_analysis/ResultMulti.java | 102 +++++-- forester/java/src/org/forester/test/Test.java | 304 +++++++++++--------- .../java/src/org/forester/util/ForesterUtil.java | 54 ++-- 8 files changed, 366 insertions(+), 247 deletions(-) diff --git a/forester/java/src/org/forester/application/cladinator.java b/forester/java/src/org/forester/application/cladinator.java index 993e295..6dc17e3 100644 --- a/forester/java/src/org/forester/application/cladinator.java +++ b/forester/java/src/org/forester/application/cladinator.java @@ -52,8 +52,8 @@ import org.forester.util.UserException; public final class cladinator { final static private String PRG_NAME = "cladinator"; - final static private String PRG_VERSION = "1.03"; - final static private String PRG_DATE = "170913"; + final static private String PRG_VERSION = "1.04"; + final static private String PRG_DATE = "170915"; final static private String PRG_DESC = "clades within clades of annotated labels -- analysis of pplacer-type outputs"; final static private String E_MAIL = "phyloxml@gmail.com"; final static private String WWW = "https://sites.google.com/site/cmzmasek/home/software/forester"; @@ -66,6 +66,7 @@ public final class cladinator { final static private String EXTRA_PROCESSING_OPTION1 = "x"; final static private String EXTRA_PROCESSING1_SEP_OPTION = "xs"; final static private String EXTRA_PROCESSING1_KEEP_EXTRA_OPTION = "xk"; + final static private String QUIET_OPTION = "Q"; final static private String VERBOSE_OPTION = "v"; final static private double SPECIFICS_CUTOFF_DEFAULT = 0.8; final static private String SEP_DEFAULT = "."; @@ -108,6 +109,7 @@ public final class cladinator { allowed_options.add( EXTRA_PROCESSING1_SEP_OPTION ); allowed_options.add( EXTRA_PROCESSING1_KEEP_EXTRA_OPTION ); allowed_options.add( VERBOSE_OPTION ); + allowed_options.add( QUIET_OPTION ); final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options ); if ( dissallowed_options.length() > 0 ) { ForesterUtil.fatalError( PRG_NAME, "unknown option(s): " + dissallowed_options ); @@ -235,6 +237,13 @@ public final class cladinator { else { verbose = false; } + final boolean quit; + if ( cla.isOptionSet( QUIET_OPTION ) ) { + quit = true; + } + else { + quit = false; + } System.out.println( "Input tree : " + intreefile ); System.out.println( "Specific-hit support cutoff: " + cutoff_specifics ); if ( mapping_file != null ) { @@ -265,10 +274,10 @@ public final class cladinator { } System.out.println( "Number of input trees : " + phys.length ); if ( phys.length == 1 ) { - System.out.println( "Ext. nodes in input tree 1 : " + phys[ 0 ].getNumberOfExternalNodes() ); + System.out.println( "Ext. nodes in input tree : " + phys[ 0 ].getNumberOfExternalNodes() ); } else { - System.out.println( "Ext. nodes in input tree : " + phys[ 0 ].getNumberOfExternalNodes() ); + System.out.println( "Ext. nodes in input tree 1 : " + phys[ 0 ].getNumberOfExternalNodes() ); } final EasyWriter outtable_writer; if ( outtablefile != null ) { @@ -277,6 +286,7 @@ public final class cladinator { else { outtable_writer = null; } + int counter = 0; for( final Phylogeny phy : phys ) { if ( map != null ) { AnalysisMulti.performMapping( pattern, map, phy, verbose ); @@ -290,11 +300,19 @@ public final class cladinator { verbose ); } final ResultMulti res = AnalysisMulti.execute( phy, pattern, separator, cutoff_specifics ); - printResult( res ); + if ( !quit ) { + if ( phys.length == 1 ) { + printResult( res, -1 ); + } + else { + printResult( res, counter ); + } + } if ( outtable_writer != null ) { writeResultToTable( res, outtable_writer ); outtable_writer.flush(); } + ++counter; } if ( outtable_writer != null ) { outtable_writer.flush(); @@ -313,10 +331,14 @@ public final class cladinator { } } - private final static void printResult( final ResultMulti res ) { - System.out.println(); - System.out.println( "Result for " + res.getQueryNamePrefix() ); + private final static void printResult( final ResultMulti res, final int counter ) { System.out.println(); + if ( counter == -1 ) { + System.out.println( "Result for " + res.getQueryNamePrefix() ); + } + else { + System.out.println( "Result for " + res.getQueryNamePrefix() + " [tree " + counter + "]" ); + } if ( ( res.getAllMultiHitPrefixes() == null ) | ( res.getAllMultiHitPrefixes().size() < 1 ) ) { System.out.println( " No match to query pattern!" ); } @@ -356,6 +378,9 @@ public final class cladinator { System.out.println( " " + prefix ); } } + System.out.println(); + System.out.println( " Total Number of Matches: " + res.getNumberOfMatches() + "/" + + res.getReferenceTreeNumberOfExternalNodes() ); } System.out.println(); } @@ -375,6 +400,10 @@ public final class cladinator { w.print( prefix.getPrefix() ); w.print( "\t" ); w.print( df.format( prefix.getConfidence() ) ); + w.print( "\t" ); + w.print( String.valueOf( res.getNumberOfMatches() ) ); + w.print( "\t" ); + w.print( String.valueOf( res.getReferenceTreeNumberOfExternalNodes() ) ); w.println(); } if ( res.isHasSpecificMultiHitsPrefixes() ) { @@ -386,6 +415,10 @@ public final class cladinator { w.print( prefix.getPrefix() ); w.print( "\t" ); w.print( df.format( prefix.getConfidence() ) ); + w.print( "\t" ); + w.print( String.valueOf( res.getNumberOfMatches() ) ); + w.print( "\t" ); + w.print( String.valueOf( res.getReferenceTreeNumberOfExternalNodes() ) ); w.println(); } } @@ -398,6 +431,10 @@ public final class cladinator { w.print( prefix.getPrefix() ); w.print( "\t" ); w.print( df.format( prefix.getConfidence() ) ); + w.print( "\t" ); + w.print( String.valueOf( res.getNumberOfMatches() ) ); + w.print( "\t" ); + w.print( String.valueOf( res.getReferenceTreeNumberOfExternalNodes() ) ); w.println(); } } @@ -410,6 +447,10 @@ public final class cladinator { w.print( prefix.getPrefix() ); w.print( "\t" ); w.print( df.format( prefix.getConfidence() ) ); + w.print( "\t" ); + w.print( String.valueOf( res.getNumberOfMatches() ) ); + w.print( "\t" ); + w.print( String.valueOf( res.getReferenceTreeNumberOfExternalNodes() ) ); w.println(); } } diff --git a/forester/java/src/org/forester/clade_analysis/AnalysisMulti.java b/forester/java/src/org/forester/clade_analysis/AnalysisMulti.java index 8eccc03..8096777 100644 --- a/forester/java/src/org/forester/clade_analysis/AnalysisMulti.java +++ b/forester/java/src/org/forester/clade_analysis/AnalysisMulti.java @@ -31,7 +31,6 @@ package org.forester.clade_analysis; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.SortedMap; import java.util.regex.Matcher; @@ -39,7 +38,6 @@ import java.util.regex.Pattern; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; -import org.forester.phylogeny.data.Confidence; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.util.ForesterUtil; import org.forester.util.UserException; @@ -73,28 +71,15 @@ public final class AnalysisMulti { final String separator, final double cutoff_for_specifics ) throws UserException { + if ( ForesterUtil.isEmpty( separator ) ) { + throw new IllegalArgumentException( "separator must not be null or empty" ); + } cleanUpExternalNames( p, separator ); final List qnodes = p.getNodes( query ); - String query_name_prefix = null; - for( final PhylogenyNode n : qnodes ) { - final String name = n.getName(); - final Matcher matcher = query.matcher( name ); - if ( matcher.find() ) { - final String prefix = name.substring( 0, matcher.start() ); - if ( ForesterUtil.isEmpty( prefix ) ) { - throw new UserException( "query nodes with empty label prefix found: \"" + prefix + "\"" ); - } - if ( query_name_prefix == null ) { - query_name_prefix = prefix; - } - else if ( !query_name_prefix.equals( prefix ) ) { - throw new UserException( "query nodes with different label prefixes found: \"" + query_name_prefix - + "\" and \"" + prefix + "\"" ); - } - } - } final ResultMulti res = new ResultMulti(); - res.setQueryNamePrefix( query_name_prefix ); + res.setQueryNamePrefix( obtainQueryPrefix( query, qnodes ) ); + res.setTotalNumberOfMatches( qnodes.size() ); + res.setReferenceTreeNumberOfExternalNodes( p.getNumberOfExternalNodes() - qnodes.size() ); for( int i = 0; i < qnodes.size(); ++i ) { final PhylogenyNode qnode = qnodes.get( i ); if ( qnode.isRoot() ) { @@ -127,7 +112,7 @@ public final class AnalysisMulti { conf_str = matcher.group( 1 ); } else { - throw new IllegalStateException( "pattern did not match -- this should have never happened!" ); + throw new IllegalStateException( "query pattern does not match [this should have never happened!]" ); } final double conf = Double.parseDouble( conf_str ); if ( !ForesterUtil.isEmpty( greatest_common_prefix ) ) { @@ -155,6 +140,29 @@ public final class AnalysisMulti { return res; } + private final static String obtainQueryPrefix( final Pattern query, final List qnodes ) + throws UserException { + String query_name_prefix = null; + for( final PhylogenyNode n : qnodes ) { + final String name = n.getName(); + final Matcher matcher = query.matcher( name ); + if ( matcher.find() ) { + final String prefix = name.substring( 0, matcher.start() ); + if ( ForesterUtil.isEmpty( prefix ) ) { + throw new UserException( "query nodes with empty label prefix found: \"" + prefix + "\"" ); + } + if ( query_name_prefix == null ) { + query_name_prefix = prefix; + } + else if ( !query_name_prefix.equals( prefix ) ) { + throw new UserException( "query nodes with different label prefixes found: \"" + query_name_prefix + + "\" and \"" + prefix + "\"" ); + } + } + } + return query_name_prefix; + } + private final static void cleanUpExternalNames( final Phylogeny p, final String separator ) throws UserException { final Pattern pattern1 = Pattern.compile( "\\Q" + separator + "\\E" + "\\s+" ); final Pattern pattern2 = Pattern.compile( "\\s+" + "\\Q" + separator + "\\E" ); @@ -212,30 +220,6 @@ public final class AnalysisMulti { return greatest_common_prefix; } - private final static String obtainConfidence( final PhylogenyNode n ) { - if ( ( n.getBranchData().getConfidences() != null ) && ( n.getBranchData().getConfidences().size() > 0 ) ) { - final List confidences = n.getBranchData().getConfidences(); - boolean not_first = false; - Collections.sort( confidences ); - final StringBuilder sb = new StringBuilder(); - for( final Confidence confidence : confidences ) { - final double value = confidence.getValue(); - if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) { - if ( not_first ) { - sb.append( " / " ); - } - else { - not_first = true; - } - sb.append( ( ForesterUtil.isEmpty( confidence.getType() ) ? "confidence: " - : confidence.getType() + ": " ) + value ); - } - } - return sb.toString(); - } - return null; - } - public final static void performMapping( final Pattern pattern, final SortedMap map, final Phylogeny p, diff --git a/forester/java/src/org/forester/clade_analysis/AnalysisSingle.java b/forester/java/src/org/forester/clade_analysis/AnalysisSingle.java index 5c725b6..14863d4 100644 --- a/forester/java/src/org/forester/clade_analysis/AnalysisSingle.java +++ b/forester/java/src/org/forester/clade_analysis/AnalysisSingle.java @@ -87,12 +87,10 @@ public final class AnalysisSingle { } res.setLeastEncompassingCladeSize( lec_ext_nodes ); res.setTreeSize( p_ext_nodes ); - final String conf = obtainConfidence( qnode_pp ); if ( conf != null ) { - res.setGreatestCommonCladeSubtreeConfidence(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 ) { @@ -106,8 +104,6 @@ public final class AnalysisSingle { return res; } - - private final static String[] analyzeSiblings( final PhylogenyNode child, final PhylogenyNode parent, final String separator ) { @@ -133,9 +129,9 @@ public final class AnalysisSingle { final String greatest_common_prefix = ForesterUtil.greatestCommonPrefix( ext_nodes_names, separator ); return new String[] { greatest_common_prefix, conf }; } - + private final static String obtainConfidence( final PhylogenyNode n ) { - if ( n.getBranchData().getConfidences() != null && n.getBranchData().getConfidences().size() > 0 ) { + if ( ( n.getBranchData().getConfidences() != null ) && ( n.getBranchData().getConfidences().size() > 0 ) ) { final List confidences = n.getBranchData().getConfidences(); boolean not_first = false; Collections.sort( confidences ); diff --git a/forester/java/src/org/forester/clade_analysis/CladeAnalysisTest.java b/forester/java/src/org/forester/clade_analysis/CladeAnalysisTest.java index 35c08b5..ac826e0 100644 --- a/forester/java/src/org/forester/clade_analysis/CladeAnalysisTest.java +++ b/forester/java/src/org/forester/clade_analysis/CladeAnalysisTest.java @@ -732,7 +732,7 @@ public class CladeAnalysisTest { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( intreefile1, true ); final Phylogeny p1 = factory.create( intreefile1, pp )[ 0 ]; - ResultMulti res2 = AnalysisMulti.execute( p1 ); + final ResultMulti res2 = AnalysisMulti.execute( p1 ); res2.analyze( 0.3 ); System.out.print( res2.toString() ); System.out.println( "------------------------- " ); @@ -751,7 +751,7 @@ public class CladeAnalysisTest { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( intreefile1, true ); final Phylogeny p1 = factory.create( intreefile1, pp )[ 0 ]; - ResultMulti res = AnalysisMulti.execute( p1 ); + final ResultMulti res = AnalysisMulti.execute( p1 ); res.analyze( 0.3 ); System.out.print( res.toString() ); System.out.println( "------------------------- " ); @@ -770,7 +770,7 @@ public class CladeAnalysisTest { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final PhylogenyParser pp = ParserUtils.createParserDependingOnFileType( intreefile1, true ); final Phylogeny p1 = factory.create( intreefile1, pp )[ 0 ]; - ResultMulti res = AnalysisMulti.execute( p1, 0.45 ); + final ResultMulti res = AnalysisMulti.execute( p1, 0.45 ); System.out.print( res.toString() ); System.out.println( "------------------------- " ); System.out.println(); diff --git a/forester/java/src/org/forester/clade_analysis/Prefix.java b/forester/java/src/org/forester/clade_analysis/Prefix.java index e4bf8fa..009c63f 100644 --- a/forester/java/src/org/forester/clade_analysis/Prefix.java +++ b/forester/java/src/org/forester/clade_analysis/Prefix.java @@ -36,11 +36,11 @@ public final class Prefix { } } - public String getPrefix() { + public String getPrefix() { return _prefix; } - public String getPrefixFirstElement() { + public String getPrefixFirstElement() { return _first; } diff --git a/forester/java/src/org/forester/clade_analysis/ResultMulti.java b/forester/java/src/org/forester/clade_analysis/ResultMulti.java index 566a646..285e533 100644 --- a/forester/java/src/org/forester/clade_analysis/ResultMulti.java +++ b/forester/java/src/org/forester/clade_analysis/ResultMulti.java @@ -40,25 +40,31 @@ import org.forester.util.UserException; public final class ResultMulti { - private final String _separator; - private final List _greatest_common_prefixes = new ArrayList<>(); - private final List _greatest_common_prefixes_up = new ArrayList<>(); - private final List _greatest_common_prefixes_down = new ArrayList<>(); - private List _all = null; - private List _collapsed = null; - private List _cleaned_spec = null; - private boolean _has_specifics = false; - private List _all_up = null; - private List _collapsed_up = null; - private List _cleaned_spec_up = null; - private boolean _has_specifics_up = false; - private List _all_down = null; - private List _collapsed_down = null; - private List _cleaned_spec_down = null; - private boolean _has_specifics_down = false; - private String _query_name_prefix = ""; + private final static double MIN_DIFF = 1E-5; + private final String _separator; + private final List _greatest_common_prefixes = new ArrayList<>(); + private final List _greatest_common_prefixes_up = new ArrayList<>(); + private final List _greatest_common_prefixes_down = new ArrayList<>(); + private List _all = null; + private List _collapsed = null; + private List _cleaned_spec = null; + private boolean _has_specifics = false; + private List _all_up = null; + private List _collapsed_up = null; + private List _cleaned_spec_up = null; + private boolean _has_specifics_up = false; + private List _all_down = null; + private List _collapsed_down = null; + private List _cleaned_spec_down = null; + private boolean _has_specifics_down = false; + private int _matches = 0; + private int _ref_tree_ext_nodes = 0; + private String _query_name_prefix = ""; ResultMulti( final String separator ) { + if ( ForesterUtil.isEmpty( separator ) ) { + throw new IllegalArgumentException( "separator must not be null or empty" ); + } _separator = separator; reset(); } @@ -120,6 +126,14 @@ public final class ResultMulti { return _query_name_prefix; } + public int getNumberOfMatches() { + return _matches; + } + + public int getReferenceTreeNumberOfExternalNodes() { + return _ref_tree_ext_nodes; + } + @Override public final String toString() { final StringBuilder sb = new StringBuilder(); @@ -172,6 +186,9 @@ public final class ResultMulti { sb.append( ForesterUtil.LINE_SEPARATOR ); } } + sb.append( ForesterUtil.LINE_SEPARATOR ); + sb.append( "Total Number of Matches: " + getNumberOfMatches() + "/" + getReferenceTreeNumberOfExternalNodes() ); + sb.append( ForesterUtil.LINE_SEPARATOR ); return sb.toString(); } @@ -194,6 +211,20 @@ public final class ResultMulti { _query_name_prefix = query_name_prefix; } + void setTotalNumberOfMatches( final int matches ) { + if ( _matches > 0 ) { + throw new IllegalStateException( "illegal attempt to change the number of matches" ); + } + _matches = matches; + } + + public void setReferenceTreeNumberOfExternalNodes( final int ext_nodes ) { + if ( _ref_tree_ext_nodes > 0 ) { + throw new IllegalStateException( "illegal attempt to change the number of external nodes" ); + } + _ref_tree_ext_nodes = ext_nodes; + } + final void analyze( final double cutoff_for_specifics ) throws UserException { reset(); analyzeGreatestCommonPrefixes( _greatest_common_prefixes, _separator, cutoff_for_specifics ); @@ -223,11 +254,11 @@ public final class ResultMulti { final List l = obtainAllPrefixes( greatest_common_prefixes, separator ); if ( !ForesterUtil.isEmpty( l ) ) { sortPrefixesAccordingToConfidence( l ); - _all = removeLessSpecificPrefixes( l ); + _all = removeLessSpecificPrefixes( l, separator ); _collapsed = collapse( _all ); _has_specifics = false; if ( cutoff >= 0 ) { - _cleaned_spec = obtainSpecifics( cutoff, _all, _collapsed ); + _cleaned_spec = obtainSpecifics( cutoff, _all, _collapsed, separator ); if ( !ForesterUtil.isEmpty( _cleaned_spec ) ) { _has_specifics = true; } @@ -242,11 +273,11 @@ public final class ResultMulti { final List l = obtainAllPrefixes( greatest_common_prefixes_up, separator ); if ( !ForesterUtil.isEmpty( l ) ) { sortPrefixesAccordingToConfidence( l ); - _all_up = removeLessSpecificPrefixes( l ); + _all_up = removeLessSpecificPrefixes( l, separator ); _collapsed_up = collapse( _all_up ); _has_specifics_up = false; if ( cutoff >= 0 ) { - _cleaned_spec_up = obtainSpecifics( cutoff, _all_up, _collapsed_up ); + _cleaned_spec_up = obtainSpecifics( cutoff, _all_up, _collapsed_up, separator ); if ( !ForesterUtil.isEmpty( _cleaned_spec_up ) ) { _has_specifics_up = true; } @@ -261,11 +292,11 @@ public final class ResultMulti { final List l = obtainAllPrefixes( greatest_common_prefixes_down, separator ); if ( !ForesterUtil.isEmpty( l ) ) { sortPrefixesAccordingToConfidence( l ); - _all_down = removeLessSpecificPrefixes( l ); + _all_down = removeLessSpecificPrefixes( l, separator ); _collapsed_down = collapse( _all_down ); _has_specifics_down = false; if ( cutoff >= 0 ) { - _cleaned_spec_down = obtainSpecifics( cutoff, _all_down, _collapsed_down ); + _cleaned_spec_down = obtainSpecifics( cutoff, _all_down, _collapsed_down, separator ); if ( !ForesterUtil.isEmpty( _cleaned_spec_down ) ) { _has_specifics_down = true; } @@ -275,7 +306,8 @@ public final class ResultMulti { final static List obtainSpecifics( final double cutoff, final List cleaned, - final List collapsed ) { + final List collapsed, + final String separator ) { final List cleaned_spec = new ArrayList<>(); final Set collapsed_set = new HashSet<>(); for( final Prefix prefix : collapsed ) { @@ -290,10 +322,15 @@ public final class ResultMulti { for( final Prefix o : spec ) { boolean ok = true; for( final Prefix i : spec ) { - if ( ( !o.getPrefix().equals( i.getPrefix() ) ) && ( i.getPrefix().startsWith( o.getPrefix() ) ) ) { + if ( ( !o.getPrefix().equals( i.getPrefix() ) ) + && ( ForesterUtil.isContainsPrefix( i.getPrefix(), o.getPrefix(), separator ) ) ) { ok = false; break; } + /* if ( ( !o.getPrefix().equals( i.getPrefix() ) ) && ( i.getPrefix().startsWith( o.getPrefix() ) ) ) { + ok = false; + break; + }*/ } if ( ok ) { cleaned_spec.add( o ); @@ -314,7 +351,7 @@ public final class ResultMulti { confidence_sum += prefix.getConfidence(); } } - if ( !ForesterUtil.isEqual( confidence_sum, 1.0, 1E-5 ) ) { + if ( !ForesterUtil.isEqual( confidence_sum, 1.0, MIN_DIFF ) ) { throw new UserException( "confidences add up to " + confidence_sum + " instead of 1.0" ); } return collapsed; @@ -330,12 +367,19 @@ public final class ResultMulti { * I.e. it removes less specific prefixes. * */ - private final static List removeLessSpecificPrefixes( final List l ) { + private final static List removeLessSpecificPrefixes( final List l, final String separator ) { final List cleaned = new ArrayList<>(); for( final Prefix o : l ) { boolean ok = true; for( final Prefix i : l ) { - if ( ( !o.getPrefix().equals( i.getPrefix() ) ) && ( i.getPrefix().startsWith( o.getPrefix() ) ) + /*if ( ( !o.getPrefix().equals( i.getPrefix() ) ) && ( i.getPrefix().startsWith( o.getPrefix() ) ) + && ForesterUtil.isEqual( i.getConfidence(), + o.getConfidence() ) ) { + ok = false; + break; + }*/ + if ( ( !o.getPrefix().equals( i.getPrefix() ) ) + && ( ForesterUtil.isContainsPrefix( i.getPrefix(), o.getPrefix(), separator ) ) && ForesterUtil.isEqual( i.getConfidence(), o.getConfidence() ) ) { ok = false; @@ -374,7 +418,7 @@ public final class ResultMulti { } for( final String key : map.keySet() ) { for( final Prefix prefix : greatest_common_prefixes ) { - if ( prefix.getPrefix().startsWith( key ) ) { + if ( ForesterUtil.isContainsPrefix( prefix.getPrefix(), key, separator ) ) { map.put( key, map.get( key ) + prefix.getConfidence() ); } } diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 9cda7b7..e3666a8 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -219,7 +219,6 @@ public final class Test { succeeded++; } System.out.println( "OK." ); - System.out.print( "Common prefix: " ); if ( !testCommonPrefix() ) { System.out.println( "failed." ); @@ -229,7 +228,6 @@ public final class Test { succeeded++; } System.out.println( "OK." ); - System.out.print( "Common prefix sep: " ); if ( !testCommonPrefixSep() ) { System.out.println( "failed." ); @@ -239,8 +237,15 @@ public final class Test { succeeded++; } System.out.println( "OK." ); - - + System.out.print( "Contains prefix: " ); + if ( !testContainsPrefix() ) { + System.out.println( "failed." ); + failed++; + } + else { + succeeded++; + } + System.out.println( "OK." ); System.out.print( "Sequence writer: " ); if ( testSequenceWriter() ) { System.out.println( "OK." ); @@ -1122,7 +1127,6 @@ public final class Test { } } - private static boolean testEngulfingOverlapRemoval() { try { final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 ); @@ -1132,7 +1136,7 @@ public final class Test { final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 ); final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 ); final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 ); - final List covered = new ArrayList(); + final List covered = new ArrayList<>(); covered.add( true ); // 0 covered.add( false ); // 1 covered.add( true ); // 2 @@ -1364,7 +1368,7 @@ public final class Test { final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 ); final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 ); final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 ); - final List covered = new ArrayList(); + final List covered = new ArrayList<>(); covered.add( true ); // 0 covered.add( false ); // 1 covered.add( true ); // 2 @@ -1885,30 +1889,26 @@ public final class Test { return true; } - private static boolean testCommonPrefix() { - final List l0 = new ArrayList(); + final List l0 = new ArrayList<>(); l0.add( "abc" ); if ( !ForesterUtil.greatestCommonPrefix( l0 ).equals( "abc" ) ) { return false; } - - final List l1 = new ArrayList(); + final List l1 = new ArrayList<>(); l1.add( "abc" ); l1.add( "abX" ); if ( !ForesterUtil.greatestCommonPrefix( l1 ).equals( "ab" ) ) { return false; } - - final List l2 = new ArrayList(); + final List l2 = new ArrayList<>(); l2.add( "abc" ); l2.add( "abX" ); l2.add( "axy" ); if ( !ForesterUtil.greatestCommonPrefix( l2 ).equals( "a" ) ) { return false; } - - final List l3 = new ArrayList(); + final List l3 = new ArrayList<>(); l3.add( "abXsdfsdfsdfsdfsdfsd" ); l3.add( "abXsdfsdfsdfsdfsdfsd" ); l3.add( "abc" ); @@ -1919,8 +1919,7 @@ public final class Test { if ( !ForesterUtil.greatestCommonPrefix( l3 ).equals( "ab" ) ) { return false; } - - final List l4 = new ArrayList(); + final List l4 = new ArrayList<>(); l4.add( "abXsdfsdfsdfsdfsdfsd" ); l4.add( "abXsdfsdfsdfsdfsdfsd" ); l4.add( "abc" ); @@ -1930,14 +1929,12 @@ public final class Test { if ( !ForesterUtil.greatestCommonPrefix( l4 ).equals( "" ) ) { return false; } - - final List l5 = new ArrayList(); + final List l5 = new ArrayList<>(); l5.add( "" ); if ( !ForesterUtil.greatestCommonPrefix( l5 ).equals( "" ) ) { return false; } - - final List l6 = new ArrayList(); + final List l6 = new ArrayList<>(); l6.add( "abc" ); l6.add( "abX" ); l6.add( "" ); @@ -1946,30 +1943,27 @@ public final class Test { } return true; } - + private static boolean testCommonPrefixSep() { - final List l0 = new ArrayList(); + final List l0 = new ArrayList<>(); l0.add( "a.b.c" ); - if ( !ForesterUtil.greatestCommonPrefix( l0, ".").equals( "a.b.c" ) ) { + if ( !ForesterUtil.greatestCommonPrefix( l0, "." ).equals( "a.b.c" ) ) { return false; } - - final List l1 = new ArrayList(); + final List l1 = new ArrayList<>(); l1.add( "a.b.c" ); l1.add( "a.b.X" ); - if ( !ForesterUtil.greatestCommonPrefix( l1 , ".").equals( "a.b" ) ) { + if ( !ForesterUtil.greatestCommonPrefix( l1, "." ).equals( "a.b" ) ) { return false; } - - final List l2 = new ArrayList(); + final List l2 = new ArrayList<>(); l2.add( "a.b.c." ); l2.add( "a.b.X." ); l2.add( "a.x.y." ); - if ( !ForesterUtil.greatestCommonPrefix( l2, ".").equals( "a" ) ) { + if ( !ForesterUtil.greatestCommonPrefix( l2, "." ).equals( "a" ) ) { return false; } - - final List l3 = new ArrayList(); + final List l3 = new ArrayList<>(); l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d/" ); l3.add( "a/b/X/s/d/f/s/d/f/s/d/f/s/d/f/s/d/f/s/d" ); l3.add( "a/b/c" ); @@ -1980,8 +1974,7 @@ public final class Test { if ( !ForesterUtil.greatestCommonPrefix( l3, "/" ).equals( "a/b" ) ) { return false; } - - final List l4 = new ArrayList(); + final List l4 = new ArrayList<>(); l4.add( "a.b.X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d" ); l4.add( "a.b.X.s.d.f.s.d.f.s.d.f.s.d.f.s.d.f.s.d" ); l4.add( "a.b.c" ); @@ -1991,21 +1984,18 @@ public final class Test { if ( !ForesterUtil.greatestCommonPrefix( l4, "." ).equals( "" ) ) { return false; } - - final List l5 = new ArrayList(); + final List l5 = new ArrayList<>(); l5.add( "" ); if ( !ForesterUtil.greatestCommonPrefix( l5, "_" ).equals( "" ) ) { return false; } - - final List l6 = new ArrayList(); + final List l6 = new ArrayList<>(); l6.add( "_" ); l6.add( "__" ); if ( !ForesterUtil.greatestCommonPrefix( l6, "_" ).equals( "" ) ) { return false; } - - final List l7 = new ArrayList(); + final List l7 = new ArrayList<>(); l7.add( "a,b,c" ); l7.add( "a,b,X" ); l7.add( "" ); @@ -2013,26 +2003,75 @@ public final class Test { if ( !ForesterUtil.greatestCommonPrefix( l7, "," ).equals( "" ) ) { return false; } - - final List l8 = new ArrayList(); + final List l8 = new ArrayList<>(); l8.add( "123.304.403.04" ); l8.add( "123.304.403.04.02" ); l8.add( "123.304.403.03.03" ); if ( !ForesterUtil.greatestCommonPrefix( l8, "." ).equals( "123.304.403" ) ) { return false; } - - final List l9 = new ArrayList(); + final List l9 = new ArrayList<>(); l9.add( "123.304.403.04" ); l9.add( "123.304.403.04.02" ); l9.add( "123.304.402.03.03" ); if ( !ForesterUtil.greatestCommonPrefix( l9, "." ).equals( "123.304" ) ) { return false; } + final List l10 = new ArrayList<>(); + l10.add( "abcde" ); + l10.add( "adc" ); + if ( !ForesterUtil.greatestCommonPrefix( l10, "." ).equals( "" ) ) { + return false; + } + return true; + } + + private static boolean testContainsPrefix() { + if ( !ForesterUtil.isContainsPrefix( "a.b", "a", "." ) ) { + return false; + } + if ( !ForesterUtil.isContainsPrefix( "a.b.c", "a", "." ) ) { + return false; + } + if ( !ForesterUtil.isContainsPrefix( "a.b.c", "a.b", "." ) ) { + return false; + } + if ( !ForesterUtil.isContainsPrefix( "a.b", "a.b", "." ) ) { + return false; + } + if ( !ForesterUtil.isContainsPrefix( "a", "a", "." ) ) { + return false; + } + if ( !ForesterUtil.isContainsPrefix( ".a.b", ".a", "." ) ) { + return false; + } + if ( !ForesterUtil.isContainsPrefix( ".a.b.", ".a", "." ) ) { + return false; + } + if ( !ForesterUtil.isContainsPrefix( ".a.b.", ".a.", "." ) ) { + return false; + } + if ( !ForesterUtil.isContainsPrefix( "a..b.", "a", "." ) ) { + return false; + } + if ( !ForesterUtil.isContainsPrefix( "a..b.", "a..", "." ) ) { + return false; + } + if ( ForesterUtil.isContainsPrefix( "a", "a.b", "." ) ) { + return false; + } + if ( ForesterUtil.isContainsPrefix( "a_b", "a", "." ) ) { + return false; + } + if ( ForesterUtil.isContainsPrefix( ".a.", ".a.b.", "." ) ) { + return false; + } + if ( ForesterUtil.isContainsPrefix( "a.b.c", "a.x", "." ) ) { + return false; + } return true; } - private static boolean testUTF8ParsingFromFile() { try { final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser(); @@ -3167,7 +3206,7 @@ public final class Test { p.addProteinDomain( A20 ); p.addProteinDomain( B25 ); p.addProteinDomain( D80 ); - List domains_ids = new ArrayList(); + List domains_ids = new ArrayList<>(); domains_ids.add( "A" ); domains_ids.add( "B" ); domains_ids.add( "C" ); @@ -3184,7 +3223,7 @@ public final class Test { if ( p.contains( domains_ids, true ) ) { return false; } - domains_ids = new ArrayList(); + domains_ids = new ArrayList<>(); domains_ids.add( "A" ); domains_ids.add( "C" ); domains_ids.add( "D" ); @@ -3194,7 +3233,7 @@ public final class Test { if ( !p.contains( domains_ids, true ) ) { return false; } - domains_ids = new ArrayList(); + domains_ids = new ArrayList<>(); domains_ids.add( "A" ); domains_ids.add( "D" ); domains_ids.add( "C" ); @@ -3204,7 +3243,7 @@ public final class Test { if ( p.contains( domains_ids, true ) ) { return false; } - domains_ids = new ArrayList(); + domains_ids = new ArrayList<>(); domains_ids.add( "A" ); domains_ids.add( "A" ); domains_ids.add( "B" ); @@ -3214,7 +3253,7 @@ public final class Test { if ( !p.contains( domains_ids, true ) ) { return false; } - domains_ids = new ArrayList(); + domains_ids = new ArrayList<>(); domains_ids.add( "A" ); domains_ids.add( "A" ); domains_ids.add( "A" ); @@ -3226,7 +3265,7 @@ public final class Test { if ( !p.contains( domains_ids, true ) ) { return false; } - domains_ids = new ArrayList(); + domains_ids = new ArrayList<>(); domains_ids.add( "A" ); domains_ids.add( "A" ); domains_ids.add( "B" ); @@ -3255,7 +3294,7 @@ public final class Test { private static boolean testBasicTable() { try { - final BasicTable t0 = new BasicTable(); + final BasicTable t0 = new BasicTable<>(); if ( t0.getNumberOfColumns() != 0 ) { return false; } @@ -3954,7 +3993,7 @@ public final class Test { final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 ); final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 ); final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 ); - final ArrayList domains0 = new ArrayList(); + final ArrayList domains0 = new ArrayList<>(); domains0.add( d2 ); domains0.add( d0 ); domains0.add( d3 ); @@ -3973,7 +4012,7 @@ public final class Test { if ( ds1.getNumberOfDomains() != 4 ) { return false; } - final ArrayList domains1 = new ArrayList(); + final ArrayList domains1 = new ArrayList<>(); domains1.add( d1 ); domains1.add( d2 ); domains1.add( d4 ); @@ -5710,7 +5749,7 @@ public final class Test { private static boolean testGeneralTable() { try { - final GeneralTable t0 = new GeneralTable(); + final GeneralTable t0 = new GeneralTable<>(); t0.setValue( 3, 2, "23" ); t0.setValue( 10, 1, "error" ); t0.setValue( 10, 1, "110" ); @@ -5746,7 +5785,7 @@ public final class Test { if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) { return false; } - final GeneralTable t1 = new GeneralTable(); + final GeneralTable t1 = new GeneralTable<>(); t1.setValue( "3", "2", "23" ); t1.setValue( "10", "1", "error" ); t1.setValue( "10", "1", "110" ); @@ -6757,7 +6796,7 @@ public final class Test { private static boolean testMafft( final String path ) { try { - final List opts = new ArrayList(); + final List opts = new ArrayList<>(); opts.add( "--maxiterate" ); opts.add( "1000" ); opts.add( "--localpair" ); @@ -6853,7 +6892,7 @@ public final class Test { final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" ); final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" ); final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" ); - final List l = new ArrayList(); + final List l = new ArrayList<>(); l.add( s0 ); l.add( s1 ); l.add( s2 ); @@ -6894,7 +6933,7 @@ public final class Test { final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" ); final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" ); final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" ); - final List l = new ArrayList(); + final List l = new ArrayList<>(); l.add( s0 ); l.add( s1 ); l.add( s2 ); @@ -6917,7 +6956,7 @@ public final class Test { // 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 l2 = new ArrayList(); + final List l2 = new ArrayList<>(); l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) ); l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) ); l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) ); @@ -6961,7 +7000,7 @@ public final class Test { final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" ); final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" ); final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" ); - final List l0 = new ArrayList(); + final List l0 = new ArrayList<>(); l0.add( s0 ); l0.add( s1 ); l0.add( s2 ); @@ -7009,7 +7048,7 @@ public final class Test { 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 l1 = new ArrayList(); + final List l1 = new ArrayList<>(); l1.add( s_0 ); l1.add( s_1 ); l1.add( s_2 ); @@ -7049,7 +7088,7 @@ public final class Test { 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 l2 = new ArrayList(); + final List l2 = new ArrayList<>(); l2.add( s__0 ); l2.add( s__1 ); l2.add( s__2 ); @@ -7115,7 +7154,7 @@ public final class Test { try { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); PhylogenyNode n; - List ext = new ArrayList(); + List ext = new ArrayList<>(); 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 ); @@ -7150,7 +7189,7 @@ public final class Test { t1.getNode( "cd" ).setCollapse( true ); t1.getNode( "cde" ).setCollapse( true ); n = t1.getNode( "ab" ); - ext = new ArrayList(); + ext = new ArrayList<>(); while ( n != null ) { ext.add( n ); n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); @@ -7181,7 +7220,7 @@ public final class Test { t2.getNode( "e" ).setCollapse( true ); t2.getNode( "gh" ).setCollapse( true ); n = t2.getNode( "ab" ); - ext = new ArrayList(); + ext = new ArrayList<>(); while ( n != null ) { ext.add( n ); n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); @@ -7210,7 +7249,7 @@ public final class Test { t3.getNode( "gh" ).setCollapse( true ); t3.getNode( "fgh" ).setCollapse( true ); n = t3.getNode( "ab" ); - ext = new ArrayList(); + ext = new ArrayList<>(); while ( n != null ) { ext.add( n ); n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); @@ -12526,7 +12565,7 @@ public final class Test { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ]; //Archaeopteryx.createApplication( p0 ); - final Set ex = new HashSet(); + final Set ex = new HashSet<>(); ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); @@ -12539,13 +12578,13 @@ public final class Test { final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex ); // System.out.println( s0.toString() ); // - Set query_nodes = new HashSet(); + Set query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); @@ -12557,7 +12596,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); @@ -12565,7 +12604,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); @@ -12574,7 +12613,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); @@ -12583,20 +12622,20 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); if ( !s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); if ( !s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); @@ -12605,14 +12644,14 @@ public final class Test { if ( !s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); if ( !s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); @@ -12620,13 +12659,13 @@ public final class Test { if ( !s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); @@ -12634,7 +12673,7 @@ public final class Test { if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); @@ -12643,71 +12682,71 @@ public final class Test { if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -12780,7 +12819,7 @@ public final class Test { // return false; // } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); @@ -12789,7 +12828,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -12799,7 +12838,7 @@ public final class Test { } /////////////////////////// // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -12808,7 +12847,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -12817,7 +12856,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -12826,7 +12865,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -12835,7 +12874,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -12844,7 +12883,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); @@ -12852,7 +12891,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -12862,7 +12901,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -12872,7 +12911,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); @@ -12882,7 +12921,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); @@ -12904,7 +12943,7 @@ public final class Test { try { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ]; - final Set ex = new HashSet(); + final Set ex = new HashSet<>(); ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); @@ -12913,13 +12952,13 @@ public final class Test { ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex ); - Set query_nodes = new HashSet(); + Set query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); if ( s0.match( query_nodes ) ) { return false; } - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); @@ -12931,7 +12970,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); @@ -12939,7 +12978,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); @@ -12948,7 +12987,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); @@ -12957,7 +12996,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); @@ -12965,14 +13004,14 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); if ( !s0.match( query_nodes ) ) { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); @@ -12982,7 +13021,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); @@ -12990,7 +13029,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); @@ -12999,14 +13038,14 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); if ( s0.match( query_nodes ) ) { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); @@ -13015,7 +13054,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); @@ -13025,7 +13064,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); @@ -13033,49 +13072,49 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); if ( s0.match( query_nodes ) ) { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); if ( s0.match( query_nodes ) ) { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) ); if ( s0.match( query_nodes ) ) { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); if ( s0.match( query_nodes ) ) { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); if ( s0.match( query_nodes ) ) { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); if ( s0.match( query_nodes ) ) { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) ); @@ -13083,7 +13122,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); @@ -13091,7 +13130,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -13099,7 +13138,7 @@ public final class Test { return false; } // - query_nodes = new HashSet(); + query_nodes = new HashSet<>(); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) ); query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) ); @@ -13634,12 +13673,11 @@ public final class Test { } return true; } - + private static boolean testPhylogenyMethods() { try { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)r", new NHXParser() )[ 0 ]; - if ( PhylogenyMethods.calculateLevel( t0.getNode( "A" ) ) != 0 ) { return false; } @@ -13667,7 +13705,8 @@ public final class Test { if ( PhylogenyMethods.calculateLevel( t0.getNode( "r" ) ) != 4 ) { return false; } - final Phylogeny t1 = factory.create( "((((A,B)ab,C)abc,D)abcd,E,((((((X)1)2)3)4)5)6)r", new NHXParser() )[ 0 ]; + final Phylogeny t1 = factory.create( "((((A,B)ab,C)abc,D)abcd,E,((((((X)1)2)3)4)5)6)r", + new NHXParser() )[ 0 ]; if ( PhylogenyMethods.calculateLevel( t1.getNode( "r" ) ) != 7 ) { return false; } @@ -13695,7 +13734,6 @@ public final class Test { if ( PhylogenyMethods.calculateLevel( t1.getNode( "abcd" ) ) != 3 ) { return false; } - } catch ( final Exception e ) { e.printStackTrace( System.out ); diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index 5d70578..6c14975 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -407,7 +407,7 @@ public final class ForesterUtil { } public static String[][] file22dArray( final File file ) throws IOException { - final List list = new ArrayList(); + final List list = new ArrayList<>(); final BufferedReader in = new BufferedReader( new FileReader( file ) ); String str; while ( ( str = in.readLine() ) != null ) { @@ -445,7 +445,7 @@ public final class ForesterUtil { } final public static List file2list( final File file ) throws IOException { - final List list = new ArrayList(); + final List list = new ArrayList<>(); final BufferedReader in = new BufferedReader( new FileReader( file ) ); String str; while ( ( str = in.readLine() ) != null ) { @@ -461,7 +461,7 @@ public final class ForesterUtil { } final public static SortedSet file2set( final File file ) throws IOException { - final SortedSet set = new TreeSet(); + final SortedSet set = new TreeSet<>(); final BufferedReader in = new BufferedReader( new FileReader( file ) ); String str; while ( ( str = in.readLine() ) != null ) { @@ -543,8 +543,8 @@ public final class ForesterUtil { final public static MolecularSequence.TYPE guessMolecularSequenceType( final String mol_seq ) { final String s = mol_seq.toUpperCase(); - if ( s.contains( "L" ) || s.contains( "I" ) || s.contains( "E" ) || s.contains( "H" ) - || s.contains( "D" ) || s.contains( "Q" ) ) { + if ( s.contains( "L" ) || s.contains( "I" ) || s.contains( "E" ) || s.contains( "H" ) || s.contains( "D" ) + || s.contains( "Q" ) ) { return TYPE.AA; } else { @@ -723,7 +723,7 @@ public final class ForesterUtil { } return null; } - + final public static String isWritableFile( final String s ) { return isWritableFile( new File( s ) ); } @@ -744,7 +744,7 @@ public final class ForesterUtil { } final public static SortedMap listToSortedCountsMap( final List list ) { - final SortedMap map = new TreeMap(); + final SortedMap map = new TreeMap<>(); for( final Object key : list ) { if ( !map.containsKey( key ) ) { map.put( key, 1 ); @@ -1176,7 +1176,7 @@ public final class ForesterUtil { //urlc.setRequestProperty( "User-Agent", "" ); final BufferedReader in = new BufferedReader( new InputStreamReader( urlc.getInputStream() ) ); String line; - final List result = new ArrayList(); + final List result = new ArrayList<>(); while ( ( line = in.readLine() ) != null ) { result.add( line ); } @@ -1211,7 +1211,7 @@ public final class ForesterUtil { protein.getSpecies().getSpeciesId(), protein.getLength() ); final List sorted = SurfacingUtil.sortDomainsWithAscendingConfidenceValues( protein ); - final List covered_positions = new ArrayList(); + final List covered_positions = new ArrayList<>(); for( final Domain domain : sorted ) { if ( ( ( max_allowed_overlap < 0 ) || ( ForesterUtil.calculateOverlap( domain, covered_positions ) <= max_allowed_overlap ) ) @@ -1518,7 +1518,7 @@ public final class ForesterUtil { is.close(); } catch ( final Exception e ) { - // ignore + // ignore } return trees; } @@ -1550,7 +1550,7 @@ public final class ForesterUtil { File the_one = null; do { int matches = 0; - for( File file : files ) { + for( final File file : files ) { if ( file.getName().startsWith( my_prefix ) ) { matches++; if ( matches > 1 ) { @@ -1598,6 +1598,24 @@ public final class ForesterUtil { return a.substring( 0, min_length ); } + public final static boolean isContainsPrefix( final String word, final String prefix, final String separator ) { + if ( ForesterUtil.isEmpty( separator ) ) { + throw new IllegalArgumentException( "separator must not be null or empty" ); + } + final String[] word_ary = word.split( Pattern.quote( separator ) ); + final String[] prefix_ary = prefix.split( Pattern.quote( separator ) ); + if ( word_ary.length < prefix_ary.length ) { + return false; + } + final int prefix_ary_length = prefix_ary.length; + for( int i = 0; i < prefix_ary_length; ++i ) { + if ( !( word_ary[ i ].equals( prefix_ary[ i ] ) ) ) { + return false; + } + } + return true; + } + public final static String greatestCommonPrefix( final String a, final String b, final String separator ) { if ( ForesterUtil.isEmpty( separator ) ) { throw new IllegalArgumentException( "separator must not be null or empty" ); @@ -1607,7 +1625,7 @@ public final class ForesterUtil { final int min_length = Math.min( as.length, bs.length ); for( int i = 0; i < min_length; ++i ) { if ( !( as[ i ].equals( bs[ i ] ) ) ) { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); boolean first = true; for( int j = 0; j < i; ++j ) { if ( first ) { @@ -1621,7 +1639,7 @@ public final class ForesterUtil { return sb.toString(); } } - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); boolean first = true; for( int j = 0; j < min_length; ++j ) { if ( first ) { @@ -1666,12 +1684,9 @@ public final class ForesterUtil { return common; } - 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(); + 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 ) { @@ -1680,15 +1695,16 @@ public final class ForesterUtil { sb.append( separator ); } } - // System.out.println( sb.toString() ); l.add( sb.toString() ); } return l; } - // public static boolean isLooksLikeFasta( final File file ) throws IOException { final String first_line = ForesterUtil.getFirstLine( file ).trim().toLowerCase(); return ( ( !isEmptyTrimmed( first_line ) && first_line.trim().startsWith( ">" ) ) ); } + + private ForesterUtil() { + } } -- 1.7.10.2