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: https://sites.google.com/site/cmzmasek/home/software/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.HashMap;
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.go.GoId;
46 import org.forester.go.GoNameSpace;
47 import org.forester.go.GoTerm;
48 import org.forester.go.GoUtils;
49 import org.forester.go.OBOparser;
50 import org.forester.go.PfamToGoMapping;
51 import org.forester.go.PfamToGoParser;
52 import org.forester.io.parsers.HmmscanPerDomainTableParser;
53 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
54 import org.forester.phylogeny.Phylogeny;
55 import org.forester.protein.BinaryDomainCombination;
56 import org.forester.protein.Domain;
57 import org.forester.protein.Protein;
58 import org.forester.species.BasicSpecies;
59 import org.forester.species.Species;
60 import org.forester.surfacing.BasicDomainSimilarityCalculator;
61 import org.forester.surfacing.BasicGenomeWideCombinableDomains;
62 import org.forester.surfacing.CombinationsBasedPairwiseDomainSimilarityCalculator;
63 import org.forester.surfacing.DomainCountsBasedPairwiseSimilarityCalculator;
64 import org.forester.surfacing.DomainLengthsTable;
65 import org.forester.surfacing.DomainParsimonyCalculator;
66 import org.forester.surfacing.DomainSimilarity;
67 import org.forester.surfacing.DomainSimilarity.DomainSimilarityScoring;
68 import org.forester.surfacing.DomainSimilarity.DomainSimilaritySortField;
69 import org.forester.surfacing.DomainSimilarityCalculator;
70 import org.forester.surfacing.DomainSimilarityCalculator.Detailedness;
71 import org.forester.surfacing.GenomeWideCombinableDomains;
72 import org.forester.surfacing.GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder;
73 import org.forester.surfacing.MappingResults;
74 import org.forester.surfacing.PairwiseDomainSimilarityCalculator;
75 import org.forester.surfacing.PairwiseGenomeComparator;
76 import org.forester.surfacing.PrintableDomainSimilarity;
77 import org.forester.surfacing.PrintableDomainSimilarity.PRINT_OPTION;
78 import org.forester.surfacing.ProteinCountsBasedPairwiseDomainSimilarityCalculator;
79 import org.forester.surfacing.SurfacingUtil;
80 import org.forester.util.BasicDescriptiveStatistics;
81 import org.forester.util.BasicTable;
82 import org.forester.util.BasicTableParser;
83 import org.forester.util.CommandLineArguments;
84 import org.forester.util.DescriptiveStatistics;
85 import org.forester.util.ForesterConstants;
86 import org.forester.util.ForesterUtil;
88 public class surfacing {
90 private static final int MINIMAL_NUMBER_OF_SIMILARITIES_FOR_SPLITTING = 1000;
91 public final static String DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS = "graph_analysis_out";
92 public final static String DOMAIN_COMBINITONS_OUTPUTFILE_SUFFIX_FOR_GRAPH_ANALYSIS = "_dc.dot";
93 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_BC_OUTPUTFILE_SUFFIX_FOR_GRAPH_ANALYSIS = "_fitch_present_dc.dot";
94 public final static String DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX = ".dcc";
96 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_DOMAINS = "_dollo_gl_d";
97 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_BINARY_COMBINATIONS = "_dollo_gl_dc";
98 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_FITCH_DOMAINS = "_fitch_gl_d";
99 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_FITCH_BINARY_COMBINATIONS = "_fitch_gl_dc";
101 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_DOMAINS = "_dollo_glc_d";
102 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_BINARY_COMBINATIONS = "_dollo_glc_dc";
103 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_FITCH_DOMAINS = "_fitch_glc_d";
104 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_FITCH_BINARY_COMBINATIONS = "_fitch_glc_dc";
106 public final static String PARSIMONY_OUTPUT_FITCH_GAINS_BC = "_fitch_gains_dc";
107 public final static String PARSIMONY_OUTPUT_FITCH_GAINS_HTML_BC = "_fitch_gains_dc.html";
108 public final static String PARSIMONY_OUTPUT_FITCH_LOSSES_BC = "_fitch_losses_dc";
109 public final static String PARSIMONY_OUTPUT_FITCH_LOSSES_HTML_BC = "_fitch_losses_dc.html";
110 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_BC = "_fitch_present_dc";
111 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_HTML_BC = "_fitch_present_dc.html";
112 public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_D = "_dollo_gains_d";
113 public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_HTML_D = "_dollo_gains_d.html";
114 public final static String PARSIMONY_OUTPUT_DOLLO_LOSSES_D = "_dollo_losses_d";
115 public final static String PARSIMONY_OUTPUT_DOLLO_LOSSES_HTML_D = "_dollo_losses_d.html";
116 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_D = "_dollo_present_d";
117 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_HTML_D = "_dollo_present_d.html";
118 public final static String DOMAINS_PRESENT_NEXUS = "_dom.nex";
119 public final static String BDC_PRESENT_NEXUS = "_dc.nex";
121 public final static String PRG_NAME = "surfacing";
122 public static final String DOMAINS_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_d_dollo"
123 + ForesterConstants.PHYLO_XML_SUFFIX;
124 public static final String DOMAINS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH = "_d_fitch"
125 + ForesterConstants.PHYLO_XML_SUFFIX;
126 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_dc_dollo"
127 + ForesterConstants.PHYLO_XML_SUFFIX;
128 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH = "_dc_fitch"
129 + ForesterConstants.PHYLO_XML_SUFFIX;
130 public static final String NEXUS_EXTERNAL_DOMAINS = "_dom.nex";
131 public static final String NEXUS_EXTERNAL_DOMAIN_COMBINATIONS = "_dc.nex";
132 public static final String NEXUS_SECONDARY_FEATURES = "_secondary_features.nex";
133 public static final String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_SECONDARY_FEATURES = "_dollo_gl_secondary_features";
134 public static final String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_SECONDARY_FEATURES = "_dollo_glc_secondary_features";
135 public static final String PARSIMONY_OUTPUT_DOLLO_GAINS_SECONDARY_FEATURES = "_dollo_gains_secondary_features";
136 public static final String PARSIMONY_OUTPUT_DOLLO_LOSSES_SECONDARY_FEATURES = "_dollo_losses_secondary_features";
137 public static final String PARSIMONY_OUTPUT_DOLLO_PRESENT_SECONDARY_FEATURES = "_dollo_present_secondary_features";
138 public static final String SECONDARY_FEATURES_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_secondary_features_dollo"
139 + ForesterConstants.PHYLO_XML_SUFFIX;
140 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_ALL_NAMESPACES = "_dollo_goid_d";
141 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_ALL_NAMESPACES = "_fitch_goid_dc";
142 final static private String HELP_OPTION_1 = "help";
143 final static private String HELP_OPTION_2 = "h";
144 final static private String OUTPUT_DIR_OPTION = "out_dir";
145 final static private String SCORING_OPTION = "scoring";
146 private static final DomainSimilarityScoring SCORING_DEFAULT = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
147 final static private String SCORING_DOMAIN_COUNT_BASED = "domains";
148 final static private String SCORING_PROTEIN_COUNT_BASED = "proteins";
149 final static private String SCORING_COMBINATION_BASED = "combinations";
150 final static private String DETAILEDNESS_OPTION = "detail";
151 private final static Detailedness DETAILEDNESS_DEFAULT = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
152 final static private String SPECIES_MATRIX_OPTION = "smatrix";
153 final static private String DETAILEDNESS_BASIC = "basic";
154 final static private String DETAILEDNESS_LIST_IDS = "list_ids";
155 final static private String DETAILEDNESS_PUNCTILIOUS = "punctilious";
156 final static private String DOMAIN_SIMILARITY_SORT_OPTION = "sort";
157 private static final DomainSimilaritySortField DOMAIN_SORT_FILD_DEFAULT = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
158 final static private String DOMAIN_SIMILARITY_SORT_MIN = "min";
159 final static private String DOMAIN_SIMILARITY_SORT_MAX = "max";
160 final static private String DOMAIN_SIMILARITY_SORT_SD = "sd";
161 final static private String DOMAIN_SIMILARITY_SORT_MEAN = "mean";
162 final static private String DOMAIN_SIMILARITY_SORT_DIFF = "diff";
163 final static private String DOMAIN_SIMILARITY_SORT_COUNTS_DIFF = "count_diff";
164 final static private String DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF = "abs_count_diff";
165 final static private String DOMAIN_SIMILARITY_SORT_SPECIES_COUNT = "species";
166 final static private String DOMAIN_SIMILARITY_SORT_ALPHA = "alpha";
167 final static private String DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION = "species_first";
168 final static private String DOMAIN_COUNT_SORT_OPTION = "dc_sort";
169 private static final GenomeWideCombinableDomainsSortOrder DOMAINS_SORT_ORDER_DEFAULT = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
170 final static private String DOMAIN_COUNT_SORT_ALPHA = "alpha";
171 final static private String DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT = "dom";
172 final static private String DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT = "prot";
173 final static private String DOMAIN_COUNT_SORT_COMBINATIONS_COUNT = "comb";
174 final static private String CUTOFF_SCORE_FILE_OPTION = "cos";
175 final static private String NOT_IGNORE_DUFS_OPTION = "dufs";
176 final static private String MAX_E_VALUE_OPTION = "e";
177 final static private String MAX_ALLOWED_OVERLAP_OPTION = "mo";
178 final static private String NO_ENGULFING_OVERLAP_OPTION = "no_eo";
179 final static private String IGNORE_COMBINATION_WITH_SAME_OPTION = "ignore_self_comb";
180 final static private String PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION = "dc_regain_stats";
181 final static private String DA_ANALYSIS_OPTION = "DA_analyis";
182 final static private String USE_LAST_IN_FITCH_OPTION = "last";
183 public final static String PAIRWISE_DOMAIN_COMPARISONS_PREFIX = "pwc_";
184 final static private String PAIRWISE_DOMAIN_COMPARISONS_OPTION = "pwc";
185 final static private String OUTPUT_FILE_OPTION = "o";
186 final static private String PFAM_TO_GO_FILE_USE_OPTION = "p2g";
187 final static private String GO_OBO_FILE_USE_OPTION = "obo";
188 final static private String GO_NAMESPACE_LIMIT_OPTION = "go_namespace";
189 final static private String GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION = "molecular_function";
190 final static private String GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS = "biological_process";
191 final static private String GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT = "cellular_component";
192 final static private String SECONDARY_FEATURES_PARSIMONY_MAP_FILE = "secondary";
193 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED = "simple_tab";
194 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML = "simple_html";
195 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML = "detailed_html";
196 final static private String DOMAIN_SIMILARITY_PRINT_OPTION = "ds_output";
197 private static final PRINT_OPTION DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT = PrintableDomainSimilarity.PRINT_OPTION.HTML;
198 final static private String IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION = "ignore_singlet_domains";
199 final static private String IGNORE_VIRAL_IDS = "ignore_viral_ids";
200 final static private boolean IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT = false;
201 final static private String IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION = "ignore_species_specific_domains";
202 final static private boolean IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT = false;
203 final static private String MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score.pwd";
204 final static private String MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains.pwd";
205 final static private String MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations.pwd";
206 final static private String NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score_NJ"
207 + ForesterConstants.PHYLO_XML_SUFFIX;
208 final static private String NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains_NJ"
209 + ForesterConstants.PHYLO_XML_SUFFIX;
210 final static private String NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations_NJ"
211 + ForesterConstants.PHYLO_XML_SUFFIX;
212 final static private String FILTER_POSITIVE_OPTION = "pos_filter";
213 final static private String FILTER_NEGATIVE_OPTION = "neg_filter";
214 final static private String FILTER_NEGATIVE_DOMAINS_OPTION = "neg_dom_filter";
215 final static private String INPUT_GENOMES_FILE_OPTION = "genomes";
216 final static private String INPUT_SPECIES_TREE_OPTION = "species_tree";
217 final static private String SEQ_EXTRACT_OPTION = "prot_extract";
218 final static private String PRG_VERSION = "2.304";
219 final static private String PRG_DATE = "131024";
220 final static private String E_MAIL = "czmasek@burnham.org";
221 final static private String WWW = "https://sites.google.com/site/cmzmasek/home/software/forester/surfacing";
222 final static private boolean IGNORE_DUFS_DEFAULT = true;
223 final static private boolean IGNORE_COMBINATION_WITH_SAME_DEFAULLT = false;
224 final static private double MAX_E_VALUE_DEFAULT = -1;
225 public final static int MAX_ALLOWED_OVERLAP_DEFAULT = -1;
226 private static final String RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION = "random_seed";
227 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS = "consider_bdc_direction";
228 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY = "consider_bdc_adj";
229 public static final String SEQ_EXTRACT_SUFFIX = ".prot";
230 public static final String PLUS_MINUS_ANALYSIS_OPTION = "plus_minus";
231 public static final String PLUS_MINUS_DOM_SUFFIX = "_plus_minus_dom.txt";
232 public static final String PLUS_MINUS_DOM_SUFFIX_HTML = "_plus_minus_dom.html";
233 public static final String PLUS_MINUS_DC_SUFFIX_HTML = "_plus_minus_dc.html";
234 public static final int PLUS_MINUS_ANALYSIS_MIN_DIFF_DEFAULT = 0;
235 public static final double PLUS_MINUS_ANALYSIS_FACTOR_DEFAULT = 1.0;
236 public static final String PLUS_MINUS_ALL_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_all.txt";
237 public static final String PLUS_MINUS_PASSING_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_passing.txt";
238 private static final String OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS = "all_prot";
239 final static private String OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION = "all_prot_e";
240 public static final boolean VERBOSE = false;
241 private static final String OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_gains_counts";
242 private static final String OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_losses_counts";
243 private static final String DOMAIN_LENGTHS_ANALYSIS_SUFFIX = "_domain_lengths_analysis";
244 private static final boolean PERFORM_DOMAIN_LENGTH_ANALYSIS = true;
245 public static final String ALL_PFAMS_ENCOUNTERED_SUFFIX = "_all_encountered_pfams";
246 public static final String ALL_PFAMS_ENCOUNTERED_WITH_GO_ANNOTATION_SUFFIX = "_all_encountered_pfams_with_go_annotation";
247 public static final String ENCOUNTERED_PFAMS_SUMMARY_SUFFIX = "_encountered_pfams_summary";
248 public static final String ALL_PFAMS_GAINED_AS_DOMAINS_SUFFIX = "_all_pfams_gained_as_domains";
249 public static final String ALL_PFAMS_LOST_AS_DOMAINS_SUFFIX = "_all_pfams_lost_as_domains";
250 public static final String ALL_PFAMS_GAINED_AS_DC_SUFFIX = "_all_pfams_gained_as_dc";
251 public static final String ALL_PFAMS_LOST_AS_DC_SUFFIX = "_all_pfams_lost_as_dc";
252 public static final String BASE_DIRECTORY_PER_NODE_DOMAIN_GAIN_LOSS_FILES = "PER_NODE_EVENTS";
253 public static final String BASE_DIRECTORY_PER_SUBTREE_DOMAIN_GAIN_LOSS_FILES = "PER_SUBTREE_EVENTS";
254 public static final String D_PROMISCUITY_FILE_SUFFIX = "_domain_promiscuities";
255 private static final String LOG_FILE_SUFFIX = "_log.txt";
256 private static final String DATA_FILE_SUFFIX = "_domain_combination_data.txt";
257 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";
258 private static final String WRITE_TO_NEXUS_OPTION = "nexus";
259 private static final INDIVIDUAL_SCORE_CUTOFF INDIVIDUAL_SCORE_CUTOFF_DEFAULT = INDIVIDUAL_SCORE_CUTOFF.FULL_SEQUENCE; //TODO look at me! change?
260 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_COUNTS_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_counts.txt";
261 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_lists.txt";
262 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_FOR_GO_MAPPING_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_lists_for_go_mapping.txt";
263 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_FOR_GO_MAPPING_OUTPUT_UNIQUE_SUFFIX = "_indep_dc_gains_fitch_lists_for_go_mapping_unique.txt";
264 public static final String LIMIT_SPEC_FOR_PROT_EX = null; // e.g. "HUMAN"; set to null for not using this feature (default).
265 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH_MAPPED = "_dc_MAPPED_secondary_features_fitch"
266 + ForesterConstants.PHYLO_XML_SUFFIX;
267 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_COUNTS_MAPPED_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_counts_MAPPED.txt";
268 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_MAPPED_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_lists_MAPPED.txt";
269 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_FOR_GO_MAPPING_MAPPED_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_lists_for_go_mapping_MAPPED.txt";
270 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_FOR_GO_MAPPING_MAPPED_OUTPUT_UNIQUE_SUFFIX = "_indep_dc_gains_fitch_lists_for_go_mapping_unique_MAPPED.txt";
271 private static final boolean CALC_SIMILARITY_SCORES = false;
273 public static void main( final String args[] ) {
274 final long start_time = new Date().getTime();
275 // final StringBuffer log = new StringBuffer();
276 final StringBuilder html_desc = new StringBuilder();
277 ForesterUtil.printProgramInformation( surfacing.PRG_NAME,
278 surfacing.PRG_VERSION,
282 final String nl = ForesterUtil.LINE_SEPARATOR;
283 html_desc.append( "<table>" + nl );
284 html_desc.append( "<tr><td>Produced by:</td><td>" + surfacing.PRG_NAME + "</td></tr>" + nl );
285 html_desc.append( "<tr><td>Version:</td><td>" + surfacing.PRG_VERSION + "</td></tr>" + nl );
286 html_desc.append( "<tr><td>Release Date:</td><td>" + surfacing.PRG_DATE + "</td></tr>" + nl );
287 html_desc.append( "<tr><td>Contact:</td><td>" + surfacing.E_MAIL + "</td></tr>" + nl );
288 html_desc.append( "<tr><td>WWW:</td><td>" + surfacing.WWW + "</td></tr>" + nl );
289 CommandLineArguments cla = null;
291 cla = new CommandLineArguments( args );
293 catch ( final Exception e ) {
294 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
296 if ( cla.isOptionSet( surfacing.HELP_OPTION_1 ) || cla.isOptionSet( surfacing.HELP_OPTION_2 ) ) {
297 surfacing.printHelp();
300 if ( ( args.length < 1 ) ) {
301 surfacing.printHelp();
304 final List<String> allowed_options = new ArrayList<String>();
305 allowed_options.add( surfacing.NOT_IGNORE_DUFS_OPTION );
306 allowed_options.add( surfacing.MAX_E_VALUE_OPTION );
307 allowed_options.add( surfacing.DETAILEDNESS_OPTION );
308 allowed_options.add( surfacing.OUTPUT_FILE_OPTION );
309 allowed_options.add( surfacing.DOMAIN_SIMILARITY_SORT_OPTION );
310 allowed_options.add( surfacing.SPECIES_MATRIX_OPTION );
311 allowed_options.add( surfacing.SCORING_OPTION );
312 allowed_options.add( surfacing.MAX_ALLOWED_OVERLAP_OPTION );
313 allowed_options.add( surfacing.NO_ENGULFING_OVERLAP_OPTION );
314 allowed_options.add( surfacing.DOMAIN_COUNT_SORT_OPTION );
315 allowed_options.add( surfacing.CUTOFF_SCORE_FILE_OPTION );
316 allowed_options.add( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION );
317 allowed_options.add( surfacing.OUTPUT_DIR_OPTION );
318 allowed_options.add( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION );
319 allowed_options.add( surfacing.PFAM_TO_GO_FILE_USE_OPTION );
320 allowed_options.add( surfacing.GO_OBO_FILE_USE_OPTION );
321 allowed_options.add( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION );
322 allowed_options.add( surfacing.GO_NAMESPACE_LIMIT_OPTION );
323 allowed_options.add( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
324 allowed_options.add( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION );
325 allowed_options.add( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS );
326 allowed_options.add( INPUT_SPECIES_TREE_OPTION );
327 allowed_options.add( FILTER_POSITIVE_OPTION );
328 allowed_options.add( FILTER_NEGATIVE_OPTION );
329 allowed_options.add( INPUT_GENOMES_FILE_OPTION );
330 allowed_options.add( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
331 allowed_options.add( FILTER_NEGATIVE_DOMAINS_OPTION );
332 allowed_options.add( IGNORE_VIRAL_IDS );
333 allowed_options.add( SEQ_EXTRACT_OPTION );
334 allowed_options.add( OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION );
335 allowed_options.add( SECONDARY_FEATURES_PARSIMONY_MAP_FILE );
336 allowed_options.add( PLUS_MINUS_ANALYSIS_OPTION );
337 allowed_options.add( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS );
338 allowed_options.add( OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS );
339 allowed_options.add( CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY );
340 allowed_options.add( WRITE_TO_NEXUS_OPTION );
341 allowed_options.add( PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION );
342 allowed_options.add( DA_ANALYSIS_OPTION );
343 allowed_options.add( USE_LAST_IN_FITCH_OPTION );
344 boolean ignore_dufs = surfacing.IGNORE_DUFS_DEFAULT;
345 boolean ignore_combination_with_same = surfacing.IGNORE_COMBINATION_WITH_SAME_DEFAULLT;
346 double e_value_max = surfacing.MAX_E_VALUE_DEFAULT;
347 int max_allowed_overlap = surfacing.MAX_ALLOWED_OVERLAP_DEFAULT;
348 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
349 if ( dissallowed_options.length() > 0 ) {
350 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown option(s): " + dissallowed_options );
352 boolean use_last_in_fitch_parsimony = false;
353 if ( cla.isOptionSet( USE_LAST_IN_FITCH_OPTION ) ) {
354 use_last_in_fitch_parsimony = true;
356 boolean write_to_nexus = false;
357 if ( cla.isOptionSet( WRITE_TO_NEXUS_OPTION ) ) {
358 write_to_nexus = true;
360 boolean perform_dc_regain_proteins_stats = false;
361 if ( cla.isOptionSet( PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION ) ) {
362 perform_dc_regain_proteins_stats = true;
364 boolean da_analysis = false;
365 if ( cla.isOptionSet( DA_ANALYSIS_OPTION ) ) {
368 boolean output_binary_domain_combinationsfor_graph_analysis = false;
369 if ( cla.isOptionSet( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS ) ) {
370 output_binary_domain_combinationsfor_graph_analysis = true;
372 if ( cla.isOptionSet( surfacing.MAX_E_VALUE_OPTION ) ) {
374 e_value_max = cla.getOptionValueAsDouble( surfacing.MAX_E_VALUE_OPTION );
376 catch ( final Exception e ) {
377 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for E-value maximum" );
380 if ( cla.isOptionSet( surfacing.MAX_ALLOWED_OVERLAP_OPTION ) ) {
382 max_allowed_overlap = cla.getOptionValueAsInt( surfacing.MAX_ALLOWED_OVERLAP_OPTION );
384 catch ( final Exception e ) {
385 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for maximal allowed domain overlap" );
388 boolean no_engulfing_overlaps = false;
389 if ( cla.isOptionSet( surfacing.NO_ENGULFING_OVERLAP_OPTION ) ) {
390 no_engulfing_overlaps = true;
392 boolean ignore_virus_like_ids = false;
393 if ( cla.isOptionSet( surfacing.IGNORE_VIRAL_IDS ) ) {
394 ignore_virus_like_ids = true;
396 if ( cla.isOptionSet( surfacing.NOT_IGNORE_DUFS_OPTION ) ) {
399 if ( cla.isOptionSet( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION ) ) {
400 ignore_combination_with_same = true;
402 boolean ignore_domains_without_combs_in_all_spec = IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT;
403 if ( cla.isOptionSet( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION ) ) {
404 ignore_domains_without_combs_in_all_spec = true;
406 boolean ignore_species_specific_domains = IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT;
407 if ( cla.isOptionSet( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION ) ) {
408 ignore_species_specific_domains = true;
410 if ( !cla.isOptionValueSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
411 ForesterUtil.fatalError( surfacing.PRG_NAME, "no input species tree file given: "
412 + surfacing.INPUT_SPECIES_TREE_OPTION + "=<file>" );
414 File output_file = null;
415 if ( cla.isOptionSet( surfacing.OUTPUT_FILE_OPTION ) ) {
416 if ( !cla.isOptionValueSet( surfacing.OUTPUT_FILE_OPTION ) ) {
417 ForesterUtil.fatalError( surfacing.PRG_NAME,
418 "no value for domain combinations similarities output file: -"
419 + surfacing.OUTPUT_FILE_OPTION + "=<file>" );
421 output_file = new File( cla.getOptionValue( surfacing.OUTPUT_FILE_OPTION ) );
422 SurfacingUtil.checkForOutputFileWriteability( output_file );
424 File cutoff_scores_file = null;
425 Map<String, Double> individual_score_cutoffs = null;
426 if ( cla.isOptionSet( surfacing.CUTOFF_SCORE_FILE_OPTION ) ) {
427 if ( !cla.isOptionValueSet( surfacing.CUTOFF_SCORE_FILE_OPTION ) ) {
428 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for individual domain score cutoffs file: -"
429 + surfacing.CUTOFF_SCORE_FILE_OPTION + "=<file>" );
431 cutoff_scores_file = new File( cla.getOptionValue( surfacing.CUTOFF_SCORE_FILE_OPTION ) );
432 final String error = ForesterUtil.isReadableFile( cutoff_scores_file );
433 if ( !ForesterUtil.isEmpty( error ) ) {
434 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read individual domain score cutoffs file: "
438 final BasicTable<String> scores_table = BasicTableParser.parse( cutoff_scores_file, ' ' );
439 individual_score_cutoffs = scores_table.getColumnsAsMapDouble( 0, 1 );
441 catch ( final IOException e ) {
442 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from individual score cutoffs file: " + e );
445 BinaryDomainCombination.DomainCombinationType dc_type = BinaryDomainCombination.DomainCombinationType.BASIC;
446 if ( cla.isOptionSet( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS ) ) {
447 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED;
449 if ( cla.isOptionSet( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY ) ) {
450 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT;
453 if ( cla.isOptionSet( surfacing.OUTPUT_DIR_OPTION ) ) {
454 if ( !cla.isOptionValueSet( surfacing.OUTPUT_DIR_OPTION ) ) {
455 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for output directory: -"
456 + surfacing.OUTPUT_DIR_OPTION + "=<dir>" );
458 out_dir = new File( cla.getOptionValue( surfacing.OUTPUT_DIR_OPTION ) );
459 if ( out_dir.exists() && ( out_dir.listFiles().length > 0 ) ) {
460 ForesterUtil.fatalError( surfacing.PRG_NAME, "\"" + out_dir + "\" aready exists and is not empty" );
462 if ( !out_dir.exists() ) {
463 final boolean success = out_dir.mkdir();
464 if ( !success || !out_dir.exists() ) {
465 ForesterUtil.fatalError( surfacing.PRG_NAME, "failed to create \"" + out_dir + "\"" );
468 if ( !out_dir.canWrite() ) {
469 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot write to \"" + out_dir + "\"" );
472 File positive_filter_file = null;
473 File negative_filter_file = null;
474 File negative_domains_filter_file = null;
475 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) && cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
476 ForesterUtil.fatalError( surfacing.PRG_NAME, "attempt to use both negative and positive protein filter" );
478 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION )
479 && ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) || cla
480 .isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) ) {
482 .fatalError( surfacing.PRG_NAME,
483 "attempt to use both negative or positive protein filter together wirh a negative domains filter" );
485 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) ) {
486 if ( !cla.isOptionValueSet( surfacing.FILTER_NEGATIVE_OPTION ) ) {
487 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for negative filter: -"
488 + surfacing.FILTER_NEGATIVE_OPTION + "=<file>" );
490 negative_filter_file = new File( cla.getOptionValue( surfacing.FILTER_NEGATIVE_OPTION ) );
491 final String msg = ForesterUtil.isReadableFile( negative_filter_file );
492 if ( !ForesterUtil.isEmpty( msg ) ) {
493 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + negative_filter_file + "\": "
497 else if ( cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
498 if ( !cla.isOptionValueSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
499 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for positive filter: -"
500 + surfacing.FILTER_POSITIVE_OPTION + "=<file>" );
502 positive_filter_file = new File( cla.getOptionValue( surfacing.FILTER_POSITIVE_OPTION ) );
503 final String msg = ForesterUtil.isReadableFile( positive_filter_file );
504 if ( !ForesterUtil.isEmpty( msg ) ) {
505 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + positive_filter_file + "\": "
509 else if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
510 if ( !cla.isOptionValueSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
511 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for negative domains filter: -"
512 + surfacing.FILTER_NEGATIVE_DOMAINS_OPTION + "=<file>" );
514 negative_domains_filter_file = new File( cla.getOptionValue( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) );
515 final String msg = ForesterUtil.isReadableFile( negative_domains_filter_file );
516 if ( !ForesterUtil.isEmpty( msg ) ) {
517 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + negative_domains_filter_file
521 final List<String> plus_minus_analysis_high_copy_base_species = new ArrayList<String>();
522 final List<String> plus_minus_analysis_high_copy_target_species = new ArrayList<String>();
523 final List<String> plus_minus_analysis_high_low_copy_species = new ArrayList<String>();
524 final List<Object> plus_minus_analysis_numbers = new ArrayList<Object>();
525 SurfacingUtil.processPlusMinusAnalysisOption( cla,
526 plus_minus_analysis_high_copy_base_species,
527 plus_minus_analysis_high_copy_target_species,
528 plus_minus_analysis_high_low_copy_species,
529 plus_minus_analysis_numbers );
530 File input_genomes_file = null;
531 if ( cla.isOptionSet( surfacing.INPUT_GENOMES_FILE_OPTION ) ) {
532 if ( !cla.isOptionValueSet( surfacing.INPUT_GENOMES_FILE_OPTION ) ) {
533 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for input genomes file: -"
534 + surfacing.INPUT_GENOMES_FILE_OPTION + "=<file>" );
536 input_genomes_file = new File( cla.getOptionValue( surfacing.INPUT_GENOMES_FILE_OPTION ) );
537 final String msg = ForesterUtil.isReadableFile( input_genomes_file );
538 if ( !ForesterUtil.isEmpty( msg ) ) {
540 .fatalError( surfacing.PRG_NAME, "can not read from \"" + input_genomes_file + "\": " + msg );
544 ForesterUtil.fatalError( surfacing.PRG_NAME, "no input genomes file given: "
545 + surfacing.INPUT_GENOMES_FILE_OPTION + "=<file>" );
547 DomainSimilarity.DomainSimilarityScoring scoring = SCORING_DEFAULT;
548 if ( cla.isOptionSet( surfacing.SCORING_OPTION ) ) {
549 if ( !cla.isOptionValueSet( surfacing.SCORING_OPTION ) ) {
550 ForesterUtil.fatalError( surfacing.PRG_NAME,
551 "no value for scoring method for domain combinations similarity calculation: -"
552 + surfacing.SCORING_OPTION + "=<"
553 + surfacing.SCORING_DOMAIN_COUNT_BASED + "|"
554 + surfacing.SCORING_PROTEIN_COUNT_BASED + "|"
555 + surfacing.SCORING_COMBINATION_BASED + ">\"" );
557 final String scoring_str = cla.getOptionValue( surfacing.SCORING_OPTION );
558 if ( scoring_str.equals( surfacing.SCORING_DOMAIN_COUNT_BASED ) ) {
559 scoring = DomainSimilarity.DomainSimilarityScoring.DOMAINS;
561 else if ( scoring_str.equals( surfacing.SCORING_COMBINATION_BASED ) ) {
562 scoring = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
564 else if ( scoring_str.equals( surfacing.SCORING_PROTEIN_COUNT_BASED ) ) {
565 scoring = DomainSimilarity.DomainSimilarityScoring.PROTEINS;
568 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + scoring_str
569 + "\" for scoring method for domain combinations similarity calculation: \"-"
570 + surfacing.SCORING_OPTION + "=<" + surfacing.SCORING_DOMAIN_COUNT_BASED + "|"
571 + surfacing.SCORING_PROTEIN_COUNT_BASED + "|" + surfacing.SCORING_COMBINATION_BASED + ">\"" );
574 boolean sort_by_species_count_first = false;
575 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION ) ) {
576 sort_by_species_count_first = true;
578 boolean species_matrix = false;
579 if ( cla.isOptionSet( surfacing.SPECIES_MATRIX_OPTION ) ) {
580 species_matrix = true;
582 boolean output_protein_lists_for_all_domains = false;
583 double output_list_of_all_proteins_per_domain_e_value_max = -1;
584 if ( cla.isOptionSet( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS ) ) {
585 output_protein_lists_for_all_domains = true;
586 if ( cla.isOptionSet( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION ) ) {
588 output_list_of_all_proteins_per_domain_e_value_max = cla
589 .getOptionValueAsDouble( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION );
591 catch ( final Exception e ) {
592 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for per domain E-value maximum" );
596 Detailedness detailedness = DETAILEDNESS_DEFAULT;
597 if ( cla.isOptionSet( surfacing.DETAILEDNESS_OPTION ) ) {
598 if ( !cla.isOptionValueSet( surfacing.DETAILEDNESS_OPTION ) ) {
599 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for -" + surfacing.DETAILEDNESS_OPTION + "=<"
600 + surfacing.DETAILEDNESS_BASIC + "|" + surfacing.DETAILEDNESS_LIST_IDS + "|"
601 + surfacing.DETAILEDNESS_PUNCTILIOUS + ">\"" );
603 final String detness = cla.getOptionValue( surfacing.DETAILEDNESS_OPTION ).toLowerCase();
604 if ( detness.equals( surfacing.DETAILEDNESS_BASIC ) ) {
605 detailedness = DomainSimilarityCalculator.Detailedness.BASIC;
607 else if ( detness.equals( surfacing.DETAILEDNESS_LIST_IDS ) ) {
608 detailedness = DomainSimilarityCalculator.Detailedness.LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES;
610 else if ( detness.equals( surfacing.DETAILEDNESS_PUNCTILIOUS ) ) {
611 detailedness = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
614 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + detness + "\" for detailedness: \"-"
615 + surfacing.DETAILEDNESS_OPTION + "=<" + surfacing.DETAILEDNESS_BASIC + "|"
616 + surfacing.DETAILEDNESS_LIST_IDS + "|" + surfacing.DETAILEDNESS_PUNCTILIOUS + ">\"" );
619 String automated_pairwise_comparison_suffix = null;
620 boolean perform_pwc = false;
621 boolean write_pwc_files = false;
622 if ( cla.isOptionSet( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
624 if ( !cla.isOptionValueSet( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
625 write_pwc_files = false;
628 write_pwc_files = true;
629 automated_pairwise_comparison_suffix = "_"
630 + cla.getOptionValue( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
633 String query_domain_ids = null;
634 if ( cla.isOptionSet( surfacing.SEQ_EXTRACT_OPTION ) ) {
635 if ( !cla.isOptionValueSet( surfacing.SEQ_EXTRACT_OPTION ) ) {
637 .fatalError( surfacing.PRG_NAME,
638 "no domain ids given for sequences with given domains to be extracted : -"
639 + surfacing.SEQ_EXTRACT_OPTION
640 + "=<ordered domain sequences, domain ids separated by '~', sequences separated by '#'>" );
642 query_domain_ids = cla.getOptionValue( surfacing.SEQ_EXTRACT_OPTION );
644 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field = DOMAIN_SORT_FILD_DEFAULT;
645 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field_for_automated_pwc = DOMAIN_SORT_FILD_DEFAULT;
646 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
647 if ( !cla.isOptionValueSet( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
648 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for domain combinations similarities sorting: -"
649 + surfacing.DOMAIN_SIMILARITY_SORT_OPTION + "=<" + surfacing.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
650 + surfacing.DOMAIN_SIMILARITY_SORT_MAX + "|" + surfacing.DOMAIN_SIMILARITY_SORT_MIN + "|"
651 + surfacing.DOMAIN_SIMILARITY_SORT_MEAN + "|" + surfacing.DOMAIN_SIMILARITY_SORT_DIFF + "|"
652 + surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
653 + surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|"
654 + surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|" + surfacing.DOMAIN_SIMILARITY_SORT_SD
657 final String sort_str = cla.getOptionValue( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ).toLowerCase();
658 if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_ALPHA ) ) {
659 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
660 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
662 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MAX ) ) {
663 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX;
664 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
666 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MIN ) ) {
667 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MIN;
668 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
670 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MEAN ) ) {
671 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MEAN;
672 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MEAN;
674 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT ) ) {
675 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SPECIES_COUNT;
676 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
678 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_SD ) ) {
679 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SD;
680 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
682 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_DIFF ) ) {
683 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
684 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
686 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF ) ) {
687 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
688 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
690 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF ) ) {
691 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
692 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
695 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort_str
696 + "\" for domain combinations similarities sorting: \"-"
697 + surfacing.DOMAIN_SIMILARITY_SORT_OPTION + "=<" + surfacing.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
698 + surfacing.DOMAIN_SIMILARITY_SORT_MAX + "|" + surfacing.DOMAIN_SIMILARITY_SORT_MIN + "|"
699 + surfacing.DOMAIN_SIMILARITY_SORT_MEAN + "|" + surfacing.DOMAIN_SIMILARITY_SORT_DIFF + "|"
700 + surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
701 + surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|" + "|"
702 + surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|" + surfacing.DOMAIN_SIMILARITY_SORT_SD
706 PrintableDomainSimilarity.PRINT_OPTION domain_similarity_print_option = DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT;
707 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
708 if ( !cla.isOptionValueSet( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
709 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for print option: -"
710 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
711 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
712 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
714 final String sort = cla.getOptionValue( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ).toLowerCase();
715 if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML ) ) {
716 domain_similarity_print_option = PrintableDomainSimilarity.PRINT_OPTION.HTML;
718 else if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML ) ) {
719 ForesterUtil.fatalError( surfacing.PRG_NAME, "simple HTML output not implemented yet :(" );
721 else if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED ) ) {
722 domain_similarity_print_option = PrintableDomainSimilarity.PRINT_OPTION.SIMPLE_TAB_DELIMITED;
725 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort + "\" for print option: -"
726 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
727 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
728 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
731 GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder dc_sort_order = DOMAINS_SORT_ORDER_DEFAULT;
732 if ( cla.isOptionSet( surfacing.DOMAIN_COUNT_SORT_OPTION ) ) {
733 if ( !cla.isOptionValueSet( surfacing.DOMAIN_COUNT_SORT_OPTION ) ) {
734 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for sorting of domain counts: -"
735 + surfacing.DOMAIN_COUNT_SORT_OPTION + "=<" + surfacing.DOMAIN_COUNT_SORT_ALPHA + "|"
736 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
737 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
738 + surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
740 final String sort = cla.getOptionValue( surfacing.DOMAIN_COUNT_SORT_OPTION ).toLowerCase();
741 if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_ALPHA ) ) {
742 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
744 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT ) ) {
745 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_COUNT;
747 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT ) ) {
748 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_PROTEINS_COUNT;
750 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT ) ) {
751 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.COMBINATIONS_COUNT;
754 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort
755 + "\" for sorting of domain counts: \"-" + surfacing.DOMAIN_COUNT_SORT_OPTION + "=<"
756 + surfacing.DOMAIN_COUNT_SORT_ALPHA + "|" + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
757 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
758 + surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
761 final String[][] input_file_properties = SurfacingUtil.processInputGenomesFile( input_genomes_file );
762 final int number_of_genomes = input_file_properties.length;
763 if ( number_of_genomes < 2 ) {
764 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot analyze less than two files" );
766 if ( ( number_of_genomes < 3 ) && perform_pwc ) {
767 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use : -"
768 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
769 + "=<suffix> to turn on pairwise analyses with less than three input files" );
771 SurfacingUtil.checkWriteabilityForPairwiseComparisons( domain_similarity_print_option,
772 input_file_properties,
773 automated_pairwise_comparison_suffix,
775 for( int i = 0; i < number_of_genomes; i++ ) {
776 File dcc_outfile = new File( input_file_properties[ i ][ 1 ]
777 + surfacing.DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX );
778 if ( out_dir != null ) {
779 dcc_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + dcc_outfile );
781 SurfacingUtil.checkForOutputFileWriteability( dcc_outfile );
783 File pfam_to_go_file = null;
784 Map<String, List<GoId>> domain_id_to_go_ids_map = null;
785 int domain_id_to_go_ids_count = 0;
786 if ( cla.isOptionSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
787 if ( !cla.isOptionValueSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
788 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for Pfam to GO mapping file: -"
789 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>" );
791 pfam_to_go_file = new File( cla.getOptionValue( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) );
792 final String error = ForesterUtil.isReadableFile( pfam_to_go_file );
793 if ( !ForesterUtil.isEmpty( error ) ) {
794 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read Pfam to GO mapping file: " + error );
797 final PfamToGoParser parser = new PfamToGoParser( pfam_to_go_file );
798 final List<PfamToGoMapping> pfam_to_go_mappings = parser.parse();
799 domain_id_to_go_ids_map = SurfacingUtil.createDomainIdToGoIdMap( pfam_to_go_mappings );
800 if ( parser.getMappingCount() < domain_id_to_go_ids_map.size() ) {
801 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME,
802 "parser.getMappingCount() < domain_id_to_go_ids_map.size()" );
804 domain_id_to_go_ids_count = parser.getMappingCount();
806 catch ( final IOException e ) {
807 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from Pfam to GO mapping file: " + e );
810 File go_obo_file = null;
811 List<GoTerm> go_terms = null;
812 if ( cla.isOptionSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
813 if ( !cla.isOptionValueSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
814 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for GO OBO file: -"
815 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>" );
817 if ( ( domain_id_to_go_ids_map == null ) || ( domain_id_to_go_ids_map.size() < 1 ) ) {
818 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use GO OBO file (-"
819 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>) without Pfam to GO mapping file ("
820 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
822 go_obo_file = new File( cla.getOptionValue( surfacing.GO_OBO_FILE_USE_OPTION ) );
823 final String error = ForesterUtil.isReadableFile( go_obo_file );
824 if ( !ForesterUtil.isEmpty( error ) ) {
825 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read GO OBO file: " + error );
828 final OBOparser parser = new OBOparser( go_obo_file, OBOparser.ReturnType.BASIC_GO_TERM );
829 go_terms = parser.parse();
830 if ( parser.getGoTermCount() != go_terms.size() ) {
832 .unexpectedFatalError( surfacing.PRG_NAME, "parser.getGoTermCount() != go_terms.size()" );
835 catch ( final IOException e ) {
836 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from GO OBO file: " + e );
839 Map<GoId, GoTerm> go_id_to_term_map = null;
840 if ( ( ( domain_id_to_go_ids_map != null ) && ( domain_id_to_go_ids_map.size() > 0 ) )
841 && ( ( go_terms != null ) && ( go_terms.size() > 0 ) ) ) {
842 go_id_to_term_map = GoUtils.createGoIdToGoTermMap( go_terms );
844 GoNameSpace go_namespace_limit = null;
845 if ( cla.isOptionSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
846 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
847 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use GO namespace limit (-"
848 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<namespace>) without Pfam to GO mapping file ("
849 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>) and GO OBO file (-"
850 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
852 if ( !cla.isOptionValueSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
853 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for GO namespace limit: \"-"
854 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
855 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
856 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
857 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
859 final String go_namespace_limit_str = cla.getOptionValue( surfacing.GO_NAMESPACE_LIMIT_OPTION )
861 if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION ) ) {
862 go_namespace_limit = GoNameSpace.createMolecularFunction();
864 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS ) ) {
865 go_namespace_limit = GoNameSpace.createBiologicalProcess();
867 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT ) ) {
868 go_namespace_limit = GoNameSpace.createCellularComponent();
871 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + go_namespace_limit_str
872 + "\" for GO namespace limit: \"-" + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
873 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
874 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
875 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
878 if ( ( domain_similarity_sort_field == DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE )
879 && ( number_of_genomes > 2 ) ) {
880 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
882 File[] intree_files = null;
883 Phylogeny[] intrees = null;
884 if ( cla.isOptionSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
885 if ( number_of_genomes < 3 ) {
886 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot infer gains and losses on input species trees (-"
887 + surfacing.INPUT_SPECIES_TREE_OPTION + " without pairwise analyses ("
888 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
889 + "=<suffix for pairwise comparison output files>)" );
891 if ( !cla.isOptionValueSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
892 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for input tree: -"
893 + surfacing.INPUT_SPECIES_TREE_OPTION + "=<tree file in phyloXML format>" );
895 final String intrees_str = cla.getOptionValue( surfacing.INPUT_SPECIES_TREE_OPTION );
896 if ( intrees_str.indexOf( "#" ) > 0 ) {
897 final String[] intrees_strs = intrees_str.split( "#" );
898 intree_files = new File[ intrees_strs.length ];
900 for( final String s : intrees_strs ) {
901 intree_files[ i++ ] = new File( s.trim() );
905 intree_files = new File[ 1 ];
906 intree_files[ 0 ] = new File( intrees_str );
908 intrees = SurfacingUtil.obtainAndPreProcessIntrees( intree_files, number_of_genomes, input_file_properties );
910 final Phylogeny intree_0_orig = SurfacingUtil.obtainFirstIntree( intree_files[ 0 ] );
911 long random_number_seed_for_fitch_parsimony = 0l;
912 boolean radomize_fitch_parsimony = false;
913 if ( cla.isOptionSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
914 if ( !cla.isOptionValueSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
915 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for random number seed: -"
916 + surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION + "=<seed>" );
919 random_number_seed_for_fitch_parsimony = cla
920 .getOptionValueAsLong( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
922 catch ( final IOException e ) {
923 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
925 radomize_fitch_parsimony = true;
927 SortedSet<String> filter = null;
928 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
929 || ( negative_domains_filter_file != null ) ) {
930 filter = new TreeSet<String>();
931 if ( positive_filter_file != null ) {
932 SurfacingUtil.processFilter( positive_filter_file, filter );
934 else if ( negative_filter_file != null ) {
935 SurfacingUtil.processFilter( negative_filter_file, filter );
937 else if ( negative_domains_filter_file != null ) {
938 SurfacingUtil.processFilter( negative_domains_filter_file, filter );
941 Map<String, Set<String>>[] domain_id_to_secondary_features_maps = null;
942 File[] secondary_features_map_files = null;
943 final File domain_lengths_analysis_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
944 + DOMAIN_LENGTHS_ANALYSIS_SUFFIX );
945 if ( PERFORM_DOMAIN_LENGTH_ANALYSIS ) {
946 SurfacingUtil.checkForOutputFileWriteability( domain_lengths_analysis_outfile );
948 if ( cla.isOptionSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
949 if ( !cla.isOptionValueSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
950 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for secondary features map file: -"
951 + surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE + "=<file>" );
953 final String[] secondary_features_map_files_strs = cla
954 .getOptionValue( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ).split( "#" );
955 secondary_features_map_files = new File[ secondary_features_map_files_strs.length ];
956 domain_id_to_secondary_features_maps = new Map[ secondary_features_map_files_strs.length ];
958 for( final String secondary_features_map_files_str : secondary_features_map_files_strs ) {
959 secondary_features_map_files[ i ] = new File( secondary_features_map_files_str );
960 final String error = ForesterUtil.isReadableFile( secondary_features_map_files[ i ] );
961 if ( !ForesterUtil.isEmpty( error ) ) {
962 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read secondary features map file: " + error );
965 domain_id_to_secondary_features_maps[ i ] = SurfacingUtil
966 .createDomainIdToSecondaryFeaturesMap( secondary_features_map_files[ i ] );
968 catch ( final IOException e ) {
969 ForesterUtil.fatalError( surfacing.PRG_NAME,
970 "cannot read secondary features map file: " + e.getMessage() );
972 catch ( final Exception e ) {
973 ForesterUtil.fatalError( surfacing.PRG_NAME, "problem with contents of features map file ["
974 + secondary_features_map_files[ i ] + "]: " + e.getMessage() );
979 if ( out_dir == null ) {
980 ForesterUtil.fatalError( surfacing.PRG_NAME, "no output directory indicated (-"
981 + surfacing.OUTPUT_DIR_OPTION + "=<dir>)" );
983 if ( output_file == null ) {
984 ForesterUtil.fatalError( surfacing.PRG_NAME, "no name for (main) output file indicated (-"
985 + surfacing.OUTPUT_FILE_OPTION + "=<file>)" );
987 if ( ( domain_id_to_go_ids_map == null ) || domain_id_to_go_ids_map.isEmpty() ) {
988 ForesterUtil.fatalError( surfacing.PRG_NAME,
989 "no (acceptable) Pfam to GO id mapping file provided ('pfam2go file') (-"
990 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
992 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
993 ForesterUtil.fatalError( surfacing.PRG_NAME,
994 "no (acceptable) go id to term mapping file provided ('GO OBO file') (-"
995 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
997 System.out.println( "Output directory : " + out_dir );
998 System.out.println( "Input genomes from : " + input_genomes_file );
999 html_desc.append( "<tr><td>Input genomes from:</td><td>" + input_genomes_file + "</td></tr>" + nl );
1000 if ( positive_filter_file != null ) {
1001 final int filter_size = filter.size();
1002 System.out.println( "Positive protein filter : " + positive_filter_file + " [" + filter_size
1004 html_desc.append( "<tr><td>Positive protein filter:</td><td>" + positive_filter_file + " [" + filter_size
1005 + " domain ids]</td></tr>" + nl );
1007 if ( negative_filter_file != null ) {
1008 final int filter_size = filter.size();
1009 System.out.println( "Negative protein filter : " + negative_filter_file + " [" + filter_size
1011 html_desc.append( "<tr><td>Negative protein filter:</td><td>" + negative_filter_file + " [" + filter_size
1012 + " domain ids]</td></tr>" + nl );
1014 if ( negative_domains_filter_file != null ) {
1015 final int filter_size = filter.size();
1016 System.out.println( "Negative domain filter : " + negative_domains_filter_file + " [" + filter_size
1018 html_desc.append( "<tr><td>Negative domain filter:</td><td>" + negative_domains_filter_file + " ["
1019 + filter_size + " domain ids]</td></tr>" + nl );
1021 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
1023 for( final String s : plus_minus_analysis_high_copy_base_species ) {
1024 plus0 += "+" + s + " ";
1027 for( final String s : plus_minus_analysis_high_copy_target_species ) {
1028 plus1 += "*" + s + " ";
1031 for( final String s : plus_minus_analysis_high_low_copy_species ) {
1032 minus += "-" + s + " ";
1034 System.out.println( "Plus-minus analysis : " + plus1 + "&& " + plus0 + "&& " + minus );
1035 html_desc.append( "<tr><td>Plus-minus analysis:</td><td>" + plus1 + "&& " + plus0 + "&& " + minus
1036 + "</td></tr>" + nl );
1038 if ( cutoff_scores_file != null ) {
1039 System.out.println( "Cutoff scores file : " + cutoff_scores_file );
1040 html_desc.append( "<tr><td>Cutoff scores file:</td><td>" + cutoff_scores_file + "</td></tr>" + nl );
1042 if ( e_value_max >= 0.0 ) {
1043 System.out.println( "E-value maximum (inclusive) : " + e_value_max );
1044 html_desc.append( "<tr><td>E-value maximum (inclusive):</td><td>" + e_value_max + "</td></tr>" + nl );
1046 if ( output_protein_lists_for_all_domains ) {
1047 System.out.println( "Domain E-value max : " + output_list_of_all_proteins_per_domain_e_value_max );
1048 html_desc.append( "<tr><td>Protein lists: E-value maximum per domain (inclusive):</td><td>"
1049 + output_list_of_all_proteins_per_domain_e_value_max + "</td></tr>" + nl );
1051 System.out.println( "Ignore DUFs : " + ignore_dufs );
1052 if ( ignore_virus_like_ids ) {
1053 System.out.println( "Ignore virus like ids : " + ignore_virus_like_ids );
1054 html_desc.append( "<tr><td>Ignore virus, phage, transposition related ids:</td><td>"
1055 + ignore_virus_like_ids + "</td></tr>" + nl );
1057 html_desc.append( "<tr><td>Ignore DUFs:</td><td>" + ignore_dufs + "</td></tr>" + nl );
1058 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1059 System.out.println( "Max allowed domain overlap : " + max_allowed_overlap );
1060 html_desc.append( "<tr><td>Max allowed domain overlap:</td><td>" + max_allowed_overlap + "</td></tr>" + nl );
1062 if ( no_engulfing_overlaps ) {
1063 System.out.println( "Ignore engulfed domains : " + no_engulfing_overlaps );
1064 html_desc.append( "<tr><td>Ignore (lower confidence) engulfed domains:</td><td>" + no_engulfing_overlaps
1065 + "</td></tr>" + nl );
1067 System.out.println( "Ignore singlet domains : " + ignore_domains_without_combs_in_all_spec );
1069 .append( "<tr><td>Ignore singlet domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1070 + ignore_domains_without_combs_in_all_spec + "</td></tr>" + nl );
1071 System.out.println( "Ignore species specific doms: " + ignore_species_specific_domains );
1073 .append( "<tr><td>Ignore species specific domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1074 + ignore_species_specific_domains + "</td></tr>" + nl );
1075 System.out.println( "Ignore combination with self: " + ignore_combination_with_same );
1076 html_desc.append( "<tr><td>Ignore combination with self for domain combination similarity analyses:</td><td>"
1077 + ignore_combination_with_same + "</td></tr>" + nl );
1078 System.out.println( "Consider directedness : "
1079 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) );
1080 html_desc.append( "<tr><td>Consider directedness of binary domain combinations:</td><td>"
1081 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) + "</td></tr>" + nl );
1082 if ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) {
1083 System.out.println( "Consider adjacency : "
1084 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) );
1085 html_desc.append( "<tr><td>Consider djacency of binary domain combinations:</td><td>"
1086 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) + "</td></tr>"
1089 System.out.println( "Use last in Fitch parimony : " + use_last_in_fitch_parsimony );
1090 html_desc.append( "<tr><td>Use last in Fitch parimon:</td><td>" + use_last_in_fitch_parsimony + "</td></tr>"
1092 System.out.println( "Write to Nexus files : " + write_to_nexus );
1093 html_desc.append( "<tr><td>Write to Nexus files:</td><td>" + write_to_nexus + "</td></tr>" + nl );
1094 System.out.println( "DC regain prot stats : " + perform_dc_regain_proteins_stats );
1095 html_desc.append( "<tr><td>DC regain prot stats:</td><td>" + perform_dc_regain_proteins_stats + "</td></tr>"
1097 System.out.println( "DA analysis : " + da_analysis );
1098 html_desc.append( "<tr><td>DA analysis :</td><td>" + da_analysis + "</td></tr>" + nl );
1099 System.out.print( "Domain counts sort order : " );
1100 html_desc.append( "<tr><td>Domain counts sort order:</td><td>" );
1101 switch ( dc_sort_order ) {
1102 case ALPHABETICAL_KEY_ID:
1103 System.out.println( "alphabetical" );
1104 html_desc.append( "alphabetical" + "</td></tr>" + nl );
1106 case KEY_DOMAIN_COUNT:
1107 System.out.println( "domain count" );
1108 html_desc.append( "domain count" + "</td></tr>" + nl );
1110 case KEY_DOMAIN_PROTEINS_COUNT:
1111 System.out.println( "domain proteins count" );
1112 html_desc.append( "domain proteins count" + "</td></tr>" + nl );
1114 case COMBINATIONS_COUNT:
1115 System.out.println( "domain combinations count" );
1116 html_desc.append( "domain combinations count" + "</td></tr>" + nl );
1119 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for dc sort order" );
1121 if ( domain_id_to_go_ids_map != null ) {
1122 System.out.println( "Pfam to GO mappings from : " + pfam_to_go_file + " [" + domain_id_to_go_ids_count
1124 html_desc.append( "<tr><td>Pfam to GO mappings from:</td><td>" + pfam_to_go_file + " ["
1125 + domain_id_to_go_ids_count + " mappings]" + "</td></tr>" + nl );
1127 if ( go_terms != null ) {
1128 System.out.println( "GO terms from : " + go_obo_file + " [" + go_terms.size() + " terms]" );
1129 html_desc.append( "<tr><td>GO terms from:</td><td>" + go_obo_file + " [" + go_terms.size() + " terms]"
1130 + "</td></tr>" + nl );
1132 if ( go_namespace_limit != null ) {
1133 System.out.println( "Limit GO terms to : " + go_namespace_limit.toString() );
1134 html_desc.append( "<tr><td>Limit GO terms to</td><td>" + go_namespace_limit + "</td></tr>" + nl );
1136 if ( perform_pwc ) {
1137 System.out.println( "Suffix for PWC files : " + automated_pairwise_comparison_suffix );
1138 html_desc.append( "<tr><td>Suffix for PWC files</td><td>" + automated_pairwise_comparison_suffix
1139 + "</td></tr>" + nl );
1141 if ( out_dir != null ) {
1142 System.out.println( "Output directory : " + out_dir );
1144 if ( query_domain_ids != null ) {
1145 System.out.println( "Query domains (ordered) : " + query_domain_ids );
1146 html_desc.append( "<tr><td></td><td>" + query_domain_ids + "</td></tr>" + nl );
1148 System.out.println( "Write similarities to : " + output_file );
1149 System.out.print( " Scoring method : " );
1150 html_desc.append( "<tr><td>Scoring method:</td><td>" );
1151 switch ( scoring ) {
1153 System.out.println( "domain combinations based" );
1154 html_desc.append( "domain combinations based" + "</td></tr>" + nl );
1157 System.out.println( "domain counts based" );
1158 html_desc.append( "domain counts based" + "</td></tr>" + nl );
1161 System.out.println( "domain proteins counts based" );
1162 html_desc.append( "domain proteins counts based" + "</td></tr>" + nl );
1165 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1167 System.out.print( " Sort by : " );
1168 html_desc.append( "<tr><td>Sort by:</td><td>" );
1169 switch ( domain_similarity_sort_field ) {
1171 System.out.print( "score minimum" );
1172 html_desc.append( "score minimum" );
1175 System.out.print( "score maximum" );
1176 html_desc.append( "score maximum" );
1179 System.out.print( "score mean" );
1180 html_desc.append( "score mean" );
1183 System.out.print( "score standard deviation" );
1184 html_desc.append( "score standard deviation" );
1187 System.out.print( "species number" );
1188 html_desc.append( "species number" );
1191 System.out.print( "alphabetical domain identifier" );
1192 html_desc.append( "alphabetical domain identifier" );
1194 case MAX_DIFFERENCE:
1195 System.out.print( "(maximal) difference" );
1196 html_desc.append( "(maximal) difference" );
1198 case ABS_MAX_COUNTS_DIFFERENCE:
1199 System.out.print( "absolute (maximal) counts difference" );
1200 html_desc.append( "absolute (maximal) counts difference" );
1202 case MAX_COUNTS_DIFFERENCE:
1203 System.out.print( "(maximal) counts difference" );
1204 html_desc.append( "(maximal) counts difference" );
1207 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1209 if ( sort_by_species_count_first ) {
1210 System.out.println( " (sort by species count first)" );
1211 html_desc.append( " (sort by species count first)" );
1214 System.out.println();
1216 html_desc.append( "</td></tr>" + nl );
1217 System.out.print( " Detailedness : " );
1218 switch ( detailedness ) {
1220 System.out.println( "basic" );
1222 case LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES:
1223 System.out.println( "list combining domains for each species" );
1226 System.out.println( "punctilious" );
1229 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for detailedness" );
1231 System.out.print( " Print option : " );
1232 switch ( domain_similarity_print_option ) {
1234 System.out.println( "HTML" );
1236 case SIMPLE_TAB_DELIMITED:
1237 System.out.println( "simple tab delimited" );
1240 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for print option" );
1242 System.out.print( " Species matrix : " + species_matrix );
1243 System.out.println();
1244 final File dc_data_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + DATA_FILE_SUFFIX );
1245 System.out.println( "Domain comb data output : " + dc_data_file );
1246 html_desc.append( "<tr><td>Domain combination data output:</td><td> " + dc_data_file + " </td></tr>" );
1247 System.out.println();
1248 if ( perform_pwc ) {
1249 System.out.println( "Pairwise comparisons: " );
1250 html_desc.append( "<tr><td>Pairwise comparisons:</td><td></td></tr>" );
1251 System.out.print( " Sort by : " );
1252 html_desc.append( "<tr><td>Sort by:</td><td>" );
1253 switch ( domain_similarity_sort_field_for_automated_pwc ) {
1255 System.out.print( "score mean" );
1256 html_desc.append( "score mean" );
1259 System.out.print( "alphabetical domain identifier" );
1260 html_desc.append( "alphabetical domain identifier" );
1262 case MAX_DIFFERENCE:
1263 System.out.print( "difference" );
1264 html_desc.append( "difference" );
1266 case ABS_MAX_COUNTS_DIFFERENCE:
1267 System.out.print( "absolute counts difference" );
1268 html_desc.append( "absolute counts difference" );
1270 case MAX_COUNTS_DIFFERENCE:
1271 System.out.print( "counts difference" );
1272 html_desc.append( "counts difference" );
1276 .unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1278 System.out.println();
1279 html_desc.append( "</td></tr>" + nl );
1280 if ( ( intrees != null ) && ( intrees.length > 0 ) ) {
1281 for( final File intree_file : intree_files ) {
1282 html_desc.append( "<tr><td>Intree for gain/loss parsimony analysis:</td><td>" + intree_file
1283 + "</td></tr>" + nl );
1284 System.out.println( " Intree for gain/loss pars.: " + intree_file );
1287 if ( radomize_fitch_parsimony ) {
1288 html_desc.append( "<tr><td> Random number seed for Fitch parsimony analysis:</td><td>"
1289 + random_number_seed_for_fitch_parsimony + "</td></tr>" + nl );
1290 System.out.println( " Random number seed : " + random_number_seed_for_fitch_parsimony );
1292 if ( ( domain_id_to_secondary_features_maps != null ) && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
1293 for( int i = 0; i < secondary_features_map_files.length; i++ ) {
1294 html_desc.append( "<tr><td>Secondary features map file:</td><td>"
1295 + secondary_features_map_files[ i ] + "</td></tr>" + nl );
1296 System.out.println( "Secondary features map file : " + secondary_features_map_files[ i ]
1297 + " [mappings for " + domain_id_to_secondary_features_maps[ i ].size() + " domain ids]" );
1299 System.out.println();
1300 System.out.println( "Domain ids to secondary features map:" );
1301 for( final String domain_id : domain_id_to_secondary_features_maps[ i ].keySet() ) {
1302 System.out.print( domain_id );
1303 System.out.print( " => " );
1304 for( final String sec : domain_id_to_secondary_features_maps[ i ].get( domain_id ) ) {
1305 System.out.print( sec );
1306 System.out.print( " " );
1308 System.out.println();
1313 } // if ( perform_pwc ) {
1314 System.out.println();
1315 html_desc.append( "<tr><td>Command line:</td><td>\n" + cla.getCommandLineArgsAsString() + "\n</td></tr>" + nl );
1316 System.out.println( "Command line : " + cla.getCommandLineArgsAsString() );
1317 BufferedWriter[] query_domains_writer_ary = null;
1318 List<String>[] query_domain_ids_array = null;
1319 if ( query_domain_ids != null ) {
1320 final String[] query_domain_ids_str_array = query_domain_ids.split( "#" );
1321 query_domain_ids_array = new ArrayList[ query_domain_ids_str_array.length ];
1322 query_domains_writer_ary = new BufferedWriter[ query_domain_ids_str_array.length ];
1323 for( int i = 0; i < query_domain_ids_str_array.length; i++ ) {
1324 String query_domain_ids_str = query_domain_ids_str_array[ i ];
1325 final String[] query_domain_ids_str_ary = query_domain_ids_str.split( "~" );
1326 final List<String> query = new ArrayList<String>();
1327 for( final String element : query_domain_ids_str_ary ) {
1328 query.add( element );
1330 query_domain_ids_array[ i ] = query;
1331 query_domain_ids_str = query_domain_ids_str.replace( '~', '_' );
1332 String protein_names_writer_str = query_domain_ids_str + surfacing.SEQ_EXTRACT_SUFFIX;
1333 if ( out_dir != null ) {
1334 protein_names_writer_str = out_dir + ForesterUtil.FILE_SEPARATOR + protein_names_writer_str;
1337 query_domains_writer_ary[ i ] = new BufferedWriter( new FileWriter( protein_names_writer_str ) );
1339 catch ( final IOException e ) {
1340 ForesterUtil.fatalError( surfacing.PRG_NAME, "Could not open [" + protein_names_writer_str + "]: "
1341 + e.getLocalizedMessage() );
1345 SortedMap<Species, List<Protein>> protein_lists_per_species = null; //This will only be created if neede.
1346 boolean need_protein_lists_per_species = false;
1347 if ( ( plus_minus_analysis_high_copy_base_species.size() > 0 ) || output_protein_lists_for_all_domains ) {
1348 need_protein_lists_per_species = true;
1350 if ( need_protein_lists_per_species ) {
1351 protein_lists_per_species = new TreeMap<Species, List<Protein>>();
1353 List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>( number_of_genomes );
1354 final SortedSet<String> all_domains_encountered = new TreeSet<String>();
1355 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered = new TreeSet<BinaryDomainCombination>();
1356 List<BinaryDomainCombination> all_bin_domain_combinations_gained_fitch = null;
1357 List<BinaryDomainCombination> all_bin_domain_combinations_lost_fitch = null;
1358 if ( ( intrees != null ) && ( intrees.length == 1 ) ) {
1359 all_bin_domain_combinations_gained_fitch = new ArrayList<BinaryDomainCombination>();
1360 all_bin_domain_combinations_lost_fitch = new ArrayList<BinaryDomainCombination>();
1362 DomainLengthsTable domain_lengths_table = new DomainLengthsTable();
1363 final File per_genome_domain_promiscuity_statistics_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR
1364 + output_file + D_PROMISCUITY_FILE_SUFFIX );
1365 BufferedWriter per_genome_domain_promiscuity_statistics_writer = null;
1367 per_genome_domain_promiscuity_statistics_writer = new BufferedWriter( new FileWriter( per_genome_domain_promiscuity_statistics_file ) );
1368 per_genome_domain_promiscuity_statistics_writer.write( "Species:\t" );
1369 per_genome_domain_promiscuity_statistics_writer.write( "Mean:\t" );
1370 per_genome_domain_promiscuity_statistics_writer.write( "SD:\t" );
1371 per_genome_domain_promiscuity_statistics_writer.write( "Median:\t" );
1372 per_genome_domain_promiscuity_statistics_writer.write( "Min:\t" );
1373 per_genome_domain_promiscuity_statistics_writer.write( "Max:\t" );
1374 per_genome_domain_promiscuity_statistics_writer.write( "N:\t" );
1375 per_genome_domain_promiscuity_statistics_writer.write( "Max Promiscuous Domains:"
1376 + ForesterUtil.LINE_SEPARATOR );
1378 catch ( final IOException e2 ) {
1379 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1381 final File log_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + LOG_FILE_SUFFIX );
1382 BufferedWriter log_writer = null;
1384 log_writer = new BufferedWriter( new FileWriter( log_file ) );
1386 catch ( final IOException e2 ) {
1387 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1389 BufferedWriter dc_data_writer = null;
1391 dc_data_writer = new BufferedWriter( new FileWriter( dc_data_file ) );
1392 dc_data_writer.write( DATA_FILE_DESC );
1393 dc_data_writer.write( ForesterUtil.LINE_SEPARATOR );
1395 catch ( final IOException e2 ) {
1396 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1398 final DescriptiveStatistics protein_coverage_stats = new BasicDescriptiveStatistics();
1399 final DescriptiveStatistics all_genomes_domains_per_potein_stats = new BasicDescriptiveStatistics();
1400 final SortedMap<Integer, Integer> all_genomes_domains_per_potein_histo = new TreeMap<Integer, Integer>();
1401 final SortedSet<String> domains_which_are_always_single = new TreeSet<String>();
1402 final SortedSet<String> domains_which_are_sometimes_single_sometimes_not = new TreeSet<String>();
1403 final SortedSet<String> domains_which_never_single = new TreeSet<String>();
1404 BufferedWriter domains_per_potein_stats_writer = null;
1406 domains_per_potein_stats_writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR
1407 + output_file + "_domains_per_potein_stats.txt" ) );
1408 domains_per_potein_stats_writer.write( "Genome" );
1409 domains_per_potein_stats_writer.write( "\t" );
1410 domains_per_potein_stats_writer.write( "Mean" );
1411 domains_per_potein_stats_writer.write( "\t" );
1412 domains_per_potein_stats_writer.write( "SD" );
1413 domains_per_potein_stats_writer.write( "\t" );
1414 domains_per_potein_stats_writer.write( "Median" );
1415 domains_per_potein_stats_writer.write( "\t" );
1416 domains_per_potein_stats_writer.write( "N" );
1417 domains_per_potein_stats_writer.write( "\t" );
1418 domains_per_potein_stats_writer.write( "Min" );
1419 domains_per_potein_stats_writer.write( "\t" );
1420 domains_per_potein_stats_writer.write( "Max" );
1421 domains_per_potein_stats_writer.write( "\n" );
1423 catch ( final IOException e3 ) {
1424 e3.printStackTrace();
1426 Map<String, DescriptiveStatistics> protein_length_stats_by_dc = null;
1427 Map<String, DescriptiveStatistics> domain_number_stats_by_dc = null;
1428 final Map<String, DescriptiveStatistics> domain_length_stats_by_domain = new HashMap<String, DescriptiveStatistics>();
1429 if ( perform_dc_regain_proteins_stats ) {
1430 protein_length_stats_by_dc = new HashMap<String, DescriptiveStatistics>();
1431 domain_number_stats_by_dc = new HashMap<String, DescriptiveStatistics>();
1434 final SortedMap<String, Set<String>> distinct_domain_architecutures_per_genome = new TreeMap<String, Set<String>>();
1435 final SortedMap<String, Integer> distinct_domain_architecuture_counts = new TreeMap<String, Integer>();
1436 for( int i = 0; i < number_of_genomes; ++i ) {
1437 System.out.println();
1438 System.out.println( ( i + 1 ) + "/" + number_of_genomes );
1439 SurfacingUtil.log( ( i + 1 ) + "/" + number_of_genomes, log_writer );
1440 System.out.println( "Processing : " + input_file_properties[ i ][ 1 ]
1441 + " [" + input_file_properties[ i ][ 0 ] + "]" );
1442 SurfacingUtil.log( "Genome : " + input_file_properties[ i ][ 1 ]
1443 + " [" + input_file_properties[ i ][ 0 ] + "]", log_writer );
1444 HmmscanPerDomainTableParser parser = null;
1445 INDIVIDUAL_SCORE_CUTOFF ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF.NONE;
1446 if ( individual_score_cutoffs != null ) {
1447 ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF_DEFAULT;
1449 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1450 || ( negative_domains_filter_file != null ) ) {
1451 HmmscanPerDomainTableParser.FilterType filter_type = HmmscanPerDomainTableParser.FilterType.NONE;
1452 if ( positive_filter_file != null ) {
1453 filter_type = HmmscanPerDomainTableParser.FilterType.POSITIVE_PROTEIN;
1455 else if ( negative_filter_file != null ) {
1456 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_PROTEIN;
1458 else if ( negative_domains_filter_file != null ) {
1459 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_DOMAIN;
1461 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1462 input_file_properties[ i ][ 1 ],
1469 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1470 input_file_properties[ i ][ 1 ],
1474 if ( e_value_max >= 0.0 ) {
1475 parser.setEValueMaximum( e_value_max );
1477 parser.setIgnoreDufs( ignore_dufs );
1478 parser.setIgnoreVirusLikeIds( ignore_virus_like_ids );
1479 parser.setIgnoreEngulfedDomains( no_engulfing_overlaps );
1480 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1481 parser.setMaxAllowedOverlap( max_allowed_overlap );
1483 parser.setReturnType( HmmscanPerDomainTableParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
1484 if ( individual_score_cutoffs != null ) {
1485 parser.setIndividualScoreCutoffs( individual_score_cutoffs );
1487 List<Protein> protein_list = null;
1489 protein_list = parser.parse();
1491 catch ( final IOException e ) {
1492 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
1494 catch ( final Exception e ) {
1495 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, e.getMessage(), e );
1498 System.out.println( "Domains ignored due to negative domain filter: " );
1499 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToNegativeDomainFilterCountsMap() );
1500 System.out.println( "Domains ignored due to virus like id: " );
1501 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToVirusLikeIdCountsMap() );
1503 final double coverage = ( double ) protein_list.size() / parser.getProteinsEncountered();
1504 protein_coverage_stats.addValue( coverage );
1505 int distinct_das = -1;
1506 if ( da_analysis ) {
1507 final String genome = input_file_properties[ i ][ 0 ];
1508 distinct_das = SurfacingUtil.storeDomainArchitectures( genome,
1509 distinct_domain_architecutures_per_genome,
1511 distinct_domain_architecuture_counts );
1513 System.out.println( "Number of proteins encountered : " + parser.getProteinsEncountered() );
1514 SurfacingUtil.log( "Number of proteins encountered : " + parser.getProteinsEncountered(),
1516 System.out.println( "Number of proteins stored : " + protein_list.size() );
1517 SurfacingUtil.log( "Number of proteins stored : " + protein_list.size(), log_writer );
1518 System.out.println( "Coverage : "
1519 + ForesterUtil.roundToInt( 100.0 * coverage ) + "%" );
1520 SurfacingUtil.log( "Coverage : "
1521 + ForesterUtil.roundToInt( 100.0 * coverage ) + "%",
1523 System.out.println( "Domains encountered : " + parser.getDomainsEncountered() );
1524 SurfacingUtil.log( "Domains encountered : " + parser.getDomainsEncountered(),
1526 System.out.println( "Domains stored : " + parser.getDomainsStored() );
1527 SurfacingUtil.log( "Domains stored : " + parser.getDomainsStored(),
1529 System.out.println( "Distinct domains stored : "
1530 + parser.getDomainsStoredSet().size() );
1531 SurfacingUtil.log( "Distinct domains stored : "
1532 + parser.getDomainsStoredSet().size(), log_writer );
1533 System.out.println( "Domains ignored due to individual score cutoffs: "
1534 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() );
1535 SurfacingUtil.log( "Domains ignored due to individual score cutoffs: "
1536 + parser.getDomainsIgnoredDueToIndividualScoreCutoff(),
1538 System.out.println( "Domains ignored due to E-value : "
1539 + parser.getDomainsIgnoredDueToEval() );
1540 SurfacingUtil.log( "Domains ignored due to E-value : "
1541 + parser.getDomainsIgnoredDueToEval(),
1543 System.out.println( "Domains ignored due to DUF designation : "
1544 + parser.getDomainsIgnoredDueToDuf() );
1546 .log( "Domains ignored due to DUF designation : " + parser.getDomainsIgnoredDueToDuf(),
1548 if ( ignore_virus_like_ids ) {
1549 System.out.println( "Domains ignored due virus like ids : "
1550 + parser.getDomainsIgnoredDueToVirusLikeIds() );
1551 SurfacingUtil.log( "Domains ignored due virus like ids : "
1552 + parser.getDomainsIgnoredDueToVirusLikeIds(),
1555 System.out.println( "Domains ignored due negative domain filter : "
1556 + parser.getDomainsIgnoredDueToNegativeDomainFilter() );
1557 SurfacingUtil.log( "Domains ignored due negative domain filter : "
1558 + parser.getDomainsIgnoredDueToNegativeDomainFilter(),
1560 System.out.println( "Domains ignored due to overlap : "
1561 + parser.getDomainsIgnoredDueToOverlap() );
1562 SurfacingUtil.log( "Domains ignored due to overlap : "
1563 + parser.getDomainsIgnoredDueToOverlap(),
1565 if ( negative_filter_file != null ) {
1566 System.out.println( "Proteins ignored due to negative filter : "
1567 + parser.getProteinsIgnoredDueToFilter() );
1568 SurfacingUtil.log( "Proteins ignored due to negative filter : "
1569 + parser.getProteinsIgnoredDueToFilter(),
1572 if ( positive_filter_file != null ) {
1573 System.out.println( "Proteins ignored due to positive filter : "
1574 + parser.getProteinsIgnoredDueToFilter() );
1575 SurfacingUtil.log( "Proteins ignored due to positive filter : "
1576 + parser.getProteinsIgnoredDueToFilter(),
1579 if ( da_analysis ) {
1580 System.out.println( "Distinct domain architectures stored : " + distinct_das );
1581 SurfacingUtil.log( "Distinct domain architectures stored : " + distinct_das, log_writer );
1583 System.out.println( "Time for processing : " + parser.getTime() + "ms" );
1584 SurfacingUtil.log( "", log_writer );
1587 for( final Protein protein : protein_list ) {
1588 dc_data_writer.write( SurfacingUtil.proteinToDomainCombinations( protein, count + "", "\t" )
1591 for( final Domain d : protein.getProteinDomains() ) {
1592 final String d_str = d.getDomainId().toString();
1593 if ( !domain_length_stats_by_domain.containsKey( d_str ) ) {
1594 domain_length_stats_by_domain.put( d_str, new BasicDescriptiveStatistics() );
1596 domain_length_stats_by_domain.get( d_str ).addValue( d.getLength() );
1600 catch ( final IOException e ) {
1601 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1603 SurfacingUtil.domainsPerProteinsStatistics( input_file_properties[ i ][ 1 ],
1605 all_genomes_domains_per_potein_stats,
1606 all_genomes_domains_per_potein_histo,
1607 domains_which_are_always_single,
1608 domains_which_are_sometimes_single_sometimes_not,
1609 domains_which_never_single,
1610 domains_per_potein_stats_writer );
1611 domain_lengths_table.addLengths( protein_list );
1612 if ( !da_analysis ) {
1613 gwcd_list.add( BasicGenomeWideCombinableDomains
1614 .createInstance( protein_list,
1615 ignore_combination_with_same,
1616 new BasicSpecies( input_file_properties[ i ][ 1 ] ),
1617 domain_id_to_go_ids_map,
1619 protein_length_stats_by_dc,
1620 domain_number_stats_by_dc ) );
1621 if ( gwcd_list.get( i ).getSize() > 0 ) {
1622 SurfacingUtil.writeDomainCombinationsCountsFile( input_file_properties,
1624 per_genome_domain_promiscuity_statistics_writer,
1628 if ( output_binary_domain_combinationsfor_graph_analysis ) {
1629 SurfacingUtil.writeBinaryDomainCombinationsFileForGraphAnalysis( input_file_properties,
1635 SurfacingUtil.addAllDomainIdsToSet( gwcd_list.get( i ), all_domains_encountered );
1636 SurfacingUtil.addAllBinaryDomainCombinationToSet( gwcd_list.get( i ),
1637 all_bin_domain_combinations_encountered );
1640 if ( query_domains_writer_ary != null ) {
1641 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1643 SurfacingUtil.extractProteinNames( protein_list,
1644 query_domain_ids_array[ j ],
1645 query_domains_writer_ary[ j ],
1647 LIMIT_SPEC_FOR_PROT_EX );
1648 query_domains_writer_ary[ j ].flush();
1650 catch ( final IOException e ) {
1651 e.printStackTrace();
1655 if ( need_protein_lists_per_species ) {
1656 protein_lists_per_species.put( new BasicSpecies( input_file_properties[ i ][ 1 ] ), protein_list );
1661 catch ( final IOException e2 ) {
1662 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1665 } // for( int i = 0; i < number_of_genomes; ++i ) {
1666 ForesterUtil.programMessage( PRG_NAME, "Wrote domain promiscuities to: "
1667 + per_genome_domain_promiscuity_statistics_file );
1669 if ( da_analysis ) {
1670 SurfacingUtil.performDomainArchitectureAnalysis( distinct_domain_architecutures_per_genome,
1671 distinct_domain_architecuture_counts,
1673 new File( out_dir.toString() + "/" + output_file
1674 + "_DA_counts.txt" ),
1675 new File( out_dir.toString() + "/" + output_file
1676 + "_unique_DAs.txt" ) );
1677 distinct_domain_architecutures_per_genome.clear();
1678 distinct_domain_architecuture_counts.clear();
1682 domains_per_potein_stats_writer.write( "ALL" );
1683 domains_per_potein_stats_writer.write( "\t" );
1684 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.arithmeticMean() + "" );
1685 domains_per_potein_stats_writer.write( "\t" );
1686 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.sampleStandardDeviation() + "" );
1687 domains_per_potein_stats_writer.write( "\t" );
1688 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.median() + "" );
1689 domains_per_potein_stats_writer.write( "\t" );
1690 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getN() + "" );
1691 domains_per_potein_stats_writer.write( "\t" );
1692 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getMin() + "" );
1693 domains_per_potein_stats_writer.write( "\t" );
1694 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getMax() + "" );
1695 domains_per_potein_stats_writer.write( "\n" );
1696 domains_per_potein_stats_writer.close();
1697 SurfacingUtil.printOutPercentageOfMultidomainProteins( all_genomes_domains_per_potein_histo, log_writer );
1698 ForesterUtil.map2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1699 + "_all_genomes_domains_per_potein_histo.txt" ), all_genomes_domains_per_potein_histo, "\t", "\n" );
1700 ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1701 + "_domains_always_single_.txt" ), domains_which_are_always_single, "\n" );
1702 ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1703 + "_domains_single_or_combined.txt" ), domains_which_are_sometimes_single_sometimes_not, "\n" );
1704 ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1705 + "_domains_always_combined.txt" ), domains_which_never_single, "\n" );
1706 ForesterUtil.programMessage( PRG_NAME,
1707 "Average of proteins with a least one domain assigned: "
1708 + ( 100 * protein_coverage_stats.arithmeticMean() ) + "% (+/-"
1709 + ( 100 * protein_coverage_stats.sampleStandardDeviation() ) + "%)" );
1710 ForesterUtil.programMessage( PRG_NAME, "Range of proteins with a least one domain assigned: "
1711 + ( 100 * protein_coverage_stats.getMin() ) + "%-" + ( 100 * protein_coverage_stats.getMax() )
1713 SurfacingUtil.log( "Average of prot with a least one dom assigned : "
1714 + ( 100 * protein_coverage_stats.arithmeticMean() ) + "% (+/-"
1715 + ( 100 * protein_coverage_stats.sampleStandardDeviation() ) + "%)",
1717 SurfacingUtil.log( "Range of prot with a least one dom assigned : "
1718 + ( 100 * protein_coverage_stats.getMin() ) + "%-"
1719 + ( 100 * protein_coverage_stats.getMax() ) + "%",
1722 catch ( final IOException e2 ) {
1723 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1725 if ( query_domains_writer_ary != null ) {
1726 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1728 query_domains_writer_ary[ j ].close();
1730 catch ( final IOException e ) {
1731 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1736 per_genome_domain_promiscuity_statistics_writer.close();
1737 dc_data_writer.close();
1740 catch ( final IOException e2 ) {
1741 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1743 if ( PERFORM_DOMAIN_LENGTH_ANALYSIS ) {
1745 SurfacingUtil.executeDomainLengthAnalysis( input_file_properties,
1747 domain_lengths_table,
1748 domain_lengths_analysis_outfile );
1750 catch ( final IOException e1 ) {
1751 ForesterUtil.fatalError( surfacing.PRG_NAME, e1.toString() );
1753 System.out.println();
1754 ForesterUtil.programMessage( PRG_NAME, "Wrote domain length data to: " + domain_lengths_analysis_outfile );
1755 System.out.println();
1757 domain_lengths_table = null;
1758 final long analysis_start_time = new Date().getTime();
1759 PairwiseDomainSimilarityCalculator pw_calc = null;
1760 final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( domain_similarity_sort_field,
1761 sort_by_species_count_first,
1762 number_of_genomes == 2,
1763 CALC_SIMILARITY_SCORES );
1764 switch ( scoring ) {
1766 pw_calc = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1769 pw_calc = new DomainCountsBasedPairwiseSimilarityCalculator();
1772 pw_calc = new ProteinCountsBasedPairwiseDomainSimilarityCalculator();
1775 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1777 DomainSimilarityCalculator.GoAnnotationOutput go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.NONE;
1778 if ( domain_id_to_go_ids_map != null ) {
1779 go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.ALL;
1781 final SortedSet<DomainSimilarity> similarities = calc
1782 .calculateSimilarities( pw_calc,
1784 ignore_domains_without_combs_in_all_spec,
1785 ignore_species_specific_domains );
1786 SurfacingUtil.decoratePrintableDomainSimilarities( similarities, detailedness );
1787 final Map<String, Integer> tax_code_to_id_map = SurfacingUtil.createTaxCodeToIdMap( intrees[ 0 ] );
1789 String my_outfile = output_file.toString();
1790 Map<Character, Writer> split_writers = null;
1791 Writer writer = null;
1792 if ( similarities.size() > MINIMAL_NUMBER_OF_SIMILARITIES_FOR_SPLITTING ) {
1793 if ( my_outfile.endsWith( ".html" ) ) {
1794 my_outfile = my_outfile.substring( 0, my_outfile.length() - 5 );
1796 split_writers = new HashMap<Character, Writer>();
1797 SurfacingUtil.createSplitWriters( out_dir, my_outfile, split_writers );
1799 else if ( !my_outfile.endsWith( ".html" ) ) {
1800 my_outfile += ".html";
1801 writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR + my_outfile ) );
1803 List<Species> species_order = null;
1804 if ( species_matrix ) {
1805 species_order = new ArrayList<Species>();
1806 for( int i = 0; i < number_of_genomes; i++ ) {
1807 species_order.add( new BasicSpecies( input_file_properties[ i ][ 1 ] ) );
1810 html_desc.append( "<tr><td>Sum of all distinct binary combinations:</td><td>"
1811 + all_bin_domain_combinations_encountered.size() + "</td></tr>" + nl );
1812 html_desc.append( "<tr><td>Sum of all distinct domains:</td><td>" + all_domains_encountered.size()
1813 + "</td></tr>" + nl );
1814 html_desc.append( "<tr><td>Analysis date/time:</td><td>"
1815 + new java.text.SimpleDateFormat( "yyyy.MM.dd HH:mm:ss" ).format( new java.util.Date() )
1816 + "</td></tr>" + nl );
1817 html_desc.append( "</table>" + nl );
1818 final Writer simple_tab_writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR
1819 + my_outfile + ".tsv" ) );
1820 SurfacingUtil.writeDomainSimilaritiesToFile( html_desc,
1821 new StringBuilder( number_of_genomes + " genomes" ),
1826 number_of_genomes == 2,
1828 domain_similarity_print_option,
1833 simple_tab_writer.close();
1834 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote main output (includes domain similarities) to: \""
1835 + ( out_dir == null ? my_outfile : out_dir + ForesterUtil.FILE_SEPARATOR + my_outfile ) + "\"" );
1837 catch ( final IOException e ) {
1838 ForesterUtil.fatalError( surfacing.PRG_NAME, "Failed to write similarites to: \"" + output_file + "\" ["
1839 + e.getMessage() + "]" );
1841 System.out.println();
1842 final Species[] species = new Species[ number_of_genomes ];
1843 for( int i = 0; i < number_of_genomes; ++i ) {
1844 species[ i ] = new BasicSpecies( input_file_properties[ i ][ 1 ] );
1846 List<Phylogeny> inferred_trees = null;
1847 if ( ( number_of_genomes > 2 ) && perform_pwc ) {
1848 final PairwiseGenomeComparator pwgc = new PairwiseGenomeComparator();
1849 pwgc.performPairwiseComparisons( html_desc,
1850 sort_by_species_count_first,
1852 ignore_domains_without_combs_in_all_spec,
1853 ignore_species_specific_domains,
1854 domain_similarity_sort_field_for_automated_pwc,
1855 domain_similarity_print_option,
1857 domain_id_to_go_ids_map,
1864 automated_pairwise_comparison_suffix,
1866 surfacing.PAIRWISE_DOMAIN_COMPARISONS_PREFIX,
1871 CALC_SIMILARITY_SCORES,
1873 String matrix_output_file = new String( output_file.toString() );
1874 if ( matrix_output_file.indexOf( '.' ) > 1 ) {
1875 matrix_output_file = matrix_output_file.substring( 0, matrix_output_file.indexOf( '.' ) );
1877 if ( out_dir != null ) {
1878 matrix_output_file = out_dir + ForesterUtil.FILE_SEPARATOR + matrix_output_file;
1879 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
1881 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
1882 + surfacing.MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc.getDomainDistanceScoresMeans() );
1884 .writeMatrixToFile( new File( matrix_output_file
1885 + surfacing.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
1886 pwgc.getSharedBinaryCombinationsBasedDistances() );
1887 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
1888 + surfacing.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
1889 pwgc.getSharedDomainsBasedDistances() );
1890 final Phylogeny nj_gd = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
1891 + surfacing.NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc.getDomainDistanceScoresMeans()
1893 final Phylogeny nj_bc = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
1894 + surfacing.NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
1895 .getSharedBinaryCombinationsBasedDistances().get( 0 ) );
1896 final Phylogeny nj_d = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
1897 + surfacing.NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
1898 .getSharedDomainsBasedDistances().get( 0 ) );
1899 inferred_trees = new ArrayList<Phylogeny>();
1900 inferred_trees.add( nj_gd );
1901 inferred_trees.add( nj_bc );
1902 inferred_trees.add( nj_d );
1903 } // if ( ( output_file != null ) && ( number_of_genomes > 2 ) && !isEmpty( automated_pairwise_comparison_suffix ) )
1904 if ( ( out_dir != null ) && ( !perform_pwc ) ) {
1905 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
1907 if ( write_to_nexus ) {
1908 SurfacingUtil.writePresentToNexus( output_file, positive_filter_file, filter, gwcd_list );
1910 if ( ( ( intrees != null ) && ( intrees.length > 0 ) ) && ( number_of_genomes > 2 ) ) {
1911 final StringBuilder parameters_sb = SurfacingUtil.createParametersAsString( ignore_dufs,
1913 max_allowed_overlap,
1914 no_engulfing_overlaps,
1918 if ( radomize_fitch_parsimony ) {
1919 s += random_number_seed_for_fitch_parsimony + "_";
1922 for( final Phylogeny intree : intrees ) {
1923 final String outfile_name = ForesterUtil.removeSuffix( output_file.toString() ) + s
1924 + ForesterUtil.removeSuffix( intree_files[ i ].toString() );
1925 final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator.createInstance( intree,
1927 SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
1928 radomize_fitch_parsimony,
1932 domain_id_to_go_ids_map,
1935 parameters_sb.toString(),
1936 domain_id_to_secondary_features_maps,
1937 positive_filter_file == null ? null : filter,
1938 output_binary_domain_combinationsfor_graph_analysis,
1939 all_bin_domain_combinations_gained_fitch,
1940 all_bin_domain_combinations_lost_fitch,
1942 protein_length_stats_by_dc,
1943 domain_number_stats_by_dc,
1944 domain_length_stats_by_domain,
1947 use_last_in_fitch_parsimony );
1948 // Listing of all domain combinations gained is only done if only one input tree is used.
1949 if ( ( domain_id_to_secondary_features_maps != null )
1950 && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
1952 for( final Map<String, Set<String>> domain_id_to_secondary_features_map : domain_id_to_secondary_features_maps ) {
1953 final Map<Species, MappingResults> mapping_results_map = new TreeMap<Species, MappingResults>();
1954 final DomainParsimonyCalculator secondary_features_parsimony = DomainParsimonyCalculator
1955 .createInstance( intree, gwcd_list, domain_id_to_secondary_features_map );
1957 .executeParsimonyAnalysisForSecondaryFeatures( outfile_name
1959 + secondary_features_map_files[ j++ ],
1960 secondary_features_parsimony,
1962 parameters_sb.toString(),
1963 mapping_results_map,
1964 use_last_in_fitch_parsimony );
1966 System.out.println();
1967 System.out.println( "Mapping to secondary features:" );
1968 for( final Species spec : mapping_results_map.keySet() ) {
1969 final MappingResults mapping_results = mapping_results_map.get( spec );
1970 final int total_domains = mapping_results.getSumOfFailures()
1971 + mapping_results.getSumOfSuccesses();
1972 System.out.print( spec + ":" );
1973 System.out.print( " mapped domains = " + mapping_results.getSumOfSuccesses() );
1974 System.out.print( ", not mapped domains = " + mapping_results.getSumOfFailures() );
1975 if ( total_domains > 0 ) {
1976 System.out.println( ", mapped ratio = "
1977 + ( ( 100 * mapping_results.getSumOfSuccesses() ) / total_domains ) + "%" );
1980 System.out.println( ", mapped ratio = n/a (total domains = 0 )" );
1987 } // for( final Phylogeny intree : intrees ) {
1989 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
1990 SurfacingUtil.executePlusMinusAnalysis( output_file,
1991 plus_minus_analysis_high_copy_base_species,
1992 plus_minus_analysis_high_copy_target_species,
1993 plus_minus_analysis_high_low_copy_species,
1995 protein_lists_per_species,
1996 domain_id_to_go_ids_map,
1998 plus_minus_analysis_numbers );
2000 if ( output_protein_lists_for_all_domains ) {
2001 SurfacingUtil.writeProteinListsForAllSpecies( out_dir,
2002 protein_lists_per_species,
2004 output_list_of_all_proteins_per_domain_e_value_max );
2007 if ( all_bin_domain_combinations_gained_fitch != null ) {
2010 .executeFitchGainsAnalysis( new File( output_file
2011 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2012 all_bin_domain_combinations_gained_fitch,
2013 all_domains_encountered.size(),
2014 all_bin_domain_combinations_encountered,
2017 catch ( final IOException e ) {
2018 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2021 if ( all_bin_domain_combinations_lost_fitch != null ) {
2024 .executeFitchGainsAnalysis( new File( output_file
2025 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2026 all_bin_domain_combinations_lost_fitch,
2027 all_domains_encountered.size(),
2028 all_bin_domain_combinations_encountered,
2031 catch ( final IOException e ) {
2032 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2035 final Runtime rt = java.lang.Runtime.getRuntime();
2036 final long free_memory = rt.freeMemory() / 1000000;
2037 final long total_memory = rt.totalMemory() / 1000000;
2038 ForesterUtil.programMessage( PRG_NAME, "Time for analysis : " + ( new Date().getTime() - analysis_start_time )
2040 ForesterUtil.programMessage( PRG_NAME, "Total running time: " + ( new Date().getTime() - start_time ) + "ms " );
2041 ForesterUtil.programMessage( PRG_NAME, "Free memory : " + free_memory + "MB, total memory: "
2042 + total_memory + "MB" );
2043 ForesterUtil.programMessage( PRG_NAME, "If this application is useful to you, please cite:" );
2044 ForesterUtil.programMessage( PRG_NAME, surfacing.WWW );
2045 ForesterUtil.programMessage( PRG_NAME, "OK" );
2046 System.out.println();
2049 private static void printHelp() {
2050 System.out.println();
2051 System.out.println( "Usage:" );
2052 System.out.println();
2053 System.out.println( "% java -Xms256m -Xmx512m -cp forester.jar org.forester.applications." + surfacing.PRG_NAME
2054 + " [options] <phylogen(y|ies) infile> [external node name 1] [name 2] ... [name n]" );
2055 System.out.println();
2056 System.out.println( " Note: This software might need a significant amount of memory (heap space);" );
2058 .println( " hence use \"-Xms128m -Xmx512m\" (or more) to prevent a \"java.lang.OutOfMemoryError\"." );
2059 System.out.println();
2060 System.out.println( " Options: " );
2061 System.out.println( surfacing.DETAILEDNESS_OPTION + ": level of detail for similarities output file (default:"
2062 + DETAILEDNESS_DEFAULT + ")" );
2063 System.out.println( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION
2064 + ": to ignore combinations with self (default: not to ignore)" );
2066 .println( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION
2067 + ": to ignore domains without combinations in any species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2069 .println( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION
2070 + ": to ignore domains specific to one species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2071 System.out.println( surfacing.NOT_IGNORE_DUFS_OPTION
2072 + ": to _not_ ignore DUFs (domains with unknown function) (default: ignore DUFs)" );
2074 .println( surfacing.IGNORE_VIRAL_IDS
2075 + ": to ignore domains with ids containing 'vir', 'retro', 'transpos', 'phage', or starting with 'rv' or 'gag_'" );
2076 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_OPTION + ": sorting for similarities (default: "
2077 + DOMAIN_SORT_FILD_DEFAULT + ")" );
2078 System.out.println( surfacing.OUTPUT_FILE_OPTION + ": name for (main) output file (mandatory)" );
2079 System.out.println( surfacing.MAX_E_VALUE_OPTION + ": max (inclusive) E-value" );
2080 System.out.println( surfacing.MAX_ALLOWED_OVERLAP_OPTION + ": maximal allowed domain overlap" );
2081 System.out.println( surfacing.NO_ENGULFING_OVERLAP_OPTION + ": to ignore engulfed lower confidence domains" );
2082 System.out.println( surfacing.SPECIES_MATRIX_OPTION + ": species matrix" );
2083 System.out.println( surfacing.SCORING_OPTION + ": scoring (default:" + SCORING_DEFAULT + ")" );
2084 System.out.println( surfacing.DOMAIN_COUNT_SORT_OPTION + ": sorting for domain counts (default:"
2085 + DOMAINS_SORT_ORDER_DEFAULT + ")" );
2086 System.out.println( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION + ": domain similarity print option (default:"
2087 + DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT + ")" );
2088 System.out.println( surfacing.CUTOFF_SCORE_FILE_OPTION + ": cutoff score file" );
2089 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION
2090 + ": sort by species count first" );
2091 System.out.println( surfacing.OUTPUT_DIR_OPTION + ": output directory" );
2092 System.out.println( surfacing.PFAM_TO_GO_FILE_USE_OPTION + ": Pfam to GO mapping file" );
2093 System.out.println( surfacing.GO_OBO_FILE_USE_OPTION + ": GO terms file (OBO format)" );
2094 System.out.println( surfacing.GO_NAMESPACE_LIMIT_OPTION + ": limit GO term to one GO namespace" );
2095 System.out.println( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
2096 + "[=<suffix for pairwise comparison output files>]: to perform pairwise comparison based analyses" );
2097 System.out.println( surfacing.INPUT_SPECIES_TREE_OPTION
2098 + ": species tree, to perform (Dollo, Fitch) parismony analyses" );
2100 .println( surfacing.INPUT_SPECIES_TREE_OPTION
2101 + "=<treefiles in phyloXML format, separated by #>: to infer domain/binary domain combination gains/losses on given species trees" );
2102 System.out.println( surfacing.FILTER_POSITIVE_OPTION
2103 + "=<file>: to filter out proteins not containing at least one domain listed in <file>" );
2104 System.out.println( surfacing.FILTER_NEGATIVE_OPTION
2105 + "=<file>: to filter out proteins containing at least one domain listed in <file>" );
2106 System.out.println( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION
2107 + "=<file>: to filter out (ignore) domains listed in <file>" );
2108 System.out.println( surfacing.INPUT_GENOMES_FILE_OPTION + "=<file>: to read input files from <file>" );
2110 .println( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION
2111 + "=<seed>: seed for random number generator for Fitch Parsimony analysis (type: long, default: no randomization - given a choice, prefer absence" );
2112 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS
2113 + ": to consider directedness in binary combinations: e.g. A-B != B-A" );
2114 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY
2115 + ": to consider directedness and adjacency in binary combinations" );
2117 .println( surfacing.SEQ_EXTRACT_OPTION
2118 + "=<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')" );
2119 System.out.println( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE
2120 + "=<file>: to perfom parsimony analysis on secondary features" );
2121 System.out.println( surfacing.PLUS_MINUS_ANALYSIS_OPTION + "=<file>: to presence/absence genome analysis" );
2122 System.out.println( surfacing.DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS
2123 + ": to output binary domain combinations for (downstream) graph analysis" );
2124 System.out.println( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS + ": to output all proteins per domain" );
2125 System.out.println( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION
2126 + ": e value max per domain for output of all proteins per domain" );
2127 System.out.println( surfacing.USE_LAST_IN_FITCH_OPTION + ": to use last in Fitch parsimony" );
2128 System.out.println( surfacing.WRITE_TO_NEXUS_OPTION + ": to output in Nexus format" );
2129 System.out.println( PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION + ": to perform DC regain protein statistics" );
2130 System.out.println( DA_ANALYSIS_OPTION + ": to do DA analysis" );
2131 System.out.println();
2132 System.out.println( "Example 1: java -Xms128m -Xmx512m -cp path/to/forester.jar"
2133 + " org.forester.application.surfacing p2g=pfam2go_2012_02_07.txt -dufs -cos=Pfam_260_NC1"
2134 + " -no_eo -mo=0 -genomes=eukaryotes.txt -out_dir=out -o=o "
2135 + " -species_tree=tol.xml -obo=gene_ontology_2012_02_07.obo -pos_filter=f.txt -all_prot" );
2136 System.out.println();
2137 System.out.println( "Example 2: java -Xms128m -Xmx512m -cp path/to/forester.jar"
2138 + " org.forester.application.surfacing -detail=punctilious -o=TEST.html -pwc=TEST"
2139 + " -cos=Pfam_ls_22_TC2 -p2g=pfam2go -obo=gene_ontology_edit.obo "
2140 + "-dc_sort=dom -ignore_with_self -no_singles -e=0.001 -mo=1 -no_eo -genomes=eukaryotes.txt "
2141 + "-ds_output=detailed_html -scoring=domains -sort=alpha " );
2142 System.out.println();