- private static void checkWriteabilityForPairwiseComparisons( final PrintableDomainSimilarity.PRINT_OPTION domain_similarity_print_option,
- final String[][] input_file_properties,
- final String automated_pairwise_comparison_suffix,
- final File outdir ) {
- for( int i = 0; i < input_file_properties.length; ++i ) {
- for( int j = 0; j < i; ++j ) {
- final String species_i = input_file_properties[ i ][ 1 ];
- final String species_j = input_file_properties[ j ][ 1 ];
- String pairwise_similarities_output_file_str = PAIRWISE_DOMAIN_COMPARISONS_PREFIX + species_i + "_"
- + species_j + automated_pairwise_comparison_suffix;
- switch ( domain_similarity_print_option ) {
- case HTML:
- if ( !pairwise_similarities_output_file_str.endsWith( ".html" ) ) {
- pairwise_similarities_output_file_str += ".html";
- }
- break;
- }
- final String error = ForesterUtil
- .isWritableFile( new File( outdir == null ? pairwise_similarities_output_file_str : outdir
- + ForesterUtil.FILE_SEPARATOR + pairwise_similarities_output_file_str ) );
- if ( !ForesterUtil.isEmpty( error ) ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME, error );
- }
- }
- }
- }
-
- private static StringBuilder createParametersAsString( final boolean ignore_dufs,
- final double e_value_max,
- final int max_allowed_overlap,
- final boolean no_engulfing_overlaps,
- final File cutoff_scores_file,
- final BinaryDomainCombination.DomainCombinationType dc_type ) {
- final StringBuilder parameters_sb = new StringBuilder();
- parameters_sb.append( "E-value: " + e_value_max );
- if ( cutoff_scores_file != null ) {
- parameters_sb.append( ", Cutoff-scores-file: " + cutoff_scores_file );
- }
- else {
- parameters_sb.append( ", Cutoff-scores-file: not-set" );
- }
- if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
- parameters_sb.append( ", Max-overlap: " + max_allowed_overlap );
- }
- else {
- parameters_sb.append( ", Max-overlap: not-set" );
- }
- if ( no_engulfing_overlaps ) {
- parameters_sb.append( ", Engulfing-overlaps: not-allowed" );
- }
- else {
- parameters_sb.append( ", Engulfing-overlaps: allowed" );
- }
- if ( ignore_dufs ) {
- parameters_sb.append( ", Ignore-dufs: true" );
- }
- else {
- parameters_sb.append( ", Ignore-dufs: false" );
- }
- parameters_sb.append( ", DC type (if applicable): " + dc_type );
- return parameters_sb;
- }
-
- /**
- * Warning: This side-effects 'all_bin_domain_combinations_encountered'!
- *
- *
- * @param output_file
- * @param all_bin_domain_combinations_changed
- * @param sum_of_all_domains_encountered
- * @param all_bin_domain_combinations_encountered
- * @param is_gains_analysis
- * @param protein_length_stats_by_dc
- * @throws IOException
- */
- private static void executeFitchGainsAnalysis( final File output_file,
- final List<BinaryDomainCombination> all_bin_domain_combinations_changed,
- final int sum_of_all_domains_encountered,
- final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered,
- final boolean is_gains_analysis ) throws IOException {
- SurfacingUtil.checkForOutputFileWriteability( output_file );
- final Writer out = ForesterUtil.createBufferedWriter( output_file );
- final SortedMap<Object, Integer> bdc_to_counts = ForesterUtil
- .listToSortedCountsMap( all_bin_domain_combinations_changed );
- final SortedSet<String> all_domains_in_combination_changed_more_than_once = new TreeSet<String>();
- final SortedSet<String> all_domains_in_combination_changed_only_once = new TreeSet<String>();
- int above_one = 0;
- int one = 0;
- for( final Object bdc_object : bdc_to_counts.keySet() ) {
- final BinaryDomainCombination bdc = ( BinaryDomainCombination ) bdc_object;
- final int count = bdc_to_counts.get( bdc_object );
- if ( count < 1 ) {
- ForesterUtil.unexpectedFatalError( PRG_NAME, "count < 1 " );
- }
- out.write( bdc + "\t" + count + ForesterUtil.LINE_SEPARATOR );
- if ( count > 1 ) {
- all_domains_in_combination_changed_more_than_once.add( bdc.getId0() );
- all_domains_in_combination_changed_more_than_once.add( bdc.getId1() );
- above_one++;
- }
- else if ( count == 1 ) {
- all_domains_in_combination_changed_only_once.add( bdc.getId0() );
- all_domains_in_combination_changed_only_once.add( bdc.getId1() );
- one++;
- }
- }
- final int all = all_bin_domain_combinations_encountered.size();
- int never_lost = -1;
- if ( !is_gains_analysis ) {
- all_bin_domain_combinations_encountered.removeAll( all_bin_domain_combinations_changed );
- never_lost = all_bin_domain_combinations_encountered.size();
- for( final BinaryDomainCombination bdc : all_bin_domain_combinations_encountered ) {
- out.write( bdc + "\t" + "0" + ForesterUtil.LINE_SEPARATOR );
- }
- }
- if ( is_gains_analysis ) {
- out.write( "Sum of all distinct domain combinations appearing once : " + one
- + ForesterUtil.LINE_SEPARATOR );
- out.write( "Sum of all distinct domain combinations appearing more than once : " + above_one
- + ForesterUtil.LINE_SEPARATOR );
- out.write( "Sum of all distinct domains in combinations apppearing only once : "
- + all_domains_in_combination_changed_only_once.size() + ForesterUtil.LINE_SEPARATOR );
- out.write( "Sum of all distinct domains in combinations apppearing more than once: "
- + all_domains_in_combination_changed_more_than_once.size() + ForesterUtil.LINE_SEPARATOR );
- }
- else {
- out.write( "Sum of all distinct domain combinations never lost : " + never_lost
- + ForesterUtil.LINE_SEPARATOR );
- out.write( "Sum of all distinct domain combinations lost once : " + one
- + ForesterUtil.LINE_SEPARATOR );
- out.write( "Sum of all distinct domain combinations lost more than once : " + above_one
- + ForesterUtil.LINE_SEPARATOR );
- out.write( "Sum of all distinct domains in combinations lost only once : "
- + all_domains_in_combination_changed_only_once.size() + ForesterUtil.LINE_SEPARATOR );
- out.write( "Sum of all distinct domains in combinations lost more than once: "
- + all_domains_in_combination_changed_more_than_once.size() + ForesterUtil.LINE_SEPARATOR );
- }
- out.write( "All binary combinations : " + all
- + ForesterUtil.LINE_SEPARATOR );
- out.write( "All domains : "
- + sum_of_all_domains_encountered );
- out.close();
- ForesterUtil.programMessage( surfacing.PRG_NAME,
- "Wrote fitch domain combination dynamics counts analysis to \"" + output_file
- + "\"" );
- }
-
- private static void executePlusMinusAnalysis( final File output_file,
- final List<String> plus_minus_analysis_high_copy_base,
- final List<String> plus_minus_analysis_high_copy_target,
- final List<String> plus_minus_analysis_low_copy,
- final List<GenomeWideCombinableDomains> gwcd_list,
- final SortedMap<Species, List<Protein>> protein_lists_per_species,
- final Map<String, List<GoId>> domain_id_to_go_ids_map,
- final Map<GoId, GoTerm> go_id_to_term_map,
- final List<Object> plus_minus_analysis_numbers ) {
- final Set<String> all_spec = new HashSet<String>();
- for( final GenomeWideCombinableDomains gwcd : gwcd_list ) {
- all_spec.add( gwcd.getSpecies().getSpeciesId() );
- }
- final File html_out_dom = new File( output_file + PLUS_MINUS_DOM_SUFFIX_HTML );
- final File plain_out_dom = new File( output_file + PLUS_MINUS_DOM_SUFFIX );
- final File html_out_dc = new File( output_file + PLUS_MINUS_DC_SUFFIX_HTML );
- final File all_domains_go_ids_out_dom = new File( output_file + PLUS_MINUS_ALL_GO_IDS_DOM_SUFFIX );
- final File passing_domains_go_ids_out_dom = new File( output_file + PLUS_MINUS_PASSING_GO_IDS_DOM_SUFFIX );
- final File proteins_file_base = new File( output_file + "" );
- final int min_diff = ( ( Integer ) plus_minus_analysis_numbers.get( 0 ) ).intValue();
- final double factor = ( ( Double ) plus_minus_analysis_numbers.get( 1 ) ).doubleValue();
- try {
- DomainCountsDifferenceUtil.calculateCopyNumberDifferences( gwcd_list,
- protein_lists_per_species,
- plus_minus_analysis_high_copy_base,
- plus_minus_analysis_high_copy_target,
- plus_minus_analysis_low_copy,
- min_diff,
- factor,
- plain_out_dom,
- html_out_dom,
- html_out_dc,
- domain_id_to_go_ids_map,
- go_id_to_term_map,
- all_domains_go_ids_out_dom,
- passing_domains_go_ids_out_dom,
- proteins_file_base );
- }
- catch ( final IOException e ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
- }
- ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote plus minus domain analysis results to \""
- + html_out_dom + "\"" );
- ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote plus minus domain analysis results to \""
- + plain_out_dom + "\"" );
- ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote plus minus domain analysis results to \"" + html_out_dc
- + "\"" );
- ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote plus minus domain analysis based passing GO ids to \""
- + passing_domains_go_ids_out_dom + "\"" );
- ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote plus minus domain analysis based all GO ids to \""
- + all_domains_go_ids_out_dom + "\"" );
- }
-
- private static Phylogeny[] getIntrees( final File[] intree_files,
- final int number_of_genomes,
- final String[][] input_file_properties ) {
- final Phylogeny[] intrees = new Phylogeny[ intree_files.length ];
- int i = 0;
- for( final File intree_file : intree_files ) {
- Phylogeny intree = null;
- final String error = ForesterUtil.isReadableFile( intree_file );
- if ( !ForesterUtil.isEmpty( error ) ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read input tree file [" + intree_file + "]: "
- + error );
- }
- try {
- final Phylogeny[] p_array = ParserBasedPhylogenyFactory.getInstance()
- .create( intree_file, ParserUtils.createParserDependingOnFileType( intree_file, true ) );
- if ( p_array.length < 1 ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME, "file [" + intree_file
- + "] does not contain any phylogeny in phyloXML format" );
- }
- else if ( p_array.length > 1 ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME, "file [" + intree_file
- + "] contains more than one phylogeny in phyloXML format" );
- }
- intree = p_array[ 0 ];
- }
- catch ( final Exception e ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME, "failed to read input tree from file [" + intree_file
- + "]: " + error );
- }
- if ( ( intree == null ) || intree.isEmpty() ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME, "input tree [" + intree_file + "] is empty" );
- }
- if ( !intree.isRooted() ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME, "input tree [" + intree_file + "] is not rooted" );
- }
- if ( intree.getNumberOfExternalNodes() < number_of_genomes ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME,
- "number of external nodes [" + intree.getNumberOfExternalNodes()
- + "] of input tree [" + intree_file
- + "] is smaller than the number of genomes the be analyzed ["
- + number_of_genomes + "]" );
- }
- final StringBuilder parent_names = new StringBuilder();
- final int nodes_lacking_name = SurfacingUtil.getNumberOfNodesLackingName( intree, parent_names );
- if ( nodes_lacking_name > 0 ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME, "input tree [" + intree_file + "] has "
- + nodes_lacking_name + " node(s) lacking a name [parent names:" + parent_names + "]" );
- }
- preparePhylogenyForParsimonyAnalyses( intree, input_file_properties );
- if ( !intree.isCompletelyBinary() ) {
- ForesterUtil.printWarningMessage( surfacing.PRG_NAME, "input tree [" + intree_file
- + "] is not completely binary" );
- }
- intrees[ i++ ] = intree;
- }
- return intrees;
- }
-
- private static void log( final String msg, final Writer w ) {
- try {
- w.write( msg );
- w.write( ForesterUtil.LINE_SEPARATOR );
- }
- catch ( final IOException e ) {
- ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
- }
- }
-