+ 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' );
+ }
+ 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 );
+ }
+ }
+ 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 );
+ w.write( "<tr><td><b>" );
+ w.write( "Species group colors:" );
+ w.write( "</b></td></tr>" );
+ w.write( SurfacingConstants.NL );
+ writeColorLabels( "Deuterostomia", TaxonomyColors.DEUTEROSTOMIA_COLOR, w );
+ writeColorLabels( "Protostomia", TaxonomyColors.PROTOSTOMIA_COLOR, w );
+ writeColorLabels( "Cnidaria", TaxonomyColors.CNIDARIA_COLOR, w );
+ writeColorLabels( "Placozoa", TaxonomyColors.PLACOZOA_COLOR, w );
+ writeColorLabels( "Ctenophora (comb jellies)", TaxonomyColors.CTENOPHORA_COLOR, w );
+ writeColorLabels( "Porifera (sponges)", TaxonomyColors.PORIFERA_COLOR, w );
+ writeColorLabels( "Choanoflagellida", TaxonomyColors.CHOANOFLAGELLIDA, w );
+ writeColorLabels( "Ichthyosporea & Filasterea", TaxonomyColors.ICHTHYOSPOREA_AND_FILASTEREA, 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 );
+ writeColorLabels( "Amoebozoa", TaxonomyColors.AMOEBOZOA_COLOR, w );
+ writeColorLabels( "Embryophyta (plants)", TaxonomyColors.EMBRYOPHYTA_COLOR, w );
+ writeColorLabels( "Chlorophyta (green algae)", TaxonomyColors.CHLOROPHYTA_COLOR, w );
+ writeColorLabels( "Rhodophyta (red algae)", TaxonomyColors.RHODOPHYTA_COLOR, w );
+ writeColorLabels( "Glaucocystophyce (Glaucophyta)", TaxonomyColors.GLAUCOPHYTA_COLOR, w );
+ writeColorLabels( "Hacrobia (Cryptophyta & Haptophyceae & Centroheliozoa)",
+ TaxonomyColors.HACROBIA_COLOR,
+ w );
+ writeColorLabels( "Stramenopiles (Chromophyta, heterokonts)", TaxonomyColors.STRAMENOPILES_COLOR, w );
+ writeColorLabels( "Alveolata", TaxonomyColors.ALVEOLATA_COLOR, w );
+ writeColorLabels( "Rhizaria", TaxonomyColors.RHIZARIA_COLOR, w );
+ writeColorLabels( "Excavata", TaxonomyColors.EXCAVATA_COLOR, w );
+ writeColorLabels( "Apusozoa", TaxonomyColors.APUSOZOA_COLOR, w );
+ writeColorLabels( "Archaea", TaxonomyColors.ARCHAEA_COLOR, w );
+ writeColorLabels( "Bacteria", TaxonomyColors.BACTERIA_COLOR, w );
+ 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() ) {
+ ( 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,
+ null ).toString() );
+ }
+ if ( single_writer != null ) {
+ single_writer.write( similarity.toStringBuffer( print_option, tax_code_to_id_map, phy ).toString() );
+ 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( similarity.toStringBuffer( print_option, tax_code_to_id_map, phy ).toString() );
+ local_writer.write( SurfacingConstants.NL );
+ }
+ }
+ switch ( print_option ) {
+ case HTML:
+ for( final Writer w : split_writers.values() ) {
+ w.write( SurfacingConstants.NL );
+ w.write( "</table>" );
+ w.write( SurfacingConstants.NL );
+ w.write( "</font>" );
+ w.write( SurfacingConstants.NL );
+ w.write( "</body>" );
+ w.write( SurfacingConstants.NL );
+ w.write( "</html>" );
+ w.write( SurfacingConstants.NL );
+ }
+ break;
+ default:
+ break;
+ }
+ for( final Writer w : split_writers.values() ) {
+ w.close();
+ }
+ }
+
+ public static void writeHtmlHead( final Writer w, final String title ) throws IOException {
+ w.write( SurfacingConstants.NL );
+ w.write( "<head>" );
+ w.write( "<title>" );
+ w.write( title );
+ w.write( "</title>" );
+ w.write( SurfacingConstants.NL );
+ w.write( "<style>" );
+ w.write( SurfacingConstants.NL );
+ w.write( "a:visited { color : #000066; text-decoration : none; }" );
+ w.write( SurfacingConstants.NL );
+ w.write( "a:link { color : #000066; text-decoration : none; }" );
+ w.write( SurfacingConstants.NL );
+ w.write( "a:active { color : ##000066; text-decoration : none; }" );
+ w.write( SurfacingConstants.NL );
+ w.write( "a:hover { color : #FFFFFF; background-color : #000000; text-decoration : none; }" );
+ w.write( SurfacingConstants.NL );
+ //
+ w.write( "a.pl:visited { color : #505050; text-decoration : none; font-size: 7px;}" );
+ w.write( SurfacingConstants.NL );
+ w.write( "a.pl:link { color : #505050; text-decoration : none; font-size: 7px;}" );
+ w.write( SurfacingConstants.NL );
+ w.write( "a.pl:active { color : #505050; text-decoration : none; font-size: 7px;}" );
+ w.write( SurfacingConstants.NL );
+ w.write( "a.pl:hover { color : #FFFFFF; background-color : #000000; text-decoration : none; font-size: 7px;}" );
+ w.write( SurfacingConstants.NL );
+ //
+ w.write( "a.ps:visited { color : #707070; text-decoration : none; font-size: 7px;}" );
+ w.write( SurfacingConstants.NL );
+ w.write( "a.ps:link { color : #707070; text-decoration : none; font-size: 7px;}" );
+ w.write( SurfacingConstants.NL );
+ w.write( "a.ps:active { color : #707070; text-decoration : none; font-size: 7px;}" );
+ w.write( SurfacingConstants.NL );
+ w.write( "a.ps:hover { color : #FFFFFF; background-color : #000000; text-decoration : none; font-size: 7px;}" );
+ 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 }" );
+ w.write( SurfacingConstants.NL );
+ w.write( "h2 { color : #0000FF; font-family: Verdana, Arial, Helvetica; font-size: 16pt; font-weight: bold }" );
+ w.write( SurfacingConstants.NL );
+ w.write( "</style>" );
+ w.write( SurfacingConstants.NL );
+ w.write( "</head>" );
+ w.write( SurfacingConstants.NL );
+ }
+
+ public static void writeMatrixToFile( final CharacterStateMatrix<?> matrix,
+ final String filename,
+ final Format format ) {
+ final File outfile = new File( filename );
+ checkForOutputFileWriteability( outfile );
+ try {
+ final BufferedWriter out = new BufferedWriter( new FileWriter( outfile ) );
+ matrix.toWriter( out, format );
+ out.flush();
+ out.close();
+ }
+ catch ( final IOException e ) {
+ ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
+ }
+ ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote matrix: \"" + filename + "\"" );
+ }
+
+ public static void writeMatrixToFile( final File matrix_outfile, final List<DistanceMatrix> matrices ) {
+ checkForOutputFileWriteability( matrix_outfile );
+ try {
+ final BufferedWriter out = new BufferedWriter( new FileWriter( matrix_outfile ) );
+ for( final DistanceMatrix distance_matrix : matrices ) {
+ out.write( distance_matrix.toStringBuffer( DistanceMatrix.Format.PHYLIP ).toString() );
+ out.write( ForesterUtil.LINE_SEPARATOR );
+ out.flush();
+ }
+ out.close();
+ }
+ catch ( final IOException e ) {
+ ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
+ }
+ ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote distance matrices to \"" + matrix_outfile + "\"" );
+ }
+
+ public static void writePhylogenyToFile( final Phylogeny phylogeny, final String filename ) {
+ final PhylogenyWriter writer = new PhylogenyWriter();
+ try {
+ writer.toPhyloXML( new File( filename ), phylogeny, 1 );
+ }
+ catch ( final IOException e ) {
+ ForesterUtil.printWarningMessage( surfacing.PRG_NAME, "failed to write phylogeny to \"" + filename + "\": "
+ + e );
+ }
+ ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote phylogeny to \"" + filename + "\"" );
+ }
+
+ public static void writePresentToNexus( final File output_file,
+ final File positive_filter_file,
+ final SortedSet<String> filter,
+ final List<GenomeWideCombinableDomains> gwcd_list ) {
+ try {
+ writeMatrixToFile( DomainParsimonyCalculator.createMatrixOfDomainPresenceOrAbsence( gwcd_list,
+ positive_filter_file == null ? null
+ : filter ),
+ output_file + surfacing.DOMAINS_PRESENT_NEXUS,
+ Format.NEXUS_BINARY );
+ writeMatrixToFile( DomainParsimonyCalculator.createMatrixOfBinaryDomainCombinationPresenceOrAbsence( gwcd_list ),
+ output_file + surfacing.BDC_PRESENT_NEXUS,
+ Format.NEXUS_BINARY );
+ }
+ catch ( final Exception e ) {
+ ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
+ }
+ }
+
+ public static void writeProteinListsForAllSpecies( final File output_dir,
+ final SortedMap<Species, List<Protein>> protein_lists_per_species,
+ final List<GenomeWideCombinableDomains> gwcd_list,
+ final double domain_e_cutoff,
+ final Set<String> pos_filter_doms ) {
+ final SortedSet<String> all_domains = new TreeSet<String>();
+ for( final GenomeWideCombinableDomains gwcd : gwcd_list ) {
+ all_domains.addAll( gwcd.getAllDomainIds() );
+ }
+ for( final String domain : all_domains ) {
+ if ( !ForesterUtil.isEmpty( pos_filter_doms ) && !pos_filter_doms.contains( domain ) ) {
+ continue;
+ }
+ final File out = new File( output_dir + ForesterUtil.FILE_SEPARATOR + domain + surfacing.SEQ_EXTRACT_SUFFIX );
+ checkForOutputFileWriteability( out );
+ try {
+ final Writer proteins_file_writer = new BufferedWriter( new FileWriter( out ) );
+ extractProteinNames( protein_lists_per_species,
+ domain,
+ proteins_file_writer,
+ "\t",
+ surfacing.LIMIT_SPEC_FOR_PROT_EX,
+ domain_e_cutoff );
+ proteins_file_writer.close();
+ }
+ catch ( final IOException e ) {
+ ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
+ }
+ ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote proteins list to \"" + out + "\"" );
+ }
+ }
+
+ public static void writeTaxonomyLinks( final Writer writer,
+ final String species,
+ final Map<String, Integer> tax_code_to_id_map ) throws IOException {
+ if ( ( species.length() > 1 ) && ( species.indexOf( '_' ) < 1 ) ) {
+ writer.write( " [" );
+ if ( ( tax_code_to_id_map != null ) && tax_code_to_id_map.containsKey( species ) ) {
+ writer.write( "<a href=\"" + SurfacingConstants.UNIPROT_TAXONOMY_ID_LINK
+ + tax_code_to_id_map.get( species ) + "\" target=\"taxonomy_window\">uniprot</a>" );
+ }
+ else {
+ writer.write( "<a href=\"" + SurfacingConstants.EOL_LINK + species
+ + "\" target=\"taxonomy_window\">eol</a>" );
+ writer.write( "|" );
+ writer.write( "<a href=\"" + SurfacingConstants.GOOGLE_SCHOLAR_SEARCH + species
+ + "\" target=\"taxonomy_window\">scholar</a>" );
+ writer.write( "|" );
+ writer.write( "<a href=\"" + SurfacingConstants.GOOGLE_WEB_SEARCH_LINK + species
+ + "\" target=\"taxonomy_window\">google</a>" );
+ }
+ writer.write( "]" );
+ }
+ }
+
+ private final static void addToCountMap( final Map<String, Integer> map, final String s ) {
+ if ( map.containsKey( s ) ) {
+ map.put( s, map.get( s ) + 1 );
+ }
+ else {
+ map.put( s, 1 );
+ }
+ }
+
+ private static void calculateIndependentDomainCombinationGains( final Phylogeny local_phylogeny_l,
+ final String outfilename_for_counts,
+ final String outfilename_for_dc,
+ final String outfilename_for_dc_for_go_mapping,
+ final String outfilename_for_dc_for_go_mapping_unique,
+ final String outfilename_for_rank_counts,
+ final String outfilename_for_ancestor_species_counts,
+ final String outfilename_for_protein_stats,
+ final Map<String, DescriptiveStatistics> protein_length_stats_by_dc,
+ final Map<String, DescriptiveStatistics> domain_number_stats_by_dc,
+ final Map<String, DescriptiveStatistics> domain_length_stats_by_domain ) {
+ try {
+ //
+ // if ( protein_length_stats_by_dc != null ) {
+ // for( final Entry<?, DescriptiveStatistics> entry : protein_length_stats_by_dc.entrySet() ) {
+ // System.out.print( entry.getKey().toString() );
+ // System.out.print( ": " );
+ // double[] a = entry.getValue().getDataAsDoubleArray();
+ // for( int i = 0; i < a.length; i++ ) {
+ // System.out.print( a[ i ] + " " );
+ // }
+ // System.out.println();
+ // }
+ // }
+ // if ( domain_number_stats_by_dc != null ) {
+ // for( final Entry<?, DescriptiveStatistics> entry : domain_number_stats_by_dc.entrySet() ) {
+ // System.out.print( entry.getKey().toString() );
+ // System.out.print( ": " );
+ // double[] a = entry.getValue().getDataAsDoubleArray();
+ // for( int i = 0; i < a.length; i++ ) {
+ // System.out.print( a[ i ] + " " );
+ // }
+ // System.out.println();
+ // }
+ // }
+ //
+ final BufferedWriter out_counts = new BufferedWriter( new FileWriter( outfilename_for_counts ) );
+ final BufferedWriter out_dc = new BufferedWriter( new FileWriter( outfilename_for_dc ) );
+ final BufferedWriter out_dc_for_go_mapping = new BufferedWriter( new FileWriter( outfilename_for_dc_for_go_mapping ) );
+ final BufferedWriter out_dc_for_go_mapping_unique = new BufferedWriter( new FileWriter( outfilename_for_dc_for_go_mapping_unique ) );
+ final SortedMap<String, Integer> dc_gain_counts = new TreeMap<String, Integer>();
+ for( final PhylogenyNodeIterator it = local_phylogeny_l.iteratorPostorder(); it.hasNext(); ) {
+ final PhylogenyNode n = it.next();
+ final Set<String> gained_dc = n.getNodeData().getBinaryCharacters().getGainedCharacters();
+ for( final String dc : gained_dc ) {
+ if ( dc_gain_counts.containsKey( dc ) ) {
+ dc_gain_counts.put( dc, dc_gain_counts.get( dc ) + 1 );
+ }
+ else {
+ dc_gain_counts.put( dc, 1 );
+ }
+ }
+ }
+ final SortedMap<Integer, Integer> histogram = new TreeMap<Integer, Integer>();
+ final SortedMap<Integer, StringBuilder> domain_lists = new TreeMap<Integer, StringBuilder>();
+ final SortedMap<Integer, DescriptiveStatistics> dc_reapp_counts_to_protein_length_stats = new TreeMap<Integer, DescriptiveStatistics>();
+ final SortedMap<Integer, DescriptiveStatistics> dc_reapp_counts_to_domain_number_stats = new TreeMap<Integer, DescriptiveStatistics>();
+ final SortedMap<Integer, DescriptiveStatistics> dc_reapp_counts_to_domain_lengths_stats = new TreeMap<Integer, DescriptiveStatistics>();
+ final SortedMap<Integer, PriorityQueue<String>> domain_lists_go = new TreeMap<Integer, PriorityQueue<String>>();
+ final SortedMap<Integer, SortedSet<String>> domain_lists_go_unique = new TreeMap<Integer, SortedSet<String>>();
+ final Set<String> dcs = dc_gain_counts.keySet();
+ final SortedSet<String> more_than_once = new TreeSet<String>();
+ DescriptiveStatistics gained_once_lengths_stats = new BasicDescriptiveStatistics();
+ DescriptiveStatistics gained_once_domain_count_stats = new BasicDescriptiveStatistics();
+ DescriptiveStatistics gained_multiple_times_lengths_stats = new BasicDescriptiveStatistics();
+ final DescriptiveStatistics gained_multiple_times_domain_count_stats = new BasicDescriptiveStatistics();
+ long gained_multiple_times_domain_length_sum = 0;
+ long gained_once_domain_length_sum = 0;
+ long gained_multiple_times_domain_length_count = 0;
+ long gained_once_domain_length_count = 0;
+ for( final String dc : dcs ) {
+ final int count = dc_gain_counts.get( dc );
+ if ( histogram.containsKey( count ) ) {
+ histogram.put( count, histogram.get( count ) + 1 );
+ domain_lists.get( count ).append( ", " + dc );
+ domain_lists_go.get( count ).addAll( splitDomainCombination( dc ) );
+ domain_lists_go_unique.get( count ).addAll( splitDomainCombination( dc ) );
+ }
+ else {
+ histogram.put( count, 1 );
+ domain_lists.put( count, new StringBuilder( dc ) );
+ final PriorityQueue<String> q = new PriorityQueue<String>();
+ q.addAll( splitDomainCombination( dc ) );
+ domain_lists_go.put( count, q );
+ final SortedSet<String> set = new TreeSet<String>();
+ set.addAll( splitDomainCombination( dc ) );
+ domain_lists_go_unique.put( count, set );
+ }
+ if ( protein_length_stats_by_dc != null ) {
+ if ( !dc_reapp_counts_to_protein_length_stats.containsKey( count ) ) {
+ dc_reapp_counts_to_protein_length_stats.put( count, new BasicDescriptiveStatistics() );
+ }
+ dc_reapp_counts_to_protein_length_stats.get( count ).addValue( protein_length_stats_by_dc.get( dc )
+ .arithmeticMean() );
+ }
+ if ( domain_number_stats_by_dc != null ) {
+ if ( !dc_reapp_counts_to_domain_number_stats.containsKey( count ) ) {
+ dc_reapp_counts_to_domain_number_stats.put( count, new BasicDescriptiveStatistics() );
+ }
+ dc_reapp_counts_to_domain_number_stats.get( count ).addValue( domain_number_stats_by_dc.get( dc )
+ .arithmeticMean() );
+ }
+ if ( domain_length_stats_by_domain != null ) {
+ if ( !dc_reapp_counts_to_domain_lengths_stats.containsKey( count ) ) {
+ dc_reapp_counts_to_domain_lengths_stats.put( count, new BasicDescriptiveStatistics() );
+ }
+ final String[] ds = dc.split( "=" );
+ dc_reapp_counts_to_domain_lengths_stats.get( count ).addValue( domain_length_stats_by_domain
+ .get( ds[ 0 ] ).arithmeticMean() );
+ dc_reapp_counts_to_domain_lengths_stats.get( count ).addValue( domain_length_stats_by_domain
+ .get( ds[ 1 ] ).arithmeticMean() );
+ }
+ if ( count > 1 ) {
+ more_than_once.add( dc );
+ if ( protein_length_stats_by_dc != null ) {
+ final DescriptiveStatistics s = protein_length_stats_by_dc.get( dc );
+ for( final double element : s.getData() ) {
+ gained_multiple_times_lengths_stats.addValue( element );
+ }
+ }
+ if ( domain_number_stats_by_dc != null ) {
+ final DescriptiveStatistics s = domain_number_stats_by_dc.get( dc );
+ for( final double element : s.getData() ) {
+ gained_multiple_times_domain_count_stats.addValue( element );
+ }
+ }
+ if ( domain_length_stats_by_domain != null ) {
+ final String[] ds = dc.split( "=" );
+ final DescriptiveStatistics s0 = domain_length_stats_by_domain.get( ds[ 0 ] );
+ final DescriptiveStatistics s1 = domain_length_stats_by_domain.get( ds[ 1 ] );
+ for( final double element : s0.getData() ) {
+ gained_multiple_times_domain_length_sum += element;
+ ++gained_multiple_times_domain_length_count;
+ }
+ for( final double element : s1.getData() ) {
+ gained_multiple_times_domain_length_sum += element;
+ ++gained_multiple_times_domain_length_count;
+ }
+ }
+ }
+ else {
+ if ( protein_length_stats_by_dc != null ) {
+ final DescriptiveStatistics s = protein_length_stats_by_dc.get( dc );
+ for( final double element : s.getData() ) {
+ gained_once_lengths_stats.addValue( element );
+ }
+ }
+ if ( domain_number_stats_by_dc != null ) {
+ final DescriptiveStatistics s = domain_number_stats_by_dc.get( dc );
+ for( final double element : s.getData() ) {
+ gained_once_domain_count_stats.addValue( element );
+ }
+ }
+ if ( domain_length_stats_by_domain != null ) {
+ final String[] ds = dc.split( "=" );
+ final DescriptiveStatistics s0 = domain_length_stats_by_domain.get( ds[ 0 ] );
+ final DescriptiveStatistics s1 = domain_length_stats_by_domain.get( ds[ 1 ] );
+ for( final double element : s0.getData() ) {
+ gained_once_domain_length_sum += element;
+ ++gained_once_domain_length_count;
+ }
+ for( final double element : s1.getData() ) {
+ gained_once_domain_length_sum += element;
+ ++gained_once_domain_length_count;
+ }
+ }
+ }
+ }
+ final Set<Integer> histogram_keys = histogram.keySet();
+ for( final Integer histogram_key : histogram_keys ) {
+ final int count = histogram.get( histogram_key );
+ final StringBuilder dc = domain_lists.get( histogram_key );
+ out_counts.write( histogram_key + "\t" + count + ForesterUtil.LINE_SEPARATOR );
+ out_dc.write( histogram_key + "\t" + dc + ForesterUtil.LINE_SEPARATOR );
+ out_dc_for_go_mapping.write( "#" + histogram_key + ForesterUtil.LINE_SEPARATOR );
+ final Object[] sorted = domain_lists_go.get( histogram_key ).toArray();
+ Arrays.sort( sorted );
+ for( final Object domain : sorted ) {
+ out_dc_for_go_mapping.write( domain + ForesterUtil.LINE_SEPARATOR );
+ }
+ out_dc_for_go_mapping_unique.write( "#" + histogram_key + ForesterUtil.LINE_SEPARATOR );
+ for( final String domain : domain_lists_go_unique.get( histogram_key ) ) {
+ out_dc_for_go_mapping_unique.write( domain + ForesterUtil.LINE_SEPARATOR );
+ }
+ }
+ out_counts.close();
+ out_dc.close();
+ out_dc_for_go_mapping.close();
+ out_dc_for_go_mapping_unique.close();
+ final SortedMap<String, Integer> lca_rank_counts = new TreeMap<String, Integer>();
+ final SortedMap<String, Integer> lca_ancestor_species_counts = new TreeMap<String, Integer>();
+ for( final String dc : more_than_once ) {
+ final List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
+ for( final PhylogenyNodeIterator it = local_phylogeny_l.iteratorExternalForward(); it.hasNext(); ) {
+ final PhylogenyNode n = it.next();
+ if ( n.getNodeData().getBinaryCharacters().getGainedCharacters().contains( dc ) ) {
+ nodes.add( n );
+ }
+ }
+ for( int i = 0; i < ( nodes.size() - 1 ); ++i ) {
+ for( int j = i + 1; j < nodes.size(); ++j ) {
+ final PhylogenyNode lca = PhylogenyMethods.calculateLCA( nodes.get( i ), nodes.get( j ) );
+ String rank = "unknown";
+ if ( lca.getNodeData().isHasTaxonomy()
+ && !ForesterUtil.isEmpty( lca.getNodeData().getTaxonomy().getRank() ) ) {
+ rank = lca.getNodeData().getTaxonomy().getRank();
+ }
+ addToCountMap( lca_rank_counts, rank );
+ String lca_species;
+ if ( lca.getNodeData().isHasTaxonomy()
+ && !ForesterUtil.isEmpty( lca.getNodeData().getTaxonomy().getScientificName() ) ) {
+ lca_species = lca.getNodeData().getTaxonomy().getScientificName();
+ }
+ else if ( lca.getNodeData().isHasTaxonomy()
+ && !ForesterUtil.isEmpty( lca.getNodeData().getTaxonomy().getCommonName() ) ) {
+ lca_species = lca.getNodeData().getTaxonomy().getCommonName();