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=00ee155ad0dcefcf85786cad5b0414b1c172a160;hpb=a1114eb8610e592961a40e5c3d46d647c02b5108;p=jalview.git diff --git a/forester/java/src/org/forester/surfacing/SurfacingUtil.java b/forester/java/src/org/forester/surfacing/SurfacingUtil.java index 00ee155..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,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 _TAXCODE_HEXCOLORSTRING_MAP = new HashMap(); - - - private final static Map _TAXCODE_TAXGROUP_MAP = new HashMap(); - - + private final static Map _TAXCODE_TAXGROUP_MAP = new HashMap(); private static final Comparator ASCENDING_CONFIDENCE_VALUE_ORDER = new Comparator() { @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 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 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 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 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> domain_architecutures, final SortedMap domain_architecuture_counts, @@ -2234,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 ); @@ -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( "" - + 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 { @@ -2289,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 ); } } @@ -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,