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.PRINT_OPTION;
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.MinimalDomainomeCalculator;
75 import org.forester.surfacing.PairwiseDomainSimilarityCalculator;
76 import org.forester.surfacing.PairwiseGenomeComparator;
77 import org.forester.surfacing.ProteinCountsBasedPairwiseDomainSimilarityCalculator;
78 import org.forester.surfacing.SurfacingUtil;
79 import org.forester.util.BasicDescriptiveStatistics;
80 import org.forester.util.BasicTable;
81 import org.forester.util.BasicTableParser;
82 import org.forester.util.CommandLineArguments;
83 import org.forester.util.DescriptiveStatistics;
84 import org.forester.util.ForesterConstants;
85 import org.forester.util.ForesterUtil;
87 public class surfacing {
89 private static final int MINIMAL_NUMBER_OF_SIMILARITIES_FOR_SPLITTING = 1000;
90 public final static String DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS = "graph_analysis_out";
91 public final static String DOMAIN_COMBINITONS_COUNTS_OUTPUT_OPTION = "dcc";
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 DomainSimilarity.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_FS_E_VALUE_OPTION = "fs_e";
177 final static private String MAX_I_E_VALUE_OPTION = "ie";
178 final static private String MIN_REL_ENV_LENGTH_RATIO_OPTION = "mrel";
179 final static private String MAX_ALLOWED_OVERLAP_OPTION = "mo";
180 final static private String NO_ENGULFING_OVERLAP_OPTION = "no_eo";
181 final static private String IGNORE_COMBINATION_WITH_SAME_OPTION = "ignore_self_comb";
182 final static private String PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION = "dc_regain_stats";
183 final static private String DA_ANALYSIS_OPTION = "da_analyis";
184 final static private String USE_LAST_IN_FITCH_OPTION = "last";
185 public final static String PAIRWISE_DOMAIN_COMPARISONS_PREFIX = "pwc_";
186 final static private String PAIRWISE_DOMAIN_COMPARISONS_OPTION = "pwc";
187 final static private String OUTPUT_FILE_OPTION = "o";
188 final static private String PFAM_TO_GO_FILE_USE_OPTION = "p2g";
189 final static private String GO_OBO_FILE_USE_OPTION = "obo";
190 final static private String GO_NAMESPACE_LIMIT_OPTION = "go_namespace";
191 final static private String GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION = "molecular_function";
192 final static private String GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS = "biological_process";
193 final static private String GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT = "cellular_component";
194 final static private String SECONDARY_FEATURES_PARSIMONY_MAP_FILE = "secondary";
195 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED = "simple_tab";
196 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML = "simple_html";
197 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML = "detailed_html";
198 final static private String DOMAIN_SIMILARITY_PRINT_OPTION = "ds_output";
199 private static final PRINT_OPTION DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT = DomainSimilarity.PRINT_OPTION.HTML;
200 final static private String IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION = "ignore_singlet_domains";
201 final static private String IGNORE_VIRAL_IDS = "ignore_viral_ids";
202 final static private boolean IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT = false;
203 final static private String IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION = "ignore_species_specific_domains";
204 final static private boolean IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT = false;
205 final static private String MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score.pwd";
206 final static private String MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains.pwd";
207 final static private String MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations.pwd";
208 final static private String NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score_NJ"
209 + ForesterConstants.PHYLO_XML_SUFFIX;
210 final static private String NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains_NJ"
211 + ForesterConstants.PHYLO_XML_SUFFIX;
212 final static private String NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations_NJ"
213 + ForesterConstants.PHYLO_XML_SUFFIX;
214 final static private String FILTER_POSITIVE_OPTION = "pos_filter";
215 final static private String FILTER_NEGATIVE_OPTION = "neg_filter";
216 final static private String FILTER_NEGATIVE_DOMAINS_OPTION = "neg_dom_filter";
217 final static private String INPUT_GENOMES_FILE_OPTION = "genomes";
218 final static private String INPUT_SPECIES_TREE_OPTION = "species_tree";
219 final static private String SEQ_EXTRACT_OPTION = "prot_extract";
220 final static private String PRG_VERSION = "2.503";
221 final static private String PRG_DATE = "170518";
222 final static private String E_MAIL = "phyloxml@gmail.com";
223 final static private String WWW = "https://sites.google.com/site/cmzmasek/home/software/forester/surfacing";
224 final static private boolean IGNORE_DUFS_DEFAULT = true;
225 final static private boolean IGNORE_COMBINATION_WITH_SAME_DEFAULLT = false;
226 final static private double MAX_E_VALUE_DEFAULT = -1;
227 public final static int MAX_ALLOWED_OVERLAP_DEFAULT = -1;
228 private static final String RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION = "random_seed";
229 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS = "consider_bdc_direction";
230 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY = "consider_bdc_adj";
231 public static final String SEQ_EXTRACT_SUFFIX = ".prot";
232 public static final String PLUS_MINUS_ANALYSIS_OPTION = "plus_minus";
233 public static final String PLUS_MINUS_DOM_SUFFIX = "_plus_minus_dom.txt";
234 public static final String PLUS_MINUS_DOM_SUFFIX_HTML = "_plus_minus_dom.html";
235 public static final String PLUS_MINUS_DC_SUFFIX_HTML = "_plus_minus_dc.html";
236 public static final int PLUS_MINUS_ANALYSIS_MIN_DIFF_DEFAULT = 0;
237 public static final double PLUS_MINUS_ANALYSIS_FACTOR_DEFAULT = 1.0;
238 public static final String PLUS_MINUS_ALL_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_all.txt";
239 public static final String PLUS_MINUS_PASSING_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_passing.txt";
240 private static final String OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS = "all_prot";
241 final static private String OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION = "all_prot_e";
242 public static final boolean VERBOSE = false;
243 private static final String OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_gains_counts";
244 private static final String OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_losses_counts";
245 private static final String DOMAIN_LENGTHS_ANALYSIS_SUFFIX = "_domain_lengths_analysis";
246 private static final String PERFORM_DOMAIN_LENGTH_ANALYSIS_OPTION = "dla";
247 public static final String ALL_PFAMS_ENCOUNTERED_SUFFIX = "_all_encountered_pfams";
248 public static final String ALL_PFAMS_ENCOUNTERED_WITH_GO_ANNOTATION_SUFFIX = "_all_encountered_pfams_with_go_annotation";
249 public static final String ENCOUNTERED_PFAMS_SUMMARY_SUFFIX = "_encountered_pfams_summary";
250 public static final String ALL_PFAMS_GAINED_AS_DOMAINS_SUFFIX = "_all_pfams_gained_as_domains";
251 public static final String ALL_PFAMS_LOST_AS_DOMAINS_SUFFIX = "_all_pfams_lost_as_domains";
252 public static final String ALL_PFAMS_GAINED_AS_DC_SUFFIX = "_all_pfams_gained_as_dc";
253 public static final String ALL_PFAMS_LOST_AS_DC_SUFFIX = "_all_pfams_lost_as_dc";
254 public static final String BASE_DIRECTORY_PER_NODE_DOMAIN_GAIN_LOSS_FILES = "PER_NODE_EVENTS";
255 public static final String BASE_DIRECTORY_PER_SUBTREE_DOMAIN_GAIN_LOSS_FILES = "PER_SUBTREE_EVENTS";
256 public static final String D_PROMISCUITY_FILE_SUFFIX = "_domain_promiscuities";
257 private static final String LOG_FILE_SUFFIX = "_log.txt";
258 private static final String DATA_FILE_SUFFIX = "_domain_combination_data.txt";
259 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";
260 private static final String WRITE_TO_NEXUS_OPTION = "nexus";
261 private static final String PERFORM_DC_FITCH = "dc_pars";
262 private static final INDIVIDUAL_SCORE_CUTOFF INDIVIDUAL_SCORE_CUTOFF_DEFAULT = INDIVIDUAL_SCORE_CUTOFF.FULL_SEQUENCE; //TODO look at me! change?
263 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_COUNTS_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_counts.txt";
264 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_lists.txt";
265 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_FOR_GO_MAPPING_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_lists_for_go_mapping.txt";
266 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";
267 public static final String LIMIT_SPEC_FOR_PROT_EX = null; // e.g. "HUMAN"; set to null for not using this feature (default).
268 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH_MAPPED = "_dc_MAPPED_secondary_features_fitch"
269 + ForesterConstants.PHYLO_XML_SUFFIX;
270 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_COUNTS_MAPPED_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_counts_MAPPED.txt";
271 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_MAPPED_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_lists_MAPPED.txt";
272 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";
273 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";
274 private static final boolean CALC_SIMILARITY_SCORES = false;
275 private static final String SEPARATOR_FOR_DA = "--";
277 @SuppressWarnings( "unchecked")
278 public static void main( final String args[] ) {
279 final long start_time = new Date().getTime();
280 // final StringBuffer log = new StringBuffer();
281 final StringBuilder html_desc = new StringBuilder();
282 ForesterUtil.printProgramInformation( surfacing.PRG_NAME,
283 surfacing.PRG_VERSION,
287 final String nl = ForesterUtil.LINE_SEPARATOR;
288 html_desc.append( "<table>" + nl );
289 html_desc.append( "<tr><td>Produced by:</td><td>" + surfacing.PRG_NAME + "</td></tr>" + nl );
290 html_desc.append( "<tr><td>Version:</td><td>" + surfacing.PRG_VERSION + "</td></tr>" + nl );
291 html_desc.append( "<tr><td>Release Date:</td><td>" + surfacing.PRG_DATE + "</td></tr>" + nl );
292 html_desc.append( "<tr><td>Contact:</td><td>" + surfacing.E_MAIL + "</td></tr>" + nl );
293 html_desc.append( "<tr><td>WWW:</td><td>" + surfacing.WWW + "</td></tr>" + nl );
294 CommandLineArguments cla = null;
296 cla = new CommandLineArguments( args );
298 catch ( final Exception e ) {
299 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
301 if ( cla.isOptionSet( surfacing.HELP_OPTION_1 ) || cla.isOptionSet( surfacing.HELP_OPTION_2 ) ) {
302 surfacing.printHelp();
305 if ( ( args.length < 1 ) ) {
306 surfacing.printHelp();
309 final List<String> allowed_options = new ArrayList<String>();
310 allowed_options.add( surfacing.NOT_IGNORE_DUFS_OPTION );
311 allowed_options.add( surfacing.MAX_FS_E_VALUE_OPTION );
312 allowed_options.add( surfacing.MAX_I_E_VALUE_OPTION );
313 allowed_options.add( surfacing.MIN_REL_ENV_LENGTH_RATIO_OPTION );
314 allowed_options.add( surfacing.DETAILEDNESS_OPTION );
315 allowed_options.add( surfacing.OUTPUT_FILE_OPTION );
316 allowed_options.add( surfacing.DOMAIN_SIMILARITY_SORT_OPTION );
317 allowed_options.add( surfacing.SPECIES_MATRIX_OPTION );
318 allowed_options.add( surfacing.SCORING_OPTION );
319 allowed_options.add( surfacing.MAX_ALLOWED_OVERLAP_OPTION );
320 allowed_options.add( surfacing.NO_ENGULFING_OVERLAP_OPTION );
321 allowed_options.add( surfacing.DOMAIN_COUNT_SORT_OPTION );
322 allowed_options.add( surfacing.CUTOFF_SCORE_FILE_OPTION );
323 allowed_options.add( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION );
324 allowed_options.add( surfacing.OUTPUT_DIR_OPTION );
325 allowed_options.add( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION );
326 allowed_options.add( surfacing.PFAM_TO_GO_FILE_USE_OPTION );
327 allowed_options.add( surfacing.GO_OBO_FILE_USE_OPTION );
328 allowed_options.add( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION );
329 allowed_options.add( surfacing.GO_NAMESPACE_LIMIT_OPTION );
330 allowed_options.add( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
331 allowed_options.add( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION );
332 allowed_options.add( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS );
333 allowed_options.add( INPUT_SPECIES_TREE_OPTION );
334 allowed_options.add( FILTER_POSITIVE_OPTION );
335 allowed_options.add( FILTER_NEGATIVE_OPTION );
336 allowed_options.add( INPUT_GENOMES_FILE_OPTION );
337 allowed_options.add( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
338 allowed_options.add( FILTER_NEGATIVE_DOMAINS_OPTION );
339 allowed_options.add( IGNORE_VIRAL_IDS );
340 allowed_options.add( SEQ_EXTRACT_OPTION );
341 allowed_options.add( OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION );
342 allowed_options.add( SECONDARY_FEATURES_PARSIMONY_MAP_FILE );
343 allowed_options.add( PLUS_MINUS_ANALYSIS_OPTION );
344 allowed_options.add( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS );
345 allowed_options.add( DOMAIN_COMBINITONS_COUNTS_OUTPUT_OPTION );
346 allowed_options.add( OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS );
347 allowed_options.add( CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY );
348 allowed_options.add( WRITE_TO_NEXUS_OPTION );
349 allowed_options.add( PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION );
350 allowed_options.add( DA_ANALYSIS_OPTION );
351 allowed_options.add( USE_LAST_IN_FITCH_OPTION );
352 allowed_options.add( PERFORM_DC_FITCH );
353 allowed_options.add( PERFORM_DOMAIN_LENGTH_ANALYSIS_OPTION );
354 boolean ignore_dufs = surfacing.IGNORE_DUFS_DEFAULT;
355 boolean ignore_combination_with_same = surfacing.IGNORE_COMBINATION_WITH_SAME_DEFAULLT;
356 double fs_e_value_max = surfacing.MAX_E_VALUE_DEFAULT;
357 double ie_value_max = surfacing.MAX_E_VALUE_DEFAULT;
358 double rel_env_length_ratio_cutoff = -1;
359 int max_allowed_overlap = surfacing.MAX_ALLOWED_OVERLAP_DEFAULT;
360 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
361 if ( dissallowed_options.length() > 0 ) {
362 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown option(s): " + dissallowed_options );
364 boolean use_last_in_fitch_parsimony = false;
365 if ( cla.isOptionSet( USE_LAST_IN_FITCH_OPTION ) ) {
366 use_last_in_fitch_parsimony = true;
368 boolean write_to_nexus = false;
369 if ( cla.isOptionSet( WRITE_TO_NEXUS_OPTION ) ) {
370 write_to_nexus = true;
372 boolean perform_dc_fich = false;
373 if ( cla.isOptionSet( PERFORM_DC_FITCH ) ) {
374 perform_dc_fich = true;
376 boolean perform_dc_regain_proteins_stats = false;
377 if ( cla.isOptionSet( PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION ) ) {
378 perform_dc_regain_proteins_stats = true;
380 boolean da_analysis = false;
381 if ( cla.isOptionSet( DA_ANALYSIS_OPTION ) ) {
384 boolean output_binary_domain_combinationsfor_graph_analysis = false;
385 if ( cla.isOptionSet( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS ) ) {
386 output_binary_domain_combinationsfor_graph_analysis = true;
388 boolean output_binary_domain_combinationsfor_counts = false;
389 if ( cla.isOptionSet( DOMAIN_COMBINITONS_COUNTS_OUTPUT_OPTION ) ) {
390 output_binary_domain_combinationsfor_counts = true;
392 if ( cla.isOptionSet( surfacing.MAX_FS_E_VALUE_OPTION ) ) {
394 fs_e_value_max = cla.getOptionValueAsDouble( surfacing.MAX_FS_E_VALUE_OPTION );
396 catch ( final Exception e ) {
397 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for E-value maximum" );
400 if ( cla.isOptionSet( surfacing.MIN_REL_ENV_LENGTH_RATIO_OPTION ) ) {
402 rel_env_length_ratio_cutoff = cla.getOptionValueAsDouble( surfacing.MIN_REL_ENV_LENGTH_RATIO_OPTION );
404 catch ( final Exception e ) {
405 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for min rel env length ratio" );
408 if ( cla.isOptionSet( surfacing.MAX_I_E_VALUE_OPTION ) ) {
410 ie_value_max = cla.getOptionValueAsDouble( surfacing.MAX_I_E_VALUE_OPTION );
412 catch ( final Exception e ) {
413 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for E-value maximum" );
416 if ( cla.isOptionSet( surfacing.MAX_ALLOWED_OVERLAP_OPTION ) ) {
418 max_allowed_overlap = cla.getOptionValueAsInt( surfacing.MAX_ALLOWED_OVERLAP_OPTION );
420 catch ( final Exception e ) {
421 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for maximal allowed domain overlap" );
424 boolean no_engulfing_overlaps = false;
425 if ( cla.isOptionSet( surfacing.NO_ENGULFING_OVERLAP_OPTION ) ) {
426 no_engulfing_overlaps = true;
428 boolean ignore_virus_like_ids = false;
429 if ( cla.isOptionSet( surfacing.IGNORE_VIRAL_IDS ) ) {
430 ignore_virus_like_ids = true;
432 if ( cla.isOptionSet( surfacing.NOT_IGNORE_DUFS_OPTION ) ) {
435 if ( cla.isOptionSet( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION ) ) {
436 ignore_combination_with_same = true;
438 boolean domain_length_analysis = false;
439 if ( cla.isOptionSet( surfacing.PERFORM_DOMAIN_LENGTH_ANALYSIS_OPTION ) ) {
440 domain_length_analysis = true;
442 boolean ignore_domains_without_combs_in_all_spec = IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT;
443 if ( cla.isOptionSet( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION ) ) {
444 ignore_domains_without_combs_in_all_spec = true;
446 boolean ignore_species_specific_domains = IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT;
447 if ( cla.isOptionSet( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION ) ) {
448 ignore_species_specific_domains = true;
450 if ( !cla.isOptionValueSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
451 ForesterUtil.fatalError( surfacing.PRG_NAME,
452 "no input species tree file given: " + surfacing.INPUT_SPECIES_TREE_OPTION
455 File output_file = null;
456 if ( cla.isOptionSet( surfacing.OUTPUT_FILE_OPTION ) ) {
457 if ( !cla.isOptionValueSet( surfacing.OUTPUT_FILE_OPTION ) ) {
458 ForesterUtil.fatalError( surfacing.PRG_NAME,
459 "no value for domain combinations similarities output file: -"
460 + surfacing.OUTPUT_FILE_OPTION + "=<file>" );
462 output_file = new File( cla.getOptionValue( surfacing.OUTPUT_FILE_OPTION ) );
463 SurfacingUtil.checkForOutputFileWriteability( output_file );
465 File cutoff_scores_file = null;
466 Map<String, Double> individual_score_cutoffs = null;
467 if ( cla.isOptionSet( surfacing.CUTOFF_SCORE_FILE_OPTION ) ) {
468 if ( !cla.isOptionValueSet( surfacing.CUTOFF_SCORE_FILE_OPTION ) ) {
469 ForesterUtil.fatalError( surfacing.PRG_NAME,
470 "no value for individual domain score cutoffs file: -"
471 + surfacing.CUTOFF_SCORE_FILE_OPTION + "=<file>" );
473 cutoff_scores_file = new File( cla.getOptionValue( surfacing.CUTOFF_SCORE_FILE_OPTION ) );
474 final String error = ForesterUtil.isReadableFile( cutoff_scores_file );
475 if ( !ForesterUtil.isEmpty( error ) ) {
476 ForesterUtil.fatalError( surfacing.PRG_NAME,
477 "cannot read individual domain score cutoffs file: " + error );
480 final BasicTable<String> scores_table = BasicTableParser.parse( cutoff_scores_file, ' ' );
481 individual_score_cutoffs = scores_table.getColumnsAsMapDouble( 0, 1 );
483 catch ( final IOException e ) {
484 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from individual score cutoffs file: " + e );
487 BinaryDomainCombination.DomainCombinationType dc_type = BinaryDomainCombination.DomainCombinationType.BASIC;
488 if ( cla.isOptionSet( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS ) ) {
489 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED;
491 if ( cla.isOptionSet( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY ) ) {
492 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT;
495 if ( cla.isOptionSet( surfacing.OUTPUT_DIR_OPTION ) ) {
496 if ( !cla.isOptionValueSet( surfacing.OUTPUT_DIR_OPTION ) ) {
497 ForesterUtil.fatalError( surfacing.PRG_NAME,
498 "no value for output directory: -" + surfacing.OUTPUT_DIR_OPTION + "=<dir>" );
500 out_dir = new File( cla.getOptionValue( surfacing.OUTPUT_DIR_OPTION ) );
501 if ( out_dir.exists() && ( out_dir.listFiles().length > 0 ) ) {
502 ForesterUtil.fatalError( surfacing.PRG_NAME, "\"" + out_dir + "\" aready exists and is not empty" );
504 if ( !out_dir.exists() ) {
505 final boolean success = out_dir.mkdir();
506 if ( !success || !out_dir.exists() ) {
507 ForesterUtil.fatalError( surfacing.PRG_NAME, "failed to create \"" + out_dir + "\"" );
510 if ( !out_dir.canWrite() ) {
511 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot write to \"" + out_dir + "\"" );
514 File positive_filter_file = null;
515 File negative_filter_file = null;
516 File negative_domains_filter_file = null;
517 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION )
518 && cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
519 ForesterUtil.fatalError( surfacing.PRG_NAME, "attempt to use both negative and positive protein filter" );
521 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION )
522 && ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION )
523 || cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) ) {
525 .fatalError( surfacing.PRG_NAME,
526 "attempt to use both negative or positive protein filter together wirh a negative domains filter" );
528 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) ) {
529 if ( !cla.isOptionValueSet( surfacing.FILTER_NEGATIVE_OPTION ) ) {
531 .fatalError( surfacing.PRG_NAME,
532 "no value for negative filter: -" + surfacing.FILTER_NEGATIVE_OPTION + "=<file>" );
534 negative_filter_file = new File( cla.getOptionValue( surfacing.FILTER_NEGATIVE_OPTION ) );
535 final String msg = ForesterUtil.isReadableFile( negative_filter_file );
536 if ( !ForesterUtil.isEmpty( msg ) ) {
537 ForesterUtil.fatalError( surfacing.PRG_NAME,
538 "can not read from \"" + negative_filter_file + "\": " + msg );
541 else if ( cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
542 if ( !cla.isOptionValueSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
544 .fatalError( surfacing.PRG_NAME,
545 "no value for positive filter: -" + surfacing.FILTER_POSITIVE_OPTION + "=<file>" );
547 positive_filter_file = new File( cla.getOptionValue( surfacing.FILTER_POSITIVE_OPTION ) );
548 final String msg = ForesterUtil.isReadableFile( positive_filter_file );
549 if ( !ForesterUtil.isEmpty( msg ) ) {
550 ForesterUtil.fatalError( surfacing.PRG_NAME,
551 "can not read from \"" + positive_filter_file + "\": " + msg );
554 else if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
555 if ( !cla.isOptionValueSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
556 ForesterUtil.fatalError( surfacing.PRG_NAME,
557 "no value for negative domains filter: -"
558 + surfacing.FILTER_NEGATIVE_DOMAINS_OPTION + "=<file>" );
560 negative_domains_filter_file = new File( cla.getOptionValue( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) );
561 final String msg = ForesterUtil.isReadableFile( negative_domains_filter_file );
562 if ( !ForesterUtil.isEmpty( msg ) ) {
563 ForesterUtil.fatalError( surfacing.PRG_NAME,
564 "can not read from \"" + negative_domains_filter_file + "\": " + msg );
567 final List<String> plus_minus_analysis_high_copy_base_species = new ArrayList<String>();
568 final List<String> plus_minus_analysis_high_copy_target_species = new ArrayList<String>();
569 final List<String> plus_minus_analysis_high_low_copy_species = new ArrayList<String>();
570 final List<Object> plus_minus_analysis_numbers = new ArrayList<Object>();
571 SurfacingUtil.processPlusMinusAnalysisOption( cla,
572 plus_minus_analysis_high_copy_base_species,
573 plus_minus_analysis_high_copy_target_species,
574 plus_minus_analysis_high_low_copy_species,
575 plus_minus_analysis_numbers );
576 File input_genomes_file = null;
577 if ( cla.isOptionSet( surfacing.INPUT_GENOMES_FILE_OPTION ) ) {
578 if ( !cla.isOptionValueSet( surfacing.INPUT_GENOMES_FILE_OPTION ) ) {
579 ForesterUtil.fatalError( surfacing.PRG_NAME,
580 "no value for input genomes file: -" + surfacing.INPUT_GENOMES_FILE_OPTION
583 input_genomes_file = new File( cla.getOptionValue( surfacing.INPUT_GENOMES_FILE_OPTION ) );
584 final String msg = ForesterUtil.isReadableFile( input_genomes_file );
585 if ( !ForesterUtil.isEmpty( msg ) ) {
586 ForesterUtil.fatalError( surfacing.PRG_NAME,
587 "can not read from \"" + input_genomes_file + "\": " + msg );
592 .fatalError( surfacing.PRG_NAME,
593 "no input genomes file given: " + surfacing.INPUT_GENOMES_FILE_OPTION + "=<file>" );
595 DomainSimilarity.DomainSimilarityScoring scoring = SCORING_DEFAULT;
596 if ( cla.isOptionSet( surfacing.SCORING_OPTION ) ) {
597 if ( !cla.isOptionValueSet( surfacing.SCORING_OPTION ) ) {
599 .fatalError( surfacing.PRG_NAME,
600 "no value for scoring method for domain combinations similarity calculation: -"
601 + surfacing.SCORING_OPTION + "=<" + surfacing.SCORING_DOMAIN_COUNT_BASED
602 + "|" + surfacing.SCORING_PROTEIN_COUNT_BASED + "|"
603 + surfacing.SCORING_COMBINATION_BASED + ">\"" );
605 final String scoring_str = cla.getOptionValue( surfacing.SCORING_OPTION );
606 if ( scoring_str.equals( surfacing.SCORING_DOMAIN_COUNT_BASED ) ) {
607 scoring = DomainSimilarity.DomainSimilarityScoring.DOMAINS;
609 else if ( scoring_str.equals( surfacing.SCORING_COMBINATION_BASED ) ) {
610 scoring = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
612 else if ( scoring_str.equals( surfacing.SCORING_PROTEIN_COUNT_BASED ) ) {
613 scoring = DomainSimilarity.DomainSimilarityScoring.PROTEINS;
617 .fatalError( surfacing.PRG_NAME,
618 "unknown value \"" + scoring_str
619 + "\" for scoring method for domain combinations similarity calculation: \"-"
620 + surfacing.SCORING_OPTION + "=<" + surfacing.SCORING_DOMAIN_COUNT_BASED
621 + "|" + surfacing.SCORING_PROTEIN_COUNT_BASED + "|"
622 + surfacing.SCORING_COMBINATION_BASED + ">\"" );
625 boolean sort_by_species_count_first = false;
626 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION ) ) {
627 sort_by_species_count_first = true;
629 boolean species_matrix = false;
630 if ( cla.isOptionSet( surfacing.SPECIES_MATRIX_OPTION ) ) {
631 species_matrix = true;
633 boolean output_protein_lists_for_all_domains = false;
634 double output_list_of_all_proteins_per_domain_e_value_max = -1;
635 if ( cla.isOptionSet( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS ) ) {
636 output_protein_lists_for_all_domains = true;
637 if ( cla.isOptionSet( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION ) ) {
639 output_list_of_all_proteins_per_domain_e_value_max = cla
640 .getOptionValueAsDouble( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION );
642 catch ( final Exception e ) {
643 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for per domain E-value maximum" );
647 Detailedness detailedness = DETAILEDNESS_DEFAULT;
648 if ( cla.isOptionSet( surfacing.DETAILEDNESS_OPTION ) ) {
649 if ( !cla.isOptionValueSet( surfacing.DETAILEDNESS_OPTION ) ) {
650 ForesterUtil.fatalError( surfacing.PRG_NAME,
651 "no value for -" + surfacing.DETAILEDNESS_OPTION + "=<"
652 + surfacing.DETAILEDNESS_BASIC + "|" + surfacing.DETAILEDNESS_LIST_IDS
653 + "|" + surfacing.DETAILEDNESS_PUNCTILIOUS + ">\"" );
655 final String detness = cla.getOptionValue( surfacing.DETAILEDNESS_OPTION ).toLowerCase();
656 if ( detness.equals( surfacing.DETAILEDNESS_BASIC ) ) {
657 detailedness = DomainSimilarityCalculator.Detailedness.BASIC;
659 else if ( detness.equals( surfacing.DETAILEDNESS_LIST_IDS ) ) {
660 detailedness = DomainSimilarityCalculator.Detailedness.LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES;
662 else if ( detness.equals( surfacing.DETAILEDNESS_PUNCTILIOUS ) ) {
663 detailedness = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
666 ForesterUtil.fatalError( surfacing.PRG_NAME,
667 "unknown value \"" + detness + "\" for detailedness: \"-"
668 + surfacing.DETAILEDNESS_OPTION + "=<" + surfacing.DETAILEDNESS_BASIC
669 + "|" + surfacing.DETAILEDNESS_LIST_IDS + "|"
670 + surfacing.DETAILEDNESS_PUNCTILIOUS + ">\"" );
673 String automated_pairwise_comparison_suffix = null;
674 boolean perform_pwc = false;
675 boolean write_pwc_files = false;
676 if ( cla.isOptionSet( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
678 if ( !cla.isOptionValueSet( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
679 write_pwc_files = false;
682 write_pwc_files = true;
683 automated_pairwise_comparison_suffix = "_"
684 + cla.getOptionValue( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
687 String query_domain_ids = null;
688 if ( cla.isOptionSet( surfacing.SEQ_EXTRACT_OPTION ) ) {
689 if ( !cla.isOptionValueSet( surfacing.SEQ_EXTRACT_OPTION ) ) {
691 .fatalError( surfacing.PRG_NAME,
692 "no domain ids given for sequences with given domains to be extracted : -"
693 + surfacing.SEQ_EXTRACT_OPTION
694 + "=<ordered domain sequences, domain ids separated by '~', sequences separated by '#'>" );
696 query_domain_ids = cla.getOptionValue( surfacing.SEQ_EXTRACT_OPTION );
698 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field = DOMAIN_SORT_FILD_DEFAULT;
699 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field_for_automated_pwc = DOMAIN_SORT_FILD_DEFAULT;
700 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
701 if ( !cla.isOptionValueSet( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
702 ForesterUtil.fatalError( surfacing.PRG_NAME,
703 "no value for domain combinations similarities sorting: -"
704 + surfacing.DOMAIN_SIMILARITY_SORT_OPTION + "=<"
705 + surfacing.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
706 + surfacing.DOMAIN_SIMILARITY_SORT_MAX + "|"
707 + surfacing.DOMAIN_SIMILARITY_SORT_MIN + "|"
708 + surfacing.DOMAIN_SIMILARITY_SORT_MEAN + "|"
709 + surfacing.DOMAIN_SIMILARITY_SORT_DIFF + "|"
710 + surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
711 + surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|"
712 + surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|"
713 + surfacing.DOMAIN_SIMILARITY_SORT_SD + ">\"" );
715 final String sort_str = cla.getOptionValue( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ).toLowerCase();
716 if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_ALPHA ) ) {
717 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
718 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
720 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MAX ) ) {
721 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX;
722 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
724 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MIN ) ) {
725 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MIN;
726 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
728 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MEAN ) ) {
729 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MEAN;
730 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MEAN;
732 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT ) ) {
733 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SPECIES_COUNT;
734 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
736 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_SD ) ) {
737 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SD;
738 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
740 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_DIFF ) ) {
741 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
742 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
744 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF ) ) {
745 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
746 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
748 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF ) ) {
749 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
750 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
753 ForesterUtil.fatalError( surfacing.PRG_NAME,
754 "unknown value \"" + sort_str
755 + "\" for domain combinations similarities sorting: \"-"
756 + surfacing.DOMAIN_SIMILARITY_SORT_OPTION + "=<"
757 + surfacing.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
758 + surfacing.DOMAIN_SIMILARITY_SORT_MAX + "|"
759 + surfacing.DOMAIN_SIMILARITY_SORT_MIN + "|"
760 + surfacing.DOMAIN_SIMILARITY_SORT_MEAN + "|"
761 + surfacing.DOMAIN_SIMILARITY_SORT_DIFF + "|"
762 + surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
763 + surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|" + "|"
764 + surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|"
765 + surfacing.DOMAIN_SIMILARITY_SORT_SD + ">\"" );
768 DomainSimilarity.PRINT_OPTION domain_similarity_print_option = DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT;
769 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
770 if ( !cla.isOptionValueSet( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
772 .fatalError( surfacing.PRG_NAME,
773 "no value for print option: -"
774 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
775 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
776 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
778 final String sort = cla.getOptionValue( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ).toLowerCase();
779 if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML ) ) {
780 domain_similarity_print_option = DomainSimilarity.PRINT_OPTION.HTML;
782 else if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML ) ) {
783 ForesterUtil.fatalError( surfacing.PRG_NAME, "simple HTML output not implemented yet :(" );
785 else if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED ) ) {
786 domain_similarity_print_option = DomainSimilarity.PRINT_OPTION.SIMPLE_TAB_DELIMITED;
790 .fatalError( surfacing.PRG_NAME,
791 "unknown value \"" + sort + "\" for print option: -"
792 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
793 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
794 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
797 GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder dc_sort_order = DOMAINS_SORT_ORDER_DEFAULT;
798 if ( cla.isOptionSet( surfacing.DOMAIN_COUNT_SORT_OPTION ) ) {
799 if ( !cla.isOptionValueSet( surfacing.DOMAIN_COUNT_SORT_OPTION ) ) {
800 ForesterUtil.fatalError( surfacing.PRG_NAME,
801 "no value for sorting of domain counts: -" + surfacing.DOMAIN_COUNT_SORT_OPTION
802 + "=<" + surfacing.DOMAIN_COUNT_SORT_ALPHA + "|"
803 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
804 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
805 + surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
807 final String sort = cla.getOptionValue( surfacing.DOMAIN_COUNT_SORT_OPTION ).toLowerCase();
808 if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_ALPHA ) ) {
809 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
811 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT ) ) {
812 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_COUNT;
814 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT ) ) {
815 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_PROTEINS_COUNT;
817 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT ) ) {
818 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.COMBINATIONS_COUNT;
821 ForesterUtil.fatalError( surfacing.PRG_NAME,
822 "unknown value \"" + sort + "\" for sorting of domain counts: \"-"
823 + surfacing.DOMAIN_COUNT_SORT_OPTION + "=<"
824 + surfacing.DOMAIN_COUNT_SORT_ALPHA + "|"
825 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
826 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
827 + surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
830 final String[][] input_file_properties = SurfacingUtil.processInputGenomesFile( input_genomes_file );
831 final int number_of_genomes = input_file_properties.length;
832 if ( number_of_genomes < 2 ) {
833 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot analyze less than two files" );
835 if ( ( number_of_genomes < 3 ) && perform_pwc ) {
837 .fatalError( surfacing.PRG_NAME,
838 "cannot use : -" + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
839 + "=<suffix> to turn on pairwise analyses with less than three input files" );
841 SurfacingUtil.checkWriteabilityForPairwiseComparisons( domain_similarity_print_option,
842 input_file_properties,
843 automated_pairwise_comparison_suffix,
845 for( int i = 0; i < number_of_genomes; i++ ) {
846 File dcc_outfile = new File( input_file_properties[ i ][ 1 ]
847 + surfacing.DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX );
848 if ( out_dir != null ) {
849 dcc_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + dcc_outfile );
851 SurfacingUtil.checkForOutputFileWriteability( dcc_outfile );
853 File pfam_to_go_file = new File( "pfam2go.txt" );
854 if ( cla.isOptionSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
855 if ( !cla.isOptionValueSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
856 ForesterUtil.fatalError( surfacing.PRG_NAME,
857 "no value for Pfam to GO mapping file: -"
858 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>" );
860 pfam_to_go_file = new File( cla.getOptionValue( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) );
862 final String error1 = ForesterUtil.isReadableFile( pfam_to_go_file );
863 if ( !ForesterUtil.isEmpty( error1 ) ) {
864 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read Pfam to GO mapping file: " + error1 );
866 Map<String, List<GoId>> domain_id_to_go_ids_map = null;
867 int domain_id_to_go_ids_count = 0;
869 final PfamToGoParser parser = new PfamToGoParser( pfam_to_go_file );
870 final List<PfamToGoMapping> pfam_to_go_mappings = parser.parse();
871 domain_id_to_go_ids_map = SurfacingUtil.createDomainIdToGoIdMap( pfam_to_go_mappings );
872 if ( parser.getMappingCount() < domain_id_to_go_ids_map.size() ) {
873 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME,
874 "parser.getMappingCount() < domain_id_to_go_ids_map.size()" );
876 domain_id_to_go_ids_count = parser.getMappingCount();
878 catch ( final IOException e ) {
879 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from Pfam to GO mapping file: " + e );
881 File go_obo_file = new File( "go.obo" );
882 if ( cla.isOptionSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
883 if ( !cla.isOptionValueSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
884 ForesterUtil.fatalError( surfacing.PRG_NAME,
885 "no value for GO OBO file: -" + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>" );
887 go_obo_file = new File( cla.getOptionValue( surfacing.GO_OBO_FILE_USE_OPTION ) );
889 final String error2 = ForesterUtil.isReadableFile( go_obo_file );
890 if ( !ForesterUtil.isEmpty( error2 ) ) {
891 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read GO OBO file: " + error2 );
893 List<GoTerm> go_terms = null;
895 final OBOparser parser = new OBOparser( go_obo_file, OBOparser.ReturnType.BASIC_GO_TERM );
896 go_terms = parser.parse();
897 if ( parser.getGoTermCount() != go_terms.size() ) {
898 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "parser.getGoTermCount() != go_terms.size()" );
901 catch ( final IOException e ) {
902 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from GO OBO file: " + e );
904 Map<GoId, GoTerm> go_id_to_term_map = null;
905 if ( ( ( domain_id_to_go_ids_map != null ) && ( domain_id_to_go_ids_map.size() > 0 ) )
906 && ( ( go_terms != null ) && ( go_terms.size() > 0 ) ) ) {
907 go_id_to_term_map = GoUtils.createGoIdToGoTermMap( go_terms );
909 GoNameSpace go_namespace_limit = null;
910 if ( cla.isOptionSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
911 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
912 ForesterUtil.fatalError( surfacing.PRG_NAME,
913 "cannot use GO namespace limit (-" + surfacing.GO_NAMESPACE_LIMIT_OPTION
914 + "=<namespace>) without Pfam to GO mapping file ("
915 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>) and GO OBO file (-"
916 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
918 if ( !cla.isOptionValueSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
919 ForesterUtil.fatalError( surfacing.PRG_NAME,
920 "no value for GO namespace limit: \"-" + surfacing.GO_NAMESPACE_LIMIT_OPTION
921 + "=<" + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
922 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
923 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
925 final String go_namespace_limit_str = cla.getOptionValue( surfacing.GO_NAMESPACE_LIMIT_OPTION )
927 if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION ) ) {
928 go_namespace_limit = GoNameSpace.createMolecularFunction();
930 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS ) ) {
931 go_namespace_limit = GoNameSpace.createBiologicalProcess();
933 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT ) ) {
934 go_namespace_limit = GoNameSpace.createCellularComponent();
937 ForesterUtil.fatalError( surfacing.PRG_NAME,
938 "unknown value \"" + go_namespace_limit_str + "\" for GO namespace limit: \"-"
939 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
940 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
941 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
942 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
945 if ( ( domain_similarity_sort_field == DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE )
946 && ( number_of_genomes > 2 ) ) {
947 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
949 File[] intree_files = null;
950 Phylogeny[] intrees = null;
951 if ( cla.isOptionSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
952 if ( number_of_genomes < 3 ) {
953 ForesterUtil.fatalError( surfacing.PRG_NAME,
954 "cannot infer gains and losses on input species trees (-"
955 + surfacing.INPUT_SPECIES_TREE_OPTION + " without pairwise analyses ("
956 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
957 + "=<suffix for pairwise comparison output files>)" );
959 if ( !cla.isOptionValueSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
960 ForesterUtil.fatalError( surfacing.PRG_NAME,
961 "no value for input tree: -" + surfacing.INPUT_SPECIES_TREE_OPTION
962 + "=<tree file in phyloXML format>" );
964 final String intrees_str = cla.getOptionValue( surfacing.INPUT_SPECIES_TREE_OPTION );
965 if ( intrees_str.indexOf( "#" ) > 0 ) {
966 final String[] intrees_strs = intrees_str.split( "#" );
967 intree_files = new File[ intrees_strs.length ];
969 for( final String s : intrees_strs ) {
970 intree_files[ i++ ] = new File( s.trim() );
974 intree_files = new File[ 1 ];
975 intree_files[ 0 ] = new File( intrees_str );
977 intrees = SurfacingUtil.obtainAndPreProcessIntrees( intree_files,
979 input_file_properties );
981 final Phylogeny intree_0_orig = SurfacingUtil.obtainFirstIntree( intree_files[ 0 ] );
982 long random_number_seed_for_fitch_parsimony = 0l;
983 boolean radomize_fitch_parsimony = false;
984 if ( cla.isOptionSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
985 if ( !cla.isOptionValueSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
986 ForesterUtil.fatalError( surfacing.PRG_NAME,
987 "no value for random number seed: -"
988 + surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION + "=<seed>" );
991 random_number_seed_for_fitch_parsimony = cla
992 .getOptionValueAsLong( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
994 catch ( final IOException e ) {
995 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
997 radomize_fitch_parsimony = true;
999 SortedSet<String> filter = null;
1000 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1001 || ( negative_domains_filter_file != null ) ) {
1002 filter = new TreeSet<String>();
1003 if ( positive_filter_file != null ) {
1004 SurfacingUtil.processFilter( positive_filter_file, filter );
1006 else if ( negative_filter_file != null ) {
1007 SurfacingUtil.processFilter( negative_filter_file, filter );
1009 else if ( negative_domains_filter_file != null ) {
1010 SurfacingUtil.processFilter( negative_domains_filter_file, filter );
1013 Map<String, Set<String>>[] domain_id_to_secondary_features_maps = null;
1014 File[] secondary_features_map_files = null;
1015 final File domain_lengths_analysis_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1016 + DOMAIN_LENGTHS_ANALYSIS_SUFFIX );
1017 if ( domain_length_analysis ) {
1018 SurfacingUtil.checkForOutputFileWriteability( domain_lengths_analysis_outfile );
1020 if ( cla.isOptionSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
1021 if ( !cla.isOptionValueSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
1022 ForesterUtil.fatalError( surfacing.PRG_NAME,
1023 "no value for secondary features map file: -"
1024 + surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE + "=<file>" );
1026 final String[] secondary_features_map_files_strs = cla
1027 .getOptionValue( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ).split( "#" );
1028 secondary_features_map_files = new File[ secondary_features_map_files_strs.length ];
1029 domain_id_to_secondary_features_maps = new Map[ secondary_features_map_files_strs.length ];
1031 for( final String secondary_features_map_files_str : secondary_features_map_files_strs ) {
1032 secondary_features_map_files[ i ] = new File( secondary_features_map_files_str );
1033 final String error = ForesterUtil.isReadableFile( secondary_features_map_files[ i ] );
1034 if ( !ForesterUtil.isEmpty( error ) ) {
1035 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read secondary features map file: " + error );
1038 domain_id_to_secondary_features_maps[ i ] = SurfacingUtil
1039 .createDomainIdToSecondaryFeaturesMap( secondary_features_map_files[ i ] );
1041 catch ( final IOException e ) {
1042 ForesterUtil.fatalError( surfacing.PRG_NAME,
1043 "cannot read secondary features map file: " + e.getMessage() );
1045 catch ( final Exception e ) {
1046 ForesterUtil.fatalError( surfacing.PRG_NAME,
1047 "problem with contents of features map file ["
1048 + secondary_features_map_files[ i ] + "]: " + e.getMessage() );
1053 if ( out_dir == null ) {
1054 ForesterUtil.fatalError( surfacing.PRG_NAME,
1055 "no output directory indicated (-" + surfacing.OUTPUT_DIR_OPTION + "=<dir>)" );
1057 if ( output_file == null ) {
1058 ForesterUtil.fatalError( surfacing.PRG_NAME,
1059 "no name for (main) output file indicated (-" + surfacing.OUTPUT_FILE_OPTION
1062 if ( ( domain_id_to_go_ids_map == null ) || domain_id_to_go_ids_map.isEmpty() ) {
1063 ForesterUtil.fatalError( surfacing.PRG_NAME,
1064 "no (acceptable) Pfam to GO id mapping file provided ('pfam2go file') (-"
1065 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1067 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1068 ForesterUtil.fatalError( surfacing.PRG_NAME,
1069 "no (acceptable) go id to term mapping file provided ('GO OBO file') (-"
1070 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1072 System.out.println( "Output directory : " + out_dir );
1073 System.out.println( "Input genomes from : " + input_genomes_file );
1074 html_desc.append( "<tr><td>Input genomes from:</td><td>" + input_genomes_file + "</td></tr>" + nl );
1075 if ( positive_filter_file != null ) {
1076 final int filter_size = filter.size();
1077 System.out.println( "Positive protein filter : " + positive_filter_file + " [" + filter_size
1079 html_desc.append( "<tr><td>Positive protein filter:</td><td>" + positive_filter_file + " [" + filter_size
1080 + " domain ids]</td></tr>" + nl );
1082 if ( negative_filter_file != null ) {
1083 final int filter_size = filter.size();
1084 System.out.println( "Negative protein filter : " + negative_filter_file + " [" + filter_size
1086 html_desc.append( "<tr><td>Negative protein filter:</td><td>" + negative_filter_file + " [" + filter_size
1087 + " domain ids]</td></tr>" + nl );
1089 if ( negative_domains_filter_file != null ) {
1090 final int filter_size = filter.size();
1091 System.out.println( "Negative domain filter : " + negative_domains_filter_file + " [" + filter_size
1093 html_desc.append( "<tr><td>Negative domain filter:</td><td>" + negative_domains_filter_file + " ["
1094 + filter_size + " domain ids]</td></tr>" + nl );
1096 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
1098 for( final String s : plus_minus_analysis_high_copy_base_species ) {
1099 plus0 += "+" + s + " ";
1102 for( final String s : plus_minus_analysis_high_copy_target_species ) {
1103 plus1 += "*" + s + " ";
1106 for( final String s : plus_minus_analysis_high_low_copy_species ) {
1107 minus += "-" + s + " ";
1109 System.out.println( "Plus-minus analysis : " + plus1 + "&& " + plus0 + "&& " + minus );
1110 html_desc.append( "<tr><td>Plus-minus analysis:</td><td>" + plus1 + "&& " + plus0 + "&& " + minus
1111 + "</td></tr>" + nl );
1113 if ( cutoff_scores_file != null ) {
1114 System.out.println( "Cutoff scores file : " + cutoff_scores_file );
1115 html_desc.append( "<tr><td>Cutoff scores file:</td><td>" + cutoff_scores_file + "</td></tr>" + nl );
1117 if ( ie_value_max >= 0.0 ) {
1118 System.out.println( "iE-value maximum (incl) : " + ie_value_max );
1119 html_desc.append( "<tr><td>iE-value maximum (inclusive):</td><td>" + ie_value_max + "</td></tr>" + nl );
1121 if ( rel_env_length_ratio_cutoff > 0.0 ) {
1122 System.out.println( "Rel env length ratio min : " + rel_env_length_ratio_cutoff );
1123 html_desc.append( "<tr><td>Relative hmm envelope length ratio min (inclusive):</td><td>"
1124 + rel_env_length_ratio_cutoff + "</td></tr>" + nl );
1126 if ( fs_e_value_max >= 0.0 ) {
1127 System.out.println( "FS E-value maximum (incl) : " + fs_e_value_max );
1128 html_desc.append( "<tr><td>FS E-value maximum (inclusive):</td><td>" + fs_e_value_max + "</td></tr>" + nl );
1130 if ( output_protein_lists_for_all_domains ) {
1131 System.out.println( "Domain E-value max : " + output_list_of_all_proteins_per_domain_e_value_max );
1132 html_desc.append( "<tr><td>Protein lists: E-value maximum per domain (inclusive):</td><td>"
1133 + output_list_of_all_proteins_per_domain_e_value_max + "</td></tr>" + nl );
1135 System.out.println( "Ignore DUFs : " + ignore_dufs );
1136 if ( ignore_virus_like_ids ) {
1137 System.out.println( "Ignore virus like ids : " + ignore_virus_like_ids );
1138 html_desc.append( "<tr><td>Ignore virus, phage, transposition related ids:</td><td>" + ignore_virus_like_ids
1139 + "</td></tr>" + nl );
1141 html_desc.append( "<tr><td>Ignore DUFs:</td><td>" + ignore_dufs + "</td></tr>" + nl );
1142 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1143 System.out.println( "Max allowed domain overlap : " + max_allowed_overlap );
1145 .append( "<tr><td>Max allowed domain overlap:</td><td>" + max_allowed_overlap + "</td></tr>" + nl );
1147 if ( no_engulfing_overlaps ) {
1148 System.out.println( "Ignore engulfed domains : " + no_engulfing_overlaps );
1149 html_desc.append( "<tr><td>Ignore (lower confidence) engulfed domains:</td><td>" + no_engulfing_overlaps
1150 + "</td></tr>" + nl );
1152 System.out.println( "Ignore singlet domains : " + ignore_domains_without_combs_in_all_spec );
1154 .append( "<tr><td>Ignore singlet domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1155 + ignore_domains_without_combs_in_all_spec + "</td></tr>" + nl );
1156 System.out.println( "Ignore species specific doms: " + ignore_species_specific_domains );
1158 .append( "<tr><td>Ignore species specific domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1159 + ignore_species_specific_domains + "</td></tr>" + nl );
1160 System.out.println( "Ignore combination with self: " + ignore_combination_with_same );
1161 html_desc.append( "<tr><td>Ignore combination with self for domain combination similarity analyses:</td><td>"
1162 + ignore_combination_with_same + "</td></tr>" + nl );
1163 System.out.println( "Consider directedness : "
1164 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) );
1165 html_desc.append( "<tr><td>Consider directedness of binary domain combinations:</td><td>"
1166 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) + "</td></tr>" + nl );
1167 if ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) {
1168 System.out.println( "Consider adjacency : "
1169 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) );
1170 html_desc.append( "<tr><td>Consider djacency of binary domain combinations:</td><td>"
1171 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) + "</td></tr>"
1174 System.out.println( "Fitch parsimony of DCs : " + perform_dc_fich );
1175 html_desc.append( "<tr><td>Fitch parsimony of DCs:</td><td>" + perform_dc_fich + "</td></tr>" + nl );
1176 if ( perform_dc_fich ) {
1177 System.out.println( "Use last in Fitch parsimony : " + use_last_in_fitch_parsimony );
1178 html_desc.append( "<tr><td>Use last in Fitch parsimony:</td><td>" + use_last_in_fitch_parsimony
1179 + "</td></tr>" + nl );
1181 System.out.println( "Write to Nexus files : " + write_to_nexus );
1182 html_desc.append( "<tr><td>Write to Nexus files:</td><td>" + write_to_nexus + "</td></tr>" + nl );
1183 if ( perform_dc_fich ) {
1184 System.out.println( "DC regain prot stats : " + perform_dc_regain_proteins_stats );
1185 html_desc.append( "<tr><td>DC regain prot stats:</td><td>" + perform_dc_regain_proteins_stats + "</td></tr>"
1188 System.out.println( "DA analysis : " + da_analysis );
1189 html_desc.append( "<tr><td>DA analysis :</td><td>" + da_analysis + "</td></tr>" + nl );
1190 System.out.print( "Domain counts sort order : " );
1191 html_desc.append( "<tr><td>Domain counts sort order:</td><td>" );
1192 switch ( dc_sort_order ) {
1193 case ALPHABETICAL_KEY_ID:
1194 System.out.println( "alphabetical" );
1195 html_desc.append( "alphabetical" + "</td></tr>" + nl );
1197 case KEY_DOMAIN_COUNT:
1198 System.out.println( "domain count" );
1199 html_desc.append( "domain count" + "</td></tr>" + nl );
1201 case KEY_DOMAIN_PROTEINS_COUNT:
1202 System.out.println( "domain proteins count" );
1203 html_desc.append( "domain proteins count" + "</td></tr>" + nl );
1205 case COMBINATIONS_COUNT:
1206 System.out.println( "domain combinations count" );
1207 html_desc.append( "domain combinations count" + "</td></tr>" + nl );
1210 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for dc sort order" );
1212 if ( domain_id_to_go_ids_map != null ) {
1213 System.out.println( "Pfam to GO mappings from : " + pfam_to_go_file + " [" + domain_id_to_go_ids_count
1215 html_desc.append( "<tr><td>Pfam to GO mappings from:</td><td>" + pfam_to_go_file + " ["
1216 + domain_id_to_go_ids_count + " mappings]" + "</td></tr>" + nl );
1218 if ( go_terms != null ) {
1219 System.out.println( "GO terms from : " + go_obo_file + " [" + go_terms.size() + " terms]" );
1220 html_desc.append( "<tr><td>GO terms from:</td><td>" + go_obo_file + " [" + go_terms.size() + " terms]"
1221 + "</td></tr>" + nl );
1223 if ( go_namespace_limit != null ) {
1224 System.out.println( "Limit GO terms to : " + go_namespace_limit.toString() );
1225 html_desc.append( "<tr><td>Limit GO terms to</td><td>" + go_namespace_limit + "</td></tr>" + nl );
1227 if ( perform_pwc ) {
1228 System.out.println( "Suffix for PWC files : " + automated_pairwise_comparison_suffix );
1229 html_desc.append( "<tr><td>Suffix for PWC files</td><td>" + automated_pairwise_comparison_suffix
1230 + "</td></tr>" + nl );
1232 if ( out_dir != null ) {
1233 System.out.println( "Output directory : " + out_dir );
1235 if ( query_domain_ids != null ) {
1236 System.out.println( "Query domains (ordered) : " + query_domain_ids );
1237 html_desc.append( "<tr><td></td><td>" + query_domain_ids + "</td></tr>" + nl );
1239 System.out.println( "Write similarities to : " + output_file );
1240 System.out.print( " Scoring method : " );
1241 html_desc.append( "<tr><td>Scoring method:</td><td>" );
1242 switch ( scoring ) {
1244 System.out.println( "domain combinations based" );
1245 html_desc.append( "domain combinations based" + "</td></tr>" + nl );
1248 System.out.println( "domain counts based" );
1249 html_desc.append( "domain counts based" + "</td></tr>" + nl );
1252 System.out.println( "domain proteins counts based" );
1253 html_desc.append( "domain proteins counts based" + "</td></tr>" + nl );
1256 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1258 System.out.print( " Sort by : " );
1259 html_desc.append( "<tr><td>Sort by:</td><td>" );
1260 switch ( domain_similarity_sort_field ) {
1262 System.out.print( "score minimum" );
1263 html_desc.append( "score minimum" );
1266 System.out.print( "score maximum" );
1267 html_desc.append( "score maximum" );
1270 System.out.print( "score mean" );
1271 html_desc.append( "score mean" );
1274 System.out.print( "score standard deviation" );
1275 html_desc.append( "score standard deviation" );
1278 System.out.print( "species number" );
1279 html_desc.append( "species number" );
1282 System.out.print( "alphabetical domain identifier" );
1283 html_desc.append( "alphabetical domain identifier" );
1285 case MAX_DIFFERENCE:
1286 System.out.print( "(maximal) difference" );
1287 html_desc.append( "(maximal) difference" );
1289 case ABS_MAX_COUNTS_DIFFERENCE:
1290 System.out.print( "absolute (maximal) counts difference" );
1291 html_desc.append( "absolute (maximal) counts difference" );
1293 case MAX_COUNTS_DIFFERENCE:
1294 System.out.print( "(maximal) counts difference" );
1295 html_desc.append( "(maximal) counts difference" );
1298 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1300 if ( sort_by_species_count_first ) {
1301 System.out.println( " (sort by species count first)" );
1302 html_desc.append( " (sort by species count first)" );
1305 System.out.println();
1307 html_desc.append( "</td></tr>" + nl );
1308 System.out.print( " Detailedness : " );
1309 switch ( detailedness ) {
1311 System.out.println( "basic" );
1313 case LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES:
1314 System.out.println( "list combining domains for each species" );
1317 System.out.println( "punctilious" );
1320 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for detailedness" );
1322 System.out.print( " Print option : " );
1323 switch ( domain_similarity_print_option ) {
1325 System.out.println( "HTML" );
1327 case SIMPLE_TAB_DELIMITED:
1328 System.out.println( "simple tab delimited" );
1331 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for print option" );
1333 System.out.print( " Species matrix : " + species_matrix );
1334 System.out.println();
1335 final File dc_data_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + DATA_FILE_SUFFIX );
1336 System.out.println( "Domain comb data output : " + dc_data_file );
1337 html_desc.append( "<tr><td>Domain combination data output:</td><td> " + dc_data_file + " </td></tr>" );
1338 System.out.println();
1339 if ( perform_pwc ) {
1340 System.out.println( "Pairwise comparisons: " );
1341 html_desc.append( "<tr><td>Pairwise comparisons:</td><td></td></tr>" );
1342 System.out.print( " Sort by : " );
1343 html_desc.append( "<tr><td>Sort by:</td><td>" );
1344 switch ( domain_similarity_sort_field_for_automated_pwc ) {
1346 System.out.print( "score mean" );
1347 html_desc.append( "score mean" );
1350 System.out.print( "alphabetical domain identifier" );
1351 html_desc.append( "alphabetical domain identifier" );
1353 case MAX_DIFFERENCE:
1354 System.out.print( "difference" );
1355 html_desc.append( "difference" );
1357 case ABS_MAX_COUNTS_DIFFERENCE:
1358 System.out.print( "absolute counts difference" );
1359 html_desc.append( "absolute counts difference" );
1361 case MAX_COUNTS_DIFFERENCE:
1362 System.out.print( "counts difference" );
1363 html_desc.append( "counts difference" );
1366 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME,
1367 "unknown value for sorting for similarities" );
1369 System.out.println();
1370 html_desc.append( "</td></tr>" + nl );
1371 if ( ( intrees != null ) && ( intrees.length > 0 ) ) {
1372 for( final File intree_file : intree_files ) {
1373 html_desc.append( "<tr><td>Intree for gain/loss parsimony analysis:</td><td>" + intree_file
1374 + "</td></tr>" + nl );
1375 System.out.println( " Intree for gain/loss pars.: " + intree_file );
1378 if ( radomize_fitch_parsimony ) {
1379 html_desc.append( "<tr><td> Random number seed for Fitch parsimony analysis:</td><td>"
1380 + random_number_seed_for_fitch_parsimony + "</td></tr>" + nl );
1381 System.out.println( " Random number seed : " + random_number_seed_for_fitch_parsimony );
1383 if ( ( domain_id_to_secondary_features_maps != null )
1384 && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
1385 for( int i = 0; i < secondary_features_map_files.length; i++ ) {
1386 html_desc.append( "<tr><td>Secondary features map file:</td><td>"
1387 + secondary_features_map_files[ i ] + "</td></tr>" + nl );
1388 System.out.println( "Secondary features map file : " + secondary_features_map_files[ i ]
1389 + " [mappings for " + domain_id_to_secondary_features_maps[ i ].size() + " domain ids]" );
1391 System.out.println();
1392 System.out.println( "Domain ids to secondary features map:" );
1393 for( final String domain_id : domain_id_to_secondary_features_maps[ i ].keySet() ) {
1394 System.out.print( domain_id );
1395 System.out.print( " => " );
1396 for( final String sec : domain_id_to_secondary_features_maps[ i ].get( domain_id ) ) {
1397 System.out.print( sec );
1398 System.out.print( " " );
1400 System.out.println();
1405 } // if ( perform_pwc ) {
1406 System.out.println();
1407 html_desc.append( "<tr><td>Command line:</td><td>" + nl + nl + cla.getCommandLineArgsAsString() + nl + nl
1408 + "</td></tr>" + nl );
1409 System.out.println( "Command line : " + cla.getCommandLineArgsAsString() );
1410 BufferedWriter[] query_domains_writer_ary = null;
1411 List<String>[] query_domain_ids_array = null;
1412 if ( query_domain_ids != null ) {
1413 final String[] query_domain_ids_str_array = query_domain_ids.split( "#" );
1414 query_domain_ids_array = new ArrayList[ query_domain_ids_str_array.length ];
1415 query_domains_writer_ary = new BufferedWriter[ query_domain_ids_str_array.length ];
1416 for( int i = 0; i < query_domain_ids_str_array.length; i++ ) {
1417 String query_domain_ids_str = query_domain_ids_str_array[ i ];
1418 final String[] query_domain_ids_str_ary = query_domain_ids_str.split( "~" );
1419 final List<String> query = new ArrayList<String>();
1420 for( final String element : query_domain_ids_str_ary ) {
1421 query.add( element );
1423 query_domain_ids_array[ i ] = query;
1424 query_domain_ids_str = query_domain_ids_str.replace( '~', '_' );
1425 String protein_names_writer_str = query_domain_ids_str + surfacing.SEQ_EXTRACT_SUFFIX;
1426 if ( out_dir != null ) {
1427 protein_names_writer_str = out_dir + ForesterUtil.FILE_SEPARATOR + protein_names_writer_str;
1430 query_domains_writer_ary[ i ] = new BufferedWriter( new FileWriter( protein_names_writer_str ) );
1432 catch ( final IOException e ) {
1433 ForesterUtil.fatalError( surfacing.PRG_NAME,
1434 "Could not open [" + protein_names_writer_str + "]: "
1435 + e.getLocalizedMessage() );
1439 SortedMap<Species, List<Protein>> protein_lists_per_species = null; //This will only be created if needed.
1440 boolean need_protein_lists_per_species = false;
1441 if ( ( plus_minus_analysis_high_copy_base_species.size() > 0 ) || output_protein_lists_for_all_domains
1443 need_protein_lists_per_species = true;
1445 if ( need_protein_lists_per_species ) {
1446 protein_lists_per_species = new TreeMap<Species, List<Protein>>();
1448 List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>( number_of_genomes );
1449 final SortedSet<String> all_domains_encountered = new TreeSet<String>();
1450 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered = new TreeSet<BinaryDomainCombination>();
1451 List<BinaryDomainCombination> all_bin_domain_combinations_gained_fitch = null;
1452 List<BinaryDomainCombination> all_bin_domain_combinations_lost_fitch = null;
1453 if ( ( intrees != null ) && ( intrees.length == 1 ) ) {
1454 all_bin_domain_combinations_gained_fitch = new ArrayList<BinaryDomainCombination>();
1455 all_bin_domain_combinations_lost_fitch = new ArrayList<BinaryDomainCombination>();
1457 final File per_genome_domain_promiscuity_statistics_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR
1458 + output_file + D_PROMISCUITY_FILE_SUFFIX );
1459 BufferedWriter per_genome_domain_promiscuity_statistics_writer = null;
1461 per_genome_domain_promiscuity_statistics_writer = new BufferedWriter( new FileWriter( per_genome_domain_promiscuity_statistics_file ) );
1462 per_genome_domain_promiscuity_statistics_writer.write( "Species:\t" );
1463 per_genome_domain_promiscuity_statistics_writer.write( "Mean:\t" );
1464 per_genome_domain_promiscuity_statistics_writer.write( "SD:\t" );
1465 per_genome_domain_promiscuity_statistics_writer.write( "Median:\t" );
1466 per_genome_domain_promiscuity_statistics_writer.write( "Min:\t" );
1467 per_genome_domain_promiscuity_statistics_writer.write( "Max:\t" );
1468 per_genome_domain_promiscuity_statistics_writer.write( "N:\t" );
1469 per_genome_domain_promiscuity_statistics_writer
1470 .write( "Max Promiscuous Domains:" + ForesterUtil.LINE_SEPARATOR );
1472 catch ( final IOException e2 ) {
1473 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1475 final File log_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + LOG_FILE_SUFFIX );
1476 BufferedWriter log_writer = null;
1478 log_writer = new BufferedWriter( new FileWriter( log_file ) );
1480 catch ( final IOException e2 ) {
1481 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1483 BufferedWriter dc_data_writer = null;
1485 dc_data_writer = new BufferedWriter( new FileWriter( dc_data_file ) );
1486 dc_data_writer.write( DATA_FILE_DESC );
1487 dc_data_writer.write( ForesterUtil.LINE_SEPARATOR );
1489 catch ( final IOException e2 ) {
1490 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1492 DescriptiveStatistics protein_coverage_stats = new BasicDescriptiveStatistics();
1493 DescriptiveStatistics all_genomes_domains_per_potein_stats = new BasicDescriptiveStatistics();
1494 final SortedMap<Integer, Integer> all_genomes_domains_per_potein_histo = new TreeMap<Integer, Integer>();
1495 final SortedSet<String> domains_which_are_always_single = new TreeSet<String>();
1496 final SortedSet<String> domains_which_are_sometimes_single_sometimes_not = new TreeSet<String>();
1497 final SortedSet<String> domains_which_never_single = new TreeSet<String>();
1498 BufferedWriter domains_per_potein_stats_writer = null;
1500 domains_per_potein_stats_writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR
1501 + output_file + "_domains_per_potein_stats.txt" ) );
1502 domains_per_potein_stats_writer.write( "Genome" );
1503 domains_per_potein_stats_writer.write( "\t" );
1504 domains_per_potein_stats_writer.write( "Mean" );
1505 domains_per_potein_stats_writer.write( "\t" );
1506 domains_per_potein_stats_writer.write( "SD" );
1507 domains_per_potein_stats_writer.write( "\t" );
1508 domains_per_potein_stats_writer.write( "Median" );
1509 domains_per_potein_stats_writer.write( "\t" );
1510 domains_per_potein_stats_writer.write( "N" );
1511 domains_per_potein_stats_writer.write( "\t" );
1512 domains_per_potein_stats_writer.write( "Min" );
1513 domains_per_potein_stats_writer.write( "\t" );
1514 domains_per_potein_stats_writer.write( "Max" );
1515 domains_per_potein_stats_writer.write( "\n" );
1517 catch ( final IOException e3 ) {
1518 e3.printStackTrace();
1520 Map<String, DescriptiveStatistics> protein_length_stats_by_dc = null;
1521 Map<String, DescriptiveStatistics> domain_number_stats_by_dc = null;
1522 final Map<String, DescriptiveStatistics> domain_length_stats_by_domain = new HashMap<String, DescriptiveStatistics>();
1523 if ( perform_dc_regain_proteins_stats ) {
1524 protein_length_stats_by_dc = new HashMap<String, DescriptiveStatistics>();
1525 domain_number_stats_by_dc = new HashMap<String, DescriptiveStatistics>();
1527 DomainLengthsTable domain_lengths_table = null;
1528 if ( domain_length_analysis ) {
1529 domain_lengths_table = new DomainLengthsTable();
1532 final SortedMap<String, Set<String>> distinct_domain_architecutures_per_genome = new TreeMap<String, Set<String>>();
1533 final SortedMap<String, Integer> distinct_domain_architecuture_counts = new TreeMap<String, Integer>();
1534 for( int i = 0; i < number_of_genomes; ++i ) {
1535 System.out.println();
1536 System.out.println( ( i + 1 ) + "/" + number_of_genomes );
1537 SurfacingUtil.log( ( i + 1 ) + "/" + number_of_genomes, log_writer );
1538 System.out.println( "Processing : " + input_file_properties[ i ][ 1 ]
1539 + " [" + input_file_properties[ i ][ 0 ] + "]" );
1540 SurfacingUtil.log( "Genome : " + input_file_properties[ i ][ 1 ]
1541 + " [" + input_file_properties[ i ][ 0 ] + "]", log_writer );
1542 HmmscanPerDomainTableParser parser = null;
1543 INDIVIDUAL_SCORE_CUTOFF ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF.NONE;
1544 if ( individual_score_cutoffs != null ) {
1545 ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF_DEFAULT;
1547 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1548 || ( negative_domains_filter_file != null ) ) {
1549 HmmscanPerDomainTableParser.FilterType filter_type = HmmscanPerDomainTableParser.FilterType.NONE;
1550 if ( positive_filter_file != null ) {
1551 filter_type = HmmscanPerDomainTableParser.FilterType.POSITIVE_PROTEIN;
1553 else if ( negative_filter_file != null ) {
1554 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_PROTEIN;
1556 else if ( negative_domains_filter_file != null ) {
1557 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_DOMAIN;
1559 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1560 input_file_properties[ i ][ 1 ],
1567 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1568 input_file_properties[ i ][ 1 ],
1572 if ( fs_e_value_max >= 0.0 ) {
1573 parser.setFsEValueMaximum( fs_e_value_max );
1575 if ( ie_value_max >= 0.0 ) {
1576 parser.setIEValueMaximum( ie_value_max );
1578 if ( rel_env_length_ratio_cutoff > 0.0 ) {
1579 parser.setRelEnvLengthRatioCutoff( rel_env_length_ratio_cutoff );
1581 parser.setIgnoreDufs( ignore_dufs );
1582 parser.setIgnoreVirusLikeIds( ignore_virus_like_ids );
1583 parser.setIgnoreEngulfedDomains( no_engulfing_overlaps );
1584 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1585 parser.setMaxAllowedOverlap( max_allowed_overlap );
1587 parser.setReturnType( HmmscanPerDomainTableParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
1588 if ( individual_score_cutoffs != null ) {
1589 parser.setIndividualScoreCutoffs( individual_score_cutoffs );
1591 List<Protein> protein_list = null;
1593 protein_list = parser.parse();
1595 catch ( final IOException e ) {
1596 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
1598 catch ( final Exception e ) {
1599 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, e.getMessage(), e );
1602 System.out.println( "Domains ignored due to negative domain filter: " );
1603 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToNegativeDomainFilterCountsMap() );
1604 System.out.println( "Domains ignored due to virus like id: " );
1605 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToVirusLikeIdCountsMap() );
1607 final double coverage = ( double ) protein_list.size() / parser.getProteinsEncountered();
1608 protein_coverage_stats.addValue( coverage );
1609 int distinct_das = -1;
1610 if ( da_analysis ) {
1611 final String genome = input_file_properties[ i ][ 0 ];
1612 distinct_das = SurfacingUtil.storeDomainArchitectures( genome,
1613 distinct_domain_architecutures_per_genome,
1615 distinct_domain_architecuture_counts );
1617 System.out.println( "Number of proteins encountered : " + parser.getProteinsEncountered() );
1618 SurfacingUtil.log( "Number of proteins encountered : " + parser.getProteinsEncountered(),
1620 System.out.println( "Number of proteins stored : " + protein_list.size() );
1621 SurfacingUtil.log( "Number of proteins stored : " + protein_list.size(), log_writer );
1622 System.out.println( "Coverage : "
1623 + ForesterUtil.roundToInt( 100.0 * coverage ) + "%" );
1624 SurfacingUtil.log( "Coverage : "
1625 + ForesterUtil.roundToInt( 100.0 * coverage ) + "%", log_writer );
1626 System.out.println( "Domains encountered : " + parser.getDomainsEncountered() );
1627 SurfacingUtil.log( "Domains encountered : " + parser.getDomainsEncountered(),
1629 System.out.println( "Domains stored : " + parser.getDomainsStored() );
1630 SurfacingUtil.log( "Domains stored : " + parser.getDomainsStored(),
1632 System.out.println( "Distinct domains stored : "
1633 + parser.getDomainsStoredSet().size() );
1635 .log( "Distinct domains stored : " + parser.getDomainsStoredSet().size(),
1637 System.out.println( "Domains ignored due to individual score cutoffs: "
1638 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() );
1639 SurfacingUtil.log( "Domains ignored due to individual score cutoffs: "
1640 + parser.getDomainsIgnoredDueToIndividualScoreCutoff(), log_writer );
1641 System.out.println( "Domains ignored due to FS E-value : "
1642 + parser.getDomainsIgnoredDueToFsEval() );
1644 .log( "Domains ignored due to FS E-value : " + parser.getDomainsIgnoredDueToFsEval(),
1646 System.out.println( "Domains ignored due to iE-value : "
1647 + parser.getDomainsIgnoredDueToIEval() );
1649 .log( "Domains ignored due to iE-value : " + parser.getDomainsIgnoredDueToIEval(),
1651 System.out.println( "Domains ignored due to rel env length ratio : "
1652 + parser.getDomainsIgnoredDueToRelEnvLengthRatioCutoff() );
1653 SurfacingUtil.log( "Domains ignored due to rel env length ratio : "
1654 + parser.getDomainsIgnoredDueToRelEnvLengthRatioCutoff(), log_writer );
1655 System.out.println( "Domains ignored due to DUF designation : "
1656 + parser.getDomainsIgnoredDueToDuf() );
1657 SurfacingUtil.log( "Domains ignored due to DUF designation : " + parser.getDomainsIgnoredDueToDuf(),
1659 if ( ignore_virus_like_ids ) {
1660 System.out.println( "Domains ignored due virus like ids : "
1661 + parser.getDomainsIgnoredDueToVirusLikeIds() );
1662 SurfacingUtil.log( "Domains ignored due virus like ids : "
1663 + parser.getDomainsIgnoredDueToVirusLikeIds(), log_writer );
1665 System.out.println( "Domains ignored due negative domain filter : "
1666 + parser.getDomainsIgnoredDueToNegativeDomainFilter() );
1667 SurfacingUtil.log( "Domains ignored due negative domain filter : "
1668 + parser.getDomainsIgnoredDueToNegativeDomainFilter(), log_writer );
1669 System.out.println( "Domains ignored due to overlap : "
1670 + parser.getDomainsIgnoredDueToOverlap() );
1672 .log( "Domains ignored due to overlap : " + parser.getDomainsIgnoredDueToOverlap(),
1674 if ( negative_filter_file != null ) {
1675 System.out.println( "Proteins ignored due to negative filter : "
1676 + parser.getProteinsIgnoredDueToFilter() );
1677 SurfacingUtil.log( "Proteins ignored due to negative filter : "
1678 + parser.getProteinsIgnoredDueToFilter(), log_writer );
1680 if ( positive_filter_file != null ) {
1681 System.out.println( "Proteins ignored due to positive filter : "
1682 + parser.getProteinsIgnoredDueToFilter() );
1683 SurfacingUtil.log( "Proteins ignored due to positive filter : "
1684 + parser.getProteinsIgnoredDueToFilter(), log_writer );
1686 if ( da_analysis ) {
1687 System.out.println( "Distinct domain architectures stored : " + distinct_das );
1688 SurfacingUtil.log( "Distinct domain architectures stored : " + distinct_das, log_writer );
1690 System.out.println( "Time for processing : " + parser.getTime() + "ms" );
1691 SurfacingUtil.log( "", log_writer );
1694 for( final Protein protein : protein_list ) {
1696 .write( SurfacingUtil.proteinToDomainCombinations( protein, count + "", "\t" ).toString() );
1698 for( final Domain d : protein.getProteinDomains() ) {
1699 final String d_str = d.getDomainId().toString();
1700 if ( !domain_length_stats_by_domain.containsKey( d_str ) ) {
1701 domain_length_stats_by_domain.put( d_str, new BasicDescriptiveStatistics() );
1703 domain_length_stats_by_domain.get( d_str ).addValue( d.getLength() );
1707 catch ( final IOException e ) {
1708 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1710 SurfacingUtil.domainsPerProteinsStatistics( input_file_properties[ i ][ 1 ],
1712 all_genomes_domains_per_potein_stats,
1713 all_genomes_domains_per_potein_histo,
1714 domains_which_are_always_single,
1715 domains_which_are_sometimes_single_sometimes_not,
1716 domains_which_never_single,
1717 domains_per_potein_stats_writer );
1718 if ( domain_length_analysis ) {
1719 domain_lengths_table.addLengths( protein_list );
1721 if ( !da_analysis ) {
1722 gwcd_list.add( BasicGenomeWideCombinableDomains.createInstance( protein_list,
1723 ignore_combination_with_same,
1724 new BasicSpecies( input_file_properties[ i ][ 1 ] ),
1725 domain_id_to_go_ids_map,
1727 protein_length_stats_by_dc,
1728 domain_number_stats_by_dc ) );
1729 if ( gwcd_list.get( i ).getSize() > 0 ) {
1730 if ( output_binary_domain_combinationsfor_counts ) {
1731 SurfacingUtil.writeDomainCombinationsCountsFile( input_file_properties,
1733 per_genome_domain_promiscuity_statistics_writer,
1738 if ( output_binary_domain_combinationsfor_graph_analysis ) {
1739 SurfacingUtil.writeBinaryDomainCombinationsFileForGraphAnalysis( input_file_properties,
1745 SurfacingUtil.addAllDomainIdsToSet( gwcd_list.get( i ), all_domains_encountered );
1746 SurfacingUtil.addAllBinaryDomainCombinationToSet( gwcd_list.get( i ),
1747 all_bin_domain_combinations_encountered );
1750 if ( query_domains_writer_ary != null ) {
1751 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1753 SurfacingUtil.extractProteinNames( protein_list,
1754 query_domain_ids_array[ j ],
1755 query_domains_writer_ary[ j ],
1757 LIMIT_SPEC_FOR_PROT_EX );
1758 query_domains_writer_ary[ j ].flush();
1760 catch ( final IOException e ) {
1761 e.printStackTrace();
1765 if ( need_protein_lists_per_species ) {
1766 protein_lists_per_species.put( new BasicSpecies( input_file_properties[ i ][ 1 ] ), protein_list );
1771 catch ( final IOException e2 ) {
1772 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1775 } // for( int i = 0; i < number_of_genomes; ++i ) {
1777 .programMessage( PRG_NAME,
1778 "Wrote domain promiscuities to: " + per_genome_domain_promiscuity_statistics_file );
1779 final int LEVEL = 0;
1781 MinimalDomainomeCalculator.calc( false,
1784 protein_lists_per_species,
1787 out_dir.toString() + "/" + output_file,
1790 catch ( IOException e ) {
1791 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
1794 MinimalDomainomeCalculator.calc( true,
1797 protein_lists_per_species,
1800 out_dir.toString() + "/" + output_file,
1803 catch ( IOException e ) {
1804 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getLocalizedMessage() );
1806 if ( da_analysis ) {
1807 SurfacingUtil.performDomainArchitectureAnalysis( distinct_domain_architecutures_per_genome,
1808 distinct_domain_architecuture_counts,
1810 new File( out_dir.toString() + "/" + output_file
1811 + "_DA_counts.txt" ),
1812 new File( out_dir.toString() + "/" + output_file
1813 + "_unique_DAs.txt" ) );
1814 distinct_domain_architecutures_per_genome.clear();
1815 distinct_domain_architecuture_counts.clear();
1819 domains_per_potein_stats_writer.write( "ALL" );
1820 domains_per_potein_stats_writer.write( "\t" );
1821 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.arithmeticMean() + "" );
1822 domains_per_potein_stats_writer.write( "\t" );
1823 domains_per_potein_stats_writer
1824 .write( all_genomes_domains_per_potein_stats.sampleStandardDeviation() + "" );
1825 domains_per_potein_stats_writer.write( "\t" );
1826 if ( all_genomes_domains_per_potein_stats.getN() <= 300 ) {
1827 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.median() + "" );
1828 domains_per_potein_stats_writer.write( "\t" );
1830 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getN() + "" );
1831 domains_per_potein_stats_writer.write( "\t" );
1832 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getMin() + "" );
1833 domains_per_potein_stats_writer.write( "\t" );
1834 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getMax() + "" );
1835 domains_per_potein_stats_writer.write( "\n" );
1836 domains_per_potein_stats_writer.close();
1837 all_genomes_domains_per_potein_stats = null;
1838 SurfacingUtil.printOutPercentageOfMultidomainProteins( all_genomes_domains_per_potein_histo, log_writer );
1839 ForesterUtil.map2file(
1840 new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1841 + "_all_genomes_domains_per_potein_histo.txt" ),
1842 all_genomes_domains_per_potein_histo,
1845 ForesterUtil.collection2file(
1846 new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1847 + "_domains_always_single_.txt" ),
1848 domains_which_are_always_single,
1850 ForesterUtil.collection2file(
1851 new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1852 + "_domains_single_or_combined.txt" ),
1853 domains_which_are_sometimes_single_sometimes_not,
1855 ForesterUtil.collection2file(
1856 new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1857 + "_domains_always_combined.txt" ),
1858 domains_which_never_single,
1860 ForesterUtil.programMessage( PRG_NAME,
1861 "Average of proteins with a least one domain assigned: "
1862 + ( 100 * protein_coverage_stats.arithmeticMean() ) + "% (+/-"
1863 + ( 100 * protein_coverage_stats.sampleStandardDeviation() ) + "%)" );
1864 ForesterUtil.programMessage( PRG_NAME,
1865 "Range of proteins with a least one domain assigned: "
1866 + ( 100 * protein_coverage_stats.getMin() ) + "%-"
1867 + ( 100 * protein_coverage_stats.getMax() ) + "%" );
1869 "Average of prot with a least one dom assigned : "
1870 + ( 100 * protein_coverage_stats.arithmeticMean() ) + "% (+/-"
1871 + ( 100 * protein_coverage_stats.sampleStandardDeviation() ) + "%)",
1873 SurfacingUtil.log( "Range of prot with a least one dom assigned : "
1874 + ( 100 * protein_coverage_stats.getMin() ) + "%-" + ( 100 * protein_coverage_stats.getMax() )
1875 + "%", log_writer );
1876 protein_coverage_stats = null;
1878 catch ( final IOException e2 ) {
1879 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1881 if ( query_domains_writer_ary != null ) {
1882 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1884 query_domains_writer_ary[ j ].close();
1886 catch ( final IOException e ) {
1887 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1892 per_genome_domain_promiscuity_statistics_writer.close();
1893 dc_data_writer.close();
1896 catch ( final IOException e2 ) {
1897 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1899 if ( domain_length_analysis ) {
1901 SurfacingUtil.executeDomainLengthAnalysis( input_file_properties,
1903 domain_lengths_table,
1904 domain_lengths_analysis_outfile );
1906 catch ( final IOException e1 ) {
1907 ForesterUtil.fatalError( surfacing.PRG_NAME, e1.toString() );
1909 System.out.println();
1910 ForesterUtil.programMessage( PRG_NAME, "Wrote domain length data to: " + domain_lengths_analysis_outfile );
1911 System.out.println();
1913 domain_lengths_table = null;
1914 final long analysis_start_time = new Date().getTime();
1915 PairwiseDomainSimilarityCalculator pw_calc = null;
1916 final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( domain_similarity_sort_field,
1917 sort_by_species_count_first,
1918 number_of_genomes == 2,
1919 CALC_SIMILARITY_SCORES,
1921 switch ( scoring ) {
1923 pw_calc = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1926 pw_calc = new DomainCountsBasedPairwiseSimilarityCalculator();
1929 pw_calc = new ProteinCountsBasedPairwiseDomainSimilarityCalculator();
1932 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1934 DomainSimilarityCalculator.GoAnnotationOutput go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.NONE;
1935 if ( domain_id_to_go_ids_map != null ) {
1936 go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.ALL;
1938 final SortedSet<DomainSimilarity> similarities = calc.calculateSimilarities( pw_calc,
1940 ignore_domains_without_combs_in_all_spec,
1941 ignore_species_specific_domains );
1942 SurfacingUtil.decoratePrintableDomainSimilarities( similarities, detailedness );
1943 final Map<String, Integer> tax_code_to_id_map = SurfacingUtil.createTaxCodeToIdMap( intrees[ 0 ] );
1945 String my_outfile = output_file.toString();
1946 Map<Character, Writer> split_writers = null;
1947 Writer writer = null;
1948 if ( similarities.size() > MINIMAL_NUMBER_OF_SIMILARITIES_FOR_SPLITTING ) {
1949 if ( my_outfile.endsWith( ".html" ) ) {
1950 my_outfile = my_outfile.substring( 0, my_outfile.length() - 5 );
1952 split_writers = new HashMap<Character, Writer>();
1953 SurfacingUtil.createSplitWriters( out_dir, my_outfile, split_writers );
1955 else if ( !my_outfile.endsWith( ".html" ) ) {
1956 my_outfile += ".html";
1957 writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR + my_outfile ) );
1959 List<Species> species_order = null;
1960 if ( species_matrix ) {
1961 species_order = new ArrayList<Species>();
1962 for( int i = 0; i < number_of_genomes; i++ ) {
1963 species_order.add( new BasicSpecies( input_file_properties[ i ][ 1 ] ) );
1966 html_desc.append( "<tr><td>Sum of all distinct binary combinations:</td><td>"
1967 + all_bin_domain_combinations_encountered.size() + "</td></tr>" + nl );
1968 html_desc.append( "<tr><td>Sum of all distinct domains:</td><td>" + all_domains_encountered.size()
1969 + "</td></tr>" + nl );
1970 html_desc.append( "<tr><td>Analysis date/time:</td><td>"
1971 + new java.text.SimpleDateFormat( "yyyy.MM.dd HH:mm:ss" ).format( new java.util.Date() )
1972 + "</td></tr>" + nl );
1973 html_desc.append( "</table>" + nl );
1974 final Writer simple_tab_writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR
1975 + my_outfile.replaceFirst( ".html", ".tsv" ) ) );
1976 SurfacingUtil.writeDomainSimilaritiesToFile( html_desc,
1977 new StringBuilder( number_of_genomes + " genomes" ),
1982 number_of_genomes == 2,
1984 domain_similarity_print_option,
1989 positive_filter_file != null ? filter : null );
1990 simple_tab_writer.close();
1991 ForesterUtil.programMessage( surfacing.PRG_NAME,
1992 "Wrote main output (includes domain similarities) to: \""
1993 + ( out_dir == null ? my_outfile
1994 : out_dir + ForesterUtil.FILE_SEPARATOR + my_outfile )
1997 catch ( final IOException e ) {
1999 .fatalError( surfacing.PRG_NAME,
2000 "Failed to write similarites to: \"" + output_file + "\" [" + e.getMessage() + "]" );
2002 System.out.println();
2003 final Species[] species = new Species[ number_of_genomes ];
2004 for( int i = 0; i < number_of_genomes; ++i ) {
2005 species[ i ] = new BasicSpecies( input_file_properties[ i ][ 1 ] );
2007 List<Phylogeny> inferred_trees = null;
2008 if ( ( number_of_genomes > 2 ) && perform_pwc ) {
2009 final PairwiseGenomeComparator pwgc = new PairwiseGenomeComparator();
2010 pwgc.performPairwiseComparisons( html_desc,
2011 sort_by_species_count_first,
2013 ignore_domains_without_combs_in_all_spec,
2014 ignore_species_specific_domains,
2015 domain_similarity_sort_field_for_automated_pwc,
2016 domain_similarity_print_option,
2018 domain_id_to_go_ids_map,
2025 automated_pairwise_comparison_suffix,
2027 surfacing.PAIRWISE_DOMAIN_COMPARISONS_PREFIX,
2032 CALC_SIMILARITY_SCORES,
2034 String matrix_output_file = new String( output_file.toString() );
2035 if ( matrix_output_file.indexOf( '.' ) > 1 ) {
2036 matrix_output_file = matrix_output_file.substring( 0, matrix_output_file.indexOf( '.' ) );
2038 if ( out_dir != null ) {
2039 matrix_output_file = out_dir + ForesterUtil.FILE_SEPARATOR + matrix_output_file;
2040 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
2042 SurfacingUtil.writeMatrixToFile(
2043 new File( matrix_output_file
2044 + surfacing.MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ),
2045 pwgc.getDomainDistanceScoresMeans() );
2046 SurfacingUtil.writeMatrixToFile(
2047 new File( matrix_output_file
2048 + surfacing.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
2049 pwgc.getSharedBinaryCombinationsBasedDistances() );
2050 SurfacingUtil.writeMatrixToFile(
2051 new File( matrix_output_file
2052 + surfacing.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
2053 pwgc.getSharedDomainsBasedDistances() );
2054 final Phylogeny nj_gd = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
2055 + surfacing.NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ),
2056 pwgc.getDomainDistanceScoresMeans()
2058 final Phylogeny nj_bc = SurfacingUtil.createNjTreeBasedOnMatrixToFile(
2059 new File( matrix_output_file
2060 + surfacing.NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
2061 pwgc.getSharedBinaryCombinationsBasedDistances()
2063 final Phylogeny nj_d = SurfacingUtil.createNjTreeBasedOnMatrixToFile(
2064 new File( matrix_output_file
2065 + surfacing.NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
2066 pwgc.getSharedDomainsBasedDistances()
2068 inferred_trees = new ArrayList<Phylogeny>();
2069 inferred_trees.add( nj_gd );
2070 inferred_trees.add( nj_bc );
2071 inferred_trees.add( nj_d );
2072 } // if ( ( output_file != null ) && ( number_of_genomes > 2 ) && !isEmpty( automated_pairwise_comparison_suffix ) )
2073 if ( ( out_dir != null ) && ( !perform_pwc ) ) {
2074 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
2076 if ( write_to_nexus ) {
2077 SurfacingUtil.writePresentToNexus( output_file, positive_filter_file, filter, gwcd_list );
2079 if ( ( ( intrees != null ) && ( intrees.length > 0 ) ) && ( number_of_genomes > 2 ) ) {
2080 final StringBuilder parameters_sb = SurfacingUtil.createParametersAsString( ignore_dufs,
2083 max_allowed_overlap,
2084 no_engulfing_overlaps,
2088 if ( radomize_fitch_parsimony ) {
2089 s += random_number_seed_for_fitch_parsimony + "_";
2092 for( final Phylogeny intree : intrees ) {
2093 final String outfile_name = ForesterUtil.removeSuffix( output_file.toString() ) + s
2094 + ForesterUtil.removeSuffix( intree_files[ i ].toString() );
2095 final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator
2096 .createInstance( intree, gwcd_list );
2097 SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
2098 radomize_fitch_parsimony,
2102 domain_id_to_go_ids_map,
2105 parameters_sb.toString(),
2106 domain_id_to_secondary_features_maps,
2107 positive_filter_file == null ? null : filter,
2108 output_binary_domain_combinationsfor_graph_analysis,
2109 all_bin_domain_combinations_gained_fitch,
2110 all_bin_domain_combinations_lost_fitch,
2112 protein_length_stats_by_dc,
2113 domain_number_stats_by_dc,
2114 domain_length_stats_by_domain,
2117 use_last_in_fitch_parsimony,
2119 // Listing of all domain combinations gained is only done if only one input tree is used.
2120 if ( ( domain_id_to_secondary_features_maps != null )
2121 && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
2123 for( final Map<String, Set<String>> domain_id_to_secondary_features_map : domain_id_to_secondary_features_maps ) {
2124 final Map<Species, MappingResults> mapping_results_map = new TreeMap<Species, MappingResults>();
2125 final DomainParsimonyCalculator secondary_features_parsimony = DomainParsimonyCalculator
2126 .createInstance( intree, gwcd_list, domain_id_to_secondary_features_map );
2127 SurfacingUtil.executeParsimonyAnalysisForSecondaryFeatures( outfile_name + "_"
2128 + secondary_features_map_files[ j++ ],
2129 secondary_features_parsimony,
2131 parameters_sb.toString(),
2132 mapping_results_map,
2133 use_last_in_fitch_parsimony );
2135 System.out.println();
2136 System.out.println( "Mapping to secondary features:" );
2137 for( final Species spec : mapping_results_map.keySet() ) {
2138 final MappingResults mapping_results = mapping_results_map.get( spec );
2139 final int total_domains = mapping_results.getSumOfFailures()
2140 + mapping_results.getSumOfSuccesses();
2141 System.out.print( spec + ":" );
2142 System.out.print( " mapped domains = " + mapping_results.getSumOfSuccesses() );
2143 System.out.print( ", not mapped domains = " + mapping_results.getSumOfFailures() );
2144 if ( total_domains > 0 ) {
2145 System.out.println( ", mapped ratio = "
2146 + ( ( 100 * mapping_results.getSumOfSuccesses() ) / total_domains ) + "%" );
2149 System.out.println( ", mapped ratio = n/a (total domains = 0 )" );
2156 } // for( final Phylogeny intree : intrees ) {
2158 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
2159 SurfacingUtil.executePlusMinusAnalysis( output_file,
2160 plus_minus_analysis_high_copy_base_species,
2161 plus_minus_analysis_high_copy_target_species,
2162 plus_minus_analysis_high_low_copy_species,
2164 protein_lists_per_species,
2165 domain_id_to_go_ids_map,
2167 plus_minus_analysis_numbers );
2169 if ( output_protein_lists_for_all_domains ) {
2170 SurfacingUtil.writeProteinListsForAllSpecies( out_dir,
2171 protein_lists_per_species,
2173 output_list_of_all_proteins_per_domain_e_value_max,
2174 positive_filter_file != null ? filter : null );
2177 if ( all_bin_domain_combinations_gained_fitch != null ) {
2179 SurfacingUtil.executeFitchGainsAnalysis(
2180 new File( output_file
2181 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2182 all_bin_domain_combinations_gained_fitch,
2183 all_domains_encountered.size(),
2184 all_bin_domain_combinations_encountered,
2187 catch ( final IOException e ) {
2188 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2191 if ( all_bin_domain_combinations_lost_fitch != null ) {
2193 SurfacingUtil.executeFitchGainsAnalysis(
2194 new File( output_file
2195 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2196 all_bin_domain_combinations_lost_fitch,
2197 all_domains_encountered.size(),
2198 all_bin_domain_combinations_encountered,
2201 catch ( final IOException e ) {
2202 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2205 final Runtime rt = java.lang.Runtime.getRuntime();
2206 final long free_memory = rt.freeMemory() / 1000000;
2207 final long total_memory = rt.totalMemory() / 1000000;
2208 ForesterUtil.programMessage( PRG_NAME,
2209 "Time for analysis : " + ( new Date().getTime() - analysis_start_time ) + "ms" );
2210 ForesterUtil.programMessage( PRG_NAME, "Total running time: " + ( new Date().getTime() - start_time ) + "ms " );
2212 .programMessage( PRG_NAME,
2213 "Free memory : " + free_memory + "MB, total memory: " + total_memory + "MB" );
2214 ForesterUtil.programMessage( PRG_NAME, "If this application is useful to you, please cite:" );
2215 ForesterUtil.programMessage( PRG_NAME, surfacing.WWW );
2217 .programMessage( PRG_NAME,
2218 "[next step for phylogenomic analysis pipeline (example, in \"DAS\" dir): % mse.rb .prot . FL_seqs DA_seqs path/to/genome_locations.txt]" );
2219 ForesterUtil.programMessage( PRG_NAME, "OK" );
2220 System.out.println();
2223 private static void printHelp() {
2224 System.out.println();
2225 System.out.println( "Usage:" );
2226 System.out.println();
2227 System.out.println( "% java -Xms256m -Xmx512m -cp forester.jar org.forester.applications." + surfacing.PRG_NAME
2228 + " [options] <phylogen(y|ies) infile> [external node name 1] [name 2] ... [name n]" );
2229 System.out.println();
2230 System.out.println( " Note: This software might need a significant amount of memory (heap space);" );
2232 .println( " hence use \"-Xms128m -Xmx512m\" (or more) to prevent a \"java.lang.OutOfMemoryError\"." );
2233 System.out.println();
2234 System.out.println( " Options: " );
2235 System.out.println( surfacing.DETAILEDNESS_OPTION + ": level of detail for similarities output file (default:"
2236 + DETAILEDNESS_DEFAULT + ")" );
2237 System.out.println( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION
2238 + ": to ignore combinations with self (default: not to ignore)" );
2239 System.out.println( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION
2240 + ": to ignore domains without combinations in any species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2241 System.out.println( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION
2242 + ": to ignore domains specific to one species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2243 System.out.println( surfacing.NOT_IGNORE_DUFS_OPTION
2244 + ": to _not_ ignore DUFs (domains with unknown function) (default: ignore DUFs)" );
2245 System.out.println( surfacing.IGNORE_VIRAL_IDS
2246 + ": to ignore domains with ids containing 'vir', 'retro', 'transpos', 'phage', or starting with 'rv' or 'gag_'" );
2247 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_OPTION + ": sorting for similarities (default: "
2248 + DOMAIN_SORT_FILD_DEFAULT + ")" );
2249 System.out.println( surfacing.OUTPUT_FILE_OPTION + ": name for (main) output file (mandatory)" );
2250 System.out.println( surfacing.MAX_I_E_VALUE_OPTION + ": max (inclusive) iE-value" );
2251 System.out.println( surfacing.MAX_FS_E_VALUE_OPTION + ": max (inclusive) FS E-value" );
2252 System.out.println( surfacing.MIN_REL_ENV_LENGTH_RATIO_OPTION
2253 + ": min (inclusive) relative envelope length ratio" );
2254 System.out.println( surfacing.MAX_ALLOWED_OVERLAP_OPTION + ": maximal allowed domain overlap" );
2255 System.out.println( surfacing.NO_ENGULFING_OVERLAP_OPTION + ": to ignore engulfed lower confidence domains" );
2256 System.out.println( surfacing.SPECIES_MATRIX_OPTION + ": species matrix" );
2257 System.out.println( surfacing.SCORING_OPTION + ": scoring (default:" + SCORING_DEFAULT + ")" );
2258 System.out.println( surfacing.DOMAIN_COUNT_SORT_OPTION + ": sorting for domain counts (default:"
2259 + DOMAINS_SORT_ORDER_DEFAULT + ")" );
2260 System.out.println( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION + ": domain similarity print option (default:"
2261 + DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT + ")" );
2262 System.out.println( surfacing.CUTOFF_SCORE_FILE_OPTION + ": cutoff score file" );
2263 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION
2264 + ": sort by species count first" );
2265 System.out.println( surfacing.OUTPUT_DIR_OPTION + ": output directory" );
2266 System.out.println( surfacing.PFAM_TO_GO_FILE_USE_OPTION + ": Pfam to GO mapping file" );
2267 System.out.println( surfacing.GO_OBO_FILE_USE_OPTION + ": GO terms file (OBO format)" );
2268 System.out.println( surfacing.GO_NAMESPACE_LIMIT_OPTION + ": limit GO term to one GO namespace" );
2269 System.out.println( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
2270 + "[=<suffix for pairwise comparison output files>]: to perform pairwise comparison based analyses" );
2271 System.out.println( surfacing.INPUT_SPECIES_TREE_OPTION
2272 + ": species tree, to perform (Dollo, Fitch) parismony analyses" );
2273 System.out.println( surfacing.INPUT_SPECIES_TREE_OPTION
2274 + "=<treefiles in phyloXML format, separated by #>: to infer domain/binary domain combination gains/losses on given species trees" );
2275 System.out.println( surfacing.FILTER_POSITIVE_OPTION
2276 + "=<file>: to filter out proteins not containing at least one domain listed in <file>" );
2277 System.out.println( surfacing.FILTER_NEGATIVE_OPTION
2278 + "=<file>: to filter out proteins containing at least one domain listed in <file>" );
2279 System.out.println( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION
2280 + "=<file>: to filter out (ignore) domains listed in <file>" );
2281 System.out.println( surfacing.INPUT_GENOMES_FILE_OPTION + "=<file>: to read input files from <file>" );
2282 System.out.println( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION
2283 + "=<seed>: seed for random number generator for Fitch Parsimony analysis (type: long, default: no randomization - given a choice, prefer absence" );
2284 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS
2285 + ": to consider directedness in binary combinations: e.g. A-B != B-A" );
2286 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY
2287 + ": to consider directedness and adjacency in binary combinations" );
2288 System.out.println( surfacing.SEQ_EXTRACT_OPTION
2289 + "=<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')" );
2290 System.out.println( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE
2291 + "=<file>: to perfom parsimony analysis on secondary features" );
2292 System.out.println( surfacing.PLUS_MINUS_ANALYSIS_OPTION + "=<file>: to presence/absence genome analysis" );
2293 System.out.println( surfacing.DOMAIN_COMBINITONS_COUNTS_OUTPUT_OPTION
2294 + ": to output binary domain counts (as individual files)" );
2295 System.out.println( surfacing.DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS
2296 + ": to output binary domain combinations for (downstream) graph analysis" );
2297 System.out.println( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS + ": to output all proteins per domain" );
2298 System.out.println( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION
2299 + ": e value max per domain for output of all proteins per domain" );
2300 System.out.println( surfacing.USE_LAST_IN_FITCH_OPTION + ": to use last in Fitch parsimony" );
2301 System.out.println( surfacing.WRITE_TO_NEXUS_OPTION + ": to output in Nexus format" );
2302 System.out.println( PERFORM_DC_FITCH + ": to perform DC Fitch parsimony" );
2303 System.out.println( PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION + ": to perform DC regain protein statistics" );
2304 System.out.println( DA_ANALYSIS_OPTION + ": to perform DA analysis" );
2305 System.out.println( PERFORM_DOMAIN_LENGTH_ANALYSIS_OPTION + ": to perform domain length analysis" );
2306 System.out.println();
2307 System.out.println();
2309 .println( "Example 1: surfacing -p2g=pfam2go.txt -obo=go.obo -species_tree=tol_156.xml -no_eo -ie=0.01 -dufs -genomes=genomes_all.txt -pos_filter=tf_1.txt -out_dir=_tf1 -o=tf1" );
2310 System.out.println();
2312 .println( "Example 2: surfacing -p2g=pfam2go.txt -obo=go.obo -species_tree=tol_156.xml -last -ignore_viral_ids -no_eo -ie=0.1 -dufs -genomes=genomes_all.txt -pos_filter=tf_1.txt -all_prot -all_prot_e=0.1 -out_dir=_tf1_e01_ape01 -o=tf1_e01_ape01" );
2313 System.out.println();
2315 .println( "Example 3: surfacing -species_tree=master_tree.xml -no_eo -ie=1e-6 -mrel=0.5 -mo=10 -dufs -genomes=genomes.txt -out_dir=a605 -o=a605" );
2316 System.out.println();
2318 .println( "[next step for phylogenomic analysis pipeline (example, in \"DAS\" dir): % mse.rb .prot . FL_seqs DA_seqs path/to/genome_locations.txt]" );
2319 System.out.println();