enable phylogram if positive bl edited
[jalview.git] / forester / java / src / org / forester / surfacing / DomainCountsDifferenceUtil.java
index 2a18c9c..a9643a8 100644 (file)
@@ -58,77 +58,11 @@ import org.forester.util.ForesterUtil;
  */
 public final class DomainCountsDifferenceUtil {
 
-    private static final COPY_CALCULATION_MODE COPY_CALC_MODE_FOR_HIGH_COPY_TARGET_SPECIES = COPY_CALCULATION_MODE.MIN;
     private static final COPY_CALCULATION_MODE COPY_CALC_MODE_FOR_HIGH_COPY_BASE_SPECIES   = COPY_CALCULATION_MODE.MIN;
+    private static final COPY_CALCULATION_MODE COPY_CALC_MODE_FOR_HIGH_COPY_TARGET_SPECIES = COPY_CALCULATION_MODE.MIN;
     private static final COPY_CALCULATION_MODE COPY_CALC_MODE_FOR_LOW_COPY_SPECIES         = COPY_CALCULATION_MODE.MAX;
     private static final String                PLUS_MINUS_PROTEINS_FILE_DOM_SUFFIX         = ".prot";
 
-    //FIXME really needs to be tested! 
-    private static void addCounts( final SortedMap<BinaryDomainCombination, List<Integer>> copy_counts,
-                                   final BinaryDomainCombination dc,
-                                   final GenomeWideCombinableDomains genome,
-                                   final Set<BinaryDomainCombination> bdc ) {
-        if ( !copy_counts.containsKey( dc ) ) {
-            copy_counts.put( dc, new ArrayList<Integer>() );
-        }
-        if ( bdc.contains( dc )
-                && ( ( ( BasicCombinableDomains ) genome.get( dc.getId0() ) ).getCombiningDomains().get( dc.getId1() ) != null ) ) {
-            final int count = ( ( BasicCombinableDomains ) genome.get( dc.getId0() ) ).getCombiningDomains()
-                    .get( dc.getId1() );
-            copy_counts.get( dc ).add( count );
-        }
-        else {
-            copy_counts.get( dc ).add( 0 );
-        }
-    }
-
-    private static void addCounts( final SortedMap<String, List<Integer>> copy_counts,
-                                   final String domain,
-                                   final GenomeWideCombinableDomains genome ) {
-        if ( !copy_counts.containsKey( domain ) ) {
-            copy_counts.put( domain, new ArrayList<Integer>() );
-        }
-        if ( genome.contains( domain ) ) {
-            copy_counts.get( domain ).add( genome.get( domain ).getKeyDomainProteinsCount() );
-        }
-        else {
-            copy_counts.get( domain ).add( 0 );
-        }
-    }
-
-    private static StringBuilder addGoInformation( final String d,
-                                                   final Map<String, List<GoId>> domain_id_to_go_ids_map,
-                                                   final Map<GoId, GoTerm> go_id_to_term_map ) {
-        final StringBuilder sb = new StringBuilder();
-        if ( ( domain_id_to_go_ids_map == null ) || domain_id_to_go_ids_map.isEmpty()
-                || !domain_id_to_go_ids_map.containsKey( d ) ) {
-            return sb;
-        }
-        final List<GoId> go_ids = domain_id_to_go_ids_map.get( d );
-        for( int i = 0; i < go_ids.size(); ++i ) {
-            final GoId go_id = go_ids.get( i );
-            if ( go_id_to_term_map.containsKey( go_id ) ) {
-                appendGoTerm( sb, go_id_to_term_map.get( go_id ) );
-                sb.append( "<br>" );
-            }
-            else {
-                sb.append( "go id \"" + go_id + "\" not found [" + d + "]" );
-            }
-        }
-        return sb;
-    }
-
-    private static void appendGoTerm( final StringBuilder sb, final GoTerm go_term ) {
-        final GoId go_id = go_term.getGoId();
-        sb.append( "<a href=\"" + SurfacingConstants.AMIGO_LINK + go_id + "\" target=\"amigo_window\">" + go_id
-                + "</a>" );
-        sb.append( ":" );
-        sb.append( go_term.getName() );
-        sb.append( " [" );
-        sb.append( go_term.getGoNameSpace().toShortString() );
-        sb.append( "]" );
-    }
-
     public static void calculateCopyNumberDifferences( final List<GenomeWideCombinableDomains> genomes,
                                                        final SortedMap<Species, List<Protein>> protein_lists_per_species,
                                                        final List<String> high_copy_base_species,
@@ -153,7 +87,7 @@ public final class DomainCountsDifferenceUtil {
         if ( high_copy_base_species.contains( high_copy_target_species )
                 || low_copy_species.contains( high_copy_target_species ) ) {
             throw new IllegalArgumentException( "species [" + high_copy_target_species
-                    + "] appears in other list as well" );
+                                                + "] appears in other list as well" );
         }
         if ( min_diff < 0 ) {
             throw new IllegalArgumentException( "attempt to use negative addition [" + min_diff + "]" );
@@ -301,6 +235,72 @@ public final class DomainCountsDifferenceUtil {
         writeGoIdsToFile( passing_gos_writer, go_ids_of_passing_domains );
     }
 
+    //FIXME really needs to be tested!
+    private static void addCounts( final SortedMap<BinaryDomainCombination, List<Integer>> copy_counts,
+                                   final BinaryDomainCombination dc,
+                                   final GenomeWideCombinableDomains genome,
+                                   final Set<BinaryDomainCombination> bdc ) {
+        if ( !copy_counts.containsKey( dc ) ) {
+            copy_counts.put( dc, new ArrayList<Integer>() );
+        }
+        if ( bdc.contains( dc )
+                && ( ( ( BasicCombinableDomains ) genome.get( dc.getId0() ) ).getCombiningDomains().get( dc.getId1() ) != null ) ) {
+            final int count = ( ( BasicCombinableDomains ) genome.get( dc.getId0() ) ).getCombiningDomains()
+                    .get( dc.getId1() );
+            copy_counts.get( dc ).add( count );
+        }
+        else {
+            copy_counts.get( dc ).add( 0 );
+        }
+    }
+
+    private static void addCounts( final SortedMap<String, List<Integer>> copy_counts,
+                                   final String domain,
+                                   final GenomeWideCombinableDomains genome ) {
+        if ( !copy_counts.containsKey( domain ) ) {
+            copy_counts.put( domain, new ArrayList<Integer>() );
+        }
+        if ( genome.contains( domain ) ) {
+            copy_counts.get( domain ).add( genome.get( domain ).getKeyDomainProteinsCount() );
+        }
+        else {
+            copy_counts.get( domain ).add( 0 );
+        }
+    }
+
+    private static StringBuilder addGoInformation( final String d,
+                                                   final Map<String, List<GoId>> domain_id_to_go_ids_map,
+                                                   final Map<GoId, GoTerm> go_id_to_term_map ) {
+        final StringBuilder sb = new StringBuilder();
+        if ( ( domain_id_to_go_ids_map == null ) || domain_id_to_go_ids_map.isEmpty()
+                || !domain_id_to_go_ids_map.containsKey( d ) ) {
+            return sb;
+        }
+        final List<GoId> go_ids = domain_id_to_go_ids_map.get( d );
+        for( int i = 0; i < go_ids.size(); ++i ) {
+            final GoId go_id = go_ids.get( i );
+            if ( go_id_to_term_map.containsKey( go_id ) ) {
+                appendGoTerm( sb, go_id_to_term_map.get( go_id ) );
+                sb.append( "<br>" );
+            }
+            else {
+                sb.append( "go id \"" + go_id + "\" not found [" + d + "]" );
+            }
+        }
+        return sb;
+    }
+
+    private static void appendGoTerm( final StringBuilder sb, final GoTerm go_term ) {
+        final GoId go_id = go_term.getGoId();
+        sb.append( "<a href=\"" + SurfacingConstants.AMIGO_LINK + go_id + "\" target=\"amigo_window\">" + go_id
+                   + "</a>" );
+        sb.append( ":" );
+        sb.append( go_term.getName() );
+        sb.append( " [" );
+        sb.append( go_term.getGoNameSpace().toShortString() );
+        sb.append( "]" );
+    }
+
     private static void calculateDomainCountsBasedValue( final SortedMap<BinaryDomainCombination, Double> copy_values,
                                                          final SortedMap<BinaryDomainCombination, List<Integer>> copy_counts,
                                                          final BinaryDomainCombination bdc,
@@ -538,11 +538,11 @@ public final class DomainCountsDifferenceUtil {
                                                              final SortedMap<BinaryDomainCombination, Double> low_copy_values,
                                                              final SortedSet<BinaryDomainCombination> all_bdcs,
                                                              final Map<String, Set<BinaryDomainCombination>> bdcs_per_genome )
-            throws IOException {
+                                                                     throws IOException {
         int counter = 0;
         int total_absense_counter = 0;
         int not_total_absense_counter = 0;
-        SurfacingUtil.addHtmlHead( html_writer, "Binary Domain Combination Copy Differences" );
+        SurfacingUtil.writeHtmlHead( html_writer, "Binary Domain Combination Copy Differences" );
         html_writer.write( "<body><table>" );
         for( final BinaryDomainCombination bdc : all_bdcs ) {
             if ( ( high_copy_base_values.get( bdc ) > 0 ) && ( high_copy_target_values.get( bdc ) > 0 )
@@ -556,8 +556,8 @@ public final class DomainCountsDifferenceUtil {
                     }
                     ++counter;
                     html_writer.write( "<tr><td><a href=\"" + SurfacingConstants.PFAM_FAMILY_ID_LINK + bdc.getId0()
-                            + "\">" + bdc.getId0() + "</a> = <a href=\"" + SurfacingConstants.PFAM_FAMILY_ID_LINK
-                            + bdc.getId1() + "\">" + bdc.getId1() + "</a>" );
+                                       + "\">" + bdc.getId0() + "</a> = <a href=\"" + SurfacingConstants.PFAM_FAMILY_ID_LINK
+                                       + bdc.getId1() + "\">" + bdc.getId1() + "</a>" );
                     html_writer.write( "</td><td>" );
                     html_writer.write( "<table>" );
                     for( final GenomeWideCombinableDomains genome : genomes ) {
@@ -570,7 +570,7 @@ public final class DomainCountsDifferenceUtil {
                                                    bdcs_per_genome,
                                                    species,
                                                    html_writer,
-                                                   "#0000FF" );
+                                    "#0000FF" );
                             html_writer.write( "</tr>" );
                         }
                         else if ( low_copy_species.contains( species ) ) {
@@ -581,7 +581,7 @@ public final class DomainCountsDifferenceUtil {
                                                    bdcs_per_genome,
                                                    species,
                                                    html_writer,
-                                                   "#A0A0A0" );
+                                    "#A0A0A0" );
                             html_writer.write( "</tr>" );
                         }
                         else if ( high_copy_base_species.contains( species ) ) {
@@ -592,7 +592,7 @@ public final class DomainCountsDifferenceUtil {
                                                    bdcs_per_genome,
                                                    species,
                                                    html_writer,
-                                                   "#404040" );
+                                    "#404040" );
                             html_writer.write( "</tr>" );
                         }
                     }
@@ -662,11 +662,11 @@ public final class DomainCountsDifferenceUtil {
                                                   final SortedSet<String> all_domains,
                                                   final SortedSet<GoId> go_ids_of_passing_domains,
                                                   final SortedMap<Species, List<Protein>> protein_lists_per_species )
-            throws IOException {
+                                                          throws IOException {
         int counter = 0;
         int total_absense_counter = 0;
         int not_total_absense_counter = 0;
-        SurfacingUtil.addHtmlHead( html_writer, "Domain Copy Differences" );
+        SurfacingUtil.writeHtmlHead( html_writer, "Domain Copy Differences" );
         html_writer.write( "<body><table>" );
         for( final String domain_id : all_domains ) {
             if ( ( high_copy_base_values.get( domain_id ) > 0 ) && ( high_copy_target_values.get( domain_id ) > 0 )
@@ -687,9 +687,9 @@ public final class DomainCountsDifferenceUtil {
                     plain_writer.write( domain_id );
                     plain_writer.write( SurfacingConstants.NL );
                     html_writer.write( "<tr><td><a href=\"" + SurfacingConstants.PFAM_FAMILY_ID_LINK + domain_id
-                            + "\">" + domain_id + "</a></td><td>" );
+                                       + "\">" + domain_id + "</a></td><td>" );
                     html_writer.write( addGoInformation( domain_id, domain_id_to_go_ids_map, go_id_to_term_map )
-                            .toString() );
+                                       .toString() );
                     html_writer.write( "</td><td>" );
                     html_writer.write( "<table>" );
                     for( final GenomeWideCombinableDomains genome : genomes ) {
@@ -702,7 +702,7 @@ public final class DomainCountsDifferenceUtil {
                                                    species,
                                                    plain_writer,
                                                    html_writer,
-                                                   "#0000FF" );
+                                    "#0000FF" );
                             html_writer.write( "</tr>" );
                         }
                         else if ( low_copy_species.contains( species ) ) {
@@ -713,7 +713,7 @@ public final class DomainCountsDifferenceUtil {
                                                    species,
                                                    plain_writer,
                                                    html_writer,
-                                                   "#A0A0A0" );
+                                    "#A0A0A0" );
                             html_writer.write( "</tr>" );
                         }
                         else if ( high_copy_base_species.contains( species ) ) {
@@ -724,7 +724,7 @@ public final class DomainCountsDifferenceUtil {
                                                    species,
                                                    plain_writer,
                                                    html_writer,
-                                                   "#404040" );
+                                    "#404040" );
                             html_writer.write( "</tr>" );
                         }
                     }
@@ -813,7 +813,7 @@ public final class DomainCountsDifferenceUtil {
                                              final SortedMap<Species, List<Protein>> protein_lists_per_species,
                                              final String domain_id ) throws IOException {
         final File my_proteins_file = new File( proteins_file_base.getParentFile() + ForesterUtil.FILE_SEPARATOR
-                + domain_id + PLUS_MINUS_PROTEINS_FILE_DOM_SUFFIX );
+                                                + domain_id + PLUS_MINUS_PROTEINS_FILE_DOM_SUFFIX );
         SurfacingUtil.checkForOutputFileWriteability( my_proteins_file );
         final Writer proteins_file_writer = new BufferedWriter( new FileWriter( my_proteins_file ) );
         SurfacingUtil.extractProteinNames( protein_lists_per_species,
@@ -827,6 +827,6 @@ public final class DomainCountsDifferenceUtil {
     }
 
     public static enum COPY_CALCULATION_MODE {
-        MEAN, MEDIAN, MAX, MIN
+        MAX, MEAN, MEDIAN, MIN
     }
 }