inprogress
[jalview.git] / forester / java / src / org / forester / surfacing / SurfacingUtil.java
index cb9df26..ecb0839 100644 (file)
@@ -82,8 +82,8 @@ import org.forester.protein.Domain;
 import org.forester.protein.Protein;
 import org.forester.species.Species;
 import org.forester.surfacing.DomainSimilarityCalculator.Detailedness;
-import org.forester.surfacing.DomainSimilarityCalculator.GoAnnotationOutput;
 import org.forester.surfacing.GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder;
+import org.forester.surfacing.PrintableDomainSimilarity.PRINT_OPTION;
 import org.forester.util.AsciiHistogram;
 import org.forester.util.BasicDescriptiveStatistics;
 import org.forester.util.BasicTable;
@@ -152,6 +152,25 @@ public final class SurfacingUtil {
         w.write( SurfacingConstants.NL );
         w.write( "a:hover { color : #FFFFFF; background-color : #99FF00; text-decoration : none; }" );
         w.write( SurfacingConstants.NL );
+        //
+        w.write( "a.pl:visited { color : #505050; text-decoration : none; font-size: 7pt;}" );
+        w.write( SurfacingConstants.NL );
+        w.write( "a.pl:link { color : #505050; text-decoration : none; font-size: 7pt;}" );
+        w.write( SurfacingConstants.NL );
+        w.write( "a.pl:active { color : #505050; text-decoration : none; font-size: 7pt;}" );
+        w.write( SurfacingConstants.NL );
+        w.write( "a.pl:hover { color : #FFFFFF; background-color : #99FF00; text-decoration : none; font-size: 7pt;}" );
+        w.write( SurfacingConstants.NL );
+        //
+        w.write( "a.ps:visited { color : #707070; text-decoration : none; font-size: 7pt;}" );
+        w.write( SurfacingConstants.NL );
+        w.write( "a.ps:link { color : #707070; text-decoration : none; font-size: 7pt;}" );
+        w.write( SurfacingConstants.NL );
+        w.write( "a.ps:active { color : #707070; text-decoration : none; font-size: 7pt;}" );
+        w.write( SurfacingConstants.NL );
+        w.write( "a.ps:hover { color : #FFFFFF; background-color : #99FF00; text-decoration : none; font-size: 7pt;}" );
+        w.write( SurfacingConstants.NL );
+        //
         w.write( "td { text-align: left; vertical-align: top; font-family: Verdana, Arial, Helvetica; font-size: 8pt}" );
         w.write( SurfacingConstants.NL );
         w.write( "h1 { color : #0000FF; font-family: Verdana, Arial, Helvetica; font-size: 18pt; font-weight: bold }" );
@@ -285,20 +304,11 @@ public final class SurfacingUtil {
     }
 
     public static void decoratePrintableDomainSimilarities( final SortedSet<DomainSimilarity> domain_similarities,
-                                                            final Detailedness detailedness,
-                                                            final GoAnnotationOutput go_annotation_output,
-                                                            final Map<GoId, GoTerm> go_id_to_term_map,
-                                                            final GoNameSpace go_namespace_limit ) {
-        if ( ( go_namespace_limit != null ) && ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) ) {
-            throw new IllegalArgumentException( "attempt to use a GO namespace limit without a GO id to term map" );
-        }
+                                                            final Detailedness detailedness ) {
         for( final DomainSimilarity domain_similarity : domain_similarities ) {
             if ( domain_similarity instanceof PrintableDomainSimilarity ) {
                 final PrintableDomainSimilarity printable_domain_similarity = ( PrintableDomainSimilarity ) domain_similarity;
                 printable_domain_similarity.setDetailedness( detailedness );
-                printable_domain_similarity.setGoAnnotationOutput( go_annotation_output );
-                printable_domain_similarity.setGoIdToTermMap( go_id_to_term_map );
-                printable_domain_similarity.setGoNamespaceLimit( go_namespace_limit );
             }
         }
     }
@@ -461,10 +471,6 @@ public final class SurfacingUtil {
                     out.write( species + "\t" );
                 }
                 out.write( ForesterUtil.LINE_SEPARATOR );
-                // DescriptiveStatistics stats_for_domain = domain_lengths
-                //         .calculateMeanBasedStatistics();
-                //AsciiHistogram histo = new AsciiHistogram( stats_for_domain );
-                //System.out.println( histo.toStringBuffer( 40, '=', 60, 4 ).toString() );
             }
         }
         out.write( ForesterUtil.LINE_SEPARATOR );
@@ -498,16 +504,6 @@ public final class SurfacingUtil {
             }
         }
         out.close();
-        //        final List<HistogramData> histogram_datas = new ArrayList<HistogramData>();
-        //        for( int i = 0; i < number_of_genomes; ++i ) {
-        //            final Species species = new BasicSpecies( input_file_properties[ i ][ 0 ] );
-        //            histogram_datas
-        //                    .add( new HistogramData( species.toString(), domain_lengths_table
-        //                            .calculateMeanBasedStatisticsForSpecies( species )
-        //                            .getDataAsDoubleArray(), 5, 600, null, 60 ) );
-        //        }
-        //        final HistogramsFrame hf = new HistogramsFrame( histogram_datas );
-        //        hf.setVisible( true );
         System.gc();
     }
 
@@ -1670,127 +1666,19 @@ public final class SurfacingUtil {
         }
     }
 
-    public static DescriptiveStatistics writeDomainSimilaritiesToFile( final StringBuilder html_desc,
-                                                                       final StringBuilder html_title,
-                                                                       final Writer single_writer,
-                                                                       Map<Character, Writer> split_writers,
-                                                                       final SortedSet<DomainSimilarity> similarities,
-                                                                       final boolean treat_as_binary,
-                                                                       final List<Species> species_order,
-                                                                       final PrintableDomainSimilarity.PRINT_OPTION print_option,
-                                                                       final DomainSimilarity.DomainSimilaritySortField sort_field,
-                                                                       final DomainSimilarity.DomainSimilarityScoring scoring,
-                                                                       final boolean verbose,
-                                                                       final Map<String, Integer> tax_code_to_id_map )
+    public static void writeDomainSimilaritiesToFile( final StringBuilder html_desc,
+                                                      final StringBuilder html_title,
+                                                      final Writer simple_tab_writer,
+                                                      final Writer single_writer,
+                                                      Map<Character, Writer> split_writers,
+                                                      final SortedSet<DomainSimilarity> similarities,
+                                                      final boolean treat_as_binary,
+                                                      final List<Species> species_order,
+                                                      final PrintableDomainSimilarity.PRINT_OPTION print_option,
+                                                      final DomainSimilarity.DomainSimilarityScoring scoring,
+                                                      final boolean verbose,
+                                                      final Map<String, Integer> tax_code_to_id_map )
             throws IOException {
-        final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
-        String histogram_title = null;
-        switch ( sort_field ) {
-            case ABS_MAX_COUNTS_DIFFERENCE:
-                if ( treat_as_binary ) {
-                    histogram_title = "absolute counts difference:";
-                }
-                else {
-                    histogram_title = "absolute (maximal) counts difference:";
-                }
-                break;
-            case MAX_COUNTS_DIFFERENCE:
-                if ( treat_as_binary ) {
-                    histogram_title = "counts difference:";
-                }
-                else {
-                    histogram_title = "(maximal) counts difference:";
-                }
-                break;
-            case DOMAIN_ID:
-                histogram_title = "score mean:";
-                break;
-            case MIN:
-                histogram_title = "score minimum:";
-                break;
-            case MAX:
-                histogram_title = "score maximum:";
-                break;
-            case MAX_DIFFERENCE:
-                if ( treat_as_binary ) {
-                    histogram_title = "difference:";
-                }
-                else {
-                    histogram_title = "(maximal) difference:";
-                }
-                break;
-            case MEAN:
-                histogram_title = "score mean:";
-                break;
-            case SD:
-                histogram_title = "score standard deviation:";
-                break;
-            case SPECIES_COUNT:
-                histogram_title = "species number:";
-                break;
-            default:
-                throw new AssertionError( "Unknown sort field: " + sort_field );
-        }
-        for( final DomainSimilarity similarity : similarities ) {
-            switch ( sort_field ) {
-                case ABS_MAX_COUNTS_DIFFERENCE:
-                    stats.addValue( Math.abs( similarity.getMaximalDifferenceInCounts() ) );
-                    break;
-                case MAX_COUNTS_DIFFERENCE:
-                    stats.addValue( similarity.getMaximalDifferenceInCounts() );
-                    break;
-                case DOMAIN_ID:
-                    stats.addValue( similarity.getMeanSimilarityScore() );
-                    break;
-                case MIN:
-                    stats.addValue( similarity.getMinimalSimilarityScore() );
-                    break;
-                case MAX:
-                    stats.addValue( similarity.getMaximalSimilarityScore() );
-                    break;
-                case MAX_DIFFERENCE:
-                    stats.addValue( similarity.getMaximalDifference() );
-                    break;
-                case MEAN:
-                    stats.addValue( similarity.getMeanSimilarityScore() );
-                    break;
-                case SD:
-                    stats.addValue( similarity.getStandardDeviationOfSimilarityScore() );
-                    break;
-                case SPECIES_COUNT:
-                    stats.addValue( similarity.getSpecies().size() );
-                    break;
-                default:
-                    throw new AssertionError( "Unknown sort field: " + sort_field );
-            }
-        }
-        AsciiHistogram histo = null;
-        if ( stats.getMin() < stats.getMin() ) {
-            histo = new AsciiHistogram( stats, histogram_title );
-        }
-        if ( verbose ) {
-            if ( histo != null ) {
-                System.out.println( histo.toStringBuffer( 20, '|', 40, 5 ) );
-            }
-            System.out.println();
-            System.out.println( "N                   : " + stats.getN() );
-            System.out.println( "Min                 : " + stats.getMin() );
-            System.out.println( "Max                 : " + stats.getMax() );
-            System.out.println( "Mean                : " + stats.arithmeticMean() );
-            if ( stats.getN() > 1 ) {
-                System.out.println( "SD                  : " + stats.sampleStandardDeviation() );
-            }
-            else {
-                System.out.println( "SD                  : n/a" );
-            }
-            System.out.println( "Median              : " + stats.median() );
-            if ( stats.getN() > 1 ) {
-                System.out.println( "Pearsonian skewness : " + stats.pearsonianSkewness() );
-            }
-            else {
-                System.out.println( "Pearsonian skewness : n/a" );
-            }
-        }
         if ( ( single_writer != null ) && ( ( split_writers == null ) || split_writers.isEmpty() ) ) {
             split_writers = new HashMap<Character, Writer>();
             split_writers.put( '_', single_writer );
@@ -1804,10 +1692,10 @@ public final class SurfacingUtil {
                     w.write( "<html>" );
                     w.write( SurfacingConstants.NL );
                     if ( key != '_' ) {
-                        addHtmlHead( w, "DCs (" + html_title + ") " + key.toString().toUpperCase() );
+                        addHtmlHead( w, "DC analysis (" + html_title + ") " + key.toString().toUpperCase() );
                     }
                     else {
-                        addHtmlHead( w, "DCs (" + html_title + ")" );
+                        addHtmlHead( w, "DC analysis (" + html_title + ")" );
                     }
                     w.write( SurfacingConstants.NL );
                     w.write( "<body>" );
@@ -1815,62 +1703,54 @@ public final class SurfacingUtil {
                     w.write( html_desc.toString() );
                     w.write( SurfacingConstants.NL );
                     w.write( "<hr>" );
-                    w.write( "<br>" );
-                    w.write( SurfacingConstants.NL );
-                    w.write( "<tt><pre>" );
-                    w.write( SurfacingConstants.NL );
-                    if ( histo != null ) {
-                        w.write( histo.toStringBuffer( 20, '|', 40, 5 ).toString() );
-                        w.write( SurfacingConstants.NL );
-                    }
-                    w.write( "</pre></tt>" );
-                    w.write( SurfacingConstants.NL );
-                    w.write( "<table>" );
-                    w.write( SurfacingConstants.NL );
-                    w.write( "<tr><td>N: </td><td>" + stats.getN() + "</td></tr>" );
-                    w.write( SurfacingConstants.NL );
-                    w.write( "<tr><td>Min: </td><td>" + stats.getMin() + "</td></tr>" );
-                    w.write( SurfacingConstants.NL );
-                    w.write( "<tr><td>Max: </td><td>" + stats.getMax() + "</td></tr>" );
-                    w.write( SurfacingConstants.NL );
-                    w.write( "<tr><td>Mean: </td><td>" + stats.arithmeticMean() + "</td></tr>" );
-                    w.write( SurfacingConstants.NL );
-                    if ( stats.getN() > 1 ) {
-                        w.write( "<tr><td>SD: </td><td>" + stats.sampleStandardDeviation() + "</td></tr>" );
-                    }
-                    else {
-                        w.write( "<tr><td>SD: </td><td>n/a</td></tr>" );
-                    }
-                    w.write( SurfacingConstants.NL );
-                    w.write( "<tr><td>Median: </td><td>" + stats.median() + "</td></tr>" );
-                    w.write( SurfacingConstants.NL );
-                    if ( stats.getN() > 1 ) {
-                        w.write( "<tr><td>Pearsonian skewness: </td><td>" + stats.pearsonianSkewness() + "</td></tr>" );
-                    }
-                    else {
-                        w.write( "<tr><td>Pearsonian skewness: </td><td>n/a</td></tr>" );
-                    }
-                    w.write( SurfacingConstants.NL );
-                    w.write( "</table>" );
-                    w.write( SurfacingConstants.NL );
-                    w.write( "<br>" );
-                    w.write( SurfacingConstants.NL );
-                    w.write( "<hr>" );
                     w.write( SurfacingConstants.NL );
                     w.write( "<br>" );
                     w.write( SurfacingConstants.NL );
                     w.write( "<table>" );
                     w.write( SurfacingConstants.NL );
+                    w.write( "<tr><td><b>Domains:</b></td></tr>" );
+                    w.write( SurfacingConstants.NL );
                 }
                 break;
         }
+        //
+        for( final DomainSimilarity similarity : similarities ) {
+            if ( ( species_order != null ) && !species_order.isEmpty() ) {
+                ( ( PrintableDomainSimilarity ) similarity ).setSpeciesOrder( species_order );
+            }
+            if ( single_writer != null ) {
+                single_writer.write( "<tr><td><b><a href=\"#" + similarity.getDomainId() + "\">"
+                        + similarity.getDomainId() + "</a></b></td></tr>" );
+                single_writer.write( SurfacingConstants.NL );
+            }
+            else {
+                Writer local_writer = split_writers.get( ( similarity.getDomainId().charAt( 0 ) + "" ).toLowerCase()
+                        .charAt( 0 ) );
+                if ( local_writer == null ) {
+                    local_writer = split_writers.get( '0' );
+                }
+                local_writer.write( "<tr><td><b><a href=\"#" + similarity.getDomainId() + "\">"
+                        + similarity.getDomainId() + "</a></b></td></tr>" );
+                local_writer.write( SurfacingConstants.NL );
+            }
+        }
         for( final Writer w : split_writers.values() ) {
+            w.write( "</table>" );
+            w.write( SurfacingConstants.NL );
+            w.write( "<hr>" );
+            w.write( SurfacingConstants.NL );
+            w.write( "<table>" );
             w.write( SurfacingConstants.NL );
         }
+        //
         for( final DomainSimilarity similarity : similarities ) {
             if ( ( species_order != null ) && !species_order.isEmpty() ) {
                 ( ( PrintableDomainSimilarity ) similarity ).setSpeciesOrder( species_order );
             }
+            if ( simple_tab_writer != null ) {
+                simple_tab_writer.write( similarity.toStringBuffer( PRINT_OPTION.SIMPLE_TAB_DELIMITED,
+                                                                    tax_code_to_id_map ).toString() );
+            }
             if ( single_writer != null ) {
                 single_writer.write( similarity.toStringBuffer( print_option, tax_code_to_id_map ).toString() );
                 single_writer.write( SurfacingConstants.NL );
@@ -1884,9 +1764,6 @@ public final class SurfacingUtil {
                 local_writer.write( similarity.toStringBuffer( print_option, tax_code_to_id_map ).toString() );
                 local_writer.write( SurfacingConstants.NL );
             }
-            // for( final Writer w : split_writers.values() ) {
-            //w.write( SurfacingConstants.NL );
-            // }
         }
         switch ( print_option ) {
             case HTML:
@@ -1906,7 +1783,42 @@ public final class SurfacingUtil {
         for( final Writer w : split_writers.values() ) {
             w.close();
         }
-        return stats;
+    }
+
+    private static void printSomeStats( final DescriptiveStatistics stats, final AsciiHistogram histo, final Writer w )
+            throws IOException {
+        w.write( "<hr>" );
+        w.write( "<br>" );
+        w.write( SurfacingConstants.NL );
+        w.write( "<tt><pre>" );
+        w.write( SurfacingConstants.NL );
+        if ( histo != null ) {
+            w.write( histo.toStringBuffer( 20, '|', 40, 5 ).toString() );
+            w.write( SurfacingConstants.NL );
+        }
+        w.write( "</pre></tt>" );
+        w.write( SurfacingConstants.NL );
+        w.write( "<table>" );
+        w.write( SurfacingConstants.NL );
+        w.write( "<tr><td>N: </td><td>" + stats.getN() + "</td></tr>" );
+        w.write( SurfacingConstants.NL );
+        w.write( "<tr><td>Min: </td><td>" + stats.getMin() + "</td></tr>" );
+        w.write( SurfacingConstants.NL );
+        w.write( "<tr><td>Max: </td><td>" + stats.getMax() + "</td></tr>" );
+        w.write( SurfacingConstants.NL );
+        w.write( "<tr><td>Mean: </td><td>" + stats.arithmeticMean() + "</td></tr>" );
+        w.write( SurfacingConstants.NL );
+        if ( stats.getN() > 1 ) {
+            w.write( "<tr><td>SD: </td><td>" + stats.sampleStandardDeviation() + "</td></tr>" );
+        }
+        else {
+            w.write( "<tr><td>SD: </td><td>n/a</td></tr>" );
+        }
+        w.write( SurfacingConstants.NL );
+        w.write( "</table>" );
+        w.write( SurfacingConstants.NL );
+        w.write( "<br>" );
+        w.write( SurfacingConstants.NL );
     }
 
     public static void writeMatrixToFile( final CharacterStateMatrix<?> matrix,