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.writers.PhylogenyWriter;
56 import org.forester.phylogeny.Phylogeny;
57 import org.forester.phylogeny.PhylogenyMethods;
58 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
59 import org.forester.surfacing.BasicDomainSimilarityCalculator;
60 import org.forester.surfacing.BasicGenomeWideCombinableDomains;
61 import org.forester.surfacing.BasicSpecies;
62 import org.forester.surfacing.BinaryDomainCombination;
63 import org.forester.surfacing.CombinationsBasedPairwiseDomainSimilarityCalculator;
64 import org.forester.surfacing.DomainCountsBasedPairwiseSimilarityCalculator;
65 import org.forester.surfacing.DomainCountsDifferenceUtil;
66 import org.forester.surfacing.DomainId;
67 import org.forester.surfacing.DomainLengthsTable;
68 import org.forester.surfacing.DomainParsimonyCalculator;
69 import org.forester.surfacing.DomainSimilarity;
70 import org.forester.surfacing.DomainSimilarity.DomainSimilarityScoring;
71 import org.forester.surfacing.DomainSimilarity.DomainSimilaritySortField;
72 import org.forester.surfacing.DomainSimilarityCalculator;
73 import org.forester.surfacing.DomainSimilarityCalculator.Detailedness;
74 import org.forester.surfacing.GenomeWideCombinableDomains;
75 import org.forester.surfacing.GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder;
76 import org.forester.surfacing.MappingResults;
77 import org.forester.surfacing.PairwiseDomainSimilarityCalculator;
78 import org.forester.surfacing.PairwiseGenomeComparator;
79 import org.forester.surfacing.PrintableDomainSimilarity;
80 import org.forester.surfacing.PrintableDomainSimilarity.PRINT_OPTION;
81 import org.forester.surfacing.Protein;
82 import org.forester.surfacing.ProteinCountsBasedPairwiseDomainSimilarityCalculator;
83 import org.forester.surfacing.Species;
84 import org.forester.surfacing.SurfacingUtil;
85 import org.forester.util.BasicTable;
86 import org.forester.util.BasicTableParser;
87 import org.forester.util.CommandLineArguments;
88 import org.forester.util.DescriptiveStatistics;
89 import org.forester.util.ForesterConstants;
90 import org.forester.util.ForesterUtil;
92 public class surfacing_hmmpfam {
94 public final static String DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS = "graph_analysis_out";
95 public final static String DOMAIN_COMBINITONS_OUTPUTFILE_SUFFIX_FOR_GRAPH_ANALYSIS = "_dc.dot";
96 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_BC_OUTPUTFILE_SUFFIX_FOR_GRAPH_ANALYSIS = "_fitch_present_dc.dot";
97 public final static String DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX = ".dcc";
99 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_DOMAINS = "_dollo_gl_d";
100 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_BINARY_COMBINATIONS = "_dollo_gl_dc";
101 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_FITCH_DOMAINS = "_fitch_gl_d";
102 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_FITCH_BINARY_COMBINATIONS = "_fitch_gl_dc";
104 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_DOMAINS = "_dollo_glc_d";
105 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_BINARY_COMBINATIONS = "_dollo_glc_dc";
106 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_FITCH_DOMAINS = "_fitch_glc_d";
107 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_FITCH_BINARY_COMBINATIONS = "_fitch_glc_dc";
109 public final static String PARSIMONY_OUTPUT_FITCH_GAINS_BC = "_fitch_gains_dc";
110 public final static String PARSIMONY_OUTPUT_FITCH_GAINS_HTML_BC = "_fitch_gains_dc.html";
111 public final static String PARSIMONY_OUTPUT_FITCH_LOSSES_BC = "_fitch_losses_dc";
112 public final static String PARSIMONY_OUTPUT_FITCH_LOSSES_HTML_BC = "_fitch_losses_dc.html";
113 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_BC = "_fitch_present_dc";
114 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_HTML_BC = "_fitch_present_dc.html";
115 public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_D = "_dollo_gains_d";
116 public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_GOID_D = "_dollo_gains_goid_d";
117 public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_HTML_D = "_dollo_gains_d.html";
118 public final static String PARSIMONY_OUTPUT_DOLLO_LOSSES_D = "_dollo_losses_d";
119 public final static String PARSIMONY_OUTPUT_DOLLO_LOSSES_HTML_D = "_dollo_losses_d.html";
120 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_D = "_dollo_present_d";
121 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_GOID_D = "_dollo_present_goid_d";
122 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_HTML_D = "_dollo_present_d.html";
123 public final static String DOMAINS_PRESENT_NEXUS = "_dom.nex";
124 public final static String BDC_PRESENT_NEXUS = "_dc.nex";
126 public final static String PRG_NAME = "surfacing";
127 public static final String DOMAINS_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_d_dollo"
128 + ForesterConstants.PHYLO_XML_SUFFIX;
129 public static final String DOMAINS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH = "_d_fitch"
130 + ForesterConstants.PHYLO_XML_SUFFIX;
131 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_dc_dollo"
132 + ForesterConstants.PHYLO_XML_SUFFIX;
133 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH = "_dc_fitch"
134 + ForesterConstants.PHYLO_XML_SUFFIX;
135 public static final String NEXUS_EXTERNAL_DOMAINS = "_dom.nex";
136 public static final String NEXUS_EXTERNAL_DOMAIN_COMBINATIONS = "_dc.nex";
137 public static final String NEXUS_SECONDARY_FEATURES = "_secondary_features.nex";
138 public static final String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_SECONDARY_FEATURES = "_dollo_gl_secondary_features";
139 public static final String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_SECONDARY_FEATURES = "_dollo_glc_secondary_features";
140 public static final String PARSIMONY_OUTPUT_DOLLO_GAINS_SECONDARY_FEATURES = "_dollo_gains_secondary_features";
141 public static final String PARSIMONY_OUTPUT_DOLLO_LOSSES_SECONDARY_FEATURES = "_dollo_losses_secondary_features";
142 public static final String PARSIMONY_OUTPUT_DOLLO_PRESENT_SECONDARY_FEATURES = "_dollo_present_secondary_features";
143 public static final String SECONDARY_FEATURES_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_secondary_features_dollo"
144 + ForesterConstants.PHYLO_XML_SUFFIX;
145 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_BIOLOGICAL_PROCESS = "_dollo_biol_proc_goid_d";
146 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_CELLULAR_COMPONENT = "_dollo_cell_comp_goid_d";
147 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_MOLECULAR_FUNCTION = "_dollo_mol_funct_goid_d";
148 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_ALL_NAMESPACES = "_dollo_goid_d";
149 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_BIOLOGICAL_PROCESS = "_fitch_biol_proc_goid_dc";
150 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_CELLULAR_COMPONENT = "_fitch_cell_comp_goid_dc";
151 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_MOLECULAR_FUNCTION = "_fitch_mol_funct_goid_dc";
152 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_ALL_NAMESPACES = "_fitch_goid_dc";
153 final static private String HELP_OPTION_1 = "help";
154 final static private String HELP_OPTION_2 = "h";
155 final static private String OUTPUT_DIR_OPTION = "out_dir";
156 final static private String SCORING_OPTION = "scoring";
157 private static final DomainSimilarityScoring SCORING_DEFAULT = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
158 final static private String SCORING_DOMAIN_COUNT_BASED = "domains";
159 final static private String SCORING_PROTEIN_COUNT_BASED = "proteins";
160 final static private String SCORING_COMBINATION_BASED = "combinations";
161 final static private String DETAILEDNESS_OPTION = "detail";
162 private final static Detailedness DETAILEDNESS_DEFAULT = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
163 final static private String SPECIES_MATRIX_OPTION = "smatrix";
164 final static private String DETAILEDNESS_BASIC = "basic";
165 final static private String DETAILEDNESS_LIST_IDS = "list_ids";
166 final static private String DETAILEDNESS_PUNCTILIOUS = "punctilious";
167 final static private String DOMAIN_SIMILARITY_SORT_OPTION = "sort";
168 private static final DomainSimilaritySortField DOMAIN_SORT_FILD_DEFAULT = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
169 final static private String DOMAIN_SIMILARITY_SORT_MIN = "min";
170 final static private String DOMAIN_SIMILARITY_SORT_MAX = "max";
171 final static private String DOMAIN_SIMILARITY_SORT_SD = "sd";
172 final static private String DOMAIN_SIMILARITY_SORT_MEAN = "mean";
173 final static private String DOMAIN_SIMILARITY_SORT_DIFF = "diff";
174 final static private String DOMAIN_SIMILARITY_SORT_COUNTS_DIFF = "count_diff";
175 final static private String DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF = "abs_count_diff";
176 final static private String DOMAIN_SIMILARITY_SORT_SPECIES_COUNT = "species";
177 final static private String DOMAIN_SIMILARITY_SORT_ALPHA = "alpha";
178 final static private String DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION = "species_first";
179 final static private String DOMAIN_COUNT_SORT_OPTION = "dc_sort";
180 private static final GenomeWideCombinableDomainsSortOrder DOMAINS_SORT_ORDER_DEFAULT = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
181 final static private String DOMAIN_COUNT_SORT_ALPHA = "alpha";
182 final static private String DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT = "dom";
183 final static private String DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT = "prot";
184 final static private String DOMAIN_COUNT_SORT_COMBINATIONS_COUNT = "comb";
185 final static private String CUTOFF_SCORE_FILE_OPTION = "cos";
186 final static private String NOT_IGNORE_DUFS_OPTION = "dufs";
187 final static private String MAX_E_VALUE_OPTION = "e";
188 final static private String MAX_ALLOWED_OVERLAP_OPTION = "mo";
189 final static private String NO_ENGULFING_OVERLAP_OPTION = "no_eo";
190 final static private String IGNORE_COMBINATION_WITH_SAME_OPTION = "ignore_self_comb";
191 final static private String PAIRWISE_DOMAIN_COMPARISONS_PREFIX = "pwc_";
192 final static private String PAIRWISE_DOMAIN_COMPARISONS_OPTION = "pwc";
193 final static private String OUTPUT_FILE_OPTION = "o";
194 final static private String PFAM_TO_GO_FILE_USE_OPTION = "p2g";
195 final static private String GO_OBO_FILE_USE_OPTION = "obo";
196 final static private String GO_NAMESPACE_LIMIT_OPTION = "go_namespace";
197 final static private String GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION = "molecular_function";
198 final static private String GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS = "biological_process";
199 final static private String GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT = "cellular_component";
200 final static private String SECONDARY_FEATURES_PARSIMONY_MAP_FILE = "secondary";
201 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED = "simple_tab";
202 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML = "simple_html";
203 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML = "detailed_html";
204 final static private String DOMAIN_SIMILARITY_PRINT_OPTION = "ds_output";
205 private static final PRINT_OPTION DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT = PrintableDomainSimilarity.PRINT_OPTION.HTML;
206 final static private String IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION = "ignore_singlet_domains";
207 final static private String IGNORE_VIRAL_IDS = "ignore_viral_ids";
208 final static private boolean IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT = false;
209 final static private String IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION = "ignore_species_specific_domains";
210 final static private boolean IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT = false;
211 final static private String MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score.pwd";
212 final static private String MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains.pwd";
213 final static private String MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations.pwd";
214 final static private String NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score_NJ"
215 + ForesterConstants.PHYLO_XML_SUFFIX;
216 final static private String NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains_NJ"
217 + ForesterConstants.PHYLO_XML_SUFFIX;
218 final static private String NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations_NJ"
219 + ForesterConstants.PHYLO_XML_SUFFIX;
220 final static private String DISPLAY_M_HISTOGRAMS_OPTION = "mhisto";
221 // final static private boolean DISPLAY_M_HISTOGRAMS_OPTION_DEFAULT = false;
222 final static private String JACKNIFE_OPTION = "jack";
223 final static private String JACKNIFE_RANDOM_SEED_OPTION = "seed";
224 final static private String JACKNIFE_RATIO_OPTION = "jack_ratio";
225 private static final int JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT = 100;
226 final static private long JACKNIFE_RANDOM_SEED_DEFAULT = 19;
227 final static private double JACKNIFE_RATIO_DEFAULT = 0.5;
228 //final static private String INFER_SPECIES_TREES_OPTION = "species_tree_inference";
229 final static private String INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX = "_sd_nj.nh";
230 final static private String INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX = "_sbc_nj.nh";
231 final static private String FILTER_POSITIVE_OPTION = "pos_filter";
232 final static private String FILTER_NEGATIVE_OPTION = "neg_filter";
233 final static private String FILTER_NEGATIVE_DOMAINS_OPTION = "neg_dom_filter";
234 final static private String INPUT_FILES_FROM_FILE_OPTION = "input";
235 final static private String INPUT_SPECIES_TREE_OPTION = "species_tree";
236 final static private String SEQ_EXTRACT_OPTION = "prot_extract";
237 final static private char SEPARATOR_FOR_INPUT_VALUES = '#';
238 final static private String PRG_VERSION = "1.00";
239 final static private String PRG_DATE = "2009.07.06";
240 final static private String E_MAIL = "czmasek@burnham.org";
241 final static private String WWW = "www.phylosoft.org/forester/applications/surfacing";
242 final static private boolean IGNORE_DUFS_DEFAULT = true;
243 final static private boolean IGNORE_COMBINATION_WITH_SAME_DEFAULLT = false;
244 final static private double MAX_E_VALUE_DEFAULT = -1;
245 final static private int MAX_ALLOWED_OVERLAP_DEFAULT = -1;
246 final static private String DEFAULT_SEARCH_PARAMETER = "ls";
247 final private static boolean ALLOW_NON_UNIQUE_QUERY_IN_HMMPFAM_OUTPUT_DEFAULT = true;
248 final private static boolean VERBOSE_DEFAULT = true;
249 private static final String RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION = "random_seed";
250 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS = "consider_bdc_direction";
251 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY = "consider_bdc_adj";
252 private static final String SEQ_EXTRACT_SUFFIX = ".prot";
253 private static final String PLUS_MINUS_ANALYSIS_OPTION = "plus_minus";
254 private static final String PLUS_MINUS_DOM_SUFFIX = "_plus_minus_dom.txt";
255 private static final String PLUS_MINUS_DOM_SUFFIX_HTML = "_plus_minus_dom.html";
256 private static final String PLUS_MINUS_DC_SUFFIX_HTML = "_plus_minus_dc.html";
257 private static final int PLUS_MINUS_ANALYSIS_MIN_DIFF_DEFAULT = 0;
258 private static final double PLUS_MINUS_ANALYSIS_FACTOR_DEFAULT = 1.0;
259 private static final String PLUS_MINUS_ALL_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_all.txt";
260 private static final String PLUS_MINUS_PASSING_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_passing.txt";
261 private static final String OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS = "all_prot";
262 private static final boolean VERBOSE = false;
263 private static final String OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_gains_counts";
264 private static final String OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_losses_counts";
265 private static final String DOMAIN_LENGTHS_ANALYSIS_SUFFIX = "_domain_lengths_analysis";
266 private static final boolean PERFORM_DOMAIN_LENGTH_ANALYSIS = true;
267 public static final String ALL_PFAMS_ENCOUNTERED_SUFFIX = "_all_encountered_pfams";
268 public static final String ALL_PFAMS_ENCOUNTERED_WITH_GO_ANNOTATION_SUFFIX = "_all_encountered_pfams_with_go_annotation";
269 public static final String ENCOUNTERED_PFAMS_SUMMARY_SUFFIX = "_encountered_pfams_summary";
270 public static final String ALL_PFAMS_GAINED_AS_DOMAINS_SUFFIX = "_all_pfams_gained_as_domains";
271 public static final String ALL_PFAMS_LOST_AS_DOMAINS_SUFFIX = "_all_pfams_lost_as_domains";
272 public static final String ALL_PFAMS_GAINED_AS_DC_SUFFIX = "_all_pfams_gained_as_dc";
273 public static final String ALL_PFAMS_LOST_AS_DC_SUFFIX = "_all_pfams_lost_as_dc";
274 public static final String BASE_DIRECTORY_PER_NODE_DOMAIN_GAIN_LOSS_FILES = "PER_NODE_EVENTS";
275 public static final String BASE_DIRECTORY_PER_SUBTREE_DOMAIN_GAIN_LOSS_FILES = "PER_SUBTREE_EVENTS";
276 public static final String D_PROMISCUITY_FILE_SUFFIX = "_domain_promiscuities";
278 // final String error = ForesterUtil.isReadableFile( new File(
279 // input_file_properties[ i ][ 0 ] ) );
280 // if ( !ForesterUtil.isEmpty( error ) ) {
281 // ForesterUtil.fatalError( surfacing.PRG_NAME, error );
283 private static void checkWriteabilityForPairwiseComparisons( final PrintableDomainSimilarity.PRINT_OPTION domain_similarity_print_option,
284 final String[][] input_file_properties,
285 final String automated_pairwise_comparison_suffix,
286 final File outdir ) {
287 for( int i = 0; i < input_file_properties.length; ++i ) {
288 for( int j = 0; j < i; ++j ) {
289 final String species_i = input_file_properties[ i ][ 1 ];
290 final String species_j = input_file_properties[ j ][ 1 ];
291 String pairwise_similarities_output_file_str = PAIRWISE_DOMAIN_COMPARISONS_PREFIX + species_i + "_"
292 + species_j + automated_pairwise_comparison_suffix;
293 switch ( domain_similarity_print_option ) {
295 if ( !pairwise_similarities_output_file_str.endsWith( ".html" ) ) {
296 pairwise_similarities_output_file_str += ".html";
300 final String error = ForesterUtil
301 .isWritableFile( new File( outdir == null ? pairwise_similarities_output_file_str : outdir
302 + ForesterUtil.FILE_SEPARATOR + pairwise_similarities_output_file_str ) );
303 if ( !ForesterUtil.isEmpty( error ) ) {
304 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, error );
310 private static StringBuilder createParametersAsString( final boolean ignore_dufs,
311 final double e_value_max,
312 final int max_allowed_overlap,
313 final boolean no_engulfing_overlaps,
314 final File cutoff_scores_file,
315 final BinaryDomainCombination.DomainCombinationType dc_type ) {
316 final StringBuilder parameters_sb = new StringBuilder();
317 parameters_sb.append( "E-value: " + e_value_max );
318 if ( cutoff_scores_file != null ) {
319 parameters_sb.append( ", Cutoff-scores-file: " + cutoff_scores_file );
322 parameters_sb.append( ", Cutoff-scores-file: not-set" );
324 if ( max_allowed_overlap != surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_DEFAULT ) {
325 parameters_sb.append( ", Max-overlap: " + max_allowed_overlap );
328 parameters_sb.append( ", Max-overlap: not-set" );
330 if ( no_engulfing_overlaps ) {
331 parameters_sb.append( ", Engulfing-overlaps: not-allowed" );
334 parameters_sb.append( ", Engulfing-overlaps: allowed" );
337 parameters_sb.append( ", Ignore-dufs: true" );
340 parameters_sb.append( ", Ignore-dufs: false" );
342 parameters_sb.append( ", DC type (if applicable): " + dc_type );
343 return parameters_sb;
347 * Warning: This sideeffects 'all_bin_domain_combinations_encountered'!
351 * @param all_bin_domain_combinations_changed
352 * @param sum_of_all_domains_encountered
353 * @param all_bin_domain_combinations_encountered
354 * @param is_gains_analysis
355 * @throws IOException
357 private static void executeFitchGainsAnalysis( final File output_file,
358 final List<BinaryDomainCombination> all_bin_domain_combinations_changed,
359 final int sum_of_all_domains_encountered,
360 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered,
361 final boolean is_gains_analysis ) throws IOException {
362 SurfacingUtil.checkForOutputFileWriteability( output_file );
363 final Writer out = ForesterUtil.createBufferedWriter( output_file );
364 final SortedMap<Object, Integer> bdc_to_counts = ForesterUtil
365 .listToSortedCountsMap( all_bin_domain_combinations_changed );
366 final SortedSet<DomainId> all_domains_in_combination_changed_more_than_once = new TreeSet<DomainId>();
367 final SortedSet<DomainId> all_domains_in_combination_changed_only_once = new TreeSet<DomainId>();
370 for( final Object bdc_object : bdc_to_counts.keySet() ) {
371 final BinaryDomainCombination bdc = ( BinaryDomainCombination ) bdc_object;
372 final int count = bdc_to_counts.get( bdc_object );
374 ForesterUtil.unexpectedFatalError( PRG_NAME, "count < 1 " );
376 out.write( bdc + "\t" + count + ForesterUtil.LINE_SEPARATOR );
378 all_domains_in_combination_changed_more_than_once.add( bdc.getId0() );
379 all_domains_in_combination_changed_more_than_once.add( bdc.getId1() );
382 else if ( count == 1 ) {
383 all_domains_in_combination_changed_only_once.add( bdc.getId0() );
384 all_domains_in_combination_changed_only_once.add( bdc.getId1() );
388 final int all = all_bin_domain_combinations_encountered.size();
390 if ( !is_gains_analysis ) {
391 all_bin_domain_combinations_encountered.removeAll( all_bin_domain_combinations_changed );
392 never_lost = all_bin_domain_combinations_encountered.size();
393 for( final BinaryDomainCombination bdc : all_bin_domain_combinations_encountered ) {
394 out.write( bdc + "\t" + "0" + ForesterUtil.LINE_SEPARATOR );
397 if ( is_gains_analysis ) {
398 out.write( "Sum of all distinct domain combinations appearing once : " + one
399 + ForesterUtil.LINE_SEPARATOR );
400 out.write( "Sum of all distinct domain combinations appearing more than once : " + above_one
401 + ForesterUtil.LINE_SEPARATOR );
402 out.write( "Sum of all distinct domains in combinations apppearing only once : "
403 + all_domains_in_combination_changed_only_once.size() + ForesterUtil.LINE_SEPARATOR );
404 out.write( "Sum of all distinct domains in combinations apppearing more than once: "
405 + all_domains_in_combination_changed_more_than_once.size() + ForesterUtil.LINE_SEPARATOR );
408 out.write( "Sum of all distinct domain combinations never lost : " + never_lost
409 + ForesterUtil.LINE_SEPARATOR );
410 out.write( "Sum of all distinct domain combinations lost once : " + one
411 + ForesterUtil.LINE_SEPARATOR );
412 out.write( "Sum of all distinct domain combinations lost more than once : " + above_one
413 + ForesterUtil.LINE_SEPARATOR );
414 out.write( "Sum of all distinct domains in combinations lost only once : "
415 + all_domains_in_combination_changed_only_once.size() + ForesterUtil.LINE_SEPARATOR );
416 out.write( "Sum of all distinct domains in combinations lost more than once: "
417 + all_domains_in_combination_changed_more_than_once.size() + ForesterUtil.LINE_SEPARATOR );
419 out.write( "All binary combinations : " + all
420 + ForesterUtil.LINE_SEPARATOR );
421 out.write( "All domains : "
422 + sum_of_all_domains_encountered );
424 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME,
425 "Wrote fitch domain combination dynamics counts analysis to \"" + output_file
429 private static void executePlusMinusAnalysis( final File output_file,
430 final List<String> plus_minus_analysis_high_copy_base,
431 final List<String> plus_minus_analysis_high_copy_target,
432 final List<String> plus_minus_analysis_low_copy,
433 final List<GenomeWideCombinableDomains> gwcd_list,
434 final SortedMap<Species, List<Protein>> protein_lists_per_species,
435 final Map<DomainId, List<GoId>> domain_id_to_go_ids_map,
436 final Map<GoId, GoTerm> go_id_to_term_map,
437 final List<Object> plus_minus_analysis_numbers ) {
438 final Set<String> all_spec = new HashSet<String>();
439 for( final GenomeWideCombinableDomains gwcd : gwcd_list ) {
440 all_spec.add( gwcd.getSpecies().getSpeciesId() );
442 final File html_out_dom = new File( output_file + PLUS_MINUS_DOM_SUFFIX_HTML );
443 final File plain_out_dom = new File( output_file + PLUS_MINUS_DOM_SUFFIX );
444 final File html_out_dc = new File( output_file + PLUS_MINUS_DC_SUFFIX_HTML );
445 final File all_domains_go_ids_out_dom = new File( output_file + PLUS_MINUS_ALL_GO_IDS_DOM_SUFFIX );
446 final File passing_domains_go_ids_out_dom = new File( output_file + PLUS_MINUS_PASSING_GO_IDS_DOM_SUFFIX );
447 final File proteins_file_base = new File( output_file + "" );
448 final int min_diff = ( ( Integer ) plus_minus_analysis_numbers.get( 0 ) ).intValue();
449 final double factor = ( ( Double ) plus_minus_analysis_numbers.get( 1 ) ).doubleValue();
451 DomainCountsDifferenceUtil.calculateCopyNumberDifferences( gwcd_list,
452 protein_lists_per_species,
453 plus_minus_analysis_high_copy_base,
454 plus_minus_analysis_high_copy_target,
455 plus_minus_analysis_low_copy,
461 domain_id_to_go_ids_map,
463 all_domains_go_ids_out_dom,
464 passing_domains_go_ids_out_dom,
465 proteins_file_base );
467 catch ( final IOException e ) {
468 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getLocalizedMessage() );
470 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME, "Wrote plus minus domain analysis results to \""
471 + html_out_dom + "\"" );
472 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME, "Wrote plus minus domain analysis results to \""
473 + plain_out_dom + "\"" );
474 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME, "Wrote plus minus domain analysis results to \""
475 + html_out_dc + "\"" );
476 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME,
477 "Wrote plus minus domain analysis based passing GO ids to \""
478 + passing_domains_go_ids_out_dom + "\"" );
479 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME,
480 "Wrote plus minus domain analysis based all GO ids to \""
481 + all_domains_go_ids_out_dom + "\"" );
484 private static Phylogeny[] getIntrees( final File[] intree_files,
485 final int number_of_genomes,
486 final String[][] input_file_properties ) {
487 final Phylogeny[] intrees = new Phylogeny[ intree_files.length ];
489 for( final File intree_file : intree_files ) {
490 Phylogeny intree = null;
491 final String error = ForesterUtil.isReadableFile( intree_file );
492 if ( !ForesterUtil.isEmpty( error ) ) {
493 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read input tree file [" + intree_file
497 final Phylogeny[] p_array = ParserBasedPhylogenyFactory.getInstance()
498 .create( intree_file, ForesterUtil.createParserDependingOnFileType( intree_file, true ) );
499 if ( p_array.length < 1 ) {
500 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "file [" + intree_file
501 + "] does not contain any phylogeny in phyloXML format" );
503 else if ( p_array.length > 1 ) {
504 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "file [" + intree_file
505 + "] contains more than one phylogeny in phyloXML format" );
507 intree = p_array[ 0 ];
509 catch ( final Exception e ) {
510 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "failed to read input tree from file ["
511 + intree_file + "]: " + error );
513 if ( ( intree == null ) || intree.isEmpty() ) {
514 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "input tree [" + intree_file + "] is empty" );
516 if ( !intree.isRooted() ) {
517 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "input tree [" + intree_file + "] is not rooted" );
519 if ( intree.getNumberOfExternalNodes() < number_of_genomes ) {
520 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
521 "number of external nodes [" + intree.getNumberOfExternalNodes()
522 + "] of input tree [" + intree_file
523 + "] is smaller than the number of genomes the be analyzed ["
524 + number_of_genomes + "]" );
526 final StringBuilder parent_names = new StringBuilder();
527 final int nodes_lacking_name = SurfacingUtil.getNumberOfNodesLackingName( intree, parent_names );
528 if ( nodes_lacking_name > 0 ) {
529 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "input tree [" + intree_file + "] has "
530 + nodes_lacking_name + " node(s) lacking a name [parent names:" + parent_names + "]" );
532 preparePhylogenyForParsimonyAnalyses( intree, input_file_properties );
533 if ( !intree.isCompletelyBinary() ) {
534 ForesterUtil.printWarningMessage( surfacing_hmmpfam.PRG_NAME, "input tree [" + intree_file
535 + "] is not completely binary" );
537 intrees[ i++ ] = intree;
542 private static List<Phylogeny> inferSpeciesTrees( final File outfile, final List<DistanceMatrix> distances_list ) {
543 final NeighborJoining nj = NeighborJoining.createInstance();
544 final List<Phylogeny> phylogenies = nj.execute( distances_list );
545 final PhylogenyWriter w = new PhylogenyWriter();
547 w.toNewHampshire( phylogenies, true, true, outfile, ";" );
549 catch ( final IOException e ) {
550 ForesterUtil.fatalError( PRG_NAME, "failed to write to outfile [" + outfile + "]: " + e.getMessage() );
555 public static void main( final String args[] ) {
556 final long start_time = new Date().getTime();
557 // final StringBuffer log = new StringBuffer();
558 final StringBuilder html_desc = new StringBuilder();
559 ForesterUtil.printProgramInformation( surfacing_hmmpfam.PRG_NAME,
560 surfacing_hmmpfam.PRG_VERSION,
561 surfacing_hmmpfam.PRG_DATE,
562 surfacing_hmmpfam.E_MAIL,
563 surfacing_hmmpfam.WWW );
564 final String nl = ForesterUtil.LINE_SEPARATOR;
565 html_desc.append( "<table>" + nl );
566 html_desc.append( "<tr><td>Produced by:</td><td>" + surfacing_hmmpfam.PRG_NAME + "</td></tr>" + nl );
567 html_desc.append( "<tr><td>Version:</td><td>" + surfacing_hmmpfam.PRG_VERSION + "</td></tr>" + nl );
568 html_desc.append( "<tr><td>Release Date:</td><td>" + surfacing_hmmpfam.PRG_DATE + "</td></tr>" + nl );
569 html_desc.append( "<tr><td>Contact:</td><td>" + surfacing_hmmpfam.E_MAIL + "</td></tr>" + nl );
570 html_desc.append( "<tr><td>WWW:</td><td>" + surfacing_hmmpfam.WWW + "</td></tr>" + nl );
571 CommandLineArguments cla = null;
573 cla = new CommandLineArguments( args );
575 catch ( final Exception e ) {
576 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage() );
578 if ( cla.isOptionSet( surfacing_hmmpfam.HELP_OPTION_1 ) || cla.isOptionSet( surfacing_hmmpfam.HELP_OPTION_2 ) ) {
579 surfacing_hmmpfam.printHelp();
582 if ( ( args.length < 1 ) ) {
583 surfacing_hmmpfam.printHelp();
586 final List<String> allowed_options = new ArrayList<String>();
587 allowed_options.add( surfacing_hmmpfam.NOT_IGNORE_DUFS_OPTION );
588 allowed_options.add( surfacing_hmmpfam.MAX_E_VALUE_OPTION );
589 allowed_options.add( surfacing_hmmpfam.DETAILEDNESS_OPTION );
590 allowed_options.add( surfacing_hmmpfam.OUTPUT_FILE_OPTION );
591 allowed_options.add( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION );
592 allowed_options.add( surfacing_hmmpfam.SPECIES_MATRIX_OPTION );
593 allowed_options.add( surfacing_hmmpfam.SCORING_OPTION );
594 allowed_options.add( surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_OPTION );
595 allowed_options.add( surfacing_hmmpfam.NO_ENGULFING_OVERLAP_OPTION );
596 allowed_options.add( surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION );
597 allowed_options.add( surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION );
598 allowed_options.add( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION );
599 allowed_options.add( surfacing_hmmpfam.OUTPUT_DIR_OPTION );
600 allowed_options.add( surfacing_hmmpfam.IGNORE_COMBINATION_WITH_SAME_OPTION );
601 allowed_options.add( surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION );
602 allowed_options.add( surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION );
603 allowed_options.add( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION );
604 allowed_options.add( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION );
605 allowed_options.add( surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
606 allowed_options.add( surfacing_hmmpfam.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION );
607 allowed_options.add( surfacing_hmmpfam.DISPLAY_M_HISTOGRAMS_OPTION );
608 allowed_options.add( surfacing_hmmpfam.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS );
609 allowed_options.add( JACKNIFE_OPTION );
610 allowed_options.add( JACKNIFE_RANDOM_SEED_OPTION );
611 allowed_options.add( JACKNIFE_RATIO_OPTION );
612 allowed_options.add( INPUT_SPECIES_TREE_OPTION );
613 //allowed_options.add( INFER_SPECIES_TREES_OPTION );
614 allowed_options.add( FILTER_POSITIVE_OPTION );
615 allowed_options.add( FILTER_NEGATIVE_OPTION );
616 allowed_options.add( INPUT_FILES_FROM_FILE_OPTION );
617 allowed_options.add( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
618 allowed_options.add( FILTER_NEGATIVE_DOMAINS_OPTION );
619 allowed_options.add( IGNORE_VIRAL_IDS );
620 allowed_options.add( SEQ_EXTRACT_OPTION );
621 allowed_options.add( SECONDARY_FEATURES_PARSIMONY_MAP_FILE );
622 allowed_options.add( PLUS_MINUS_ANALYSIS_OPTION );
623 allowed_options.add( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS );
624 allowed_options.add( OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS );
625 allowed_options.add( CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY );
626 boolean ignore_dufs = surfacing_hmmpfam.IGNORE_DUFS_DEFAULT;
627 boolean ignore_combination_with_same = surfacing_hmmpfam.IGNORE_COMBINATION_WITH_SAME_DEFAULLT;
628 double e_value_max = surfacing_hmmpfam.MAX_E_VALUE_DEFAULT;
629 int max_allowed_overlap = surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_DEFAULT;
630 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
631 if ( dissallowed_options.length() > 0 ) {
632 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown option(s): " + dissallowed_options );
634 boolean output_binary_domain_combinationsfor_graph_analysis = false;
635 if ( cla.isOptionSet( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS ) ) {
636 output_binary_domain_combinationsfor_graph_analysis = true;
638 if ( cla.isOptionSet( surfacing_hmmpfam.MAX_E_VALUE_OPTION ) ) {
640 e_value_max = cla.getOptionValueAsDouble( surfacing_hmmpfam.MAX_E_VALUE_OPTION );
642 catch ( final Exception e ) {
643 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no acceptable value for E-value maximum" );
646 if ( cla.isOptionSet( surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_OPTION ) ) {
648 max_allowed_overlap = cla.getOptionValueAsInt( surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_OPTION );
650 catch ( final Exception e ) {
651 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
652 "no acceptable value for maximal allowed domain overlap" );
655 boolean no_engulfing_overlaps = false;
656 if ( cla.isOptionSet( surfacing_hmmpfam.NO_ENGULFING_OVERLAP_OPTION ) ) {
657 no_engulfing_overlaps = true;
659 boolean ignore_virus_like_ids = false;
660 if ( cla.isOptionSet( surfacing_hmmpfam.IGNORE_VIRAL_IDS ) ) {
661 ignore_virus_like_ids = true;
663 if ( cla.isOptionSet( surfacing_hmmpfam.NOT_IGNORE_DUFS_OPTION ) ) {
666 if ( cla.isOptionSet( surfacing_hmmpfam.IGNORE_COMBINATION_WITH_SAME_OPTION ) ) {
667 ignore_combination_with_same = true;
669 boolean ignore_domains_without_combs_in_all_spec = IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT;
670 if ( cla.isOptionSet( surfacing_hmmpfam.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION ) ) {
671 ignore_domains_without_combs_in_all_spec = true;
673 boolean ignore_species_specific_domains = IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT;
674 if ( cla.isOptionSet( surfacing_hmmpfam.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION ) ) {
675 ignore_species_specific_domains = true;
677 File output_file = null;
678 if ( cla.isOptionSet( surfacing_hmmpfam.OUTPUT_FILE_OPTION ) ) {
679 if ( !cla.isOptionValueSet( surfacing_hmmpfam.OUTPUT_FILE_OPTION ) ) {
680 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
681 "no value for domain combinations similarities output file: -"
682 + surfacing_hmmpfam.OUTPUT_FILE_OPTION + "=<file>" );
684 output_file = new File( cla.getOptionValue( surfacing_hmmpfam.OUTPUT_FILE_OPTION ) );
685 SurfacingUtil.checkForOutputFileWriteability( output_file );
687 File cutoff_scores_file = null;
688 Map<String, String> individual_domain_score_cutoffs = null;
689 if ( cla.isOptionSet( surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION ) ) {
690 if ( !cla.isOptionValueSet( surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION ) ) {
691 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
692 "no value for individual domain score cutoffs file: -"
693 + surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION + "=<file>" );
695 cutoff_scores_file = new File( cla.getOptionValue( surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION ) );
696 final String error = ForesterUtil.isReadableFile( cutoff_scores_file );
697 if ( !ForesterUtil.isEmpty( error ) ) {
698 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
699 "cannot read individual domain score cutoffs file: " + error );
702 final BasicTable<String> scores_table = BasicTableParser.parse( cutoff_scores_file, " " );
703 individual_domain_score_cutoffs = scores_table.getColumnsAsMap( 0, 1 );
705 catch ( final IOException e ) {
706 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
707 "cannot read from individual domain score cutoffs file: " + e );
710 BinaryDomainCombination.DomainCombinationType dc_type = BinaryDomainCombination.DomainCombinationType.BASIC;
711 if ( cla.isOptionSet( surfacing_hmmpfam.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS ) ) {
712 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED;
714 if ( cla.isOptionSet( surfacing_hmmpfam.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY ) ) {
715 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT;
718 if ( cla.isOptionSet( surfacing_hmmpfam.OUTPUT_DIR_OPTION ) ) {
719 if ( !cla.isOptionValueSet( surfacing_hmmpfam.OUTPUT_DIR_OPTION ) ) {
720 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for output directory: -"
721 + surfacing_hmmpfam.OUTPUT_DIR_OPTION + "=<dir>" );
723 out_dir = new File( cla.getOptionValue( surfacing_hmmpfam.OUTPUT_DIR_OPTION ) );
724 if ( out_dir.exists() && ( out_dir.listFiles().length > 0 ) ) {
725 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "\"" + out_dir
726 + "\" aready exists and is not empty" );
728 if ( !out_dir.exists() ) {
729 final boolean success = out_dir.mkdir();
730 if ( !success || !out_dir.exists() ) {
731 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "failed to create \"" + out_dir + "\"" );
734 if ( !out_dir.canWrite() ) {
735 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot write to \"" + out_dir + "\"" );
738 File positive_filter_file = null;
739 File negative_filter_file = null;
740 File negative_domains_filter_file = null;
741 if ( cla.isOptionSet( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION )
742 && cla.isOptionSet( surfacing_hmmpfam.FILTER_POSITIVE_OPTION ) ) {
743 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
744 "attempt to use both negative and positive protein filter" );
746 if ( cla.isOptionSet( surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION )
747 && ( cla.isOptionSet( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION ) || cla
748 .isOptionSet( surfacing_hmmpfam.FILTER_POSITIVE_OPTION ) ) ) {
750 .fatalError( surfacing_hmmpfam.PRG_NAME,
751 "attempt to use both negative or positive protein filter together wirh a negative domains filter" );
753 if ( cla.isOptionSet( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION ) ) {
754 if ( !cla.isOptionValueSet( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION ) ) {
755 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for negative filter: -"
756 + surfacing_hmmpfam.FILTER_NEGATIVE_OPTION + "=<file>" );
758 negative_filter_file = new File( cla.getOptionValue( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION ) );
759 final String msg = ForesterUtil.isReadableFile( negative_filter_file );
760 if ( !ForesterUtil.isEmpty( msg ) ) {
761 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "can not read from \"" + negative_filter_file
765 else if ( cla.isOptionSet( surfacing_hmmpfam.FILTER_POSITIVE_OPTION ) ) {
766 if ( !cla.isOptionValueSet( surfacing_hmmpfam.FILTER_POSITIVE_OPTION ) ) {
767 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for positive filter: -"
768 + surfacing_hmmpfam.FILTER_POSITIVE_OPTION + "=<file>" );
770 positive_filter_file = new File( cla.getOptionValue( surfacing_hmmpfam.FILTER_POSITIVE_OPTION ) );
771 final String msg = ForesterUtil.isReadableFile( positive_filter_file );
772 if ( !ForesterUtil.isEmpty( msg ) ) {
773 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "can not read from \"" + positive_filter_file
777 else if ( cla.isOptionSet( surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
778 if ( !cla.isOptionValueSet( surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
779 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for negative domains filter: -"
780 + surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION + "=<file>" );
782 negative_domains_filter_file = new File( cla.getOptionValue( surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION ) );
783 final String msg = ForesterUtil.isReadableFile( negative_domains_filter_file );
784 if ( !ForesterUtil.isEmpty( msg ) ) {
785 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "can not read from \""
786 + negative_domains_filter_file + "\": " + msg );
789 final List<String> plus_minus_analysis_high_copy_base_species = new ArrayList<String>();
790 final List<String> plus_minus_analysis_high_copy_target_species = new ArrayList<String>();
791 final List<String> plus_minus_analysis_high_low_copy_species = new ArrayList<String>();
792 final List<Object> plus_minus_analysis_numbers = new ArrayList<Object>();
793 processPlusMinusAnalysisOption( cla,
794 plus_minus_analysis_high_copy_base_species,
795 plus_minus_analysis_high_copy_target_species,
796 plus_minus_analysis_high_low_copy_species,
797 plus_minus_analysis_numbers );
798 File input_files_file = null;
799 String[] input_file_names_from_file = null;
800 if ( cla.isOptionSet( surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION ) ) {
801 if ( !cla.isOptionValueSet( surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION ) ) {
802 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for input files file: -"
803 + surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION + "=<file>" );
805 input_files_file = new File( cla.getOptionValue( surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION ) );
806 final String msg = ForesterUtil.isReadableFile( input_files_file );
807 if ( !ForesterUtil.isEmpty( msg ) ) {
808 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "can not read from \"" + input_files_file + "\": "
812 input_file_names_from_file = ForesterUtil.file2array( input_files_file );
814 catch ( final IOException e ) {
815 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "failed to read from \"" + input_files_file
819 if ( ( cla.getNumberOfNames() < 1 )
820 && ( ( input_file_names_from_file == null ) || ( input_file_names_from_file.length < 1 ) ) ) {
821 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
822 "No hmmpfam output file indicated is input: use comand line directly or "
823 + surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION + "=<file>" );
825 DomainSimilarity.DomainSimilarityScoring scoring = SCORING_DEFAULT;
826 if ( cla.isOptionSet( surfacing_hmmpfam.SCORING_OPTION ) ) {
827 if ( !cla.isOptionValueSet( surfacing_hmmpfam.SCORING_OPTION ) ) {
828 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
829 "no value for scoring method for domain combinations similarity calculation: -"
830 + surfacing_hmmpfam.SCORING_OPTION + "=<"
831 + surfacing_hmmpfam.SCORING_DOMAIN_COUNT_BASED + "|"
832 + surfacing_hmmpfam.SCORING_PROTEIN_COUNT_BASED + "|"
833 + surfacing_hmmpfam.SCORING_COMBINATION_BASED + ">\"" );
835 final String scoring_str = cla.getOptionValue( surfacing_hmmpfam.SCORING_OPTION );
836 if ( scoring_str.equals( surfacing_hmmpfam.SCORING_DOMAIN_COUNT_BASED ) ) {
837 scoring = DomainSimilarity.DomainSimilarityScoring.DOMAINS;
839 else if ( scoring_str.equals( surfacing_hmmpfam.SCORING_COMBINATION_BASED ) ) {
840 scoring = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
842 else if ( scoring_str.equals( surfacing_hmmpfam.SCORING_PROTEIN_COUNT_BASED ) ) {
843 scoring = DomainSimilarity.DomainSimilarityScoring.PROTEINS;
846 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + scoring_str
847 + "\" for scoring method for domain combinations similarity calculation: \"-"
848 + surfacing_hmmpfam.SCORING_OPTION + "=<" + surfacing_hmmpfam.SCORING_DOMAIN_COUNT_BASED + "|"
849 + surfacing_hmmpfam.SCORING_PROTEIN_COUNT_BASED + "|"
850 + surfacing_hmmpfam.SCORING_COMBINATION_BASED + ">\"" );
853 boolean sort_by_species_count_first = false;
854 if ( cla.isOptionSet( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION ) ) {
855 sort_by_species_count_first = true;
857 boolean species_matrix = false;
858 if ( cla.isOptionSet( surfacing_hmmpfam.SPECIES_MATRIX_OPTION ) ) {
859 species_matrix = true;
861 boolean output_protein_lists_for_all_domains = false;
862 if ( cla.isOptionSet( surfacing_hmmpfam.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS ) ) {
863 output_protein_lists_for_all_domains = true;
865 Detailedness detailedness = DETAILEDNESS_DEFAULT;
866 if ( cla.isOptionSet( surfacing_hmmpfam.DETAILEDNESS_OPTION ) ) {
867 if ( !cla.isOptionValueSet( surfacing_hmmpfam.DETAILEDNESS_OPTION ) ) {
868 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for -"
869 + surfacing_hmmpfam.DETAILEDNESS_OPTION + "=<" + surfacing_hmmpfam.DETAILEDNESS_BASIC + "|"
870 + surfacing_hmmpfam.DETAILEDNESS_LIST_IDS + "|" + surfacing_hmmpfam.DETAILEDNESS_PUNCTILIOUS
873 final String detness = cla.getOptionValue( surfacing_hmmpfam.DETAILEDNESS_OPTION ).toLowerCase();
874 if ( detness.equals( surfacing_hmmpfam.DETAILEDNESS_BASIC ) ) {
875 detailedness = DomainSimilarityCalculator.Detailedness.BASIC;
877 else if ( detness.equals( surfacing_hmmpfam.DETAILEDNESS_LIST_IDS ) ) {
878 detailedness = DomainSimilarityCalculator.Detailedness.LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES;
880 else if ( detness.equals( surfacing_hmmpfam.DETAILEDNESS_PUNCTILIOUS ) ) {
881 detailedness = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
884 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + detness
885 + "\" for detailedness: \"-" + surfacing_hmmpfam.DETAILEDNESS_OPTION + "=<"
886 + surfacing_hmmpfam.DETAILEDNESS_BASIC + "|" + surfacing_hmmpfam.DETAILEDNESS_LIST_IDS + "|"
887 + surfacing_hmmpfam.DETAILEDNESS_PUNCTILIOUS + ">\"" );
890 String automated_pairwise_comparison_suffix = null;
891 boolean perform_pwc = false;
892 boolean write_pwc_files = false;
893 if ( cla.isOptionSet( surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
895 if ( !cla.isOptionValueSet( surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
896 write_pwc_files = false;
899 write_pwc_files = true;
900 automated_pairwise_comparison_suffix = "_"
901 + cla.getOptionValue( surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
904 String query_domain_ids = null;
905 if ( cla.isOptionSet( surfacing_hmmpfam.SEQ_EXTRACT_OPTION ) ) {
906 if ( !cla.isOptionValueSet( surfacing_hmmpfam.SEQ_EXTRACT_OPTION ) ) {
908 .fatalError( surfacing_hmmpfam.PRG_NAME,
909 "no domain ids given for sequences with given domains to be extracted : -"
910 + surfacing_hmmpfam.SEQ_EXTRACT_OPTION
911 + "=<ordered domain sequences, domain ids separated by '~', sequences separated by '#'>" );
913 query_domain_ids = cla.getOptionValue( surfacing_hmmpfam.SEQ_EXTRACT_OPTION );
915 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field = DOMAIN_SORT_FILD_DEFAULT;
916 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field_for_automated_pwc = DOMAIN_SORT_FILD_DEFAULT;
917 if ( cla.isOptionSet( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
918 if ( !cla.isOptionValueSet( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
919 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
920 "no value for domain combinations similarities sorting: -"
921 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION + "=<"
922 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
923 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MAX + "|"
924 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MIN + "|"
925 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MEAN + "|"
926 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_DIFF + "|"
927 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
928 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|"
929 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|"
930 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SD + ">\"" );
932 final String sort_str = cla.getOptionValue( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION ).toLowerCase();
933 if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ALPHA ) ) {
934 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
935 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
937 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MAX ) ) {
938 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX;
939 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
941 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MIN ) ) {
942 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MIN;
943 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
945 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MEAN ) ) {
946 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MEAN;
947 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MEAN;
949 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT ) ) {
950 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SPECIES_COUNT;
951 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
953 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SD ) ) {
954 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SD;
955 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
957 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_DIFF ) ) {
958 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
959 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
961 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF ) ) {
962 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
963 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
965 else if ( sort_str.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF ) ) {
966 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
967 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
970 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + sort_str
971 + "\" for domain combinations similarities sorting: \"-"
972 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION + "=<"
973 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
974 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MAX + "|"
975 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MIN + "|"
976 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_MEAN + "|"
977 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_DIFF + "|"
978 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
979 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|" + "|"
980 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|"
981 + surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_SD + ">\"" );
984 PrintableDomainSimilarity.PRINT_OPTION domain_similarity_print_option = DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT;
985 if ( cla.isOptionSet( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
986 if ( !cla.isOptionValueSet( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
987 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for print option: -"
988 + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
989 + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
990 + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
992 final String sort = cla.getOptionValue( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION ).toLowerCase();
993 if ( sort.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML ) ) {
994 domain_similarity_print_option = PrintableDomainSimilarity.PRINT_OPTION.HTML;
996 else if ( sort.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML ) ) {
997 // domain_similarity_print_option =
998 // DomainSimilarity.PRINT_OPTION.SIMPLE_HTML;
999 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "simple HTML output not implemented yet :(" );
1001 else if ( sort.equals( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED ) ) {
1002 domain_similarity_print_option = PrintableDomainSimilarity.PRINT_OPTION.SIMPLE_TAB_DELIMITED;
1005 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + sort
1006 + "\" for print option: -" + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML
1007 + "|" + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
1008 + surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
1011 GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder dc_sort_order = DOMAINS_SORT_ORDER_DEFAULT;
1012 if ( cla.isOptionSet( surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION ) ) {
1013 if ( !cla.isOptionValueSet( surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION ) ) {
1014 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for sorting of domain counts: -"
1015 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION + "=<" + surfacing_hmmpfam.DOMAIN_COUNT_SORT_ALPHA
1016 + "|" + surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
1017 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
1018 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
1020 final String sort = cla.getOptionValue( surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION ).toLowerCase();
1021 if ( sort.equals( surfacing_hmmpfam.DOMAIN_COUNT_SORT_ALPHA ) ) {
1022 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
1024 else if ( sort.equals( surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT ) ) {
1025 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_COUNT;
1027 else if ( sort.equals( surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT ) ) {
1028 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_PROTEINS_COUNT;
1030 else if ( sort.equals( surfacing_hmmpfam.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT ) ) {
1031 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.COMBINATIONS_COUNT;
1034 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + sort
1035 + "\" for sorting of domain counts: \"-" + surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION + "=<"
1036 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_ALPHA + "|"
1037 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
1038 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
1039 + surfacing_hmmpfam.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
1042 String[][] input_file_properties = null;
1043 if ( input_file_names_from_file != null ) {
1044 input_file_properties = surfacing_hmmpfam.processInputFileNames( input_file_names_from_file );
1047 input_file_properties = surfacing_hmmpfam.processInputFileNames( cla.getNames() );
1049 final int number_of_genomes = input_file_properties.length;
1050 if ( number_of_genomes < 2 ) {
1051 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot analyze less than two files" );
1053 if ( ( number_of_genomes < 3 ) && perform_pwc ) {
1054 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot use : -"
1055 + surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1056 + "=<suffix> to turn on pairwise analyses with less than three input files" );
1058 checkWriteabilityForPairwiseComparisons( domain_similarity_print_option,
1059 input_file_properties,
1060 automated_pairwise_comparison_suffix,
1062 for( int i = 0; i < number_of_genomes; i++ ) {
1063 File dcc_outfile = new File( input_file_properties[ i ][ 0 ]
1064 + surfacing_hmmpfam.DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX );
1065 if ( out_dir != null ) {
1066 dcc_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + dcc_outfile );
1068 SurfacingUtil.checkForOutputFileWriteability( dcc_outfile );
1070 File pfam_to_go_file = null;
1071 Map<DomainId, List<GoId>> domain_id_to_go_ids_map = null;
1072 int domain_id_to_go_ids_count = 0;
1073 if ( cla.isOptionSet( surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION ) ) {
1074 if ( !cla.isOptionValueSet( surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION ) ) {
1075 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for Pfam to GO mapping file: -"
1076 + surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION + "=<file>" );
1078 pfam_to_go_file = new File( cla.getOptionValue( surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION ) );
1079 final String error = ForesterUtil.isReadableFile( pfam_to_go_file );
1080 if ( !ForesterUtil.isEmpty( error ) ) {
1081 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read Pfam to GO mapping file: " + error );
1084 final PfamToGoParser parser = new PfamToGoParser( pfam_to_go_file );
1085 final List<PfamToGoMapping> pfam_to_go_mappings = parser.parse();
1086 domain_id_to_go_ids_map = SurfacingUtil.createDomainIdToGoIdMap( pfam_to_go_mappings );
1087 if ( parser.getMappingCount() < domain_id_to_go_ids_map.size() ) {
1088 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME,
1089 "parser.getMappingCount() < domain_id_to_go_ids_map.size()" );
1091 domain_id_to_go_ids_count = parser.getMappingCount();
1093 catch ( final IOException e ) {
1094 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read from Pfam to GO mapping file: " + e );
1097 File go_obo_file = null;
1098 List<GoTerm> go_terms = null;
1099 if ( cla.isOptionSet( surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION ) ) {
1100 if ( !cla.isOptionValueSet( surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION ) ) {
1101 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for GO OBO file: -"
1102 + surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION + "=<file>" );
1104 if ( ( domain_id_to_go_ids_map == null ) || ( domain_id_to_go_ids_map.size() < 1 ) ) {
1105 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot use GO OBO file (-"
1106 + surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION + "=<file>) without Pfam to GO mapping file ("
1107 + surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1109 go_obo_file = new File( cla.getOptionValue( surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION ) );
1110 final String error = ForesterUtil.isReadableFile( go_obo_file );
1111 if ( !ForesterUtil.isEmpty( error ) ) {
1112 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read GO OBO file: " + error );
1115 final OBOparser parser = new OBOparser( go_obo_file, OBOparser.ReturnType.BASIC_GO_TERM );
1116 go_terms = parser.parse();
1117 if ( parser.getGoTermCount() != go_terms.size() ) {
1118 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME,
1119 "parser.getGoTermCount() != go_terms.size()" );
1122 catch ( final IOException e ) {
1123 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
1124 "cannot read from GO OBO file: " + e.getLocalizedMessage() );
1127 Map<GoId, GoTerm> go_id_to_term_map = null;
1128 if ( ( ( domain_id_to_go_ids_map != null ) && ( domain_id_to_go_ids_map.size() > 0 ) )
1129 && ( ( go_terms != null ) && ( go_terms.size() > 0 ) ) ) {
1130 go_id_to_term_map = GoUtils.createGoIdToGoTermMap( go_terms );
1132 GoNameSpace go_namespace_limit = null;
1133 if ( cla.isOptionSet( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION ) ) {
1134 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1135 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot use GO namespace limit (-"
1136 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION
1137 + "=<namespace>) without Pfam to GO mapping file ("
1138 + surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION + "=<file>) and GO OBO file (-"
1139 + surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1141 if ( !cla.isOptionValueSet( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION ) ) {
1142 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for GO namespace limit: \"-"
1143 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION + "=<"
1144 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
1145 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
1146 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
1148 final String go_namespace_limit_str = cla.getOptionValue( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION )
1150 if ( go_namespace_limit_str.equals( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION ) ) {
1151 go_namespace_limit = GoNameSpace.createMolecularFunction();
1153 else if ( go_namespace_limit_str.equals( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS ) ) {
1154 go_namespace_limit = GoNameSpace.createBiologicalProcess();
1156 else if ( go_namespace_limit_str.equals( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT ) ) {
1157 go_namespace_limit = GoNameSpace.createCellularComponent();
1160 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "unknown value \"" + go_namespace_limit_str
1161 + "\" for GO namespace limit: \"-" + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION + "=<"
1162 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
1163 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
1164 + surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
1167 if ( ( domain_similarity_sort_field == DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE )
1168 && ( number_of_genomes > 2 ) ) {
1169 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
1171 boolean jacknifed_distances = false;
1172 int jacknife_resamplings = JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT;
1173 double jacknife_ratio = JACKNIFE_RATIO_DEFAULT;
1174 long random_seed = JACKNIFE_RANDOM_SEED_DEFAULT;
1175 if ( cla.isOptionSet( surfacing_hmmpfam.JACKNIFE_OPTION ) ) {
1176 if ( ( number_of_genomes < 3 ) || !perform_pwc ) {
1177 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot use jacknife resampling analysis (-"
1178 + surfacing_hmmpfam.JACKNIFE_OPTION + "[=<number of resamplings>]) without pairwise analyses ("
1179 + surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1180 + "=<suffix for pairwise comparison output files>)" );
1182 jacknifed_distances = true;
1183 if ( cla.isOptionHasAValue( surfacing_hmmpfam.JACKNIFE_OPTION ) ) {
1185 jacknife_resamplings = cla.getOptionValueAsInt( surfacing_hmmpfam.JACKNIFE_OPTION );
1187 catch ( final IOException e ) {
1188 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "illegal format for number of resamplings" );
1190 if ( jacknife_resamplings < 2 ) {
1191 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "attempt to use less than 2 resamplings" );
1194 if ( cla.isOptionSet( surfacing_hmmpfam.JACKNIFE_RATIO_OPTION )
1195 && cla.isOptionHasAValue( surfacing_hmmpfam.JACKNIFE_RATIO_OPTION ) ) {
1197 jacknife_ratio = cla.getOptionValueAsDouble( surfacing_hmmpfam.JACKNIFE_RATIO_OPTION );
1199 catch ( final IOException e ) {
1200 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "illegal format for jacknife ratio" );
1202 if ( ( jacknife_ratio <= 0.0 ) || ( jacknife_ratio >= 1.0 ) ) {
1203 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
1204 "attempt to use illegal value for jacknife ratio: " + jacknife_ratio );
1207 if ( cla.isOptionSet( surfacing_hmmpfam.JACKNIFE_RANDOM_SEED_OPTION )
1208 && cla.isOptionHasAValue( surfacing_hmmpfam.JACKNIFE_RANDOM_SEED_OPTION ) ) {
1210 random_seed = cla.getOptionValueAsLong( surfacing_hmmpfam.JACKNIFE_RANDOM_SEED_OPTION );
1212 catch ( final IOException e ) {
1213 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "illegal format for random generator seed" );
1217 // boolean infer_species_trees = false;
1218 // if ( cla.isOptionSet( surfacing.INFER_SPECIES_TREES_OPTION ) ) {
1219 // if ( ( output_file == null ) || ( number_of_genomes < 3 )
1220 // || ForesterUtil.isEmpty( automated_pairwise_comparison_suffix ) ) {
1221 // ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot infer species trees (-"
1222 // + surfacing.INFER_SPECIES_TREES_OPTION + " without pairwise analyses ("
1223 // + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1224 // + "=<suffix for pairwise comparison output files>)" );
1226 // infer_species_trees = true;
1228 File[] intree_files = null;
1229 Phylogeny[] intrees = null;
1230 if ( cla.isOptionSet( surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION ) ) {
1231 // TODO FIXME if jacknife.... maybe not
1232 if ( number_of_genomes < 3 ) {
1233 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
1234 "cannot infer gains and losses on input species trees (-"
1235 + surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION
1236 + " without pairwise analyses ("
1237 + surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1238 + "=<suffix for pairwise comparison output files>)" );
1240 if ( !cla.isOptionValueSet( surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION ) ) {
1241 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for input tree: -"
1242 + surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION + "=<tree file in phyloXML format>" );
1244 final String intrees_str = cla.getOptionValue( surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION );
1245 if ( intrees_str.indexOf( "#" ) > 0 ) {
1246 final String[] intrees_strs = intrees_str.split( "#" );
1247 intree_files = new File[ intrees_strs.length ];
1249 for( final String s : intrees_strs ) {
1250 intree_files[ i++ ] = new File( s.trim() );
1254 intree_files = new File[ 1 ];
1255 intree_files[ 0 ] = new File( intrees_str );
1257 intrees = getIntrees( intree_files, number_of_genomes, input_file_properties );
1259 long random_number_seed_for_fitch_parsimony = 0l;
1260 boolean radomize_fitch_parsimony = false;
1261 if ( cla.isOptionSet( surfacing_hmmpfam.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
1262 if ( !cla.isOptionValueSet( surfacing_hmmpfam.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
1263 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for random number seed: -"
1264 + surfacing_hmmpfam.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION + "=<seed>" );
1267 random_number_seed_for_fitch_parsimony = cla
1268 .getOptionValueAsLong( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
1270 catch ( final IOException e ) {
1271 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage() );
1273 radomize_fitch_parsimony = true;
1275 SortedSet<DomainId> filter = null;
1276 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1277 || ( negative_domains_filter_file != null ) ) {
1278 filter = new TreeSet<DomainId>();
1279 if ( positive_filter_file != null ) {
1280 processFilter( positive_filter_file, filter );
1282 else if ( negative_filter_file != null ) {
1283 processFilter( negative_filter_file, filter );
1285 else if ( negative_domains_filter_file != null ) {
1286 processFilter( negative_domains_filter_file, filter );
1289 Map<DomainId, Set<String>>[] domain_id_to_secondary_features_maps = null;
1290 File[] secondary_features_map_files = null;
1291 final File domain_lengths_analysis_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1292 + DOMAIN_LENGTHS_ANALYSIS_SUFFIX );
1293 if ( PERFORM_DOMAIN_LENGTH_ANALYSIS ) {
1294 SurfacingUtil.checkForOutputFileWriteability( domain_lengths_analysis_outfile );
1296 if ( cla.isOptionSet( surfacing_hmmpfam.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
1297 if ( !cla.isOptionValueSet( surfacing_hmmpfam.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
1298 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for secondary features map file: -"
1299 + surfacing_hmmpfam.SECONDARY_FEATURES_PARSIMONY_MAP_FILE + "=<file>" );
1301 final String[] secondary_features_map_files_strs = cla
1302 .getOptionValue( surfacing_hmmpfam.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ).split( "#" );
1303 secondary_features_map_files = new File[ secondary_features_map_files_strs.length ];
1304 domain_id_to_secondary_features_maps = new Map[ secondary_features_map_files_strs.length ];
1306 for( final String secondary_features_map_files_str : secondary_features_map_files_strs ) {
1307 secondary_features_map_files[ i ] = new File( secondary_features_map_files_str );
1308 final String error = ForesterUtil.isReadableFile( secondary_features_map_files[ i ] );
1309 if ( !ForesterUtil.isEmpty( error ) ) {
1310 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read secondary features map file: "
1314 domain_id_to_secondary_features_maps[ i ] = SurfacingUtil
1315 .createDomainIdToSecondaryFeaturesMap( secondary_features_map_files[ i ] );
1317 catch ( final IOException e ) {
1318 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "cannot read secondary features map file: "
1321 catch ( final Exception e ) {
1322 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "problem with contents of features map file ["
1323 + secondary_features_map_files[ i ] + "]: " + e.getMessage() );
1328 if ( out_dir == null ) {
1329 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no output directory indicated (-"
1330 + surfacing_hmmpfam.OUTPUT_DIR_OPTION + "=<dir>)" );
1332 if ( output_file == null ) {
1333 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no name for (main) output file indicated (-"
1334 + surfacing_hmmpfam.OUTPUT_FILE_OPTION + "=<file>)" );
1336 if ( ( domain_id_to_go_ids_map == null ) || domain_id_to_go_ids_map.isEmpty() ) {
1337 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
1338 "no (acceptable) Pfam to GO id mapping file provided ('pfam2go file') (-"
1339 + surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1341 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1342 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
1343 "no (acceptable) go id to term mapping file provided ('GO OBO file') (-"
1344 + surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1346 boolean display_histograms = false;
1347 if ( cla.isOptionSet( surfacing_hmmpfam.DISPLAY_M_HISTOGRAMS_OPTION ) ) {
1348 display_histograms = true;
1350 System.out.println( "Output directory : " + out_dir );
1351 if ( input_file_names_from_file != null ) {
1352 System.out.println( "Input files names from : " + input_files_file + " ["
1353 + input_file_names_from_file.length + " input files]" );
1354 html_desc.append( "<tr><td>Input files names from:</td><td>" + input_files_file + " ["
1355 + input_file_names_from_file.length + " input files]</td></tr>" + nl );
1357 if ( positive_filter_file != null ) {
1358 final int filter_size = filter.size();
1359 System.out.println( "Positive protein filter : " + positive_filter_file + " [" + filter_size
1361 html_desc.append( "<tr><td>Positive protein filter:</td><td>" + positive_filter_file + " [" + filter_size
1362 + " domain ids]</td></tr>" + nl );
1364 if ( negative_filter_file != null ) {
1365 final int filter_size = filter.size();
1366 System.out.println( "Negative protein filter : " + negative_filter_file + " [" + filter_size
1368 html_desc.append( "<tr><td>Negative protein filter:</td><td>" + negative_filter_file + " [" + filter_size
1369 + " domain ids]</td></tr>" + nl );
1371 if ( negative_domains_filter_file != null ) {
1372 final int filter_size = filter.size();
1373 System.out.println( "Negative domain filter : " + negative_domains_filter_file + " [" + filter_size
1375 html_desc.append( "<tr><td>Negative domain filter:</td><td>" + negative_domains_filter_file + " ["
1376 + filter_size + " domain ids]</td></tr>" + nl );
1378 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
1380 for( final String s : plus_minus_analysis_high_copy_base_species ) {
1381 plus0 += "+" + s + " ";
1384 for( final String s : plus_minus_analysis_high_copy_target_species ) {
1385 plus1 += "*" + s + " ";
1388 for( final String s : plus_minus_analysis_high_low_copy_species ) {
1389 minus += "-" + s + " ";
1391 System.out.println( "Plus-minus analysis : " + plus1 + "&& " + plus0 + "&& " + minus );
1392 html_desc.append( "<tr><td>Plus-minus analysis:</td><td>" + plus1 + "&& " + plus0 + "&& " + minus
1393 + "</td></tr>" + nl );
1395 if ( cutoff_scores_file != null ) {
1396 System.out.println( "Cutoff scores file : " + cutoff_scores_file );
1397 html_desc.append( "<tr><td>Cutoff scores file:</td><td>" + cutoff_scores_file + "</td></tr>" + nl );
1399 if ( e_value_max >= 0.0 ) {
1400 System.out.println( "E-value maximum (inclusive) : " + e_value_max );
1401 html_desc.append( "<tr><td>E-value maximum (inclusive):</td><td>" + e_value_max + "</td></tr>" + nl );
1403 System.out.println( "Ignore DUFs : " + ignore_dufs );
1404 if ( ignore_virus_like_ids ) {
1405 System.out.println( "Ignore virus like ids : " + ignore_virus_like_ids );
1406 html_desc.append( "<tr><td>Ignore virus, phage, transposition related ids:</td><td>"
1407 + ignore_virus_like_ids + "</td></tr>" + nl );
1409 html_desc.append( "<tr><td>Ignore DUFs:</td><td>" + ignore_dufs + "</td></tr>" + nl );
1410 if ( max_allowed_overlap != surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1411 System.out.println( "Max allowed domain overlap : " + max_allowed_overlap );
1412 html_desc.append( "<tr><td>Max allowed domain overlap:</td><td>" + max_allowed_overlap + "</td></tr>" + nl );
1414 if ( no_engulfing_overlaps ) {
1415 System.out.println( "Ignore engulfed domains : " + no_engulfing_overlaps );
1416 html_desc.append( "<tr><td>Ignore (lower confidence) engulfed domains:</td><td>" + no_engulfing_overlaps
1417 + "</td></tr>" + nl );
1419 System.out.println( "Ignore singlet domains : " + ignore_domains_without_combs_in_all_spec );
1421 .append( "<tr><td>Ignore singlet domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1422 + ignore_domains_without_combs_in_all_spec + "</td></tr>" + nl );
1423 System.out.println( "Ignore species specific doms: " + ignore_species_specific_domains );
1425 .append( "<tr><td>Ignore species specific domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1426 + ignore_species_specific_domains + "</td></tr>" + nl );
1427 System.out.println( "Ignore combination with self: " + ignore_combination_with_same );
1428 html_desc.append( "<tr><td>Ignore combination with self for domain combination similarity analyses:</td><td>"
1429 + ignore_combination_with_same + "</td></tr>" + nl );
1431 System.out.println( "Consider directedness : "
1432 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) );
1433 html_desc.append( "<tr><td>Consider directedness of binary domain combinations:</td><td>"
1434 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) + "</td></tr>" + nl );
1435 if ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) {
1436 System.out.println( "Consider adjacency : "
1437 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) );
1438 html_desc.append( "<tr><td>Consider djacency of binary domain combinations:</td><td>"
1439 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) + "</td></tr>"
1442 System.out.print( "Domain counts sort order : " );
1443 switch ( dc_sort_order ) {
1444 case ALPHABETICAL_KEY_ID:
1445 System.out.println( "alphabetical" );
1447 case KEY_DOMAIN_COUNT:
1448 System.out.println( "domain count" );
1450 case KEY_DOMAIN_PROTEINS_COUNT:
1451 System.out.println( "domain proteins count" );
1453 case COMBINATIONS_COUNT:
1454 System.out.println( "domain combinations count" );
1457 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME, "unknown value for dc sort order" );
1459 if ( domain_id_to_go_ids_map != null ) {
1460 System.out.println( "Pfam to GO mappings from : " + pfam_to_go_file + " [" + domain_id_to_go_ids_count
1462 html_desc.append( "<tr><td>Pfam to GO mappings from:</td><td>" + pfam_to_go_file + " ["
1463 + domain_id_to_go_ids_count + " mappings]" + "</td></tr>" + nl );
1465 if ( go_terms != null ) {
1466 System.out.println( "GO terms from : " + go_obo_file + " [" + go_terms.size() + " terms]" );
1467 html_desc.append( "<tr><td>GO terms from:</td><td>" + go_obo_file + " [" + go_terms.size() + " terms]"
1468 + "</td></tr>" + nl );
1470 if ( go_namespace_limit != null ) {
1471 System.out.println( "Limit GO terms to : " + go_namespace_limit.toString() );
1472 html_desc.append( "<tr><td>Limit GO terms to</td><td>" + go_namespace_limit + "</td></tr>" + nl );
1474 if ( perform_pwc ) {
1475 System.out.println( "Suffix for PWC files : " + automated_pairwise_comparison_suffix );
1476 html_desc.append( "<tr><td>Suffix for PWC files</td><td>" + automated_pairwise_comparison_suffix
1477 + "</td></tr>" + nl );
1479 if ( out_dir != null ) {
1480 System.out.println( "Output directory : " + out_dir );
1482 if ( query_domain_ids != null ) {
1483 System.out.println( "Query domains (ordered) : " + query_domain_ids );
1484 html_desc.append( "<tr><td></td><td>" + query_domain_ids + "</td></tr>" + nl );
1486 System.out.println( "Write similarities to : " + output_file );
1487 System.out.print( " Scoring method : " );
1488 html_desc.append( "<tr><td>Scoring method:</td><td>" );
1489 switch ( scoring ) {
1491 System.out.println( "domain combinations based" );
1492 html_desc.append( "domain combinations based" + "</td></tr>" + nl );
1495 System.out.println( "domain counts based" );
1496 html_desc.append( "domain counts based" + "</td></tr>" + nl );
1499 System.out.println( "domain proteins counts based" );
1500 html_desc.append( "domain proteins counts based" + "</td></tr>" + nl );
1503 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME, "unknown value for sorting for scoring" );
1505 System.out.print( " Sort by : " );
1506 html_desc.append( "<tr><td>Sort by:</td><td>" );
1507 switch ( domain_similarity_sort_field ) {
1509 System.out.print( "score minimum" );
1510 html_desc.append( "score minimum" );
1513 System.out.print( "score maximum" );
1514 html_desc.append( "score maximum" );
1517 System.out.print( "score mean" );
1518 html_desc.append( "score mean" );
1521 System.out.print( "score standard deviation" );
1522 html_desc.append( "score standard deviation" );
1525 System.out.print( "species number" );
1526 html_desc.append( "species number" );
1529 System.out.print( "alphabetical domain identifier" );
1530 html_desc.append( "alphabetical domain identifier" );
1532 case MAX_DIFFERENCE:
1533 System.out.print( "(maximal) difference" );
1534 html_desc.append( "(maximal) difference" );
1536 case ABS_MAX_COUNTS_DIFFERENCE:
1537 System.out.print( "absolute (maximal) counts difference" );
1538 html_desc.append( "absolute (maximal) counts difference" );
1540 case MAX_COUNTS_DIFFERENCE:
1541 System.out.print( "(maximal) counts difference" );
1542 html_desc.append( "(maximal) counts difference" );
1545 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME,
1546 "unknown value for sorting for similarities" );
1548 if ( sort_by_species_count_first ) {
1549 System.out.println( " (sort by species count first)" );
1550 html_desc.append( " (sort by species count first)" );
1553 System.out.println();
1555 html_desc.append( "</td></tr>" + nl );
1556 System.out.print( " Detailedness : " );
1557 switch ( detailedness ) {
1559 System.out.println( "basic" );
1561 case LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES:
1562 System.out.println( "list combining domains for each species" );
1565 System.out.println( "punctilious" );
1568 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME,
1569 "unknown value for sorting for detailedness" );
1571 System.out.print( " Print option : " );
1572 switch ( domain_similarity_print_option ) {
1574 System.out.println( "HTML" );
1576 case SIMPLE_TAB_DELIMITED:
1577 System.out.println( "simple tab delimited" );
1580 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME, "unknown value for print option" );
1582 System.out.print( " Species matrix : " + species_matrix );
1583 System.out.println();
1584 if ( perform_pwc ) {
1585 System.out.println( "Pairwise comparisons: " );
1586 html_desc.append( "<tr><td>Pairwise comparisons:</td><td></td></tr>" );
1587 System.out.print( " Sort by : " );
1588 html_desc.append( "<tr><td>Sort by:</td><td>" );
1589 switch ( domain_similarity_sort_field_for_automated_pwc ) {
1591 System.out.print( "score mean" );
1592 html_desc.append( "score mean" );
1595 System.out.print( "alphabetical domain identifier" );
1596 html_desc.append( "alphabetical domain identifier" );
1598 case MAX_DIFFERENCE:
1599 System.out.print( "difference" );
1600 html_desc.append( "difference" );
1602 case ABS_MAX_COUNTS_DIFFERENCE:
1603 System.out.print( "absolute counts difference" );
1604 html_desc.append( "absolute counts difference" );
1606 case MAX_COUNTS_DIFFERENCE:
1607 System.out.print( "counts difference" );
1608 html_desc.append( "counts difference" );
1611 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME,
1612 "unknown value for sorting for similarities" );
1614 System.out.println();
1615 html_desc.append( "</td></tr>" + nl );
1616 if ( jacknifed_distances ) {
1617 html_desc.append( "<tr><td>Jacknife:</td><td>" + jacknife_resamplings + " resamplings</td></tr>" + nl );
1618 html_desc.append( "<tr><td>Jacknife ratio:</td><td>" + ForesterUtil.round( jacknife_ratio, 2 )
1619 + "</td></tr>" + nl );
1620 html_desc.append( "<tr><td>Jacknife random number seed:</td><td>" + random_seed + "</td></tr>" + nl );
1621 System.out.println( " Jacknife : " + jacknife_resamplings + " resamplings" );
1622 System.out.println( " Ratio : " + ForesterUtil.round( jacknife_ratio, 2 ) );
1623 System.out.println( " Random number seed : " + random_seed );
1625 // if ( infer_species_trees ) {
1626 // html_desc.append( "<tr><td>Infer species trees:</td><td>true</td></tr>" + nl );
1627 // System.out.println( " Infer species trees : true" );
1629 if ( ( intrees != null ) && ( intrees.length > 0 ) ) {
1630 for( final File intree_file : intree_files ) {
1631 html_desc.append( "<tr><td>Intree for gain/loss parsimony analysis:</td><td>" + intree_file
1632 + "</td></tr>" + nl );
1633 System.out.println( " Intree for gain/loss pars.: " + intree_file );
1636 if ( radomize_fitch_parsimony ) {
1637 html_desc.append( "<tr><td> Random number seed for Fitch parsimony analysis:</td><td>"
1638 + random_number_seed_for_fitch_parsimony + "</td></tr>" + nl );
1639 System.out.println( " Random number seed : " + random_number_seed_for_fitch_parsimony );
1641 if ( ( domain_id_to_secondary_features_maps != null ) && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
1642 for( int i = 0; i < secondary_features_map_files.length; i++ ) {
1643 html_desc.append( "<tr><td>Secondary features map file:</td><td>"
1644 + secondary_features_map_files[ i ] + "</td></tr>" + nl );
1645 System.out.println( "Secondary features map file : " + secondary_features_map_files[ i ]
1646 + " [mappings for " + domain_id_to_secondary_features_maps[ i ].size() + " domain ids]" );
1648 System.out.println();
1649 System.out.println( "Domain ids to secondary features map:" );
1650 for( final DomainId domain_id : domain_id_to_secondary_features_maps[ i ].keySet() ) {
1651 System.out.print( domain_id.getId() );
1652 System.out.print( " => " );
1653 for( final String sec : domain_id_to_secondary_features_maps[ i ].get( domain_id ) ) {
1654 System.out.print( sec );
1655 System.out.print( " " );
1657 System.out.println();
1662 } // if ( perform_pwc ) {
1663 System.out.println();
1664 html_desc.append( "<tr><td>Command line:</td><td>" + cla.getCommandLineArgsAsString() + "</td></tr>" + nl );
1665 System.out.println( "Command line : " + cla.getCommandLineArgsAsString() );
1666 BufferedWriter[] query_domains_writer_ary = null;
1667 List<DomainId>[] query_domain_ids_array = null;
1668 if ( query_domain_ids != null ) {
1669 final String[] query_domain_ids_str_array = query_domain_ids.split( "#" );
1670 query_domain_ids_array = new ArrayList[ query_domain_ids_str_array.length ];
1671 query_domains_writer_ary = new BufferedWriter[ query_domain_ids_str_array.length ];
1672 for( int i = 0; i < query_domain_ids_str_array.length; i++ ) {
1673 String query_domain_ids_str = query_domain_ids_str_array[ i ];
1674 final String[] query_domain_ids_str_ary = query_domain_ids_str.split( "~" );
1675 final List<DomainId> query = new ArrayList<DomainId>();
1676 for( final String element : query_domain_ids_str_ary ) {
1677 query.add( new DomainId( element ) );
1679 query_domain_ids_array[ i ] = query;
1680 query_domain_ids_str = query_domain_ids_str.replace( '~', '_' );
1681 String protein_names_writer_str = query_domain_ids_str + surfacing_hmmpfam.SEQ_EXTRACT_SUFFIX;
1682 if ( out_dir != null ) {
1683 protein_names_writer_str = out_dir + ForesterUtil.FILE_SEPARATOR + protein_names_writer_str;
1686 query_domains_writer_ary[ i ] = new BufferedWriter( new FileWriter( protein_names_writer_str ) );
1688 catch ( final IOException e ) {
1689 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "Could not open [" + protein_names_writer_str
1690 + "]: " + e.getLocalizedMessage() );
1694 SortedMap<Species, List<Protein>> protein_lists_per_species = null; //This will only be created if neede.
1695 boolean need_protein_lists_per_species = false;
1696 if ( ( plus_minus_analysis_high_copy_base_species.size() > 0 ) || output_protein_lists_for_all_domains ) {
1697 need_protein_lists_per_species = true;
1699 if ( need_protein_lists_per_species ) {
1700 protein_lists_per_species = new TreeMap<Species, List<Protein>>();
1702 final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>( number_of_genomes );
1703 final SortedSet<DomainId> all_domains_encountered = new TreeSet<DomainId>();
1704 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered = new TreeSet<BinaryDomainCombination>();
1705 List<BinaryDomainCombination> all_bin_domain_combinations_gained_fitch = null;
1706 List<BinaryDomainCombination> all_bin_domain_combinations_lost_fitch = null;
1707 if ( ( intrees != null ) && ( intrees.length == 1 ) ) {
1708 all_bin_domain_combinations_gained_fitch = new ArrayList<BinaryDomainCombination>();
1709 all_bin_domain_combinations_lost_fitch = new ArrayList<BinaryDomainCombination>();
1711 final DomainLengthsTable domain_lengths_table = new DomainLengthsTable();
1712 final File per_genome_domain_promiscuity_statistics_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR
1713 + output_file + D_PROMISCUITY_FILE_SUFFIX );
1714 BufferedWriter per_genome_domain_promiscuity_statistics_writer = null;
1716 per_genome_domain_promiscuity_statistics_writer = new BufferedWriter( new FileWriter( per_genome_domain_promiscuity_statistics_file ) );
1717 per_genome_domain_promiscuity_statistics_writer.write( "Species:\t" );
1718 per_genome_domain_promiscuity_statistics_writer.write( "Mean:\t" );
1719 per_genome_domain_promiscuity_statistics_writer.write( "SD:\t" );
1720 per_genome_domain_promiscuity_statistics_writer.write( "Median:\t" );
1721 per_genome_domain_promiscuity_statistics_writer.write( "Min:\t" );
1722 per_genome_domain_promiscuity_statistics_writer.write( "Max:\t" );
1723 per_genome_domain_promiscuity_statistics_writer.write( "N:\t" );
1724 per_genome_domain_promiscuity_statistics_writer.write( "Max Promiscuous Domains:"
1725 + ForesterUtil.LINE_SEPARATOR );
1727 catch ( final IOException e2 ) {
1728 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e2.getMessage() );
1730 for( int i = 0; i < number_of_genomes; ++i ) {
1731 System.out.println();
1732 System.out.println( ( i + 1 ) + "/" + number_of_genomes );
1733 System.out.println( "Processing : " + input_file_properties[ i ][ 0 ] );
1734 HmmPfamOutputParser parser = null;
1735 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1736 || ( negative_domains_filter_file != null ) ) {
1737 HmmPfamOutputParser.FilterType filter_type = HmmPfamOutputParser.FilterType.NONE;
1738 if ( positive_filter_file != null ) {
1739 filter_type = HmmPfamOutputParser.FilterType.POSITIVE_PROTEIN;
1741 else if ( negative_filter_file != null ) {
1742 filter_type = HmmPfamOutputParser.FilterType.NEGATIVE_PROTEIN;
1744 else if ( negative_domains_filter_file != null ) {
1745 filter_type = HmmPfamOutputParser.FilterType.NEGATIVE_DOMAIN;
1747 parser = new HmmPfamOutputParser( new File( input_file_properties[ i ][ 0 ] ),
1748 input_file_properties[ i ][ 1 ],
1749 input_file_properties[ i ][ 2 ],
1754 parser = new HmmPfamOutputParser( new File( input_file_properties[ i ][ 0 ] ),
1755 input_file_properties[ i ][ 1 ],
1756 input_file_properties[ i ][ 2 ] );
1758 if ( e_value_max >= 0.0 ) {
1759 parser.setEValueMaximum( e_value_max );
1761 parser.setIgnoreDufs( ignore_dufs );
1762 parser.setIgnoreVirusLikeIds( ignore_virus_like_ids );
1763 parser.setIgnoreEngulfedDomains( no_engulfing_overlaps );
1764 if ( max_allowed_overlap != surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1765 parser.setMaxAllowedOverlap( max_allowed_overlap );
1767 parser.setReturnType( HmmPfamOutputParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
1768 if ( individual_domain_score_cutoffs != null ) {
1769 parser.setIndividualDomainScoreCutoffs( individual_domain_score_cutoffs );
1771 parser.setAllowNonUniqueQuery( ALLOW_NON_UNIQUE_QUERY_IN_HMMPFAM_OUTPUT_DEFAULT );
1772 parser.setVerbose( VERBOSE_DEFAULT );
1773 List<Protein> protein_list = null;
1775 protein_list = parser.parse();
1777 catch ( final IOException e ) {
1778 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage() );
1780 catch ( final Exception e ) {
1781 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage(), e );
1784 System.out.println( "Domains ignored due to negative domain filter: " );
1785 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToNegativeDomainFilterCountsMap() );
1786 System.out.println( "Domains ignored due to virus like id: " );
1787 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToVirusLikeIdCountsMap() );
1789 System.out.println( "Number of proteins encountered : " + parser.getProteinsEncountered() );
1790 System.out.println( "Number of proteins stored : " + protein_list.size() );
1791 System.out.println( "Domains encountered : " + parser.getDomainsEncountered() );
1792 System.out.println( "Domains stored : " + parser.getDomainsStored() );
1793 System.out.println( "Distinct domains stored : "
1794 + parser.getDomainsStoredSet().size() );
1795 System.out.println( "Domains ignored due to individual score cutoffs: "
1796 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() );
1797 System.out.println( "Domains ignored due to E-value : "
1798 + parser.getDomainsIgnoredDueToEval() );
1799 System.out.println( "Domains ignored due to DUF designation : "
1800 + parser.getDomainsIgnoredDueToDuf() );
1801 if ( ignore_virus_like_ids ) {
1802 System.out.println( "Domains ignored due virus like ids : "
1803 + parser.getDomainsIgnoredDueToVirusLikeIds() );
1805 System.out.println( "Domains ignored due negative domain filter : "
1806 + parser.getDomainsIgnoredDueToNegativeDomainFilter() );
1807 System.out.println( "Domains ignored due to overlap : "
1808 + parser.getDomainsIgnoredDueToOverlap() );
1809 if ( negative_filter_file != null ) {
1810 System.out.println( "Proteins ignored due to negative filter : "
1811 + parser.getProteinsIgnoredDueToFilter() );
1813 if ( positive_filter_file != null ) {
1814 System.out.println( "Proteins ignored due to positive filter : "
1815 + parser.getProteinsIgnoredDueToFilter() );
1817 System.out.println( "Time for processing : " + parser.getTime() + "ms" );
1818 html_desc.append( "<tr><td>" + input_file_properties[ i ][ 0 ] + " [species: "
1819 + input_file_properties[ i ][ 1 ] + "]" + ":</td><td>domains analyzed: "
1820 + parser.getDomainsStored() + "; domains ignored: [ind score cutoffs: "
1821 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() + "] [E-value cutoff: "
1822 + parser.getDomainsIgnoredDueToEval() + "] [DUF: " + parser.getDomainsIgnoredDueToDuf()
1823 + "] [virus like ids: " + parser.getDomainsIgnoredDueToVirusLikeIds()
1824 + "] [negative domain filter: " + parser.getDomainsIgnoredDueToNegativeDomainFilter()
1825 + "] [overlap: " + parser.getDomainsIgnoredDueToOverlap() + "]" );
1826 if ( negative_filter_file != null ) {
1827 html_desc.append( "; proteins ignored due to negative filter: "
1828 + parser.getProteinsIgnoredDueToFilter() );
1830 if ( positive_filter_file != null ) {
1831 html_desc.append( "; proteins ignored due to positive filter: "
1832 + parser.getProteinsIgnoredDueToFilter() );
1834 html_desc.append( "</td></tr>" + nl );
1835 // domain_partner_counts_array[ i ] =
1836 // Methods.getDomainPartnerCounts( protein_domain_collections_array[
1838 // false, input_file_properties[ i ][ 1 ] );
1839 gwcd_list.add( BasicGenomeWideCombinableDomains
1840 .createInstance( protein_list,
1841 ignore_combination_with_same,
1842 new BasicSpecies( input_file_properties[ i ][ 1 ] ),
1843 domain_id_to_go_ids_map,
1845 domain_lengths_table.addLengths( protein_list );
1846 if ( gwcd_list.get( i ).getSize() > 0 ) {
1847 SurfacingUtil.writeDomainCombinationsCountsFile( input_file_properties,
1849 per_genome_domain_promiscuity_statistics_writer,
1853 if ( output_binary_domain_combinationsfor_graph_analysis ) {
1854 SurfacingUtil.writeBinaryDomainCombinationsFileForGraphAnalysis( input_file_properties,
1860 SurfacingUtil.addAllDomainIdsToSet( gwcd_list.get( i ), all_domains_encountered );
1861 SurfacingUtil.addAllBinaryDomainCombinationToSet( gwcd_list.get( i ),
1862 all_bin_domain_combinations_encountered );
1864 if ( query_domains_writer_ary != null ) {
1865 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1867 SurfacingUtil.extractProteinNames( protein_list,
1868 query_domain_ids_array[ j ],
1869 query_domains_writer_ary[ j ],
1871 query_domains_writer_ary[ j ].flush();
1873 catch ( final IOException e ) {
1874 e.printStackTrace();
1878 if ( need_protein_lists_per_species ) {
1879 protein_lists_per_species.put( new BasicSpecies( input_file_properties[ i ][ 1 ] ), protein_list );
1882 } // for( int i = 0; i < number_of_hmmpfam_files_to_analyze; ++i ) {
1884 per_genome_domain_promiscuity_statistics_writer.flush();
1885 per_genome_domain_promiscuity_statistics_writer.close();
1887 catch ( final IOException e2 ) {
1888 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e2.toString() );
1890 ForesterUtil.programMessage( PRG_NAME, "Wrote domain promiscuities to: "
1891 + per_genome_domain_promiscuity_statistics_file );
1892 if ( query_domains_writer_ary != null ) {
1893 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1895 query_domains_writer_ary[ j ].close();
1897 catch ( final IOException e ) {
1898 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.toString() );
1902 if ( PERFORM_DOMAIN_LENGTH_ANALYSIS ) {
1904 SurfacingUtil.executeDomainLengthAnalysis( input_file_properties,
1906 domain_lengths_table,
1907 domain_lengths_analysis_outfile );
1909 catch ( final IOException e1 ) {
1910 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e1.toString() );
1912 System.out.println();
1913 ForesterUtil.programMessage( PRG_NAME, "Wrote domain length data to: " + domain_lengths_analysis_outfile );
1914 System.out.println();
1916 final long analysis_start_time = new Date().getTime();
1917 PairwiseDomainSimilarityCalculator pw_calc = null;
1918 // double[] values_for_all_scores_histogram = null;
1919 final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( domain_similarity_sort_field,
1920 sort_by_species_count_first,
1921 number_of_genomes == 2 );
1922 switch ( scoring ) {
1924 pw_calc = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1927 pw_calc = new DomainCountsBasedPairwiseSimilarityCalculator();
1930 pw_calc = new ProteinCountsBasedPairwiseDomainSimilarityCalculator();
1933 ForesterUtil.unexpectedFatalError( surfacing_hmmpfam.PRG_NAME, "unknown value for sorting for scoring" );
1935 DomainSimilarityCalculator.GoAnnotationOutput go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.NONE;
1936 if ( domain_id_to_go_ids_map != null ) {
1937 go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.ALL;
1939 final SortedSet<DomainSimilarity> similarities = calc
1940 .calculateSimilarities( pw_calc,
1942 ignore_domains_without_combs_in_all_spec,
1943 ignore_species_specific_domains );
1944 SurfacingUtil.decoratePrintableDomainSimilarities( similarities,
1946 go_annotation_output,
1948 go_namespace_limit );
1949 DescriptiveStatistics pw_stats = null;
1951 String my_outfile = output_file.toString();
1952 if ( !my_outfile.endsWith( ".html" ) ) {
1953 my_outfile += ".html";
1955 final Writer writer = new BufferedWriter( new FileWriter( out_dir == null ? my_outfile : out_dir
1956 + ForesterUtil.FILE_SEPARATOR + my_outfile ) );
1957 List<Species> species_order = null;
1958 if ( species_matrix ) {
1959 species_order = new ArrayList<Species>();
1960 for( int i = 0; i < number_of_genomes; i++ ) {
1961 species_order.add( new BasicSpecies( input_file_properties[ i ][ 1 ] ) );
1964 html_desc.append( "<tr><td>Sum of all distinct binary combinations:</td><td>"
1965 + all_bin_domain_combinations_encountered.size() + "</td></tr>" + nl );
1966 html_desc.append( "<tr><td>Sum of all distinct domains:</td><td>" + all_domains_encountered.size()
1967 + "</td></tr>" + nl );
1968 html_desc.append( "<tr><td>Analysis date/time:</td><td>"
1969 + new java.text.SimpleDateFormat( "yyyy.MM.dd HH:mm:ss" ).format( new java.util.Date() )
1970 + "</td></tr>" + nl );
1971 html_desc.append( "</table>" + nl );
1972 pw_stats = SurfacingUtil
1973 .writeDomainSimilaritiesToFile( html_desc,
1974 new StringBuilder( number_of_genomes + " genomes" ),
1977 number_of_genomes == 2,
1979 domain_similarity_print_option,
1980 domain_similarity_sort_field,
1983 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME,
1984 "Wrote main output (includes domain similarities) to: \""
1985 + ( out_dir == null ? my_outfile : out_dir
1986 + ForesterUtil.FILE_SEPARATOR + my_outfile ) + "\"" );
1988 catch ( final IOException e ) {
1989 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "Failed to write similarites to: \"" + output_file
1990 + "\" [" + e.getMessage() + "]" );
1992 System.out.println();
1993 // values_for_all_scores_histogram = pw_stats.getDataAsDoubleArray();
1994 final Species[] species = new Species[ number_of_genomes ];
1995 for( int i = 0; i < number_of_genomes; ++i ) {
1996 species[ i ] = new BasicSpecies( input_file_properties[ i ][ 1 ] );
1998 List<Phylogeny> inferred_trees = null;
1999 if ( ( number_of_genomes > 2 ) && perform_pwc ) {
2000 final PairwiseGenomeComparator pwgc = new PairwiseGenomeComparator();
2001 pwgc.performPairwiseComparisons( html_desc,
2002 sort_by_species_count_first,
2004 ignore_domains_without_combs_in_all_spec,
2005 ignore_species_specific_domains,
2006 domain_similarity_sort_field_for_automated_pwc,
2007 domain_similarity_print_option,
2009 domain_id_to_go_ids_map,
2016 automated_pairwise_comparison_suffix,
2018 surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_PREFIX,
2019 surfacing_hmmpfam.PRG_NAME,
2022 String matrix_output_file = new String( output_file.toString() );
2023 if ( matrix_output_file.indexOf( '.' ) > 1 ) {
2024 matrix_output_file = matrix_output_file.substring( 0, matrix_output_file.indexOf( '.' ) );
2026 if ( out_dir != null ) {
2027 matrix_output_file = out_dir + ForesterUtil.FILE_SEPARATOR + matrix_output_file;
2028 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
2031 .writeMatrixToFile( new File( matrix_output_file
2032 + surfacing_hmmpfam.MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ),
2033 pwgc.getDomainDistanceScoresMeans() );
2035 .writeMatrixToFile( new File( matrix_output_file
2036 + surfacing_hmmpfam.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
2037 pwgc.getSharedBinaryCombinationsBasedDistances() );
2039 .writeMatrixToFile( new File( matrix_output_file
2040 + surfacing_hmmpfam.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
2041 pwgc.getSharedDomainsBasedDistances() );
2042 final Phylogeny nj_gd = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2043 + surfacing_hmmpfam.NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2044 .getDomainDistanceScoresMeans().get( 0 ) );
2045 final Phylogeny nj_bc = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2046 + surfacing_hmmpfam.NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2047 .getSharedBinaryCombinationsBasedDistances().get( 0 ) );
2048 final Phylogeny nj_d = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2049 + surfacing_hmmpfam.NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2050 .getSharedDomainsBasedDistances().get( 0 ) );
2051 inferred_trees = new ArrayList<Phylogeny>();
2052 inferred_trees.add( nj_gd );
2053 inferred_trees.add( nj_bc );
2054 inferred_trees.add( nj_d );
2055 // final List<HistogramData> histogram_datas = pwgc.getHistogramDatas();
2056 // if ( infer_species_trees ) {
2057 // inferred_trees = new ArrayList<Phylogeny>();
2058 // final List<Phylogeny> inferred_trees_bc = inferSpeciesTrees( new File( output_file + INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2059 // .getSharedBinaryCombinationsBasedDistances() );
2060 // final List<Phylogeny> inferred_trees_d = inferSpeciesTrees( new File( output_file + INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2061 // .getSharedDomainsBasedDistances() );
2062 // inferred_trees.addAll( inferred_trees_bc );
2063 // inferred_trees.addAll( inferred_trees_d );
2065 if ( jacknifed_distances ) {
2066 pwgc.performPairwiseComparisonsJacknifed( species,
2070 jacknife_resamplings,
2074 .writeMatrixToFile( new File( matrix_output_file
2076 + ForesterUtil.round( jacknife_ratio, 2 )
2078 + jacknife_resamplings
2079 + surfacing_hmmpfam.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
2080 pwgc.getSharedBinaryCombinationsBasedDistances() );
2082 .writeMatrixToFile( new File( matrix_output_file
2084 + ForesterUtil.round( jacknife_ratio, 2 )
2086 + jacknife_resamplings
2087 + surfacing_hmmpfam.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
2088 pwgc.getSharedDomainsBasedDistances() );
2089 // if ( infer_species_trees ) {
2090 // inferSpeciesTrees( new File( output_file + "_" + jacknife_resamplings
2091 // + INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2092 // .getSharedBinaryCombinationsBasedDistances() );
2093 // inferSpeciesTrees( new File( output_file + "_" + jacknife_resamplings
2094 // + INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc.getSharedDomainsBasedDistances() );
2097 if ( display_histograms ) {
2098 // final List<HistogramData> histogram_datas_all = new ArrayList<HistogramData>();
2099 // histogram_datas_all.add( new HistogramData( "all",
2100 // values_for_all_scores_histogram,
2103 // final HistogramsFrame hf_all = new HistogramsFrame( histogram_datas_all );
2104 // final HistogramsFrame hf = new HistogramsFrame( histogram_datas );
2105 // hf_all.setVisible( true );
2106 // hf.setVisible( true );
2108 } // if ( ( output_file != null ) && ( number_of_genomes > 2 ) && !isEmpty( automated_pairwise_comparison_suffix ) )
2109 if ( ( out_dir != null ) && ( !perform_pwc ) ) {
2110 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
2112 // writePresentToNexus( output_file, positive_filter_file, filter, gwcd_list );
2113 if ( ( ( intrees != null ) && ( intrees.length > 0 ) ) && ( number_of_genomes > 2 ) ) {
2114 final StringBuilder parameters_sb = createParametersAsString( ignore_dufs,
2116 max_allowed_overlap,
2117 no_engulfing_overlaps,
2121 if ( radomize_fitch_parsimony ) {
2122 s += random_number_seed_for_fitch_parsimony + "_";
2125 for( final Phylogeny intree : intrees ) {
2126 final String outfile_name = ForesterUtil.removeSuffix( output_file.toString() ) + s
2127 + ForesterUtil.removeSuffix( intree_files[ i ].toString() );
2128 final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator.createInstance( intree,
2130 SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
2131 radomize_fitch_parsimony,
2135 domain_id_to_go_ids_map,
2138 parameters_sb.toString(),
2139 domain_id_to_secondary_features_maps,
2140 positive_filter_file == null ? null : filter,
2141 output_binary_domain_combinationsfor_graph_analysis,
2142 all_bin_domain_combinations_gained_fitch,
2143 all_bin_domain_combinations_lost_fitch,
2145 // Listing of all domain combinations gained is only done if only one input tree is used.
2146 if ( ( domain_id_to_secondary_features_maps != null )
2147 && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
2149 for( final Map<DomainId, Set<String>> domain_id_to_secondary_features_map : domain_id_to_secondary_features_maps ) {
2150 final Map<Species, MappingResults> mapping_results_map = new TreeMap<Species, MappingResults>();
2151 final DomainParsimonyCalculator secondary_features_parsimony = DomainParsimonyCalculator
2152 .createInstance( intree, gwcd_list, domain_id_to_secondary_features_map );
2154 .executeParsimonyAnalysisForSecondaryFeatures( outfile_name
2156 + secondary_features_map_files[ j++ ],
2157 secondary_features_parsimony,
2159 parameters_sb.toString(),
2160 mapping_results_map );
2162 System.out.println();
2163 System.out.println( "Mapping to secondary features:" );
2164 for( final Species spec : mapping_results_map.keySet() ) {
2165 final MappingResults mapping_results = mapping_results_map.get( spec );
2166 final int total_domains = mapping_results.getSumOfFailures()
2167 + mapping_results.getSumOfSuccesses();
2168 System.out.print( spec + ":" );
2169 System.out.print( " mapped domains = " + mapping_results.getSumOfSuccesses() );
2170 System.out.print( ", not mapped domains = " + mapping_results.getSumOfFailures() );
2171 if ( total_domains > 0 ) {
2172 System.out.println( ", mapped ratio = "
2173 + ( 100 * mapping_results.getSumOfSuccesses() / total_domains ) + "%" );
2176 System.out.println( ", mapped ratio = n/a (total domains = 0 )" );
2183 } // for( final Phylogeny intree : intrees ) {
2185 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
2186 executePlusMinusAnalysis( output_file,
2187 plus_minus_analysis_high_copy_base_species,
2188 plus_minus_analysis_high_copy_target_species,
2189 plus_minus_analysis_high_low_copy_species,
2191 protein_lists_per_species,
2192 domain_id_to_go_ids_map,
2194 plus_minus_analysis_numbers );
2196 if ( output_protein_lists_for_all_domains ) {
2197 writeProteinListsForAllSpecies( out_dir, protein_lists_per_species, gwcd_list );
2199 // if ( ( intrees != null ) && ( intrees.length > 0 ) && ( inferred_trees != null ) && ( inferred_trees.size() > 0 ) ) {
2200 // final StringBuilder parameters_sb = createParametersAsString( ignore_dufs,
2202 // max_allowed_overlap,
2203 // no_engulfing_overlaps,
2204 // cutoff_scores_file );
2206 // if ( radomize_fitch_parsimony ) {
2207 // s += random_number_seed_for_fitch_parsimony + "_";
2210 // for( final Phylogeny inferred_tree : inferred_trees ) {
2211 // if ( !inferred_tree.isRooted() ) {
2212 // intrees[ 0 ].getRoot().getName();
2215 // final String outfile_name = ForesterUtil.removeSuffix( inferred_tree.getName() ) + s;
2216 // final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator
2217 // .createInstance( inferred_tree, gwcd_list );
2218 // SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
2219 // radomize_fitch_parsimony,
2221 // domain_parsimony,
2223 // domain_id_to_go_ids_map,
2224 // go_id_to_term_map,
2225 // go_namespace_limit,
2226 // parameters_sb.toString() );
2230 if ( all_bin_domain_combinations_gained_fitch != null ) {
2232 executeFitchGainsAnalysis( new File( output_file
2233 + surfacing_hmmpfam.OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2234 all_bin_domain_combinations_gained_fitch,
2235 all_domains_encountered.size(),
2236 all_bin_domain_combinations_encountered,
2239 catch ( final IOException e ) {
2240 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2243 if ( all_bin_domain_combinations_lost_fitch != null ) {
2245 executeFitchGainsAnalysis( new File( output_file
2246 + surfacing_hmmpfam.OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2247 all_bin_domain_combinations_lost_fitch,
2248 all_domains_encountered.size(),
2249 all_bin_domain_combinations_encountered,
2252 catch ( final IOException e ) {
2253 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2256 final Runtime rt = java.lang.Runtime.getRuntime();
2257 final long free_memory = rt.freeMemory() / 1000000;
2258 final long total_memory = rt.totalMemory() / 1000000;
2259 System.out.println();
2260 System.out.println( "Time for analysis : " + ( new Date().getTime() - analysis_start_time ) + "ms" );
2261 System.out.println( "Total running time: " + ( new Date().getTime() - start_time ) + "ms " );
2262 System.out.println( "Free memory : " + free_memory + "MB, total memory: " + total_memory + "MB" );
2263 System.out.println();
2264 System.out.println( "If this application is useful to you, please cite:" );
2265 System.out.println( surfacing_hmmpfam.WWW );
2266 System.out.println();
2267 ForesterUtil.programMessage( PRG_NAME, "OK" );
2268 System.out.println();
2271 private static void preparePhylogenyForParsimonyAnalyses( final Phylogeny intree,
2272 final String[][] input_file_properties ) {
2273 final String[] genomes = new String[ input_file_properties.length ];
2274 for( int i = 0; i < input_file_properties.length; ++i ) {
2275 if ( intree.getNodes( input_file_properties[ i ][ 1 ] ).size() > 1 ) {
2276 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "node named [" + input_file_properties[ i ][ 1 ]
2277 + "] is not unique in input tree " + intree.getName() );
2279 genomes[ i ] = input_file_properties[ i ][ 1 ];
2281 PhylogenyMethods.deleteExternalNodesPositiveSelection( genomes, intree );
2282 for( int i = 0; i < input_file_properties.length; ++i ) {
2284 intree.getNode( input_file_properties[ i ][ 1 ] );
2286 catch ( final IllegalArgumentException e ) {
2287 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "node named [" + input_file_properties[ i ][ 1 ]
2288 + "] not present/not unique in input tree" );
2293 // public static StringBuffer stringCombinableDomainsMapToStringBuffer(
2294 // final SortedMap<String, CombinableDomains> map ) {
2295 // final StringBuffer sb = new StringBuffer();
2296 // for( final Iterator<String> iter = map.keySet().iterator();
2297 // iter.hasNext(); ) {
2298 // final Object key = iter.next();
2299 // sb.append( ForesterUtil.pad( new StringBuffer( key.toString() ), 18, ' ',
2301 // final CombinableDomains domain_combination = map.get( key );
2302 // sb.append( ForesterUtil.pad( new StringBuffer( "" +
2303 // domain_combination.getNumberOfCombiningDomains() ), 8,
2305 // sb.append( domain_combination.toStringBuffer() );
2306 // sb.append( ForesterUtil.getLineSeparator() );
2310 private static void printHelp() {
2311 System.out.println();
2312 System.out.println( "Usage:" );
2313 System.out.println();
2314 System.out.println( "% java -Xms256m -Xmx512m -cp forester.jar org.forester.applications."
2315 + surfacing_hmmpfam.PRG_NAME
2316 + " [options] <phylogen(y|ies) infile> [external node name 1] [name 2] ... [name n]" );
2317 System.out.println();
2318 System.out.println( " Note: This software might need a significant amount of memory (heap space);" );
2320 .println( " hence use \"-Xms128m -Xmx512m\" (or more) to prevent a \"java.lang.OutOfMemoryError\"." );
2321 System.out.println();
2322 System.out.println( " Options: " );
2323 System.out.println( surfacing_hmmpfam.DETAILEDNESS_OPTION
2324 + ": level of detail for similarities output file (default:" + DETAILEDNESS_DEFAULT + ")" );
2325 System.out.println( surfacing_hmmpfam.IGNORE_COMBINATION_WITH_SAME_OPTION
2326 + ": to ignore combinations with self (default: not to ignore)" );
2328 .println( surfacing_hmmpfam.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION
2329 + ": to ignore domains without combinations in any species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2331 .println( surfacing_hmmpfam.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION
2332 + ": to ignore domains specific to one species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2333 System.out.println( surfacing_hmmpfam.NOT_IGNORE_DUFS_OPTION
2334 + ": to _not_ ignore DUFs (domains with unknown function) (default: ignore DUFs)" );
2336 .println( surfacing_hmmpfam.IGNORE_VIRAL_IDS
2337 + ": to ignore domains with ids containing 'vir', 'retro', 'transpos', 'phage', or starting with 'rv' or 'gag_'" );
2338 System.out.println( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_OPTION + ": sorting for similarities (default: "
2339 + DOMAIN_SORT_FILD_DEFAULT + ")" );
2340 System.out.println( surfacing_hmmpfam.OUTPUT_FILE_OPTION + ": name for (main) output file (mandatory)" );
2341 System.out.println( surfacing_hmmpfam.MAX_E_VALUE_OPTION + ": max (inclusive) E-value" );
2342 System.out.println( surfacing_hmmpfam.MAX_ALLOWED_OVERLAP_OPTION + ": maximal allowed domain overlap" );
2343 System.out.println( surfacing_hmmpfam.NO_ENGULFING_OVERLAP_OPTION
2344 + ": to ignore engulfed lower confidence domains" );
2345 System.out.println( surfacing_hmmpfam.SPECIES_MATRIX_OPTION + ": species matrix" );
2346 System.out.println( surfacing_hmmpfam.SCORING_OPTION + ": scoring (default:" + SCORING_DEFAULT + ")" );
2347 System.out.println( surfacing_hmmpfam.DOMAIN_COUNT_SORT_OPTION + ": sorting for domain counts (default:"
2348 + DOMAINS_SORT_ORDER_DEFAULT + ")" );
2349 System.out.println( surfacing_hmmpfam.DOMAIN_SIMILARITY_PRINT_OPTION
2350 + ": domain similarity print option (default:" + DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT + ")" );
2351 System.out.println( surfacing_hmmpfam.CUTOFF_SCORE_FILE_OPTION + ": cutoff score file" );
2352 System.out.println( surfacing_hmmpfam.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION
2353 + ": sort by species count first" );
2354 System.out.println( surfacing_hmmpfam.OUTPUT_DIR_OPTION + ": output directory" );
2355 System.out.println( surfacing_hmmpfam.PFAM_TO_GO_FILE_USE_OPTION + ": Pfam to GO mapping file" );
2356 System.out.println( surfacing_hmmpfam.GO_OBO_FILE_USE_OPTION + ": GO terms file (OBO format)" );
2357 System.out.println( surfacing_hmmpfam.GO_NAMESPACE_LIMIT_OPTION + ": limit GO term to one GO namespace" );
2358 System.out.println( surfacing_hmmpfam.PAIRWISE_DOMAIN_COMPARISONS_OPTION
2359 + "[=<suffix for pairwise comparison output files>]: to perform pairwise comparison based analyses" );
2360 System.out.println( surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION
2361 + ": species tree, to perform (Dollo, Fitch) parismony analyses" );
2362 System.out.println( surfacing_hmmpfam.DISPLAY_M_HISTOGRAMS_OPTION
2363 + ": to display multiple histograms (using fluorite)" );
2365 .println( JACKNIFE_OPTION
2366 + ": perform jacknife resampling for domain and binary domain combination based distance matrices [default resamplings: "
2367 + JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT + "]" );
2368 System.out.println( JACKNIFE_RATIO_OPTION + ": ratio for jacknife resampling [default: "
2369 + JACKNIFE_RATIO_DEFAULT + "]" );
2370 System.out.println( JACKNIFE_RANDOM_SEED_OPTION
2371 + ": seed for random number generator for jacknife resampling [default: "
2372 + JACKNIFE_RANDOM_SEED_DEFAULT + "]" );
2373 // System.out.println( surfacing.INFER_SPECIES_TREES_OPTION
2374 // + ": to infer NJ species trees based on shared domains/binary domain combinations" );
2376 .println( surfacing_hmmpfam.INPUT_SPECIES_TREE_OPTION
2377 + "=<treefiles in phyloXML format, separated by #>: to infer domain/binary domain combination gains/losses on given species trees" );
2378 System.out.println( surfacing_hmmpfam.FILTER_POSITIVE_OPTION
2379 + "=<file>: to filter out proteins not containing at least one domain listed in <file>" );
2380 System.out.println( surfacing_hmmpfam.FILTER_NEGATIVE_OPTION
2381 + "=<file>: to filter out proteins containing at least one domain listed in <file>" );
2382 System.out.println( surfacing_hmmpfam.FILTER_NEGATIVE_DOMAINS_OPTION
2383 + "=<file>: to filter out (ignore) domains listed in <file>" );
2385 .println( surfacing_hmmpfam.INPUT_FILES_FROM_FILE_OPTION + "=<file>: to read input files from <file>" );
2387 .println( surfacing_hmmpfam.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION
2388 + "=<seed>: seed for random number generator for Fitch Parsimony analysis (type: long, default: no randomization - given a choice, prefer absence" );
2389 System.out.println( surfacing_hmmpfam.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS
2390 + ": to consider directedness in binary combinations: e.g. A-B != B-A" );
2391 System.out.println( surfacing_hmmpfam.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY
2392 + ": to consider directedness and adjacency in binary combinations" );
2394 .println( surfacing_hmmpfam.SEQ_EXTRACT_OPTION
2395 + "=<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')" );
2396 System.out.println( surfacing_hmmpfam.SECONDARY_FEATURES_PARSIMONY_MAP_FILE
2397 + "=<file>: to perfom parsimony analysis on secondary features" );
2398 System.out.println( surfacing_hmmpfam.PLUS_MINUS_ANALYSIS_OPTION
2399 + "=<file>: to presence/absence genome analysis" );
2400 System.out.println( surfacing_hmmpfam.DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS
2401 + ": to output binary domain combinations for (downstream) graph analysis" );
2402 System.out.println( surfacing_hmmpfam.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS
2403 + ": to output all proteins per domain" );
2404 System.out.println();
2405 System.out.println();
2406 System.out.println( "Example: java -Xms128m -Xmx512m -cp path/to/forester.jar"
2407 + "org.forester.application.surfacing -detail=punctilious -o=TEST.html -pwc=TEST"
2408 + " -cos=Pfam_ls_22_TC2 -p2g=pfam2go -obo=gene_ontology_edit.obo "
2409 + "-dc_sort=dom -ignore_with_self -no_singles -e=0.001 -mo=1 -no_eo "
2410 + "-ds_output=detailed_html -scoring=domains -sort=alpha -" + JACKNIFE_OPTION
2411 + "=50 human mouse brafl strpu" );
2412 System.out.println();
2415 private static void processFilter( final File filter_file, final SortedSet<DomainId> filter ) {
2416 SortedSet<String> filter_str = null;
2418 filter_str = ForesterUtil.file2set( filter_file );
2420 catch ( final IOException e ) {
2421 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage() );
2423 if ( filter_str != null ) {
2424 for( final String string : filter_str ) {
2425 filter.add( new DomainId( string ) );
2429 System.out.println( "Filter:" );
2430 for( final DomainId domainId : filter ) {
2431 System.out.println( domainId.getId() );
2436 private static String[][] processInputFileNames( final String[] names ) {
2437 final String[][] input_file_properties = new String[ names.length ][];
2438 for( int i = 0; i < names.length; ++i ) {
2439 if ( names[ i ].indexOf( SEPARATOR_FOR_INPUT_VALUES ) < 0 ) {
2440 input_file_properties[ i ] = new String[ 3 ];
2441 input_file_properties[ i ][ 0 ] = names[ i ];
2442 input_file_properties[ i ][ 1 ] = names[ i ];
2443 input_file_properties[ i ][ 2 ] = DEFAULT_SEARCH_PARAMETER;
2446 input_file_properties[ i ] = names[ i ].split( surfacing_hmmpfam.SEPARATOR_FOR_INPUT_VALUES + "" );
2447 if ( input_file_properties[ i ].length != 3 ) {
2449 .fatalError( surfacing_hmmpfam.PRG_NAME,
2450 "properties for the input files (hmmpfam output) are expected "
2451 + "to be in the following format \"<hmmpfam output file>#<species>#<search"
2452 + " parameter>\" (or just one word, which is both the filename and the species id), instead received \""
2453 + names[ i ] + "\"" );
2456 final String error = ForesterUtil.isReadableFile( new File( input_file_properties[ i ][ 0 ] ) );
2457 if ( !ForesterUtil.isEmpty( error ) ) {
2458 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, error );
2461 return input_file_properties;
2464 private static void processPlusMinusAnalysisOption( final CommandLineArguments cla,
2465 final List<String> high_copy_base,
2466 final List<String> high_copy_target,
2467 final List<String> low_copy,
2468 final List<Object> numbers ) {
2469 if ( cla.isOptionSet( surfacing_hmmpfam.PLUS_MINUS_ANALYSIS_OPTION ) ) {
2470 if ( !cla.isOptionValueSet( surfacing_hmmpfam.PLUS_MINUS_ANALYSIS_OPTION ) ) {
2471 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "no value for 'plus-minus' file: -"
2472 + surfacing_hmmpfam.PLUS_MINUS_ANALYSIS_OPTION + "=<file>" );
2474 final File plus_minus_file = new File( cla.getOptionValue( surfacing_hmmpfam.PLUS_MINUS_ANALYSIS_OPTION ) );
2475 final String msg = ForesterUtil.isReadableFile( plus_minus_file );
2476 if ( !ForesterUtil.isEmpty( msg ) ) {
2477 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "can not read from \"" + plus_minus_file + "\": "
2480 processPlusMinusFile( plus_minus_file, high_copy_base, high_copy_target, low_copy, numbers );
2484 // First numbers is minimal difference, second is factor.
2485 private static void processPlusMinusFile( final File plus_minus_file,
2486 final List<String> high_copy_base,
2487 final List<String> high_copy_target,
2488 final List<String> low_copy,
2489 final List<Object> numbers ) {
2490 Set<String> species_set = null;
2491 int min_diff = PLUS_MINUS_ANALYSIS_MIN_DIFF_DEFAULT;
2492 double factor = PLUS_MINUS_ANALYSIS_FACTOR_DEFAULT;
2494 species_set = ForesterUtil.file2set( plus_minus_file );
2496 catch ( final IOException e ) {
2497 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getMessage() );
2499 if ( species_set != null ) {
2500 for( final String species : species_set ) {
2501 final String species_trimmed = species.substring( 1 );
2502 if ( species.startsWith( "+" ) ) {
2503 if ( low_copy.contains( species_trimmed ) ) {
2504 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
2505 "species/genome names can not appear with both '+' and '-' suffix, as appears the case for: \""
2506 + species_trimmed + "\"" );
2508 high_copy_base.add( species_trimmed );
2510 else if ( species.startsWith( "*" ) ) {
2511 if ( low_copy.contains( species_trimmed ) ) {
2512 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
2513 "species/genome names can not appear with both '*' and '-' suffix, as appears the case for: \""
2514 + species_trimmed + "\"" );
2516 high_copy_target.add( species_trimmed );
2518 else if ( species.startsWith( "-" ) ) {
2519 if ( high_copy_base.contains( species_trimmed ) || high_copy_target.contains( species_trimmed ) ) {
2520 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
2521 "species/genome names can not appear with both '+' or '*' and '-' suffix, as appears the case for: \""
2522 + species_trimmed + "\"" );
2524 low_copy.add( species_trimmed );
2526 else if ( species.startsWith( "$D" ) ) {
2528 min_diff = Integer.parseInt( species.substring( 3 ) );
2530 catch ( final NumberFormatException e ) {
2531 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
2532 "could not parse integer value for minimal difference from: \""
2533 + species.substring( 3 ) + "\"" );
2536 else if ( species.startsWith( "$F" ) ) {
2538 factor = Double.parseDouble( species.substring( 3 ) );
2540 catch ( final NumberFormatException e ) {
2541 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME,
2542 "could not parse double value for factor from: \""
2543 + species.substring( 3 ) + "\"" );
2546 else if ( species.startsWith( "#" ) ) {
2551 .fatalError( surfacing_hmmpfam.PRG_NAME,
2552 "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: \""
2555 numbers.add( new Integer( min_diff + "" ) );
2556 numbers.add( new Double( factor + "" ) );
2560 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, "'plus minus' file [" + plus_minus_file
2561 + "] appears empty" );
2565 private static void writeProteinListsForAllSpecies( final File output_dir,
2566 final SortedMap<Species, List<Protein>> protein_lists_per_species,
2567 final List<GenomeWideCombinableDomains> gwcd_list ) {
2568 final SortedSet<DomainId> all_domains = new TreeSet<DomainId>();
2569 for( final GenomeWideCombinableDomains gwcd : gwcd_list ) {
2570 all_domains.addAll( gwcd.getAllDomainIds() );
2572 for( final DomainId domain : all_domains ) {
2573 final File out = new File( output_dir + ForesterUtil.FILE_SEPARATOR + domain + SEQ_EXTRACT_SUFFIX );
2574 SurfacingUtil.checkForOutputFileWriteability( out );
2576 final Writer proteins_file_writer = new BufferedWriter( new FileWriter( out ) );
2577 SurfacingUtil.extractProteinNames( protein_lists_per_species, domain, proteins_file_writer, "\t" );
2578 proteins_file_writer.close();
2580 catch ( final IOException e ) {
2581 ForesterUtil.fatalError( surfacing_hmmpfam.PRG_NAME, e.getLocalizedMessage() );
2583 ForesterUtil.programMessage( surfacing_hmmpfam.PRG_NAME, "Wrote proteins list to \"" + out + "\"" );