From: cmzmasek@gmail.com Date: Tue, 18 Oct 2011 22:50:08 +0000 (+0000) Subject: in progress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9c8c68df524fe97f22fd19bec72dba51b06fcf43;p=jalview.git in progress --- diff --git a/forester/java/src/org/forester/application/surfacing.java b/forester/java/src/org/forester/application/surfacing.java index 42883c6..b795c3e 100644 --- a/forester/java/src/org/forester/application/surfacing.java +++ b/forester/java/src/org/forester/application/surfacing.java @@ -36,7 +36,6 @@ import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; @@ -232,8 +231,8 @@ public class surfacing { final static private String INPUT_SPECIES_TREE_OPTION = "species_tree"; final static private String SEQ_EXTRACT_OPTION = "prot_extract"; final static private char SEPARATOR_FOR_INPUT_VALUES = '#'; - final static private String PRG_VERSION = "2.100"; - final static private String PRG_DATE = "2011.06.17"; + final static private String PRG_VERSION = "2.200"; + final static private String PRG_DATE = "2011.10.18"; final static private String E_MAIL = "czmasek@burnham.org"; final static private String WWW = "www.phylosoft.org/forester/applications/surfacing"; final static private boolean IGNORE_DUFS_DEFAULT = true; @@ -1727,14 +1726,8 @@ public class surfacing { final SortedSet domains_which_are_always_single = new TreeSet(); final SortedSet domains_which_are_sometimes_single_sometimes_not = new TreeSet(); final SortedSet domains_which_never_single = new TreeSet(); - final BufferedWriter domains_which_are_always_single_writer = null; - final BufferedWriter domains_which_are_sometimes_single_sometimes_not_writer = null; - final BufferedWriter domains_which_never_single_writer = null; - BufferedWriter all_genomes_domains_per_potein_histo_writer = null; BufferedWriter domains_per_potein_stats_writer = null; try { - all_genomes_domains_per_potein_histo_writer = new BufferedWriter( new FileWriter( out_dir - + ForesterUtil.FILE_SEPARATOR + output_file + "__all_genomes_domains_per_potein_histo.txt" ) ); domains_per_potein_stats_writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + "__domains_per_potein_stats.txt" ) ); domains_per_potein_stats_writer.write( "Genome" ); @@ -1990,16 +1983,18 @@ public class surfacing { domains_per_potein_stats_writer.write( "\n" ); domains_per_potein_stats_writer.flush(); domains_per_potein_stats_writer.close(); - for( final Entry entry : all_genomes_domains_per_potein_histo.entrySet() ) { - all_genomes_domains_per_potein_histo_writer.write( entry.getKey() + "\t" + entry.getValue() + "\n" ); - } - all_genomes_domains_per_potein_histo_writer.flush(); - all_genomes_domains_per_potein_histo_writer.close(); + ForesterUtil.map2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + + "__all_genomes_domains_per_potein_histo.txt" ), all_genomes_domains_per_potein_histo, "\t", "\n" ); + ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + + "__domains_always_single_.txt" ), domains_which_are_always_single, "\n" ); + ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + + "__domains_single_or_combined.txt" ), domains_which_are_sometimes_single_sometimes_not, "\n" ); + ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + + "__domains_always_combined.txt" ), domains_which_never_single, "\n" ); } catch ( final IOException e2 ) { ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() ); } - // if ( query_domains_writer_ary != null ) { for( int j = 0; j < query_domain_ids_array.length; j++ ) { try { diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index 78b01ea..5af580b 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -38,6 +38,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringReader; +import java.io.Writer; import java.math.BigDecimal; import java.net.URL; import java.text.DateFormat; @@ -47,10 +48,12 @@ import java.text.NumberFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; @@ -220,6 +223,27 @@ public final class ForesterUtil { return s.replaceAll( "[\\s]+", " " ); } + final public static void collection2file( final File file, final Collection data, final String separator ) + throws IOException { + final Writer writer = new BufferedWriter( new FileWriter( file ) ); + collection2writer( writer, data, separator ); + writer.close(); + } + + final public static void collection2writer( final Writer writer, final Collection data, final String separator ) + throws IOException { + boolean first = true; + for( final Object object : data ) { + if ( !first ) { + writer.write( separator ); + } + else { + first = false; + } + writer.write( object.toString() ); + } + } + final public static String colorToHex( final Color color ) { final String rgb = Integer.toHexString( color.getRGB() ); return rgb.substring( 2, rgb.length() ); @@ -536,6 +560,33 @@ public final class ForesterUtil { return map; } + final public static void map2file( final File file, + final Map data, + final String entry_separator, + final String data_separator ) throws IOException { + final Writer writer = new BufferedWriter( new FileWriter( file ) ); + map2writer( writer, data, entry_separator, data_separator ); + writer.close(); + } + + final public static void map2writer( final Writer writer, + final Map data, + final String entry_separator, + final String data_separator ) throws IOException { + for( final Entry entry : data.entrySet() ) { + boolean first = true; + if ( !first ) { + writer.write( data_separator ); + } + else { + first = false; + } + writer.write( entry.getKey().toString() ); + writer.write( entry_separator ); + writer.write( entry.getValue().toString() ); + } + } + final public static StringBuffer mapToStringBuffer( final Map map, final String key_value_separator ) { final StringBuffer sb = new StringBuffer(); for( final Iterator iter = map.keySet().iterator(); iter.hasNext(); ) { @@ -772,6 +823,10 @@ public final class ForesterUtil { return str.split( regex ); } + final public static String stringArrayToString( final String[] a ) { + return stringArrayToString( a, ", " ); + } + final public static String stringArrayToString( final String[] a, final String separator ) { final StringBuilder sb = new StringBuilder(); if ( ( a != null ) && ( a.length > 0 ) ) { @@ -783,6 +838,18 @@ public final class ForesterUtil { return sb.toString(); } + final public static String[] stringListToArray( final List list ) { + if ( list != null ) { + final String[] str = new String[ list.size() ]; + int i = 0; + for( final String l : list ) { + str[ i++ ] = l; + } + return str; + } + return null; + } + final public static String stringListToString( final List l, final String separator ) { final StringBuilder sb = new StringBuilder(); if ( ( l != null ) && ( l.size() > 0 ) ) { @@ -794,10 +861,6 @@ public final class ForesterUtil { return sb.toString(); } - final public static String stringArrayToString( final String[] a ) { - return stringArrayToString( a, ", " ); - } - final public static String[] stringSetToArray( final Set strings ) { final String[] str_array = new String[ strings.size() ]; int i = 0; @@ -807,18 +870,6 @@ public final class ForesterUtil { return str_array; } - final public static String[] stringListToArray( final List list ) { - if ( list != null ) { - final String[] str = new String[ list.size() ]; - int i = 0; - for( final String l : list ) { - str[ i++ ] = l; - } - return str; - } - return null; - } - final public static void unexpectedFatalError( final String prg_name, final Exception e ) { System.err.println(); System.err.println( "[" + prg_name