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.character.CharacterStateMatrix.Format;
47 import org.forester.evoinference.matrix.distance.DistanceMatrix;
48 import org.forester.go.GoId;
49 import org.forester.go.GoNameSpace;
50 import org.forester.go.GoTerm;
51 import org.forester.go.GoUtils;
52 import org.forester.go.OBOparser;
53 import org.forester.go.PfamToGoMapping;
54 import org.forester.go.PfamToGoParser;
55 import org.forester.io.parsers.HmmscanPerDomainTableParser;
56 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
57 import org.forester.io.writers.PhylogenyWriter;
58 import org.forester.phylogeny.Phylogeny;
59 import org.forester.phylogeny.PhylogenyMethods;
60 import org.forester.phylogeny.PhylogenyNode;
61 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
62 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
63 import org.forester.surfacing.BasicDomainSimilarityCalculator;
64 import org.forester.surfacing.BasicGenomeWideCombinableDomains;
65 import org.forester.surfacing.BasicSpecies;
66 import org.forester.surfacing.BinaryDomainCombination;
67 import org.forester.surfacing.CombinationsBasedPairwiseDomainSimilarityCalculator;
68 import org.forester.surfacing.DomainCountsBasedPairwiseSimilarityCalculator;
69 import org.forester.surfacing.DomainCountsDifferenceUtil;
70 import org.forester.surfacing.DomainId;
71 import org.forester.surfacing.DomainLengthsTable;
72 import org.forester.surfacing.DomainParsimonyCalculator;
73 import org.forester.surfacing.DomainSimilarity;
74 import org.forester.surfacing.DomainSimilarity.DomainSimilarityScoring;
75 import org.forester.surfacing.DomainSimilarity.DomainSimilaritySortField;
76 import org.forester.surfacing.DomainSimilarityCalculator;
77 import org.forester.surfacing.DomainSimilarityCalculator.Detailedness;
78 import org.forester.surfacing.GenomeWideCombinableDomains;
79 import org.forester.surfacing.GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder;
80 import org.forester.surfacing.MappingResults;
81 import org.forester.surfacing.PairwiseDomainSimilarityCalculator;
82 import org.forester.surfacing.PairwiseGenomeComparator;
83 import org.forester.surfacing.PrintableDomainSimilarity;
84 import org.forester.surfacing.PrintableDomainSimilarity.PRINT_OPTION;
85 import org.forester.surfacing.Protein;
86 import org.forester.surfacing.ProteinCountsBasedPairwiseDomainSimilarityCalculator;
87 import org.forester.surfacing.Species;
88 import org.forester.surfacing.SurfacingUtil;
89 import org.forester.util.BasicTable;
90 import org.forester.util.BasicTableParser;
91 import org.forester.util.CommandLineArguments;
92 import org.forester.util.DescriptiveStatistics;
93 import org.forester.util.ForesterConstants;
94 import org.forester.util.ForesterUtil;
96 public class surfacing {
98 public final static String DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS = "graph_analysis_out";
99 public final static String DOMAIN_COMBINITONS_OUTPUTFILE_SUFFIX_FOR_GRAPH_ANALYSIS = "_dc.dot";
100 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_BC_OUTPUTFILE_SUFFIX_FOR_GRAPH_ANALYSIS = "_fitch_present_dc.dot";
101 public final static String DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX = ".dcc";
103 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_DOMAINS = "_dollo_gl_d";
104 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_BINARY_COMBINATIONS = "_dollo_gl_dc";
105 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_FITCH_DOMAINS = "_fitch_gl_d";
106 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_FITCH_BINARY_COMBINATIONS = "_fitch_gl_dc";
108 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_DOMAINS = "_dollo_glc_d";
109 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_BINARY_COMBINATIONS = "_dollo_glc_dc";
110 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_FITCH_DOMAINS = "_fitch_glc_d";
111 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_FITCH_BINARY_COMBINATIONS = "_fitch_glc_dc";
113 // public final static String PARSIMONY_OUTPUT_FITCH_GAINS_BC = "_fitch_gains_dc";
114 // public final static String PARSIMONY_OUTPUT_FITCH_GAINS_HTML_BC = "_fitch_gains_dc.html";
115 // public final static String PARSIMONY_OUTPUT_FITCH_LOSSES_BC = "_fitch_losses_dc";
116 // public final static String PARSIMONY_OUTPUT_FITCH_LOSSES_HTML_BC = "_fitch_losses_dc.html";
117 // public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_BC = "_fitch_present_dc";
118 // public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_HTML_BC = "_fitch_present_dc.html";
119 // public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_D = "_dollo_gains_d";
120 // public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_GOID_D = "_dollo_gains_goid_d";
121 // public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_HTML_D = "_dollo_gains_d.html";
122 // public final static String PARSIMONY_OUTPUT_DOLLO_LOSSES_D = "_dollo_losses_d";
123 //public final static String PARSIMONY_OUTPUT_DOLLO_LOSSES_HTML_D = "_dollo_losses_d.html";
124 // public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_D = "_dollo_present_d";
125 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_GOID_D = "_dollo_present_goid_d";
126 //public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_HTML_D = "_dollo_present_d.html";
127 public final static String DOMAINS_PRESENT_NEXUS = "_dom.nex";
128 public final static String BDC_PRESENT_NEXUS = "_dc.nex";
130 public final static String PRG_NAME = "surfacing";
131 public static final String DOMAINS_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_d_dollo"
132 + ForesterConstants.PHYLO_XML_SUFFIX;
133 public static final String DOMAINS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH = "_d_fitch"
134 + ForesterConstants.PHYLO_XML_SUFFIX;
135 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_dc_dollo"
136 + ForesterConstants.PHYLO_XML_SUFFIX;
137 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH = "_dc_fitch"
138 + ForesterConstants.PHYLO_XML_SUFFIX;
139 public static final String NEXUS_EXTERNAL_DOMAINS = "_dom.nex";
140 public static final String NEXUS_EXTERNAL_DOMAIN_COMBINATIONS = "_dc.nex";
141 public static final String NEXUS_SECONDARY_FEATURES = "_secondary_features.nex";
142 public static final String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_SECONDARY_FEATURES = "_dollo_gl_secondary_features";
143 public static final String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_SECONDARY_FEATURES = "_dollo_glc_secondary_features";
144 public static final String PARSIMONY_OUTPUT_DOLLO_GAINS_SECONDARY_FEATURES = "_dollo_gains_secondary_features";
145 public static final String PARSIMONY_OUTPUT_DOLLO_LOSSES_SECONDARY_FEATURES = "_dollo_losses_secondary_features";
146 public static final String PARSIMONY_OUTPUT_DOLLO_PRESENT_SECONDARY_FEATURES = "_dollo_present_secondary_features";
147 public static final String SECONDARY_FEATURES_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_secondary_features_dollo"
148 + ForesterConstants.PHYLO_XML_SUFFIX;
149 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_BIOLOGICAL_PROCESS = "_dollo_biol_proc_goid_d";
150 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_CELLULAR_COMPONENT = "_dollo_cell_comp_goid_d";
151 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_MOLECULAR_FUNCTION = "_dollo_mol_funct_goid_d";
152 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_ALL_NAMESPACES = "_dollo_goid_d";
153 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_BIOLOGICAL_PROCESS = "_fitch_biol_proc_goid_dc";
154 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_CELLULAR_COMPONENT = "_fitch_cell_comp_goid_dc";
155 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_MOLECULAR_FUNCTION = "_fitch_mol_funct_goid_dc";
156 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_ALL_NAMESPACES = "_fitch_goid_dc";
157 final static private String HELP_OPTION_1 = "help";
158 final static private String HELP_OPTION_2 = "h";
159 final static private String OUTPUT_DIR_OPTION = "out_dir";
160 final static private String SCORING_OPTION = "scoring";
161 private static final DomainSimilarityScoring SCORING_DEFAULT = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
162 final static private String SCORING_DOMAIN_COUNT_BASED = "domains";
163 final static private String SCORING_PROTEIN_COUNT_BASED = "proteins";
164 final static private String SCORING_COMBINATION_BASED = "combinations";
165 final static private String DETAILEDNESS_OPTION = "detail";
166 private final static Detailedness DETAILEDNESS_DEFAULT = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
167 final static private String SPECIES_MATRIX_OPTION = "smatrix";
168 final static private String DETAILEDNESS_BASIC = "basic";
169 final static private String DETAILEDNESS_LIST_IDS = "list_ids";
170 final static private String DETAILEDNESS_PUNCTILIOUS = "punctilious";
171 final static private String DOMAIN_SIMILARITY_SORT_OPTION = "sort";
172 private static final DomainSimilaritySortField DOMAIN_SORT_FILD_DEFAULT = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
173 final static private String DOMAIN_SIMILARITY_SORT_MIN = "min";
174 final static private String DOMAIN_SIMILARITY_SORT_MAX = "max";
175 final static private String DOMAIN_SIMILARITY_SORT_SD = "sd";
176 final static private String DOMAIN_SIMILARITY_SORT_MEAN = "mean";
177 final static private String DOMAIN_SIMILARITY_SORT_DIFF = "diff";
178 final static private String DOMAIN_SIMILARITY_SORT_COUNTS_DIFF = "count_diff";
179 final static private String DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF = "abs_count_diff";
180 final static private String DOMAIN_SIMILARITY_SORT_SPECIES_COUNT = "species";
181 final static private String DOMAIN_SIMILARITY_SORT_ALPHA = "alpha";
182 final static private String DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION = "species_first";
183 final static private String DOMAIN_COUNT_SORT_OPTION = "dc_sort";
184 private static final GenomeWideCombinableDomainsSortOrder DOMAINS_SORT_ORDER_DEFAULT = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
185 final static private String DOMAIN_COUNT_SORT_ALPHA = "alpha";
186 final static private String DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT = "dom";
187 final static private String DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT = "prot";
188 final static private String DOMAIN_COUNT_SORT_COMBINATIONS_COUNT = "comb";
189 final static private String CUTOFF_SCORE_FILE_OPTION = "cos";
190 final static private String NOT_IGNORE_DUFS_OPTION = "dufs";
191 final static private String MAX_E_VALUE_OPTION = "e";
192 final static private String MAX_ALLOWED_OVERLAP_OPTION = "mo";
193 final static private String NO_ENGULFING_OVERLAP_OPTION = "no_eo";
194 final static private String IGNORE_COMBINATION_WITH_SAME_OPTION = "ignore_self_comb";
195 final static private String PAIRWISE_DOMAIN_COMPARISONS_PREFIX = "pwc_";
196 final static private String PAIRWISE_DOMAIN_COMPARISONS_OPTION = "pwc";
197 final static private String OUTPUT_FILE_OPTION = "o";
198 final static private String PFAM_TO_GO_FILE_USE_OPTION = "p2g";
199 final static private String GO_OBO_FILE_USE_OPTION = "obo";
200 final static private String GO_NAMESPACE_LIMIT_OPTION = "go_namespace";
201 final static private String GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION = "molecular_function";
202 final static private String GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS = "biological_process";
203 final static private String GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT = "cellular_component";
204 final static private String SECONDARY_FEATURES_PARSIMONY_MAP_FILE = "secondary";
205 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED = "simple_tab";
206 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML = "simple_html";
207 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML = "detailed_html";
208 final static private String DOMAIN_SIMILARITY_PRINT_OPTION = "ds_output";
209 private static final PRINT_OPTION DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT = PrintableDomainSimilarity.PRINT_OPTION.HTML;
210 final static private String IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION = "ignore_singlet_domains";
211 final static private String IGNORE_VIRAL_IDS = "ignore_viral_ids";
212 final static private boolean IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT = false;
213 final static private String IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION = "ignore_species_specific_domains";
214 final static private boolean IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT = false;
215 final static private String MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score.pwd";
216 final static private String MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains.pwd";
217 final static private String MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations.pwd";
218 final static private String NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score_NJ"
219 + ForesterConstants.PHYLO_XML_SUFFIX;
220 final static private String NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains_NJ"
221 + ForesterConstants.PHYLO_XML_SUFFIX;
222 final static private String NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations_NJ"
223 + ForesterConstants.PHYLO_XML_SUFFIX;
224 final static private String DISPLAY_M_HISTOGRAMS_OPTION = "mhisto";
225 // final static private boolean DISPLAY_M_HISTOGRAMS_OPTION_DEFAULT = false;
226 final static private String JACKNIFE_OPTION = "jack";
227 final static private String JACKNIFE_RANDOM_SEED_OPTION = "seed";
228 final static private String JACKNIFE_RATIO_OPTION = "jack_ratio";
229 private static final int JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT = 100;
230 final static private long JACKNIFE_RANDOM_SEED_DEFAULT = 19;
231 final static private double JACKNIFE_RATIO_DEFAULT = 0.5;
232 //final static private String INFER_SPECIES_TREES_OPTION = "species_tree_inference";
233 final static private String INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX = "_sd_nj.nh";
234 final static private String INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX = "_sbc_nj.nh";
235 final static private String FILTER_POSITIVE_OPTION = "pos_filter";
236 final static private String FILTER_NEGATIVE_OPTION = "neg_filter";
237 final static private String FILTER_NEGATIVE_DOMAINS_OPTION = "neg_dom_filter";
238 final static private String INPUT_FILES_FROM_FILE_OPTION = "input";
239 final static private String INPUT_SPECIES_TREE_OPTION = "species_tree";
240 final static private String SEQ_EXTRACT_OPTION = "prot_extract";
241 final static private char SEPARATOR_FOR_INPUT_VALUES = '#';
242 final static private String PRG_VERSION = "2.003";
243 final static private String PRG_DATE = "2010.12.03";
244 final static private String E_MAIL = "czmasek@burnham.org";
245 final static private String WWW = "www.phylosoft.org/forester/applications/surfacing";
246 final static private boolean IGNORE_DUFS_DEFAULT = true;
247 final static private boolean IGNORE_COMBINATION_WITH_SAME_DEFAULLT = false;
248 final static private double MAX_E_VALUE_DEFAULT = -1;
249 final static private int MAX_ALLOWED_OVERLAP_DEFAULT = -1;
250 final static private String DEFAULT_SEARCH_PARAMETER = "ls";
251 final private static boolean VERBOSE_DEFAULT = true;
252 private static final String RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION = "random_seed";
253 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS = "consider_bdc_direction";
254 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY = "consider_bdc_adj";
255 private static final String SEQ_EXTRACT_SUFFIX = ".prot";
256 private static final String PLUS_MINUS_ANALYSIS_OPTION = "plus_minus";
257 private static final String PLUS_MINUS_DOM_SUFFIX = "_plus_minus_dom.txt";
258 private static final String PLUS_MINUS_DOM_SUFFIX_HTML = "_plus_minus_dom.html";
259 private static final String PLUS_MINUS_DC_SUFFIX_HTML = "_plus_minus_dc.html";
260 private static final int PLUS_MINUS_ANALYSIS_MIN_DIFF_DEFAULT = 0;
261 private static final double PLUS_MINUS_ANALYSIS_FACTOR_DEFAULT = 1.0;
262 private static final String PLUS_MINUS_ALL_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_all.txt";
263 private static final String PLUS_MINUS_PASSING_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_passing.txt";
264 private static final String OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS = "all_prot";
265 private static final boolean VERBOSE = false;
266 private static final String OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_gains_counts";
267 private static final String OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_losses_counts";
268 private static final String DOMAIN_LENGTHS_ANALYSIS_SUFFIX = "_domain_lengths_analysis";
269 private static final boolean PERFORM_DOMAIN_LENGTH_ANALYSIS = true;
270 public static final String ALL_PFAMS_ENCOUNTERED_SUFFIX = "_all_encountered_pfams";
271 public static final String ALL_PFAMS_ENCOUNTERED_WITH_GO_ANNOTATION_SUFFIX = "_all_encountered_pfams_with_go_annotation";
272 public static final String ENCOUNTERED_PFAMS_SUMMARY_SUFFIX = "_encountered_pfams_summary";
273 public static final String ALL_PFAMS_GAINED_AS_DOMAINS_SUFFIX = "_all_pfams_gained_as_domains";
274 public static final String ALL_PFAMS_LOST_AS_DOMAINS_SUFFIX = "_all_pfams_lost_as_domains";
275 public static final String ALL_PFAMS_GAINED_AS_DC_SUFFIX = "_all_pfams_gained_as_dc";
276 public static final String ALL_PFAMS_LOST_AS_DC_SUFFIX = "_all_pfams_lost_as_dc";
277 public static final String BASE_DIRECTORY_PER_NODE_DOMAIN_GAIN_LOSS_FILES = "PER_NODE_EVENTS";
278 public static final String BASE_DIRECTORY_PER_SUBTREE_DOMAIN_GAIN_LOSS_FILES = "PER_SUBTREE_EVENTS";
279 public static final String D_PROMISCUITY_FILE_SUFFIX = "_domain_promiscuities";
280 private static final String LOG_FILE_SUFFIX = "_log.txt";
281 private static final String DATA_FILE_SUFFIX = "_domain_combination_data.txt";
282 private static final String DATA_FILE_DESC = "#SPECIES\tPRTEIN_ID\tN_TERM_DOMAIN\tC_TERM_DOMAIN\tN_TERM_DOMAIN_PER_DOMAIN_E_VALUE\tC_TERM_DOMAIN_PER_DOMAIN_E_VALUE\tN_TERM_DOMAIN_COUNTS_PER_PROTEIN\tC_TERM_DOMAIN_COUNTS_PER_PROTEIN";
283 private static final INDIVIDUAL_SCORE_CUTOFF INDIVIDUAL_SCORE_CUTOFF_DEFAULT = INDIVIDUAL_SCORE_CUTOFF.FULL_SEQUENCE;
285 // final String error = ForesterUtil.isReadableFile( new File(
286 // input_file_properties[ i ][ 0 ] ) );
287 // if ( !ForesterUtil.isEmpty( error ) ) {
288 // ForesterUtil.fatalError( surfacing.PRG_NAME, error );
290 private static void checkWriteabilityForPairwiseComparisons( final PrintableDomainSimilarity.PRINT_OPTION domain_similarity_print_option,
291 final String[][] input_file_properties,
292 final String automated_pairwise_comparison_suffix,
293 final File outdir ) {
294 for( int i = 0; i < input_file_properties.length; ++i ) {
295 for( int j = 0; j < i; ++j ) {
296 final String species_i = input_file_properties[ i ][ 1 ];
297 final String species_j = input_file_properties[ j ][ 1 ];
298 String pairwise_similarities_output_file_str = PAIRWISE_DOMAIN_COMPARISONS_PREFIX + species_i + "_"
299 + species_j + automated_pairwise_comparison_suffix;
300 switch ( domain_similarity_print_option ) {
302 if ( !pairwise_similarities_output_file_str.endsWith( ".html" ) ) {
303 pairwise_similarities_output_file_str += ".html";
307 final String error = ForesterUtil
308 .isWritableFile( new File( outdir == null ? pairwise_similarities_output_file_str : outdir
309 + ForesterUtil.FILE_SEPARATOR + pairwise_similarities_output_file_str ) );
310 if ( !ForesterUtil.isEmpty( error ) ) {
311 ForesterUtil.fatalError( surfacing.PRG_NAME, error );
317 private static StringBuilder createParametersAsString( final boolean ignore_dufs,
318 final double e_value_max,
319 final int max_allowed_overlap,
320 final boolean no_engulfing_overlaps,
321 final File cutoff_scores_file,
322 final BinaryDomainCombination.DomainCombinationType dc_type ) {
323 final StringBuilder parameters_sb = new StringBuilder();
324 parameters_sb.append( "E-value: " + e_value_max );
325 if ( cutoff_scores_file != null ) {
326 parameters_sb.append( ", Cutoff-scores-file: " + cutoff_scores_file );
329 parameters_sb.append( ", Cutoff-scores-file: not-set" );
331 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
332 parameters_sb.append( ", Max-overlap: " + max_allowed_overlap );
335 parameters_sb.append( ", Max-overlap: not-set" );
337 if ( no_engulfing_overlaps ) {
338 parameters_sb.append( ", Engulfing-overlaps: not-allowed" );
341 parameters_sb.append( ", Engulfing-overlaps: allowed" );
344 parameters_sb.append( ", Ignore-dufs: true" );
347 parameters_sb.append( ", Ignore-dufs: false" );
349 parameters_sb.append( ", DC type (if applicable): " + dc_type );
350 return parameters_sb;
354 * Warning: This sideeffects 'all_bin_domain_combinations_encountered'!
358 * @param all_bin_domain_combinations_changed
359 * @param sum_of_all_domains_encountered
360 * @param all_bin_domain_combinations_encountered
361 * @param is_gains_analysis
362 * @throws IOException
364 private static void executeFitchGainsAnalysis( final File output_file,
365 final List<BinaryDomainCombination> all_bin_domain_combinations_changed,
366 final int sum_of_all_domains_encountered,
367 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered,
368 final boolean is_gains_analysis ) throws IOException {
369 SurfacingUtil.checkForOutputFileWriteability( output_file );
370 final Writer out = ForesterUtil.createBufferedWriter( output_file );
371 final SortedMap<Object, Integer> bdc_to_counts = ForesterUtil
372 .listToSortedCountsMap( all_bin_domain_combinations_changed );
373 final SortedSet<DomainId> all_domains_in_combination_changed_more_than_once = new TreeSet<DomainId>();
374 final SortedSet<DomainId> all_domains_in_combination_changed_only_once = new TreeSet<DomainId>();
377 for( final Object bdc_object : bdc_to_counts.keySet() ) {
378 final BinaryDomainCombination bdc = ( BinaryDomainCombination ) bdc_object;
379 final int count = bdc_to_counts.get( bdc_object );
381 ForesterUtil.unexpectedFatalError( PRG_NAME, "count < 1 " );
383 out.write( bdc + "\t" + count + ForesterUtil.LINE_SEPARATOR );
385 all_domains_in_combination_changed_more_than_once.add( bdc.getId0() );
386 all_domains_in_combination_changed_more_than_once.add( bdc.getId1() );
389 else if ( count == 1 ) {
390 all_domains_in_combination_changed_only_once.add( bdc.getId0() );
391 all_domains_in_combination_changed_only_once.add( bdc.getId1() );
395 final int all = all_bin_domain_combinations_encountered.size();
397 if ( !is_gains_analysis ) {
398 all_bin_domain_combinations_encountered.removeAll( all_bin_domain_combinations_changed );
399 never_lost = all_bin_domain_combinations_encountered.size();
400 for( final BinaryDomainCombination bdc : all_bin_domain_combinations_encountered ) {
401 out.write( bdc + "\t" + "0" + ForesterUtil.LINE_SEPARATOR );
404 if ( is_gains_analysis ) {
405 out.write( "Sum of all distinct domain combinations appearing once : " + one
406 + ForesterUtil.LINE_SEPARATOR );
407 out.write( "Sum of all distinct domain combinations appearing more than once : " + above_one
408 + ForesterUtil.LINE_SEPARATOR );
409 out.write( "Sum of all distinct domains in combinations apppearing only once : "
410 + all_domains_in_combination_changed_only_once.size() + ForesterUtil.LINE_SEPARATOR );
411 out.write( "Sum of all distinct domains in combinations apppearing more than once: "
412 + all_domains_in_combination_changed_more_than_once.size() + ForesterUtil.LINE_SEPARATOR );
415 out.write( "Sum of all distinct domain combinations never lost : " + never_lost
416 + ForesterUtil.LINE_SEPARATOR );
417 out.write( "Sum of all distinct domain combinations lost once : " + one
418 + ForesterUtil.LINE_SEPARATOR );
419 out.write( "Sum of all distinct domain combinations lost more than once : " + above_one
420 + ForesterUtil.LINE_SEPARATOR );
421 out.write( "Sum of all distinct domains in combinations lost only once : "
422 + all_domains_in_combination_changed_only_once.size() + ForesterUtil.LINE_SEPARATOR );
423 out.write( "Sum of all distinct domains in combinations lost more than once: "
424 + all_domains_in_combination_changed_more_than_once.size() + ForesterUtil.LINE_SEPARATOR );
426 out.write( "All binary combinations : " + all
427 + ForesterUtil.LINE_SEPARATOR );
428 out.write( "All domains : "
429 + sum_of_all_domains_encountered );
431 ForesterUtil.programMessage( surfacing.PRG_NAME,
432 "Wrote fitch domain combination dynamics counts analysis to \"" + output_file
436 private static void executePlusMinusAnalysis( final File output_file,
437 final List<String> plus_minus_analysis_high_copy_base,
438 final List<String> plus_minus_analysis_high_copy_target,
439 final List<String> plus_minus_analysis_low_copy,
440 final List<GenomeWideCombinableDomains> gwcd_list,
441 final SortedMap<Species, List<Protein>> protein_lists_per_species,
442 final Map<DomainId, List<GoId>> domain_id_to_go_ids_map,
443 final Map<GoId, GoTerm> go_id_to_term_map,
444 final List<Object> plus_minus_analysis_numbers ) {
445 final Set<String> all_spec = new HashSet<String>();
446 for( final GenomeWideCombinableDomains gwcd : gwcd_list ) {
447 all_spec.add( gwcd.getSpecies().getSpeciesId() );
449 final File html_out_dom = new File( output_file + PLUS_MINUS_DOM_SUFFIX_HTML );
450 final File plain_out_dom = new File( output_file + PLUS_MINUS_DOM_SUFFIX );
451 final File html_out_dc = new File( output_file + PLUS_MINUS_DC_SUFFIX_HTML );
452 final File all_domains_go_ids_out_dom = new File( output_file + PLUS_MINUS_ALL_GO_IDS_DOM_SUFFIX );
453 final File passing_domains_go_ids_out_dom = new File( output_file + PLUS_MINUS_PASSING_GO_IDS_DOM_SUFFIX );
454 final File proteins_file_base = new File( output_file + "" );
455 final int min_diff = ( ( Integer ) plus_minus_analysis_numbers.get( 0 ) ).intValue();
456 final double factor = ( ( Double ) plus_minus_analysis_numbers.get( 1 ) ).doubleValue();
458 DomainCountsDifferenceUtil.calculateCopyNumberDifferences( gwcd_list,
459 protein_lists_per_species,
460 plus_minus_analysis_high_copy_base,
461 plus_minus_analysis_high_copy_target,
462 plus_minus_analysis_low_copy,
468 domain_id_to_go_ids_map,
470 all_domains_go_ids_out_dom,
471 passing_domains_go_ids_out_dom,
472 proteins_file_base );
474 catch ( final IOException e ) {
475 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
477 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote plus minus domain analysis results to \""
478 + html_out_dom + "\"" );
479 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote plus minus domain analysis results to \""
480 + plain_out_dom + "\"" );
481 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote plus minus domain analysis results to \"" + html_out_dc
483 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote plus minus domain analysis based passing GO ids to \""
484 + passing_domains_go_ids_out_dom + "\"" );
485 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote plus minus domain analysis based all GO ids to \""
486 + all_domains_go_ids_out_dom + "\"" );
489 private static Phylogeny[] getIntrees( final File[] intree_files,
490 final int number_of_genomes,
491 final String[][] input_file_properties ) {
492 final Phylogeny[] intrees = new Phylogeny[ intree_files.length ];
494 for( final File intree_file : intree_files ) {
495 Phylogeny intree = null;
496 final String error = ForesterUtil.isReadableFile( intree_file );
497 if ( !ForesterUtil.isEmpty( error ) ) {
498 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read input tree file [" + intree_file + "]: "
502 final Phylogeny[] p_array = ParserBasedPhylogenyFactory.getInstance()
503 .create( intree_file, ForesterUtil.createParserDependingOnFileType( intree_file, true ) );
504 if ( p_array.length < 1 ) {
505 ForesterUtil.fatalError( surfacing.PRG_NAME, "file [" + intree_file
506 + "] does not contain any phylogeny in phyloXML format" );
508 else if ( p_array.length > 1 ) {
509 ForesterUtil.fatalError( surfacing.PRG_NAME, "file [" + intree_file
510 + "] contains more than one phylogeny in phyloXML format" );
512 intree = p_array[ 0 ];
514 catch ( final Exception e ) {
515 ForesterUtil.fatalError( surfacing.PRG_NAME, "failed to read input tree from file [" + intree_file
518 if ( ( intree == null ) || intree.isEmpty() ) {
519 ForesterUtil.fatalError( surfacing.PRG_NAME, "input tree [" + intree_file + "] is empty" );
521 if ( !intree.isRooted() ) {
522 ForesterUtil.fatalError( surfacing.PRG_NAME, "input tree [" + intree_file + "] is not rooted" );
524 if ( intree.getNumberOfExternalNodes() < number_of_genomes ) {
525 ForesterUtil.fatalError( surfacing.PRG_NAME,
526 "number of external nodes [" + intree.getNumberOfExternalNodes()
527 + "] of input tree [" + intree_file
528 + "] is smaller than the number of genomes the be analyzed ["
529 + number_of_genomes + "]" );
531 final StringBuilder parent_names = new StringBuilder();
532 final int nodes_lacking_name = SurfacingUtil.getNumberOfNodesLackingName( intree, parent_names );
533 if ( nodes_lacking_name > 0 ) {
534 ForesterUtil.fatalError( surfacing.PRG_NAME, "input tree [" + intree_file + "] has "
535 + nodes_lacking_name + " node(s) lacking a name [parent names:" + parent_names + "]" );
537 preparePhylogenyForParsimonyAnalyses( intree, input_file_properties );
538 if ( !intree.isCompletelyBinary() ) {
539 ForesterUtil.printWarningMessage( surfacing.PRG_NAME, "input tree [" + intree_file
540 + "] is not completely binary" );
542 intrees[ i++ ] = intree;
547 private static List<Phylogeny> inferSpeciesTrees( final File outfile, final List<DistanceMatrix> distances_list ) {
548 final NeighborJoining nj = NeighborJoining.createInstance();
549 final List<Phylogeny> phylogenies = nj.execute( distances_list );
550 final PhylogenyWriter w = new PhylogenyWriter();
552 w.toNewHampshire( phylogenies, true, true, outfile, ";" );
554 catch ( final IOException e ) {
555 ForesterUtil.fatalError( PRG_NAME, "failed to write to outfile [" + outfile + "]: " + e.getMessage() );
560 private static void log( final String msg, final Writer w ) {
563 w.write( ForesterUtil.LINE_SEPARATOR );
565 catch ( final IOException e ) {
566 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
570 public static void main( final String args[] ) {
571 final long start_time = new Date().getTime();
572 // final StringBuffer log = new StringBuffer();
573 final StringBuilder html_desc = new StringBuilder();
574 ForesterUtil.printProgramInformation( surfacing.PRG_NAME,
575 surfacing.PRG_VERSION,
579 final String nl = ForesterUtil.LINE_SEPARATOR;
580 html_desc.append( "<table>" + nl );
581 html_desc.append( "<tr><td>Produced by:</td><td>" + surfacing.PRG_NAME + "</td></tr>" + nl );
582 html_desc.append( "<tr><td>Version:</td><td>" + surfacing.PRG_VERSION + "</td></tr>" + nl );
583 html_desc.append( "<tr><td>Release Date:</td><td>" + surfacing.PRG_DATE + "</td></tr>" + nl );
584 html_desc.append( "<tr><td>Contact:</td><td>" + surfacing.E_MAIL + "</td></tr>" + nl );
585 html_desc.append( "<tr><td>WWW:</td><td>" + surfacing.WWW + "</td></tr>" + nl );
586 CommandLineArguments cla = null;
588 cla = new CommandLineArguments( args );
590 catch ( final Exception e ) {
591 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
593 if ( cla.isOptionSet( surfacing.HELP_OPTION_1 ) || cla.isOptionSet( surfacing.HELP_OPTION_2 ) ) {
594 surfacing.printHelp();
597 if ( ( args.length < 1 ) ) {
598 surfacing.printHelp();
601 final List<String> allowed_options = new ArrayList<String>();
602 allowed_options.add( surfacing.NOT_IGNORE_DUFS_OPTION );
603 allowed_options.add( surfacing.MAX_E_VALUE_OPTION );
604 allowed_options.add( surfacing.DETAILEDNESS_OPTION );
605 allowed_options.add( surfacing.OUTPUT_FILE_OPTION );
606 allowed_options.add( surfacing.DOMAIN_SIMILARITY_SORT_OPTION );
607 allowed_options.add( surfacing.SPECIES_MATRIX_OPTION );
608 allowed_options.add( surfacing.SCORING_OPTION );
609 allowed_options.add( surfacing.MAX_ALLOWED_OVERLAP_OPTION );
610 allowed_options.add( surfacing.NO_ENGULFING_OVERLAP_OPTION );
611 allowed_options.add( surfacing.DOMAIN_COUNT_SORT_OPTION );
612 allowed_options.add( surfacing.CUTOFF_SCORE_FILE_OPTION );
613 allowed_options.add( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION );
614 allowed_options.add( surfacing.OUTPUT_DIR_OPTION );
615 allowed_options.add( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION );
616 allowed_options.add( surfacing.PFAM_TO_GO_FILE_USE_OPTION );
617 allowed_options.add( surfacing.GO_OBO_FILE_USE_OPTION );
618 allowed_options.add( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION );
619 allowed_options.add( surfacing.GO_NAMESPACE_LIMIT_OPTION );
620 allowed_options.add( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
621 allowed_options.add( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION );
622 allowed_options.add( surfacing.DISPLAY_M_HISTOGRAMS_OPTION );
623 allowed_options.add( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS );
624 allowed_options.add( JACKNIFE_OPTION );
625 allowed_options.add( JACKNIFE_RANDOM_SEED_OPTION );
626 allowed_options.add( JACKNIFE_RATIO_OPTION );
627 allowed_options.add( INPUT_SPECIES_TREE_OPTION );
628 //allowed_options.add( INFER_SPECIES_TREES_OPTION );
629 allowed_options.add( FILTER_POSITIVE_OPTION );
630 allowed_options.add( FILTER_NEGATIVE_OPTION );
631 allowed_options.add( INPUT_FILES_FROM_FILE_OPTION );
632 allowed_options.add( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
633 allowed_options.add( FILTER_NEGATIVE_DOMAINS_OPTION );
634 allowed_options.add( IGNORE_VIRAL_IDS );
635 allowed_options.add( SEQ_EXTRACT_OPTION );
636 allowed_options.add( SECONDARY_FEATURES_PARSIMONY_MAP_FILE );
637 allowed_options.add( PLUS_MINUS_ANALYSIS_OPTION );
638 allowed_options.add( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS );
639 allowed_options.add( OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS );
640 allowed_options.add( CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY );
641 boolean ignore_dufs = surfacing.IGNORE_DUFS_DEFAULT;
642 boolean ignore_combination_with_same = surfacing.IGNORE_COMBINATION_WITH_SAME_DEFAULLT;
643 double e_value_max = surfacing.MAX_E_VALUE_DEFAULT;
644 int max_allowed_overlap = surfacing.MAX_ALLOWED_OVERLAP_DEFAULT;
645 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
646 if ( dissallowed_options.length() > 0 ) {
647 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown option(s): " + dissallowed_options );
649 boolean output_binary_domain_combinationsfor_graph_analysis = false;
650 if ( cla.isOptionSet( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS ) ) {
651 output_binary_domain_combinationsfor_graph_analysis = true;
653 if ( cla.isOptionSet( surfacing.MAX_E_VALUE_OPTION ) ) {
655 e_value_max = cla.getOptionValueAsDouble( surfacing.MAX_E_VALUE_OPTION );
657 catch ( final Exception e ) {
658 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for E-value maximum" );
661 if ( cla.isOptionSet( surfacing.MAX_ALLOWED_OVERLAP_OPTION ) ) {
663 max_allowed_overlap = cla.getOptionValueAsInt( surfacing.MAX_ALLOWED_OVERLAP_OPTION );
665 catch ( final Exception e ) {
666 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for maximal allowed domain overlap" );
669 boolean no_engulfing_overlaps = false;
670 if ( cla.isOptionSet( surfacing.NO_ENGULFING_OVERLAP_OPTION ) ) {
671 no_engulfing_overlaps = true;
673 boolean ignore_virus_like_ids = false;
674 if ( cla.isOptionSet( surfacing.IGNORE_VIRAL_IDS ) ) {
675 ignore_virus_like_ids = true;
677 if ( cla.isOptionSet( surfacing.NOT_IGNORE_DUFS_OPTION ) ) {
680 if ( cla.isOptionSet( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION ) ) {
681 ignore_combination_with_same = true;
683 boolean ignore_domains_without_combs_in_all_spec = IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT;
684 if ( cla.isOptionSet( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION ) ) {
685 ignore_domains_without_combs_in_all_spec = true;
687 boolean ignore_species_specific_domains = IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT;
688 if ( cla.isOptionSet( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION ) ) {
689 ignore_species_specific_domains = true;
691 File output_file = null;
692 if ( cla.isOptionSet( surfacing.OUTPUT_FILE_OPTION ) ) {
693 if ( !cla.isOptionValueSet( surfacing.OUTPUT_FILE_OPTION ) ) {
694 ForesterUtil.fatalError( surfacing.PRG_NAME,
695 "no value for domain combinations similarities output file: -"
696 + surfacing.OUTPUT_FILE_OPTION + "=<file>" );
698 output_file = new File( cla.getOptionValue( surfacing.OUTPUT_FILE_OPTION ) );
699 SurfacingUtil.checkForOutputFileWriteability( output_file );
701 File cutoff_scores_file = null;
702 Map<String, Double> individual_score_cutoffs = null;
703 if ( cla.isOptionSet( surfacing.CUTOFF_SCORE_FILE_OPTION ) ) {
704 if ( !cla.isOptionValueSet( surfacing.CUTOFF_SCORE_FILE_OPTION ) ) {
705 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for individual domain score cutoffs file: -"
706 + surfacing.CUTOFF_SCORE_FILE_OPTION + "=<file>" );
708 cutoff_scores_file = new File( cla.getOptionValue( surfacing.CUTOFF_SCORE_FILE_OPTION ) );
709 final String error = ForesterUtil.isReadableFile( cutoff_scores_file );
710 if ( !ForesterUtil.isEmpty( error ) ) {
711 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read individual domain score cutoffs file: "
715 final BasicTable<String> scores_table = BasicTableParser.parse( cutoff_scores_file, " " );
716 individual_score_cutoffs = scores_table.getColumnsAsMapDouble( 0, 1 );
718 catch ( final IOException e ) {
719 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from individual score cutoffs file: " + e );
722 BinaryDomainCombination.DomainCombinationType dc_type = BinaryDomainCombination.DomainCombinationType.BASIC;
723 if ( cla.isOptionSet( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS ) ) {
724 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED;
726 if ( cla.isOptionSet( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY ) ) {
727 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT;
730 if ( cla.isOptionSet( surfacing.OUTPUT_DIR_OPTION ) ) {
731 if ( !cla.isOptionValueSet( surfacing.OUTPUT_DIR_OPTION ) ) {
732 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for output directory: -"
733 + surfacing.OUTPUT_DIR_OPTION + "=<dir>" );
735 out_dir = new File( cla.getOptionValue( surfacing.OUTPUT_DIR_OPTION ) );
736 if ( out_dir.exists() && ( out_dir.listFiles().length > 0 ) ) {
737 ForesterUtil.fatalError( surfacing.PRG_NAME, "\"" + out_dir + "\" aready exists and is not empty" );
739 if ( !out_dir.exists() ) {
740 final boolean success = out_dir.mkdir();
741 if ( !success || !out_dir.exists() ) {
742 ForesterUtil.fatalError( surfacing.PRG_NAME, "failed to create \"" + out_dir + "\"" );
745 if ( !out_dir.canWrite() ) {
746 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot write to \"" + out_dir + "\"" );
749 File positive_filter_file = null;
750 File negative_filter_file = null;
751 File negative_domains_filter_file = null;
752 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) && cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
753 ForesterUtil.fatalError( surfacing.PRG_NAME, "attempt to use both negative and positive protein filter" );
755 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION )
756 && ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) || cla
757 .isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) ) {
759 .fatalError( surfacing.PRG_NAME,
760 "attempt to use both negative or positive protein filter together wirh a negative domains filter" );
762 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) ) {
763 if ( !cla.isOptionValueSet( surfacing.FILTER_NEGATIVE_OPTION ) ) {
764 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for negative filter: -"
765 + surfacing.FILTER_NEGATIVE_OPTION + "=<file>" );
767 negative_filter_file = new File( cla.getOptionValue( surfacing.FILTER_NEGATIVE_OPTION ) );
768 final String msg = ForesterUtil.isReadableFile( negative_filter_file );
769 if ( !ForesterUtil.isEmpty( msg ) ) {
770 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + negative_filter_file + "\": "
774 else if ( cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
775 if ( !cla.isOptionValueSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
776 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for positive filter: -"
777 + surfacing.FILTER_POSITIVE_OPTION + "=<file>" );
779 positive_filter_file = new File( cla.getOptionValue( surfacing.FILTER_POSITIVE_OPTION ) );
780 final String msg = ForesterUtil.isReadableFile( positive_filter_file );
781 if ( !ForesterUtil.isEmpty( msg ) ) {
782 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + positive_filter_file + "\": "
786 else if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
787 if ( !cla.isOptionValueSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
788 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for negative domains filter: -"
789 + surfacing.FILTER_NEGATIVE_DOMAINS_OPTION + "=<file>" );
791 negative_domains_filter_file = new File( cla.getOptionValue( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) );
792 final String msg = ForesterUtil.isReadableFile( negative_domains_filter_file );
793 if ( !ForesterUtil.isEmpty( msg ) ) {
794 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + negative_domains_filter_file
798 final List<String> plus_minus_analysis_high_copy_base_species = new ArrayList<String>();
799 final List<String> plus_minus_analysis_high_copy_target_species = new ArrayList<String>();
800 final List<String> plus_minus_analysis_high_low_copy_species = new ArrayList<String>();
801 final List<Object> plus_minus_analysis_numbers = new ArrayList<Object>();
802 processPlusMinusAnalysisOption( cla,
803 plus_minus_analysis_high_copy_base_species,
804 plus_minus_analysis_high_copy_target_species,
805 plus_minus_analysis_high_low_copy_species,
806 plus_minus_analysis_numbers );
807 File input_files_file = null;
808 String[] input_file_names_from_file = null;
809 if ( cla.isOptionSet( surfacing.INPUT_FILES_FROM_FILE_OPTION ) ) {
810 if ( !cla.isOptionValueSet( surfacing.INPUT_FILES_FROM_FILE_OPTION ) ) {
811 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for input files file: -"
812 + surfacing.INPUT_FILES_FROM_FILE_OPTION + "=<file>" );
814 input_files_file = new File( cla.getOptionValue( surfacing.INPUT_FILES_FROM_FILE_OPTION ) );
815 final String msg = ForesterUtil.isReadableFile( input_files_file );
816 if ( !ForesterUtil.isEmpty( msg ) ) {
817 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + input_files_file + "\": " + msg );
820 input_file_names_from_file = ForesterUtil.file2array( input_files_file );
822 catch ( final IOException e ) {
823 ForesterUtil.fatalError( surfacing.PRG_NAME, "failed to read from \"" + input_files_file + "\": " + e );
826 if ( ( cla.getNumberOfNames() < 1 )
827 && ( ( input_file_names_from_file == null ) || ( input_file_names_from_file.length < 1 ) ) ) {
828 ForesterUtil.fatalError( surfacing.PRG_NAME,
829 "No hmmpfam output file indicated is input: use comand line directly or "
830 + surfacing.INPUT_FILES_FROM_FILE_OPTION + "=<file>" );
832 DomainSimilarity.DomainSimilarityScoring scoring = SCORING_DEFAULT;
833 if ( cla.isOptionSet( surfacing.SCORING_OPTION ) ) {
834 if ( !cla.isOptionValueSet( surfacing.SCORING_OPTION ) ) {
835 ForesterUtil.fatalError( surfacing.PRG_NAME,
836 "no value for scoring method for domain combinations similarity calculation: -"
837 + surfacing.SCORING_OPTION + "=<"
838 + surfacing.SCORING_DOMAIN_COUNT_BASED + "|"
839 + surfacing.SCORING_PROTEIN_COUNT_BASED + "|"
840 + surfacing.SCORING_COMBINATION_BASED + ">\"" );
842 final String scoring_str = cla.getOptionValue( surfacing.SCORING_OPTION );
843 if ( scoring_str.equals( surfacing.SCORING_DOMAIN_COUNT_BASED ) ) {
844 scoring = DomainSimilarity.DomainSimilarityScoring.DOMAINS;
846 else if ( scoring_str.equals( surfacing.SCORING_COMBINATION_BASED ) ) {
847 scoring = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
849 else if ( scoring_str.equals( surfacing.SCORING_PROTEIN_COUNT_BASED ) ) {
850 scoring = DomainSimilarity.DomainSimilarityScoring.PROTEINS;
853 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + scoring_str
854 + "\" for scoring method for domain combinations similarity calculation: \"-"
855 + surfacing.SCORING_OPTION + "=<" + surfacing.SCORING_DOMAIN_COUNT_BASED + "|"
856 + surfacing.SCORING_PROTEIN_COUNT_BASED + "|" + surfacing.SCORING_COMBINATION_BASED + ">\"" );
859 boolean sort_by_species_count_first = false;
860 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION ) ) {
861 sort_by_species_count_first = true;
863 boolean species_matrix = false;
864 if ( cla.isOptionSet( surfacing.SPECIES_MATRIX_OPTION ) ) {
865 species_matrix = true;
867 boolean output_protein_lists_for_all_domains = false;
868 if ( cla.isOptionSet( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS ) ) {
869 output_protein_lists_for_all_domains = true;
871 Detailedness detailedness = DETAILEDNESS_DEFAULT;
872 if ( cla.isOptionSet( surfacing.DETAILEDNESS_OPTION ) ) {
873 if ( !cla.isOptionValueSet( surfacing.DETAILEDNESS_OPTION ) ) {
874 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for -" + surfacing.DETAILEDNESS_OPTION + "=<"
875 + surfacing.DETAILEDNESS_BASIC + "|" + surfacing.DETAILEDNESS_LIST_IDS + "|"
876 + surfacing.DETAILEDNESS_PUNCTILIOUS + ">\"" );
878 final String detness = cla.getOptionValue( surfacing.DETAILEDNESS_OPTION ).toLowerCase();
879 if ( detness.equals( surfacing.DETAILEDNESS_BASIC ) ) {
880 detailedness = DomainSimilarityCalculator.Detailedness.BASIC;
882 else if ( detness.equals( surfacing.DETAILEDNESS_LIST_IDS ) ) {
883 detailedness = DomainSimilarityCalculator.Detailedness.LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES;
885 else if ( detness.equals( surfacing.DETAILEDNESS_PUNCTILIOUS ) ) {
886 detailedness = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
889 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + detness + "\" for detailedness: \"-"
890 + surfacing.DETAILEDNESS_OPTION + "=<" + surfacing.DETAILEDNESS_BASIC + "|"
891 + surfacing.DETAILEDNESS_LIST_IDS + "|" + surfacing.DETAILEDNESS_PUNCTILIOUS + ">\"" );
894 String automated_pairwise_comparison_suffix = null;
895 boolean perform_pwc = false;
896 boolean write_pwc_files = false;
897 if ( cla.isOptionSet( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
899 if ( !cla.isOptionValueSet( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
900 write_pwc_files = false;
903 write_pwc_files = true;
904 automated_pairwise_comparison_suffix = "_"
905 + cla.getOptionValue( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
908 String query_domain_ids = null;
909 if ( cla.isOptionSet( surfacing.SEQ_EXTRACT_OPTION ) ) {
910 if ( !cla.isOptionValueSet( surfacing.SEQ_EXTRACT_OPTION ) ) {
912 .fatalError( surfacing.PRG_NAME,
913 "no domain ids given for sequences with given domains to be extracted : -"
914 + surfacing.SEQ_EXTRACT_OPTION
915 + "=<ordered domain sequences, domain ids separated by '~', sequences separated by '#'>" );
917 query_domain_ids = cla.getOptionValue( surfacing.SEQ_EXTRACT_OPTION );
919 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field = DOMAIN_SORT_FILD_DEFAULT;
920 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field_for_automated_pwc = DOMAIN_SORT_FILD_DEFAULT;
921 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
922 if ( !cla.isOptionValueSet( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
923 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for domain combinations similarities sorting: -"
924 + surfacing.DOMAIN_SIMILARITY_SORT_OPTION + "=<" + surfacing.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
925 + surfacing.DOMAIN_SIMILARITY_SORT_MAX + "|" + surfacing.DOMAIN_SIMILARITY_SORT_MIN + "|"
926 + surfacing.DOMAIN_SIMILARITY_SORT_MEAN + "|" + surfacing.DOMAIN_SIMILARITY_SORT_DIFF + "|"
927 + surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
928 + surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|"
929 + surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|" + surfacing.DOMAIN_SIMILARITY_SORT_SD
932 final String sort_str = cla.getOptionValue( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ).toLowerCase();
933 if ( sort_str.equals( surfacing.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.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.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.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.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.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.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.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.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.PRG_NAME, "unknown value \"" + sort_str
971 + "\" for domain combinations similarities sorting: \"-"
972 + surfacing.DOMAIN_SIMILARITY_SORT_OPTION + "=<" + surfacing.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
973 + surfacing.DOMAIN_SIMILARITY_SORT_MAX + "|" + surfacing.DOMAIN_SIMILARITY_SORT_MIN + "|"
974 + surfacing.DOMAIN_SIMILARITY_SORT_MEAN + "|" + surfacing.DOMAIN_SIMILARITY_SORT_DIFF + "|"
975 + surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
976 + surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|" + "|"
977 + surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|" + surfacing.DOMAIN_SIMILARITY_SORT_SD
981 PrintableDomainSimilarity.PRINT_OPTION domain_similarity_print_option = DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT;
982 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
983 if ( !cla.isOptionValueSet( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
984 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for print option: -"
985 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
986 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
987 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
989 final String sort = cla.getOptionValue( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ).toLowerCase();
990 if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML ) ) {
991 domain_similarity_print_option = PrintableDomainSimilarity.PRINT_OPTION.HTML;
993 else if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML ) ) {
994 // domain_similarity_print_option =
995 // DomainSimilarity.PRINT_OPTION.SIMPLE_HTML;
996 ForesterUtil.fatalError( surfacing.PRG_NAME, "simple HTML output not implemented yet :(" );
998 else if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED ) ) {
999 domain_similarity_print_option = PrintableDomainSimilarity.PRINT_OPTION.SIMPLE_TAB_DELIMITED;
1002 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort + "\" for print option: -"
1003 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
1004 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
1005 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
1008 GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder dc_sort_order = DOMAINS_SORT_ORDER_DEFAULT;
1009 if ( cla.isOptionSet( surfacing.DOMAIN_COUNT_SORT_OPTION ) ) {
1010 if ( !cla.isOptionValueSet( surfacing.DOMAIN_COUNT_SORT_OPTION ) ) {
1011 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for sorting of domain counts: -"
1012 + surfacing.DOMAIN_COUNT_SORT_OPTION + "=<" + surfacing.DOMAIN_COUNT_SORT_ALPHA + "|"
1013 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
1014 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
1015 + surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
1017 final String sort = cla.getOptionValue( surfacing.DOMAIN_COUNT_SORT_OPTION ).toLowerCase();
1018 if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_ALPHA ) ) {
1019 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
1021 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT ) ) {
1022 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_COUNT;
1024 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT ) ) {
1025 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_PROTEINS_COUNT;
1027 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT ) ) {
1028 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.COMBINATIONS_COUNT;
1031 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort
1032 + "\" for sorting of domain counts: \"-" + surfacing.DOMAIN_COUNT_SORT_OPTION + "=<"
1033 + surfacing.DOMAIN_COUNT_SORT_ALPHA + "|" + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
1034 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
1035 + surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
1038 String[][] input_file_properties = null;
1039 if ( input_file_names_from_file != null ) {
1040 input_file_properties = surfacing.processInputFileNames( input_file_names_from_file );
1043 input_file_properties = surfacing.processInputFileNames( cla.getNames() );
1045 final int number_of_genomes = input_file_properties.length;
1046 if ( number_of_genomes < 2 ) {
1047 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot analyze less than two files" );
1049 if ( ( number_of_genomes < 3 ) && perform_pwc ) {
1050 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use : -"
1051 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1052 + "=<suffix> to turn on pairwise analyses with less than three input files" );
1054 checkWriteabilityForPairwiseComparisons( domain_similarity_print_option,
1055 input_file_properties,
1056 automated_pairwise_comparison_suffix,
1058 for( int i = 0; i < number_of_genomes; i++ ) {
1059 File dcc_outfile = new File( input_file_properties[ i ][ 0 ]
1060 + surfacing.DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX );
1061 if ( out_dir != null ) {
1062 dcc_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + dcc_outfile );
1064 SurfacingUtil.checkForOutputFileWriteability( dcc_outfile );
1066 File pfam_to_go_file = null;
1067 Map<DomainId, List<GoId>> domain_id_to_go_ids_map = null;
1068 int domain_id_to_go_ids_count = 0;
1069 if ( cla.isOptionSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
1070 if ( !cla.isOptionValueSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
1071 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for Pfam to GO mapping file: -"
1072 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>" );
1074 pfam_to_go_file = new File( cla.getOptionValue( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) );
1075 final String error = ForesterUtil.isReadableFile( pfam_to_go_file );
1076 if ( !ForesterUtil.isEmpty( error ) ) {
1077 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read Pfam to GO mapping file: " + error );
1080 final PfamToGoParser parser = new PfamToGoParser( pfam_to_go_file );
1081 final List<PfamToGoMapping> pfam_to_go_mappings = parser.parse();
1082 domain_id_to_go_ids_map = SurfacingUtil.createDomainIdToGoIdMap( pfam_to_go_mappings );
1083 if ( parser.getMappingCount() < domain_id_to_go_ids_map.size() ) {
1084 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME,
1085 "parser.getMappingCount() < domain_id_to_go_ids_map.size()" );
1087 domain_id_to_go_ids_count = parser.getMappingCount();
1089 catch ( final IOException e ) {
1090 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from Pfam to GO mapping file: " + e );
1093 File go_obo_file = null;
1094 List<GoTerm> go_terms = null;
1095 if ( cla.isOptionSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
1096 if ( !cla.isOptionValueSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
1097 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for GO OBO file: -"
1098 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>" );
1100 if ( ( domain_id_to_go_ids_map == null ) || ( domain_id_to_go_ids_map.size() < 1 ) ) {
1101 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use GO OBO file (-"
1102 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>) without Pfam to GO mapping file ("
1103 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1105 go_obo_file = new File( cla.getOptionValue( surfacing.GO_OBO_FILE_USE_OPTION ) );
1106 final String error = ForesterUtil.isReadableFile( go_obo_file );
1107 if ( !ForesterUtil.isEmpty( error ) ) {
1108 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read GO OBO file: " + error );
1111 final OBOparser parser = new OBOparser( go_obo_file, OBOparser.ReturnType.BASIC_GO_TERM );
1112 go_terms = parser.parse();
1113 if ( parser.getGoTermCount() != go_terms.size() ) {
1115 .unexpectedFatalError( surfacing.PRG_NAME, "parser.getGoTermCount() != go_terms.size()" );
1118 catch ( final IOException e ) {
1119 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from GO OBO file: " + e );
1122 Map<GoId, GoTerm> go_id_to_term_map = null;
1123 if ( ( ( domain_id_to_go_ids_map != null ) && ( domain_id_to_go_ids_map.size() > 0 ) )
1124 && ( ( go_terms != null ) && ( go_terms.size() > 0 ) ) ) {
1125 go_id_to_term_map = GoUtils.createGoIdToGoTermMap( go_terms );
1127 GoNameSpace go_namespace_limit = null;
1128 if ( cla.isOptionSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
1129 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1130 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use GO namespace limit (-"
1131 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<namespace>) without Pfam to GO mapping file ("
1132 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>) and GO OBO file (-"
1133 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1135 if ( !cla.isOptionValueSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
1136 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for GO namespace limit: \"-"
1137 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
1138 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
1139 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
1140 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
1142 final String go_namespace_limit_str = cla.getOptionValue( surfacing.GO_NAMESPACE_LIMIT_OPTION )
1144 if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION ) ) {
1145 go_namespace_limit = GoNameSpace.createMolecularFunction();
1147 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS ) ) {
1148 go_namespace_limit = GoNameSpace.createBiologicalProcess();
1150 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT ) ) {
1151 go_namespace_limit = GoNameSpace.createCellularComponent();
1154 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + go_namespace_limit_str
1155 + "\" for GO namespace limit: \"-" + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
1156 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
1157 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
1158 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
1161 if ( ( domain_similarity_sort_field == DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE )
1162 && ( number_of_genomes > 2 ) ) {
1163 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
1165 boolean jacknifed_distances = false;
1166 int jacknife_resamplings = JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT;
1167 double jacknife_ratio = JACKNIFE_RATIO_DEFAULT;
1168 long random_seed = JACKNIFE_RANDOM_SEED_DEFAULT;
1169 if ( cla.isOptionSet( surfacing.JACKNIFE_OPTION ) ) {
1170 if ( ( number_of_genomes < 3 ) || !perform_pwc ) {
1171 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use jacknife resampling analysis (-"
1172 + surfacing.JACKNIFE_OPTION + "[=<number of resamplings>]) without pairwise analyses ("
1173 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1174 + "=<suffix for pairwise comparison output files>)" );
1176 jacknifed_distances = true;
1177 if ( cla.isOptionHasAValue( surfacing.JACKNIFE_OPTION ) ) {
1179 jacknife_resamplings = cla.getOptionValueAsInt( surfacing.JACKNIFE_OPTION );
1181 catch ( final IOException e ) {
1182 ForesterUtil.fatalError( surfacing.PRG_NAME, "illegal format for number of resamplings" );
1184 if ( jacknife_resamplings < 2 ) {
1185 ForesterUtil.fatalError( surfacing.PRG_NAME, "attempt to use less than 2 resamplings" );
1188 if ( cla.isOptionSet( surfacing.JACKNIFE_RATIO_OPTION )
1189 && cla.isOptionHasAValue( surfacing.JACKNIFE_RATIO_OPTION ) ) {
1191 jacknife_ratio = cla.getOptionValueAsDouble( surfacing.JACKNIFE_RATIO_OPTION );
1193 catch ( final IOException e ) {
1194 ForesterUtil.fatalError( surfacing.PRG_NAME, "illegal format for jacknife ratio" );
1196 if ( ( jacknife_ratio <= 0.0 ) || ( jacknife_ratio >= 1.0 ) ) {
1197 ForesterUtil.fatalError( surfacing.PRG_NAME, "attempt to use illegal value for jacknife ratio: "
1201 if ( cla.isOptionSet( surfacing.JACKNIFE_RANDOM_SEED_OPTION )
1202 && cla.isOptionHasAValue( surfacing.JACKNIFE_RANDOM_SEED_OPTION ) ) {
1204 random_seed = cla.getOptionValueAsLong( surfacing.JACKNIFE_RANDOM_SEED_OPTION );
1206 catch ( final IOException e ) {
1207 ForesterUtil.fatalError( surfacing.PRG_NAME, "illegal format for random generator seed" );
1211 // boolean infer_species_trees = false;
1212 // if ( cla.isOptionSet( surfacing.INFER_SPECIES_TREES_OPTION ) ) {
1213 // if ( ( output_file == null ) || ( number_of_genomes < 3 )
1214 // || ForesterUtil.isEmpty( automated_pairwise_comparison_suffix ) ) {
1215 // ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot infer species trees (-"
1216 // + surfacing.INFER_SPECIES_TREES_OPTION + " without pairwise analyses ("
1217 // + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1218 // + "=<suffix for pairwise comparison output files>)" );
1220 // infer_species_trees = true;
1222 File[] intree_files = null;
1223 Phylogeny[] intrees = null;
1224 if ( cla.isOptionSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
1225 // TODO FIXME if jacknife.... maybe not
1226 if ( number_of_genomes < 3 ) {
1227 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot infer gains and losses on input species trees (-"
1228 + surfacing.INPUT_SPECIES_TREE_OPTION + " without pairwise analyses ("
1229 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1230 + "=<suffix for pairwise comparison output files>)" );
1232 if ( !cla.isOptionValueSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
1233 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for input tree: -"
1234 + surfacing.INPUT_SPECIES_TREE_OPTION + "=<tree file in phyloXML format>" );
1236 final String intrees_str = cla.getOptionValue( surfacing.INPUT_SPECIES_TREE_OPTION );
1237 if ( intrees_str.indexOf( "#" ) > 0 ) {
1238 final String[] intrees_strs = intrees_str.split( "#" );
1239 intree_files = new File[ intrees_strs.length ];
1241 for( final String s : intrees_strs ) {
1242 intree_files[ i++ ] = new File( s.trim() );
1246 intree_files = new File[ 1 ];
1247 intree_files[ 0 ] = new File( intrees_str );
1249 intrees = getIntrees( intree_files, number_of_genomes, input_file_properties );
1251 long random_number_seed_for_fitch_parsimony = 0l;
1252 boolean radomize_fitch_parsimony = false;
1253 if ( cla.isOptionSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
1254 if ( !cla.isOptionValueSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
1255 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for random number seed: -"
1256 + surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION + "=<seed>" );
1259 random_number_seed_for_fitch_parsimony = cla
1260 .getOptionValueAsLong( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
1262 catch ( final IOException e ) {
1263 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
1265 radomize_fitch_parsimony = true;
1267 SortedSet<DomainId> filter = null;
1268 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1269 || ( negative_domains_filter_file != null ) ) {
1270 filter = new TreeSet<DomainId>();
1271 if ( positive_filter_file != null ) {
1272 processFilter( positive_filter_file, filter );
1274 else if ( negative_filter_file != null ) {
1275 processFilter( negative_filter_file, filter );
1277 else if ( negative_domains_filter_file != null ) {
1278 processFilter( negative_domains_filter_file, filter );
1281 Map<DomainId, Set<String>>[] domain_id_to_secondary_features_maps = null;
1282 File[] secondary_features_map_files = null;
1283 final File domain_lengths_analysis_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1284 + DOMAIN_LENGTHS_ANALYSIS_SUFFIX );
1285 if ( PERFORM_DOMAIN_LENGTH_ANALYSIS ) {
1286 SurfacingUtil.checkForOutputFileWriteability( domain_lengths_analysis_outfile );
1288 if ( cla.isOptionSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
1289 if ( !cla.isOptionValueSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
1290 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for secondary features map file: -"
1291 + surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE + "=<file>" );
1293 final String[] secondary_features_map_files_strs = cla
1294 .getOptionValue( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ).split( "#" );
1295 secondary_features_map_files = new File[ secondary_features_map_files_strs.length ];
1296 domain_id_to_secondary_features_maps = new Map[ secondary_features_map_files_strs.length ];
1298 for( final String secondary_features_map_files_str : secondary_features_map_files_strs ) {
1299 secondary_features_map_files[ i ] = new File( secondary_features_map_files_str );
1300 final String error = ForesterUtil.isReadableFile( secondary_features_map_files[ i ] );
1301 if ( !ForesterUtil.isEmpty( error ) ) {
1302 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read secondary features map file: " + error );
1305 domain_id_to_secondary_features_maps[ i ] = SurfacingUtil
1306 .createDomainIdToSecondaryFeaturesMap( secondary_features_map_files[ i ] );
1308 catch ( final IOException e ) {
1309 ForesterUtil.fatalError( surfacing.PRG_NAME,
1310 "cannot read secondary features map file: " + e.getMessage() );
1312 catch ( final Exception e ) {
1313 ForesterUtil.fatalError( surfacing.PRG_NAME, "problem with contents of features map file ["
1314 + secondary_features_map_files[ i ] + "]: " + e.getMessage() );
1319 if ( out_dir == null ) {
1320 ForesterUtil.fatalError( surfacing.PRG_NAME, "no output directory indicated (-"
1321 + surfacing.OUTPUT_DIR_OPTION + "=<dir>)" );
1323 if ( output_file == null ) {
1324 ForesterUtil.fatalError( surfacing.PRG_NAME, "no name for (main) output file indicated (-"
1325 + surfacing.OUTPUT_FILE_OPTION + "=<file>)" );
1327 if ( ( domain_id_to_go_ids_map == null ) || domain_id_to_go_ids_map.isEmpty() ) {
1328 ForesterUtil.fatalError( surfacing.PRG_NAME,
1329 "no (acceptable) Pfam to GO id mapping file provided ('pfam2go file') (-"
1330 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1332 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1333 ForesterUtil.fatalError( surfacing.PRG_NAME,
1334 "no (acceptable) go id to term mapping file provided ('GO OBO file') (-"
1335 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1337 boolean display_histograms = false;
1338 if ( cla.isOptionSet( surfacing.DISPLAY_M_HISTOGRAMS_OPTION ) ) {
1339 display_histograms = true;
1341 System.out.println( "Output directory : " + out_dir );
1342 if ( input_file_names_from_file != null ) {
1343 System.out.println( "Input files names from : " + input_files_file + " ["
1344 + input_file_names_from_file.length + " input files]" );
1345 html_desc.append( "<tr><td>Input files names from:</td><td>" + input_files_file + " ["
1346 + input_file_names_from_file.length + " input files]</td></tr>" + nl );
1348 if ( positive_filter_file != null ) {
1349 final int filter_size = filter.size();
1350 System.out.println( "Positive protein filter : " + positive_filter_file + " [" + filter_size
1352 html_desc.append( "<tr><td>Positive protein filter:</td><td>" + positive_filter_file + " [" + filter_size
1353 + " domain ids]</td></tr>" + nl );
1355 if ( negative_filter_file != null ) {
1356 final int filter_size = filter.size();
1357 System.out.println( "Negative protein filter : " + negative_filter_file + " [" + filter_size
1359 html_desc.append( "<tr><td>Negative protein filter:</td><td>" + negative_filter_file + " [" + filter_size
1360 + " domain ids]</td></tr>" + nl );
1362 if ( negative_domains_filter_file != null ) {
1363 final int filter_size = filter.size();
1364 System.out.println( "Negative domain filter : " + negative_domains_filter_file + " [" + filter_size
1366 html_desc.append( "<tr><td>Negative domain filter:</td><td>" + negative_domains_filter_file + " ["
1367 + filter_size + " domain ids]</td></tr>" + nl );
1369 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
1371 for( final String s : plus_minus_analysis_high_copy_base_species ) {
1372 plus0 += "+" + s + " ";
1375 for( final String s : plus_minus_analysis_high_copy_target_species ) {
1376 plus1 += "*" + s + " ";
1379 for( final String s : plus_minus_analysis_high_low_copy_species ) {
1380 minus += "-" + s + " ";
1382 System.out.println( "Plus-minus analysis : " + plus1 + "&& " + plus0 + "&& " + minus );
1383 html_desc.append( "<tr><td>Plus-minus analysis:</td><td>" + plus1 + "&& " + plus0 + "&& " + minus
1384 + "</td></tr>" + nl );
1386 if ( cutoff_scores_file != null ) {
1387 System.out.println( "Cutoff scores file : " + cutoff_scores_file );
1388 html_desc.append( "<tr><td>Cutoff scores file:</td><td>" + cutoff_scores_file + "</td></tr>" + nl );
1390 if ( e_value_max >= 0.0 ) {
1391 System.out.println( "E-value maximum (inclusive) : " + e_value_max );
1392 html_desc.append( "<tr><td>E-value maximum (inclusive):</td><td>" + e_value_max + "</td></tr>" + nl );
1394 System.out.println( "Ignore DUFs : " + ignore_dufs );
1395 if ( ignore_virus_like_ids ) {
1396 System.out.println( "Ignore virus like ids : " + ignore_virus_like_ids );
1397 html_desc.append( "<tr><td>Ignore virus, phage, transposition related ids:</td><td>"
1398 + ignore_virus_like_ids + "</td></tr>" + nl );
1400 html_desc.append( "<tr><td>Ignore DUFs:</td><td>" + ignore_dufs + "</td></tr>" + nl );
1401 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1402 System.out.println( "Max allowed domain overlap : " + max_allowed_overlap );
1403 html_desc.append( "<tr><td>Max allowed domain overlap:</td><td>" + max_allowed_overlap + "</td></tr>" + nl );
1405 if ( no_engulfing_overlaps ) {
1406 System.out.println( "Ignore engulfed domains : " + no_engulfing_overlaps );
1407 html_desc.append( "<tr><td>Ignore (lower confidence) engulfed domains:</td><td>" + no_engulfing_overlaps
1408 + "</td></tr>" + nl );
1410 System.out.println( "Ignore singlet domains : " + ignore_domains_without_combs_in_all_spec );
1412 .append( "<tr><td>Ignore singlet domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1413 + ignore_domains_without_combs_in_all_spec + "</td></tr>" + nl );
1414 System.out.println( "Ignore species specific doms: " + ignore_species_specific_domains );
1416 .append( "<tr><td>Ignore species specific domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1417 + ignore_species_specific_domains + "</td></tr>" + nl );
1418 System.out.println( "Ignore combination with self: " + ignore_combination_with_same );
1419 html_desc.append( "<tr><td>Ignore combination with self for domain combination similarity analyses:</td><td>"
1420 + ignore_combination_with_same + "</td></tr>" + nl );
1422 System.out.println( "Consider directedness : "
1423 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) );
1424 html_desc.append( "<tr><td>Consider directedness of binary domain combinations:</td><td>"
1425 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) + "</td></tr>" + nl );
1426 if ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) {
1427 System.out.println( "Consider adjacency : "
1428 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) );
1429 html_desc.append( "<tr><td>Consider djacency of binary domain combinations:</td><td>"
1430 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) + "</td></tr>"
1433 System.out.print( "Domain counts sort order : " );
1434 switch ( dc_sort_order ) {
1435 case ALPHABETICAL_KEY_ID:
1436 System.out.println( "alphabetical" );
1438 case KEY_DOMAIN_COUNT:
1439 System.out.println( "domain count" );
1441 case KEY_DOMAIN_PROTEINS_COUNT:
1442 System.out.println( "domain proteins count" );
1444 case COMBINATIONS_COUNT:
1445 System.out.println( "domain combinations count" );
1448 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for dc sort order" );
1450 if ( domain_id_to_go_ids_map != null ) {
1451 System.out.println( "Pfam to GO mappings from : " + pfam_to_go_file + " [" + domain_id_to_go_ids_count
1453 html_desc.append( "<tr><td>Pfam to GO mappings from:</td><td>" + pfam_to_go_file + " ["
1454 + domain_id_to_go_ids_count + " mappings]" + "</td></tr>" + nl );
1456 if ( go_terms != null ) {
1457 System.out.println( "GO terms from : " + go_obo_file + " [" + go_terms.size() + " terms]" );
1458 html_desc.append( "<tr><td>GO terms from:</td><td>" + go_obo_file + " [" + go_terms.size() + " terms]"
1459 + "</td></tr>" + nl );
1461 if ( go_namespace_limit != null ) {
1462 System.out.println( "Limit GO terms to : " + go_namespace_limit.toString() );
1463 html_desc.append( "<tr><td>Limit GO terms to</td><td>" + go_namespace_limit + "</td></tr>" + nl );
1465 if ( perform_pwc ) {
1466 System.out.println( "Suffix for PWC files : " + automated_pairwise_comparison_suffix );
1467 html_desc.append( "<tr><td>Suffix for PWC files</td><td>" + automated_pairwise_comparison_suffix
1468 + "</td></tr>" + nl );
1470 if ( out_dir != null ) {
1471 System.out.println( "Output directory : " + out_dir );
1473 if ( query_domain_ids != null ) {
1474 System.out.println( "Query domains (ordered) : " + query_domain_ids );
1475 html_desc.append( "<tr><td></td><td>" + query_domain_ids + "</td></tr>" + nl );
1477 System.out.println( "Write similarities to : " + output_file );
1478 System.out.print( " Scoring method : " );
1479 html_desc.append( "<tr><td>Scoring method:</td><td>" );
1480 switch ( scoring ) {
1482 System.out.println( "domain combinations based" );
1483 html_desc.append( "domain combinations based" + "</td></tr>" + nl );
1486 System.out.println( "domain counts based" );
1487 html_desc.append( "domain counts based" + "</td></tr>" + nl );
1490 System.out.println( "domain proteins counts based" );
1491 html_desc.append( "domain proteins counts based" + "</td></tr>" + nl );
1494 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1496 System.out.print( " Sort by : " );
1497 html_desc.append( "<tr><td>Sort by:</td><td>" );
1498 switch ( domain_similarity_sort_field ) {
1500 System.out.print( "score minimum" );
1501 html_desc.append( "score minimum" );
1504 System.out.print( "score maximum" );
1505 html_desc.append( "score maximum" );
1508 System.out.print( "score mean" );
1509 html_desc.append( "score mean" );
1512 System.out.print( "score standard deviation" );
1513 html_desc.append( "score standard deviation" );
1516 System.out.print( "species number" );
1517 html_desc.append( "species number" );
1520 System.out.print( "alphabetical domain identifier" );
1521 html_desc.append( "alphabetical domain identifier" );
1523 case MAX_DIFFERENCE:
1524 System.out.print( "(maximal) difference" );
1525 html_desc.append( "(maximal) difference" );
1527 case ABS_MAX_COUNTS_DIFFERENCE:
1528 System.out.print( "absolute (maximal) counts difference" );
1529 html_desc.append( "absolute (maximal) counts difference" );
1531 case MAX_COUNTS_DIFFERENCE:
1532 System.out.print( "(maximal) counts difference" );
1533 html_desc.append( "(maximal) counts difference" );
1536 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1538 if ( sort_by_species_count_first ) {
1539 System.out.println( " (sort by species count first)" );
1540 html_desc.append( " (sort by species count first)" );
1543 System.out.println();
1545 html_desc.append( "</td></tr>" + nl );
1546 System.out.print( " Detailedness : " );
1547 switch ( detailedness ) {
1549 System.out.println( "basic" );
1551 case LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES:
1552 System.out.println( "list combining domains for each species" );
1555 System.out.println( "punctilious" );
1558 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for detailedness" );
1560 System.out.print( " Print option : " );
1561 switch ( domain_similarity_print_option ) {
1563 System.out.println( "HTML" );
1565 case SIMPLE_TAB_DELIMITED:
1566 System.out.println( "simple tab delimited" );
1569 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for print option" );
1571 System.out.print( " Species matrix : " + species_matrix );
1572 System.out.println();
1573 final File dc_data_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + DATA_FILE_SUFFIX );
1574 System.out.println( "Domain comb data output : " + dc_data_file );
1575 html_desc.append( "<tr><td>Domain combination data output:</td><td> " + dc_data_file + " </td></tr>" );
1576 System.out.println();
1577 if ( perform_pwc ) {
1578 System.out.println( "Pairwise comparisons: " );
1579 html_desc.append( "<tr><td>Pairwise comparisons:</td><td></td></tr>" );
1580 System.out.print( " Sort by : " );
1581 html_desc.append( "<tr><td>Sort by:</td><td>" );
1582 switch ( domain_similarity_sort_field_for_automated_pwc ) {
1584 System.out.print( "score mean" );
1585 html_desc.append( "score mean" );
1588 System.out.print( "alphabetical domain identifier" );
1589 html_desc.append( "alphabetical domain identifier" );
1591 case MAX_DIFFERENCE:
1592 System.out.print( "difference" );
1593 html_desc.append( "difference" );
1595 case ABS_MAX_COUNTS_DIFFERENCE:
1596 System.out.print( "absolute counts difference" );
1597 html_desc.append( "absolute counts difference" );
1599 case MAX_COUNTS_DIFFERENCE:
1600 System.out.print( "counts difference" );
1601 html_desc.append( "counts difference" );
1605 .unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1607 System.out.println();
1608 html_desc.append( "</td></tr>" + nl );
1609 if ( jacknifed_distances ) {
1610 html_desc.append( "<tr><td>Jacknife:</td><td>" + jacknife_resamplings + " resamplings</td></tr>" + nl );
1611 html_desc.append( "<tr><td>Jacknife ratio:</td><td>" + ForesterUtil.round( jacknife_ratio, 2 )
1612 + "</td></tr>" + nl );
1613 html_desc.append( "<tr><td>Jacknife random number seed:</td><td>" + random_seed + "</td></tr>" + nl );
1614 System.out.println( " Jacknife : " + jacknife_resamplings + " resamplings" );
1615 System.out.println( " Ratio : " + ForesterUtil.round( jacknife_ratio, 2 ) );
1616 System.out.println( " Random number seed : " + random_seed );
1618 // if ( infer_species_trees ) {
1619 // html_desc.append( "<tr><td>Infer species trees:</td><td>true</td></tr>" + nl );
1620 // System.out.println( " Infer species trees : true" );
1622 if ( ( intrees != null ) && ( intrees.length > 0 ) ) {
1623 for( final File intree_file : intree_files ) {
1624 html_desc.append( "<tr><td>Intree for gain/loss parsimony analysis:</td><td>" + intree_file
1625 + "</td></tr>" + nl );
1626 System.out.println( " Intree for gain/loss pars.: " + intree_file );
1629 if ( radomize_fitch_parsimony ) {
1630 html_desc.append( "<tr><td> Random number seed for Fitch parsimony analysis:</td><td>"
1631 + random_number_seed_for_fitch_parsimony + "</td></tr>" + nl );
1632 System.out.println( " Random number seed : " + random_number_seed_for_fitch_parsimony );
1634 if ( ( domain_id_to_secondary_features_maps != null ) && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
1635 for( int i = 0; i < secondary_features_map_files.length; i++ ) {
1636 html_desc.append( "<tr><td>Secondary features map file:</td><td>"
1637 + secondary_features_map_files[ i ] + "</td></tr>" + nl );
1638 System.out.println( "Secondary features map file : " + secondary_features_map_files[ i ]
1639 + " [mappings for " + domain_id_to_secondary_features_maps[ i ].size() + " domain ids]" );
1641 System.out.println();
1642 System.out.println( "Domain ids to secondary features map:" );
1643 for( final DomainId domain_id : domain_id_to_secondary_features_maps[ i ].keySet() ) {
1644 System.out.print( domain_id.getId() );
1645 System.out.print( " => " );
1646 for( final String sec : domain_id_to_secondary_features_maps[ i ].get( domain_id ) ) {
1647 System.out.print( sec );
1648 System.out.print( " " );
1650 System.out.println();
1655 } // if ( perform_pwc ) {
1656 System.out.println();
1657 html_desc.append( "<tr><td>Command line:</td><td>" + cla.getCommandLineArgsAsString() + "</td></tr>" + nl );
1658 System.out.println( "Command line : " + cla.getCommandLineArgsAsString() );
1659 BufferedWriter[] query_domains_writer_ary = null;
1660 List<DomainId>[] query_domain_ids_array = null;
1661 if ( query_domain_ids != null ) {
1662 final String[] query_domain_ids_str_array = query_domain_ids.split( "#" );
1663 query_domain_ids_array = new ArrayList[ query_domain_ids_str_array.length ];
1664 query_domains_writer_ary = new BufferedWriter[ query_domain_ids_str_array.length ];
1665 for( int i = 0; i < query_domain_ids_str_array.length; i++ ) {
1666 String query_domain_ids_str = query_domain_ids_str_array[ i ];
1667 final String[] query_domain_ids_str_ary = query_domain_ids_str.split( "~" );
1668 final List<DomainId> query = new ArrayList<DomainId>();
1669 for( final String element : query_domain_ids_str_ary ) {
1670 query.add( new DomainId( element ) );
1672 query_domain_ids_array[ i ] = query;
1673 query_domain_ids_str = query_domain_ids_str.replace( '~', '_' );
1674 String protein_names_writer_str = query_domain_ids_str + surfacing.SEQ_EXTRACT_SUFFIX;
1675 if ( out_dir != null ) {
1676 protein_names_writer_str = out_dir + ForesterUtil.FILE_SEPARATOR + protein_names_writer_str;
1679 query_domains_writer_ary[ i ] = new BufferedWriter( new FileWriter( protein_names_writer_str ) );
1681 catch ( final IOException e ) {
1682 ForesterUtil.fatalError( surfacing.PRG_NAME, "Could not open [" + protein_names_writer_str + "]: "
1683 + e.getLocalizedMessage() );
1687 SortedMap<Species, List<Protein>> protein_lists_per_species = null; //This will only be created if neede.
1688 boolean need_protein_lists_per_species = false;
1689 if ( ( plus_minus_analysis_high_copy_base_species.size() > 0 ) || output_protein_lists_for_all_domains ) {
1690 need_protein_lists_per_species = true;
1692 if ( need_protein_lists_per_species ) {
1693 protein_lists_per_species = new TreeMap<Species, List<Protein>>();
1695 final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>( number_of_genomes );
1696 final SortedSet<DomainId> all_domains_encountered = new TreeSet<DomainId>();
1697 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered = new TreeSet<BinaryDomainCombination>();
1698 List<BinaryDomainCombination> all_bin_domain_combinations_gained_fitch = null;
1699 List<BinaryDomainCombination> all_bin_domain_combinations_lost_fitch = null;
1700 if ( ( intrees != null ) && ( intrees.length == 1 ) ) {
1701 all_bin_domain_combinations_gained_fitch = new ArrayList<BinaryDomainCombination>();
1702 all_bin_domain_combinations_lost_fitch = new ArrayList<BinaryDomainCombination>();
1704 final DomainLengthsTable domain_lengths_table = new DomainLengthsTable();
1705 final File per_genome_domain_promiscuity_statistics_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR
1706 + output_file + D_PROMISCUITY_FILE_SUFFIX );
1707 BufferedWriter per_genome_domain_promiscuity_statistics_writer = null;
1709 per_genome_domain_promiscuity_statistics_writer = new BufferedWriter( new FileWriter( per_genome_domain_promiscuity_statistics_file ) );
1710 per_genome_domain_promiscuity_statistics_writer.write( "Species:\t" );
1711 per_genome_domain_promiscuity_statistics_writer.write( "Mean:\t" );
1712 per_genome_domain_promiscuity_statistics_writer.write( "SD:\t" );
1713 per_genome_domain_promiscuity_statistics_writer.write( "Median:\t" );
1714 per_genome_domain_promiscuity_statistics_writer.write( "Min:\t" );
1715 per_genome_domain_promiscuity_statistics_writer.write( "Max:\t" );
1716 per_genome_domain_promiscuity_statistics_writer.write( "N:\t" );
1717 per_genome_domain_promiscuity_statistics_writer.write( "Max Promiscuous Domains:"
1718 + ForesterUtil.LINE_SEPARATOR );
1720 catch ( final IOException e2 ) {
1721 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1723 final File log_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + LOG_FILE_SUFFIX );
1724 BufferedWriter log_writer = null;
1726 log_writer = new BufferedWriter( new FileWriter( log_file ) );
1728 catch ( final IOException e2 ) {
1729 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1731 BufferedWriter dc_data_writer = null;
1733 dc_data_writer = new BufferedWriter( new FileWriter( dc_data_file ) );
1734 dc_data_writer.write( DATA_FILE_DESC );
1735 dc_data_writer.write( ForesterUtil.LINE_SEPARATOR );
1737 catch ( final IOException e2 ) {
1738 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1740 for( int i = 0; i < number_of_genomes; ++i ) {
1741 System.out.println();
1742 System.out.println( ( i + 1 ) + "/" + number_of_genomes );
1743 log( ( i + 1 ) + "/" + number_of_genomes, log_writer );
1744 System.out.println( "Processing : " + input_file_properties[ i ][ 0 ] );
1745 log( "Genome : " + input_file_properties[ i ][ 0 ], log_writer );
1746 HmmscanPerDomainTableParser parser = null;
1747 INDIVIDUAL_SCORE_CUTOFF ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF.NONE;
1748 if ( individual_score_cutoffs != null ) {
1749 ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF_DEFAULT;
1751 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1752 || ( negative_domains_filter_file != null ) ) {
1753 HmmscanPerDomainTableParser.FilterType filter_type = HmmscanPerDomainTableParser.FilterType.NONE;
1754 if ( positive_filter_file != null ) {
1755 filter_type = HmmscanPerDomainTableParser.FilterType.POSITIVE_PROTEIN;
1757 else if ( negative_filter_file != null ) {
1758 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_PROTEIN;
1760 else if ( negative_domains_filter_file != null ) {
1761 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_DOMAIN;
1763 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1764 input_file_properties[ i ][ 1 ],
1770 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1771 input_file_properties[ i ][ 1 ],
1774 if ( e_value_max >= 0.0 ) {
1775 parser.setEValueMaximum( e_value_max );
1777 parser.setIgnoreDufs( ignore_dufs );
1778 parser.setIgnoreVirusLikeIds( ignore_virus_like_ids );
1779 parser.setIgnoreEngulfedDomains( no_engulfing_overlaps );
1780 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1781 parser.setMaxAllowedOverlap( max_allowed_overlap );
1783 parser.setReturnType( HmmscanPerDomainTableParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
1784 if ( individual_score_cutoffs != null ) {
1785 parser.setIndividualScoreCutoffs( individual_score_cutoffs );
1787 List<Protein> protein_list = null;
1789 protein_list = parser.parse();
1791 catch ( final IOException e ) {
1792 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
1794 catch ( final Exception e ) {
1795 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, e.getMessage(), e );
1798 System.out.println( "Domains ignored due to negative domain filter: " );
1799 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToNegativeDomainFilterCountsMap() );
1800 System.out.println( "Domains ignored due to virus like id: " );
1801 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToVirusLikeIdCountsMap() );
1803 System.out.println( "Number of proteins encountered : " + parser.getProteinsEncountered() );
1804 log( "Number of proteins encountered : " + parser.getProteinsEncountered(), log_writer );
1805 System.out.println( "Number of proteins stored : " + protein_list.size() );
1806 log( "Number of proteins stored : " + protein_list.size(), log_writer );
1807 System.out.println( "Domains encountered : " + parser.getDomainsEncountered() );
1808 log( "Domains encountered : " + parser.getDomainsEncountered(), log_writer );
1809 System.out.println( "Domains stored : " + parser.getDomainsStored() );
1810 log( "Domains stored : " + parser.getDomainsStored(), log_writer );
1811 System.out.println( "Distinct domains stored : "
1812 + parser.getDomainsStoredSet().size() );
1813 log( "Distinct domains stored : " + parser.getDomainsStoredSet().size(), log_writer );
1814 System.out.println( "Domains ignored due to individual score cutoffs: "
1815 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() );
1816 log( "Domains ignored due to individual score cutoffs: "
1817 + parser.getDomainsIgnoredDueToIndividualScoreCutoff(),
1819 System.out.println( "Domains ignored due to E-value : "
1820 + parser.getDomainsIgnoredDueToEval() );
1821 log( "Domains ignored due to E-value : " + parser.getDomainsIgnoredDueToEval(), log_writer );
1822 System.out.println( "Domains ignored due to DUF designation : "
1823 + parser.getDomainsIgnoredDueToDuf() );
1824 log( "Domains ignored due to DUF designation : " + parser.getDomainsIgnoredDueToDuf(), log_writer );
1825 if ( ignore_virus_like_ids ) {
1826 System.out.println( "Domains ignored due virus like ids : "
1827 + parser.getDomainsIgnoredDueToVirusLikeIds() );
1828 log( "Domains ignored due virus like ids : " + parser.getDomainsIgnoredDueToVirusLikeIds(),
1831 System.out.println( "Domains ignored due negative domain filter : "
1832 + parser.getDomainsIgnoredDueToNegativeDomainFilter() );
1833 log( "Domains ignored due negative domain filter : "
1834 + parser.getDomainsIgnoredDueToNegativeDomainFilter(),
1836 System.out.println( "Domains ignored due to overlap : "
1837 + parser.getDomainsIgnoredDueToOverlap() );
1838 log( "Domains ignored due to overlap : " + parser.getDomainsIgnoredDueToOverlap(),
1840 if ( negative_filter_file != null ) {
1841 System.out.println( "Proteins ignored due to negative filter : "
1842 + parser.getProteinsIgnoredDueToFilter() );
1843 log( "Proteins ignored due to negative filter : " + parser.getProteinsIgnoredDueToFilter(),
1846 if ( positive_filter_file != null ) {
1847 System.out.println( "Proteins ignored due to positive filter : "
1848 + parser.getProteinsIgnoredDueToFilter() );
1849 log( "Proteins ignored due to positive filter : " + parser.getProteinsIgnoredDueToFilter(),
1852 System.out.println( "Time for processing : " + parser.getTime() + "ms" );
1853 log( "", log_writer );
1854 html_desc.append( "<tr><td>" + input_file_properties[ i ][ 0 ] + " [species: "
1855 + input_file_properties[ i ][ 1 ] + "]" + ":</td><td>domains analyzed: "
1856 + parser.getDomainsStored() + "; domains ignored: [ind score cutoffs: "
1857 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() + "] [E-value cutoff: "
1858 + parser.getDomainsIgnoredDueToEval() + "] [DUF: " + parser.getDomainsIgnoredDueToDuf()
1859 + "] [virus like ids: " + parser.getDomainsIgnoredDueToVirusLikeIds()
1860 + "] [negative domain filter: " + parser.getDomainsIgnoredDueToNegativeDomainFilter()
1861 + "] [overlap: " + parser.getDomainsIgnoredDueToOverlap() + "]" );
1862 if ( negative_filter_file != null ) {
1863 html_desc.append( "; proteins ignored due to negative filter: "
1864 + parser.getProteinsIgnoredDueToFilter() );
1866 if ( positive_filter_file != null ) {
1867 html_desc.append( "; proteins ignored due to positive filter: "
1868 + parser.getProteinsIgnoredDueToFilter() );
1870 html_desc.append( "</td></tr>" + nl );
1871 // domain_partner_counts_array[ i ] =
1872 // Methods.getDomainPartnerCounts( protein_domain_collections_array[
1874 // false, input_file_properties[ i ][ 1 ] );
1877 for( final Protein protein : protein_list ) {
1878 dc_data_writer.write( SurfacingUtil.proteinToDomainCombinations( protein, count + "", "\t" )
1883 catch ( final IOException e ) {
1884 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1886 gwcd_list.add( BasicGenomeWideCombinableDomains
1887 .createInstance( protein_list,
1888 ignore_combination_with_same,
1889 new BasicSpecies( input_file_properties[ i ][ 1 ] ),
1890 domain_id_to_go_ids_map,
1892 domain_lengths_table.addLengths( protein_list );
1893 if ( gwcd_list.get( i ).getSize() > 0 ) {
1894 SurfacingUtil.writeDomainCombinationsCountsFile( input_file_properties,
1896 per_genome_domain_promiscuity_statistics_writer,
1900 if ( output_binary_domain_combinationsfor_graph_analysis ) {
1901 SurfacingUtil.writeBinaryDomainCombinationsFileForGraphAnalysis( input_file_properties,
1907 SurfacingUtil.addAllDomainIdsToSet( gwcd_list.get( i ), all_domains_encountered );
1908 SurfacingUtil.addAllBinaryDomainCombinationToSet( gwcd_list.get( i ),
1909 all_bin_domain_combinations_encountered );
1911 if ( query_domains_writer_ary != null ) {
1912 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1914 SurfacingUtil.extractProteinNames( protein_list,
1915 query_domain_ids_array[ j ],
1916 query_domains_writer_ary[ j ],
1918 query_domains_writer_ary[ j ].flush();
1920 catch ( final IOException e ) {
1921 e.printStackTrace();
1925 if ( need_protein_lists_per_species ) {
1926 protein_lists_per_species.put( new BasicSpecies( input_file_properties[ i ][ 1 ] ), protein_list );
1931 catch ( final IOException e2 ) {
1932 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1935 } // for( int i = 0; i < number_of_genomes; ++i ) {
1937 per_genome_domain_promiscuity_statistics_writer.flush();
1938 per_genome_domain_promiscuity_statistics_writer.close();
1939 dc_data_writer.flush();
1940 dc_data_writer.close();
1944 catch ( final IOException e2 ) {
1945 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1947 ForesterUtil.programMessage( PRG_NAME, "Wrote domain promiscuities to: "
1948 + per_genome_domain_promiscuity_statistics_file );
1949 if ( query_domains_writer_ary != null ) {
1950 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1952 query_domains_writer_ary[ j ].close();
1954 catch ( final IOException e ) {
1955 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1959 if ( PERFORM_DOMAIN_LENGTH_ANALYSIS ) {
1961 SurfacingUtil.executeDomainLengthAnalysis( input_file_properties,
1963 domain_lengths_table,
1964 domain_lengths_analysis_outfile );
1966 catch ( final IOException e1 ) {
1967 ForesterUtil.fatalError( surfacing.PRG_NAME, e1.toString() );
1969 System.out.println();
1970 ForesterUtil.programMessage( PRG_NAME, "Wrote domain length data to: " + domain_lengths_analysis_outfile );
1971 System.out.println();
1973 final long analysis_start_time = new Date().getTime();
1974 PairwiseDomainSimilarityCalculator pw_calc = null;
1975 // double[] values_for_all_scores_histogram = null;
1976 final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( domain_similarity_sort_field,
1977 sort_by_species_count_first,
1978 number_of_genomes == 2 );
1979 switch ( scoring ) {
1981 pw_calc = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1984 pw_calc = new DomainCountsBasedPairwiseSimilarityCalculator();
1987 pw_calc = new ProteinCountsBasedPairwiseDomainSimilarityCalculator();
1990 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1992 DomainSimilarityCalculator.GoAnnotationOutput go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.NONE;
1993 if ( domain_id_to_go_ids_map != null ) {
1994 go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.ALL;
1996 final SortedSet<DomainSimilarity> similarities = calc
1997 .calculateSimilarities( pw_calc,
1999 ignore_domains_without_combs_in_all_spec,
2000 ignore_species_specific_domains );
2001 SurfacingUtil.decoratePrintableDomainSimilarities( similarities,
2003 go_annotation_output,
2005 go_namespace_limit );
2006 DescriptiveStatistics pw_stats = null;
2008 String my_outfile = output_file.toString();
2009 if ( !my_outfile.endsWith( ".html" ) ) {
2010 my_outfile += ".html";
2012 final Writer writer = new BufferedWriter( new FileWriter( out_dir == null ? my_outfile : out_dir
2013 + ForesterUtil.FILE_SEPARATOR + my_outfile ) );
2014 List<Species> species_order = null;
2015 if ( species_matrix ) {
2016 species_order = new ArrayList<Species>();
2017 for( int i = 0; i < number_of_genomes; i++ ) {
2018 species_order.add( new BasicSpecies( input_file_properties[ i ][ 1 ] ) );
2021 html_desc.append( "<tr><td>Sum of all distinct binary combinations:</td><td>"
2022 + all_bin_domain_combinations_encountered.size() + "</td></tr>" + nl );
2023 html_desc.append( "<tr><td>Sum of all distinct domains:</td><td>" + all_domains_encountered.size()
2024 + "</td></tr>" + nl );
2025 html_desc.append( "<tr><td>Analysis date/time:</td><td>"
2026 + new java.text.SimpleDateFormat( "yyyy.MM.dd HH:mm:ss" ).format( new java.util.Date() )
2027 + "</td></tr>" + nl );
2028 html_desc.append( "</table>" + nl );
2029 pw_stats = SurfacingUtil
2030 .writeDomainSimilaritiesToFile( html_desc,
2031 new StringBuilder( number_of_genomes + " genomes" ),
2034 number_of_genomes == 2,
2036 domain_similarity_print_option,
2037 domain_similarity_sort_field,
2040 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote main output (includes domain similarities) to: \""
2041 + ( out_dir == null ? my_outfile : out_dir + ForesterUtil.FILE_SEPARATOR + my_outfile ) + "\"" );
2043 catch ( final IOException e ) {
2044 ForesterUtil.fatalError( surfacing.PRG_NAME, "Failed to write similarites to: \"" + output_file + "\" ["
2045 + e.getMessage() + "]" );
2047 System.out.println();
2048 // values_for_all_scores_histogram = pw_stats.getDataAsDoubleArray();
2049 final Species[] species = new Species[ number_of_genomes ];
2050 for( int i = 0; i < number_of_genomes; ++i ) {
2051 species[ i ] = new BasicSpecies( input_file_properties[ i ][ 1 ] );
2053 List<Phylogeny> inferred_trees = null;
2054 if ( ( number_of_genomes > 2 ) && perform_pwc ) {
2055 final PairwiseGenomeComparator pwgc = new PairwiseGenomeComparator();
2056 pwgc.performPairwiseComparisons( html_desc,
2057 sort_by_species_count_first,
2059 ignore_domains_without_combs_in_all_spec,
2060 ignore_species_specific_domains,
2061 domain_similarity_sort_field_for_automated_pwc,
2062 domain_similarity_print_option,
2064 domain_id_to_go_ids_map,
2071 automated_pairwise_comparison_suffix,
2073 surfacing.PAIRWISE_DOMAIN_COMPARISONS_PREFIX,
2078 String matrix_output_file = new String( output_file.toString() );
2079 if ( matrix_output_file.indexOf( '.' ) > 1 ) {
2080 matrix_output_file = matrix_output_file.substring( 0, matrix_output_file.indexOf( '.' ) );
2082 if ( out_dir != null ) {
2083 matrix_output_file = out_dir + ForesterUtil.FILE_SEPARATOR + matrix_output_file;
2084 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
2086 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
2087 + surfacing.MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc.getDomainDistanceScoresMeans() );
2089 .writeMatrixToFile( new File( matrix_output_file
2090 + surfacing.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
2091 pwgc.getSharedBinaryCombinationsBasedDistances() );
2092 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
2093 + surfacing.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
2094 pwgc.getSharedDomainsBasedDistances() );
2095 final Phylogeny nj_gd = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2096 + surfacing.NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc.getDomainDistanceScoresMeans()
2098 final Phylogeny nj_bc = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2099 + surfacing.NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2100 .getSharedBinaryCombinationsBasedDistances().get( 0 ) );
2101 final Phylogeny nj_d = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2102 + surfacing.NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2103 .getSharedDomainsBasedDistances().get( 0 ) );
2104 inferred_trees = new ArrayList<Phylogeny>();
2105 inferred_trees.add( nj_gd );
2106 inferred_trees.add( nj_bc );
2107 inferred_trees.add( nj_d );
2108 // final List<HistogramData> histogram_datas = pwgc.getHistogramDatas();
2109 // if ( infer_species_trees ) {
2110 // inferred_trees = new ArrayList<Phylogeny>();
2111 // final List<Phylogeny> inferred_trees_bc = inferSpeciesTrees( new File( output_file + INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2112 // .getSharedBinaryCombinationsBasedDistances() );
2113 // final List<Phylogeny> inferred_trees_d = inferSpeciesTrees( new File( output_file + INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2114 // .getSharedDomainsBasedDistances() );
2115 // inferred_trees.addAll( inferred_trees_bc );
2116 // inferred_trees.addAll( inferred_trees_d );
2118 if ( jacknifed_distances ) {
2119 pwgc.performPairwiseComparisonsJacknifed( species,
2123 jacknife_resamplings,
2127 .writeMatrixToFile( new File( matrix_output_file
2129 + ForesterUtil.round( jacknife_ratio, 2 )
2131 + jacknife_resamplings
2132 + surfacing.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
2133 pwgc.getSharedBinaryCombinationsBasedDistances() );
2135 .writeMatrixToFile( new File( matrix_output_file + "_" + ForesterUtil.round( jacknife_ratio, 2 )
2136 + "_" + jacknife_resamplings
2137 + surfacing.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
2138 pwgc.getSharedDomainsBasedDistances() );
2139 // if ( infer_species_trees ) {
2140 // inferSpeciesTrees( new File( output_file + "_" + jacknife_resamplings
2141 // + INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2142 // .getSharedBinaryCombinationsBasedDistances() );
2143 // inferSpeciesTrees( new File( output_file + "_" + jacknife_resamplings
2144 // + INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc.getSharedDomainsBasedDistances() );
2147 if ( display_histograms ) {
2148 // final List<HistogramData> histogram_datas_all = new ArrayList<HistogramData>();
2149 // histogram_datas_all.add( new HistogramData( "all",
2150 // values_for_all_scores_histogram,
2153 // final HistogramsFrame hf_all = new HistogramsFrame( histogram_datas_all );
2154 // final HistogramsFrame hf = new HistogramsFrame( histogram_datas );
2155 // hf_all.setVisible( true );
2156 // hf.setVisible( true );
2158 } // if ( ( output_file != null ) && ( number_of_genomes > 2 ) && !isEmpty( automated_pairwise_comparison_suffix ) )
2159 if ( ( out_dir != null ) && ( !perform_pwc ) ) {
2160 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
2162 writePresentToNexus( output_file, positive_filter_file, filter, gwcd_list );
2163 if ( ( ( intrees != null ) && ( intrees.length > 0 ) ) && ( number_of_genomes > 2 ) ) {
2164 final StringBuilder parameters_sb = createParametersAsString( ignore_dufs,
2166 max_allowed_overlap,
2167 no_engulfing_overlaps,
2171 if ( radomize_fitch_parsimony ) {
2172 s += random_number_seed_for_fitch_parsimony + "_";
2175 for( final Phylogeny intree : intrees ) {
2176 final String outfile_name = ForesterUtil.removeSuffix( output_file.toString() ) + s
2177 + ForesterUtil.removeSuffix( intree_files[ i ].toString() );
2178 final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator.createInstance( intree,
2180 SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
2181 radomize_fitch_parsimony,
2185 domain_id_to_go_ids_map,
2188 parameters_sb.toString(),
2189 domain_id_to_secondary_features_maps,
2190 positive_filter_file == null ? null : filter,
2191 output_binary_domain_combinationsfor_graph_analysis,
2192 all_bin_domain_combinations_gained_fitch,
2193 all_bin_domain_combinations_lost_fitch,
2195 // Listing of all domain combinations gained is only done if only one input tree is used.
2196 if ( ( domain_id_to_secondary_features_maps != null )
2197 && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
2199 for( final Map<DomainId, Set<String>> domain_id_to_secondary_features_map : domain_id_to_secondary_features_maps ) {
2200 final Map<Species, MappingResults> mapping_results_map = new TreeMap<Species, MappingResults>();
2201 final DomainParsimonyCalculator secondary_features_parsimony = DomainParsimonyCalculator
2202 .createInstance( intree, gwcd_list, domain_id_to_secondary_features_map );
2204 .executeParsimonyAnalysisForSecondaryFeatures( outfile_name
2206 + secondary_features_map_files[ j++ ],
2207 secondary_features_parsimony,
2209 parameters_sb.toString(),
2210 mapping_results_map );
2212 System.out.println();
2213 System.out.println( "Mapping to secondary features:" );
2214 for( final Species spec : mapping_results_map.keySet() ) {
2215 final MappingResults mapping_results = mapping_results_map.get( spec );
2216 final int total_domains = mapping_results.getSumOfFailures()
2217 + mapping_results.getSumOfSuccesses();
2218 System.out.print( spec + ":" );
2219 System.out.print( " mapped domains = " + mapping_results.getSumOfSuccesses() );
2220 System.out.print( ", not mapped domains = " + mapping_results.getSumOfFailures() );
2221 if ( total_domains > 0 ) {
2222 System.out.println( ", mapped ratio = "
2223 + ( 100 * mapping_results.getSumOfSuccesses() / total_domains ) + "%" );
2226 System.out.println( ", mapped ratio = n/a (total domains = 0 )" );
2233 } // for( final Phylogeny intree : intrees ) {
2235 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
2236 executePlusMinusAnalysis( output_file,
2237 plus_minus_analysis_high_copy_base_species,
2238 plus_minus_analysis_high_copy_target_species,
2239 plus_minus_analysis_high_low_copy_species,
2241 protein_lists_per_species,
2242 domain_id_to_go_ids_map,
2244 plus_minus_analysis_numbers );
2246 if ( output_protein_lists_for_all_domains ) {
2247 writeProteinListsForAllSpecies( out_dir, protein_lists_per_species, gwcd_list );
2249 // if ( ( intrees != null ) && ( intrees.length > 0 ) && ( inferred_trees != null ) && ( inferred_trees.size() > 0 ) ) {
2250 // final StringBuilder parameters_sb = createParametersAsString( ignore_dufs,
2252 // max_allowed_overlap,
2253 // no_engulfing_overlaps,
2254 // cutoff_scores_file );
2256 // if ( radomize_fitch_parsimony ) {
2257 // s += random_number_seed_for_fitch_parsimony + "_";
2260 // for( final Phylogeny inferred_tree : inferred_trees ) {
2261 // if ( !inferred_tree.isRooted() ) {
2262 // intrees[ 0 ].getRoot().getName();
2265 // final String outfile_name = ForesterUtil.removeSuffix( inferred_tree.getName() ) + s;
2266 // final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator
2267 // .createInstance( inferred_tree, gwcd_list );
2268 // SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
2269 // radomize_fitch_parsimony,
2271 // domain_parsimony,
2273 // domain_id_to_go_ids_map,
2274 // go_id_to_term_map,
2275 // go_namespace_limit,
2276 // parameters_sb.toString() );
2280 if ( all_bin_domain_combinations_gained_fitch != null ) {
2282 executeFitchGainsAnalysis( new File( output_file
2283 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2284 all_bin_domain_combinations_gained_fitch,
2285 all_domains_encountered.size(),
2286 all_bin_domain_combinations_encountered,
2289 catch ( final IOException e ) {
2290 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2293 if ( all_bin_domain_combinations_lost_fitch != null ) {
2295 executeFitchGainsAnalysis( new File( output_file
2296 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2297 all_bin_domain_combinations_lost_fitch,
2298 all_domains_encountered.size(),
2299 all_bin_domain_combinations_encountered,
2302 catch ( final IOException e ) {
2303 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2306 final Runtime rt = java.lang.Runtime.getRuntime();
2307 final long free_memory = rt.freeMemory() / 1000000;
2308 final long total_memory = rt.totalMemory() / 1000000;
2309 System.out.println();
2310 System.out.println( "Time for analysis : " + ( new Date().getTime() - analysis_start_time ) + "ms" );
2311 System.out.println( "Total running time: " + ( new Date().getTime() - start_time ) + "ms " );
2312 System.out.println( "Free memory : " + free_memory + "MB, total memory: " + total_memory + "MB" );
2313 System.out.println();
2314 System.out.println( "If this application is useful to you, please cite:" );
2315 System.out.println( surfacing.WWW );
2316 System.out.println();
2317 ForesterUtil.programMessage( PRG_NAME, "OK" );
2318 System.out.println();
2321 private static void preparePhylogenyForParsimonyAnalyses( final Phylogeny intree,
2322 final String[][] input_file_properties ) {
2323 final String[] genomes = new String[ input_file_properties.length ];
2324 for( int i = 0; i < input_file_properties.length; ++i ) {
2325 if ( intree.getNodes( input_file_properties[ i ][ 1 ] ).size() > 1 ) {
2326 ForesterUtil.fatalError( surfacing.PRG_NAME, "node named [" + input_file_properties[ i ][ 1 ]
2327 + "] is not unique in input tree " + intree.getName() );
2329 genomes[ i ] = input_file_properties[ i ][ 1 ];
2332 final PhylogenyNodeIterator it = intree.iteratorPostorder();
2333 while ( it.hasNext() ) {
2334 final PhylogenyNode n = it.next();
2335 if ( ForesterUtil.isEmpty( n.getName() ) ) {
2336 if ( n.getNodeData().isHasTaxonomy()
2337 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
2338 n.setName( n.getNodeData().getTaxonomy().getScientificName() );
2341 ForesterUtil.fatalError( surfacing.PRG_NAME,
2342 "node without both name and scientific taxonomy name found" );
2347 final List<String> igns = PhylogenyMethods.deleteExternalNodesPositiveSelection( genomes, intree );
2348 if ( igns.size() > 0 ) {
2349 System.out.println( "Not using the following " + igns.size() + " nodes:" );
2350 for( int i = 0; i < igns.size(); ++i ) {
2351 System.out.println( " " + i + ": " + igns.get( i ) );
2353 System.out.println( "--" );
2355 for( int i = 0; i < input_file_properties.length; ++i ) {
2357 intree.getNode( input_file_properties[ i ][ 1 ] );
2359 catch ( final IllegalArgumentException e ) {
2360 ForesterUtil.fatalError( surfacing.PRG_NAME, "node named [" + input_file_properties[ i ][ 1 ]
2361 + "] not present/not unique in input tree" );
2366 // public static StringBuffer stringCombinableDomainsMapToStringBuffer(
2367 // final SortedMap<String, CombinableDomains> map ) {
2368 // final StringBuffer sb = new StringBuffer();
2369 // for( final Iterator<String> iter = map.keySet().iterator();
2370 // iter.hasNext(); ) {
2371 // final Object key = iter.next();
2372 // sb.append( ForesterUtil.pad( new StringBuffer( key.toString() ), 18, ' ',
2374 // final CombinableDomains domain_combination = map.get( key );
2375 // sb.append( ForesterUtil.pad( new StringBuffer( "" +
2376 // domain_combination.getNumberOfCombiningDomains() ), 8,
2378 // sb.append( domain_combination.toStringBuffer() );
2379 // sb.append( ForesterUtil.getLineSeparator() );
2383 private static void printHelp() {
2384 System.out.println();
2385 System.out.println( "Usage:" );
2386 System.out.println();
2387 System.out.println( "% java -Xms256m -Xmx512m -cp forester.jar org.forester.applications." + surfacing.PRG_NAME
2388 + " [options] <phylogen(y|ies) infile> [external node name 1] [name 2] ... [name n]" );
2389 System.out.println();
2390 System.out.println( " Note: This software might need a significant amount of memory (heap space);" );
2392 .println( " hence use \"-Xms128m -Xmx512m\" (or more) to prevent a \"java.lang.OutOfMemoryError\"." );
2393 System.out.println();
2394 System.out.println( " Options: " );
2395 System.out.println( surfacing.DETAILEDNESS_OPTION + ": level of detail for similarities output file (default:"
2396 + DETAILEDNESS_DEFAULT + ")" );
2397 System.out.println( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION
2398 + ": to ignore combinations with self (default: not to ignore)" );
2400 .println( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION
2401 + ": to ignore domains without combinations in any species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2403 .println( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION
2404 + ": to ignore domains specific to one species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2405 System.out.println( surfacing.NOT_IGNORE_DUFS_OPTION
2406 + ": to _not_ ignore DUFs (domains with unknown function) (default: ignore DUFs)" );
2408 .println( surfacing.IGNORE_VIRAL_IDS
2409 + ": to ignore domains with ids containing 'vir', 'retro', 'transpos', 'phage', or starting with 'rv' or 'gag_'" );
2410 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_OPTION + ": sorting for similarities (default: "
2411 + DOMAIN_SORT_FILD_DEFAULT + ")" );
2412 System.out.println( surfacing.OUTPUT_FILE_OPTION + ": name for (main) output file (mandatory)" );
2413 System.out.println( surfacing.MAX_E_VALUE_OPTION + ": max (inclusive) E-value" );
2414 System.out.println( surfacing.MAX_ALLOWED_OVERLAP_OPTION + ": maximal allowed domain overlap" );
2415 System.out.println( surfacing.NO_ENGULFING_OVERLAP_OPTION + ": to ignore engulfed lower confidence domains" );
2416 System.out.println( surfacing.SPECIES_MATRIX_OPTION + ": species matrix" );
2417 System.out.println( surfacing.SCORING_OPTION + ": scoring (default:" + SCORING_DEFAULT + ")" );
2418 System.out.println( surfacing.DOMAIN_COUNT_SORT_OPTION + ": sorting for domain counts (default:"
2419 + DOMAINS_SORT_ORDER_DEFAULT + ")" );
2420 System.out.println( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION + ": domain similarity print option (default:"
2421 + DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT + ")" );
2422 System.out.println( surfacing.CUTOFF_SCORE_FILE_OPTION + ": cutoff score file" );
2423 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION
2424 + ": sort by species count first" );
2425 System.out.println( surfacing.OUTPUT_DIR_OPTION + ": output directory" );
2426 System.out.println( surfacing.PFAM_TO_GO_FILE_USE_OPTION + ": Pfam to GO mapping file" );
2427 System.out.println( surfacing.GO_OBO_FILE_USE_OPTION + ": GO terms file (OBO format)" );
2428 System.out.println( surfacing.GO_NAMESPACE_LIMIT_OPTION + ": limit GO term to one GO namespace" );
2429 System.out.println( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
2430 + "[=<suffix for pairwise comparison output files>]: to perform pairwise comparison based analyses" );
2431 System.out.println( surfacing.INPUT_SPECIES_TREE_OPTION
2432 + ": species tree, to perform (Dollo, Fitch) parismony analyses" );
2434 .println( surfacing.DISPLAY_M_HISTOGRAMS_OPTION + ": to display multiple histograms (using fluorite)" );
2436 .println( JACKNIFE_OPTION
2437 + ": perform jacknife resampling for domain and binary domain combination based distance matrices [default resamplings: "
2438 + JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT + "]" );
2439 System.out.println( JACKNIFE_RATIO_OPTION + ": ratio for jacknife resampling [default: "
2440 + JACKNIFE_RATIO_DEFAULT + "]" );
2441 System.out.println( JACKNIFE_RANDOM_SEED_OPTION
2442 + ": seed for random number generator for jacknife resampling [default: "
2443 + JACKNIFE_RANDOM_SEED_DEFAULT + "]" );
2444 // System.out.println( surfacing.INFER_SPECIES_TREES_OPTION
2445 // + ": to infer NJ species trees based on shared domains/binary domain combinations" );
2447 .println( surfacing.INPUT_SPECIES_TREE_OPTION
2448 + "=<treefiles in phyloXML format, separated by #>: to infer domain/binary domain combination gains/losses on given species trees" );
2449 System.out.println( surfacing.FILTER_POSITIVE_OPTION
2450 + "=<file>: to filter out proteins not containing at least one domain listed in <file>" );
2451 System.out.println( surfacing.FILTER_NEGATIVE_OPTION
2452 + "=<file>: to filter out proteins containing at least one domain listed in <file>" );
2453 System.out.println( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION
2454 + "=<file>: to filter out (ignore) domains listed in <file>" );
2455 System.out.println( surfacing.INPUT_FILES_FROM_FILE_OPTION + "=<file>: to read input files from <file>" );
2457 .println( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION
2458 + "=<seed>: seed for random number generator for Fitch Parsimony analysis (type: long, default: no randomization - given a choice, prefer absence" );
2459 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS
2460 + ": to consider directedness in binary combinations: e.g. A-B != B-A" );
2461 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY
2462 + ": to consider directedness and adjacency in binary combinations" );
2464 .println( surfacing.SEQ_EXTRACT_OPTION
2465 + "=<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')" );
2466 System.out.println( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE
2467 + "=<file>: to perfom parsimony analysis on secondary features" );
2468 System.out.println( surfacing.PLUS_MINUS_ANALYSIS_OPTION + "=<file>: to presence/absence genome analysis" );
2469 System.out.println( surfacing.DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS
2470 + ": to output binary domain combinations for (downstream) graph analysis" );
2471 System.out.println( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS + ": to output all proteins per domain" );
2472 System.out.println();
2473 System.out.println();
2474 System.out.println( "Example: java -Xms128m -Xmx512m -cp path/to/forester.jar"
2475 + "org.forester.application.surfacing -detail=punctilious -o=TEST.html -pwc=TEST"
2476 + " -cos=Pfam_ls_22_TC2 -p2g=pfam2go -obo=gene_ontology_edit.obo "
2477 + "-dc_sort=dom -ignore_with_self -no_singles -e=0.001 -mo=1 -no_eo "
2478 + "-ds_output=detailed_html -scoring=domains -sort=alpha -" + JACKNIFE_OPTION
2479 + "=50 human mouse brafl strpu" );
2480 System.out.println();
2483 private static void processFilter( final File filter_file, final SortedSet<DomainId> filter ) {
2484 SortedSet<String> filter_str = null;
2486 filter_str = ForesterUtil.file2set( filter_file );
2488 catch ( final IOException e ) {
2489 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
2491 if ( filter_str != null ) {
2492 for( final String string : filter_str ) {
2493 filter.add( new DomainId( string ) );
2497 System.out.println( "Filter:" );
2498 for( final DomainId domainId : filter ) {
2499 System.out.println( domainId.getId() );
2504 private static String[][] processInputFileNames( final String[] names ) {
2505 final String[][] input_file_properties = new String[ names.length ][];
2506 for( int i = 0; i < names.length; ++i ) {
2507 if ( names[ i ].indexOf( SEPARATOR_FOR_INPUT_VALUES ) < 0 ) {
2508 input_file_properties[ i ] = new String[ 2 ];
2509 input_file_properties[ i ][ 0 ] = names[ i ];
2510 input_file_properties[ i ][ 1 ] = names[ i ];
2513 input_file_properties[ i ] = names[ i ].split( surfacing.SEPARATOR_FOR_INPUT_VALUES + "" );
2514 if ( input_file_properties[ i ].length != 3 ) {
2516 .fatalError( surfacing.PRG_NAME,
2517 "properties for the input files (hmmpfam output) are expected "
2518 + "to be in the following format \"<hmmpfam output file>#<species>\" (or just one word, which is both the filename and the species id), instead received \""
2519 + names[ i ] + "\"" );
2522 final String error = ForesterUtil.isReadableFile( new File( input_file_properties[ i ][ 0 ] ) );
2523 if ( !ForesterUtil.isEmpty( error ) ) {
2524 ForesterUtil.fatalError( surfacing.PRG_NAME, error );
2527 return input_file_properties;
2530 private static void processPlusMinusAnalysisOption( final CommandLineArguments cla,
2531 final List<String> high_copy_base,
2532 final List<String> high_copy_target,
2533 final List<String> low_copy,
2534 final List<Object> numbers ) {
2535 if ( cla.isOptionSet( surfacing.PLUS_MINUS_ANALYSIS_OPTION ) ) {
2536 if ( !cla.isOptionValueSet( surfacing.PLUS_MINUS_ANALYSIS_OPTION ) ) {
2537 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for 'plus-minus' file: -"
2538 + surfacing.PLUS_MINUS_ANALYSIS_OPTION + "=<file>" );
2540 final File plus_minus_file = new File( cla.getOptionValue( surfacing.PLUS_MINUS_ANALYSIS_OPTION ) );
2541 final String msg = ForesterUtil.isReadableFile( plus_minus_file );
2542 if ( !ForesterUtil.isEmpty( msg ) ) {
2543 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + plus_minus_file + "\": " + msg );
2545 processPlusMinusFile( plus_minus_file, high_copy_base, high_copy_target, low_copy, numbers );
2549 // First numbers is minimal difference, second is factor.
2550 private static void processPlusMinusFile( final File plus_minus_file,
2551 final List<String> high_copy_base,
2552 final List<String> high_copy_target,
2553 final List<String> low_copy,
2554 final List<Object> numbers ) {
2555 Set<String> species_set = null;
2556 int min_diff = PLUS_MINUS_ANALYSIS_MIN_DIFF_DEFAULT;
2557 double factor = PLUS_MINUS_ANALYSIS_FACTOR_DEFAULT;
2559 species_set = ForesterUtil.file2set( plus_minus_file );
2561 catch ( final IOException e ) {
2562 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
2564 if ( species_set != null ) {
2565 for( final String species : species_set ) {
2566 final String species_trimmed = species.substring( 1 );
2567 if ( species.startsWith( "+" ) ) {
2568 if ( low_copy.contains( species_trimmed ) ) {
2569 ForesterUtil.fatalError( surfacing.PRG_NAME,
2570 "species/genome names can not appear with both '+' and '-' suffix, as appears the case for: \""
2571 + species_trimmed + "\"" );
2573 high_copy_base.add( species_trimmed );
2575 else if ( species.startsWith( "*" ) ) {
2576 if ( low_copy.contains( species_trimmed ) ) {
2577 ForesterUtil.fatalError( surfacing.PRG_NAME,
2578 "species/genome names can not appear with both '*' and '-' suffix, as appears the case for: \""
2579 + species_trimmed + "\"" );
2581 high_copy_target.add( species_trimmed );
2583 else if ( species.startsWith( "-" ) ) {
2584 if ( high_copy_base.contains( species_trimmed ) || high_copy_target.contains( species_trimmed ) ) {
2585 ForesterUtil.fatalError( surfacing.PRG_NAME,
2586 "species/genome names can not appear with both '+' or '*' and '-' suffix, as appears the case for: \""
2587 + species_trimmed + "\"" );
2589 low_copy.add( species_trimmed );
2591 else if ( species.startsWith( "$D" ) ) {
2593 min_diff = Integer.parseInt( species.substring( 3 ) );
2595 catch ( final NumberFormatException e ) {
2596 ForesterUtil.fatalError( surfacing.PRG_NAME,
2597 "could not parse integer value for minimal difference from: \""
2598 + species.substring( 3 ) + "\"" );
2601 else if ( species.startsWith( "$F" ) ) {
2603 factor = Double.parseDouble( species.substring( 3 ) );
2605 catch ( final NumberFormatException e ) {
2606 ForesterUtil.fatalError( surfacing.PRG_NAME, "could not parse double value for factor from: \""
2607 + species.substring( 3 ) + "\"" );
2610 else if ( species.startsWith( "#" ) ) {
2615 .fatalError( surfacing.PRG_NAME,
2616 "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: \""
2619 numbers.add( new Integer( min_diff + "" ) );
2620 numbers.add( new Double( factor + "" ) );
2624 ForesterUtil.fatalError( surfacing.PRG_NAME, "'plus minus' file [" + plus_minus_file + "] appears empty" );
2628 private static void writePresentToNexus( final File output_file,
2629 final File positive_filter_file,
2630 final SortedSet<DomainId> filter,
2631 final List<GenomeWideCombinableDomains> gwcd_list ) {
2634 .writeMatrixToFile( DomainParsimonyCalculator
2635 .createMatrixOfDomainPresenceOrAbsence( gwcd_list, positive_filter_file == null ? null
2636 : filter ), output_file + DOMAINS_PRESENT_NEXUS, Format.NEXUS_BINARY );
2637 SurfacingUtil.writeMatrixToFile( DomainParsimonyCalculator
2638 .createMatrixOfBinaryDomainCombinationPresenceOrAbsence( gwcd_list ), output_file
2639 + BDC_PRESENT_NEXUS, Format.NEXUS_BINARY );
2641 catch ( final Exception e ) {
2642 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
2646 private static void writeProteinListsForAllSpecies( final File output_dir,
2647 final SortedMap<Species, List<Protein>> protein_lists_per_species,
2648 final List<GenomeWideCombinableDomains> gwcd_list ) {
2649 final SortedSet<DomainId> all_domains = new TreeSet<DomainId>();
2650 for( final GenomeWideCombinableDomains gwcd : gwcd_list ) {
2651 all_domains.addAll( gwcd.getAllDomainIds() );
2653 for( final DomainId domain : all_domains ) {
2654 final File out = new File( output_dir + ForesterUtil.FILE_SEPARATOR + domain + SEQ_EXTRACT_SUFFIX );
2655 SurfacingUtil.checkForOutputFileWriteability( out );
2657 final Writer proteins_file_writer = new BufferedWriter( new FileWriter( out ) );
2658 SurfacingUtil.extractProteinNames( protein_lists_per_species, domain, proteins_file_writer, "\t" );
2659 proteins_file_writer.close();
2661 catch ( final IOException e ) {
2662 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
2664 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote proteins list to \"" + out + "\"" );