3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: www.phylosoft.org/forester
27 package org.forester.application;
29 import java.io.BufferedWriter;
31 import java.io.FileWriter;
32 import java.io.IOException;
33 import java.io.Writer;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.List;
40 import java.util.SortedMap;
41 import java.util.SortedSet;
42 import java.util.TreeMap;
43 import java.util.TreeSet;
45 import org.forester.evoinference.distance.NeighborJoining;
46 import org.forester.evoinference.matrix.distance.DistanceMatrix;
47 import org.forester.go.GoId;
48 import org.forester.go.GoNameSpace;
49 import org.forester.go.GoTerm;
50 import org.forester.go.GoUtils;
51 import org.forester.go.OBOparser;
52 import org.forester.go.PfamToGoMapping;
53 import org.forester.go.PfamToGoParser;
54 import org.forester.io.parsers.HmmPfamOutputParser;
55 import org.forester.io.parsers.util.ParserUtils;
56 import org.forester.io.writers.PhylogenyWriter;
57 import org.forester.phylogeny.Phylogeny;
58 import org.forester.phylogeny.PhylogenyMethods;
59 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
60 import org.forester.surfacing.BasicDomainSimilarityCalculator;
61 import org.forester.surfacing.BasicGenomeWideCombinableDomains;
62 import org.forester.surfacing.BasicSpecies;
63 import org.forester.surfacing.BinaryDomainCombination;
64 import org.forester.surfacing.CombinationsBasedPairwiseDomainSimilarityCalculator;
65 import org.forester.surfacing.DomainCountsBasedPairwiseSimilarityCalculator;
66 import org.forester.surfacing.DomainCountsDifferenceUtil;
67 import org.forester.surfacing.DomainId;
68 import org.forester.surfacing.DomainLengthsTable;
69 import org.forester.surfacing.DomainParsimonyCalculator;
70 import org.forester.surfacing.DomainSimilarity;
71 import org.forester.surfacing.DomainSimilarity.DomainSimilarityScoring;
72 import org.forester.surfacing.DomainSimilarity.DomainSimilaritySortField;
73 import org.forester.surfacing.DomainSimilarityCalculator;
74 import org.forester.surfacing.DomainSimilarityCalculator.Detailedness;
75 import org.forester.surfacing.GenomeWideCombinableDomains;
76 import org.forester.surfacing.GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder;
77 import org.forester.surfacing.MappingResults;
78 import org.forester.surfacing.PairwiseDomainSimilarityCalculator;
79 import org.forester.surfacing.PairwiseGenomeComparator;
80 import org.forester.surfacing.PrintableDomainSimilarity;
81 import org.forester.surfacing.PrintableDomainSimilarity.PRINT_OPTION;
82 import org.forester.surfacing.Protein;
83 import org.forester.surfacing.ProteinCountsBasedPairwiseDomainSimilarityCalculator;
84 import org.forester.surfacing.Species;
85 import org.forester.surfacing.SurfacingUtil;
86 import org.forester.util.BasicTable;
87 import org.forester.util.BasicTableParser;
88 import org.forester.util.CommandLineArguments;
89 import org.forester.util.DescriptiveStatistics;
90 import org.forester.util.ForesterConstants;
91 import org.forester.util.ForesterUtil;
93 public class surfacing_hmmpfam {
95 public final static String DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS = "graph_analysis_out";
96 public final static String DOMAIN_COMBINITONS_OUTPUTFILE_SUFFIX_FOR_GRAPH_ANALYSIS = "_dc.dot";
97 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_BC_OUTPUTFILE_SUFFIX_FOR_GRAPH_ANALYSIS = "_fitch_present_dc.dot";
98 public final static String DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX = ".dcc";
100 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_DOMAINS = "_dollo_gl_d";
101 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_BINARY_COMBINATIONS = "_dollo_gl_dc";
102 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_FITCH_DOMAINS = "_fitch_gl_d";
103 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_FITCH_BINARY_COMBINATIONS = "_fitch_gl_dc";
105 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_DOMAINS = "_dollo_glc_d";
106 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_BINARY_COMBINATIONS = "_dollo_glc_dc";
107 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_FITCH_DOMAINS = "_fitch_glc_d";
108 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_FITCH_BINARY_COMBINATIONS = "_fitch_glc_dc";
110 public final static String PARSIMONY_OUTPUT_FITCH_GAINS_BC = "_fitch_gains_dc";
111 public final static String PARSIMONY_OUTPUT_FITCH_GAINS_HTML_BC = "_fitch_gains_dc.html";
112 public final static String PARSIMONY_OUTPUT_FITCH_LOSSES_BC = "_fitch_losses_dc";
113 public final static String PARSIMONY_OUTPUT_FITCH_LOSSES_HTML_BC = "_fitch_losses_dc.html";
114 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_BC = "_fitch_present_dc";
115 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_HTML_BC = "_fitch_present_dc.html";
116 public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_D = "_dollo_gains_d";
117 public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_GOID_D = "_dollo_gains_goid_d";
118 public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_HTML_D = "_dollo_gains_d.html";
119 public final static String PARSIMONY_OUTPUT_DOLLO_LOSSES_D = "_dollo_losses_d";
120 public final static String PARSIMONY_OUTPUT_DOLLO_LOSSES_HTML_D = "_dollo_losses_d.html";
121 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_D = "_dollo_present_d";
122 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_GOID_D = "_dollo_present_goid_d";
123 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_HTML_D = "_dollo_present_d.html";
124 public final static String DOMAINS_PRESENT_NEXUS = "_dom.nex";
125 public final static String BDC_PRESENT_NEXUS = "_dc.nex";
127 public final static String PRG_NAME = "surfacing";
128 public static final String DOMAINS_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_d_dollo"
129 + ForesterConstants.PHYLO_XML_SUFFIX;
130 public static final String DOMAINS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH = "_d_fitch"
131 + ForesterConstants.PHYLO_XML_SUFFIX;
132 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_dc_dollo"
133 + ForesterConstants.PHYLO_XML_SUFFIX;
134 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH = "_dc_fitch"
135 + ForesterConstants.PHYLO_XML_SUFFIX;
136 public static final String NEXUS_EXTERNAL_DOMAINS = "_dom.nex";
137 public static final String NEXUS_EXTERNAL_DOMAIN_COMBINATIONS = "_dc.nex";
138 public static final String NEXUS_SECONDARY_FEATURES = "_secondary_features.nex";
139 public static final String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_SECONDARY_FEATURES = "_dollo_gl_secondary_features";
140 public static final String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_SECONDARY_FEATURES = "_dollo_glc_secondary_features";
141 public static final String PARSIMONY_OUTPUT_DOLLO_GAINS_SECONDARY_FEATURES = "_dollo_gains_secondary_features";
142 public static final String PARSIMONY_OUTPUT_DOLLO_LOSSES_SECONDARY_FEATURES = "_dollo_losses_secondary_features";
143 public static final String PARSIMONY_OUTPUT_DOLLO_PRESENT_SECONDARY_FEATURES = "_dollo_present_secondary_features";
144 public static final String SECONDARY_FEATURES_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_secondary_features_dollo"
145 + ForesterConstants.PHYLO_XML_SUFFIX;
146 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_BIOLOGICAL_PROCESS = "_dollo_biol_proc_goid_d";
147 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_CELLULAR_COMPONENT = "_dollo_cell_comp_goid_d";
148 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_MOLECULAR_FUNCTION = "_dollo_mol_funct_goid_d";
149 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_ALL_NAMESPACES = "_dollo_goid_d";
150 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_BIOLOGICAL_PROCESS = "_fitch_biol_proc_goid_dc";
151 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_CELLULAR_COMPONENT = "_fitch_cell_comp_goid_dc";
152 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_MOLECULAR_FUNCTION = "_fitch_mol_funct_goid_dc";
153 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_ALL_NAMESPACES = "_fitch_goid_dc";
154 final static private String HELP_OPTION_1 = "help";
155 final static private String HELP_OPTION_2 = "h";
156 final static private String OUTPUT_DIR_OPTION = "out_dir";
157 final static private String SCORING_OPTION = "scoring";
158 private static final DomainSimilarityScoring SCORING_DEFAULT = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
159 final static private String SCORING_DOMAIN_COUNT_BASED = "domains";
160 final static private String SCORING_PROTEIN_COUNT_BASED = "proteins";
161 final static private String SCORING_COMBINATION_BASED = "combinations";
162 final static private String DETAILEDNESS_OPTION = "detail";
163 private final static Detailedness DETAILEDNESS_DEFAULT = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
164 final static private String SPECIES_MATRIX_OPTION = "smatrix";
165 final static private String DETAILEDNESS_BASIC = "basic";
166 final static private String DETAILEDNESS_LIST_IDS = "list_ids";
167 final static private String DETAILEDNESS_PUNCTILIOUS = "punctilious";
168 final static private String DOMAIN_SIMILARITY_SORT_OPTION = "sort";
169 private static final DomainSimilaritySortField DOMAIN_SORT_FILD_DEFAULT = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
170 final static private String DOMAIN_SIMILARITY_SORT_MIN = "min";
171 final static private String DOMAIN_SIMILARITY_SORT_MAX = "max";
172 final static private String DOMAIN_SIMILARITY_SORT_SD = "sd";
173 final static private String DOMAIN_SIMILARITY_SORT_MEAN = "mean";
174 final static private String DOMAIN_SIMILARITY_SORT_DIFF = "diff";
175 final static private String DOMAIN_SIMILARITY_SORT_COUNTS_DIFF = "count_diff";
176 final static private String DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF = "abs_count_diff";
177 final static private String DOMAIN_SIMILARITY_SORT_SPECIES_COUNT = "species";
178 final static private String DOMAIN_SIMILARITY_SORT_ALPHA = "alpha";
179 final static private String DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION = "species_first";
180 final static private String DOMAIN_COUNT_SORT_OPTION = "dc_sort";
181 private static final GenomeWideCombinableDomainsSortOrder DOMAINS_SORT_ORDER_DEFAULT = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
182 final static private String DOMAIN_COUNT_SORT_ALPHA = "alpha";
183 final static private String DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT = "dom";
184 final static private String DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT = "prot";
185 final static private String DOMAIN_COUNT_SORT_COMBINATIONS_COUNT = "comb";
186 final static private String CUTOFF_SCORE_FILE_OPTION = "cos";
187 final static private String NOT_IGNORE_DUFS_OPTION = "dufs";
188 final static private String MAX_E_VALUE_OPTION = "e";
189 final static private String MAX_ALLOWED_OVERLAP_OPTION = "mo";
190 final static private String NO_ENGULFING_OVERLAP_OPTION = "no_eo";
191 final static private String IGNORE_COMBINATION_WITH_SAME_OPTION = "ignore_self_comb";
192 final static private String PAIRWISE_DOMAIN_COMPARISONS_PREFIX = "pwc_";
193 final static private String PAIRWISE_DOMAIN_COMPARISONS_OPTION = "pwc";
194 final static private String OUTPUT_FILE_OPTION = "o";
195 final static private String PFAM_TO_GO_FILE_USE_OPTION = "p2g";
196 final static private String GO_OBO_FILE_USE_OPTION = "obo";
197 final static private String GO_NAMESPACE_LIMIT_OPTION = "go_namespace";
198 final static private String GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION = "molecular_function";
199 final static private String GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS = "biological_process";
200 final static private String GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT = "cellular_component";
201 final static private String SECONDARY_FEATURES_PARSIMONY_MAP_FILE = "secondary";
202 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED = "simple_tab";
203 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML = "simple_html";
204 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML = "detailed_html";
205 final static private String DOMAIN_SIMILARITY_PRINT_OPTION = "ds_output";
206 private static final PRINT_OPTION DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT = PrintableDomainSimilarity.PRINT_OPTION.HTML;
207 final static private String IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION = "ignore_singlet_domains";
208 final static private String IGNORE_VIRAL_IDS = "ignore_viral_ids";
209 final static private boolean IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT = false;
210 final static private String IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION = "ignore_species_specific_domains";
211 final static private boolean IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT = false;
212 final static private String MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score.pwd";
213 final static private String MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains.pwd";
214 final static private String MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations.pwd";
215 final static private String NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score_NJ"
216 + ForesterConstants.PHYLO_XML_SUFFIX;
217 final static private String NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains_NJ"
218 + ForesterConstants.PHYLO_XML_SUFFIX;
219 final static private String NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations_NJ"
220 + ForesterConstants.PHYLO_XML_SUFFIX;
221 final static private String DISPLAY_M_HISTOGRAMS_OPTION = "mhisto";
222 // final static private boolean DISPLAY_M_HISTOGRAMS_OPTION_DEFAULT = false;
223 final static private String JACKNIFE_OPTION = "jack";
224 final static private String JACKNIFE_RANDOM_SEED_OPTION = "seed";
225 final static private String JACKNIFE_RATIO_OPTION = "jack_ratio";
226 private static final int JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT = 100;
227 final static private long JACKNIFE_RANDOM_SEED_DEFAULT = 19;
228 final static private double JACKNIFE_RATIO_DEFAULT = 0.5;
229 //final static private String INFER_SPECIES_TREES_OPTION = "species_tree_inference";
230 final static private String INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX = "_sd_nj.nh";
231 final static private String INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX = "_sbc_nj.nh";
232 final static private String FILTER_POSITIVE_OPTION = "pos_filter";
233 final static private String FILTER_NEGATIVE_OPTION = "neg_filter";
234 final static private String FILTER_NEGATIVE_DOMAINS_OPTION = "neg_dom_filter";
235 final static private String INPUT_FILES_FROM_FILE_OPTION = "input";
236 final static private String INPUT_SPECIES_TREE_OPTION = "species_tree";
237 final static private String SEQ_EXTRACT_OPTION = "prot_extract";
238 final static private char SEPARATOR_FOR_INPUT_VALUES = '#';
239 final static private String PRG_VERSION = "1.00";
240 final static private String PRG_DATE = "2009.07.06";
241 final static private String E_MAIL = "czmasek@burnham.org";
242 final static private String WWW = "www.phylosoft.org/forester/applications/surfacing";
243 final static private boolean IGNORE_DUFS_DEFAULT = true;
244 final static private boolean IGNORE_COMBINATION_WITH_SAME_DEFAULLT = false;
245 final static private double MAX_E_VALUE_DEFAULT = -1;
246 final static private int MAX_ALLOWED_OVERLAP_DEFAULT = -1;
247 final static private String DEFAULT_SEARCH_PARAMETER = "ls";
248 final private static boolean ALLOW_NON_UNIQUE_QUERY_IN_HMMPFAM_OUTPUT_DEFAULT = true;
249 final private static boolean VERBOSE_DEFAULT = true;
250 private static final String RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION = "random_seed";
251 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS = "consider_bdc_direction";
252 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY = "consider_bdc_adj";
253 private static final String SEQ_EXTRACT_SUFFIX = ".prot";
254 private static final String PLUS_MINUS_ANALYSIS_OPTION = "plus_minus";
255 private static final String PLUS_MINUS_DOM_SUFFIX = "_plus_minus_dom.txt";
256 private static final String PLUS_MINUS_DOM_SUFFIX_HTML = "_plus_minus_dom.html";
257 private static final String PLUS_MINUS_DC_SUFFIX_HTML = "_plus_minus_dc.html";
258 private static final int PLUS_MINUS_ANALYSIS_MIN_DIFF_DEFAULT = 0;
259 private static final double PLUS_MINUS_ANALYSIS_FACTOR_DEFAULT = 1.0;
260 private static final String PLUS_MINUS_ALL_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_all.txt";
261 private static final String PLUS_MINUS_PASSING_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_passing.txt";
262 private static final String OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS = "all_prot";
263 private static final boolean VERBOSE = false;
264 private static final String OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_gains_counts";
265 private static final String OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_losses_counts";
266 private static final String DOMAIN_LENGTHS_ANALYSIS_SUFFIX = "_domain_lengths_analysis";
267 private static final boolean PERFORM_DOMAIN_LENGTH_ANALYSIS = true;
268 public static final String ALL_PFAMS_ENCOUNTERED_SUFFIX = "_all_encountered_pfams";
269 public static final String ALL_PFAMS_ENCOUNTERED_WITH_GO_ANNOTATION_SUFFIX = "_all_encountered_pfams_with_go_annotation";
270 public static final String ENCOUNTERED_PFAMS_SUMMARY_SUFFIX = "_encountered_pfams_summary";
271 public static final String ALL_PFAMS_GAINED_AS_DOMAINS_SUFFIX = "_all_pfams_gained_as_domains";
272 public static final String ALL_PFAMS_LOST_AS_DOMAINS_SUFFIX = "_all_pfams_lost_as_domains";
273 public static final String ALL_PFAMS_GAINED_AS_DC_SUFFIX = "_all_pfams_gained_as_dc";
274 public static final String ALL_PFAMS_LOST_AS_DC_SUFFIX = "_all_pfams_lost_as_dc";
275 public static final String BASE_DIRECTORY_PER_NODE_DOMAIN_GAIN_LOSS_FILES = "PER_NODE_EVENTS";
276 public static final String BASE_DIRECTORY_PER_SUBTREE_DOMAIN_GAIN_LOSS_FILES = "PER_SUBTREE_EVENTS";
277 public static final String D_PROMISCUITY_FILE_SUFFIX = "_domain_promiscuities";
279 // final String error = ForesterUtil.isReadableFile( new File(
280 // input_file_properties[ i ][ 0 ] ) );
281 // if ( !ForesterUtil.isEmpty( error ) ) {
282 // ForesterUtil.fatalError( surfacing.PRG_NAME, error );
284 private static void checkWriteabilityForPairwiseComparisons( final PrintableDomainSimilarity.PRINT_OPTION domain_similarity_print_option,
285 final String[][] input_file_properties,
286 final String automated_pairwise_comparison_suffix,
287 final File outdir ) {
288 for( int i = 0; i < input_file_properties.length; ++i ) {
289 for( int j = 0; j < i; ++j ) {
290 final String species_i = input_file_properties[ i ][ 1 ];
291 final String species_j = input_file_properties[ j ][ 1 ];
292 String pairwise_similarities_output_file_str = PAIRWISE_DOMAIN_COMPARISONS_PREFIX + species_i + "_"
293 + species_j + automated_pairwise_comparison_suffix;
294 switch ( domain_similarity_print_option ) {
296 if ( !pairwise_similarities_output_file_str.endsWith( ".html" ) ) {
297 pairwise_similarities_output_file_str += ".html";
301 final String error = ForesterUtil
302 .isWritableFile( new File( outdir == null ? pairwise_similarities_output_file_str : outdir
303 + ForesterUtil.FILE_SEPARATOR + pairwise_similarities_output_file_str ) );
304 if ( !ForesterUtil.isEmpty( error ) ) {
305 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, error );
311 private static StringBuilder createParametersAsString( final boolean ignore_dufs,
312 final double e_value_max,
313 final int max_allowed_overlap,
314 final boolean no_engulfing_overlaps,
315 final File cutoff_scores_file,
316 final BinaryDomainCombination.DomainCombinationType dc_type ) {
317 final StringBuilder parameters_sb = new StringBuilder();
318 parameters_sb.append( "E-value: " + e_value_max );
319 if ( cutoff_scores_file != null ) {
320 parameters_sb.append( ", Cutoff-scores-file: " + cutoff_scores_file );
323 parameters_sb.append( ", Cutoff-scores-file: not-set" );
325 if ( max_allowed_overlap != surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_DEFAULT ) {
326 parameters_sb.append( ", Max-overlap: " + max_allowed_overlap );
329 parameters_sb.append( ", Max-overlap: not-set" );
331 if ( no_engulfing_overlaps ) {
332 parameters_sb.append( ", Engulfing-overlaps: not-allowed" );
335 parameters_sb.append( ", Engulfing-overlaps: allowed" );
338 parameters_sb.append( ", Ignore-dufs: true" );
341 parameters_sb.append( ", Ignore-dufs: false" );
343 parameters_sb.append( ", DC type (if applicable): " + dc_type );
344 return parameters_sb;
348 * Warning: This sideeffects 'all_bin_domain_combinations_encountered'!
352 * @param all_bin_domain_combinations_changed
353 * @param sum_of_all_domains_encountered
354 * @param all_bin_domain_combinations_encountered
355 * @param is_gains_analysis
356 * @throws IOException
358 private static void executeFitchGainsAnalysis( final File output_file,
359 final List<BinaryDomainCombination> all_bin_domain_combinations_changed,
360 final int sum_of_all_domains_encountered,
361 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered,
362 final boolean is_gains_analysis ) throws IOException {
363 SurfacingUtil.checkForOutputFileWriteability( output_file );
364 final Writer out = ForesterUtil.createBufferedWriter( output_file );
365 final SortedMap<Object, Integer> bdc_to_counts = ForesterUtil
366 .listToSortedCountsMap( all_bin_domain_combinations_changed );
367 final SortedSet<DomainId> all_domains_in_combination_changed_more_than_once = new TreeSet<DomainId>();
368 final SortedSet<DomainId> all_domains_in_combination_changed_only_once = new TreeSet<DomainId>();
371 for( final Object bdc_object : bdc_to_counts.keySet() ) {
372 final BinaryDomainCombination bdc = ( BinaryDomainCombination ) bdc_object;
373 final int count = bdc_to_counts.get( bdc_object );
375 ForesterUtil.unexpectedFatalError( PRG_NAME, "count < 1 " );
377 out.write( bdc + "\t" + count + ForesterUtil.LINE_SEPARATOR );
379 all_domains_in_combination_changed_more_than_once.add( bdc.getId0() );
380 all_domains_in_combination_changed_more_than_once.add( bdc.getId1() );
383 else if ( count == 1 ) {
384 all_domains_in_combination_changed_only_once.add( bdc.getId0() );
385 all_domains_in_combination_changed_only_once.add( bdc.getId1() );
389 final int all = all_bin_domain_combinations_encountered.size();
391 if ( !is_gains_analysis ) {
392 all_bin_domain_combinations_encountered.removeAll( all_bin_domain_combinations_changed );
393 never_lost = all_bin_domain_combinations_encountered.size();
394 for( final BinaryDomainCombination bdc : all_bin_domain_combinations_encountered ) {
395 out.write( bdc + "\t" + "0" + ForesterUtil.LINE_SEPARATOR );
398 if ( is_gains_analysis ) {
399 out.write( "Sum of all distinct domain combinations appearing once : " + one
400 + ForesterUtil.LINE_SEPARATOR );
401 out.write( "Sum of all distinct domain combinations appearing more than once : " + above_one
402 + ForesterUtil.LINE_SEPARATOR );
403 out.write( "Sum of all distinct domains in combinations apppearing only once : "
404 + all_domains_in_combination_changed_only_once.size() + ForesterUtil.LINE_SEPARATOR );
405 out.write( "Sum of all distinct domains in combinations apppearing more than once: "
406 + all_domains_in_combination_changed_more_than_once.size() + ForesterUtil.LINE_SEPARATOR );
409 out.write( "Sum of all distinct domain combinations never lost : " + never_lost
410 + ForesterUtil.LINE_SEPARATOR );
411 out.write( "Sum of all distinct domain combinations lost once : " + one
412 + ForesterUtil.LINE_SEPARATOR );
413 out.write( "Sum of all distinct domain combinations lost more than once : " + above_one
414 + ForesterUtil.LINE_SEPARATOR );
415 out.write( "Sum of all distinct domains in combinations lost only once : "
416 + all_domains_in_combination_changed_only_once.size() + ForesterUtil.LINE_SEPARATOR );
417 out.write( "Sum of all distinct domains in combinations lost more than once: "
418 + all_domains_in_combination_changed_more_than_once.size() + ForesterUtil.LINE_SEPARATOR );
420 out.write( "All binary combinations : " + all
421 + ForesterUtil.LINE_SEPARATOR );
422 out.write( "All domains : "
423 + sum_of_all_domains_encountered );
425 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME,
426 "Wrote fitch domain combination dynamics counts analysis to \"" + output_file
430 private static void executePlusMinusAnalysis( final File output_file,
431 final List<String> plus_minus_analysis_high_copy_base,
432 final List<String> plus_minus_analysis_high_copy_target,
433 final List<String> plus_minus_analysis_low_copy,
434 final List<GenomeWideCombinableDomains> gwcd_list,
435 final SortedMap<Species, List<Protein>> protein_lists_per_species,
436 final Map<DomainId, List<GoId>> domain_id_to_go_ids_map,
437 final Map<GoId, GoTerm> go_id_to_term_map,
438 final List<Object> plus_minus_analysis_numbers ) {
439 final Set<String> all_spec = new HashSet<String>();
440 for( final GenomeWideCombinableDomains gwcd : gwcd_list ) {
441 all_spec.add( gwcd.getSpecies().getSpeciesId() );
443 final File html_out_dom = new File( output_file + PLUS_MINUS_DOM_SUFFIX_HTML );
444 final File plain_out_dom = new File( output_file + PLUS_MINUS_DOM_SUFFIX );
445 final File html_out_dc = new File( output_file + PLUS_MINUS_DC_SUFFIX_HTML );
446 final File all_domains_go_ids_out_dom = new File( output_file + PLUS_MINUS_ALL_GO_IDS_DOM_SUFFIX );
447 final File passing_domains_go_ids_out_dom = new File( output_file + PLUS_MINUS_PASSING_GO_IDS_DOM_SUFFIX );
448 final File proteins_file_base = new File( output_file + "" );
449 final int min_diff = ( ( Integer ) plus_minus_analysis_numbers.get( 0 ) ).intValue();
450 final double factor = ( ( Double ) plus_minus_analysis_numbers.get( 1 ) ).doubleValue();
452 DomainCountsDifferenceUtil.calculateCopyNumberDifferences( gwcd_list,
453 protein_lists_per_species,
454 plus_minus_analysis_high_copy_base,
455 plus_minus_analysis_high_copy_target,
456 plus_minus_analysis_low_copy,
462 domain_id_to_go_ids_map,
464 all_domains_go_ids_out_dom,
465 passing_domains_go_ids_out_dom,
466 proteins_file_base );
468 catch ( final IOException e ) {
469 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getLocalizedMessage() );
471 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME, "Wrote plus minus domain analysis results to \""
472 + html_out_dom + "\"" );
473 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME, "Wrote plus minus domain analysis results to \""
474 + plain_out_dom + "\"" );
475 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME, "Wrote plus minus domain analysis results to \""
476 + html_out_dc + "\"" );
477 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME,
478 "Wrote plus minus domain analysis based passing GO ids to \""
479 + passing_domains_go_ids_out_dom + "\"" );
480 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME,
481 "Wrote plus minus domain analysis based all GO ids to \""
482 + all_domains_go_ids_out_dom + "\"" );
485 private static Phylogeny[] getIntrees( final File[] intree_files,
486 final int number_of_genomes,
487 final String[][] input_file_properties ) {
488 final Phylogeny[] intrees = new Phylogeny[ intree_files.length ];
490 for( final File intree_file : intree_files ) {
491 Phylogeny intree = null;
492 final String error = ForesterUtil.isReadableFile( intree_file );
493 if ( !ForesterUtil.isEmpty( error ) ) {
494 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read input tree file [" + intree_file
498 final Phylogeny[] p_array = ParserBasedPhylogenyFactory.getInstance()
499 .create( intree_file, ParserUtils.createParserDependingOnFileType( intree_file, true ) );
500 if ( p_array.length < 1 ) {
501 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "file [" + intree_file
502 + "] does not contain any phylogeny in phyloXML format" );
504 else if ( p_array.length > 1 ) {
505 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "file [" + intree_file
506 + "] contains more than one phylogeny in phyloXML format" );
508 intree = p_array[ 0 ];
510 catch ( final Exception e ) {
511 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "failed to read input tree from file ["
512 + intree_file + "]: " + error );
514 if ( ( intree == null ) || intree.isEmpty() ) {
515 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "input tree [" + intree_file + "] is empty" );
517 if ( !intree.isRooted() ) {
518 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "input tree [" + intree_file + "] is not rooted" );
520 if ( intree.getNumberOfExternalNodes() < number_of_genomes ) {
521 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
522 "number of external nodes [" + intree.getNumberOfExternalNodes()
523 + "] of input tree [" + intree_file
524 + "] is smaller than the number of genomes the be analyzed ["
525 + number_of_genomes + "]" );
527 final StringBuilder parent_names = new StringBuilder();
528 final int nodes_lacking_name = SurfacingUtil.getNumberOfNodesLackingName( intree, parent_names );
529 if ( nodes_lacking_name > 0 ) {
530 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "input tree [" + intree_file + "] has "
531 + nodes_lacking_name + " node(s) lacking a name [parent names:" + parent_names + "]" );
533 preparePhylogenyForParsimonyAnalyses( intree, input_file_properties );
534 if ( !intree.isCompletelyBinary() ) {
535 ForesterUtil.printWarningMessage( surfacing_hmmpfam.PRG_NAME, "input tree [" + intree_file
536 + "] is not completely binary" );
538 intrees[ i++ ] = intree;
543 private static List<Phylogeny> inferSpeciesTrees( final File outfile, final List<DistanceMatrix> distances_list ) {
544 final NeighborJoining nj = NeighborJoining.createInstance();
545 final List<Phylogeny> phylogenies = nj.execute( distances_list );
546 final PhylogenyWriter w = new PhylogenyWriter();
548 w.toNewHampshire( phylogenies, true, true, outfile, ";" );
550 catch ( final IOException e ) {
551 ForesterUtil.fatalError( PRG_NAME, "failed to write to outfile [" + outfile + "]: " + e.getMessage() );
556 public static void main( final String args[] ) {
557 final long start_time = new Date().getTime();
558 // final StringBuffer log = new StringBuffer();
559 final StringBuilder html_desc = new StringBuilder();
560 ForesterUtil.printProgramInformation( surfacing_hmmpfam.PRG_NAME,
561 surfacing_hmmpfam.PRG_VERSION,
562 surfacing_hmmpfam.PRG_DATE,
563 surfacing_hmmpfam.E_MAIL,
564 surfacing_hmmpfam.WWW );
565 final String nl = ForesterUtil.LINE_SEPARATOR;
566 html_desc.append( "<table>" + nl );
567 html_desc.append( "<tr><td>Produced by:</td><td>" + surfacing_hmmpfam.PRG_NAME + "</td></tr>" + nl );
568 html_desc.append( "<tr><td>Version:</td><td>" + surfacing_hmmpfam.PRG_VERSION + "</td></tr>" + nl );
569 html_desc.append( "<tr><td>Release Date:</td><td>" + surfacing_hmmpfam.PRG_DATE + "</td></tr>" + nl );
570 html_desc.append( "<tr><td>Contact:</td><td>" + surfacing_hmmpfam.E_MAIL + "</td></tr>" + nl );
571 html_desc.append( "<tr><td>WWW:</td><td>" + surfacing_hmmpfam.WWW + "</td></tr>" + nl );
572 CommandLineArguments cla = null;
574 cla = new CommandLineArguments( args );
576 catch ( final Exception e ) {
577 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage() );
579 if ( cla.isOptionSet( surfacing_hmmpfam.HELP_OPTION_1 ) || cla.isOptionSet( surfacing_hmmpfam.HELP_OPTION_2 ) ) {
580 surfacing_hmmpfam.printHelp();
583 if ( ( args.length < 1 ) ) {
584 surfacing_hmmpfam.printHelp();
587 final List<String> allowed_options = new ArrayList<String>();
588 allowed_options.add( surfacing_hmmpfam.NOT_IGNORE_DUFS_OPTION );
589 allowed_options.add( surfacing_hmmpfam.MAX_E_VALUE_OPTION );
590 allowed_options.add( surfacing_hmmpfam.DETAILEDNESS_OPTION );
591 allowed_options.add( surfacing_hmmpfam.OUTPUT_FILE_OPTION );
592 allowed_options.add( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION );
593 allowed_options.add( surfacing_hmmpfam.SPECIES_MATRIX_OPTION );
594 allowed_options.add( surfacing_hmmpfam.SCORING_OPTION );
595 allowed_options.add( surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_OPTION );
596 allowed_options.add( surfacing_hmmpfam.NO_ENGULFING_OVERLAP_OPTION );
597 allowed_options.add( surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION );
598 allowed_options.add( surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION );
599 allowed_options.add( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION );
600 allowed_options.add( surfacing_hmmpfam.OUTPUT_DIR_OPTION );
601 allowed_options.add( surfacing_hmmpfam.IGNORE_COMBINATION_WITH_SAME_OPTION );
602 allowed_options.add( surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION );
603 allowed_options.add( surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION );
604 allowed_options.add( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION );
605 allowed_options.add( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION );
606 allowed_options.add( surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
607 allowed_options.add( surfacing_hmmpfam.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION );
608 allowed_options.add( surfacing_hmmpfam.DISPLAY_M_HISTOGRAMS_OPTION );
609 allowed_options.add( surfacing_hmmpfam.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS );
610 allowed_options.add( JACKNIFE_OPTION );
611 allowed_options.add( JACKNIFE_RANDOM_SEED_OPTION );
612 allowed_options.add( JACKNIFE_RATIO_OPTION );
613 allowed_options.add( INPUT_SPECIES_TREE_OPTION );
614 //allowed_options.add( INFER_SPECIES_TREES_OPTION );
615 allowed_options.add( FILTER_POSITIVE_OPTION );
616 allowed_options.add( FILTER_NEGATIVE_OPTION );
617 allowed_options.add( INPUT_FILES_FROM_FILE_OPTION );
618 allowed_options.add( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
619 allowed_options.add( FILTER_NEGATIVE_DOMAINS_OPTION );
620 allowed_options.add( IGNORE_VIRAL_IDS );
621 allowed_options.add( SEQ_EXTRACT_OPTION );
622 allowed_options.add( SECONDARY_FEATURES_PARSIMONY_MAP_FILE );
623 allowed_options.add( PLUS_MINUS_ANALYSIS_OPTION );
624 allowed_options.add( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS );
625 allowed_options.add( OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS );
626 allowed_options.add( CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY );
627 boolean ignore_dufs = surfacing_hmmpfam.IGNORE_DUFS_DEFAULT;
628 boolean ignore_combination_with_same = surfacing_hmmpfam.IGNORE_COMBINATION_WITH_SAME_DEFAULLT;
629 double e_value_max = surfacing_hmmpfam.MAX_E_VALUE_DEFAULT;
630 int max_allowed_overlap = surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_DEFAULT;
631 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
632 if ( dissallowed_options.length() > 0 ) {
633 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown option(s): " + dissallowed_options );
635 boolean output_binary_domain_combinationsfor_graph_analysis = false;
636 if ( cla.isOptionSet( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS ) ) {
637 output_binary_domain_combinationsfor_graph_analysis = true;
639 if ( cla.isOptionSet( surfacing_hmmpfam.MAX_E_VALUE_OPTION ) ) {
641 e_value_max = cla.getOptionValueAsDouble( surfacing_hmmpfam.MAX_E_VALUE_OPTION );
643 catch ( final Exception e ) {
644 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no acceptable value for E-value maximum" );
647 if ( cla.isOptionSet( surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_OPTION ) ) {
649 max_allowed_overlap = cla.getOptionValueAsInt( surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_OPTION );
651 catch ( final Exception e ) {
652 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
653 "no acceptable value for maximal allowed domain overlap" );
656 boolean no_engulfing_overlaps = false;
657 if ( cla.isOptionSet( surfacing_hmmpfam.NO_ENGULFING_OVERLAP_OPTION ) ) {
658 no_engulfing_overlaps = true;
660 boolean ignore_virus_like_ids = false;
661 if ( cla.isOptionSet( surfacing_hmmpfam.IGNORE_VIRAL_IDS ) ) {
662 ignore_virus_like_ids = true;
664 if ( cla.isOptionSet( surfacing_hmmpfam.NOT_IGNORE_DUFS_OPTION ) ) {
667 if ( cla.isOptionSet( surfacing_hmmpfam.IGNORE_COMBINATION_WITH_SAME_OPTION ) ) {
668 ignore_combination_with_same = true;
670 boolean ignore_domains_without_combs_in_all_spec = IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT;
671 if ( cla.isOptionSet( surfacing_hmmpfam.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION ) ) {
672 ignore_domains_without_combs_in_all_spec = true;
674 boolean ignore_species_specific_domains = IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT;
675 if ( cla.isOptionSet( surfacing_hmmpfam.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION ) ) {
676 ignore_species_specific_domains = true;
678 File output_file = null;
679 if ( cla.isOptionSet( surfacing_hmmpfam.OUTPUT_FILE_OPTION ) ) {
680 if ( !cla.isOptionValueSet( surfacing_hmmpfam.OUTPUT_FILE_OPTION ) ) {
681 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
682 "no value for domain combinations similarities output file: -"
683 + surfacing_hmmpfam.OUTPUT_FILE_OPTION + "=<file>" );
685 output_file = new File( cla.getOptionValue( surfacing_hmmpfam.OUTPUT_FILE_OPTION ) );
686 SurfacingUtil.checkForOutputFileWriteability( output_file );
688 File cutoff_scores_file = null;
689 Map<String, String> individual_domain_score_cutoffs = null;
690 if ( cla.isOptionSet( surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION ) ) {
691 if ( !cla.isOptionValueSet( surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION ) ) {
692 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
693 "no value for individual domain score cutoffs file: -"
694 + surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION + "=<file>" );
696 cutoff_scores_file = new File( cla.getOptionValue( surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION ) );
697 final String error = ForesterUtil.isReadableFile( cutoff_scores_file );
698 if ( !ForesterUtil.isEmpty( error ) ) {
699 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
700 "cannot read individual domain score cutoffs file: " + error );
703 final BasicTable<String> scores_table = BasicTableParser.parse( cutoff_scores_file, " " );
704 individual_domain_score_cutoffs = scores_table.getColumnsAsMap( 0, 1 );
706 catch ( final IOException e ) {
707 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
708 "cannot read from individual domain score cutoffs file: " + e );
711 BinaryDomainCombination.DomainCombinationType dc_type = BinaryDomainCombination.DomainCombinationType.BASIC;
712 if ( cla.isOptionSet( surfacing_hmmpfam.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS ) ) {
713 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED;
715 if ( cla.isOptionSet( surfacing_hmmpfam.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY ) ) {
716 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT;
719 if ( cla.isOptionSet( surfacing_hmmpfam.OUTPUT_DIR_OPTION ) ) {
720 if ( !cla.isOptionValueSet( surfacing_hmmpfam.OUTPUT_DIR_OPTION ) ) {
721 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for output directory: -"
722 + surfacing_hmmpfam.OUTPUT_DIR_OPTION + "=<dir>" );
724 out_dir = new File( cla.getOptionValue( surfacing_hmmpfam.OUTPUT_DIR_OPTION ) );
725 if ( out_dir.exists() && ( out_dir.listFiles().length > 0 ) ) {
726 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "\"" + out_dir
727 + "\" aready exists and is not empty" );
729 if ( !out_dir.exists() ) {
730 final boolean success = out_dir.mkdir();
731 if ( !success || !out_dir.exists() ) {
732 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "failed to create \"" + out_dir + "\"" );
735 if ( !out_dir.canWrite() ) {
736 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot write to \"" + out_dir + "\"" );
739 File positive_filter_file = null;
740 File negative_filter_file = null;
741 File negative_domains_filter_file = null;
742 if ( cla.isOptionSet( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION )
743 && cla.isOptionSet( surfacing_hmmpfam.FILTER_POSITIVE_OPTION ) ) {
744 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
745 "attempt to use both negative and positive protein filter" );
747 if ( cla.isOptionSet( surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION )
748 && ( cla.isOptionSet( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION ) || cla
749 .isOptionSet( surfacing_hmmpfam.FILTER_POSITIVE_OPTION ) ) ) {
751 .fatalError( surfacing_hmmpfam.PRG_NAME,
752 "attempt to use both negative or positive protein filter together wirh a negative domains filter" );
754 if ( cla.isOptionSet( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION ) ) {
755 if ( !cla.isOptionValueSet( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION ) ) {
756 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for negative filter: -"
757 + surfacing_hmmpfam.FILTER_NEGATIVE_OPTION + "=<file>" );
759 negative_filter_file = new File( cla.getOptionValue( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION ) );
760 final String msg = ForesterUtil.isReadableFile( negative_filter_file );
761 if ( !ForesterUtil.isEmpty( msg ) ) {
762 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "can not read from \"" + negative_filter_file
766 else if ( cla.isOptionSet( surfacing_hmmpfam.FILTER_POSITIVE_OPTION ) ) {
767 if ( !cla.isOptionValueSet( surfacing_hmmpfam.FILTER_POSITIVE_OPTION ) ) {
768 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for positive filter: -"
769 + surfacing_hmmpfam.FILTER_POSITIVE_OPTION + "=<file>" );
771 positive_filter_file = new File( cla.getOptionValue( surfacing_hmmpfam.FILTER_POSITIVE_OPTION ) );
772 final String msg = ForesterUtil.isReadableFile( positive_filter_file );
773 if ( !ForesterUtil.isEmpty( msg ) ) {
774 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "can not read from \"" + positive_filter_file
778 else if ( cla.isOptionSet( surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
779 if ( !cla.isOptionValueSet( surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
780 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for negative domains filter: -"
781 + surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION + "=<file>" );
783 negative_domains_filter_file = new File( cla.getOptionValue( surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION ) );
784 final String msg = ForesterUtil.isReadableFile( negative_domains_filter_file );
785 if ( !ForesterUtil.isEmpty( msg ) ) {
786 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "can not read from \""
787 + negative_domains_filter_file + "\": " + msg );
790 final List<String> plus_minus_analysis_high_copy_base_species = new ArrayList<String>();
791 final List<String> plus_minus_analysis_high_copy_target_species = new ArrayList<String>();
792 final List<String> plus_minus_analysis_high_low_copy_species = new ArrayList<String>();
793 final List<Object> plus_minus_analysis_numbers = new ArrayList<Object>();
794 processPlusMinusAnalysisOption( cla,
795 plus_minus_analysis_high_copy_base_species,
796 plus_minus_analysis_high_copy_target_species,
797 plus_minus_analysis_high_low_copy_species,
798 plus_minus_analysis_numbers );
799 File input_files_file = null;
800 String[] input_file_names_from_file = null;
801 if ( cla.isOptionSet( surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION ) ) {
802 if ( !cla.isOptionValueSet( surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION ) ) {
803 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for input files file: -"
804 + surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION + "=<file>" );
806 input_files_file = new File( cla.getOptionValue( surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION ) );
807 final String msg = ForesterUtil.isReadableFile( input_files_file );
808 if ( !ForesterUtil.isEmpty( msg ) ) {
809 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "can not read from \"" + input_files_file + "\": "
813 input_file_names_from_file = ForesterUtil.file2array( input_files_file );
815 catch ( final IOException e ) {
816 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "failed to read from \"" + input_files_file
820 if ( ( cla.getNumberOfNames() < 1 )
821 && ( ( input_file_names_from_file == null ) || ( input_file_names_from_file.length < 1 ) ) ) {
822 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
823 "No hmmpfam output file indicated is input: use comand line directly or "
824 + surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION + "=<file>" );
826 DomainSimilarity.DomainSimilarityScoring scoring = SCORING_DEFAULT;
827 if ( cla.isOptionSet( surfacing_hmmpfam.SCORING_OPTION ) ) {
828 if ( !cla.isOptionValueSet( surfacing_hmmpfam.SCORING_OPTION ) ) {
829 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
830 "no value for scoring method for domain combinations similarity calculation: -"
831 + surfacing_hmmpfam.SCORING_OPTION + "=<"
832 + surfacing_hmmpfam.SCORING_DOMAIN_COUNT_BASED + "|"
833 + surfacing_hmmpfam.SCORING_PROTEIN_COUNT_BASED + "|"
834 + surfacing_hmmpfam.SCORING_COMBINATION_BASED + ">\"" );
836 final String scoring_str = cla.getOptionValue( surfacing_hmmpfam.SCORING_OPTION );
837 if ( scoring_str.equals( surfacing_hmmpfam.SCORING_DOMAIN_COUNT_BASED ) ) {
838 scoring = DomainSimilarity.DomainSimilarityScoring.DOMAINS;
840 else if ( scoring_str.equals( surfacing_hmmpfam.SCORING_COMBINATION_BASED ) ) {
841 scoring = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
843 else if ( scoring_str.equals( surfacing_hmmpfam.SCORING_PROTEIN_COUNT_BASED ) ) {
844 scoring = DomainSimilarity.DomainSimilarityScoring.PROTEINS;
847 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + scoring_str
848 + "\" for scoring method for domain combinations similarity calculation: \"-"
849 + surfacing_hmmpfam.SCORING_OPTION + "=<" + surfacing_hmmpfam.SCORING_DOMAIN_COUNT_BASED + "|"
850 + surfacing_hmmpfam.SCORING_PROTEIN_COUNT_BASED + "|"
851 + surfacing_hmmpfam.SCORING_COMBINATION_BASED + ">\"" );
854 boolean sort_by_species_count_first = false;
855 if ( cla.isOptionSet( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION ) ) {
856 sort_by_species_count_first = true;
858 boolean species_matrix = false;
859 if ( cla.isOptionSet( surfacing_hmmpfam.SPECIES_MATRIX_OPTION ) ) {
860 species_matrix = true;
862 boolean output_protein_lists_for_all_domains = false;
863 if ( cla.isOptionSet( surfacing_hmmpfam.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS ) ) {
864 output_protein_lists_for_all_domains = true;
866 Detailedness detailedness = DETAILEDNESS_DEFAULT;
867 if ( cla.isOptionSet( surfacing_hmmpfam.DETAILEDNESS_OPTION ) ) {
868 if ( !cla.isOptionValueSet( surfacing_hmmpfam.DETAILEDNESS_OPTION ) ) {
869 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for -"
870 + surfacing_hmmpfam.DETAILEDNESS_OPTION + "=<" + surfacing_hmmpfam.DETAILEDNESS_BASIC + "|"
871 + surfacing_hmmpfam.DETAILEDNESS_LIST_IDS + "|" + surfacing_hmmpfam.DETAILEDNESS_PUNCTILIOUS
874 final String detness = cla.getOptionValue( surfacing_hmmpfam.DETAILEDNESS_OPTION ).toLowerCase();
875 if ( detness.equals( surfacing_hmmpfam.DETAILEDNESS_BASIC ) ) {
876 detailedness = DomainSimilarityCalculator.Detailedness.BASIC;
878 else if ( detness.equals( surfacing_hmmpfam.DETAILEDNESS_LIST_IDS ) ) {
879 detailedness = DomainSimilarityCalculator.Detailedness.LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES;
881 else if ( detness.equals( surfacing_hmmpfam.DETAILEDNESS_PUNCTILIOUS ) ) {
882 detailedness = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
885 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + detness
886 + "\" for detailedness: \"-" + surfacing_hmmpfam.DETAILEDNESS_OPTION + "=<"
887 + surfacing_hmmpfam.DETAILEDNESS_BASIC + "|" + surfacing_hmmpfam.DETAILEDNESS_LIST_IDS + "|"
888 + surfacing_hmmpfam.DETAILEDNESS_PUNCTILIOUS + ">\"" );
891 String automated_pairwise_comparison_suffix = null;
892 boolean perform_pwc = false;
893 boolean write_pwc_files = false;
894 if ( cla.isOptionSet( surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
896 if ( !cla.isOptionValueSet( surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
897 write_pwc_files = false;
900 write_pwc_files = true;
901 automated_pairwise_comparison_suffix = "_"
902 + cla.getOptionValue( surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
905 String query_domain_ids = null;
906 if ( cla.isOptionSet( surfacing_hmmpfam.SEQ_EXTRACT_OPTION ) ) {
907 if ( !cla.isOptionValueSet( surfacing_hmmpfam.SEQ_EXTRACT_OPTION ) ) {
909 .fatalError( surfacing_hmmpfam.PRG_NAME,
910 "no domain ids given for sequences with given domains to be extracted : -"
911 + surfacing_hmmpfam.SEQ_EXTRACT_OPTION
912 + "=<ordered domain sequences, domain ids separated by '~', sequences separated by '#'>" );
914 query_domain_ids = cla.getOptionValue( surfacing_hmmpfam.SEQ_EXTRACT_OPTION );
916 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field = DOMAIN_SORT_FILD_DEFAULT;
917 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field_for_automated_pwc = DOMAIN_SORT_FILD_DEFAULT;
918 if ( cla.isOptionSet( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
919 if ( !cla.isOptionValueSet( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
920 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
921 "no value for domain combinations similarities sorting: -"
922 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION + "=<"
923 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
924 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MAX + "|"
925 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MIN + "|"
926 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MEAN + "|"
927 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_DIFF + "|"
928 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
929 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|"
930 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|"
931 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SD + ">\"" );
933 final String sort_str = cla.getOptionValue( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION ).toLowerCase();
934 if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ALPHA ) ) {
935 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
936 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
938 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MAX ) ) {
939 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX;
940 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
942 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MIN ) ) {
943 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MIN;
944 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
946 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MEAN ) ) {
947 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MEAN;
948 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MEAN;
950 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT ) ) {
951 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SPECIES_COUNT;
952 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
954 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SD ) ) {
955 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SD;
956 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
958 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_DIFF ) ) {
959 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
960 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
962 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF ) ) {
963 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
964 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
966 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF ) ) {
967 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
968 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
971 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + sort_str
972 + "\" for domain combinations similarities sorting: \"-"
973 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION + "=<"
974 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
975 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MAX + "|"
976 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MIN + "|"
977 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MEAN + "|"
978 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_DIFF + "|"
979 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
980 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|" + "|"
981 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|"
982 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SD + ">\"" );
985 PrintableDomainSimilarity.PRINT_OPTION domain_similarity_print_option = DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT;
986 if ( cla.isOptionSet( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
987 if ( !cla.isOptionValueSet( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
988 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for print option: -"
989 + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
990 + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
991 + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
993 final String sort = cla.getOptionValue( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION ).toLowerCase();
994 if ( sort.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML ) ) {
995 domain_similarity_print_option = PrintableDomainSimilarity.PRINT_OPTION.HTML;
997 else if ( sort.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML ) ) {
998 // domain_similarity_print_option =
999 // DomainSimilarity.PRINT_OPTION.SIMPLE_HTML;
1000 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "simple HTML output not implemented yet :(" );
1002 else if ( sort.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED ) ) {
1003 domain_similarity_print_option = PrintableDomainSimilarity.PRINT_OPTION.SIMPLE_TAB_DELIMITED;
1006 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + sort
1007 + "\" for print option: -" + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML
1008 + "|" + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
1009 + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
1012 GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder dc_sort_order = DOMAINS_SORT_ORDER_DEFAULT;
1013 if ( cla.isOptionSet( surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION ) ) {
1014 if ( !cla.isOptionValueSet( surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION ) ) {
1015 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for sorting of domain counts: -"
1016 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION + "=<" + surfacing_hmmpfam.DOMAIN_COUNT_SORT_ALPHA
1017 + "|" + surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
1018 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
1019 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
1021 final String sort = cla.getOptionValue( surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION ).toLowerCase();
1022 if ( sort.equals( surfacing_hmmpfam.DOMAIN_COUNT_SORT_ALPHA ) ) {
1023 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
1025 else if ( sort.equals( surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT ) ) {
1026 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_COUNT;
1028 else if ( sort.equals( surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT ) ) {
1029 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_PROTEINS_COUNT;
1031 else if ( sort.equals( surfacing_hmmpfam.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT ) ) {
1032 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.COMBINATIONS_COUNT;
1035 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + sort
1036 + "\" for sorting of domain counts: \"-" + surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION + "=<"
1037 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_ALPHA + "|"
1038 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
1039 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
1040 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
1043 String[][] input_file_properties = null;
1044 if ( input_file_names_from_file != null ) {
1045 input_file_properties = surfacing_hmmpfam.processInputFileNames( input_file_names_from_file );
1048 input_file_properties = surfacing_hmmpfam.processInputFileNames( cla.getNames() );
1050 final int number_of_genomes = input_file_properties.length;
1051 if ( number_of_genomes < 2 ) {
1052 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot analyze less than two files" );
1054 if ( ( number_of_genomes < 3 ) && perform_pwc ) {
1055 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot use : -"
1056 + surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1057 + "=<suffix> to turn on pairwise analyses with less than three input files" );
1059 checkWriteabilityForPairwiseComparisons( domain_similarity_print_option,
1060 input_file_properties,
1061 automated_pairwise_comparison_suffix,
1063 for( int i = 0; i < number_of_genomes; i++ ) {
1064 File dcc_outfile = new File( input_file_properties[ i ][ 0 ]
1065 + surfacing_hmmpfam.DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX );
1066 if ( out_dir != null ) {
1067 dcc_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + dcc_outfile );
1069 SurfacingUtil.checkForOutputFileWriteability( dcc_outfile );
1071 File pfam_to_go_file = null;
1072 Map<DomainId, List<GoId>> domain_id_to_go_ids_map = null;
1073 int domain_id_to_go_ids_count = 0;
1074 if ( cla.isOptionSet( surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION ) ) {
1075 if ( !cla.isOptionValueSet( surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION ) ) {
1076 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for Pfam to GO mapping file: -"
1077 + surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION + "=<file>" );
1079 pfam_to_go_file = new File( cla.getOptionValue( surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION ) );
1080 final String error = ForesterUtil.isReadableFile( pfam_to_go_file );
1081 if ( !ForesterUtil.isEmpty( error ) ) {
1082 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read Pfam to GO mapping file: " + error );
1085 final PfamToGoParser parser = new PfamToGoParser( pfam_to_go_file );
1086 final List<PfamToGoMapping> pfam_to_go_mappings = parser.parse();
1087 domain_id_to_go_ids_map = SurfacingUtil.createDomainIdToGoIdMap( pfam_to_go_mappings );
1088 if ( parser.getMappingCount() < domain_id_to_go_ids_map.size() ) {
1089 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME,
1090 "parser.getMappingCount() < domain_id_to_go_ids_map.size()" );
1092 domain_id_to_go_ids_count = parser.getMappingCount();
1094 catch ( final IOException e ) {
1095 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read from Pfam to GO mapping file: " + e );
1098 File go_obo_file = null;
1099 List<GoTerm> go_terms = null;
1100 if ( cla.isOptionSet( surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION ) ) {
1101 if ( !cla.isOptionValueSet( surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION ) ) {
1102 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for GO OBO file: -"
1103 + surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION + "=<file>" );
1105 if ( ( domain_id_to_go_ids_map == null ) || ( domain_id_to_go_ids_map.size() < 1 ) ) {
1106 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot use GO OBO file (-"
1107 + surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION + "=<file>) without Pfam to GO mapping file ("
1108 + surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1110 go_obo_file = new File( cla.getOptionValue( surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION ) );
1111 final String error = ForesterUtil.isReadableFile( go_obo_file );
1112 if ( !ForesterUtil.isEmpty( error ) ) {
1113 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read GO OBO file: " + error );
1116 final OBOparser parser = new OBOparser( go_obo_file, OBOparser.ReturnType.BASIC_GO_TERM );
1117 go_terms = parser.parse();
1118 if ( parser.getGoTermCount() != go_terms.size() ) {
1119 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME,
1120 "parser.getGoTermCount() != go_terms.size()" );
1123 catch ( final IOException e ) {
1124 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
1125 "cannot read from GO OBO file: " + e.getLocalizedMessage() );
1128 Map<GoId, GoTerm> go_id_to_term_map = null;
1129 if ( ( ( domain_id_to_go_ids_map != null ) && ( domain_id_to_go_ids_map.size() > 0 ) )
1130 && ( ( go_terms != null ) && ( go_terms.size() > 0 ) ) ) {
1131 go_id_to_term_map = GoUtils.createGoIdToGoTermMap( go_terms );
1133 GoNameSpace go_namespace_limit = null;
1134 if ( cla.isOptionSet( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION ) ) {
1135 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1136 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot use GO namespace limit (-"
1137 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION
1138 + "=<namespace>) without Pfam to GO mapping file ("
1139 + surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION + "=<file>) and GO OBO file (-"
1140 + surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1142 if ( !cla.isOptionValueSet( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION ) ) {
1143 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for GO namespace limit: \"-"
1144 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION + "=<"
1145 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
1146 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
1147 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
1149 final String go_namespace_limit_str = cla.getOptionValue( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION )
1151 if ( go_namespace_limit_str.equals( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION ) ) {
1152 go_namespace_limit = GoNameSpace.createMolecularFunction();
1154 else if ( go_namespace_limit_str.equals( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS ) ) {
1155 go_namespace_limit = GoNameSpace.createBiologicalProcess();
1157 else if ( go_namespace_limit_str.equals( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT ) ) {
1158 go_namespace_limit = GoNameSpace.createCellularComponent();
1161 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + go_namespace_limit_str
1162 + "\" for GO namespace limit: \"-" + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION + "=<"
1163 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
1164 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
1165 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
1168 if ( ( domain_similarity_sort_field == DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE )
1169 && ( number_of_genomes > 2 ) ) {
1170 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
1172 boolean jacknifed_distances = false;
1173 int jacknife_resamplings = JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT;
1174 double jacknife_ratio = JACKNIFE_RATIO_DEFAULT;
1175 long random_seed = JACKNIFE_RANDOM_SEED_DEFAULT;
1176 if ( cla.isOptionSet( surfacing_hmmpfam.JACKNIFE_OPTION ) ) {
1177 if ( ( number_of_genomes < 3 ) || !perform_pwc ) {
1178 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot use jacknife resampling analysis (-"
1179 + surfacing_hmmpfam.JACKNIFE_OPTION + "[=<number of resamplings>]) without pairwise analyses ("
1180 + surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1181 + "=<suffix for pairwise comparison output files>)" );
1183 jacknifed_distances = true;
1184 if ( cla.isOptionHasAValue( surfacing_hmmpfam.JACKNIFE_OPTION ) ) {
1186 jacknife_resamplings = cla.getOptionValueAsInt( surfacing_hmmpfam.JACKNIFE_OPTION );
1188 catch ( final IOException e ) {
1189 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "illegal format for number of resamplings" );
1191 if ( jacknife_resamplings < 2 ) {
1192 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "attempt to use less than 2 resamplings" );
1195 if ( cla.isOptionSet( surfacing_hmmpfam.JACKNIFE_RATIO_OPTION )
1196 && cla.isOptionHasAValue( surfacing_hmmpfam.JACKNIFE_RATIO_OPTION ) ) {
1198 jacknife_ratio = cla.getOptionValueAsDouble( surfacing_hmmpfam.JACKNIFE_RATIO_OPTION );
1200 catch ( final IOException e ) {
1201 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "illegal format for jacknife ratio" );
1203 if ( ( jacknife_ratio <= 0.0 ) || ( jacknife_ratio >= 1.0 ) ) {
1204 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
1205 "attempt to use illegal value for jacknife ratio: " + jacknife_ratio );
1208 if ( cla.isOptionSet( surfacing_hmmpfam.JACKNIFE_RANDOM_SEED_OPTION )
1209 && cla.isOptionHasAValue( surfacing_hmmpfam.JACKNIFE_RANDOM_SEED_OPTION ) ) {
1211 random_seed = cla.getOptionValueAsLong( surfacing_hmmpfam.JACKNIFE_RANDOM_SEED_OPTION );
1213 catch ( final IOException e ) {
1214 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "illegal format for random generator seed" );
1218 // boolean infer_species_trees = false;
1219 // if ( cla.isOptionSet( surfacing.INFER_SPECIES_TREES_OPTION ) ) {
1220 // if ( ( output_file == null ) || ( number_of_genomes < 3 )
1221 // || ForesterUtil.isEmpty( automated_pairwise_comparison_suffix ) ) {
1222 // ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot infer species trees (-"
1223 // + surfacing.INFER_SPECIES_TREES_OPTION + " without pairwise analyses ("
1224 // + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1225 // + "=<suffix for pairwise comparison output files>)" );
1227 // infer_species_trees = true;
1229 File[] intree_files = null;
1230 Phylogeny[] intrees = null;
1231 if ( cla.isOptionSet( surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION ) ) {
1232 // TODO FIXME if jacknife.... maybe not
1233 if ( number_of_genomes < 3 ) {
1234 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
1235 "cannot infer gains and losses on input species trees (-"
1236 + surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION
1237 + " without pairwise analyses ("
1238 + surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1239 + "=<suffix for pairwise comparison output files>)" );
1241 if ( !cla.isOptionValueSet( surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION ) ) {
1242 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for input tree: -"
1243 + surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION + "=<tree file in phyloXML format>" );
1245 final String intrees_str = cla.getOptionValue( surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION );
1246 if ( intrees_str.indexOf( "#" ) > 0 ) {
1247 final String[] intrees_strs = intrees_str.split( "#" );
1248 intree_files = new File[ intrees_strs.length ];
1250 for( final String s : intrees_strs ) {
1251 intree_files[ i++ ] = new File( s.trim() );
1255 intree_files = new File[ 1 ];
1256 intree_files[ 0 ] = new File( intrees_str );
1258 intrees = getIntrees( intree_files, number_of_genomes, input_file_properties );
1260 long random_number_seed_for_fitch_parsimony = 0l;
1261 boolean radomize_fitch_parsimony = false;
1262 if ( cla.isOptionSet( surfacing_hmmpfam.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
1263 if ( !cla.isOptionValueSet( surfacing_hmmpfam.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
1264 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for random number seed: -"
1265 + surfacing_hmmpfam.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION + "=<seed>" );
1268 random_number_seed_for_fitch_parsimony = cla
1269 .getOptionValueAsLong( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
1271 catch ( final IOException e ) {
1272 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage() );
1274 radomize_fitch_parsimony = true;
1276 SortedSet<DomainId> filter = null;
1277 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1278 || ( negative_domains_filter_file != null ) ) {
1279 filter = new TreeSet<DomainId>();
1280 if ( positive_filter_file != null ) {
1281 processFilter( positive_filter_file, filter );
1283 else if ( negative_filter_file != null ) {
1284 processFilter( negative_filter_file, filter );
1286 else if ( negative_domains_filter_file != null ) {
1287 processFilter( negative_domains_filter_file, filter );
1290 Map<DomainId, Set<String>>[] domain_id_to_secondary_features_maps = null;
1291 File[] secondary_features_map_files = null;
1292 final File domain_lengths_analysis_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1293 + DOMAIN_LENGTHS_ANALYSIS_SUFFIX );
1294 if ( PERFORM_DOMAIN_LENGTH_ANALYSIS ) {
1295 SurfacingUtil.checkForOutputFileWriteability( domain_lengths_analysis_outfile );
1297 if ( cla.isOptionSet( surfacing_hmmpfam.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
1298 if ( !cla.isOptionValueSet( surfacing_hmmpfam.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
1299 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for secondary features map file: -"
1300 + surfacing_hmmpfam.SECONDARY_FEATURES_PARSIMONY_MAP_FILE + "=<file>" );
1302 final String[] secondary_features_map_files_strs = cla
1303 .getOptionValue( surfacing_hmmpfam.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ).split( "#" );
1304 secondary_features_map_files = new File[ secondary_features_map_files_strs.length ];
1305 domain_id_to_secondary_features_maps = new Map[ secondary_features_map_files_strs.length ];
1307 for( final String secondary_features_map_files_str : secondary_features_map_files_strs ) {
1308 secondary_features_map_files[ i ] = new File( secondary_features_map_files_str );
1309 final String error = ForesterUtil.isReadableFile( secondary_features_map_files[ i ] );
1310 if ( !ForesterUtil.isEmpty( error ) ) {
1311 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read secondary features map file: "
1315 domain_id_to_secondary_features_maps[ i ] = SurfacingUtil
1316 .createDomainIdToSecondaryFeaturesMap( secondary_features_map_files[ i ] );
1318 catch ( final IOException e ) {
1319 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read secondary features map file: "
1322 catch ( final Exception e ) {
1323 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "problem with contents of features map file ["
1324 + secondary_features_map_files[ i ] + "]: " + e.getMessage() );
1329 if ( out_dir == null ) {
1330 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no output directory indicated (-"
1331 + surfacing_hmmpfam.OUTPUT_DIR_OPTION + "=<dir>)" );
1333 if ( output_file == null ) {
1334 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no name for (main) output file indicated (-"
1335 + surfacing_hmmpfam.OUTPUT_FILE_OPTION + "=<file>)" );
1337 if ( ( domain_id_to_go_ids_map == null ) || domain_id_to_go_ids_map.isEmpty() ) {
1338 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
1339 "no (acceptable) Pfam to GO id mapping file provided ('pfam2go file') (-"
1340 + surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1342 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1343 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
1344 "no (acceptable) go id to term mapping file provided ('GO OBO file') (-"
1345 + surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1347 boolean display_histograms = false;
1348 if ( cla.isOptionSet( surfacing_hmmpfam.DISPLAY_M_HISTOGRAMS_OPTION ) ) {
1349 display_histograms = true;
1351 System.out.println( "Output directory : " + out_dir );
1352 if ( input_file_names_from_file != null ) {
1353 System.out.println( "Input files names from : " + input_files_file + " ["
1354 + input_file_names_from_file.length + " input files]" );
1355 html_desc.append( "<tr><td>Input files names from:</td><td>" + input_files_file + " ["
1356 + input_file_names_from_file.length + " input files]</td></tr>" + nl );
1358 if ( positive_filter_file != null ) {
1359 final int filter_size = filter.size();
1360 System.out.println( "Positive protein filter : " + positive_filter_file + " [" + filter_size
1362 html_desc.append( "<tr><td>Positive protein filter:</td><td>" + positive_filter_file + " [" + filter_size
1363 + " domain ids]</td></tr>" + nl );
1365 if ( negative_filter_file != null ) {
1366 final int filter_size = filter.size();
1367 System.out.println( "Negative protein filter : " + negative_filter_file + " [" + filter_size
1369 html_desc.append( "<tr><td>Negative protein filter:</td><td>" + negative_filter_file + " [" + filter_size
1370 + " domain ids]</td></tr>" + nl );
1372 if ( negative_domains_filter_file != null ) {
1373 final int filter_size = filter.size();
1374 System.out.println( "Negative domain filter : " + negative_domains_filter_file + " [" + filter_size
1376 html_desc.append( "<tr><td>Negative domain filter:</td><td>" + negative_domains_filter_file + " ["
1377 + filter_size + " domain ids]</td></tr>" + nl );
1379 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
1381 for( final String s : plus_minus_analysis_high_copy_base_species ) {
1382 plus0 += "+" + s + " ";
1385 for( final String s : plus_minus_analysis_high_copy_target_species ) {
1386 plus1 += "*" + s + " ";
1389 for( final String s : plus_minus_analysis_high_low_copy_species ) {
1390 minus += "-" + s + " ";
1392 System.out.println( "Plus-minus analysis : " + plus1 + "&& " + plus0 + "&& " + minus );
1393 html_desc.append( "<tr><td>Plus-minus analysis:</td><td>" + plus1 + "&& " + plus0 + "&& " + minus
1394 + "</td></tr>" + nl );
1396 if ( cutoff_scores_file != null ) {
1397 System.out.println( "Cutoff scores file : " + cutoff_scores_file );
1398 html_desc.append( "<tr><td>Cutoff scores file:</td><td>" + cutoff_scores_file + "</td></tr>" + nl );
1400 if ( e_value_max >= 0.0 ) {
1401 System.out.println( "E-value maximum (inclusive) : " + e_value_max );
1402 html_desc.append( "<tr><td>E-value maximum (inclusive):</td><td>" + e_value_max + "</td></tr>" + nl );
1404 System.out.println( "Ignore DUFs : " + ignore_dufs );
1405 if ( ignore_virus_like_ids ) {
1406 System.out.println( "Ignore virus like ids : " + ignore_virus_like_ids );
1407 html_desc.append( "<tr><td>Ignore virus, phage, transposition related ids:</td><td>"
1408 + ignore_virus_like_ids + "</td></tr>" + nl );
1410 html_desc.append( "<tr><td>Ignore DUFs:</td><td>" + ignore_dufs + "</td></tr>" + nl );
1411 if ( max_allowed_overlap != surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1412 System.out.println( "Max allowed domain overlap : " + max_allowed_overlap );
1413 html_desc.append( "<tr><td>Max allowed domain overlap:</td><td>" + max_allowed_overlap + "</td></tr>" + nl );
1415 if ( no_engulfing_overlaps ) {
1416 System.out.println( "Ignore engulfed domains : " + no_engulfing_overlaps );
1417 html_desc.append( "<tr><td>Ignore (lower confidence) engulfed domains:</td><td>" + no_engulfing_overlaps
1418 + "</td></tr>" + nl );
1420 System.out.println( "Ignore singlet domains : " + ignore_domains_without_combs_in_all_spec );
1422 .append( "<tr><td>Ignore singlet domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1423 + ignore_domains_without_combs_in_all_spec + "</td></tr>" + nl );
1424 System.out.println( "Ignore species specific doms: " + ignore_species_specific_domains );
1426 .append( "<tr><td>Ignore species specific domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1427 + ignore_species_specific_domains + "</td></tr>" + nl );
1428 System.out.println( "Ignore combination with self: " + ignore_combination_with_same );
1429 html_desc.append( "<tr><td>Ignore combination with self for domain combination similarity analyses:</td><td>"
1430 + ignore_combination_with_same + "</td></tr>" + nl );
1432 System.out.println( "Consider directedness : "
1433 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) );
1434 html_desc.append( "<tr><td>Consider directedness of binary domain combinations:</td><td>"
1435 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) + "</td></tr>" + nl );
1436 if ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) {
1437 System.out.println( "Consider adjacency : "
1438 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) );
1439 html_desc.append( "<tr><td>Consider djacency of binary domain combinations:</td><td>"
1440 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) + "</td></tr>"
1443 System.out.print( "Domain counts sort order : " );
1444 switch ( dc_sort_order ) {
1445 case ALPHABETICAL_KEY_ID:
1446 System.out.println( "alphabetical" );
1448 case KEY_DOMAIN_COUNT:
1449 System.out.println( "domain count" );
1451 case KEY_DOMAIN_PROTEINS_COUNT:
1452 System.out.println( "domain proteins count" );
1454 case COMBINATIONS_COUNT:
1455 System.out.println( "domain combinations count" );
1458 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME, "unknown value for dc sort order" );
1460 if ( domain_id_to_go_ids_map != null ) {
1461 System.out.println( "Pfam to GO mappings from : " + pfam_to_go_file + " [" + domain_id_to_go_ids_count
1463 html_desc.append( "<tr><td>Pfam to GO mappings from:</td><td>" + pfam_to_go_file + " ["
1464 + domain_id_to_go_ids_count + " mappings]" + "</td></tr>" + nl );
1466 if ( go_terms != null ) {
1467 System.out.println( "GO terms from : " + go_obo_file + " [" + go_terms.size() + " terms]" );
1468 html_desc.append( "<tr><td>GO terms from:</td><td>" + go_obo_file + " [" + go_terms.size() + " terms]"
1469 + "</td></tr>" + nl );
1471 if ( go_namespace_limit != null ) {
1472 System.out.println( "Limit GO terms to : " + go_namespace_limit.toString() );
1473 html_desc.append( "<tr><td>Limit GO terms to</td><td>" + go_namespace_limit + "</td></tr>" + nl );
1475 if ( perform_pwc ) {
1476 System.out.println( "Suffix for PWC files : " + automated_pairwise_comparison_suffix );
1477 html_desc.append( "<tr><td>Suffix for PWC files</td><td>" + automated_pairwise_comparison_suffix
1478 + "</td></tr>" + nl );
1480 if ( out_dir != null ) {
1481 System.out.println( "Output directory : " + out_dir );
1483 if ( query_domain_ids != null ) {
1484 System.out.println( "Query domains (ordered) : " + query_domain_ids );
1485 html_desc.append( "<tr><td></td><td>" + query_domain_ids + "</td></tr>" + nl );
1487 System.out.println( "Write similarities to : " + output_file );
1488 System.out.print( " Scoring method : " );
1489 html_desc.append( "<tr><td>Scoring method:</td><td>" );
1490 switch ( scoring ) {
1492 System.out.println( "domain combinations based" );
1493 html_desc.append( "domain combinations based" + "</td></tr>" + nl );
1496 System.out.println( "domain counts based" );
1497 html_desc.append( "domain counts based" + "</td></tr>" + nl );
1500 System.out.println( "domain proteins counts based" );
1501 html_desc.append( "domain proteins counts based" + "</td></tr>" + nl );
1504 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME, "unknown value for sorting for scoring" );
1506 System.out.print( " Sort by : " );
1507 html_desc.append( "<tr><td>Sort by:</td><td>" );
1508 switch ( domain_similarity_sort_field ) {
1510 System.out.print( "score minimum" );
1511 html_desc.append( "score minimum" );
1514 System.out.print( "score maximum" );
1515 html_desc.append( "score maximum" );
1518 System.out.print( "score mean" );
1519 html_desc.append( "score mean" );
1522 System.out.print( "score standard deviation" );
1523 html_desc.append( "score standard deviation" );
1526 System.out.print( "species number" );
1527 html_desc.append( "species number" );
1530 System.out.print( "alphabetical domain identifier" );
1531 html_desc.append( "alphabetical domain identifier" );
1533 case MAX_DIFFERENCE:
1534 System.out.print( "(maximal) difference" );
1535 html_desc.append( "(maximal) difference" );
1537 case ABS_MAX_COUNTS_DIFFERENCE:
1538 System.out.print( "absolute (maximal) counts difference" );
1539 html_desc.append( "absolute (maximal) counts difference" );
1541 case MAX_COUNTS_DIFFERENCE:
1542 System.out.print( "(maximal) counts difference" );
1543 html_desc.append( "(maximal) counts difference" );
1546 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME,
1547 "unknown value for sorting for similarities" );
1549 if ( sort_by_species_count_first ) {
1550 System.out.println( " (sort by species count first)" );
1551 html_desc.append( " (sort by species count first)" );
1554 System.out.println();
1556 html_desc.append( "</td></tr>" + nl );
1557 System.out.print( " Detailedness : " );
1558 switch ( detailedness ) {
1560 System.out.println( "basic" );
1562 case LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES:
1563 System.out.println( "list combining domains for each species" );
1566 System.out.println( "punctilious" );
1569 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME,
1570 "unknown value for sorting for detailedness" );
1572 System.out.print( " Print option : " );
1573 switch ( domain_similarity_print_option ) {
1575 System.out.println( "HTML" );
1577 case SIMPLE_TAB_DELIMITED:
1578 System.out.println( "simple tab delimited" );
1581 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME, "unknown value for print option" );
1583 System.out.print( " Species matrix : " + species_matrix );
1584 System.out.println();
1585 if ( perform_pwc ) {
1586 System.out.println( "Pairwise comparisons: " );
1587 html_desc.append( "<tr><td>Pairwise comparisons:</td><td></td></tr>" );
1588 System.out.print( " Sort by : " );
1589 html_desc.append( "<tr><td>Sort by:</td><td>" );
1590 switch ( domain_similarity_sort_field_for_automated_pwc ) {
1592 System.out.print( "score mean" );
1593 html_desc.append( "score mean" );
1596 System.out.print( "alphabetical domain identifier" );
1597 html_desc.append( "alphabetical domain identifier" );
1599 case MAX_DIFFERENCE:
1600 System.out.print( "difference" );
1601 html_desc.append( "difference" );
1603 case ABS_MAX_COUNTS_DIFFERENCE:
1604 System.out.print( "absolute counts difference" );
1605 html_desc.append( "absolute counts difference" );
1607 case MAX_COUNTS_DIFFERENCE:
1608 System.out.print( "counts difference" );
1609 html_desc.append( "counts difference" );
1612 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME,
1613 "unknown value for sorting for similarities" );
1615 System.out.println();
1616 html_desc.append( "</td></tr>" + nl );
1617 if ( jacknifed_distances ) {
1618 html_desc.append( "<tr><td>Jacknife:</td><td>" + jacknife_resamplings + " resamplings</td></tr>" + nl );
1619 html_desc.append( "<tr><td>Jacknife ratio:</td><td>" + ForesterUtil.round( jacknife_ratio, 2 )
1620 + "</td></tr>" + nl );
1621 html_desc.append( "<tr><td>Jacknife random number seed:</td><td>" + random_seed + "</td></tr>" + nl );
1622 System.out.println( " Jacknife : " + jacknife_resamplings + " resamplings" );
1623 System.out.println( " Ratio : " + ForesterUtil.round( jacknife_ratio, 2 ) );
1624 System.out.println( " Random number seed : " + random_seed );
1626 // if ( infer_species_trees ) {
1627 // html_desc.append( "<tr><td>Infer species trees:</td><td>true</td></tr>" + nl );
1628 // System.out.println( " Infer species trees : true" );
1630 if ( ( intrees != null ) && ( intrees.length > 0 ) ) {
1631 for( final File intree_file : intree_files ) {
1632 html_desc.append( "<tr><td>Intree for gain/loss parsimony analysis:</td><td>" + intree_file
1633 + "</td></tr>" + nl );
1634 System.out.println( " Intree for gain/loss pars.: " + intree_file );
1637 if ( radomize_fitch_parsimony ) {
1638 html_desc.append( "<tr><td> Random number seed for Fitch parsimony analysis:</td><td>"
1639 + random_number_seed_for_fitch_parsimony + "</td></tr>" + nl );
1640 System.out.println( " Random number seed : " + random_number_seed_for_fitch_parsimony );
1642 if ( ( domain_id_to_secondary_features_maps != null ) && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
1643 for( int i = 0; i < secondary_features_map_files.length; i++ ) {
1644 html_desc.append( "<tr><td>Secondary features map file:</td><td>"
1645 + secondary_features_map_files[ i ] + "</td></tr>" + nl );
1646 System.out.println( "Secondary features map file : " + secondary_features_map_files[ i ]
1647 + " [mappings for " + domain_id_to_secondary_features_maps[ i ].size() + " domain ids]" );
1649 System.out.println();
1650 System.out.println( "Domain ids to secondary features map:" );
1651 for( final DomainId domain_id : domain_id_to_secondary_features_maps[ i ].keySet() ) {
1652 System.out.print( domain_id.getId() );
1653 System.out.print( " => " );
1654 for( final String sec : domain_id_to_secondary_features_maps[ i ].get( domain_id ) ) {
1655 System.out.print( sec );
1656 System.out.print( " " );
1658 System.out.println();
1663 } // if ( perform_pwc ) {
1664 System.out.println();
1665 html_desc.append( "<tr><td>Command line:</td><td>" + cla.getCommandLineArgsAsString() + "</td></tr>" + nl );
1666 System.out.println( "Command line : " + cla.getCommandLineArgsAsString() );
1667 BufferedWriter[] query_domains_writer_ary = null;
1668 List<DomainId>[] query_domain_ids_array = null;
1669 if ( query_domain_ids != null ) {
1670 final String[] query_domain_ids_str_array = query_domain_ids.split( "#" );
1671 query_domain_ids_array = new ArrayList[ query_domain_ids_str_array.length ];
1672 query_domains_writer_ary = new BufferedWriter[ query_domain_ids_str_array.length ];
1673 for( int i = 0; i < query_domain_ids_str_array.length; i++ ) {
1674 String query_domain_ids_str = query_domain_ids_str_array[ i ];
1675 final String[] query_domain_ids_str_ary = query_domain_ids_str.split( "~" );
1676 final List<DomainId> query = new ArrayList<DomainId>();
1677 for( final String element : query_domain_ids_str_ary ) {
1678 query.add( new DomainId( element ) );
1680 query_domain_ids_array[ i ] = query;
1681 query_domain_ids_str = query_domain_ids_str.replace( '~', '_' );
1682 String protein_names_writer_str = query_domain_ids_str + surfacing_hmmpfam.SEQ_EXTRACT_SUFFIX;
1683 if ( out_dir != null ) {
1684 protein_names_writer_str = out_dir + ForesterUtil.FILE_SEPARATOR + protein_names_writer_str;
1687 query_domains_writer_ary[ i ] = new BufferedWriter( new FileWriter( protein_names_writer_str ) );
1689 catch ( final IOException e ) {
1690 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "Could not open [" + protein_names_writer_str
1691 + "]: " + e.getLocalizedMessage() );
1695 SortedMap<Species, List<Protein>> protein_lists_per_species = null; //This will only be created if neede.
1696 boolean need_protein_lists_per_species = false;
1697 if ( ( plus_minus_analysis_high_copy_base_species.size() > 0 ) || output_protein_lists_for_all_domains ) {
1698 need_protein_lists_per_species = true;
1700 if ( need_protein_lists_per_species ) {
1701 protein_lists_per_species = new TreeMap<Species, List<Protein>>();
1703 final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>( number_of_genomes );
1704 final SortedSet<DomainId> all_domains_encountered = new TreeSet<DomainId>();
1705 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered = new TreeSet<BinaryDomainCombination>();
1706 List<BinaryDomainCombination> all_bin_domain_combinations_gained_fitch = null;
1707 List<BinaryDomainCombination> all_bin_domain_combinations_lost_fitch = null;
1708 if ( ( intrees != null ) && ( intrees.length == 1 ) ) {
1709 all_bin_domain_combinations_gained_fitch = new ArrayList<BinaryDomainCombination>();
1710 all_bin_domain_combinations_lost_fitch = new ArrayList<BinaryDomainCombination>();
1712 final DomainLengthsTable domain_lengths_table = new DomainLengthsTable();
1713 final File per_genome_domain_promiscuity_statistics_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR
1714 + output_file + D_PROMISCUITY_FILE_SUFFIX );
1715 BufferedWriter per_genome_domain_promiscuity_statistics_writer = null;
1717 per_genome_domain_promiscuity_statistics_writer = new BufferedWriter( new FileWriter( per_genome_domain_promiscuity_statistics_file ) );
1718 per_genome_domain_promiscuity_statistics_writer.write( "Species:\t" );
1719 per_genome_domain_promiscuity_statistics_writer.write( "Mean:\t" );
1720 per_genome_domain_promiscuity_statistics_writer.write( "SD:\t" );
1721 per_genome_domain_promiscuity_statistics_writer.write( "Median:\t" );
1722 per_genome_domain_promiscuity_statistics_writer.write( "Min:\t" );
1723 per_genome_domain_promiscuity_statistics_writer.write( "Max:\t" );
1724 per_genome_domain_promiscuity_statistics_writer.write( "N:\t" );
1725 per_genome_domain_promiscuity_statistics_writer.write( "Max Promiscuous Domains:"
1726 + ForesterUtil.LINE_SEPARATOR );
1728 catch ( final IOException e2 ) {
1729 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e2.getMessage() );
1731 for( int i = 0; i < number_of_genomes; ++i ) {
1732 System.out.println();
1733 System.out.println( ( i + 1 ) + "/" + number_of_genomes );
1734 System.out.println( "Processing : " + input_file_properties[ i ][ 0 ] );
1735 HmmPfamOutputParser parser = null;
1736 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1737 || ( negative_domains_filter_file != null ) ) {
1738 HmmPfamOutputParser.FilterType filter_type = HmmPfamOutputParser.FilterType.NONE;
1739 if ( positive_filter_file != null ) {
1740 filter_type = HmmPfamOutputParser.FilterType.POSITIVE_PROTEIN;
1742 else if ( negative_filter_file != null ) {
1743 filter_type = HmmPfamOutputParser.FilterType.NEGATIVE_PROTEIN;
1745 else if ( negative_domains_filter_file != null ) {
1746 filter_type = HmmPfamOutputParser.FilterType.NEGATIVE_DOMAIN;
1748 parser = new HmmPfamOutputParser( new File( input_file_properties[ i ][ 0 ] ),
1749 input_file_properties[ i ][ 1 ],
1750 input_file_properties[ i ][ 2 ],
1755 parser = new HmmPfamOutputParser( new File( input_file_properties[ i ][ 0 ] ),
1756 input_file_properties[ i ][ 1 ],
1757 input_file_properties[ i ][ 2 ] );
1759 if ( e_value_max >= 0.0 ) {
1760 parser.setEValueMaximum( e_value_max );
1762 parser.setIgnoreDufs( ignore_dufs );
1763 parser.setIgnoreVirusLikeIds( ignore_virus_like_ids );
1764 parser.setIgnoreEngulfedDomains( no_engulfing_overlaps );
1765 if ( max_allowed_overlap != surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1766 parser.setMaxAllowedOverlap( max_allowed_overlap );
1768 parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
1769 if ( individual_domain_score_cutoffs != null ) {
1770 parser.setIndividualDomainScoreCutoffs( individual_domain_score_cutoffs );
1772 parser.setAllowNonUniqueQuery( ALLOW_NON_UNIQUE_QUERY_IN_HMMPFAM_OUTPUT_DEFAULT );
1773 parser.setVerbose( VERBOSE_DEFAULT );
1774 List<Protein> protein_list = null;
1776 protein_list = parser.parse();
1778 catch ( final IOException e ) {
1779 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage() );
1781 catch ( final Exception e ) {
1782 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage(), e );
1785 System.out.println( "Domains ignored due to negative domain filter: " );
1786 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToNegativeDomainFilterCountsMap() );
1787 System.out.println( "Domains ignored due to virus like id: " );
1788 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToVirusLikeIdCountsMap() );
1790 System.out.println( "Number of proteins encountered : " + parser.getProteinsEncountered() );
1791 System.out.println( "Number of proteins stored : " + protein_list.size() );
1792 System.out.println( "Domains encountered : " + parser.getDomainsEncountered() );
1793 System.out.println( "Domains stored : " + parser.getDomainsStored() );
1794 System.out.println( "Distinct domains stored : "
1795 + parser.getDomainsStoredSet().size() );
1796 System.out.println( "Domains ignored due to individual score cutoffs: "
1797 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() );
1798 System.out.println( "Domains ignored due to E-value : "
1799 + parser.getDomainsIgnoredDueToEval() );
1800 System.out.println( "Domains ignored due to DUF designation : "
1801 + parser.getDomainsIgnoredDueToDuf() );
1802 if ( ignore_virus_like_ids ) {
1803 System.out.println( "Domains ignored due virus like ids : "
1804 + parser.getDomainsIgnoredDueToVirusLikeIds() );
1806 System.out.println( "Domains ignored due negative domain filter : "
1807 + parser.getDomainsIgnoredDueToNegativeDomainFilter() );
1808 System.out.println( "Domains ignored due to overlap : "
1809 + parser.getDomainsIgnoredDueToOverlap() );
1810 if ( negative_filter_file != null ) {
1811 System.out.println( "Proteins ignored due to negative filter : "
1812 + parser.getProteinsIgnoredDueToFilter() );
1814 if ( positive_filter_file != null ) {
1815 System.out.println( "Proteins ignored due to positive filter : "
1816 + parser.getProteinsIgnoredDueToFilter() );
1818 System.out.println( "Time for processing : " + parser.getTime() + "ms" );
1819 html_desc.append( "<tr><td>" + input_file_properties[ i ][ 0 ] + " [species: "
1820 + input_file_properties[ i ][ 1 ] + "]" + ":</td><td>domains analyzed: "
1821 + parser.getDomainsStored() + "; domains ignored: [ind score cutoffs: "
1822 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() + "] [E-value cutoff: "
1823 + parser.getDomainsIgnoredDueToEval() + "] [DUF: " + parser.getDomainsIgnoredDueToDuf()
1824 + "] [virus like ids: " + parser.getDomainsIgnoredDueToVirusLikeIds()
1825 + "] [negative domain filter: " + parser.getDomainsIgnoredDueToNegativeDomainFilter()
1826 + "] [overlap: " + parser.getDomainsIgnoredDueToOverlap() + "]" );
1827 if ( negative_filter_file != null ) {
1828 html_desc.append( "; proteins ignored due to negative filter: "
1829 + parser.getProteinsIgnoredDueToFilter() );
1831 if ( positive_filter_file != null ) {
1832 html_desc.append( "; proteins ignored due to positive filter: "
1833 + parser.getProteinsIgnoredDueToFilter() );
1835 html_desc.append( "</td></tr>" + nl );
1836 // domain_partner_counts_array[ i ] =
1837 // Methods.getDomainPartnerCounts( protein_domain_collections_array[
1839 // false, input_file_properties[ i ][ 1 ] );
1840 gwcd_list.add( BasicGenomeWideCombinableDomains
1841 .createInstance( protein_list,
1842 ignore_combination_with_same,
1843 new BasicSpecies( input_file_properties[ i ][ 1 ] ),
1844 domain_id_to_go_ids_map,
1846 domain_lengths_table.addLengths( protein_list );
1847 if ( gwcd_list.get( i ).getSize() > 0 ) {
1848 SurfacingUtil.writeDomainCombinationsCountsFile( input_file_properties,
1850 per_genome_domain_promiscuity_statistics_writer,
1854 if ( output_binary_domain_combinationsfor_graph_analysis ) {
1855 SurfacingUtil.writeBinaryDomainCombinationsFileForGraphAnalysis( input_file_properties,
1861 SurfacingUtil.addAllDomainIdsToSet( gwcd_list.get( i ), all_domains_encountered );
1862 SurfacingUtil.addAllBinaryDomainCombinationToSet( gwcd_list.get( i ),
1863 all_bin_domain_combinations_encountered );
1865 if ( query_domains_writer_ary != null ) {
1866 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1868 SurfacingUtil.extractProteinNames( protein_list,
1869 query_domain_ids_array[ j ],
1870 query_domains_writer_ary[ j ],
1872 query_domains_writer_ary[ j ].flush();
1874 catch ( final IOException e ) {
1875 e.printStackTrace();
1879 if ( need_protein_lists_per_species ) {
1880 protein_lists_per_species.put( new BasicSpecies( input_file_properties[ i ][ 1 ] ), protein_list );
1883 } // for( int i = 0; i < number_of_hmmpfam_files_to_analyze; ++i ) {
1885 per_genome_domain_promiscuity_statistics_writer.flush();
1886 per_genome_domain_promiscuity_statistics_writer.close();
1888 catch ( final IOException e2 ) {
1889 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e2.toString() );
1891 ForesterUtil.programMessage( PRG_NAME, "Wrote domain promiscuities to: "
1892 + per_genome_domain_promiscuity_statistics_file );
1893 if ( query_domains_writer_ary != null ) {
1894 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1896 query_domains_writer_ary[ j ].close();
1898 catch ( final IOException e ) {
1899 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.toString() );
1903 if ( PERFORM_DOMAIN_LENGTH_ANALYSIS ) {
1905 SurfacingUtil.executeDomainLengthAnalysis( input_file_properties,
1907 domain_lengths_table,
1908 domain_lengths_analysis_outfile );
1910 catch ( final IOException e1 ) {
1911 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e1.toString() );
1913 System.out.println();
1914 ForesterUtil.programMessage( PRG_NAME, "Wrote domain length data to: " + domain_lengths_analysis_outfile );
1915 System.out.println();
1917 final long analysis_start_time = new Date().getTime();
1918 PairwiseDomainSimilarityCalculator pw_calc = null;
1919 // double[] values_for_all_scores_histogram = null;
1920 final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( domain_similarity_sort_field,
1921 sort_by_species_count_first,
1922 number_of_genomes == 2 );
1923 switch ( scoring ) {
1925 pw_calc = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1928 pw_calc = new DomainCountsBasedPairwiseSimilarityCalculator();
1931 pw_calc = new ProteinCountsBasedPairwiseDomainSimilarityCalculator();
1934 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME, "unknown value for sorting for scoring" );
1936 DomainSimilarityCalculator.GoAnnotationOutput go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.NONE;
1937 if ( domain_id_to_go_ids_map != null ) {
1938 go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.ALL;
1940 final SortedSet<DomainSimilarity> similarities = calc
1941 .calculateSimilarities( pw_calc,
1943 ignore_domains_without_combs_in_all_spec,
1944 ignore_species_specific_domains );
1945 SurfacingUtil.decoratePrintableDomainSimilarities( similarities,
1947 go_annotation_output,
1949 go_namespace_limit );
1950 DescriptiveStatistics pw_stats = null;
1952 String my_outfile = output_file.toString();
1953 if ( !my_outfile.endsWith( ".html" ) ) {
1954 my_outfile += ".html";
1956 final Writer writer = new BufferedWriter( new FileWriter( out_dir == null ? my_outfile : out_dir
1957 + ForesterUtil.FILE_SEPARATOR + my_outfile ) );
1958 List<Species> species_order = null;
1959 if ( species_matrix ) {
1960 species_order = new ArrayList<Species>();
1961 for( int i = 0; i < number_of_genomes; i++ ) {
1962 species_order.add( new BasicSpecies( input_file_properties[ i ][ 1 ] ) );
1965 html_desc.append( "<tr><td>Sum of all distinct binary combinations:</td><td>"
1966 + all_bin_domain_combinations_encountered.size() + "</td></tr>" + nl );
1967 html_desc.append( "<tr><td>Sum of all distinct domains:</td><td>" + all_domains_encountered.size()
1968 + "</td></tr>" + nl );
1969 html_desc.append( "<tr><td>Analysis date/time:</td><td>"
1970 + new java.text.SimpleDateFormat( "yyyy.MM.dd HH:mm:ss" ).format( new java.util.Date() )
1971 + "</td></tr>" + nl );
1972 html_desc.append( "</table>" + nl );
1973 pw_stats = SurfacingUtil
1974 .writeDomainSimilaritiesToFile( html_desc,
1975 new StringBuilder( number_of_genomes + " genomes" ),
1978 number_of_genomes == 2,
1980 domain_similarity_print_option,
1981 domain_similarity_sort_field,
1984 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME,
1985 "Wrote main output (includes domain similarities) to: \""
1986 + ( out_dir == null ? my_outfile : out_dir
1987 + ForesterUtil.FILE_SEPARATOR + my_outfile ) + "\"" );
1989 catch ( final IOException e ) {
1990 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "Failed to write similarites to: \"" + output_file
1991 + "\" [" + e.getMessage() + "]" );
1993 System.out.println();
1994 // values_for_all_scores_histogram = pw_stats.getDataAsDoubleArray();
1995 final Species[] species = new Species[ number_of_genomes ];
1996 for( int i = 0; i < number_of_genomes; ++i ) {
1997 species[ i ] = new BasicSpecies( input_file_properties[ i ][ 1 ] );
1999 List<Phylogeny> inferred_trees = null;
2000 if ( ( number_of_genomes > 2 ) && perform_pwc ) {
2001 final PairwiseGenomeComparator pwgc = new PairwiseGenomeComparator();
2002 pwgc.performPairwiseComparisons( html_desc,
2003 sort_by_species_count_first,
2005 ignore_domains_without_combs_in_all_spec,
2006 ignore_species_specific_domains,
2007 domain_similarity_sort_field_for_automated_pwc,
2008 domain_similarity_print_option,
2010 domain_id_to_go_ids_map,
2017 automated_pairwise_comparison_suffix,
2019 surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_PREFIX,
2020 surfacing_hmmpfam.PRG_NAME,
2023 String matrix_output_file = new String( output_file.toString() );
2024 if ( matrix_output_file.indexOf( '.' ) > 1 ) {
2025 matrix_output_file = matrix_output_file.substring( 0, matrix_output_file.indexOf( '.' ) );
2027 if ( out_dir != null ) {
2028 matrix_output_file = out_dir + ForesterUtil.FILE_SEPARATOR + matrix_output_file;
2029 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
2032 .writeMatrixToFile( new File( matrix_output_file
2033 + surfacing_hmmpfam.MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ),
2034 pwgc.getDomainDistanceScoresMeans() );
2036 .writeMatrixToFile( new File( matrix_output_file
2037 + surfacing_hmmpfam.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
2038 pwgc.getSharedBinaryCombinationsBasedDistances() );
2040 .writeMatrixToFile( new File( matrix_output_file
2041 + surfacing_hmmpfam.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
2042 pwgc.getSharedDomainsBasedDistances() );
2043 final Phylogeny nj_gd = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2044 + surfacing_hmmpfam.NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2045 .getDomainDistanceScoresMeans().get( 0 ) );
2046 final Phylogeny nj_bc = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2047 + surfacing_hmmpfam.NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2048 .getSharedBinaryCombinationsBasedDistances().get( 0 ) );
2049 final Phylogeny nj_d = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2050 + surfacing_hmmpfam.NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2051 .getSharedDomainsBasedDistances().get( 0 ) );
2052 inferred_trees = new ArrayList<Phylogeny>();
2053 inferred_trees.add( nj_gd );
2054 inferred_trees.add( nj_bc );
2055 inferred_trees.add( nj_d );
2056 // final List<HistogramData> histogram_datas = pwgc.getHistogramDatas();
2057 // if ( infer_species_trees ) {
2058 // inferred_trees = new ArrayList<Phylogeny>();
2059 // final List<Phylogeny> inferred_trees_bc = inferSpeciesTrees( new File( output_file + INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2060 // .getSharedBinaryCombinationsBasedDistances() );
2061 // final List<Phylogeny> inferred_trees_d = inferSpeciesTrees( new File( output_file + INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2062 // .getSharedDomainsBasedDistances() );
2063 // inferred_trees.addAll( inferred_trees_bc );
2064 // inferred_trees.addAll( inferred_trees_d );
2066 if ( jacknifed_distances ) {
2067 pwgc.performPairwiseComparisonsJacknifed( species,
2071 jacknife_resamplings,
2075 .writeMatrixToFile( new File( matrix_output_file
2077 + ForesterUtil.round( jacknife_ratio, 2 )
2079 + jacknife_resamplings
2080 + surfacing_hmmpfam.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
2081 pwgc.getSharedBinaryCombinationsBasedDistances() );
2083 .writeMatrixToFile( new File( matrix_output_file
2085 + ForesterUtil.round( jacknife_ratio, 2 )
2087 + jacknife_resamplings
2088 + surfacing_hmmpfam.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
2089 pwgc.getSharedDomainsBasedDistances() );
2090 // if ( infer_species_trees ) {
2091 // inferSpeciesTrees( new File( output_file + "_" + jacknife_resamplings
2092 // + INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2093 // .getSharedBinaryCombinationsBasedDistances() );
2094 // inferSpeciesTrees( new File( output_file + "_" + jacknife_resamplings
2095 // + INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc.getSharedDomainsBasedDistances() );
2098 if ( display_histograms ) {
2099 // final List<HistogramData> histogram_datas_all = new ArrayList<HistogramData>();
2100 // histogram_datas_all.add( new HistogramData( "all",
2101 // values_for_all_scores_histogram,
2104 // final HistogramsFrame hf_all = new HistogramsFrame( histogram_datas_all );
2105 // final HistogramsFrame hf = new HistogramsFrame( histogram_datas );
2106 // hf_all.setVisible( true );
2107 // hf.setVisible( true );
2109 } // if ( ( output_file != null ) && ( number_of_genomes > 2 ) && !isEmpty( automated_pairwise_comparison_suffix ) )
2110 if ( ( out_dir != null ) && ( !perform_pwc ) ) {
2111 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
2113 // writePresentToNexus( output_file, positive_filter_file, filter, gwcd_list );
2114 if ( ( ( intrees != null ) && ( intrees.length > 0 ) ) && ( number_of_genomes > 2 ) ) {
2115 final StringBuilder parameters_sb = createParametersAsString( ignore_dufs,
2117 max_allowed_overlap,
2118 no_engulfing_overlaps,
2122 if ( radomize_fitch_parsimony ) {
2123 s += random_number_seed_for_fitch_parsimony + "_";
2126 for( final Phylogeny intree : intrees ) {
2127 final String outfile_name = ForesterUtil.removeSuffix( output_file.toString() ) + s
2128 + ForesterUtil.removeSuffix( intree_files[ i ].toString() );
2129 final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator.createInstance( intree,
2131 SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
2132 radomize_fitch_parsimony,
2136 domain_id_to_go_ids_map,
2139 parameters_sb.toString(),
2140 domain_id_to_secondary_features_maps,
2141 positive_filter_file == null ? null : filter,
2142 output_binary_domain_combinationsfor_graph_analysis,
2143 all_bin_domain_combinations_gained_fitch,
2144 all_bin_domain_combinations_lost_fitch,
2146 // Listing of all domain combinations gained is only done if only one input tree is used.
2147 if ( ( domain_id_to_secondary_features_maps != null )
2148 && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
2150 for( final Map<DomainId, Set<String>> domain_id_to_secondary_features_map : domain_id_to_secondary_features_maps ) {
2151 final Map<Species, MappingResults> mapping_results_map = new TreeMap<Species, MappingResults>();
2152 final DomainParsimonyCalculator secondary_features_parsimony = DomainParsimonyCalculator
2153 .createInstance( intree, gwcd_list, domain_id_to_secondary_features_map );
2155 .executeParsimonyAnalysisForSecondaryFeatures( outfile_name
2157 + secondary_features_map_files[ j++ ],
2158 secondary_features_parsimony,
2160 parameters_sb.toString(),
2161 mapping_results_map );
2163 System.out.println();
2164 System.out.println( "Mapping to secondary features:" );
2165 for( final Species spec : mapping_results_map.keySet() ) {
2166 final MappingResults mapping_results = mapping_results_map.get( spec );
2167 final int total_domains = mapping_results.getSumOfFailures()
2168 + mapping_results.getSumOfSuccesses();
2169 System.out.print( spec + ":" );
2170 System.out.print( " mapped domains = " + mapping_results.getSumOfSuccesses() );
2171 System.out.print( ", not mapped domains = " + mapping_results.getSumOfFailures() );
2172 if ( total_domains > 0 ) {
2173 System.out.println( ", mapped ratio = "
2174 + ( 100 * mapping_results.getSumOfSuccesses() / total_domains ) + "%" );
2177 System.out.println( ", mapped ratio = n/a (total domains = 0 )" );
2184 } // for( final Phylogeny intree : intrees ) {
2186 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
2187 executePlusMinusAnalysis( output_file,
2188 plus_minus_analysis_high_copy_base_species,
2189 plus_minus_analysis_high_copy_target_species,
2190 plus_minus_analysis_high_low_copy_species,
2192 protein_lists_per_species,
2193 domain_id_to_go_ids_map,
2195 plus_minus_analysis_numbers );
2197 if ( output_protein_lists_for_all_domains ) {
2198 writeProteinListsForAllSpecies( out_dir, protein_lists_per_species, gwcd_list );
2200 // if ( ( intrees != null ) && ( intrees.length > 0 ) && ( inferred_trees != null ) && ( inferred_trees.size() > 0 ) ) {
2201 // final StringBuilder parameters_sb = createParametersAsString( ignore_dufs,
2203 // max_allowed_overlap,
2204 // no_engulfing_overlaps,
2205 // cutoff_scores_file );
2207 // if ( radomize_fitch_parsimony ) {
2208 // s += random_number_seed_for_fitch_parsimony + "_";
2211 // for( final Phylogeny inferred_tree : inferred_trees ) {
2212 // if ( !inferred_tree.isRooted() ) {
2213 // intrees[ 0 ].getRoot().getName();
2216 // final String outfile_name = ForesterUtil.removeSuffix( inferred_tree.getName() ) + s;
2217 // final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator
2218 // .createInstance( inferred_tree, gwcd_list );
2219 // SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
2220 // radomize_fitch_parsimony,
2222 // domain_parsimony,
2224 // domain_id_to_go_ids_map,
2225 // go_id_to_term_map,
2226 // go_namespace_limit,
2227 // parameters_sb.toString() );
2231 if ( all_bin_domain_combinations_gained_fitch != null ) {
2233 executeFitchGainsAnalysis( new File( output_file
2234 + surfacing_hmmpfam.OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2235 all_bin_domain_combinations_gained_fitch,
2236 all_domains_encountered.size(),
2237 all_bin_domain_combinations_encountered,
2240 catch ( final IOException e ) {
2241 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2244 if ( all_bin_domain_combinations_lost_fitch != null ) {
2246 executeFitchGainsAnalysis( new File( output_file
2247 + surfacing_hmmpfam.OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2248 all_bin_domain_combinations_lost_fitch,
2249 all_domains_encountered.size(),
2250 all_bin_domain_combinations_encountered,
2253 catch ( final IOException e ) {
2254 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2257 final Runtime rt = java.lang.Runtime.getRuntime();
2258 final long free_memory = rt.freeMemory() / 1000000;
2259 final long total_memory = rt.totalMemory() / 1000000;
2260 System.out.println();
2261 System.out.println( "Time for analysis : " + ( new Date().getTime() - analysis_start_time ) + "ms" );
2262 System.out.println( "Total running time: " + ( new Date().getTime() - start_time ) + "ms " );
2263 System.out.println( "Free memory : " + free_memory + "MB, total memory: " + total_memory + "MB" );
2264 System.out.println();
2265 System.out.println( "If this application is useful to you, please cite:" );
2266 System.out.println( surfacing_hmmpfam.WWW );
2267 System.out.println();
2268 ForesterUtil.programMessage( PRG_NAME, "OK" );
2269 System.out.println();
2272 private static void preparePhylogenyForParsimonyAnalyses( final Phylogeny intree,
2273 final String[][] input_file_properties ) {
2274 final String[] genomes = new String[ input_file_properties.length ];
2275 for( int i = 0; i < input_file_properties.length; ++i ) {
2276 if ( intree.getNodes( input_file_properties[ i ][ 1 ] ).size() > 1 ) {
2277 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "node named [" + input_file_properties[ i ][ 1 ]
2278 + "] is not unique in input tree " + intree.getName() );
2280 genomes[ i ] = input_file_properties[ i ][ 1 ];
2282 PhylogenyMethods.deleteExternalNodesPositiveSelection( genomes, intree );
2283 for( int i = 0; i < input_file_properties.length; ++i ) {
2285 intree.getNode( input_file_properties[ i ][ 1 ] );
2287 catch ( final IllegalArgumentException e ) {
2288 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "node named [" + input_file_properties[ i ][ 1 ]
2289 + "] not present/not unique in input tree" );
2294 // public static StringBuffer stringCombinableDomainsMapToStringBuffer(
2295 // final SortedMap<String, CombinableDomains> map ) {
2296 // final StringBuffer sb = new StringBuffer();
2297 // for( final Iterator<String> iter = map.keySet().iterator();
2298 // iter.hasNext(); ) {
2299 // final Object key = iter.next();
2300 // sb.append( ForesterUtil.pad( new StringBuffer( key.toString() ), 18, ' ',
2302 // final CombinableDomains domain_combination = map.get( key );
2303 // sb.append( ForesterUtil.pad( new StringBuffer( "" +
2304 // domain_combination.getNumberOfCombiningDomains() ), 8,
2306 // sb.append( domain_combination.toStringBuffer() );
2307 // sb.append( ForesterUtil.getLineSeparator() );
2311 private static void printHelp() {
2312 System.out.println();
2313 System.out.println( "Usage:" );
2314 System.out.println();
2315 System.out.println( "% java -Xms256m -Xmx512m -cp forester.jar org.forester.applications."
2316 + surfacing_hmmpfam.PRG_NAME
2317 + " [options] <phylogen(y|ies) infile> [external node name 1] [name 2] ... [name n]" );
2318 System.out.println();
2319 System.out.println( " Note: This software might need a significant amount of memory (heap space);" );
2321 .println( " hence use \"-Xms128m -Xmx512m\" (or more) to prevent a \"java.lang.OutOfMemoryError\"." );
2322 System.out.println();
2323 System.out.println( " Options: " );
2324 System.out.println( surfacing_hmmpfam.DETAILEDNESS_OPTION
2325 + ": level of detail for similarities output file (default:" + DETAILEDNESS_DEFAULT + ")" );
2326 System.out.println( surfacing_hmmpfam.IGNORE_COMBINATION_WITH_SAME_OPTION
2327 + ": to ignore combinations with self (default: not to ignore)" );
2329 .println( surfacing_hmmpfam.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION
2330 + ": to ignore domains without combinations in any species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2332 .println( surfacing_hmmpfam.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION
2333 + ": to ignore domains specific to one species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2334 System.out.println( surfacing_hmmpfam.NOT_IGNORE_DUFS_OPTION
2335 + ": to _not_ ignore DUFs (domains with unknown function) (default: ignore DUFs)" );
2337 .println( surfacing_hmmpfam.IGNORE_VIRAL_IDS
2338 + ": to ignore domains with ids containing 'vir', 'retro', 'transpos', 'phage', or starting with 'rv' or 'gag_'" );
2339 System.out.println( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION + ": sorting for similarities (default: "
2340 + DOMAIN_SORT_FILD_DEFAULT + ")" );
2341 System.out.println( surfacing_hmmpfam.OUTPUT_FILE_OPTION + ": name for (main) output file (mandatory)" );
2342 System.out.println( surfacing_hmmpfam.MAX_E_VALUE_OPTION + ": max (inclusive) E-value" );
2343 System.out.println( surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_OPTION + ": maximal allowed domain overlap" );
2344 System.out.println( surfacing_hmmpfam.NO_ENGULFING_OVERLAP_OPTION
2345 + ": to ignore engulfed lower confidence domains" );
2346 System.out.println( surfacing_hmmpfam.SPECIES_MATRIX_OPTION + ": species matrix" );
2347 System.out.println( surfacing_hmmpfam.SCORING_OPTION + ": scoring (default:" + SCORING_DEFAULT + ")" );
2348 System.out.println( surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION + ": sorting for domain counts (default:"
2349 + DOMAINS_SORT_ORDER_DEFAULT + ")" );
2350 System.out.println( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION
2351 + ": domain similarity print option (default:" + DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT + ")" );
2352 System.out.println( surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION + ": cutoff score file" );
2353 System.out.println( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION
2354 + ": sort by species count first" );
2355 System.out.println( surfacing_hmmpfam.OUTPUT_DIR_OPTION + ": output directory" );
2356 System.out.println( surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION + ": Pfam to GO mapping file" );
2357 System.out.println( surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION + ": GO terms file (OBO format)" );
2358 System.out.println( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION + ": limit GO term to one GO namespace" );
2359 System.out.println( surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION
2360 + "[=<suffix for pairwise comparison output files>]: to perform pairwise comparison based analyses" );
2361 System.out.println( surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION
2362 + ": species tree, to perform (Dollo, Fitch) parismony analyses" );
2363 System.out.println( surfacing_hmmpfam.DISPLAY_M_HISTOGRAMS_OPTION
2364 + ": to display multiple histograms (using fluorite)" );
2366 .println( JACKNIFE_OPTION
2367 + ": perform jacknife resampling for domain and binary domain combination based distance matrices [default resamplings: "
2368 + JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT + "]" );
2369 System.out.println( JACKNIFE_RATIO_OPTION + ": ratio for jacknife resampling [default: "
2370 + JACKNIFE_RATIO_DEFAULT + "]" );
2371 System.out.println( JACKNIFE_RANDOM_SEED_OPTION
2372 + ": seed for random number generator for jacknife resampling [default: "
2373 + JACKNIFE_RANDOM_SEED_DEFAULT + "]" );
2374 // System.out.println( surfacing.INFER_SPECIES_TREES_OPTION
2375 // + ": to infer NJ species trees based on shared domains/binary domain combinations" );
2377 .println( surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION
2378 + "=<treefiles in phyloXML format, separated by #>: to infer domain/binary domain combination gains/losses on given species trees" );
2379 System.out.println( surfacing_hmmpfam.FILTER_POSITIVE_OPTION
2380 + "=<file>: to filter out proteins not containing at least one domain listed in <file>" );
2381 System.out.println( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION
2382 + "=<file>: to filter out proteins containing at least one domain listed in <file>" );
2383 System.out.println( surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION
2384 + "=<file>: to filter out (ignore) domains listed in <file>" );
2386 .println( surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION + "=<file>: to read input files from <file>" );
2388 .println( surfacing_hmmpfam.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION
2389 + "=<seed>: seed for random number generator for Fitch Parsimony analysis (type: long, default: no randomization - given a choice, prefer absence" );
2390 System.out.println( surfacing_hmmpfam.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS
2391 + ": to consider directedness in binary combinations: e.g. A-B != B-A" );
2392 System.out.println( surfacing_hmmpfam.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY
2393 + ": to consider directedness and adjacency in binary combinations" );
2395 .println( surfacing_hmmpfam.SEQ_EXTRACT_OPTION
2396 + "=<domain ids (Pfam names)>: to extract sequence names of sequences containing matching domains and/or domain-sequences (order N to C) (domain separator: '~', domain sequences speparator: '#', e.g. 'NACHT#BIR~CARD')" );
2397 System.out.println( surfacing_hmmpfam.SECONDARY_FEATURES_PARSIMONY_MAP_FILE
2398 + "=<file>: to perfom parsimony analysis on secondary features" );
2399 System.out.println( surfacing_hmmpfam.PLUS_MINUS_ANALYSIS_OPTION
2400 + "=<file>: to presence/absence genome analysis" );
2401 System.out.println( surfacing_hmmpfam.DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS
2402 + ": to output binary domain combinations for (downstream) graph analysis" );
2403 System.out.println( surfacing_hmmpfam.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS
2404 + ": to output all proteins per domain" );
2405 System.out.println();
2406 System.out.println();
2407 System.out.println( "Example: java -Xms128m -Xmx512m -cp path/to/forester.jar"
2408 + "org.forester.application.surfacing -detail=punctilious -o=TEST.html -pwc=TEST"
2409 + " -cos=Pfam_ls_22_TC2 -p2g=pfam2go -obo=gene_ontology_edit.obo "
2410 + "-dc_sort=dom -ignore_with_self -no_singles -e=0.001 -mo=1 -no_eo "
2411 + "-ds_output=detailed_html -scoring=domains -sort=alpha -" + JACKNIFE_OPTION
2412 + "=50 human mouse brafl strpu" );
2413 System.out.println();
2416 private static void processFilter( final File filter_file, final SortedSet<DomainId> filter ) {
2417 SortedSet<String> filter_str = null;
2419 filter_str = ForesterUtil.file2set( filter_file );
2421 catch ( final IOException e ) {
2422 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage() );
2424 if ( filter_str != null ) {
2425 for( final String string : filter_str ) {
2426 filter.add( new DomainId( string ) );
2430 System.out.println( "Filter:" );
2431 for( final DomainId domainId : filter ) {
2432 System.out.println( domainId.getId() );
2437 private static String[][] processInputFileNames( final String[] names ) {
2438 final String[][] input_file_properties = new String[ names.length ][];
2439 for( int i = 0; i < names.length; ++i ) {
2440 if ( names[ i ].indexOf( SEPARATOR_FOR_INPUT_VALUES ) < 0 ) {
2441 input_file_properties[ i ] = new String[ 3 ];
2442 input_file_properties[ i ][ 0 ] = names[ i ];
2443 input_file_properties[ i ][ 1 ] = names[ i ];
2444 input_file_properties[ i ][ 2 ] = DEFAULT_SEARCH_PARAMETER;
2447 input_file_properties[ i ] = names[ i ].split( surfacing_hmmpfam.SEPARATOR_FOR_INPUT_VALUES + "" );
2448 if ( input_file_properties[ i ].length != 3 ) {
2450 .fatalError( surfacing_hmmpfam.PRG_NAME,
2451 "properties for the input files (hmmpfam output) are expected "
2452 + "to be in the following format \"<hmmpfam output file>#<species>#<search"
2453 + " parameter>\" (or just one word, which is both the filename and the species id), instead received \""
2454 + names[ i ] + "\"" );
2457 final String error = ForesterUtil.isReadableFile( new File( input_file_properties[ i ][ 0 ] ) );
2458 if ( !ForesterUtil.isEmpty( error ) ) {
2459 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, error );
2462 return input_file_properties;
2465 private static void processPlusMinusAnalysisOption( final CommandLineArguments cla,
2466 final List<String> high_copy_base,
2467 final List<String> high_copy_target,
2468 final List<String> low_copy,
2469 final List<Object> numbers ) {
2470 if ( cla.isOptionSet( surfacing_hmmpfam.PLUS_MINUS_ANALYSIS_OPTION ) ) {
2471 if ( !cla.isOptionValueSet( surfacing_hmmpfam.PLUS_MINUS_ANALYSIS_OPTION ) ) {
2472 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for 'plus-minus' file: -"
2473 + surfacing_hmmpfam.PLUS_MINUS_ANALYSIS_OPTION + "=<file>" );
2475 final File plus_minus_file = new File( cla.getOptionValue( surfacing_hmmpfam.PLUS_MINUS_ANALYSIS_OPTION ) );
2476 final String msg = ForesterUtil.isReadableFile( plus_minus_file );
2477 if ( !ForesterUtil.isEmpty( msg ) ) {
2478 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "can not read from \"" + plus_minus_file + "\": "
2481 processPlusMinusFile( plus_minus_file, high_copy_base, high_copy_target, low_copy, numbers );
2485 // First numbers is minimal difference, second is factor.
2486 private static void processPlusMinusFile( final File plus_minus_file,
2487 final List<String> high_copy_base,
2488 final List<String> high_copy_target,
2489 final List<String> low_copy,
2490 final List<Object> numbers ) {
2491 Set<String> species_set = null;
2492 int min_diff = PLUS_MINUS_ANALYSIS_MIN_DIFF_DEFAULT;
2493 double factor = PLUS_MINUS_ANALYSIS_FACTOR_DEFAULT;
2495 species_set = ForesterUtil.file2set( plus_minus_file );
2497 catch ( final IOException e ) {
2498 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage() );
2500 if ( species_set != null ) {
2501 for( final String species : species_set ) {
2502 final String species_trimmed = species.substring( 1 );
2503 if ( species.startsWith( "+" ) ) {
2504 if ( low_copy.contains( species_trimmed ) ) {
2505 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
2506 "species/genome names can not appear with both '+' and '-' suffix, as appears the case for: \""
2507 + species_trimmed + "\"" );
2509 high_copy_base.add( species_trimmed );
2511 else if ( species.startsWith( "*" ) ) {
2512 if ( low_copy.contains( species_trimmed ) ) {
2513 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
2514 "species/genome names can not appear with both '*' and '-' suffix, as appears the case for: \""
2515 + species_trimmed + "\"" );
2517 high_copy_target.add( species_trimmed );
2519 else if ( species.startsWith( "-" ) ) {
2520 if ( high_copy_base.contains( species_trimmed ) || high_copy_target.contains( species_trimmed ) ) {
2521 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
2522 "species/genome names can not appear with both '+' or '*' and '-' suffix, as appears the case for: \""
2523 + species_trimmed + "\"" );
2525 low_copy.add( species_trimmed );
2527 else if ( species.startsWith( "$D" ) ) {
2529 min_diff = Integer.parseInt( species.substring( 3 ) );
2531 catch ( final NumberFormatException e ) {
2532 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
2533 "could not parse integer value for minimal difference from: \""
2534 + species.substring( 3 ) + "\"" );
2537 else if ( species.startsWith( "$F" ) ) {
2539 factor = Double.parseDouble( species.substring( 3 ) );
2541 catch ( final NumberFormatException e ) {
2542 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
2543 "could not parse double value for factor from: \""
2544 + species.substring( 3 ) + "\"" );
2547 else if ( species.startsWith( "#" ) ) {
2552 .fatalError( surfacing_hmmpfam.PRG_NAME,
2553 "species/genome names in 'plus minus' file must begin with '*' (high copy target genome), '+' (high copy base genomes), '-' (low copy genomes), '$D=<integer>' minimal Difference (default is 1), '$F=<double>' factor (default is 1.0), double), or '#' (ignore) suffix, encountered: \""
2556 numbers.add( new Integer( min_diff + "" ) );
2557 numbers.add( new Double( factor + "" ) );
2561 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "'plus minus' file [" + plus_minus_file
2562 + "] appears empty" );
2566 private static void writeProteinListsForAllSpecies( final File output_dir,
2567 final SortedMap<Species, List<Protein>> protein_lists_per_species,
2568 final List<GenomeWideCombinableDomains> gwcd_list ) {
2569 final SortedSet<DomainId> all_domains = new TreeSet<DomainId>();
2570 for( final GenomeWideCombinableDomains gwcd : gwcd_list ) {
2571 all_domains.addAll( gwcd.getAllDomainIds() );
2573 for( final DomainId domain : all_domains ) {
2574 final File out = new File( output_dir + ForesterUtil.FILE_SEPARATOR + domain + SEQ_EXTRACT_SUFFIX );
2575 SurfacingUtil.checkForOutputFileWriteability( out );
2577 final Writer proteins_file_writer = new BufferedWriter( new FileWriter( out ) );
2578 SurfacingUtil.extractProteinNames( protein_lists_per_species, domain, proteins_file_writer, "\t" );
2579 proteins_file_writer.close();
2581 catch ( final IOException e ) {
2582 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getLocalizedMessage() );
2584 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME, "Wrote proteins list to \"" + out + "\"" );