inprogress
[jalview.git] / forester / java / src / org / forester / surfacing / SurfacingUtil.java
index 00ee155..55bfb6f 100644 (file)
@@ -85,9 +85,9 @@ import org.forester.protein.BinaryDomainCombination;
 import org.forester.protein.Domain;
 import org.forester.protein.Protein;
 import org.forester.species.Species;
+import org.forester.surfacing.DomainSimilarity.PRINT_OPTION;
 import org.forester.surfacing.DomainSimilarityCalculator.Detailedness;
 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;
@@ -101,11 +101,7 @@ public final class SurfacingUtil {
 
     public final static Pattern              PATTERN_SP_STYLE_TAXONOMY        = Pattern.compile( "^[A-Z0-9]{3,5}$" );
     private final static Map<String, String> _TAXCODE_HEXCOLORSTRING_MAP      = new HashMap<String, String>();
-  
-    
-    private final static Map<String, String> _TAXCODE_TAXGROUP_MAP = new HashMap<String, String>();
-    
-    
+    private final static Map<String, String> _TAXCODE_TAXGROUP_MAP            = new HashMap<String, String>();
     private static final Comparator<Domain>  ASCENDING_CONFIDENCE_VALUE_ORDER = new Comparator<Domain>() {
 
                                                                                   @Override
@@ -162,7 +158,7 @@ public final class SurfacingUtil {
         }
     }
 
-    public static void checkWriteabilityForPairwiseComparisons( final PrintableDomainSimilarity.PRINT_OPTION domain_similarity_print_option,
+    public static void checkWriteabilityForPairwiseComparisons( final DomainSimilarity.PRINT_OPTION domain_similarity_print_option,
                                                                 final String[][] input_file_properties,
                                                                 final String automated_pairwise_comparison_suffix,
                                                                 final File outdir ) {
@@ -382,8 +378,8 @@ public final class SurfacingUtil {
     public static void decoratePrintableDomainSimilarities( final SortedSet<DomainSimilarity> domain_similarities,
                                                             final Detailedness detailedness ) {
         for( final DomainSimilarity domain_similarity : domain_similarities ) {
-            if ( domain_similarity instanceof PrintableDomainSimilarity ) {
-                final PrintableDomainSimilarity printable_domain_similarity = ( PrintableDomainSimilarity ) domain_similarity;
+            if ( domain_similarity instanceof DomainSimilarity ) {
+                final DomainSimilarity printable_domain_similarity = domain_similarity;
                 printable_domain_similarity.setDetailedness( detailedness );
             }
         }
@@ -1347,34 +1343,35 @@ public final class SurfacingUtil {
             throws IllegalArgumentException {
         if ( !_TAXCODE_HEXCOLORSTRING_MAP.containsKey( tax_code ) ) {
             if ( ( phy != null ) && !phy.isEmpty() ) {
-//                final List<PhylogenyNode> nodes = phy.getNodesViaTaxonomyCode( tax_code );
-//                Color c = null;
-//                if ( ( nodes == null ) || nodes.isEmpty() ) {
-//                    throw new IllegalArgumentException( "code " + tax_code + " is not found" );
-//                }
-//                if ( nodes.size() != 1 ) {
-//                    throw new IllegalArgumentException( "code " + tax_code + " is not unique" );
-//                }
-//                PhylogenyNode n = nodes.get( 0 );
-//                while ( n != null ) {
-//                    if ( n.getNodeData().isHasTaxonomy()
-//                            && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
-//                        c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getNodeData().getTaxonomy()
-//                                .getScientificName(), tax_code );
-//                    }
-//                    if ( ( c == null ) && !ForesterUtil.isEmpty( n.getName() ) ) {
-//                        c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getName(), tax_code );
-//                    }
-//                    if ( c != null ) {
-//                        break;
-//                    }
-//                    n = n.getParent();
-//                }
+                //                final List<PhylogenyNode> nodes = phy.getNodesViaTaxonomyCode( tax_code );
+                //                Color c = null;
+                //                if ( ( nodes == null ) || nodes.isEmpty() ) {
+                //                    throw new IllegalArgumentException( "code " + tax_code + " is not found" );
+                //                }
+                //                if ( nodes.size() != 1 ) {
+                //                    throw new IllegalArgumentException( "code " + tax_code + " is not unique" );
+                //                }
+                //                PhylogenyNode n = nodes.get( 0 );
+                //                while ( n != null ) {
+                //                    if ( n.getNodeData().isHasTaxonomy()
+                //                            && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
+                //                        c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getNodeData().getTaxonomy()
+                //                                .getScientificName(), tax_code );
+                //                    }
+                //                    if ( ( c == null ) && !ForesterUtil.isEmpty( n.getName() ) ) {
+                //                        c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getName(), tax_code );
+                //                    }
+                //                    if ( c != null ) {
+                //                        break;
+                //                    }
+                //                    n = n.getParent();
+                //                }
                 final String group = obtainTaxonomyGroup( tax_code, phy );
-                Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group );
+                final Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group );
                 if ( c == null ) {
-                    throw new IllegalArgumentException( "no color found for taxonomy code \"" + tax_code + "\"" );
-                } 
+                    throw new IllegalArgumentException( "no color found for taxonomy group \"" + group
+                            + "\" for code \"" + tax_code + "\"" );
+                }
                 final String hex = String.format( "#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue() );
                 _TAXCODE_HEXCOLORSTRING_MAP.put( tax_code, hex );
             }
@@ -1385,14 +1382,12 @@ public final class SurfacingUtil {
         }
         return _TAXCODE_HEXCOLORSTRING_MAP.get( tax_code );
     }
-    
-    
+
     public static String obtainTaxonomyGroup( final String tax_code, final Phylogeny species_tree )
             throws IllegalArgumentException {
         if ( !_TAXCODE_TAXGROUP_MAP.containsKey( tax_code ) ) {
             if ( ( species_tree != null ) && !species_tree.isEmpty() ) {
                 final List<PhylogenyNode> nodes = species_tree.getNodesViaTaxonomyCode( tax_code );
-                
                 if ( ( nodes == null ) || nodes.isEmpty() ) {
                     throw new IllegalArgumentException( "code " + tax_code + " is not found" );
                 }
@@ -1401,28 +1396,23 @@ public final class SurfacingUtil {
                 }
                 PhylogenyNode n = nodes.get( 0 );
                 String group = null;
-                
                 while ( n != null ) {
                     if ( n.getNodeData().isHasTaxonomy()
                             && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
                         group = ForesterUtil.obtainNormalizedTaxonomyGroup( n.getNodeData().getTaxonomy()
                                 .getScientificName() );
-                        
                     }
-                    if ( ForesterUtil.isEmpty( group  ) && !ForesterUtil.isEmpty( n.getName() ) ) {
+                    if ( ForesterUtil.isEmpty( group ) && !ForesterUtil.isEmpty( n.getName() ) ) {
                         group = ForesterUtil.obtainNormalizedTaxonomyGroup( n.getName() );
-                        
                     }
-                    if ( !ForesterUtil.isEmpty( group  ) ) {
+                    if ( !ForesterUtil.isEmpty( group ) ) {
                         break;
                     }
-                    
                     n = n.getParent();
                 }
-                if ( ForesterUtil.isEmpty( group  ) ) {
+                if ( ForesterUtil.isEmpty( group ) ) {
                     throw new IllegalArgumentException( "no group found for taxonomy code \"" + tax_code + "\"" );
                 }
-                
                 _TAXCODE_TAXGROUP_MAP.put( tax_code, group );
             }
             else {
@@ -1432,9 +1422,6 @@ public final class SurfacingUtil {
         }
         return _TAXCODE_TAXGROUP_MAP.get( tax_code );
     }
-    
-    
-    
 
     public static void performDomainArchitectureAnalysis( final SortedMap<String, Set<String>> domain_architecutures,
                                                           final SortedMap<String, Integer> domain_architecuture_counts,
@@ -2234,11 +2221,12 @@ public final class SurfacingUtil {
                                                       final SortedSet<DomainSimilarity> similarities,
                                                       final boolean treat_as_binary,
                                                       final List<Species> species_order,
-                                                      final PrintableDomainSimilarity.PRINT_OPTION print_option,
+                                                      final DomainSimilarity.PRINT_OPTION print_option,
                                                       final DomainSimilarity.DomainSimilarityScoring scoring,
                                                       final boolean verbose,
                                                       final Map<String, Integer> tax_code_to_id_map,
-                                                      final Phylogeny phy ) throws IOException {
+                                                      final Phylogeny phy,
+                                                      final Set<String> pos_filter_doms ) throws IOException {
         if ( ( single_writer != null ) && ( ( split_writers == null ) || split_writers.isEmpty() ) ) {
             split_writers = new HashMap<Character, Writer>();
             split_writers.put( '_', single_writer );
@@ -2276,11 +2264,18 @@ public final class SurfacingUtil {
         //
         for( final DomainSimilarity similarity : similarities ) {
             if ( ( species_order != null ) && !species_order.isEmpty() ) {
-                ( ( PrintableDomainSimilarity ) similarity ).setSpeciesOrder( species_order );
+                ( similarity ).setSpeciesOrder( species_order );
             }
             if ( single_writer != null ) {
-                single_writer.write( "<tr><td><b><a href=\"#" + similarity.getDomainId() + "\">"
-                        + similarity.getDomainId() + "</a></b></td></tr>" );
+                if ( !ForesterUtil.isEmpty( pos_filter_doms ) && pos_filter_doms.contains( similarity.getDomainId() ) ) {
+                    single_writer.write( "<tr><td><b><a href=\"#" + similarity.getDomainId()
+                            + "\"><span style=\"color:#00ff00\">" + similarity.getDomainId()
+                            + "</span></a></b></td></tr>" );
+                }
+                else {
+                    single_writer.write( "<tr><td><b><a href=\"#" + similarity.getDomainId() + "\">"
+                            + similarity.getDomainId() + "</a></b></td></tr>" );
+                }
                 single_writer.write( SurfacingConstants.NL );
             }
             else {
@@ -2289,8 +2284,15 @@ public final class SurfacingUtil {
                 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>" );
+                if ( !ForesterUtil.isEmpty( pos_filter_doms ) && pos_filter_doms.contains( similarity.getDomainId() ) ) {
+                    local_writer.write( "<tr><td><b><a href=\"#" + similarity.getDomainId()
+                            + "\"><span style=\"color:#00ff00\">" + similarity.getDomainId()
+                            + "</span></a></b></td></tr>" );
+                }
+                else {
+                    local_writer.write( "<tr><td><b><a href=\"#" + similarity.getDomainId() + "\">"
+                            + similarity.getDomainId() + "</a></b></td></tr>" );
+                }
                 local_writer.write( SurfacingConstants.NL );
             }
         }
@@ -2347,7 +2349,7 @@ public final class SurfacingUtil {
         //
         for( final DomainSimilarity similarity : similarities ) {
             if ( ( species_order != null ) && !species_order.isEmpty() ) {
-                ( ( PrintableDomainSimilarity ) similarity ).setSpeciesOrder( species_order );
+                ( similarity ).setSpeciesOrder( species_order );
             }
             if ( simple_tab_writer != null ) {
                 simple_tab_writer.write( similarity.toStringBuffer( PRINT_OPTION.SIMPLE_TAB_DELIMITED,