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.DomainSimilarityCalculator;
75 import org.forester.surfacing.GenomeWideCombinableDomains;
76 import org.forester.surfacing.MappingResults;
77 import org.forester.surfacing.PairwiseDomainSimilarityCalculator;
78 import org.forester.surfacing.PairwiseGenomeComparator;
79 import org.forester.surfacing.PrintableDomainSimilarity;
80 import org.forester.surfacing.Protein;
81 import org.forester.surfacing.ProteinCountsBasedPairwiseDomainSimilarityCalculator;
82 import org.forester.surfacing.Species;
83 import org.forester.surfacing.SurfacingUtil;
84 import org.forester.surfacing.DomainSimilarity.DomainSimilarityScoring;
85 import org.forester.surfacing.DomainSimilarity.DomainSimilaritySortField;
86 import org.forester.surfacing.DomainSimilarityCalculator.Detailedness;
87 import org.forester.surfacing.GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder;
88 import org.forester.surfacing.PrintableDomainSimilarity.PRINT_OPTION;
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, "number of external nodes ["
526 + intree.getNumberOfExternalNodes() + "] of input tree [" + intree_file
527 + "] is smaller than the number of genomes the be analyzed [" + number_of_genomes + "]" );
529 final StringBuilder parent_names = new StringBuilder();
530 final int nodes_lacking_name = SurfacingUtil.getNumberOfNodesLackingName( intree, parent_names );
531 if ( nodes_lacking_name > 0 ) {
532 ForesterUtil.fatalError( surfacing.PRG_NAME, "input tree [" + intree_file + "] has "
533 + nodes_lacking_name + " node(s) lacking a name [parent names:" + parent_names + "]" );
535 preparePhylogenyForParsimonyAnalyses( intree, input_file_properties );
536 if ( !intree.isCompletelyBinary() ) {
537 ForesterUtil.printWarningMessage( surfacing.PRG_NAME, "input tree [" + intree_file
538 + "] is not completely binary" );
540 intrees[ i++ ] = intree;
545 private static List<Phylogeny> inferSpeciesTrees( final File outfile, final List<DistanceMatrix> distances_list ) {
546 final NeighborJoining nj = NeighborJoining.createInstance();
547 final List<Phylogeny> phylogenies = nj.execute( distances_list );
548 final PhylogenyWriter w = new PhylogenyWriter();
550 w.toNewHampshire( phylogenies, true, true, outfile, ";" );
552 catch ( final IOException e ) {
553 ForesterUtil.fatalError( PRG_NAME, "failed to write to outfile [" + outfile + "]: " + e.getMessage() );
558 private static void log( final String msg, final Writer w ) {
561 w.write( ForesterUtil.LINE_SEPARATOR );
563 catch ( final IOException e ) {
564 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
568 public static void main( final String args[] ) {
569 final long start_time = new Date().getTime();
570 // final StringBuffer log = new StringBuffer();
571 final StringBuilder html_desc = new StringBuilder();
572 ForesterUtil.printProgramInformation( surfacing.PRG_NAME,
573 surfacing.PRG_VERSION,
577 final String nl = ForesterUtil.LINE_SEPARATOR;
578 html_desc.append( "<table>" + nl );
579 html_desc.append( "<tr><td>Produced by:</td><td>" + surfacing.PRG_NAME + "</td></tr>" + nl );
580 html_desc.append( "<tr><td>Version:</td><td>" + surfacing.PRG_VERSION + "</td></tr>" + nl );
581 html_desc.append( "<tr><td>Release Date:</td><td>" + surfacing.PRG_DATE + "</td></tr>" + nl );
582 html_desc.append( "<tr><td>Contact:</td><td>" + surfacing.E_MAIL + "</td></tr>" + nl );
583 html_desc.append( "<tr><td>WWW:</td><td>" + surfacing.WWW + "</td></tr>" + nl );
584 CommandLineArguments cla = null;
586 cla = new CommandLineArguments( args );
588 catch ( final Exception e ) {
589 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
591 if ( cla.isOptionSet( surfacing.HELP_OPTION_1 ) || cla.isOptionSet( surfacing.HELP_OPTION_2 ) ) {
592 surfacing.printHelp();
595 if ( ( args.length < 1 ) ) {
596 surfacing.printHelp();
599 final List<String> allowed_options = new ArrayList<String>();
600 allowed_options.add( surfacing.NOT_IGNORE_DUFS_OPTION );
601 allowed_options.add( surfacing.MAX_E_VALUE_OPTION );
602 allowed_options.add( surfacing.DETAILEDNESS_OPTION );
603 allowed_options.add( surfacing.OUTPUT_FILE_OPTION );
604 allowed_options.add( surfacing.DOMAIN_SIMILARITY_SORT_OPTION );
605 allowed_options.add( surfacing.SPECIES_MATRIX_OPTION );
606 allowed_options.add( surfacing.SCORING_OPTION );
607 allowed_options.add( surfacing.MAX_ALLOWED_OVERLAP_OPTION );
608 allowed_options.add( surfacing.NO_ENGULFING_OVERLAP_OPTION );
609 allowed_options.add( surfacing.DOMAIN_COUNT_SORT_OPTION );
610 allowed_options.add( surfacing.CUTOFF_SCORE_FILE_OPTION );
611 allowed_options.add( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION );
612 allowed_options.add( surfacing.OUTPUT_DIR_OPTION );
613 allowed_options.add( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION );
614 allowed_options.add( surfacing.PFAM_TO_GO_FILE_USE_OPTION );
615 allowed_options.add( surfacing.GO_OBO_FILE_USE_OPTION );
616 allowed_options.add( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION );
617 allowed_options.add( surfacing.GO_NAMESPACE_LIMIT_OPTION );
618 allowed_options.add( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
619 allowed_options.add( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION );
620 allowed_options.add( surfacing.DISPLAY_M_HISTOGRAMS_OPTION );
621 allowed_options.add( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS );
622 allowed_options.add( JACKNIFE_OPTION );
623 allowed_options.add( JACKNIFE_RANDOM_SEED_OPTION );
624 allowed_options.add( JACKNIFE_RATIO_OPTION );
625 allowed_options.add( INPUT_SPECIES_TREE_OPTION );
626 //allowed_options.add( INFER_SPECIES_TREES_OPTION );
627 allowed_options.add( FILTER_POSITIVE_OPTION );
628 allowed_options.add( FILTER_NEGATIVE_OPTION );
629 allowed_options.add( INPUT_FILES_FROM_FILE_OPTION );
630 allowed_options.add( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
631 allowed_options.add( FILTER_NEGATIVE_DOMAINS_OPTION );
632 allowed_options.add( IGNORE_VIRAL_IDS );
633 allowed_options.add( SEQ_EXTRACT_OPTION );
634 allowed_options.add( SECONDARY_FEATURES_PARSIMONY_MAP_FILE );
635 allowed_options.add( PLUS_MINUS_ANALYSIS_OPTION );
636 allowed_options.add( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS );
637 allowed_options.add( OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS );
638 allowed_options.add( CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY );
639 boolean ignore_dufs = surfacing.IGNORE_DUFS_DEFAULT;
640 boolean ignore_combination_with_same = surfacing.IGNORE_COMBINATION_WITH_SAME_DEFAULLT;
641 double e_value_max = surfacing.MAX_E_VALUE_DEFAULT;
642 int max_allowed_overlap = surfacing.MAX_ALLOWED_OVERLAP_DEFAULT;
643 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
644 if ( dissallowed_options.length() > 0 ) {
645 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown option(s): " + dissallowed_options );
647 boolean output_binary_domain_combinationsfor_graph_analysis = false;
648 if ( cla.isOptionSet( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS ) ) {
649 output_binary_domain_combinationsfor_graph_analysis = true;
651 if ( cla.isOptionSet( surfacing.MAX_E_VALUE_OPTION ) ) {
653 e_value_max = cla.getOptionValueAsDouble( surfacing.MAX_E_VALUE_OPTION );
655 catch ( final Exception e ) {
656 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for E-value maximum" );
659 if ( cla.isOptionSet( surfacing.MAX_ALLOWED_OVERLAP_OPTION ) ) {
661 max_allowed_overlap = cla.getOptionValueAsInt( surfacing.MAX_ALLOWED_OVERLAP_OPTION );
663 catch ( final Exception e ) {
664 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for maximal allowed domain overlap" );
667 boolean no_engulfing_overlaps = false;
668 if ( cla.isOptionSet( surfacing.NO_ENGULFING_OVERLAP_OPTION ) ) {
669 no_engulfing_overlaps = true;
671 boolean ignore_virus_like_ids = false;
672 if ( cla.isOptionSet( surfacing.IGNORE_VIRAL_IDS ) ) {
673 ignore_virus_like_ids = true;
675 if ( cla.isOptionSet( surfacing.NOT_IGNORE_DUFS_OPTION ) ) {
678 if ( cla.isOptionSet( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION ) ) {
679 ignore_combination_with_same = true;
681 boolean ignore_domains_without_combs_in_all_spec = IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT;
682 if ( cla.isOptionSet( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION ) ) {
683 ignore_domains_without_combs_in_all_spec = true;
685 boolean ignore_species_specific_domains = IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT;
686 if ( cla.isOptionSet( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION ) ) {
687 ignore_species_specific_domains = true;
689 File output_file = null;
690 if ( cla.isOptionSet( surfacing.OUTPUT_FILE_OPTION ) ) {
691 if ( !cla.isOptionValueSet( surfacing.OUTPUT_FILE_OPTION ) ) {
692 ForesterUtil.fatalError( surfacing.PRG_NAME,
693 "no value for domain combinations similarities output file: -"
694 + surfacing.OUTPUT_FILE_OPTION + "=<file>" );
696 output_file = new File( cla.getOptionValue( surfacing.OUTPUT_FILE_OPTION ) );
697 SurfacingUtil.checkForOutputFileWriteability( output_file );
699 File cutoff_scores_file = null;
700 Map<String, Double> individual_score_cutoffs = null;
701 if ( cla.isOptionSet( surfacing.CUTOFF_SCORE_FILE_OPTION ) ) {
702 if ( !cla.isOptionValueSet( surfacing.CUTOFF_SCORE_FILE_OPTION ) ) {
703 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for individual domain score cutoffs file: -"
704 + surfacing.CUTOFF_SCORE_FILE_OPTION + "=<file>" );
706 cutoff_scores_file = new File( cla.getOptionValue( surfacing.CUTOFF_SCORE_FILE_OPTION ) );
707 final String error = ForesterUtil.isReadableFile( cutoff_scores_file );
708 if ( !ForesterUtil.isEmpty( error ) ) {
709 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read individual domain score cutoffs file: "
713 final BasicTable<String> scores_table = BasicTableParser.parse( cutoff_scores_file, " " );
714 individual_score_cutoffs = scores_table.getColumnsAsMapDouble( 0, 1 );
716 catch ( final IOException e ) {
717 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from individual score cutoffs file: " + e );
720 BinaryDomainCombination.DomainCombinationType dc_type = BinaryDomainCombination.DomainCombinationType.BASIC;
721 if ( cla.isOptionSet( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS ) ) {
722 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED;
724 if ( cla.isOptionSet( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY ) ) {
725 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT;
728 if ( cla.isOptionSet( surfacing.OUTPUT_DIR_OPTION ) ) {
729 if ( !cla.isOptionValueSet( surfacing.OUTPUT_DIR_OPTION ) ) {
730 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for output directory: -"
731 + surfacing.OUTPUT_DIR_OPTION + "=<dir>" );
733 out_dir = new File( cla.getOptionValue( surfacing.OUTPUT_DIR_OPTION ) );
734 if ( out_dir.exists() && ( out_dir.listFiles().length > 0 ) ) {
735 ForesterUtil.fatalError( surfacing.PRG_NAME, "\"" + out_dir + "\" aready exists and is not empty" );
737 if ( !out_dir.exists() ) {
738 final boolean success = out_dir.mkdir();
739 if ( !success || !out_dir.exists() ) {
740 ForesterUtil.fatalError( surfacing.PRG_NAME, "failed to create \"" + out_dir + "\"" );
743 if ( !out_dir.canWrite() ) {
744 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot write to \"" + out_dir + "\"" );
747 File positive_filter_file = null;
748 File negative_filter_file = null;
749 File negative_domains_filter_file = null;
750 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) && cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
751 ForesterUtil.fatalError( surfacing.PRG_NAME, "attempt to use both negative and positive protein filter" );
753 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION )
754 && ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) || cla
755 .isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) ) {
757 .fatalError( surfacing.PRG_NAME,
758 "attempt to use both negative or positive protein filter together wirh a negative domains filter" );
760 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) ) {
761 if ( !cla.isOptionValueSet( surfacing.FILTER_NEGATIVE_OPTION ) ) {
762 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for negative filter: -"
763 + surfacing.FILTER_NEGATIVE_OPTION + "=<file>" );
765 negative_filter_file = new File( cla.getOptionValue( surfacing.FILTER_NEGATIVE_OPTION ) );
766 final String msg = ForesterUtil.isReadableFile( negative_filter_file );
767 if ( !ForesterUtil.isEmpty( msg ) ) {
768 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + negative_filter_file + "\": "
772 else if ( cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
773 if ( !cla.isOptionValueSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
774 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for positive filter: -"
775 + surfacing.FILTER_POSITIVE_OPTION + "=<file>" );
777 positive_filter_file = new File( cla.getOptionValue( surfacing.FILTER_POSITIVE_OPTION ) );
778 final String msg = ForesterUtil.isReadableFile( positive_filter_file );
779 if ( !ForesterUtil.isEmpty( msg ) ) {
780 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + positive_filter_file + "\": "
784 else if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
785 if ( !cla.isOptionValueSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
786 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for negative domains filter: -"
787 + surfacing.FILTER_NEGATIVE_DOMAINS_OPTION + "=<file>" );
789 negative_domains_filter_file = new File( cla.getOptionValue( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) );
790 final String msg = ForesterUtil.isReadableFile( negative_domains_filter_file );
791 if ( !ForesterUtil.isEmpty( msg ) ) {
792 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + negative_domains_filter_file
796 final List<String> plus_minus_analysis_high_copy_base_species = new ArrayList<String>();
797 final List<String> plus_minus_analysis_high_copy_target_species = new ArrayList<String>();
798 final List<String> plus_minus_analysis_high_low_copy_species = new ArrayList<String>();
799 final List<Object> plus_minus_analysis_numbers = new ArrayList<Object>();
800 processPlusMinusAnalysisOption( cla,
801 plus_minus_analysis_high_copy_base_species,
802 plus_minus_analysis_high_copy_target_species,
803 plus_minus_analysis_high_low_copy_species,
804 plus_minus_analysis_numbers );
805 File input_files_file = null;
806 String[] input_file_names_from_file = null;
807 if ( cla.isOptionSet( surfacing.INPUT_FILES_FROM_FILE_OPTION ) ) {
808 if ( !cla.isOptionValueSet( surfacing.INPUT_FILES_FROM_FILE_OPTION ) ) {
809 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for input files file: -"
810 + surfacing.INPUT_FILES_FROM_FILE_OPTION + "=<file>" );
812 input_files_file = new File( cla.getOptionValue( surfacing.INPUT_FILES_FROM_FILE_OPTION ) );
813 final String msg = ForesterUtil.isReadableFile( input_files_file );
814 if ( !ForesterUtil.isEmpty( msg ) ) {
815 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + input_files_file + "\": " + msg );
818 input_file_names_from_file = ForesterUtil.file2array( input_files_file );
820 catch ( final IOException e ) {
821 ForesterUtil.fatalError( surfacing.PRG_NAME, "failed to read from \"" + input_files_file + "\": " + e );
824 if ( ( cla.getNumberOfNames() < 1 )
825 && ( ( input_file_names_from_file == null ) || ( input_file_names_from_file.length < 1 ) ) ) {
826 ForesterUtil.fatalError( surfacing.PRG_NAME,
827 "No hmmpfam output file indicated is input: use comand line directly or "
828 + surfacing.INPUT_FILES_FROM_FILE_OPTION + "=<file>" );
830 DomainSimilarity.DomainSimilarityScoring scoring = SCORING_DEFAULT;
831 if ( cla.isOptionSet( surfacing.SCORING_OPTION ) ) {
832 if ( !cla.isOptionValueSet( surfacing.SCORING_OPTION ) ) {
833 ForesterUtil.fatalError( surfacing.PRG_NAME,
834 "no value for scoring method for domain combinations similarity calculation: -"
835 + surfacing.SCORING_OPTION + "=<"
836 + surfacing.SCORING_DOMAIN_COUNT_BASED + "|"
837 + surfacing.SCORING_PROTEIN_COUNT_BASED + "|"
838 + surfacing.SCORING_COMBINATION_BASED + ">\"" );
840 final String scoring_str = cla.getOptionValue( surfacing.SCORING_OPTION );
841 if ( scoring_str.equals( surfacing.SCORING_DOMAIN_COUNT_BASED ) ) {
842 scoring = DomainSimilarity.DomainSimilarityScoring.DOMAINS;
844 else if ( scoring_str.equals( surfacing.SCORING_COMBINATION_BASED ) ) {
845 scoring = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
847 else if ( scoring_str.equals( surfacing.SCORING_PROTEIN_COUNT_BASED ) ) {
848 scoring = DomainSimilarity.DomainSimilarityScoring.PROTEINS;
851 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + scoring_str
852 + "\" for scoring method for domain combinations similarity calculation: \"-"
853 + surfacing.SCORING_OPTION + "=<" + surfacing.SCORING_DOMAIN_COUNT_BASED + "|"
854 + surfacing.SCORING_PROTEIN_COUNT_BASED + "|" + surfacing.SCORING_COMBINATION_BASED + ">\"" );
857 boolean sort_by_species_count_first = false;
858 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION ) ) {
859 sort_by_species_count_first = true;
861 boolean species_matrix = false;
862 if ( cla.isOptionSet( surfacing.SPECIES_MATRIX_OPTION ) ) {
863 species_matrix = true;
865 boolean output_protein_lists_for_all_domains = false;
866 if ( cla.isOptionSet( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS ) ) {
867 output_protein_lists_for_all_domains = true;
869 Detailedness detailedness = DETAILEDNESS_DEFAULT;
870 if ( cla.isOptionSet( surfacing.DETAILEDNESS_OPTION ) ) {
871 if ( !cla.isOptionValueSet( surfacing.DETAILEDNESS_OPTION ) ) {
872 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for -" + surfacing.DETAILEDNESS_OPTION + "=<"
873 + surfacing.DETAILEDNESS_BASIC + "|" + surfacing.DETAILEDNESS_LIST_IDS + "|"
874 + surfacing.DETAILEDNESS_PUNCTILIOUS + ">\"" );
876 final String detness = cla.getOptionValue( surfacing.DETAILEDNESS_OPTION ).toLowerCase();
877 if ( detness.equals( surfacing.DETAILEDNESS_BASIC ) ) {
878 detailedness = DomainSimilarityCalculator.Detailedness.BASIC;
880 else if ( detness.equals( surfacing.DETAILEDNESS_LIST_IDS ) ) {
881 detailedness = DomainSimilarityCalculator.Detailedness.LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES;
883 else if ( detness.equals( surfacing.DETAILEDNESS_PUNCTILIOUS ) ) {
884 detailedness = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
887 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + detness + "\" for detailedness: \"-"
888 + surfacing.DETAILEDNESS_OPTION + "=<" + surfacing.DETAILEDNESS_BASIC + "|"
889 + surfacing.DETAILEDNESS_LIST_IDS + "|" + surfacing.DETAILEDNESS_PUNCTILIOUS + ">\"" );
892 String automated_pairwise_comparison_suffix = null;
893 boolean perform_pwc = false;
894 boolean write_pwc_files = false;
895 if ( cla.isOptionSet( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
897 if ( !cla.isOptionValueSet( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
898 write_pwc_files = false;
901 write_pwc_files = true;
902 automated_pairwise_comparison_suffix = "_"
903 + cla.getOptionValue( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
906 String query_domain_ids = null;
907 if ( cla.isOptionSet( surfacing.SEQ_EXTRACT_OPTION ) ) {
908 if ( !cla.isOptionValueSet( surfacing.SEQ_EXTRACT_OPTION ) ) {
910 .fatalError( surfacing.PRG_NAME,
911 "no domain ids given for sequences with given domains to be extracted : -"
912 + surfacing.SEQ_EXTRACT_OPTION
913 + "=<ordered domain sequences, domain ids separated by '~', sequences separated by '#'>" );
915 query_domain_ids = cla.getOptionValue( surfacing.SEQ_EXTRACT_OPTION );
917 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field = DOMAIN_SORT_FILD_DEFAULT;
918 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field_for_automated_pwc = DOMAIN_SORT_FILD_DEFAULT;
919 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
920 if ( !cla.isOptionValueSet( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
921 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for domain combinations similarities sorting: -"
922 + surfacing.DOMAIN_SIMILARITY_SORT_OPTION + "=<" + surfacing.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
923 + surfacing.DOMAIN_SIMILARITY_SORT_MAX + "|" + surfacing.DOMAIN_SIMILARITY_SORT_MIN + "|"
924 + surfacing.DOMAIN_SIMILARITY_SORT_MEAN + "|" + surfacing.DOMAIN_SIMILARITY_SORT_DIFF + "|"
925 + surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
926 + surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|"
927 + surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|" + surfacing.DOMAIN_SIMILARITY_SORT_SD
930 final String sort_str = cla.getOptionValue( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ).toLowerCase();
931 if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_ALPHA ) ) {
932 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
933 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
935 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MAX ) ) {
936 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX;
937 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
939 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MIN ) ) {
940 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MIN;
941 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
943 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MEAN ) ) {
944 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MEAN;
945 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MEAN;
947 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT ) ) {
948 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SPECIES_COUNT;
949 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
951 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_SD ) ) {
952 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SD;
953 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
955 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_DIFF ) ) {
956 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
957 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
959 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF ) ) {
960 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
961 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
963 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF ) ) {
964 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
965 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
968 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort_str
969 + "\" for domain combinations similarities sorting: \"-"
970 + surfacing.DOMAIN_SIMILARITY_SORT_OPTION + "=<" + surfacing.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
971 + surfacing.DOMAIN_SIMILARITY_SORT_MAX + "|" + surfacing.DOMAIN_SIMILARITY_SORT_MIN + "|"
972 + surfacing.DOMAIN_SIMILARITY_SORT_MEAN + "|" + surfacing.DOMAIN_SIMILARITY_SORT_DIFF + "|"
973 + surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
974 + surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|" + "|"
975 + surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|" + surfacing.DOMAIN_SIMILARITY_SORT_SD
979 PrintableDomainSimilarity.PRINT_OPTION domain_similarity_print_option = DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT;
980 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
981 if ( !cla.isOptionValueSet( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
982 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for print option: -"
983 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
984 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
985 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
987 final String sort = cla.getOptionValue( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ).toLowerCase();
988 if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML ) ) {
989 domain_similarity_print_option = PrintableDomainSimilarity.PRINT_OPTION.HTML;
991 else if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML ) ) {
992 // domain_similarity_print_option =
993 // DomainSimilarity.PRINT_OPTION.SIMPLE_HTML;
994 ForesterUtil.fatalError( surfacing.PRG_NAME, "simple HTML output not implemented yet :(" );
996 else if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED ) ) {
997 domain_similarity_print_option = PrintableDomainSimilarity.PRINT_OPTION.SIMPLE_TAB_DELIMITED;
1000 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort + "\" for print option: -"
1001 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
1002 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
1003 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
1006 GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder dc_sort_order = DOMAINS_SORT_ORDER_DEFAULT;
1007 if ( cla.isOptionSet( surfacing.DOMAIN_COUNT_SORT_OPTION ) ) {
1008 if ( !cla.isOptionValueSet( surfacing.DOMAIN_COUNT_SORT_OPTION ) ) {
1009 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for sorting of domain counts: -"
1010 + surfacing.DOMAIN_COUNT_SORT_OPTION + "=<" + surfacing.DOMAIN_COUNT_SORT_ALPHA + "|"
1011 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
1012 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
1013 + surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
1015 final String sort = cla.getOptionValue( surfacing.DOMAIN_COUNT_SORT_OPTION ).toLowerCase();
1016 if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_ALPHA ) ) {
1017 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
1019 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT ) ) {
1020 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_COUNT;
1022 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT ) ) {
1023 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_PROTEINS_COUNT;
1025 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT ) ) {
1026 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.COMBINATIONS_COUNT;
1029 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort
1030 + "\" for sorting of domain counts: \"-" + surfacing.DOMAIN_COUNT_SORT_OPTION + "=<"
1031 + surfacing.DOMAIN_COUNT_SORT_ALPHA + "|" + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
1032 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
1033 + surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
1036 String[][] input_file_properties = null;
1037 if ( input_file_names_from_file != null ) {
1038 input_file_properties = surfacing.processInputFileNames( input_file_names_from_file );
1041 input_file_properties = surfacing.processInputFileNames( cla.getNames() );
1043 final int number_of_genomes = input_file_properties.length;
1044 if ( number_of_genomes < 2 ) {
1045 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot analyze less than two files" );
1047 if ( ( number_of_genomes < 3 ) && perform_pwc ) {
1048 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use : -"
1049 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1050 + "=<suffix> to turn on pairwise analyses with less than three input files" );
1052 checkWriteabilityForPairwiseComparisons( domain_similarity_print_option,
1053 input_file_properties,
1054 automated_pairwise_comparison_suffix,
1056 for( int i = 0; i < number_of_genomes; i++ ) {
1057 File dcc_outfile = new File( input_file_properties[ i ][ 0 ]
1058 + surfacing.DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX );
1059 if ( out_dir != null ) {
1060 dcc_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + dcc_outfile );
1062 SurfacingUtil.checkForOutputFileWriteability( dcc_outfile );
1064 File pfam_to_go_file = null;
1065 Map<DomainId, List<GoId>> domain_id_to_go_ids_map = null;
1066 int domain_id_to_go_ids_count = 0;
1067 if ( cla.isOptionSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
1068 if ( !cla.isOptionValueSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
1069 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for Pfam to GO mapping file: -"
1070 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>" );
1072 pfam_to_go_file = new File( cla.getOptionValue( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) );
1073 final String error = ForesterUtil.isReadableFile( pfam_to_go_file );
1074 if ( !ForesterUtil.isEmpty( error ) ) {
1075 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read Pfam to GO mapping file: " + error );
1078 final PfamToGoParser parser = new PfamToGoParser( pfam_to_go_file );
1079 final List<PfamToGoMapping> pfam_to_go_mappings = parser.parse();
1080 domain_id_to_go_ids_map = SurfacingUtil.createDomainIdToGoIdMap( pfam_to_go_mappings );
1081 if ( parser.getMappingCount() < domain_id_to_go_ids_map.size() ) {
1082 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME,
1083 "parser.getMappingCount() < domain_id_to_go_ids_map.size()" );
1085 domain_id_to_go_ids_count = parser.getMappingCount();
1087 catch ( final IOException e ) {
1088 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from Pfam to GO mapping file: " + e );
1091 File go_obo_file = null;
1092 List<GoTerm> go_terms = null;
1093 if ( cla.isOptionSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
1094 if ( !cla.isOptionValueSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
1095 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for GO OBO file: -"
1096 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>" );
1098 if ( ( domain_id_to_go_ids_map == null ) || ( domain_id_to_go_ids_map.size() < 1 ) ) {
1099 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use GO OBO file (-"
1100 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>) without Pfam to GO mapping file ("
1101 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1103 go_obo_file = new File( cla.getOptionValue( surfacing.GO_OBO_FILE_USE_OPTION ) );
1104 final String error = ForesterUtil.isReadableFile( go_obo_file );
1105 if ( !ForesterUtil.isEmpty( error ) ) {
1106 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read GO OBO file: " + error );
1109 final OBOparser parser = new OBOparser( go_obo_file, OBOparser.ReturnType.BASIC_GO_TERM );
1110 go_terms = parser.parse();
1111 if ( parser.getGoTermCount() != go_terms.size() ) {
1113 .unexpectedFatalError( surfacing.PRG_NAME, "parser.getGoTermCount() != go_terms.size()" );
1116 catch ( final IOException e ) {
1117 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from GO OBO file: " + e );
1120 Map<GoId, GoTerm> go_id_to_term_map = null;
1121 if ( ( ( domain_id_to_go_ids_map != null ) && ( domain_id_to_go_ids_map.size() > 0 ) )
1122 && ( ( go_terms != null ) && ( go_terms.size() > 0 ) ) ) {
1123 go_id_to_term_map = GoUtils.createGoIdToGoTermMap( go_terms );
1125 GoNameSpace go_namespace_limit = null;
1126 if ( cla.isOptionSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
1127 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1128 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use GO namespace limit (-"
1129 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<namespace>) without Pfam to GO mapping file ("
1130 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>) and GO OBO file (-"
1131 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1133 if ( !cla.isOptionValueSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
1134 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for GO namespace limit: \"-"
1135 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
1136 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
1137 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
1138 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
1140 final String go_namespace_limit_str = cla.getOptionValue( surfacing.GO_NAMESPACE_LIMIT_OPTION )
1142 if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION ) ) {
1143 go_namespace_limit = GoNameSpace.createMolecularFunction();
1145 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS ) ) {
1146 go_namespace_limit = GoNameSpace.createBiologicalProcess();
1148 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT ) ) {
1149 go_namespace_limit = GoNameSpace.createCellularComponent();
1152 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + go_namespace_limit_str
1153 + "\" for GO namespace limit: \"-" + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
1154 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
1155 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
1156 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
1159 if ( ( domain_similarity_sort_field == DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE )
1160 && ( number_of_genomes > 2 ) ) {
1161 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
1163 boolean jacknifed_distances = false;
1164 int jacknife_resamplings = JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT;
1165 double jacknife_ratio = JACKNIFE_RATIO_DEFAULT;
1166 long random_seed = JACKNIFE_RANDOM_SEED_DEFAULT;
1167 if ( cla.isOptionSet( surfacing.JACKNIFE_OPTION ) ) {
1168 if ( ( number_of_genomes < 3 ) || !perform_pwc ) {
1169 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use jacknife resampling analysis (-"
1170 + surfacing.JACKNIFE_OPTION + "[=<number of resamplings>]) without pairwise analyses ("
1171 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1172 + "=<suffix for pairwise comparison output files>)" );
1174 jacknifed_distances = true;
1175 if ( cla.isOptionHasAValue( surfacing.JACKNIFE_OPTION ) ) {
1177 jacknife_resamplings = cla.getOptionValueAsInt( surfacing.JACKNIFE_OPTION );
1179 catch ( final IOException e ) {
1180 ForesterUtil.fatalError( surfacing.PRG_NAME, "illegal format for number of resamplings" );
1182 if ( jacknife_resamplings < 2 ) {
1183 ForesterUtil.fatalError( surfacing.PRG_NAME, "attempt to use less than 2 resamplings" );
1186 if ( cla.isOptionSet( surfacing.JACKNIFE_RATIO_OPTION )
1187 && cla.isOptionHasAValue( surfacing.JACKNIFE_RATIO_OPTION ) ) {
1189 jacknife_ratio = cla.getOptionValueAsDouble( surfacing.JACKNIFE_RATIO_OPTION );
1191 catch ( final IOException e ) {
1192 ForesterUtil.fatalError( surfacing.PRG_NAME, "illegal format for jacknife ratio" );
1194 if ( ( jacknife_ratio <= 0.0 ) || ( jacknife_ratio >= 1.0 ) ) {
1195 ForesterUtil.fatalError( surfacing.PRG_NAME, "attempt to use illegal value for jacknife ratio: "
1199 if ( cla.isOptionSet( surfacing.JACKNIFE_RANDOM_SEED_OPTION )
1200 && cla.isOptionHasAValue( surfacing.JACKNIFE_RANDOM_SEED_OPTION ) ) {
1202 random_seed = cla.getOptionValueAsLong( surfacing.JACKNIFE_RANDOM_SEED_OPTION );
1204 catch ( final IOException e ) {
1205 ForesterUtil.fatalError( surfacing.PRG_NAME, "illegal format for random generator seed" );
1209 // boolean infer_species_trees = false;
1210 // if ( cla.isOptionSet( surfacing.INFER_SPECIES_TREES_OPTION ) ) {
1211 // if ( ( output_file == null ) || ( number_of_genomes < 3 )
1212 // || ForesterUtil.isEmpty( automated_pairwise_comparison_suffix ) ) {
1213 // ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot infer species trees (-"
1214 // + surfacing.INFER_SPECIES_TREES_OPTION + " without pairwise analyses ("
1215 // + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1216 // + "=<suffix for pairwise comparison output files>)" );
1218 // infer_species_trees = true;
1220 File[] intree_files = null;
1221 Phylogeny[] intrees = null;
1222 if ( cla.isOptionSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
1223 // TODO FIXME if jacknife.... maybe not
1224 if ( number_of_genomes < 3 ) {
1225 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot infer gains and losses on input species trees (-"
1226 + surfacing.INPUT_SPECIES_TREE_OPTION + " without pairwise analyses ("
1227 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
1228 + "=<suffix for pairwise comparison output files>)" );
1230 if ( !cla.isOptionValueSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
1231 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for input tree: -"
1232 + surfacing.INPUT_SPECIES_TREE_OPTION + "=<tree file in phyloXML format>" );
1234 final String intrees_str = cla.getOptionValue( surfacing.INPUT_SPECIES_TREE_OPTION );
1235 if ( intrees_str.indexOf( "#" ) > 0 ) {
1236 final String[] intrees_strs = intrees_str.split( "#" );
1237 intree_files = new File[ intrees_strs.length ];
1239 for( final String s : intrees_strs ) {
1240 intree_files[ i++ ] = new File( s.trim() );
1244 intree_files = new File[ 1 ];
1245 intree_files[ 0 ] = new File( intrees_str );
1247 intrees = getIntrees( intree_files, number_of_genomes, input_file_properties );
1249 long random_number_seed_for_fitch_parsimony = 0l;
1250 boolean radomize_fitch_parsimony = false;
1251 if ( cla.isOptionSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
1252 if ( !cla.isOptionValueSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
1253 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for random number seed: -"
1254 + surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION + "=<seed>" );
1257 random_number_seed_for_fitch_parsimony = cla
1258 .getOptionValueAsLong( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
1260 catch ( final IOException e ) {
1261 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
1263 radomize_fitch_parsimony = true;
1265 SortedSet<DomainId> filter = null;
1266 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1267 || ( negative_domains_filter_file != null ) ) {
1268 filter = new TreeSet<DomainId>();
1269 if ( positive_filter_file != null ) {
1270 processFilter( positive_filter_file, filter );
1272 else if ( negative_filter_file != null ) {
1273 processFilter( negative_filter_file, filter );
1275 else if ( negative_domains_filter_file != null ) {
1276 processFilter( negative_domains_filter_file, filter );
1279 Map<DomainId, Set<String>>[] domain_id_to_secondary_features_maps = null;
1280 File[] secondary_features_map_files = null;
1281 final File domain_lengths_analysis_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1282 + DOMAIN_LENGTHS_ANALYSIS_SUFFIX );
1283 if ( PERFORM_DOMAIN_LENGTH_ANALYSIS ) {
1284 SurfacingUtil.checkForOutputFileWriteability( domain_lengths_analysis_outfile );
1286 if ( cla.isOptionSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
1287 if ( !cla.isOptionValueSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
1288 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for secondary features map file: -"
1289 + surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE + "=<file>" );
1291 final String[] secondary_features_map_files_strs = cla
1292 .getOptionValue( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ).split( "#" );
1293 secondary_features_map_files = new File[ secondary_features_map_files_strs.length ];
1294 domain_id_to_secondary_features_maps = new Map[ secondary_features_map_files_strs.length ];
1296 for( final String secondary_features_map_files_str : secondary_features_map_files_strs ) {
1297 secondary_features_map_files[ i ] = new File( secondary_features_map_files_str );
1298 final String error = ForesterUtil.isReadableFile( secondary_features_map_files[ i ] );
1299 if ( !ForesterUtil.isEmpty( error ) ) {
1300 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read secondary features map file: " + error );
1303 domain_id_to_secondary_features_maps[ i ] = SurfacingUtil
1304 .createDomainIdToSecondaryFeaturesMap( secondary_features_map_files[ i ] );
1306 catch ( final IOException e ) {
1307 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read secondary features map file: "
1310 catch ( final Exception e ) {
1311 ForesterUtil.fatalError( surfacing.PRG_NAME, "problem with contents of features map file ["
1312 + secondary_features_map_files[ i ] + "]: " + e.getMessage() );
1317 if ( out_dir == null ) {
1318 ForesterUtil.fatalError( surfacing.PRG_NAME, "no output directory indicated (-"
1319 + surfacing.OUTPUT_DIR_OPTION + "=<dir>)" );
1321 if ( output_file == null ) {
1322 ForesterUtil.fatalError( surfacing.PRG_NAME, "no name for (main) output file indicated (-"
1323 + surfacing.OUTPUT_FILE_OPTION + "=<file>)" );
1325 if ( ( domain_id_to_go_ids_map == null ) || domain_id_to_go_ids_map.isEmpty() ) {
1326 ForesterUtil.fatalError( surfacing.PRG_NAME,
1327 "no (acceptable) Pfam to GO id mapping file provided ('pfam2go file') (-"
1328 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1330 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1331 ForesterUtil.fatalError( surfacing.PRG_NAME,
1332 "no (acceptable) go id to term mapping file provided ('GO OBO file') (-"
1333 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1335 boolean display_histograms = false;
1336 if ( cla.isOptionSet( surfacing.DISPLAY_M_HISTOGRAMS_OPTION ) ) {
1337 display_histograms = true;
1339 System.out.println( "Output directory : " + out_dir );
1340 if ( input_file_names_from_file != null ) {
1341 System.out.println( "Input files names from : " + input_files_file + " ["
1342 + input_file_names_from_file.length + " input files]" );
1343 html_desc.append( "<tr><td>Input files names from:</td><td>" + input_files_file + " ["
1344 + input_file_names_from_file.length + " input files]</td></tr>" + nl );
1346 if ( positive_filter_file != null ) {
1347 final int filter_size = filter.size();
1348 System.out.println( "Positive protein filter : " + positive_filter_file + " [" + filter_size
1350 html_desc.append( "<tr><td>Positive protein filter:</td><td>" + positive_filter_file + " [" + filter_size
1351 + " domain ids]</td></tr>" + nl );
1353 if ( negative_filter_file != null ) {
1354 final int filter_size = filter.size();
1355 System.out.println( "Negative protein filter : " + negative_filter_file + " [" + filter_size
1357 html_desc.append( "<tr><td>Negative protein filter:</td><td>" + negative_filter_file + " [" + filter_size
1358 + " domain ids]</td></tr>" + nl );
1360 if ( negative_domains_filter_file != null ) {
1361 final int filter_size = filter.size();
1362 System.out.println( "Negative domain filter : " + negative_domains_filter_file + " [" + filter_size
1364 html_desc.append( "<tr><td>Negative domain filter:</td><td>" + negative_domains_filter_file + " ["
1365 + filter_size + " domain ids]</td></tr>" + nl );
1367 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
1369 for( final String s : plus_minus_analysis_high_copy_base_species ) {
1370 plus0 += "+" + s + " ";
1373 for( final String s : plus_minus_analysis_high_copy_target_species ) {
1374 plus1 += "*" + s + " ";
1377 for( final String s : plus_minus_analysis_high_low_copy_species ) {
1378 minus += "-" + s + " ";
1380 System.out.println( "Plus-minus analysis : " + plus1 + "&& " + plus0 + "&& " + minus );
1381 html_desc.append( "<tr><td>Plus-minus analysis:</td><td>" + plus1 + "&& " + plus0 + "&& " + minus
1382 + "</td></tr>" + nl );
1384 if ( cutoff_scores_file != null ) {
1385 System.out.println( "Cutoff scores file : " + cutoff_scores_file );
1386 html_desc.append( "<tr><td>Cutoff scores file:</td><td>" + cutoff_scores_file + "</td></tr>" + nl );
1388 if ( e_value_max >= 0.0 ) {
1389 System.out.println( "E-value maximum (inclusive) : " + e_value_max );
1390 html_desc.append( "<tr><td>E-value maximum (inclusive):</td><td>" + e_value_max + "</td></tr>" + nl );
1392 System.out.println( "Ignore DUFs : " + ignore_dufs );
1393 if ( ignore_virus_like_ids ) {
1394 System.out.println( "Ignore virus like ids : " + ignore_virus_like_ids );
1395 html_desc.append( "<tr><td>Ignore virus, phage, transposition related ids:</td><td>"
1396 + ignore_virus_like_ids + "</td></tr>" + nl );
1398 html_desc.append( "<tr><td>Ignore DUFs:</td><td>" + ignore_dufs + "</td></tr>" + nl );
1399 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1400 System.out.println( "Max allowed domain overlap : " + max_allowed_overlap );
1401 html_desc.append( "<tr><td>Max allowed domain overlap:</td><td>" + max_allowed_overlap + "</td></tr>" + nl );
1403 if ( no_engulfing_overlaps ) {
1404 System.out.println( "Ignore engulfed domains : " + no_engulfing_overlaps );
1405 html_desc.append( "<tr><td>Ignore (lower confidence) engulfed domains:</td><td>" + no_engulfing_overlaps
1406 + "</td></tr>" + nl );
1408 System.out.println( "Ignore singlet domains : " + ignore_domains_without_combs_in_all_spec );
1410 .append( "<tr><td>Ignore singlet domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1411 + ignore_domains_without_combs_in_all_spec + "</td></tr>" + nl );
1412 System.out.println( "Ignore species specific doms: " + ignore_species_specific_domains );
1414 .append( "<tr><td>Ignore species specific domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1415 + ignore_species_specific_domains + "</td></tr>" + nl );
1416 System.out.println( "Ignore combination with self: " + ignore_combination_with_same );
1417 html_desc.append( "<tr><td>Ignore combination with self for domain combination similarity analyses:</td><td>"
1418 + ignore_combination_with_same + "</td></tr>" + nl );
1420 System.out.println( "Consider directedness : "
1421 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) );
1422 html_desc.append( "<tr><td>Consider directedness of binary domain combinations:</td><td>"
1423 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) + "</td></tr>" + nl );
1424 if ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) {
1425 System.out.println( "Consider adjacency : "
1426 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) );
1427 html_desc.append( "<tr><td>Consider djacency of binary domain combinations:</td><td>"
1428 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) + "</td></tr>"
1431 System.out.print( "Domain counts sort order : " );
1432 switch ( dc_sort_order ) {
1433 case ALPHABETICAL_KEY_ID:
1434 System.out.println( "alphabetical" );
1436 case KEY_DOMAIN_COUNT:
1437 System.out.println( "domain count" );
1439 case KEY_DOMAIN_PROTEINS_COUNT:
1440 System.out.println( "domain proteins count" );
1442 case COMBINATIONS_COUNT:
1443 System.out.println( "domain combinations count" );
1446 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for dc sort order" );
1448 if ( domain_id_to_go_ids_map != null ) {
1449 System.out.println( "Pfam to GO mappings from : " + pfam_to_go_file + " [" + domain_id_to_go_ids_count
1451 html_desc.append( "<tr><td>Pfam to GO mappings from:</td><td>" + pfam_to_go_file + " ["
1452 + domain_id_to_go_ids_count + " mappings]" + "</td></tr>" + nl );
1454 if ( go_terms != null ) {
1455 System.out.println( "GO terms from : " + go_obo_file + " [" + go_terms.size() + " terms]" );
1456 html_desc.append( "<tr><td>GO terms from:</td><td>" + go_obo_file + " [" + go_terms.size() + " terms]"
1457 + "</td></tr>" + nl );
1459 if ( go_namespace_limit != null ) {
1460 System.out.println( "Limit GO terms to : " + go_namespace_limit.toString() );
1461 html_desc.append( "<tr><td>Limit GO terms to</td><td>" + go_namespace_limit + "</td></tr>" + nl );
1463 if ( perform_pwc ) {
1464 System.out.println( "Suffix for PWC files : " + automated_pairwise_comparison_suffix );
1465 html_desc.append( "<tr><td>Suffix for PWC files</td><td>" + automated_pairwise_comparison_suffix
1466 + "</td></tr>" + nl );
1468 if ( out_dir != null ) {
1469 System.out.println( "Output directory : " + out_dir );
1471 if ( query_domain_ids != null ) {
1472 System.out.println( "Query domains (ordered) : " + query_domain_ids );
1473 html_desc.append( "<tr><td></td><td>" + query_domain_ids + "</td></tr>" + nl );
1475 System.out.println( "Write similarities to : " + output_file );
1476 System.out.print( " Scoring method : " );
1477 html_desc.append( "<tr><td>Scoring method:</td><td>" );
1478 switch ( scoring ) {
1480 System.out.println( "domain combinations based" );
1481 html_desc.append( "domain combinations based" + "</td></tr>" + nl );
1484 System.out.println( "domain counts based" );
1485 html_desc.append( "domain counts based" + "</td></tr>" + nl );
1488 System.out.println( "domain proteins counts based" );
1489 html_desc.append( "domain proteins counts based" + "</td></tr>" + nl );
1492 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1494 System.out.print( " Sort by : " );
1495 html_desc.append( "<tr><td>Sort by:</td><td>" );
1496 switch ( domain_similarity_sort_field ) {
1498 System.out.print( "score minimum" );
1499 html_desc.append( "score minimum" );
1502 System.out.print( "score maximum" );
1503 html_desc.append( "score maximum" );
1506 System.out.print( "score mean" );
1507 html_desc.append( "score mean" );
1510 System.out.print( "score standard deviation" );
1511 html_desc.append( "score standard deviation" );
1514 System.out.print( "species number" );
1515 html_desc.append( "species number" );
1518 System.out.print( "alphabetical domain identifier" );
1519 html_desc.append( "alphabetical domain identifier" );
1521 case MAX_DIFFERENCE:
1522 System.out.print( "(maximal) difference" );
1523 html_desc.append( "(maximal) difference" );
1525 case ABS_MAX_COUNTS_DIFFERENCE:
1526 System.out.print( "absolute (maximal) counts difference" );
1527 html_desc.append( "absolute (maximal) counts difference" );
1529 case MAX_COUNTS_DIFFERENCE:
1530 System.out.print( "(maximal) counts difference" );
1531 html_desc.append( "(maximal) counts difference" );
1534 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1536 if ( sort_by_species_count_first ) {
1537 System.out.println( " (sort by species count first)" );
1538 html_desc.append( " (sort by species count first)" );
1541 System.out.println();
1543 html_desc.append( "</td></tr>" + nl );
1544 System.out.print( " Detailedness : " );
1545 switch ( detailedness ) {
1547 System.out.println( "basic" );
1549 case LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES:
1550 System.out.println( "list combining domains for each species" );
1553 System.out.println( "punctilious" );
1556 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for detailedness" );
1558 System.out.print( " Print option : " );
1559 switch ( domain_similarity_print_option ) {
1561 System.out.println( "HTML" );
1563 case SIMPLE_TAB_DELIMITED:
1564 System.out.println( "simple tab delimited" );
1567 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for print option" );
1569 System.out.print( " Species matrix : " + species_matrix );
1570 System.out.println();
1571 final File dc_data_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + DATA_FILE_SUFFIX );
1572 System.out.println( "Domain comb data output : " + dc_data_file );
1573 html_desc.append( "<tr><td>Domain combination data output:</td><td> " + dc_data_file + " </td></tr>" );
1574 System.out.println();
1575 if ( perform_pwc ) {
1576 System.out.println( "Pairwise comparisons: " );
1577 html_desc.append( "<tr><td>Pairwise comparisons:</td><td></td></tr>" );
1578 System.out.print( " Sort by : " );
1579 html_desc.append( "<tr><td>Sort by:</td><td>" );
1580 switch ( domain_similarity_sort_field_for_automated_pwc ) {
1582 System.out.print( "score mean" );
1583 html_desc.append( "score mean" );
1586 System.out.print( "alphabetical domain identifier" );
1587 html_desc.append( "alphabetical domain identifier" );
1589 case MAX_DIFFERENCE:
1590 System.out.print( "difference" );
1591 html_desc.append( "difference" );
1593 case ABS_MAX_COUNTS_DIFFERENCE:
1594 System.out.print( "absolute counts difference" );
1595 html_desc.append( "absolute counts difference" );
1597 case MAX_COUNTS_DIFFERENCE:
1598 System.out.print( "counts difference" );
1599 html_desc.append( "counts difference" );
1603 .unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1605 System.out.println();
1606 html_desc.append( "</td></tr>" + nl );
1607 if ( jacknifed_distances ) {
1608 html_desc.append( "<tr><td>Jacknife:</td><td>" + jacknife_resamplings + " resamplings</td></tr>" + nl );
1609 html_desc.append( "<tr><td>Jacknife ratio:</td><td>" + ForesterUtil.round( jacknife_ratio, 2 )
1610 + "</td></tr>" + nl );
1611 html_desc.append( "<tr><td>Jacknife random number seed:</td><td>" + random_seed + "</td></tr>" + nl );
1612 System.out.println( " Jacknife : " + jacknife_resamplings + " resamplings" );
1613 System.out.println( " Ratio : " + ForesterUtil.round( jacknife_ratio, 2 ) );
1614 System.out.println( " Random number seed : " + random_seed );
1616 // if ( infer_species_trees ) {
1617 // html_desc.append( "<tr><td>Infer species trees:</td><td>true</td></tr>" + nl );
1618 // System.out.println( " Infer species trees : true" );
1620 if ( ( intrees != null ) && ( intrees.length > 0 ) ) {
1621 for( final File intree_file : intree_files ) {
1622 html_desc.append( "<tr><td>Intree for gain/loss parsimony analysis:</td><td>" + intree_file
1623 + "</td></tr>" + nl );
1624 System.out.println( " Intree for gain/loss pars.: " + intree_file );
1627 if ( radomize_fitch_parsimony ) {
1628 html_desc.append( "<tr><td> Random number seed for Fitch parsimony analysis:</td><td>"
1629 + random_number_seed_for_fitch_parsimony + "</td></tr>" + nl );
1630 System.out.println( " Random number seed : " + random_number_seed_for_fitch_parsimony );
1632 if ( ( domain_id_to_secondary_features_maps != null ) && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
1633 for( int i = 0; i < secondary_features_map_files.length; i++ ) {
1634 html_desc.append( "<tr><td>Secondary features map file:</td><td>"
1635 + secondary_features_map_files[ i ] + "</td></tr>" + nl );
1636 System.out.println( "Secondary features map file : " + secondary_features_map_files[ i ]
1637 + " [mappings for " + domain_id_to_secondary_features_maps[ i ].size() + " domain ids]" );
1639 System.out.println();
1640 System.out.println( "Domain ids to secondary features map:" );
1641 for( final DomainId domain_id : domain_id_to_secondary_features_maps[ i ].keySet() ) {
1642 System.out.print( domain_id.getId() );
1643 System.out.print( " => " );
1644 for( final String sec : domain_id_to_secondary_features_maps[ i ].get( domain_id ) ) {
1645 System.out.print( sec );
1646 System.out.print( " " );
1648 System.out.println();
1653 } // if ( perform_pwc ) {
1654 System.out.println();
1655 html_desc.append( "<tr><td>Command line:</td><td>" + cla.getCommandLineArgsAsString() + "</td></tr>" + nl );
1656 System.out.println( "Command line : " + cla.getCommandLineArgsAsString() );
1657 BufferedWriter[] query_domains_writer_ary = null;
1658 List<DomainId>[] query_domain_ids_array = null;
1659 if ( query_domain_ids != null ) {
1660 final String[] query_domain_ids_str_array = query_domain_ids.split( "#" );
1661 query_domain_ids_array = new ArrayList[ query_domain_ids_str_array.length ];
1662 query_domains_writer_ary = new BufferedWriter[ query_domain_ids_str_array.length ];
1663 for( int i = 0; i < query_domain_ids_str_array.length; i++ ) {
1664 String query_domain_ids_str = query_domain_ids_str_array[ i ];
1665 final String[] query_domain_ids_str_ary = query_domain_ids_str.split( "~" );
1666 final List<DomainId> query = new ArrayList<DomainId>();
1667 for( final String element : query_domain_ids_str_ary ) {
1668 query.add( new DomainId( element ) );
1670 query_domain_ids_array[ i ] = query;
1671 query_domain_ids_str = query_domain_ids_str.replace( '~', '_' );
1672 String protein_names_writer_str = query_domain_ids_str + surfacing.SEQ_EXTRACT_SUFFIX;
1673 if ( out_dir != null ) {
1674 protein_names_writer_str = out_dir + ForesterUtil.FILE_SEPARATOR + protein_names_writer_str;
1677 query_domains_writer_ary[ i ] = new BufferedWriter( new FileWriter( protein_names_writer_str ) );
1679 catch ( final IOException e ) {
1680 ForesterUtil.fatalError( surfacing.PRG_NAME, "Could not open [" + protein_names_writer_str + "]: "
1681 + e.getLocalizedMessage() );
1685 SortedMap<Species, List<Protein>> protein_lists_per_species = null; //This will only be created if neede.
1686 boolean need_protein_lists_per_species = false;
1687 if ( ( plus_minus_analysis_high_copy_base_species.size() > 0 ) || output_protein_lists_for_all_domains ) {
1688 need_protein_lists_per_species = true;
1690 if ( need_protein_lists_per_species ) {
1691 protein_lists_per_species = new TreeMap<Species, List<Protein>>();
1693 final List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>( number_of_genomes );
1694 final SortedSet<DomainId> all_domains_encountered = new TreeSet<DomainId>();
1695 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered = new TreeSet<BinaryDomainCombination>();
1696 List<BinaryDomainCombination> all_bin_domain_combinations_gained_fitch = null;
1697 List<BinaryDomainCombination> all_bin_domain_combinations_lost_fitch = null;
1698 if ( ( intrees != null ) && ( intrees.length == 1 ) ) {
1699 all_bin_domain_combinations_gained_fitch = new ArrayList<BinaryDomainCombination>();
1700 all_bin_domain_combinations_lost_fitch = new ArrayList<BinaryDomainCombination>();
1702 final DomainLengthsTable domain_lengths_table = new DomainLengthsTable();
1703 final File per_genome_domain_promiscuity_statistics_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR
1704 + output_file + D_PROMISCUITY_FILE_SUFFIX );
1705 BufferedWriter per_genome_domain_promiscuity_statistics_writer = null;
1707 per_genome_domain_promiscuity_statistics_writer = new BufferedWriter( new FileWriter( per_genome_domain_promiscuity_statistics_file ) );
1708 per_genome_domain_promiscuity_statistics_writer.write( "Species:\t" );
1709 per_genome_domain_promiscuity_statistics_writer.write( "Mean:\t" );
1710 per_genome_domain_promiscuity_statistics_writer.write( "SD:\t" );
1711 per_genome_domain_promiscuity_statistics_writer.write( "Median:\t" );
1712 per_genome_domain_promiscuity_statistics_writer.write( "Min:\t" );
1713 per_genome_domain_promiscuity_statistics_writer.write( "Max:\t" );
1714 per_genome_domain_promiscuity_statistics_writer.write( "N:\t" );
1715 per_genome_domain_promiscuity_statistics_writer.write( "Max Promiscuous Domains:"
1716 + ForesterUtil.LINE_SEPARATOR );
1718 catch ( final IOException e2 ) {
1719 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1721 final File log_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + LOG_FILE_SUFFIX );
1722 BufferedWriter log_writer = null;
1724 log_writer = new BufferedWriter( new FileWriter( log_file ) );
1726 catch ( final IOException e2 ) {
1727 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1729 BufferedWriter dc_data_writer = null;
1731 dc_data_writer = new BufferedWriter( new FileWriter( dc_data_file ) );
1732 dc_data_writer.write( DATA_FILE_DESC );
1733 dc_data_writer.write( ForesterUtil.LINE_SEPARATOR );
1735 catch ( final IOException e2 ) {
1736 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1738 for( int i = 0; i < number_of_genomes; ++i ) {
1739 System.out.println();
1740 System.out.println( ( i + 1 ) + "/" + number_of_genomes );
1741 log( ( i + 1 ) + "/" + number_of_genomes, log_writer );
1742 System.out.println( "Processing : " + input_file_properties[ i ][ 0 ] );
1743 log( "Genome : " + input_file_properties[ i ][ 0 ], log_writer );
1744 HmmscanPerDomainTableParser parser = null;
1745 INDIVIDUAL_SCORE_CUTOFF ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF.NONE;
1746 if ( individual_score_cutoffs != null ) {
1747 ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF_DEFAULT;
1749 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1750 || ( negative_domains_filter_file != null ) ) {
1751 HmmscanPerDomainTableParser.FilterType filter_type = HmmscanPerDomainTableParser.FilterType.NONE;
1752 if ( positive_filter_file != null ) {
1753 filter_type = HmmscanPerDomainTableParser.FilterType.POSITIVE_PROTEIN;
1755 else if ( negative_filter_file != null ) {
1756 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_PROTEIN;
1758 else if ( negative_domains_filter_file != null ) {
1759 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_DOMAIN;
1761 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1762 input_file_properties[ i ][ 1 ],
1768 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1769 input_file_properties[ i ][ 1 ],
1772 if ( e_value_max >= 0.0 ) {
1773 parser.setEValueMaximum( e_value_max );
1775 parser.setIgnoreDufs( ignore_dufs );
1776 parser.setIgnoreVirusLikeIds( ignore_virus_like_ids );
1777 parser.setIgnoreEngulfedDomains( no_engulfing_overlaps );
1778 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1779 parser.setMaxAllowedOverlap( max_allowed_overlap );
1782 .setReturnType( HmmscanPerDomainTableParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
1783 if ( individual_score_cutoffs != null ) {
1784 parser.setIndividualScoreCutoffs( individual_score_cutoffs );
1786 List<Protein> protein_list = null;
1788 protein_list = parser.parse();
1790 catch ( final IOException e ) {
1791 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
1793 catch ( final Exception e ) {
1794 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, e.getMessage(), e );
1797 System.out.println( "Domains ignored due to negative domain filter: " );
1798 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToNegativeDomainFilterCountsMap() );
1799 System.out.println( "Domains ignored due to virus like id: " );
1800 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToVirusLikeIdCountsMap() );
1802 System.out.println( "Number of proteins encountered : " + parser.getProteinsEncountered() );
1803 log( "Number of proteins encountered : " + parser.getProteinsEncountered(), log_writer );
1804 System.out.println( "Number of proteins stored : " + protein_list.size() );
1805 log( "Number of proteins stored : " + protein_list.size(), log_writer );
1806 System.out.println( "Domains encountered : " + parser.getDomainsEncountered() );
1807 log( "Domains encountered : " + parser.getDomainsEncountered(), log_writer );
1808 System.out.println( "Domains stored : " + parser.getDomainsStored() );
1809 log( "Domains stored : " + parser.getDomainsStored(), log_writer );
1810 System.out.println( "Distinct domains stored : "
1811 + parser.getDomainsStoredSet().size() );
1812 log( "Distinct domains stored : " + parser.getDomainsStoredSet().size(), log_writer );
1813 System.out.println( "Domains ignored due to individual score cutoffs: "
1814 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() );
1815 log( "Domains ignored due to individual score cutoffs: "
1816 + parser.getDomainsIgnoredDueToIndividualScoreCutoff(), log_writer );
1817 System.out.println( "Domains ignored due to E-value : "
1818 + parser.getDomainsIgnoredDueToEval() );
1819 log( "Domains ignored due to E-value : " + parser.getDomainsIgnoredDueToEval(), log_writer );
1820 System.out.println( "Domains ignored due to DUF designation : "
1821 + parser.getDomainsIgnoredDueToDuf() );
1822 log( "Domains ignored due to DUF designation : " + parser.getDomainsIgnoredDueToDuf(), log_writer );
1823 if ( ignore_virus_like_ids ) {
1824 System.out.println( "Domains ignored due virus like ids : "
1825 + parser.getDomainsIgnoredDueToVirusLikeIds() );
1826 log( "Domains ignored due virus like ids : " + parser.getDomainsIgnoredDueToVirusLikeIds(),
1829 System.out.println( "Domains ignored due negative domain filter : "
1830 + parser.getDomainsIgnoredDueToNegativeDomainFilter() );
1831 log( "Domains ignored due negative domain filter : "
1832 + parser.getDomainsIgnoredDueToNegativeDomainFilter(), log_writer );
1833 System.out.println( "Domains ignored due to overlap : "
1834 + parser.getDomainsIgnoredDueToOverlap() );
1835 log( "Domains ignored due to overlap : " + parser.getDomainsIgnoredDueToOverlap(),
1837 if ( negative_filter_file != null ) {
1838 System.out.println( "Proteins ignored due to negative filter : "
1839 + parser.getProteinsIgnoredDueToFilter() );
1840 log( "Proteins ignored due to negative filter : " + parser.getProteinsIgnoredDueToFilter(),
1843 if ( positive_filter_file != null ) {
1844 System.out.println( "Proteins ignored due to positive filter : "
1845 + parser.getProteinsIgnoredDueToFilter() );
1846 log( "Proteins ignored due to positive filter : " + parser.getProteinsIgnoredDueToFilter(),
1849 System.out.println( "Time for processing : " + parser.getTime() + "ms" );
1850 log( "", log_writer );
1851 html_desc.append( "<tr><td>" + input_file_properties[ i ][ 0 ] + " [species: "
1852 + input_file_properties[ i ][ 1 ] + "]" + ":</td><td>domains analyzed: "
1853 + parser.getDomainsStored() + "; domains ignored: [ind score cutoffs: "
1854 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() + "] [E-value cutoff: "
1855 + parser.getDomainsIgnoredDueToEval() + "] [DUF: " + parser.getDomainsIgnoredDueToDuf()
1856 + "] [virus like ids: " + parser.getDomainsIgnoredDueToVirusLikeIds()
1857 + "] [negative domain filter: " + parser.getDomainsIgnoredDueToNegativeDomainFilter()
1858 + "] [overlap: " + parser.getDomainsIgnoredDueToOverlap() + "]" );
1859 if ( negative_filter_file != null ) {
1860 html_desc.append( "; proteins ignored due to negative filter: "
1861 + parser.getProteinsIgnoredDueToFilter() );
1863 if ( positive_filter_file != null ) {
1864 html_desc.append( "; proteins ignored due to positive filter: "
1865 + parser.getProteinsIgnoredDueToFilter() );
1867 html_desc.append( "</td></tr>" + nl );
1868 // domain_partner_counts_array[ i ] =
1869 // Methods.getDomainPartnerCounts( protein_domain_collections_array[
1871 // false, input_file_properties[ i ][ 1 ] );
1874 for( final Protein protein : protein_list ) {
1875 dc_data_writer.write( SurfacingUtil.proteinToDomainCombinations( protein, count + "", "\t" )
1880 catch ( final IOException e ) {
1881 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1883 gwcd_list.add( BasicGenomeWideCombinableDomains
1884 .createInstance( protein_list,
1885 ignore_combination_with_same,
1886 new BasicSpecies( input_file_properties[ i ][ 1 ] ),
1887 domain_id_to_go_ids_map,
1889 domain_lengths_table.addLengths( protein_list );
1890 if ( gwcd_list.get( i ).getSize() > 0 ) {
1891 SurfacingUtil.writeDomainCombinationsCountsFile( input_file_properties,
1893 per_genome_domain_promiscuity_statistics_writer,
1897 if ( output_binary_domain_combinationsfor_graph_analysis ) {
1898 SurfacingUtil.writeBinaryDomainCombinationsFileForGraphAnalysis( input_file_properties,
1904 SurfacingUtil.addAllDomainIdsToSet( gwcd_list.get( i ), all_domains_encountered );
1905 SurfacingUtil.addAllBinaryDomainCombinationToSet( gwcd_list.get( i ),
1906 all_bin_domain_combinations_encountered );
1908 if ( query_domains_writer_ary != null ) {
1909 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1911 SurfacingUtil.extractProteinNames( protein_list,
1912 query_domain_ids_array[ j ],
1913 query_domains_writer_ary[ j ],
1915 query_domains_writer_ary[ j ].flush();
1917 catch ( final IOException e ) {
1918 e.printStackTrace();
1922 if ( need_protein_lists_per_species ) {
1923 protein_lists_per_species.put( new BasicSpecies( input_file_properties[ i ][ 1 ] ), protein_list );
1928 catch ( final IOException e2 ) {
1929 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1932 } // for( int i = 0; i < number_of_genomes; ++i ) {
1934 per_genome_domain_promiscuity_statistics_writer.flush();
1935 per_genome_domain_promiscuity_statistics_writer.close();
1936 dc_data_writer.flush();
1937 dc_data_writer.close();
1941 catch ( final IOException e2 ) {
1942 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1944 ForesterUtil.programMessage( PRG_NAME, "Wrote domain promiscuities to: "
1945 + per_genome_domain_promiscuity_statistics_file );
1946 if ( query_domains_writer_ary != null ) {
1947 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1949 query_domains_writer_ary[ j ].close();
1951 catch ( final IOException e ) {
1952 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1956 if ( PERFORM_DOMAIN_LENGTH_ANALYSIS ) {
1958 SurfacingUtil.executeDomainLengthAnalysis( input_file_properties,
1960 domain_lengths_table,
1961 domain_lengths_analysis_outfile );
1963 catch ( final IOException e1 ) {
1964 ForesterUtil.fatalError( surfacing.PRG_NAME, e1.toString() );
1966 System.out.println();
1967 ForesterUtil.programMessage( PRG_NAME, "Wrote domain length data to: " + domain_lengths_analysis_outfile );
1968 System.out.println();
1970 final long analysis_start_time = new Date().getTime();
1971 PairwiseDomainSimilarityCalculator pw_calc = null;
1972 // double[] values_for_all_scores_histogram = null;
1973 final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( domain_similarity_sort_field,
1974 sort_by_species_count_first,
1975 number_of_genomes == 2 );
1976 switch ( scoring ) {
1978 pw_calc = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1981 pw_calc = new DomainCountsBasedPairwiseSimilarityCalculator();
1984 pw_calc = new ProteinCountsBasedPairwiseDomainSimilarityCalculator();
1987 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1989 DomainSimilarityCalculator.GoAnnotationOutput go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.NONE;
1990 if ( domain_id_to_go_ids_map != null ) {
1991 go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.ALL;
1993 final SortedSet<DomainSimilarity> similarities = calc
1994 .calculateSimilarities( pw_calc,
1996 ignore_domains_without_combs_in_all_spec,
1997 ignore_species_specific_domains );
1998 SurfacingUtil.decoratePrintableDomainSimilarities( similarities,
2000 go_annotation_output,
2002 go_namespace_limit );
2003 DescriptiveStatistics pw_stats = null;
2005 String my_outfile = output_file.toString();
2006 if ( !my_outfile.endsWith( ".html" ) ) {
2007 my_outfile += ".html";
2009 final Writer writer = new BufferedWriter( new FileWriter( out_dir == null ? my_outfile : out_dir
2010 + ForesterUtil.FILE_SEPARATOR + my_outfile ) );
2011 List<Species> species_order = null;
2012 if ( species_matrix ) {
2013 species_order = new ArrayList<Species>();
2014 for( int i = 0; i < number_of_genomes; i++ ) {
2015 species_order.add( new BasicSpecies( input_file_properties[ i ][ 1 ] ) );
2018 html_desc.append( "<tr><td>Sum of all distinct binary combinations:</td><td>"
2019 + all_bin_domain_combinations_encountered.size() + "</td></tr>" + nl );
2020 html_desc.append( "<tr><td>Sum of all distinct domains:</td><td>" + all_domains_encountered.size()
2021 + "</td></tr>" + nl );
2022 html_desc.append( "<tr><td>Analysis date/time:</td><td>"
2023 + new java.text.SimpleDateFormat( "yyyy.MM.dd HH:mm:ss" ).format( new java.util.Date() )
2024 + "</td></tr>" + nl );
2025 html_desc.append( "</table>" + nl );
2026 pw_stats = SurfacingUtil
2027 .writeDomainSimilaritiesToFile( html_desc,
2028 new StringBuilder( number_of_genomes + " genomes" ),
2031 number_of_genomes == 2,
2033 domain_similarity_print_option,
2034 domain_similarity_sort_field,
2037 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote main output (includes domain similarities) to: \""
2038 + ( out_dir == null ? my_outfile : out_dir + ForesterUtil.FILE_SEPARATOR + my_outfile ) + "\"" );
2040 catch ( final IOException e ) {
2041 ForesterUtil.fatalError( surfacing.PRG_NAME, "Failed to write similarites to: \"" + output_file + "\" ["
2042 + e.getMessage() + "]" );
2044 System.out.println();
2045 // values_for_all_scores_histogram = pw_stats.getDataAsDoubleArray();
2046 final Species[] species = new Species[ number_of_genomes ];
2047 for( int i = 0; i < number_of_genomes; ++i ) {
2048 species[ i ] = new BasicSpecies( input_file_properties[ i ][ 1 ] );
2050 List<Phylogeny> inferred_trees = null;
2051 if ( ( number_of_genomes > 2 ) && perform_pwc ) {
2052 final PairwiseGenomeComparator pwgc = new PairwiseGenomeComparator();
2053 pwgc.performPairwiseComparisons( html_desc,
2054 sort_by_species_count_first,
2056 ignore_domains_without_combs_in_all_spec,
2057 ignore_species_specific_domains,
2058 domain_similarity_sort_field_for_automated_pwc,
2059 domain_similarity_print_option,
2061 domain_id_to_go_ids_map,
2068 automated_pairwise_comparison_suffix,
2070 surfacing.PAIRWISE_DOMAIN_COMPARISONS_PREFIX,
2075 String matrix_output_file = new String( output_file.toString() );
2076 if ( matrix_output_file.indexOf( '.' ) > 1 ) {
2077 matrix_output_file = matrix_output_file.substring( 0, matrix_output_file.indexOf( '.' ) );
2079 if ( out_dir != null ) {
2080 matrix_output_file = out_dir + ForesterUtil.FILE_SEPARATOR + matrix_output_file;
2081 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
2083 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
2084 + surfacing.MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc.getDomainDistanceScoresMeans() );
2085 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
2086 + surfacing.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2087 .getSharedBinaryCombinationsBasedDistances() );
2088 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
2089 + surfacing.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2090 .getSharedDomainsBasedDistances() );
2091 final Phylogeny nj_gd = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2092 + surfacing.NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc.getDomainDistanceScoresMeans()
2094 final Phylogeny nj_bc = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2095 + surfacing.NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2096 .getSharedBinaryCombinationsBasedDistances().get( 0 ) );
2097 final Phylogeny nj_d = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2098 + surfacing.NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2099 .getSharedDomainsBasedDistances().get( 0 ) );
2100 inferred_trees = new ArrayList<Phylogeny>();
2101 inferred_trees.add( nj_gd );
2102 inferred_trees.add( nj_bc );
2103 inferred_trees.add( nj_d );
2104 // final List<HistogramData> histogram_datas = pwgc.getHistogramDatas();
2105 // if ( infer_species_trees ) {
2106 // inferred_trees = new ArrayList<Phylogeny>();
2107 // final List<Phylogeny> inferred_trees_bc = inferSpeciesTrees( new File( output_file + INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2108 // .getSharedBinaryCombinationsBasedDistances() );
2109 // final List<Phylogeny> inferred_trees_d = inferSpeciesTrees( new File( output_file + INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2110 // .getSharedDomainsBasedDistances() );
2111 // inferred_trees.addAll( inferred_trees_bc );
2112 // inferred_trees.addAll( inferred_trees_d );
2114 if ( jacknifed_distances ) {
2115 pwgc.performPairwiseComparisonsJacknifed( species,
2119 jacknife_resamplings,
2122 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file + "_"
2123 + ForesterUtil.round( jacknife_ratio, 2 ) + "_" + jacknife_resamplings
2124 + surfacing.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2125 .getSharedBinaryCombinationsBasedDistances() );
2126 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file + "_"
2127 + ForesterUtil.round( jacknife_ratio, 2 ) + "_" + jacknife_resamplings
2128 + surfacing.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
2129 .getSharedDomainsBasedDistances() );
2130 // if ( infer_species_trees ) {
2131 // inferSpeciesTrees( new File( output_file + "_" + jacknife_resamplings
2132 // + INFERRED_SBC_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc
2133 // .getSharedBinaryCombinationsBasedDistances() );
2134 // inferSpeciesTrees( new File( output_file + "_" + jacknife_resamplings
2135 // + INFERRED_SD_BASED_NJ_SPECIES_TREE_SUFFIX ), pwgc.getSharedDomainsBasedDistances() );
2138 if ( display_histograms ) {
2139 // final List<HistogramData> histogram_datas_all = new ArrayList<HistogramData>();
2140 // histogram_datas_all.add( new HistogramData( "all",
2141 // values_for_all_scores_histogram,
2144 // final HistogramsFrame hf_all = new HistogramsFrame( histogram_datas_all );
2145 // final HistogramsFrame hf = new HistogramsFrame( histogram_datas );
2146 // hf_all.setVisible( true );
2147 // hf.setVisible( true );
2149 } // if ( ( output_file != null ) && ( number_of_genomes > 2 ) && !isEmpty( automated_pairwise_comparison_suffix ) )
2150 if ( ( out_dir != null ) && ( !perform_pwc ) ) {
2151 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
2153 writePresentToNexus( output_file, positive_filter_file, filter, gwcd_list );
2154 if ( ( ( intrees != null ) && ( intrees.length > 0 ) ) && ( number_of_genomes > 2 ) ) {
2155 final StringBuilder parameters_sb = createParametersAsString( ignore_dufs,
2157 max_allowed_overlap,
2158 no_engulfing_overlaps,
2162 if ( radomize_fitch_parsimony ) {
2163 s += random_number_seed_for_fitch_parsimony + "_";
2166 for( final Phylogeny intree : intrees ) {
2167 final String outfile_name = ForesterUtil.removeSuffix( output_file.toString() ) + s
2168 + ForesterUtil.removeSuffix( intree_files[ i ].toString() );
2169 final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator.createInstance( intree,
2171 SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
2172 radomize_fitch_parsimony,
2176 domain_id_to_go_ids_map,
2179 parameters_sb.toString(),
2180 domain_id_to_secondary_features_maps,
2181 positive_filter_file == null ? null : filter,
2182 output_binary_domain_combinationsfor_graph_analysis,
2183 all_bin_domain_combinations_gained_fitch,
2184 all_bin_domain_combinations_lost_fitch,
2186 // Listing of all domain combinations gained is only done if only one input tree is used.
2187 if ( ( domain_id_to_secondary_features_maps != null )
2188 && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
2190 for( final Map<DomainId, Set<String>> domain_id_to_secondary_features_map : domain_id_to_secondary_features_maps ) {
2191 final Map<Species, MappingResults> mapping_results_map = new TreeMap<Species, MappingResults>();
2192 final DomainParsimonyCalculator secondary_features_parsimony = DomainParsimonyCalculator
2193 .createInstance( intree, gwcd_list, domain_id_to_secondary_features_map );
2195 .executeParsimonyAnalysisForSecondaryFeatures( outfile_name
2197 + secondary_features_map_files[ j++ ],
2198 secondary_features_parsimony,
2200 parameters_sb.toString(),
2201 mapping_results_map );
2203 System.out.println();
2204 System.out.println( "Mapping to secondary features:" );
2205 for( final Species spec : mapping_results_map.keySet() ) {
2206 final MappingResults mapping_results = mapping_results_map.get( spec );
2207 final int total_domains = mapping_results.getSumOfFailures()
2208 + mapping_results.getSumOfSuccesses();
2209 System.out.print( spec + ":" );
2210 System.out.print( " mapped domains = " + mapping_results.getSumOfSuccesses() );
2211 System.out.print( ", not mapped domains = " + mapping_results.getSumOfFailures() );
2212 if ( total_domains > 0 ) {
2213 System.out.println( ", mapped ratio = "
2214 + ( 100 * mapping_results.getSumOfSuccesses() / total_domains ) + "%" );
2217 System.out.println( ", mapped ratio = n/a (total domains = 0 )" );
2224 } // for( final Phylogeny intree : intrees ) {
2226 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
2227 executePlusMinusAnalysis( output_file,
2228 plus_minus_analysis_high_copy_base_species,
2229 plus_minus_analysis_high_copy_target_species,
2230 plus_minus_analysis_high_low_copy_species,
2232 protein_lists_per_species,
2233 domain_id_to_go_ids_map,
2235 plus_minus_analysis_numbers );
2237 if ( output_protein_lists_for_all_domains ) {
2238 writeProteinListsForAllSpecies( out_dir, protein_lists_per_species, gwcd_list );
2240 // if ( ( intrees != null ) && ( intrees.length > 0 ) && ( inferred_trees != null ) && ( inferred_trees.size() > 0 ) ) {
2241 // final StringBuilder parameters_sb = createParametersAsString( ignore_dufs,
2243 // max_allowed_overlap,
2244 // no_engulfing_overlaps,
2245 // cutoff_scores_file );
2247 // if ( radomize_fitch_parsimony ) {
2248 // s += random_number_seed_for_fitch_parsimony + "_";
2251 // for( final Phylogeny inferred_tree : inferred_trees ) {
2252 // if ( !inferred_tree.isRooted() ) {
2253 // intrees[ 0 ].getRoot().getName();
2256 // final String outfile_name = ForesterUtil.removeSuffix( inferred_tree.getName() ) + s;
2257 // final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator
2258 // .createInstance( inferred_tree, gwcd_list );
2259 // SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
2260 // radomize_fitch_parsimony,
2262 // domain_parsimony,
2264 // domain_id_to_go_ids_map,
2265 // go_id_to_term_map,
2266 // go_namespace_limit,
2267 // parameters_sb.toString() );
2271 if ( all_bin_domain_combinations_gained_fitch != null ) {
2273 executeFitchGainsAnalysis( new File( output_file
2274 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2275 all_bin_domain_combinations_gained_fitch,
2276 all_domains_encountered.size(),
2277 all_bin_domain_combinations_encountered,
2280 catch ( final IOException e ) {
2281 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2284 if ( all_bin_domain_combinations_lost_fitch != null ) {
2286 executeFitchGainsAnalysis( new File( output_file
2287 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2288 all_bin_domain_combinations_lost_fitch,
2289 all_domains_encountered.size(),
2290 all_bin_domain_combinations_encountered,
2293 catch ( final IOException e ) {
2294 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2297 final Runtime rt = java.lang.Runtime.getRuntime();
2298 final long free_memory = rt.freeMemory() / 1000000;
2299 final long total_memory = rt.totalMemory() / 1000000;
2300 System.out.println();
2301 System.out.println( "Time for analysis : " + ( new Date().getTime() - analysis_start_time ) + "ms" );
2302 System.out.println( "Total running time: " + ( new Date().getTime() - start_time ) + "ms " );
2303 System.out.println( "Free memory : " + free_memory + "MB, total memory: " + total_memory + "MB" );
2304 System.out.println();
2305 System.out.println( "If this application is useful to you, please cite:" );
2306 System.out.println( surfacing.WWW );
2307 System.out.println();
2308 ForesterUtil.programMessage( PRG_NAME, "OK" );
2309 System.out.println();
2312 private static void preparePhylogenyForParsimonyAnalyses( final Phylogeny intree,
2313 final String[][] input_file_properties ) {
2314 final String[] genomes = new String[ input_file_properties.length ];
2315 for( int i = 0; i < input_file_properties.length; ++i ) {
2316 if ( intree.getNodes( input_file_properties[ i ][ 1 ] ).size() > 1 ) {
2317 ForesterUtil.fatalError( surfacing.PRG_NAME, "node named [" + input_file_properties[ i ][ 1 ]
2318 + "] is not unique in input tree " + intree.getName() );
2320 genomes[ i ] = input_file_properties[ i ][ 1 ];
2323 final PhylogenyNodeIterator it = intree.iteratorPostorder();
2324 while ( it.hasNext() ) {
2325 final PhylogenyNode n = it.next();
2326 if ( ForesterUtil.isEmpty( n.getName() ) ) {
2327 if ( n.getNodeData().isHasTaxonomy()
2328 && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
2329 n.setName( n.getNodeData().getTaxonomy().getScientificName() );
2332 ForesterUtil.fatalError( surfacing.PRG_NAME,
2333 "node without both name and scientific taxonomy name found" );
2338 final List<String> igns = PhylogenyMethods.deleteExternalNodesPositiveSelection( genomes, intree );
2339 if ( igns.size() > 0 ) {
2340 System.out.println( "Not using the following " + igns.size() + " nodes:" );
2341 for( int i = 0; i < igns.size(); ++i ) {
2342 System.out.println( " " + i + ": " + igns.get( i ) );
2344 System.out.println( "--" );
2346 for( int i = 0; i < input_file_properties.length; ++i ) {
2348 intree.getNode( input_file_properties[ i ][ 1 ] );
2350 catch ( final IllegalArgumentException e ) {
2351 ForesterUtil.fatalError( surfacing.PRG_NAME, "node named [" + input_file_properties[ i ][ 1 ]
2352 + "] not present/not unique in input tree" );
2357 // public static StringBuffer stringCombinableDomainsMapToStringBuffer(
2358 // final SortedMap<String, CombinableDomains> map ) {
2359 // final StringBuffer sb = new StringBuffer();
2360 // for( final Iterator<String> iter = map.keySet().iterator();
2361 // iter.hasNext(); ) {
2362 // final Object key = iter.next();
2363 // sb.append( ForesterUtil.pad( new StringBuffer( key.toString() ), 18, ' ',
2365 // final CombinableDomains domain_combination = map.get( key );
2366 // sb.append( ForesterUtil.pad( new StringBuffer( "" +
2367 // domain_combination.getNumberOfCombiningDomains() ), 8,
2369 // sb.append( domain_combination.toStringBuffer() );
2370 // sb.append( ForesterUtil.getLineSeparator() );
2374 private static void printHelp() {
2375 System.out.println();
2376 System.out.println( "Usage:" );
2377 System.out.println();
2378 System.out.println( "% java -Xms256m -Xmx512m -cp forester.jar org.forester.applications." + surfacing.PRG_NAME
2379 + " [options] <phylogen(y|ies) infile> [external node name 1] [name 2] ... [name n]" );
2380 System.out.println();
2381 System.out.println( " Note: This software might need a significant amount of memory (heap space);" );
2383 .println( " hence use \"-Xms128m -Xmx512m\" (or more) to prevent a \"java.lang.OutOfMemoryError\"." );
2384 System.out.println();
2385 System.out.println( " Options: " );
2386 System.out.println( surfacing.DETAILEDNESS_OPTION + ": level of detail for similarities output file (default:"
2387 + DETAILEDNESS_DEFAULT + ")" );
2388 System.out.println( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION
2389 + ": to ignore combinations with self (default: not to ignore)" );
2391 .println( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION
2392 + ": to ignore domains without combinations in any species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2394 .println( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION
2395 + ": to ignore domains specific to one species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2396 System.out.println( surfacing.NOT_IGNORE_DUFS_OPTION
2397 + ": to _not_ ignore DUFs (domains with unknown function) (default: ignore DUFs)" );
2399 .println( surfacing.IGNORE_VIRAL_IDS
2400 + ": to ignore domains with ids containing 'vir', 'retro', 'transpos', 'phage', or starting with 'rv' or 'gag_'" );
2401 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_OPTION + ": sorting for similarities (default: "
2402 + DOMAIN_SORT_FILD_DEFAULT + ")" );
2403 System.out.println( surfacing.OUTPUT_FILE_OPTION + ": name for (main) output file (mandatory)" );
2404 System.out.println( surfacing.MAX_E_VALUE_OPTION + ": max (inclusive) E-value" );
2405 System.out.println( surfacing.MAX_ALLOWED_OVERLAP_OPTION + ": maximal allowed domain overlap" );
2406 System.out.println( surfacing.NO_ENGULFING_OVERLAP_OPTION + ": to ignore engulfed lower confidence domains" );
2407 System.out.println( surfacing.SPECIES_MATRIX_OPTION + ": species matrix" );
2408 System.out.println( surfacing.SCORING_OPTION + ": scoring (default:" + SCORING_DEFAULT + ")" );
2409 System.out.println( surfacing.DOMAIN_COUNT_SORT_OPTION + ": sorting for domain counts (default:"
2410 + DOMAINS_SORT_ORDER_DEFAULT + ")" );
2411 System.out.println( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION + ": domain similarity print option (default:"
2412 + DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT + ")" );
2413 System.out.println( surfacing.CUTOFF_SCORE_FILE_OPTION + ": cutoff score file" );
2414 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION
2415 + ": sort by species count first" );
2416 System.out.println( surfacing.OUTPUT_DIR_OPTION + ": output directory" );
2417 System.out.println( surfacing.PFAM_TO_GO_FILE_USE_OPTION + ": Pfam to GO mapping file" );
2418 System.out.println( surfacing.GO_OBO_FILE_USE_OPTION + ": GO terms file (OBO format)" );
2419 System.out.println( surfacing.GO_NAMESPACE_LIMIT_OPTION + ": limit GO term to one GO namespace" );
2420 System.out.println( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
2421 + "[=<suffix for pairwise comparison output files>]: to perform pairwise comparison based analyses" );
2422 System.out.println( surfacing.INPUT_SPECIES_TREE_OPTION
2423 + ": species tree, to perform (Dollo, Fitch) parismony analyses" );
2425 .println( surfacing.DISPLAY_M_HISTOGRAMS_OPTION + ": to display multiple histograms (using fluorite)" );
2427 .println( JACKNIFE_OPTION
2428 + ": perform jacknife resampling for domain and binary domain combination based distance matrices [default resamplings: "
2429 + JACKNIFE_NUMBER_OF_RESAMPLINGS_DEFAULT + "]" );
2430 System.out.println( JACKNIFE_RATIO_OPTION + ": ratio for jacknife resampling [default: "
2431 + JACKNIFE_RATIO_DEFAULT + "]" );
2432 System.out.println( JACKNIFE_RANDOM_SEED_OPTION
2433 + ": seed for random number generator for jacknife resampling [default: "
2434 + JACKNIFE_RANDOM_SEED_DEFAULT + "]" );
2435 // System.out.println( surfacing.INFER_SPECIES_TREES_OPTION
2436 // + ": to infer NJ species trees based on shared domains/binary domain combinations" );
2438 .println( surfacing.INPUT_SPECIES_TREE_OPTION
2439 + "=<treefiles in phyloXML format, separated by #>: to infer domain/binary domain combination gains/losses on given species trees" );
2440 System.out.println( surfacing.FILTER_POSITIVE_OPTION
2441 + "=<file>: to filter out proteins not containing at least one domain listed in <file>" );
2442 System.out.println( surfacing.FILTER_NEGATIVE_OPTION
2443 + "=<file>: to filter out proteins containing at least one domain listed in <file>" );
2444 System.out.println( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION
2445 + "=<file>: to filter out (ignore) domains listed in <file>" );
2446 System.out.println( surfacing.INPUT_FILES_FROM_FILE_OPTION + "=<file>: to read input files from <file>" );
2448 .println( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION
2449 + "=<seed>: seed for random number generator for Fitch Parsimony analysis (type: long, default: no randomization - given a choice, prefer absence" );
2450 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS
2451 + ": to consider directedness in binary combinations: e.g. A-B != B-A" );
2452 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY
2453 + ": to consider directedness and adjacency in binary combinations" );
2455 .println( surfacing.SEQ_EXTRACT_OPTION
2456 + "=<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')" );
2457 System.out.println( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE
2458 + "=<file>: to perfom parsimony analysis on secondary features" );
2459 System.out.println( surfacing.PLUS_MINUS_ANALYSIS_OPTION + "=<file>: to presence/absence genome analysis" );
2460 System.out.println( surfacing.DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS
2461 + ": to output binary domain combinations for (downstream) graph analysis" );
2462 System.out.println( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS + ": to output all proteins per domain" );
2463 System.out.println();
2464 System.out.println();
2465 System.out.println( "Example: java -Xms128m -Xmx512m -cp path/to/forester.jar"
2466 + "org.forester.application.surfacing -detail=punctilious -o=TEST.html -pwc=TEST"
2467 + " -cos=Pfam_ls_22_TC2 -p2g=pfam2go -obo=gene_ontology_edit.obo "
2468 + "-dc_sort=dom -ignore_with_self -no_singles -e=0.001 -mo=1 -no_eo "
2469 + "-ds_output=detailed_html -scoring=domains -sort=alpha -" + JACKNIFE_OPTION
2470 + "=50 human mouse brafl strpu" );
2471 System.out.println();
2474 private static void processFilter( final File filter_file, final SortedSet<DomainId> filter ) {
2475 SortedSet<String> filter_str = null;
2477 filter_str = ForesterUtil.file2set( filter_file );
2479 catch ( final IOException e ) {
2480 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
2482 if ( filter_str != null ) {
2483 for( final String string : filter_str ) {
2484 filter.add( new DomainId( string ) );
2488 System.out.println( "Filter:" );
2489 for( final DomainId domainId : filter ) {
2490 System.out.println( domainId.getId() );
2495 private static String[][] processInputFileNames( final String[] names ) {
2496 final String[][] input_file_properties = new String[ names.length ][];
2497 for( int i = 0; i < names.length; ++i ) {
2498 if ( names[ i ].indexOf( SEPARATOR_FOR_INPUT_VALUES ) < 0 ) {
2499 input_file_properties[ i ] = new String[ 2 ];
2500 input_file_properties[ i ][ 0 ] = names[ i ];
2501 input_file_properties[ i ][ 1 ] = names[ i ];
2504 input_file_properties[ i ] = names[ i ].split( surfacing.SEPARATOR_FOR_INPUT_VALUES + "" );
2505 if ( input_file_properties[ i ].length != 3 ) {
2507 .fatalError( surfacing.PRG_NAME,
2508 "properties for the input files (hmmpfam output) are expected "
2509 + "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 \""
2510 + names[ i ] + "\"" );
2513 final String error = ForesterUtil.isReadableFile( new File( input_file_properties[ i ][ 0 ] ) );
2514 if ( !ForesterUtil.isEmpty( error ) ) {
2515 ForesterUtil.fatalError( surfacing.PRG_NAME, error );
2518 return input_file_properties;
2521 private static void processPlusMinusAnalysisOption( final CommandLineArguments cla,
2522 final List<String> high_copy_base,
2523 final List<String> high_copy_target,
2524 final List<String> low_copy,
2525 final List<Object> numbers ) {
2526 if ( cla.isOptionSet( surfacing.PLUS_MINUS_ANALYSIS_OPTION ) ) {
2527 if ( !cla.isOptionValueSet( surfacing.PLUS_MINUS_ANALYSIS_OPTION ) ) {
2528 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for 'plus-minus' file: -"
2529 + surfacing.PLUS_MINUS_ANALYSIS_OPTION + "=<file>" );
2531 final File plus_minus_file = new File( cla.getOptionValue( surfacing.PLUS_MINUS_ANALYSIS_OPTION ) );
2532 final String msg = ForesterUtil.isReadableFile( plus_minus_file );
2533 if ( !ForesterUtil.isEmpty( msg ) ) {
2534 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + plus_minus_file + "\": " + msg );
2536 processPlusMinusFile( plus_minus_file, high_copy_base, high_copy_target, low_copy, numbers );
2540 // First numbers is minimal difference, second is factor.
2541 private static void processPlusMinusFile( final File plus_minus_file,
2542 final List<String> high_copy_base,
2543 final List<String> high_copy_target,
2544 final List<String> low_copy,
2545 final List<Object> numbers ) {
2546 Set<String> species_set = null;
2547 int min_diff = PLUS_MINUS_ANALYSIS_MIN_DIFF_DEFAULT;
2548 double factor = PLUS_MINUS_ANALYSIS_FACTOR_DEFAULT;
2550 species_set = ForesterUtil.file2set( plus_minus_file );
2552 catch ( final IOException e ) {
2553 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
2555 if ( species_set != null ) {
2556 for( final String species : species_set ) {
2557 final String species_trimmed = species.substring( 1 );
2558 if ( species.startsWith( "+" ) ) {
2559 if ( low_copy.contains( species_trimmed ) ) {
2560 ForesterUtil.fatalError( surfacing.PRG_NAME,
2561 "species/genome names can not appear with both '+' and '-' suffix, as appears the case for: \""
2562 + species_trimmed + "\"" );
2564 high_copy_base.add( species_trimmed );
2566 else if ( species.startsWith( "*" ) ) {
2567 if ( low_copy.contains( species_trimmed ) ) {
2568 ForesterUtil.fatalError( surfacing.PRG_NAME,
2569 "species/genome names can not appear with both '*' and '-' suffix, as appears the case for: \""
2570 + species_trimmed + "\"" );
2572 high_copy_target.add( species_trimmed );
2574 else if ( species.startsWith( "-" ) ) {
2575 if ( high_copy_base.contains( species_trimmed ) || high_copy_target.contains( species_trimmed ) ) {
2576 ForesterUtil.fatalError( surfacing.PRG_NAME,
2577 "species/genome names can not appear with both '+' or '*' and '-' suffix, as appears the case for: \""
2578 + species_trimmed + "\"" );
2580 low_copy.add( species_trimmed );
2582 else if ( species.startsWith( "$D" ) ) {
2584 min_diff = Integer.parseInt( species.substring( 3 ) );
2586 catch ( final NumberFormatException e ) {
2587 ForesterUtil.fatalError( surfacing.PRG_NAME,
2588 "could not parse integer value for minimal difference from: \""
2589 + species.substring( 3 ) + "\"" );
2592 else if ( species.startsWith( "$F" ) ) {
2594 factor = Double.parseDouble( species.substring( 3 ) );
2596 catch ( final NumberFormatException e ) {
2597 ForesterUtil.fatalError( surfacing.PRG_NAME, "could not parse double value for factor from: \""
2598 + species.substring( 3 ) + "\"" );
2601 else if ( species.startsWith( "#" ) ) {
2606 .fatalError( surfacing.PRG_NAME,
2607 "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: \""
2610 numbers.add( new Integer( min_diff + "" ) );
2611 numbers.add( new Double( factor + "" ) );
2615 ForesterUtil.fatalError( surfacing.PRG_NAME, "'plus minus' file [" + plus_minus_file + "] appears empty" );
2619 private static void writePresentToNexus( final File output_file,
2620 final File positive_filter_file,
2621 final SortedSet<DomainId> filter,
2622 final List<GenomeWideCombinableDomains> gwcd_list ) {
2625 .writeMatrixToFile( DomainParsimonyCalculator
2626 .createMatrixOfDomainPresenceOrAbsence( gwcd_list, positive_filter_file == null ? null
2627 : filter ), output_file + DOMAINS_PRESENT_NEXUS, Format.NEXUS_BINARY );
2628 SurfacingUtil.writeMatrixToFile( DomainParsimonyCalculator
2629 .createMatrixOfBinaryDomainCombinationPresenceOrAbsence( gwcd_list ), output_file
2630 + BDC_PRESENT_NEXUS, Format.NEXUS_BINARY );
2632 catch ( final Exception e ) {
2633 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
2637 private static void writeProteinListsForAllSpecies( final File output_dir,
2638 final SortedMap<Species, List<Protein>> protein_lists_per_species,
2639 final List<GenomeWideCombinableDomains> gwcd_list ) {
2640 final SortedSet<DomainId> all_domains = new TreeSet<DomainId>();
2641 for( final GenomeWideCombinableDomains gwcd : gwcd_list ) {
2642 all_domains.addAll( gwcd.getAllDomainIds() );
2644 for( final DomainId domain : all_domains ) {
2645 final File out = new File( output_dir + ForesterUtil.FILE_SEPARATOR + domain + SEQ_EXTRACT_SUFFIX );
2646 SurfacingUtil.checkForOutputFileWriteability( out );
2648 final Writer proteins_file_writer = new BufferedWriter( new FileWriter( out ) );
2649 SurfacingUtil.extractProteinNames( protein_lists_per_species, domain, proteins_file_writer, "\t" );
2650 proteins_file_writer.close();
2652 catch ( final IOException e ) {
2653 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
2655 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote proteins list to \"" + out + "\"" );