X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fsurfacing%2FSurfacingUtil.java;h=55bfb6f56dbaefe0f2d533336e105e04a0c07e59;hb=1d144f35479f96cb36c5247d9711e22ed234651a;hp=b605e66f377e10750528b6dadf4686c8aaa6739e;hpb=41ea5973f93687513d29e5b7cad1abff8f3adb4b;p=jalview.git diff --git a/forester/java/src/org/forester/surfacing/SurfacingUtil.java b/forester/java/src/org/forester/surfacing/SurfacingUtil.java index b605e66..55bfb6f 100644 --- a/forester/java/src/org/forester/surfacing/SurfacingUtil.java +++ b/forester/java/src/org/forester/surfacing/SurfacingUtil.java @@ -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,6 +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 _TAXCODE_HEXCOLORSTRING_MAP = new HashMap(); + private final static Map _TAXCODE_TAXGROUP_MAP = new HashMap(); private static final Comparator ASCENDING_CONFIDENCE_VALUE_ORDER = new Comparator() { @Override @@ -121,6 +122,7 @@ public final class SurfacingUtil { } }; private final static NumberFormat FORMATTER_3 = new DecimalFormat( "0.000" ); + private SurfacingUtil() { // Hidden constructor. } @@ -156,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 ) { @@ -376,8 +378,8 @@ public final class SurfacingUtil { public static void decoratePrintableDomainSimilarities( final SortedSet 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 ); } } @@ -1341,8 +1343,51 @@ public final class SurfacingUtil { throws IllegalArgumentException { if ( !_TAXCODE_HEXCOLORSTRING_MAP.containsKey( tax_code ) ) { if ( ( phy != null ) && !phy.isEmpty() ) { - final List nodes = phy.getNodesViaTaxonomyCode( tax_code ); - Color c = null; + // final List 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 ); + final Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group ); + if ( c == null ) { + 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 ); + } + else { + throw new IllegalArgumentException( "unable to obtain color for code " + tax_code + + " (tree is null or empty and code is not in map)" ); + } + } + 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 nodes = species_tree.getNodesViaTaxonomyCode( tax_code ); if ( ( nodes == null ) || nodes.isEmpty() ) { throw new IllegalArgumentException( "code " + tax_code + " is not found" ); } @@ -1350,32 +1395,32 @@ public final class SurfacingUtil { throw new IllegalArgumentException( "code " + tax_code + " is not unique" ); } PhylogenyNode n = nodes.get( 0 ); + String group = null; while ( n != null ) { if ( n.getNodeData().isHasTaxonomy() && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { - c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getNodeData().getTaxonomy() - .getScientificName(), tax_code ); + group = ForesterUtil.obtainNormalizedTaxonomyGroup( n.getNodeData().getTaxonomy() + .getScientificName() ); } - if ( ( c == null ) && !ForesterUtil.isEmpty( n.getName() ) ) { - c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getName(), tax_code ); + if ( ForesterUtil.isEmpty( group ) && !ForesterUtil.isEmpty( n.getName() ) ) { + group = ForesterUtil.obtainNormalizedTaxonomyGroup( n.getName() ); } - if ( c != null ) { + if ( !ForesterUtil.isEmpty( group ) ) { break; } n = n.getParent(); } - if ( c == null ) { - throw new IllegalArgumentException( "no color found for taxonomy code \"" + tax_code + "\"" ); + if ( ForesterUtil.isEmpty( group ) ) { + throw new IllegalArgumentException( "no group found for taxonomy code \"" + tax_code + "\"" ); } - final String hex = String.format( "#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue() ); - _TAXCODE_HEXCOLORSTRING_MAP.put( tax_code, hex ); + _TAXCODE_TAXGROUP_MAP.put( tax_code, group ); } else { - throw new IllegalArgumentException( "unable to obtain color for code " + tax_code + throw new IllegalArgumentException( "unable to obtain group for code " + tax_code + " (tree is null or empty and code is not in map)" ); } } - return _TAXCODE_HEXCOLORSTRING_MAP.get( tax_code ); + return _TAXCODE_TAXGROUP_MAP.get( tax_code ); } public static void performDomainArchitectureAnalysis( final SortedMap> domain_architecutures, @@ -2176,11 +2221,12 @@ public final class SurfacingUtil { final SortedSet similarities, final boolean treat_as_binary, final List species_order, - final PrintableDomainSimilarity.PRINT_OPTION print_option, + final DomainSimilarity.PRINT_OPTION print_option, final DomainSimilarity.DomainSimilarityScoring scoring, final boolean verbose, final Map tax_code_to_id_map, - final Phylogeny phy ) throws IOException { + final Phylogeny phy, + final Set pos_filter_doms ) throws IOException { if ( ( single_writer != null ) && ( ( split_writers == null ) || split_writers.isEmpty() ) ) { split_writers = new HashMap(); split_writers.put( '_', single_writer ); @@ -2218,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( "" - + similarity.getDomainId() + "" ); + if ( !ForesterUtil.isEmpty( pos_filter_doms ) && pos_filter_doms.contains( similarity.getDomainId() ) ) { + single_writer.write( "" + similarity.getDomainId() + + "" ); + } + else { + single_writer.write( "" + + similarity.getDomainId() + "" ); + } single_writer.write( SurfacingConstants.NL ); } else { @@ -2231,8 +2284,15 @@ public final class SurfacingUtil { if ( local_writer == null ) { local_writer = split_writers.get( '0' ); } - local_writer.write( "" - + similarity.getDomainId() + "" ); + if ( !ForesterUtil.isEmpty( pos_filter_doms ) && pos_filter_doms.contains( similarity.getDomainId() ) ) { + local_writer.write( "" + similarity.getDomainId() + + "" ); + } + else { + local_writer.write( "" + + similarity.getDomainId() + "" ); + } local_writer.write( SurfacingConstants.NL ); } } @@ -2256,7 +2316,10 @@ public final class SurfacingUtil { writeColorLabels( "Porifera (sponges)", TaxonomyColors.PORIFERA_COLOR, w ); writeColorLabels( "Choanoflagellida", TaxonomyColors.CHOANOFLAGELLIDA, w ); writeColorLabels( "Ichthyosporea & Filasterea", TaxonomyColors.ICHTHYOSPOREA_AND_FILASTEREA, w ); - writeColorLabels( "Fungi", TaxonomyColors.FUNGI_COLOR, w ); + writeColorLabels( "Dikarya (Ascomycota & Basidiomycota, so-called \"higher fungi\")", + TaxonomyColors.DIKARYA_COLOR, + w ); + writeColorLabels( "other Fungi", TaxonomyColors.OTHER_FUNGI_COLOR, w ); writeColorLabels( "Nucleariidae and Fonticula group", TaxonomyColors.NUCLEARIIDAE_AND_FONTICULA_GROUP_COLOR, w ); @@ -2286,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,