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.PairwiseDomainSimilarityCalculator;
75 import org.forester.surfacing.PairwiseGenomeComparator;
76 import org.forester.surfacing.ProteinCountsBasedPairwiseDomainSimilarityCalculator;
77 import org.forester.surfacing.SurfacingUtil;
78 import org.forester.util.BasicDescriptiveStatistics;
79 import org.forester.util.BasicTable;
80 import org.forester.util.BasicTableParser;
81 import org.forester.util.CommandLineArguments;
82 import org.forester.util.DescriptiveStatistics;
83 import org.forester.util.ForesterConstants;
84 import org.forester.util.ForesterUtil;
86 public class surfacing {
88 private static final int MINIMAL_NUMBER_OF_SIMILARITIES_FOR_SPLITTING = 1000;
89 public final static String DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS = "graph_analysis_out";
90 public final static String DOMAIN_COMBINITONS_COUNTS_OUTPUT_OPTION = "dcc";
91 public final static String DOMAIN_COMBINITONS_OUTPUTFILE_SUFFIX_FOR_GRAPH_ANALYSIS = "_dc.dot";
92 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_BC_OUTPUTFILE_SUFFIX_FOR_GRAPH_ANALYSIS = "_fitch_present_dc.dot";
93 public final static String DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX = ".dcc";
95 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_DOMAINS = "_dollo_gl_d";
96 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_BINARY_COMBINATIONS = "_dollo_gl_dc";
97 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_FITCH_DOMAINS = "_fitch_gl_d";
98 public final static String PARSIMONY_OUTPUT_GL_SUFFIX_FITCH_BINARY_COMBINATIONS = "_fitch_gl_dc";
100 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_DOMAINS = "_dollo_glc_d";
101 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_BINARY_COMBINATIONS = "_dollo_glc_dc";
102 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_FITCH_DOMAINS = "_fitch_glc_d";
103 public final static String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_FITCH_BINARY_COMBINATIONS = "_fitch_glc_dc";
105 public final static String PARSIMONY_OUTPUT_FITCH_GAINS_BC = "_fitch_gains_dc";
106 public final static String PARSIMONY_OUTPUT_FITCH_GAINS_HTML_BC = "_fitch_gains_dc.html";
107 public final static String PARSIMONY_OUTPUT_FITCH_LOSSES_BC = "_fitch_losses_dc";
108 public final static String PARSIMONY_OUTPUT_FITCH_LOSSES_HTML_BC = "_fitch_losses_dc.html";
109 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_BC = "_fitch_present_dc";
110 public final static String PARSIMONY_OUTPUT_FITCH_PRESENT_HTML_BC = "_fitch_present_dc.html";
111 public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_D = "_dollo_gains_d";
112 public final static String PARSIMONY_OUTPUT_DOLLO_GAINS_HTML_D = "_dollo_gains_d.html";
113 public final static String PARSIMONY_OUTPUT_DOLLO_LOSSES_D = "_dollo_losses_d";
114 public final static String PARSIMONY_OUTPUT_DOLLO_LOSSES_HTML_D = "_dollo_losses_d.html";
115 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_D = "_dollo_present_d";
116 public final static String PARSIMONY_OUTPUT_DOLLO_PRESENT_HTML_D = "_dollo_present_d.html";
117 public final static String DOMAINS_PRESENT_NEXUS = "_dom.nex";
118 public final static String BDC_PRESENT_NEXUS = "_dc.nex";
120 public final static String PRG_NAME = "surfacing";
121 public static final String DOMAINS_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_d_dollo"
122 + ForesterConstants.PHYLO_XML_SUFFIX;
123 public static final String DOMAINS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH = "_d_fitch"
124 + ForesterConstants.PHYLO_XML_SUFFIX;
125 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_dc_dollo"
126 + ForesterConstants.PHYLO_XML_SUFFIX;
127 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH = "_dc_fitch"
128 + ForesterConstants.PHYLO_XML_SUFFIX;
129 public static final String NEXUS_EXTERNAL_DOMAINS = "_dom.nex";
130 public static final String NEXUS_EXTERNAL_DOMAIN_COMBINATIONS = "_dc.nex";
131 public static final String NEXUS_SECONDARY_FEATURES = "_secondary_features.nex";
132 public static final String PARSIMONY_OUTPUT_GL_SUFFIX_DOLLO_SECONDARY_FEATURES = "_dollo_gl_secondary_features";
133 public static final String PARSIMONY_OUTPUT_GL_COUNTS_SUFFIX_DOLLO_SECONDARY_FEATURES = "_dollo_glc_secondary_features";
134 public static final String PARSIMONY_OUTPUT_DOLLO_GAINS_SECONDARY_FEATURES = "_dollo_gains_secondary_features";
135 public static final String PARSIMONY_OUTPUT_DOLLO_LOSSES_SECONDARY_FEATURES = "_dollo_losses_secondary_features";
136 public static final String PARSIMONY_OUTPUT_DOLLO_PRESENT_SECONDARY_FEATURES = "_dollo_present_secondary_features";
137 public static final String SECONDARY_FEATURES_PARSIMONY_TREE_OUTPUT_SUFFIX_DOLLO = "_secondary_features_dollo"
138 + ForesterConstants.PHYLO_XML_SUFFIX;
139 public static final String PARSIMONY_OUTPUT_DOLLO_ALL_GOID_D_ALL_NAMESPACES = "_dollo_goid_d";
140 public static final String PARSIMONY_OUTPUT_FITCH_ALL_GOID_BC_ALL_NAMESPACES = "_fitch_goid_dc";
141 final static private String HELP_OPTION_1 = "help";
142 final static private String HELP_OPTION_2 = "h";
143 final static private String OUTPUT_DIR_OPTION = "out_dir";
144 final static private String SCORING_OPTION = "scoring";
145 private static final DomainSimilarityScoring SCORING_DEFAULT = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
146 final static private String SCORING_DOMAIN_COUNT_BASED = "domains";
147 final static private String SCORING_PROTEIN_COUNT_BASED = "proteins";
148 final static private String SCORING_COMBINATION_BASED = "combinations";
149 final static private String DETAILEDNESS_OPTION = "detail";
150 private final static Detailedness DETAILEDNESS_DEFAULT = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
151 final static private String SPECIES_MATRIX_OPTION = "smatrix";
152 final static private String DETAILEDNESS_BASIC = "basic";
153 final static private String DETAILEDNESS_LIST_IDS = "list_ids";
154 final static private String DETAILEDNESS_PUNCTILIOUS = "punctilious";
155 final static private String DOMAIN_SIMILARITY_SORT_OPTION = "sort";
156 private static final DomainSimilarity.DomainSimilaritySortField DOMAIN_SORT_FILD_DEFAULT = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
157 final static private String DOMAIN_SIMILARITY_SORT_MIN = "min";
158 final static private String DOMAIN_SIMILARITY_SORT_MAX = "max";
159 final static private String DOMAIN_SIMILARITY_SORT_SD = "sd";
160 final static private String DOMAIN_SIMILARITY_SORT_MEAN = "mean";
161 final static private String DOMAIN_SIMILARITY_SORT_DIFF = "diff";
162 final static private String DOMAIN_SIMILARITY_SORT_COUNTS_DIFF = "count_diff";
163 final static private String DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF = "abs_count_diff";
164 final static private String DOMAIN_SIMILARITY_SORT_SPECIES_COUNT = "species";
165 final static private String DOMAIN_SIMILARITY_SORT_ALPHA = "alpha";
166 final static private String DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION = "species_first";
167 final static private String DOMAIN_COUNT_SORT_OPTION = "dc_sort";
168 private static final GenomeWideCombinableDomainsSortOrder DOMAINS_SORT_ORDER_DEFAULT = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
169 final static private String DOMAIN_COUNT_SORT_ALPHA = "alpha";
170 final static private String DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT = "dom";
171 final static private String DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT = "prot";
172 final static private String DOMAIN_COUNT_SORT_COMBINATIONS_COUNT = "comb";
173 final static private String CUTOFF_SCORE_FILE_OPTION = "cos";
174 final static private String NOT_IGNORE_DUFS_OPTION = "dufs";
175 final static private String MAX_FS_E_VALUE_OPTION = "fs_e";
176 final static private String MAX_I_E_VALUE_OPTION = "ie";
177 final static private String MAX_ALLOWED_OVERLAP_OPTION = "mo";
178 final static private String NO_ENGULFING_OVERLAP_OPTION = "no_eo";
179 final static private String IGNORE_COMBINATION_WITH_SAME_OPTION = "ignore_self_comb";
180 final static private String PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION = "dc_regain_stats";
181 final static private String DA_ANALYSIS_OPTION = "da_analyis";
182 final static private String USE_LAST_IN_FITCH_OPTION = "last";
183 public final static String PAIRWISE_DOMAIN_COMPARISONS_PREFIX = "pwc_";
184 final static private String PAIRWISE_DOMAIN_COMPARISONS_OPTION = "pwc";
185 final static private String OUTPUT_FILE_OPTION = "o";
186 final static private String PFAM_TO_GO_FILE_USE_OPTION = "p2g";
187 final static private String GO_OBO_FILE_USE_OPTION = "obo";
188 final static private String GO_NAMESPACE_LIMIT_OPTION = "go_namespace";
189 final static private String GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION = "molecular_function";
190 final static private String GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS = "biological_process";
191 final static private String GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT = "cellular_component";
192 final static private String SECONDARY_FEATURES_PARSIMONY_MAP_FILE = "secondary";
193 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED = "simple_tab";
194 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML = "simple_html";
195 final static private String DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML = "detailed_html";
196 final static private String DOMAIN_SIMILARITY_PRINT_OPTION = "ds_output";
197 private static final PRINT_OPTION DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT = DomainSimilarity.PRINT_OPTION.HTML;
198 final static private String IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION = "ignore_singlet_domains";
199 final static private String IGNORE_VIRAL_IDS = "ignore_viral_ids";
200 final static private boolean IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT = false;
201 final static private String IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION = "ignore_species_specific_domains";
202 final static private boolean IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT = false;
203 final static private String MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score.pwd";
204 final static private String MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains.pwd";
205 final static private String MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations.pwd";
206 final static private String NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX = "_mean_score_NJ"
207 + ForesterConstants.PHYLO_XML_SUFFIX;
208 final static private String NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX = "_domains_NJ"
209 + ForesterConstants.PHYLO_XML_SUFFIX;
210 final static private String NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX = "_bin_combinations_NJ"
211 + ForesterConstants.PHYLO_XML_SUFFIX;
212 final static private String FILTER_POSITIVE_OPTION = "pos_filter";
213 final static private String FILTER_NEGATIVE_OPTION = "neg_filter";
214 final static private String FILTER_NEGATIVE_DOMAINS_OPTION = "neg_dom_filter";
215 final static private String INPUT_GENOMES_FILE_OPTION = "genomes";
216 final static private String INPUT_SPECIES_TREE_OPTION = "species_tree";
217 final static private String SEQ_EXTRACT_OPTION = "prot_extract";
218 final static private String PRG_VERSION = "2.404";
219 final static private String PRG_DATE = "140709";
220 final static private String E_MAIL = "czmasek@burnham.org";
221 final static private String WWW = "https://sites.google.com/site/cmzmasek/home/software/forester/surfacing";
222 final static private boolean IGNORE_DUFS_DEFAULT = true;
223 final static private boolean IGNORE_COMBINATION_WITH_SAME_DEFAULLT = false;
224 final static private double MAX_E_VALUE_DEFAULT = -1;
225 public final static int MAX_ALLOWED_OVERLAP_DEFAULT = -1;
226 private static final String RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION = "random_seed";
227 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS = "consider_bdc_direction";
228 private static final String CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY = "consider_bdc_adj";
229 public static final String SEQ_EXTRACT_SUFFIX = ".prot";
230 public static final String PLUS_MINUS_ANALYSIS_OPTION = "plus_minus";
231 public static final String PLUS_MINUS_DOM_SUFFIX = "_plus_minus_dom.txt";
232 public static final String PLUS_MINUS_DOM_SUFFIX_HTML = "_plus_minus_dom.html";
233 public static final String PLUS_MINUS_DC_SUFFIX_HTML = "_plus_minus_dc.html";
234 public static final int PLUS_MINUS_ANALYSIS_MIN_DIFF_DEFAULT = 0;
235 public static final double PLUS_MINUS_ANALYSIS_FACTOR_DEFAULT = 1.0;
236 public static final String PLUS_MINUS_ALL_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_all.txt";
237 public static final String PLUS_MINUS_PASSING_GO_IDS_DOM_SUFFIX = "_plus_minus_go_ids_passing.txt";
238 private static final String OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS = "all_prot";
239 final static private String OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION = "all_prot_e";
240 public static final boolean VERBOSE = false;
241 private static final String OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_gains_counts";
242 private static final String OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX = "_fitch_dc_losses_counts";
243 private static final String DOMAIN_LENGTHS_ANALYSIS_SUFFIX = "_domain_lengths_analysis";
244 private static final String PERFORM_DOMAIN_LENGTH_ANALYSIS_OPTION = "dla";
245 public static final String ALL_PFAMS_ENCOUNTERED_SUFFIX = "_all_encountered_pfams";
246 public static final String ALL_PFAMS_ENCOUNTERED_WITH_GO_ANNOTATION_SUFFIX = "_all_encountered_pfams_with_go_annotation";
247 public static final String ENCOUNTERED_PFAMS_SUMMARY_SUFFIX = "_encountered_pfams_summary";
248 public static final String ALL_PFAMS_GAINED_AS_DOMAINS_SUFFIX = "_all_pfams_gained_as_domains";
249 public static final String ALL_PFAMS_LOST_AS_DOMAINS_SUFFIX = "_all_pfams_lost_as_domains";
250 public static final String ALL_PFAMS_GAINED_AS_DC_SUFFIX = "_all_pfams_gained_as_dc";
251 public static final String ALL_PFAMS_LOST_AS_DC_SUFFIX = "_all_pfams_lost_as_dc";
252 public static final String BASE_DIRECTORY_PER_NODE_DOMAIN_GAIN_LOSS_FILES = "PER_NODE_EVENTS";
253 public static final String BASE_DIRECTORY_PER_SUBTREE_DOMAIN_GAIN_LOSS_FILES = "PER_SUBTREE_EVENTS";
254 public static final String D_PROMISCUITY_FILE_SUFFIX = "_domain_promiscuities";
255 private static final String LOG_FILE_SUFFIX = "_log.txt";
256 private static final String DATA_FILE_SUFFIX = "_domain_combination_data.txt";
257 private static final String DATA_FILE_DESC = "#SPECIES\tPRTEIN_ID\tN_TERM_DOMAIN\tC_TERM_DOMAIN\tN_TERM_DOMAIN_PER_DOMAIN_E_VALUE\tC_TERM_DOMAIN_PER_DOMAIN_E_VALUE\tN_TERM_DOMAIN_COUNTS_PER_PROTEIN\tC_TERM_DOMAIN_COUNTS_PER_PROTEIN";
258 private static final String WRITE_TO_NEXUS_OPTION = "nexus";
259 private static final String PERFORM_DC_FITCH = "dc_pars";
260 private static final INDIVIDUAL_SCORE_CUTOFF INDIVIDUAL_SCORE_CUTOFF_DEFAULT = INDIVIDUAL_SCORE_CUTOFF.FULL_SEQUENCE; //TODO look at me! change?
261 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_COUNTS_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_counts.txt";
262 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_lists.txt";
263 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_FOR_GO_MAPPING_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_lists_for_go_mapping.txt";
264 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";
265 public static final String LIMIT_SPEC_FOR_PROT_EX = null; // e.g. "HUMAN"; set to null for not using this feature (default).
266 public static final String BINARY_DOMAIN_COMBINATIONS_PARSIMONY_TREE_OUTPUT_SUFFIX_FITCH_MAPPED = "_dc_MAPPED_secondary_features_fitch"
267 + ForesterConstants.PHYLO_XML_SUFFIX;
268 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_COUNTS_MAPPED_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_counts_MAPPED.txt";
269 public static final String INDEPENDENT_DC_GAINS_FITCH_PARS_DC_MAPPED_OUTPUT_SUFFIX = "_indep_dc_gains_fitch_lists_MAPPED.txt";
270 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";
271 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";
272 private static final boolean CALC_SIMILARITY_SCORES = false;
274 public static void main( final String args[] ) {
275 final long start_time = new Date().getTime();
276 // final StringBuffer log = new StringBuffer();
277 final StringBuilder html_desc = new StringBuilder();
278 ForesterUtil.printProgramInformation( surfacing.PRG_NAME,
279 surfacing.PRG_VERSION,
283 final String nl = ForesterUtil.LINE_SEPARATOR;
284 html_desc.append( "<table>" + nl );
285 html_desc.append( "<tr><td>Produced by:</td><td>" + surfacing.PRG_NAME + "</td></tr>" + nl );
286 html_desc.append( "<tr><td>Version:</td><td>" + surfacing.PRG_VERSION + "</td></tr>" + nl );
287 html_desc.append( "<tr><td>Release Date:</td><td>" + surfacing.PRG_DATE + "</td></tr>" + nl );
288 html_desc.append( "<tr><td>Contact:</td><td>" + surfacing.E_MAIL + "</td></tr>" + nl );
289 html_desc.append( "<tr><td>WWW:</td><td>" + surfacing.WWW + "</td></tr>" + nl );
290 CommandLineArguments cla = null;
292 cla = new CommandLineArguments( args );
294 catch ( final Exception e ) {
295 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
297 if ( cla.isOptionSet( surfacing.HELP_OPTION_1 ) || cla.isOptionSet( surfacing.HELP_OPTION_2 ) ) {
298 surfacing.printHelp();
301 if ( ( args.length < 1 ) ) {
302 surfacing.printHelp();
305 final List<String> allowed_options = new ArrayList<String>();
306 allowed_options.add( surfacing.NOT_IGNORE_DUFS_OPTION );
307 allowed_options.add( surfacing.MAX_FS_E_VALUE_OPTION );
308 allowed_options.add( surfacing.MAX_I_E_VALUE_OPTION );
309 allowed_options.add( surfacing.DETAILEDNESS_OPTION );
310 allowed_options.add( surfacing.OUTPUT_FILE_OPTION );
311 allowed_options.add( surfacing.DOMAIN_SIMILARITY_SORT_OPTION );
312 allowed_options.add( surfacing.SPECIES_MATRIX_OPTION );
313 allowed_options.add( surfacing.SCORING_OPTION );
314 allowed_options.add( surfacing.MAX_ALLOWED_OVERLAP_OPTION );
315 allowed_options.add( surfacing.NO_ENGULFING_OVERLAP_OPTION );
316 allowed_options.add( surfacing.DOMAIN_COUNT_SORT_OPTION );
317 allowed_options.add( surfacing.CUTOFF_SCORE_FILE_OPTION );
318 allowed_options.add( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION );
319 allowed_options.add( surfacing.OUTPUT_DIR_OPTION );
320 allowed_options.add( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION );
321 allowed_options.add( surfacing.PFAM_TO_GO_FILE_USE_OPTION );
322 allowed_options.add( surfacing.GO_OBO_FILE_USE_OPTION );
323 allowed_options.add( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION );
324 allowed_options.add( surfacing.GO_NAMESPACE_LIMIT_OPTION );
325 allowed_options.add( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
326 allowed_options.add( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION );
327 allowed_options.add( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS );
328 allowed_options.add( INPUT_SPECIES_TREE_OPTION );
329 allowed_options.add( FILTER_POSITIVE_OPTION );
330 allowed_options.add( FILTER_NEGATIVE_OPTION );
331 allowed_options.add( INPUT_GENOMES_FILE_OPTION );
332 allowed_options.add( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
333 allowed_options.add( FILTER_NEGATIVE_DOMAINS_OPTION );
334 allowed_options.add( IGNORE_VIRAL_IDS );
335 allowed_options.add( SEQ_EXTRACT_OPTION );
336 allowed_options.add( OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION );
337 allowed_options.add( SECONDARY_FEATURES_PARSIMONY_MAP_FILE );
338 allowed_options.add( PLUS_MINUS_ANALYSIS_OPTION );
339 allowed_options.add( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS );
340 allowed_options.add( DOMAIN_COMBINITONS_COUNTS_OUTPUT_OPTION );
341 allowed_options.add( OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS );
342 allowed_options.add( CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY );
343 allowed_options.add( WRITE_TO_NEXUS_OPTION );
344 allowed_options.add( PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION );
345 allowed_options.add( DA_ANALYSIS_OPTION );
346 allowed_options.add( USE_LAST_IN_FITCH_OPTION );
347 allowed_options.add( PERFORM_DC_FITCH );
348 allowed_options.add( PERFORM_DOMAIN_LENGTH_ANALYSIS_OPTION );
349 boolean ignore_dufs = surfacing.IGNORE_DUFS_DEFAULT;
350 boolean ignore_combination_with_same = surfacing.IGNORE_COMBINATION_WITH_SAME_DEFAULLT;
351 double fs_e_value_max = surfacing.MAX_E_VALUE_DEFAULT;
352 double ie_value_max = surfacing.MAX_E_VALUE_DEFAULT;
353 int max_allowed_overlap = surfacing.MAX_ALLOWED_OVERLAP_DEFAULT;
354 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
355 if ( dissallowed_options.length() > 0 ) {
356 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown option(s): " + dissallowed_options );
358 boolean use_last_in_fitch_parsimony = false;
359 if ( cla.isOptionSet( USE_LAST_IN_FITCH_OPTION ) ) {
360 use_last_in_fitch_parsimony = true;
362 boolean write_to_nexus = false;
363 if ( cla.isOptionSet( WRITE_TO_NEXUS_OPTION ) ) {
364 write_to_nexus = true;
366 boolean perform_dc_fich = false;
367 if ( cla.isOptionSet( PERFORM_DC_FITCH ) ) {
368 perform_dc_fich = true;
370 boolean perform_dc_regain_proteins_stats = false;
371 if ( cla.isOptionSet( PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION ) ) {
372 perform_dc_regain_proteins_stats = true;
374 boolean da_analysis = false;
375 if ( cla.isOptionSet( DA_ANALYSIS_OPTION ) ) {
378 boolean output_binary_domain_combinationsfor_graph_analysis = false;
379 if ( cla.isOptionSet( DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS ) ) {
380 output_binary_domain_combinationsfor_graph_analysis = true;
382 boolean output_binary_domain_combinationsfor_counts = false;
383 if ( cla.isOptionSet( DOMAIN_COMBINITONS_COUNTS_OUTPUT_OPTION ) ) {
384 output_binary_domain_combinationsfor_counts = true;
386 if ( cla.isOptionSet( surfacing.MAX_FS_E_VALUE_OPTION ) ) {
388 fs_e_value_max = cla.getOptionValueAsDouble( surfacing.MAX_FS_E_VALUE_OPTION );
390 catch ( final Exception e ) {
391 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for E-value maximum" );
394 if ( cla.isOptionSet( surfacing.MAX_I_E_VALUE_OPTION ) ) {
396 ie_value_max = cla.getOptionValueAsDouble( surfacing.MAX_I_E_VALUE_OPTION );
398 catch ( final Exception e ) {
399 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for E-value maximum" );
402 if ( cla.isOptionSet( surfacing.MAX_ALLOWED_OVERLAP_OPTION ) ) {
404 max_allowed_overlap = cla.getOptionValueAsInt( surfacing.MAX_ALLOWED_OVERLAP_OPTION );
406 catch ( final Exception e ) {
407 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for maximal allowed domain overlap" );
410 boolean no_engulfing_overlaps = false;
411 if ( cla.isOptionSet( surfacing.NO_ENGULFING_OVERLAP_OPTION ) ) {
412 no_engulfing_overlaps = true;
414 boolean ignore_virus_like_ids = false;
415 if ( cla.isOptionSet( surfacing.IGNORE_VIRAL_IDS ) ) {
416 ignore_virus_like_ids = true;
418 if ( cla.isOptionSet( surfacing.NOT_IGNORE_DUFS_OPTION ) ) {
421 if ( cla.isOptionSet( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION ) ) {
422 ignore_combination_with_same = true;
424 boolean domain_length_analysis = false;
425 if ( cla.isOptionSet( surfacing.PERFORM_DOMAIN_LENGTH_ANALYSIS_OPTION ) ) {
426 domain_length_analysis = true;
428 boolean ignore_domains_without_combs_in_all_spec = IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_DEFAULT;
429 if ( cla.isOptionSet( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION ) ) {
430 ignore_domains_without_combs_in_all_spec = true;
432 boolean ignore_species_specific_domains = IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION_DEFAULT;
433 if ( cla.isOptionSet( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION ) ) {
434 ignore_species_specific_domains = true;
436 if ( !cla.isOptionValueSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
437 ForesterUtil.fatalError( surfacing.PRG_NAME, "no input species tree file given: "
438 + surfacing.INPUT_SPECIES_TREE_OPTION + "=<file>" );
440 File output_file = null;
441 if ( cla.isOptionSet( surfacing.OUTPUT_FILE_OPTION ) ) {
442 if ( !cla.isOptionValueSet( surfacing.OUTPUT_FILE_OPTION ) ) {
443 ForesterUtil.fatalError( surfacing.PRG_NAME,
444 "no value for domain combinations similarities output file: -"
445 + surfacing.OUTPUT_FILE_OPTION + "=<file>" );
447 output_file = new File( cla.getOptionValue( surfacing.OUTPUT_FILE_OPTION ) );
448 SurfacingUtil.checkForOutputFileWriteability( output_file );
450 File cutoff_scores_file = null;
451 Map<String, Double> individual_score_cutoffs = null;
452 if ( cla.isOptionSet( surfacing.CUTOFF_SCORE_FILE_OPTION ) ) {
453 if ( !cla.isOptionValueSet( surfacing.CUTOFF_SCORE_FILE_OPTION ) ) {
454 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for individual domain score cutoffs file: -"
455 + surfacing.CUTOFF_SCORE_FILE_OPTION + "=<file>" );
457 cutoff_scores_file = new File( cla.getOptionValue( surfacing.CUTOFF_SCORE_FILE_OPTION ) );
458 final String error = ForesterUtil.isReadableFile( cutoff_scores_file );
459 if ( !ForesterUtil.isEmpty( error ) ) {
460 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read individual domain score cutoffs file: "
464 final BasicTable<String> scores_table = BasicTableParser.parse( cutoff_scores_file, ' ' );
465 individual_score_cutoffs = scores_table.getColumnsAsMapDouble( 0, 1 );
467 catch ( final IOException e ) {
468 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from individual score cutoffs file: " + e );
471 BinaryDomainCombination.DomainCombinationType dc_type = BinaryDomainCombination.DomainCombinationType.BASIC;
472 if ( cla.isOptionSet( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS ) ) {
473 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED;
475 if ( cla.isOptionSet( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY ) ) {
476 dc_type = BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT;
479 if ( cla.isOptionSet( surfacing.OUTPUT_DIR_OPTION ) ) {
480 if ( !cla.isOptionValueSet( surfacing.OUTPUT_DIR_OPTION ) ) {
481 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for output directory: -"
482 + surfacing.OUTPUT_DIR_OPTION + "=<dir>" );
484 out_dir = new File( cla.getOptionValue( surfacing.OUTPUT_DIR_OPTION ) );
485 if ( out_dir.exists() && ( out_dir.listFiles().length > 0 ) ) {
486 ForesterUtil.fatalError( surfacing.PRG_NAME, "\"" + out_dir + "\" aready exists and is not empty" );
488 if ( !out_dir.exists() ) {
489 final boolean success = out_dir.mkdir();
490 if ( !success || !out_dir.exists() ) {
491 ForesterUtil.fatalError( surfacing.PRG_NAME, "failed to create \"" + out_dir + "\"" );
494 if ( !out_dir.canWrite() ) {
495 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot write to \"" + out_dir + "\"" );
498 File positive_filter_file = null;
499 File negative_filter_file = null;
500 File negative_domains_filter_file = null;
501 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) && cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
502 ForesterUtil.fatalError( surfacing.PRG_NAME, "attempt to use both negative and positive protein filter" );
504 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION )
505 && ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) || cla
506 .isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) ) {
508 .fatalError( surfacing.PRG_NAME,
509 "attempt to use both negative or positive protein filter together wirh a negative domains filter" );
511 if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_OPTION ) ) {
512 if ( !cla.isOptionValueSet( surfacing.FILTER_NEGATIVE_OPTION ) ) {
513 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for negative filter: -"
514 + surfacing.FILTER_NEGATIVE_OPTION + "=<file>" );
516 negative_filter_file = new File( cla.getOptionValue( surfacing.FILTER_NEGATIVE_OPTION ) );
517 final String msg = ForesterUtil.isReadableFile( negative_filter_file );
518 if ( !ForesterUtil.isEmpty( msg ) ) {
519 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + negative_filter_file + "\": "
523 else if ( cla.isOptionSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
524 if ( !cla.isOptionValueSet( surfacing.FILTER_POSITIVE_OPTION ) ) {
525 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for positive filter: -"
526 + surfacing.FILTER_POSITIVE_OPTION + "=<file>" );
528 positive_filter_file = new File( cla.getOptionValue( surfacing.FILTER_POSITIVE_OPTION ) );
529 final String msg = ForesterUtil.isReadableFile( positive_filter_file );
530 if ( !ForesterUtil.isEmpty( msg ) ) {
531 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + positive_filter_file + "\": "
535 else if ( cla.isOptionSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
536 if ( !cla.isOptionValueSet( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) ) {
537 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for negative domains filter: -"
538 + surfacing.FILTER_NEGATIVE_DOMAINS_OPTION + "=<file>" );
540 negative_domains_filter_file = new File( cla.getOptionValue( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION ) );
541 final String msg = ForesterUtil.isReadableFile( negative_domains_filter_file );
542 if ( !ForesterUtil.isEmpty( msg ) ) {
543 ForesterUtil.fatalError( surfacing.PRG_NAME, "can not read from \"" + negative_domains_filter_file
547 final List<String> plus_minus_analysis_high_copy_base_species = new ArrayList<String>();
548 final List<String> plus_minus_analysis_high_copy_target_species = new ArrayList<String>();
549 final List<String> plus_minus_analysis_high_low_copy_species = new ArrayList<String>();
550 final List<Object> plus_minus_analysis_numbers = new ArrayList<Object>();
551 SurfacingUtil.processPlusMinusAnalysisOption( cla,
552 plus_minus_analysis_high_copy_base_species,
553 plus_minus_analysis_high_copy_target_species,
554 plus_minus_analysis_high_low_copy_species,
555 plus_minus_analysis_numbers );
556 File input_genomes_file = null;
557 if ( cla.isOptionSet( surfacing.INPUT_GENOMES_FILE_OPTION ) ) {
558 if ( !cla.isOptionValueSet( surfacing.INPUT_GENOMES_FILE_OPTION ) ) {
559 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for input genomes file: -"
560 + surfacing.INPUT_GENOMES_FILE_OPTION + "=<file>" );
562 input_genomes_file = new File( cla.getOptionValue( surfacing.INPUT_GENOMES_FILE_OPTION ) );
563 final String msg = ForesterUtil.isReadableFile( input_genomes_file );
564 if ( !ForesterUtil.isEmpty( msg ) ) {
566 .fatalError( surfacing.PRG_NAME, "can not read from \"" + input_genomes_file + "\": " + msg );
570 ForesterUtil.fatalError( surfacing.PRG_NAME, "no input genomes file given: "
571 + surfacing.INPUT_GENOMES_FILE_OPTION + "=<file>" );
573 DomainSimilarity.DomainSimilarityScoring scoring = SCORING_DEFAULT;
574 if ( cla.isOptionSet( surfacing.SCORING_OPTION ) ) {
575 if ( !cla.isOptionValueSet( surfacing.SCORING_OPTION ) ) {
576 ForesterUtil.fatalError( surfacing.PRG_NAME,
577 "no value for scoring method for domain combinations similarity calculation: -"
578 + surfacing.SCORING_OPTION + "=<"
579 + surfacing.SCORING_DOMAIN_COUNT_BASED + "|"
580 + surfacing.SCORING_PROTEIN_COUNT_BASED + "|"
581 + surfacing.SCORING_COMBINATION_BASED + ">\"" );
583 final String scoring_str = cla.getOptionValue( surfacing.SCORING_OPTION );
584 if ( scoring_str.equals( surfacing.SCORING_DOMAIN_COUNT_BASED ) ) {
585 scoring = DomainSimilarity.DomainSimilarityScoring.DOMAINS;
587 else if ( scoring_str.equals( surfacing.SCORING_COMBINATION_BASED ) ) {
588 scoring = DomainSimilarity.DomainSimilarityScoring.COMBINATIONS;
590 else if ( scoring_str.equals( surfacing.SCORING_PROTEIN_COUNT_BASED ) ) {
591 scoring = DomainSimilarity.DomainSimilarityScoring.PROTEINS;
594 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + scoring_str
595 + "\" for scoring method for domain combinations similarity calculation: \"-"
596 + surfacing.SCORING_OPTION + "=<" + surfacing.SCORING_DOMAIN_COUNT_BASED + "|"
597 + surfacing.SCORING_PROTEIN_COUNT_BASED + "|" + surfacing.SCORING_COMBINATION_BASED + ">\"" );
600 boolean sort_by_species_count_first = false;
601 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION ) ) {
602 sort_by_species_count_first = true;
604 boolean species_matrix = false;
605 if ( cla.isOptionSet( surfacing.SPECIES_MATRIX_OPTION ) ) {
606 species_matrix = true;
608 boolean output_protein_lists_for_all_domains = false;
609 double output_list_of_all_proteins_per_domain_e_value_max = -1;
610 if ( cla.isOptionSet( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS ) ) {
611 output_protein_lists_for_all_domains = true;
612 if ( cla.isOptionSet( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION ) ) {
614 output_list_of_all_proteins_per_domain_e_value_max = cla
615 .getOptionValueAsDouble( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION );
617 catch ( final Exception e ) {
618 ForesterUtil.fatalError( surfacing.PRG_NAME, "no acceptable value for per domain E-value maximum" );
622 Detailedness detailedness = DETAILEDNESS_DEFAULT;
623 if ( cla.isOptionSet( surfacing.DETAILEDNESS_OPTION ) ) {
624 if ( !cla.isOptionValueSet( surfacing.DETAILEDNESS_OPTION ) ) {
625 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for -" + surfacing.DETAILEDNESS_OPTION + "=<"
626 + surfacing.DETAILEDNESS_BASIC + "|" + surfacing.DETAILEDNESS_LIST_IDS + "|"
627 + surfacing.DETAILEDNESS_PUNCTILIOUS + ">\"" );
629 final String detness = cla.getOptionValue( surfacing.DETAILEDNESS_OPTION ).toLowerCase();
630 if ( detness.equals( surfacing.DETAILEDNESS_BASIC ) ) {
631 detailedness = DomainSimilarityCalculator.Detailedness.BASIC;
633 else if ( detness.equals( surfacing.DETAILEDNESS_LIST_IDS ) ) {
634 detailedness = DomainSimilarityCalculator.Detailedness.LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES;
636 else if ( detness.equals( surfacing.DETAILEDNESS_PUNCTILIOUS ) ) {
637 detailedness = DomainSimilarityCalculator.Detailedness.PUNCTILIOUS;
640 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + detness + "\" for detailedness: \"-"
641 + surfacing.DETAILEDNESS_OPTION + "=<" + surfacing.DETAILEDNESS_BASIC + "|"
642 + surfacing.DETAILEDNESS_LIST_IDS + "|" + surfacing.DETAILEDNESS_PUNCTILIOUS + ">\"" );
645 String automated_pairwise_comparison_suffix = null;
646 boolean perform_pwc = false;
647 boolean write_pwc_files = false;
648 if ( cla.isOptionSet( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
650 if ( !cla.isOptionValueSet( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION ) ) {
651 write_pwc_files = false;
654 write_pwc_files = true;
655 automated_pairwise_comparison_suffix = "_"
656 + cla.getOptionValue( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION );
659 String query_domain_ids = null;
660 if ( cla.isOptionSet( surfacing.SEQ_EXTRACT_OPTION ) ) {
661 if ( !cla.isOptionValueSet( surfacing.SEQ_EXTRACT_OPTION ) ) {
663 .fatalError( surfacing.PRG_NAME,
664 "no domain ids given for sequences with given domains to be extracted : -"
665 + surfacing.SEQ_EXTRACT_OPTION
666 + "=<ordered domain sequences, domain ids separated by '~', sequences separated by '#'>" );
668 query_domain_ids = cla.getOptionValue( surfacing.SEQ_EXTRACT_OPTION );
670 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field = DOMAIN_SORT_FILD_DEFAULT;
671 DomainSimilarity.DomainSimilaritySortField domain_similarity_sort_field_for_automated_pwc = DOMAIN_SORT_FILD_DEFAULT;
672 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
673 if ( !cla.isOptionValueSet( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ) ) {
674 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for domain combinations similarities sorting: -"
675 + surfacing.DOMAIN_SIMILARITY_SORT_OPTION + "=<" + surfacing.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
676 + surfacing.DOMAIN_SIMILARITY_SORT_MAX + "|" + surfacing.DOMAIN_SIMILARITY_SORT_MIN + "|"
677 + surfacing.DOMAIN_SIMILARITY_SORT_MEAN + "|" + surfacing.DOMAIN_SIMILARITY_SORT_DIFF + "|"
678 + surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
679 + surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|"
680 + surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|" + surfacing.DOMAIN_SIMILARITY_SORT_SD
683 final String sort_str = cla.getOptionValue( surfacing.DOMAIN_SIMILARITY_SORT_OPTION ).toLowerCase();
684 if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_ALPHA ) ) {
685 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
686 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
688 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MAX ) ) {
689 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX;
690 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
692 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MIN ) ) {
693 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MIN;
694 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
696 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_MEAN ) ) {
697 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MEAN;
698 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MEAN;
700 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT ) ) {
701 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SPECIES_COUNT;
702 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
704 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_SD ) ) {
705 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.SD;
706 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.DOMAIN_ID;
708 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_DIFF ) ) {
709 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
710 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_DIFFERENCE;
712 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF ) ) {
713 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
714 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
716 else if ( sort_str.equals( surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF ) ) {
717 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
718 domain_similarity_sort_field_for_automated_pwc = DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE;
721 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort_str
722 + "\" for domain combinations similarities sorting: \"-"
723 + surfacing.DOMAIN_SIMILARITY_SORT_OPTION + "=<" + surfacing.DOMAIN_SIMILARITY_SORT_ALPHA + "|"
724 + surfacing.DOMAIN_SIMILARITY_SORT_MAX + "|" + surfacing.DOMAIN_SIMILARITY_SORT_MIN + "|"
725 + surfacing.DOMAIN_SIMILARITY_SORT_MEAN + "|" + surfacing.DOMAIN_SIMILARITY_SORT_DIFF + "|"
726 + surfacing.DOMAIN_SIMILARITY_SORT_ABS_COUNTS_DIFF + "|"
727 + surfacing.DOMAIN_SIMILARITY_SORT_COUNTS_DIFF + "|" + "|"
728 + surfacing.DOMAIN_SIMILARITY_SORT_SPECIES_COUNT + "|" + surfacing.DOMAIN_SIMILARITY_SORT_SD
732 DomainSimilarity.PRINT_OPTION domain_similarity_print_option = DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT;
733 if ( cla.isOptionSet( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
734 if ( !cla.isOptionValueSet( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ) ) {
735 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for print option: -"
736 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
737 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
738 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
740 final String sort = cla.getOptionValue( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION ).toLowerCase();
741 if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML ) ) {
742 domain_similarity_print_option = DomainSimilarity.PRINT_OPTION.HTML;
744 else if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML ) ) {
745 ForesterUtil.fatalError( surfacing.PRG_NAME, "simple HTML output not implemented yet :(" );
747 else if ( sort.equals( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED ) ) {
748 domain_similarity_print_option = DomainSimilarity.PRINT_OPTION.SIMPLE_TAB_DELIMITED;
751 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort + "\" for print option: -"
752 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_DETAILED_HTML + "|"
753 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_HTML + "|"
754 + surfacing.DOMAIN_SIMILARITY_PRINT_OPTION_SIMPLE_TAB_DELIMITED + ">\"" );
757 GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder dc_sort_order = DOMAINS_SORT_ORDER_DEFAULT;
758 if ( cla.isOptionSet( surfacing.DOMAIN_COUNT_SORT_OPTION ) ) {
759 if ( !cla.isOptionValueSet( surfacing.DOMAIN_COUNT_SORT_OPTION ) ) {
760 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for sorting of domain counts: -"
761 + surfacing.DOMAIN_COUNT_SORT_OPTION + "=<" + surfacing.DOMAIN_COUNT_SORT_ALPHA + "|"
762 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
763 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
764 + surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
766 final String sort = cla.getOptionValue( surfacing.DOMAIN_COUNT_SORT_OPTION ).toLowerCase();
767 if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_ALPHA ) ) {
768 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.ALPHABETICAL_KEY_ID;
770 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT ) ) {
771 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_COUNT;
773 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT ) ) {
774 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.KEY_DOMAIN_PROTEINS_COUNT;
776 else if ( sort.equals( surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT ) ) {
777 dc_sort_order = GenomeWideCombinableDomains.GenomeWideCombinableDomainsSortOrder.COMBINATIONS_COUNT;
780 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + sort
781 + "\" for sorting of domain counts: \"-" + surfacing.DOMAIN_COUNT_SORT_OPTION + "=<"
782 + surfacing.DOMAIN_COUNT_SORT_ALPHA + "|" + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_COUNT + "|"
783 + surfacing.DOMAIN_COUNT_SORT_KEY_DOMAIN_PROTEINS_COUNT + "|"
784 + surfacing.DOMAIN_COUNT_SORT_COMBINATIONS_COUNT + ">\"" );
787 final String[][] input_file_properties = SurfacingUtil.processInputGenomesFile( input_genomes_file );
788 final int number_of_genomes = input_file_properties.length;
789 if ( number_of_genomes < 2 ) {
790 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot analyze less than two files" );
792 if ( ( number_of_genomes < 3 ) && perform_pwc ) {
793 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use : -"
794 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
795 + "=<suffix> to turn on pairwise analyses with less than three input files" );
797 SurfacingUtil.checkWriteabilityForPairwiseComparisons( domain_similarity_print_option,
798 input_file_properties,
799 automated_pairwise_comparison_suffix,
801 for( int i = 0; i < number_of_genomes; i++ ) {
802 File dcc_outfile = new File( input_file_properties[ i ][ 1 ]
803 + surfacing.DOMAIN_COMBINITON_COUNTS_OUTPUTFILE_SUFFIX );
804 if ( out_dir != null ) {
805 dcc_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + dcc_outfile );
807 SurfacingUtil.checkForOutputFileWriteability( dcc_outfile );
809 File pfam_to_go_file = new File( "pfam2go.txt" );
810 if ( cla.isOptionSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
811 if ( !cla.isOptionValueSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
812 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for Pfam to GO mapping file: -"
813 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>" );
815 pfam_to_go_file = new File( cla.getOptionValue( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) );
817 final String error1 = ForesterUtil.isReadableFile( pfam_to_go_file );
818 if ( !ForesterUtil.isEmpty( error1 ) ) {
819 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read Pfam to GO mapping file: " + error1 );
821 Map<String, List<GoId>> domain_id_to_go_ids_map = null;
822 int domain_id_to_go_ids_count = 0;
824 final PfamToGoParser parser = new PfamToGoParser( pfam_to_go_file );
825 final List<PfamToGoMapping> pfam_to_go_mappings = parser.parse();
826 domain_id_to_go_ids_map = SurfacingUtil.createDomainIdToGoIdMap( pfam_to_go_mappings );
827 if ( parser.getMappingCount() < domain_id_to_go_ids_map.size() ) {
828 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME,
829 "parser.getMappingCount() < domain_id_to_go_ids_map.size()" );
831 domain_id_to_go_ids_count = parser.getMappingCount();
833 catch ( final IOException e ) {
834 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from Pfam to GO mapping file: " + e );
836 File go_obo_file = new File( "go.obo" );
837 if ( cla.isOptionSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
838 if ( !cla.isOptionValueSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
839 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for GO OBO file: -"
840 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>" );
842 go_obo_file = new File( cla.getOptionValue( surfacing.GO_OBO_FILE_USE_OPTION ) );
844 final String error2 = ForesterUtil.isReadableFile( go_obo_file );
845 if ( !ForesterUtil.isEmpty( error2 ) ) {
846 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read GO OBO file: " + error2 );
848 List<GoTerm> go_terms = null;
850 final OBOparser parser = new OBOparser( go_obo_file, OBOparser.ReturnType.BASIC_GO_TERM );
851 go_terms = parser.parse();
852 if ( parser.getGoTermCount() != go_terms.size() ) {
853 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "parser.getGoTermCount() != go_terms.size()" );
856 catch ( final IOException e ) {
857 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from GO OBO file: " + e );
859 Map<GoId, GoTerm> go_id_to_term_map = null;
860 if ( ( ( domain_id_to_go_ids_map != null ) && ( domain_id_to_go_ids_map.size() > 0 ) )
861 && ( ( go_terms != null ) && ( go_terms.size() > 0 ) ) ) {
862 go_id_to_term_map = GoUtils.createGoIdToGoTermMap( go_terms );
864 GoNameSpace go_namespace_limit = null;
865 if ( cla.isOptionSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
866 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
867 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use GO namespace limit (-"
868 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<namespace>) without Pfam to GO mapping file ("
869 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>) and GO OBO file (-"
870 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
872 if ( !cla.isOptionValueSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
873 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for GO namespace limit: \"-"
874 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
875 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
876 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
877 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
879 final String go_namespace_limit_str = cla.getOptionValue( surfacing.GO_NAMESPACE_LIMIT_OPTION )
881 if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION ) ) {
882 go_namespace_limit = GoNameSpace.createMolecularFunction();
884 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS ) ) {
885 go_namespace_limit = GoNameSpace.createBiologicalProcess();
887 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT ) ) {
888 go_namespace_limit = GoNameSpace.createCellularComponent();
891 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + go_namespace_limit_str
892 + "\" for GO namespace limit: \"-" + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
893 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
894 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
895 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
898 if ( ( domain_similarity_sort_field == DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE )
899 && ( number_of_genomes > 2 ) ) {
900 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
902 File[] intree_files = null;
903 Phylogeny[] intrees = null;
904 if ( cla.isOptionSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
905 if ( number_of_genomes < 3 ) {
906 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot infer gains and losses on input species trees (-"
907 + surfacing.INPUT_SPECIES_TREE_OPTION + " without pairwise analyses ("
908 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
909 + "=<suffix for pairwise comparison output files>)" );
911 if ( !cla.isOptionValueSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
912 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for input tree: -"
913 + surfacing.INPUT_SPECIES_TREE_OPTION + "=<tree file in phyloXML format>" );
915 final String intrees_str = cla.getOptionValue( surfacing.INPUT_SPECIES_TREE_OPTION );
916 if ( intrees_str.indexOf( "#" ) > 0 ) {
917 final String[] intrees_strs = intrees_str.split( "#" );
918 intree_files = new File[ intrees_strs.length ];
920 for( final String s : intrees_strs ) {
921 intree_files[ i++ ] = new File( s.trim() );
925 intree_files = new File[ 1 ];
926 intree_files[ 0 ] = new File( intrees_str );
928 intrees = SurfacingUtil.obtainAndPreProcessIntrees( intree_files, number_of_genomes, input_file_properties );
930 final Phylogeny intree_0_orig = SurfacingUtil.obtainFirstIntree( intree_files[ 0 ] );
931 long random_number_seed_for_fitch_parsimony = 0l;
932 boolean radomize_fitch_parsimony = false;
933 if ( cla.isOptionSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
934 if ( !cla.isOptionValueSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
935 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for random number seed: -"
936 + surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION + "=<seed>" );
939 random_number_seed_for_fitch_parsimony = cla
940 .getOptionValueAsLong( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
942 catch ( final IOException e ) {
943 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
945 radomize_fitch_parsimony = true;
947 SortedSet<String> filter = null;
948 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
949 || ( negative_domains_filter_file != null ) ) {
950 filter = new TreeSet<String>();
951 if ( positive_filter_file != null ) {
952 SurfacingUtil.processFilter( positive_filter_file, filter );
954 else if ( negative_filter_file != null ) {
955 SurfacingUtil.processFilter( negative_filter_file, filter );
957 else if ( negative_domains_filter_file != null ) {
958 SurfacingUtil.processFilter( negative_domains_filter_file, filter );
961 Map<String, Set<String>>[] domain_id_to_secondary_features_maps = null;
962 File[] secondary_features_map_files = null;
963 final File domain_lengths_analysis_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
964 + DOMAIN_LENGTHS_ANALYSIS_SUFFIX );
965 if ( domain_length_analysis ) {
966 SurfacingUtil.checkForOutputFileWriteability( domain_lengths_analysis_outfile );
968 if ( cla.isOptionSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
969 if ( !cla.isOptionValueSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
970 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for secondary features map file: -"
971 + surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE + "=<file>" );
973 final String[] secondary_features_map_files_strs = cla
974 .getOptionValue( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ).split( "#" );
975 secondary_features_map_files = new File[ secondary_features_map_files_strs.length ];
976 domain_id_to_secondary_features_maps = new Map[ secondary_features_map_files_strs.length ];
978 for( final String secondary_features_map_files_str : secondary_features_map_files_strs ) {
979 secondary_features_map_files[ i ] = new File( secondary_features_map_files_str );
980 final String error = ForesterUtil.isReadableFile( secondary_features_map_files[ i ] );
981 if ( !ForesterUtil.isEmpty( error ) ) {
982 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read secondary features map file: " + error );
985 domain_id_to_secondary_features_maps[ i ] = SurfacingUtil
986 .createDomainIdToSecondaryFeaturesMap( secondary_features_map_files[ i ] );
988 catch ( final IOException e ) {
989 ForesterUtil.fatalError( surfacing.PRG_NAME,
990 "cannot read secondary features map file: " + e.getMessage() );
992 catch ( final Exception e ) {
993 ForesterUtil.fatalError( surfacing.PRG_NAME, "problem with contents of features map file ["
994 + secondary_features_map_files[ i ] + "]: " + e.getMessage() );
999 if ( out_dir == null ) {
1000 ForesterUtil.fatalError( surfacing.PRG_NAME, "no output directory indicated (-"
1001 + surfacing.OUTPUT_DIR_OPTION + "=<dir>)" );
1003 if ( output_file == null ) {
1004 ForesterUtil.fatalError( surfacing.PRG_NAME, "no name for (main) output file indicated (-"
1005 + surfacing.OUTPUT_FILE_OPTION + "=<file>)" );
1007 if ( ( domain_id_to_go_ids_map == null ) || domain_id_to_go_ids_map.isEmpty() ) {
1008 ForesterUtil.fatalError( surfacing.PRG_NAME,
1009 "no (acceptable) Pfam to GO id mapping file provided ('pfam2go file') (-"
1010 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1012 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1013 ForesterUtil.fatalError( surfacing.PRG_NAME,
1014 "no (acceptable) go id to term mapping file provided ('GO OBO file') (-"
1015 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1017 System.out.println( "Output directory : " + out_dir );
1018 System.out.println( "Input genomes from : " + input_genomes_file );
1019 html_desc.append( "<tr><td>Input genomes from:</td><td>" + input_genomes_file + "</td></tr>" + nl );
1020 if ( positive_filter_file != null ) {
1021 final int filter_size = filter.size();
1022 System.out.println( "Positive protein filter : " + positive_filter_file + " [" + filter_size
1024 html_desc.append( "<tr><td>Positive protein filter:</td><td>" + positive_filter_file + " [" + filter_size
1025 + " domain ids]</td></tr>" + nl );
1027 if ( negative_filter_file != null ) {
1028 final int filter_size = filter.size();
1029 System.out.println( "Negative protein filter : " + negative_filter_file + " [" + filter_size
1031 html_desc.append( "<tr><td>Negative protein filter:</td><td>" + negative_filter_file + " [" + filter_size
1032 + " domain ids]</td></tr>" + nl );
1034 if ( negative_domains_filter_file != null ) {
1035 final int filter_size = filter.size();
1036 System.out.println( "Negative domain filter : " + negative_domains_filter_file + " [" + filter_size
1038 html_desc.append( "<tr><td>Negative domain filter:</td><td>" + negative_domains_filter_file + " ["
1039 + filter_size + " domain ids]</td></tr>" + nl );
1041 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
1043 for( final String s : plus_minus_analysis_high_copy_base_species ) {
1044 plus0 += "+" + s + " ";
1047 for( final String s : plus_minus_analysis_high_copy_target_species ) {
1048 plus1 += "*" + s + " ";
1051 for( final String s : plus_minus_analysis_high_low_copy_species ) {
1052 minus += "-" + s + " ";
1054 System.out.println( "Plus-minus analysis : " + plus1 + "&& " + plus0 + "&& " + minus );
1055 html_desc.append( "<tr><td>Plus-minus analysis:</td><td>" + plus1 + "&& " + plus0 + "&& " + minus
1056 + "</td></tr>" + nl );
1058 if ( cutoff_scores_file != null ) {
1059 System.out.println( "Cutoff scores file : " + cutoff_scores_file );
1060 html_desc.append( "<tr><td>Cutoff scores file:</td><td>" + cutoff_scores_file + "</td></tr>" + nl );
1062 if ( ie_value_max >= 0.0 ) {
1063 System.out.println( "iE-value maximum (incl) : " + ie_value_max );
1064 html_desc.append( "<tr><td>iE-value maximum (inclusive):</td><td>" + ie_value_max + "</td></tr>" + nl );
1066 if ( fs_e_value_max >= 0.0 ) {
1067 System.out.println( "FS E-value maximum (incl) : " + fs_e_value_max );
1068 html_desc.append( "<tr><td>FS E-value maximum (inclusive):</td><td>" + fs_e_value_max + "</td></tr>" + nl );
1070 if ( output_protein_lists_for_all_domains ) {
1071 System.out.println( "Domain E-value max : " + output_list_of_all_proteins_per_domain_e_value_max );
1072 html_desc.append( "<tr><td>Protein lists: E-value maximum per domain (inclusive):</td><td>"
1073 + output_list_of_all_proteins_per_domain_e_value_max + "</td></tr>" + nl );
1075 System.out.println( "Ignore DUFs : " + ignore_dufs );
1076 if ( ignore_virus_like_ids ) {
1077 System.out.println( "Ignore virus like ids : " + ignore_virus_like_ids );
1078 html_desc.append( "<tr><td>Ignore virus, phage, transposition related ids:</td><td>"
1079 + ignore_virus_like_ids + "</td></tr>" + nl );
1081 html_desc.append( "<tr><td>Ignore DUFs:</td><td>" + ignore_dufs + "</td></tr>" + nl );
1082 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1083 System.out.println( "Max allowed domain overlap : " + max_allowed_overlap );
1084 html_desc.append( "<tr><td>Max allowed domain overlap:</td><td>" + max_allowed_overlap + "</td></tr>" + nl );
1086 if ( no_engulfing_overlaps ) {
1087 System.out.println( "Ignore engulfed domains : " + no_engulfing_overlaps );
1088 html_desc.append( "<tr><td>Ignore (lower confidence) engulfed domains:</td><td>" + no_engulfing_overlaps
1089 + "</td></tr>" + nl );
1091 System.out.println( "Ignore singlet domains : " + ignore_domains_without_combs_in_all_spec );
1093 .append( "<tr><td>Ignore singlet domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1094 + ignore_domains_without_combs_in_all_spec + "</td></tr>" + nl );
1095 System.out.println( "Ignore species specific doms: " + ignore_species_specific_domains );
1097 .append( "<tr><td>Ignore species specific domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1098 + ignore_species_specific_domains + "</td></tr>" + nl );
1099 System.out.println( "Ignore combination with self: " + ignore_combination_with_same );
1100 html_desc.append( "<tr><td>Ignore combination with self for domain combination similarity analyses:</td><td>"
1101 + ignore_combination_with_same + "</td></tr>" + nl );
1102 System.out.println( "Consider directedness : "
1103 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) );
1104 html_desc.append( "<tr><td>Consider directedness of binary domain combinations:</td><td>"
1105 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) + "</td></tr>" + nl );
1106 if ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) {
1107 System.out.println( "Consider adjacency : "
1108 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) );
1109 html_desc.append( "<tr><td>Consider djacency of binary domain combinations:</td><td>"
1110 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) + "</td></tr>"
1113 System.out.println( "Fitch parsimony of DCs : " + perform_dc_fich );
1114 html_desc.append( "<tr><td>Fitch parsimony of DCs:</td><td>" + perform_dc_fich + "</td></tr>" + nl );
1115 if ( perform_dc_fich ) {
1116 System.out.println( "Use last in Fitch parsimony : " + use_last_in_fitch_parsimony );
1117 html_desc.append( "<tr><td>Use last in Fitch parsimony:</td><td>" + use_last_in_fitch_parsimony
1118 + "</td></tr>" + nl );
1120 System.out.println( "Write to Nexus files : " + write_to_nexus );
1121 html_desc.append( "<tr><td>Write to Nexus files:</td><td>" + write_to_nexus + "</td></tr>" + nl );
1122 if ( perform_dc_fich ) {
1123 System.out.println( "DC regain prot stats : " + perform_dc_regain_proteins_stats );
1124 html_desc.append( "<tr><td>DC regain prot stats:</td><td>" + perform_dc_regain_proteins_stats
1125 + "</td></tr>" + nl );
1127 System.out.println( "DA analysis : " + da_analysis );
1128 html_desc.append( "<tr><td>DA analysis :</td><td>" + da_analysis + "</td></tr>" + nl );
1129 System.out.print( "Domain counts sort order : " );
1130 html_desc.append( "<tr><td>Domain counts sort order:</td><td>" );
1131 switch ( dc_sort_order ) {
1132 case ALPHABETICAL_KEY_ID:
1133 System.out.println( "alphabetical" );
1134 html_desc.append( "alphabetical" + "</td></tr>" + nl );
1136 case KEY_DOMAIN_COUNT:
1137 System.out.println( "domain count" );
1138 html_desc.append( "domain count" + "</td></tr>" + nl );
1140 case KEY_DOMAIN_PROTEINS_COUNT:
1141 System.out.println( "domain proteins count" );
1142 html_desc.append( "domain proteins count" + "</td></tr>" + nl );
1144 case COMBINATIONS_COUNT:
1145 System.out.println( "domain combinations count" );
1146 html_desc.append( "domain combinations count" + "</td></tr>" + nl );
1149 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for dc sort order" );
1151 if ( domain_id_to_go_ids_map != null ) {
1152 System.out.println( "Pfam to GO mappings from : " + pfam_to_go_file + " [" + domain_id_to_go_ids_count
1154 html_desc.append( "<tr><td>Pfam to GO mappings from:</td><td>" + pfam_to_go_file + " ["
1155 + domain_id_to_go_ids_count + " mappings]" + "</td></tr>" + nl );
1157 if ( go_terms != null ) {
1158 System.out.println( "GO terms from : " + go_obo_file + " [" + go_terms.size() + " terms]" );
1159 html_desc.append( "<tr><td>GO terms from:</td><td>" + go_obo_file + " [" + go_terms.size() + " terms]"
1160 + "</td></tr>" + nl );
1162 if ( go_namespace_limit != null ) {
1163 System.out.println( "Limit GO terms to : " + go_namespace_limit.toString() );
1164 html_desc.append( "<tr><td>Limit GO terms to</td><td>" + go_namespace_limit + "</td></tr>" + nl );
1166 if ( perform_pwc ) {
1167 System.out.println( "Suffix for PWC files : " + automated_pairwise_comparison_suffix );
1168 html_desc.append( "<tr><td>Suffix for PWC files</td><td>" + automated_pairwise_comparison_suffix
1169 + "</td></tr>" + nl );
1171 if ( out_dir != null ) {
1172 System.out.println( "Output directory : " + out_dir );
1174 if ( query_domain_ids != null ) {
1175 System.out.println( "Query domains (ordered) : " + query_domain_ids );
1176 html_desc.append( "<tr><td></td><td>" + query_domain_ids + "</td></tr>" + nl );
1178 System.out.println( "Write similarities to : " + output_file );
1179 System.out.print( " Scoring method : " );
1180 html_desc.append( "<tr><td>Scoring method:</td><td>" );
1181 switch ( scoring ) {
1183 System.out.println( "domain combinations based" );
1184 html_desc.append( "domain combinations based" + "</td></tr>" + nl );
1187 System.out.println( "domain counts based" );
1188 html_desc.append( "domain counts based" + "</td></tr>" + nl );
1191 System.out.println( "domain proteins counts based" );
1192 html_desc.append( "domain proteins counts based" + "</td></tr>" + nl );
1195 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1197 System.out.print( " Sort by : " );
1198 html_desc.append( "<tr><td>Sort by:</td><td>" );
1199 switch ( domain_similarity_sort_field ) {
1201 System.out.print( "score minimum" );
1202 html_desc.append( "score minimum" );
1205 System.out.print( "score maximum" );
1206 html_desc.append( "score maximum" );
1209 System.out.print( "score mean" );
1210 html_desc.append( "score mean" );
1213 System.out.print( "score standard deviation" );
1214 html_desc.append( "score standard deviation" );
1217 System.out.print( "species number" );
1218 html_desc.append( "species number" );
1221 System.out.print( "alphabetical domain identifier" );
1222 html_desc.append( "alphabetical domain identifier" );
1224 case MAX_DIFFERENCE:
1225 System.out.print( "(maximal) difference" );
1226 html_desc.append( "(maximal) difference" );
1228 case ABS_MAX_COUNTS_DIFFERENCE:
1229 System.out.print( "absolute (maximal) counts difference" );
1230 html_desc.append( "absolute (maximal) counts difference" );
1232 case MAX_COUNTS_DIFFERENCE:
1233 System.out.print( "(maximal) counts difference" );
1234 html_desc.append( "(maximal) counts difference" );
1237 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1239 if ( sort_by_species_count_first ) {
1240 System.out.println( " (sort by species count first)" );
1241 html_desc.append( " (sort by species count first)" );
1244 System.out.println();
1246 html_desc.append( "</td></tr>" + nl );
1247 System.out.print( " Detailedness : " );
1248 switch ( detailedness ) {
1250 System.out.println( "basic" );
1252 case LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES:
1253 System.out.println( "list combining domains for each species" );
1256 System.out.println( "punctilious" );
1259 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for detailedness" );
1261 System.out.print( " Print option : " );
1262 switch ( domain_similarity_print_option ) {
1264 System.out.println( "HTML" );
1266 case SIMPLE_TAB_DELIMITED:
1267 System.out.println( "simple tab delimited" );
1270 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for print option" );
1272 System.out.print( " Species matrix : " + species_matrix );
1273 System.out.println();
1274 final File dc_data_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + DATA_FILE_SUFFIX );
1275 System.out.println( "Domain comb data output : " + dc_data_file );
1276 html_desc.append( "<tr><td>Domain combination data output:</td><td> " + dc_data_file + " </td></tr>" );
1277 System.out.println();
1278 if ( perform_pwc ) {
1279 System.out.println( "Pairwise comparisons: " );
1280 html_desc.append( "<tr><td>Pairwise comparisons:</td><td></td></tr>" );
1281 System.out.print( " Sort by : " );
1282 html_desc.append( "<tr><td>Sort by:</td><td>" );
1283 switch ( domain_similarity_sort_field_for_automated_pwc ) {
1285 System.out.print( "score mean" );
1286 html_desc.append( "score mean" );
1289 System.out.print( "alphabetical domain identifier" );
1290 html_desc.append( "alphabetical domain identifier" );
1292 case MAX_DIFFERENCE:
1293 System.out.print( "difference" );
1294 html_desc.append( "difference" );
1296 case ABS_MAX_COUNTS_DIFFERENCE:
1297 System.out.print( "absolute counts difference" );
1298 html_desc.append( "absolute counts difference" );
1300 case MAX_COUNTS_DIFFERENCE:
1301 System.out.print( "counts difference" );
1302 html_desc.append( "counts difference" );
1306 .unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1308 System.out.println();
1309 html_desc.append( "</td></tr>" + nl );
1310 if ( ( intrees != null ) && ( intrees.length > 0 ) ) {
1311 for( final File intree_file : intree_files ) {
1312 html_desc.append( "<tr><td>Intree for gain/loss parsimony analysis:</td><td>" + intree_file
1313 + "</td></tr>" + nl );
1314 System.out.println( " Intree for gain/loss pars.: " + intree_file );
1317 if ( radomize_fitch_parsimony ) {
1318 html_desc.append( "<tr><td> Random number seed for Fitch parsimony analysis:</td><td>"
1319 + random_number_seed_for_fitch_parsimony + "</td></tr>" + nl );
1320 System.out.println( " Random number seed : " + random_number_seed_for_fitch_parsimony );
1322 if ( ( domain_id_to_secondary_features_maps != null ) && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
1323 for( int i = 0; i < secondary_features_map_files.length; i++ ) {
1324 html_desc.append( "<tr><td>Secondary features map file:</td><td>"
1325 + secondary_features_map_files[ i ] + "</td></tr>" + nl );
1326 System.out.println( "Secondary features map file : " + secondary_features_map_files[ i ]
1327 + " [mappings for " + domain_id_to_secondary_features_maps[ i ].size() + " domain ids]" );
1329 System.out.println();
1330 System.out.println( "Domain ids to secondary features map:" );
1331 for( final String domain_id : domain_id_to_secondary_features_maps[ i ].keySet() ) {
1332 System.out.print( domain_id );
1333 System.out.print( " => " );
1334 for( final String sec : domain_id_to_secondary_features_maps[ i ].get( domain_id ) ) {
1335 System.out.print( sec );
1336 System.out.print( " " );
1338 System.out.println();
1343 } // if ( perform_pwc ) {
1344 System.out.println();
1345 html_desc.append( "<tr><td>Command line:</td><td>" + nl + nl + cla.getCommandLineArgsAsString() + nl + nl
1346 + "</td></tr>" + nl );
1347 System.out.println( "Command line : " + cla.getCommandLineArgsAsString() );
1348 BufferedWriter[] query_domains_writer_ary = null;
1349 List<String>[] query_domain_ids_array = null;
1350 if ( query_domain_ids != null ) {
1351 final String[] query_domain_ids_str_array = query_domain_ids.split( "#" );
1352 query_domain_ids_array = new ArrayList[ query_domain_ids_str_array.length ];
1353 query_domains_writer_ary = new BufferedWriter[ query_domain_ids_str_array.length ];
1354 for( int i = 0; i < query_domain_ids_str_array.length; i++ ) {
1355 String query_domain_ids_str = query_domain_ids_str_array[ i ];
1356 final String[] query_domain_ids_str_ary = query_domain_ids_str.split( "~" );
1357 final List<String> query = new ArrayList<String>();
1358 for( final String element : query_domain_ids_str_ary ) {
1359 query.add( element );
1361 query_domain_ids_array[ i ] = query;
1362 query_domain_ids_str = query_domain_ids_str.replace( '~', '_' );
1363 String protein_names_writer_str = query_domain_ids_str + surfacing.SEQ_EXTRACT_SUFFIX;
1364 if ( out_dir != null ) {
1365 protein_names_writer_str = out_dir + ForesterUtil.FILE_SEPARATOR + protein_names_writer_str;
1368 query_domains_writer_ary[ i ] = new BufferedWriter( new FileWriter( protein_names_writer_str ) );
1370 catch ( final IOException e ) {
1371 ForesterUtil.fatalError( surfacing.PRG_NAME, "Could not open [" + protein_names_writer_str + "]: "
1372 + e.getLocalizedMessage() );
1376 SortedMap<Species, List<Protein>> protein_lists_per_species = null; //This will only be created if neede.
1377 boolean need_protein_lists_per_species = false;
1378 if ( ( plus_minus_analysis_high_copy_base_species.size() > 0 ) || output_protein_lists_for_all_domains ) {
1379 need_protein_lists_per_species = true;
1381 if ( need_protein_lists_per_species ) {
1382 protein_lists_per_species = new TreeMap<Species, List<Protein>>();
1384 List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>( number_of_genomes );
1385 final SortedSet<String> all_domains_encountered = new TreeSet<String>();
1386 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered = new TreeSet<BinaryDomainCombination>();
1387 List<BinaryDomainCombination> all_bin_domain_combinations_gained_fitch = null;
1388 List<BinaryDomainCombination> all_bin_domain_combinations_lost_fitch = null;
1389 if ( ( intrees != null ) && ( intrees.length == 1 ) ) {
1390 all_bin_domain_combinations_gained_fitch = new ArrayList<BinaryDomainCombination>();
1391 all_bin_domain_combinations_lost_fitch = new ArrayList<BinaryDomainCombination>();
1393 final File per_genome_domain_promiscuity_statistics_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR
1394 + output_file + D_PROMISCUITY_FILE_SUFFIX );
1395 BufferedWriter per_genome_domain_promiscuity_statistics_writer = null;
1397 per_genome_domain_promiscuity_statistics_writer = new BufferedWriter( new FileWriter( per_genome_domain_promiscuity_statistics_file ) );
1398 per_genome_domain_promiscuity_statistics_writer.write( "Species:\t" );
1399 per_genome_domain_promiscuity_statistics_writer.write( "Mean:\t" );
1400 per_genome_domain_promiscuity_statistics_writer.write( "SD:\t" );
1401 per_genome_domain_promiscuity_statistics_writer.write( "Median:\t" );
1402 per_genome_domain_promiscuity_statistics_writer.write( "Min:\t" );
1403 per_genome_domain_promiscuity_statistics_writer.write( "Max:\t" );
1404 per_genome_domain_promiscuity_statistics_writer.write( "N:\t" );
1405 per_genome_domain_promiscuity_statistics_writer.write( "Max Promiscuous Domains:"
1406 + ForesterUtil.LINE_SEPARATOR );
1408 catch ( final IOException e2 ) {
1409 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1411 final File log_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + LOG_FILE_SUFFIX );
1412 BufferedWriter log_writer = null;
1414 log_writer = new BufferedWriter( new FileWriter( log_file ) );
1416 catch ( final IOException e2 ) {
1417 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1419 BufferedWriter dc_data_writer = null;
1421 dc_data_writer = new BufferedWriter( new FileWriter( dc_data_file ) );
1422 dc_data_writer.write( DATA_FILE_DESC );
1423 dc_data_writer.write( ForesterUtil.LINE_SEPARATOR );
1425 catch ( final IOException e2 ) {
1426 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1428 DescriptiveStatistics protein_coverage_stats = new BasicDescriptiveStatistics();
1429 DescriptiveStatistics all_genomes_domains_per_potein_stats = new BasicDescriptiveStatistics();
1430 final SortedMap<Integer, Integer> all_genomes_domains_per_potein_histo = new TreeMap<Integer, Integer>();
1431 final SortedSet<String> domains_which_are_always_single = new TreeSet<String>();
1432 final SortedSet<String> domains_which_are_sometimes_single_sometimes_not = new TreeSet<String>();
1433 final SortedSet<String> domains_which_never_single = new TreeSet<String>();
1434 BufferedWriter domains_per_potein_stats_writer = null;
1436 domains_per_potein_stats_writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR
1437 + output_file + "_domains_per_potein_stats.txt" ) );
1438 domains_per_potein_stats_writer.write( "Genome" );
1439 domains_per_potein_stats_writer.write( "\t" );
1440 domains_per_potein_stats_writer.write( "Mean" );
1441 domains_per_potein_stats_writer.write( "\t" );
1442 domains_per_potein_stats_writer.write( "SD" );
1443 domains_per_potein_stats_writer.write( "\t" );
1444 domains_per_potein_stats_writer.write( "Median" );
1445 domains_per_potein_stats_writer.write( "\t" );
1446 domains_per_potein_stats_writer.write( "N" );
1447 domains_per_potein_stats_writer.write( "\t" );
1448 domains_per_potein_stats_writer.write( "Min" );
1449 domains_per_potein_stats_writer.write( "\t" );
1450 domains_per_potein_stats_writer.write( "Max" );
1451 domains_per_potein_stats_writer.write( "\n" );
1453 catch ( final IOException e3 ) {
1454 e3.printStackTrace();
1456 Map<String, DescriptiveStatistics> protein_length_stats_by_dc = null;
1457 Map<String, DescriptiveStatistics> domain_number_stats_by_dc = null;
1458 final Map<String, DescriptiveStatistics> domain_length_stats_by_domain = new HashMap<String, DescriptiveStatistics>();
1459 if ( perform_dc_regain_proteins_stats ) {
1460 protein_length_stats_by_dc = new HashMap<String, DescriptiveStatistics>();
1461 domain_number_stats_by_dc = new HashMap<String, DescriptiveStatistics>();
1463 DomainLengthsTable domain_lengths_table = null;
1464 if ( domain_length_analysis ) {
1465 domain_lengths_table = new DomainLengthsTable();
1468 final SortedMap<String, Set<String>> distinct_domain_architecutures_per_genome = new TreeMap<String, Set<String>>();
1469 final SortedMap<String, Integer> distinct_domain_architecuture_counts = new TreeMap<String, Integer>();
1470 for( int i = 0; i < number_of_genomes; ++i ) {
1471 System.out.println();
1472 System.out.println( ( i + 1 ) + "/" + number_of_genomes );
1473 SurfacingUtil.log( ( i + 1 ) + "/" + number_of_genomes, log_writer );
1474 System.out.println( "Processing : " + input_file_properties[ i ][ 1 ]
1475 + " [" + input_file_properties[ i ][ 0 ] + "]" );
1476 SurfacingUtil.log( "Genome : " + input_file_properties[ i ][ 1 ]
1477 + " [" + input_file_properties[ i ][ 0 ] + "]", log_writer );
1478 HmmscanPerDomainTableParser parser = null;
1479 INDIVIDUAL_SCORE_CUTOFF ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF.NONE;
1480 if ( individual_score_cutoffs != null ) {
1481 ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF_DEFAULT;
1483 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1484 || ( negative_domains_filter_file != null ) ) {
1485 HmmscanPerDomainTableParser.FilterType filter_type = HmmscanPerDomainTableParser.FilterType.NONE;
1486 if ( positive_filter_file != null ) {
1487 filter_type = HmmscanPerDomainTableParser.FilterType.POSITIVE_PROTEIN;
1489 else if ( negative_filter_file != null ) {
1490 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_PROTEIN;
1492 else if ( negative_domains_filter_file != null ) {
1493 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_DOMAIN;
1495 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1496 input_file_properties[ i ][ 1 ],
1503 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1504 input_file_properties[ i ][ 1 ],
1508 if ( fs_e_value_max >= 0.0 ) {
1509 parser.setFsEValueMaximum( fs_e_value_max );
1511 if ( ie_value_max >= 0.0 ) {
1512 parser.setIEValueMaximum( ie_value_max );
1514 parser.setIgnoreDufs( ignore_dufs );
1515 parser.setIgnoreVirusLikeIds( ignore_virus_like_ids );
1516 parser.setIgnoreEngulfedDomains( no_engulfing_overlaps );
1517 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1518 parser.setMaxAllowedOverlap( max_allowed_overlap );
1520 parser.setReturnType( HmmscanPerDomainTableParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
1521 if ( individual_score_cutoffs != null ) {
1522 parser.setIndividualScoreCutoffs( individual_score_cutoffs );
1524 List<Protein> protein_list = null;
1526 protein_list = parser.parse();
1528 catch ( final IOException e ) {
1529 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
1531 catch ( final Exception e ) {
1532 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, e.getMessage(), e );
1535 System.out.println( "Domains ignored due to negative domain filter: " );
1536 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToNegativeDomainFilterCountsMap() );
1537 System.out.println( "Domains ignored due to virus like id: " );
1538 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToVirusLikeIdCountsMap() );
1540 final double coverage = ( double ) protein_list.size() / parser.getProteinsEncountered();
1541 protein_coverage_stats.addValue( coverage );
1542 int distinct_das = -1;
1543 if ( da_analysis ) {
1544 final String genome = input_file_properties[ i ][ 0 ];
1545 distinct_das = SurfacingUtil.storeDomainArchitectures( genome,
1546 distinct_domain_architecutures_per_genome,
1548 distinct_domain_architecuture_counts );
1550 System.out.println( "Number of proteins encountered : " + parser.getProteinsEncountered() );
1551 SurfacingUtil.log( "Number of proteins encountered : " + parser.getProteinsEncountered(),
1553 System.out.println( "Number of proteins stored : " + protein_list.size() );
1554 SurfacingUtil.log( "Number of proteins stored : " + protein_list.size(), log_writer );
1555 System.out.println( "Coverage : "
1556 + ForesterUtil.roundToInt( 100.0 * coverage ) + "%" );
1557 SurfacingUtil.log( "Coverage : "
1558 + ForesterUtil.roundToInt( 100.0 * coverage ) + "%",
1560 System.out.println( "Domains encountered : " + parser.getDomainsEncountered() );
1561 SurfacingUtil.log( "Domains encountered : " + parser.getDomainsEncountered(),
1563 System.out.println( "Domains stored : " + parser.getDomainsStored() );
1564 SurfacingUtil.log( "Domains stored : " + parser.getDomainsStored(),
1566 System.out.println( "Distinct domains stored : "
1567 + parser.getDomainsStoredSet().size() );
1568 SurfacingUtil.log( "Distinct domains stored : "
1569 + parser.getDomainsStoredSet().size(), log_writer );
1570 System.out.println( "Domains ignored due to individual score cutoffs: "
1571 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() );
1572 SurfacingUtil.log( "Domains ignored due to individual score cutoffs: "
1573 + parser.getDomainsIgnoredDueToIndividualScoreCutoff(),
1575 System.out.println( "Domains ignored due to FS E-value : "
1576 + parser.getDomainsIgnoredDueToFsEval() );
1577 SurfacingUtil.log( "Domains ignored due to FS E-value : "
1578 + parser.getDomainsIgnoredDueToFsEval(),
1580 System.out.println( "Domains ignored due to iE-value : "
1581 + parser.getDomainsIgnoredDueToIEval() );
1582 SurfacingUtil.log( "Domains ignored due to iE-value : "
1583 + parser.getDomainsIgnoredDueToIEval(),
1585 System.out.println( "Domains ignored due to DUF designation : "
1586 + parser.getDomainsIgnoredDueToDuf() );
1588 .log( "Domains ignored due to DUF designation : " + parser.getDomainsIgnoredDueToDuf(),
1590 if ( ignore_virus_like_ids ) {
1591 System.out.println( "Domains ignored due virus like ids : "
1592 + parser.getDomainsIgnoredDueToVirusLikeIds() );
1593 SurfacingUtil.log( "Domains ignored due virus like ids : "
1594 + parser.getDomainsIgnoredDueToVirusLikeIds(),
1597 System.out.println( "Domains ignored due negative domain filter : "
1598 + parser.getDomainsIgnoredDueToNegativeDomainFilter() );
1599 SurfacingUtil.log( "Domains ignored due negative domain filter : "
1600 + parser.getDomainsIgnoredDueToNegativeDomainFilter(),
1602 System.out.println( "Domains ignored due to overlap : "
1603 + parser.getDomainsIgnoredDueToOverlap() );
1604 SurfacingUtil.log( "Domains ignored due to overlap : "
1605 + parser.getDomainsIgnoredDueToOverlap(),
1607 if ( negative_filter_file != null ) {
1608 System.out.println( "Proteins ignored due to negative filter : "
1609 + parser.getProteinsIgnoredDueToFilter() );
1610 SurfacingUtil.log( "Proteins ignored due to negative filter : "
1611 + parser.getProteinsIgnoredDueToFilter(),
1614 if ( positive_filter_file != null ) {
1615 System.out.println( "Proteins ignored due to positive filter : "
1616 + parser.getProteinsIgnoredDueToFilter() );
1617 SurfacingUtil.log( "Proteins ignored due to positive filter : "
1618 + parser.getProteinsIgnoredDueToFilter(),
1621 if ( da_analysis ) {
1622 System.out.println( "Distinct domain architectures stored : " + distinct_das );
1623 SurfacingUtil.log( "Distinct domain architectures stored : " + distinct_das, log_writer );
1625 System.out.println( "Time for processing : " + parser.getTime() + "ms" );
1626 SurfacingUtil.log( "", log_writer );
1629 for( final Protein protein : protein_list ) {
1630 dc_data_writer.write( SurfacingUtil.proteinToDomainCombinations( protein, count + "", "\t" )
1633 for( final Domain d : protein.getProteinDomains() ) {
1634 final String d_str = d.getDomainId().toString();
1635 if ( !domain_length_stats_by_domain.containsKey( d_str ) ) {
1636 domain_length_stats_by_domain.put( d_str, new BasicDescriptiveStatistics() );
1638 domain_length_stats_by_domain.get( d_str ).addValue( d.getLength() );
1642 catch ( final IOException e ) {
1643 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1645 SurfacingUtil.domainsPerProteinsStatistics( input_file_properties[ i ][ 1 ],
1647 all_genomes_domains_per_potein_stats,
1648 all_genomes_domains_per_potein_histo,
1649 domains_which_are_always_single,
1650 domains_which_are_sometimes_single_sometimes_not,
1651 domains_which_never_single,
1652 domains_per_potein_stats_writer );
1653 if ( domain_length_analysis ) {
1654 domain_lengths_table.addLengths( protein_list );
1656 if ( !da_analysis ) {
1657 gwcd_list.add( BasicGenomeWideCombinableDomains
1658 .createInstance( protein_list,
1659 ignore_combination_with_same,
1660 new BasicSpecies( input_file_properties[ i ][ 1 ] ),
1661 domain_id_to_go_ids_map,
1663 protein_length_stats_by_dc,
1664 domain_number_stats_by_dc ) );
1665 if ( gwcd_list.get( i ).getSize() > 0 ) {
1666 if ( output_binary_domain_combinationsfor_counts ) {
1668 .writeDomainCombinationsCountsFile( input_file_properties,
1670 per_genome_domain_promiscuity_statistics_writer,
1675 if ( output_binary_domain_combinationsfor_graph_analysis ) {
1676 SurfacingUtil.writeBinaryDomainCombinationsFileForGraphAnalysis( input_file_properties,
1682 SurfacingUtil.addAllDomainIdsToSet( gwcd_list.get( i ), all_domains_encountered );
1683 SurfacingUtil.addAllBinaryDomainCombinationToSet( gwcd_list.get( i ),
1684 all_bin_domain_combinations_encountered );
1687 if ( query_domains_writer_ary != null ) {
1688 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1690 SurfacingUtil.extractProteinNames( protein_list,
1691 query_domain_ids_array[ j ],
1692 query_domains_writer_ary[ j ],
1694 LIMIT_SPEC_FOR_PROT_EX );
1695 query_domains_writer_ary[ j ].flush();
1697 catch ( final IOException e ) {
1698 e.printStackTrace();
1702 if ( need_protein_lists_per_species ) {
1703 protein_lists_per_species.put( new BasicSpecies( input_file_properties[ i ][ 1 ] ), protein_list );
1708 catch ( final IOException e2 ) {
1709 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1712 } // for( int i = 0; i < number_of_genomes; ++i ) {
1713 ForesterUtil.programMessage( PRG_NAME, "Wrote domain promiscuities to: "
1714 + per_genome_domain_promiscuity_statistics_file );
1716 if ( da_analysis ) {
1717 SurfacingUtil.performDomainArchitectureAnalysis( distinct_domain_architecutures_per_genome,
1718 distinct_domain_architecuture_counts,
1720 new File( out_dir.toString() + "/" + output_file
1721 + "_DA_counts.txt" ),
1722 new File( out_dir.toString() + "/" + output_file
1723 + "_unique_DAs.txt" ) );
1724 distinct_domain_architecutures_per_genome.clear();
1725 distinct_domain_architecuture_counts.clear();
1729 domains_per_potein_stats_writer.write( "ALL" );
1730 domains_per_potein_stats_writer.write( "\t" );
1731 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.arithmeticMean() + "" );
1732 domains_per_potein_stats_writer.write( "\t" );
1733 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.sampleStandardDeviation() + "" );
1734 domains_per_potein_stats_writer.write( "\t" );
1735 if ( all_genomes_domains_per_potein_stats.getN() <= 300 ) {
1736 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.median() + "" );
1737 domains_per_potein_stats_writer.write( "\t" );
1739 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getN() + "" );
1740 domains_per_potein_stats_writer.write( "\t" );
1741 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getMin() + "" );
1742 domains_per_potein_stats_writer.write( "\t" );
1743 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getMax() + "" );
1744 domains_per_potein_stats_writer.write( "\n" );
1745 domains_per_potein_stats_writer.close();
1746 all_genomes_domains_per_potein_stats = null;
1747 SurfacingUtil.printOutPercentageOfMultidomainProteins( all_genomes_domains_per_potein_histo, log_writer );
1748 ForesterUtil.map2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1749 + "_all_genomes_domains_per_potein_histo.txt" ), all_genomes_domains_per_potein_histo, "\t", "\n" );
1750 ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1751 + "_domains_always_single_.txt" ), domains_which_are_always_single, "\n" );
1752 ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1753 + "_domains_single_or_combined.txt" ), domains_which_are_sometimes_single_sometimes_not, "\n" );
1754 ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1755 + "_domains_always_combined.txt" ), domains_which_never_single, "\n" );
1756 ForesterUtil.programMessage( PRG_NAME,
1757 "Average of proteins with a least one domain assigned: "
1758 + ( 100 * protein_coverage_stats.arithmeticMean() ) + "% (+/-"
1759 + ( 100 * protein_coverage_stats.sampleStandardDeviation() ) + "%)" );
1760 ForesterUtil.programMessage( PRG_NAME, "Range of proteins with a least one domain assigned: "
1761 + ( 100 * protein_coverage_stats.getMin() ) + "%-" + ( 100 * protein_coverage_stats.getMax() )
1763 SurfacingUtil.log( "Average of prot with a least one dom assigned : "
1764 + ( 100 * protein_coverage_stats.arithmeticMean() ) + "% (+/-"
1765 + ( 100 * protein_coverage_stats.sampleStandardDeviation() ) + "%)",
1767 SurfacingUtil.log( "Range of prot with a least one dom assigned : "
1768 + ( 100 * protein_coverage_stats.getMin() ) + "%-"
1769 + ( 100 * protein_coverage_stats.getMax() ) + "%",
1771 protein_coverage_stats = null;
1773 catch ( final IOException e2 ) {
1774 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1776 if ( query_domains_writer_ary != null ) {
1777 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1779 query_domains_writer_ary[ j ].close();
1781 catch ( final IOException e ) {
1782 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1787 per_genome_domain_promiscuity_statistics_writer.close();
1788 dc_data_writer.close();
1791 catch ( final IOException e2 ) {
1792 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1794 if ( domain_length_analysis ) {
1796 SurfacingUtil.executeDomainLengthAnalysis( input_file_properties,
1798 domain_lengths_table,
1799 domain_lengths_analysis_outfile );
1801 catch ( final IOException e1 ) {
1802 ForesterUtil.fatalError( surfacing.PRG_NAME, e1.toString() );
1804 System.out.println();
1805 ForesterUtil.programMessage( PRG_NAME, "Wrote domain length data to: " + domain_lengths_analysis_outfile );
1806 System.out.println();
1808 domain_lengths_table = null;
1809 final long analysis_start_time = new Date().getTime();
1810 PairwiseDomainSimilarityCalculator pw_calc = null;
1811 final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( domain_similarity_sort_field,
1812 sort_by_species_count_first,
1813 number_of_genomes == 2,
1814 CALC_SIMILARITY_SCORES,
1816 switch ( scoring ) {
1818 pw_calc = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1821 pw_calc = new DomainCountsBasedPairwiseSimilarityCalculator();
1824 pw_calc = new ProteinCountsBasedPairwiseDomainSimilarityCalculator();
1827 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1829 DomainSimilarityCalculator.GoAnnotationOutput go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.NONE;
1830 if ( domain_id_to_go_ids_map != null ) {
1831 go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.ALL;
1833 final SortedSet<DomainSimilarity> similarities = calc
1834 .calculateSimilarities( pw_calc,
1836 ignore_domains_without_combs_in_all_spec,
1837 ignore_species_specific_domains );
1838 SurfacingUtil.decoratePrintableDomainSimilarities( similarities, detailedness );
1839 final Map<String, Integer> tax_code_to_id_map = SurfacingUtil.createTaxCodeToIdMap( intrees[ 0 ] );
1841 String my_outfile = output_file.toString();
1842 Map<Character, Writer> split_writers = null;
1843 Writer writer = null;
1844 if ( similarities.size() > MINIMAL_NUMBER_OF_SIMILARITIES_FOR_SPLITTING ) {
1845 if ( my_outfile.endsWith( ".html" ) ) {
1846 my_outfile = my_outfile.substring( 0, my_outfile.length() - 5 );
1848 split_writers = new HashMap<Character, Writer>();
1849 SurfacingUtil.createSplitWriters( out_dir, my_outfile, split_writers );
1851 else if ( !my_outfile.endsWith( ".html" ) ) {
1852 my_outfile += ".html";
1853 writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR + my_outfile ) );
1855 List<Species> species_order = null;
1856 if ( species_matrix ) {
1857 species_order = new ArrayList<Species>();
1858 for( int i = 0; i < number_of_genomes; i++ ) {
1859 species_order.add( new BasicSpecies( input_file_properties[ i ][ 1 ] ) );
1862 html_desc.append( "<tr><td>Sum of all distinct binary combinations:</td><td>"
1863 + all_bin_domain_combinations_encountered.size() + "</td></tr>" + nl );
1864 html_desc.append( "<tr><td>Sum of all distinct domains:</td><td>" + all_domains_encountered.size()
1865 + "</td></tr>" + nl );
1866 html_desc.append( "<tr><td>Analysis date/time:</td><td>"
1867 + new java.text.SimpleDateFormat( "yyyy.MM.dd HH:mm:ss" ).format( new java.util.Date() )
1868 + "</td></tr>" + nl );
1869 html_desc.append( "</table>" + nl );
1870 final Writer simple_tab_writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR
1871 + my_outfile + ".tsv" ) );
1872 SurfacingUtil.writeDomainSimilaritiesToFile( html_desc,
1873 new StringBuilder( number_of_genomes + " genomes" ),
1878 number_of_genomes == 2,
1880 domain_similarity_print_option,
1885 positive_filter_file != null ? filter : null );
1886 simple_tab_writer.close();
1887 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote main output (includes domain similarities) to: \""
1888 + ( out_dir == null ? my_outfile : out_dir + ForesterUtil.FILE_SEPARATOR + my_outfile ) + "\"" );
1890 catch ( final IOException e ) {
1891 ForesterUtil.fatalError( surfacing.PRG_NAME, "Failed to write similarites to: \"" + output_file + "\" ["
1892 + e.getMessage() + "]" );
1894 System.out.println();
1895 final Species[] species = new Species[ number_of_genomes ];
1896 for( int i = 0; i < number_of_genomes; ++i ) {
1897 species[ i ] = new BasicSpecies( input_file_properties[ i ][ 1 ] );
1899 List<Phylogeny> inferred_trees = null;
1900 if ( ( number_of_genomes > 2 ) && perform_pwc ) {
1901 final PairwiseGenomeComparator pwgc = new PairwiseGenomeComparator();
1902 pwgc.performPairwiseComparisons( html_desc,
1903 sort_by_species_count_first,
1905 ignore_domains_without_combs_in_all_spec,
1906 ignore_species_specific_domains,
1907 domain_similarity_sort_field_for_automated_pwc,
1908 domain_similarity_print_option,
1910 domain_id_to_go_ids_map,
1917 automated_pairwise_comparison_suffix,
1919 surfacing.PAIRWISE_DOMAIN_COMPARISONS_PREFIX,
1924 CALC_SIMILARITY_SCORES,
1926 String matrix_output_file = new String( output_file.toString() );
1927 if ( matrix_output_file.indexOf( '.' ) > 1 ) {
1928 matrix_output_file = matrix_output_file.substring( 0, matrix_output_file.indexOf( '.' ) );
1930 if ( out_dir != null ) {
1931 matrix_output_file = out_dir + ForesterUtil.FILE_SEPARATOR + matrix_output_file;
1932 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
1934 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
1935 + surfacing.MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc.getDomainDistanceScoresMeans() );
1937 .writeMatrixToFile( new File( matrix_output_file
1938 + surfacing.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
1939 pwgc.getSharedBinaryCombinationsBasedDistances() );
1940 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
1941 + surfacing.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
1942 pwgc.getSharedDomainsBasedDistances() );
1943 final Phylogeny nj_gd = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
1944 + surfacing.NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc.getDomainDistanceScoresMeans()
1946 final Phylogeny nj_bc = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
1947 + surfacing.NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
1948 .getSharedBinaryCombinationsBasedDistances().get( 0 ) );
1949 final Phylogeny nj_d = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
1950 + surfacing.NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
1951 .getSharedDomainsBasedDistances().get( 0 ) );
1952 inferred_trees = new ArrayList<Phylogeny>();
1953 inferred_trees.add( nj_gd );
1954 inferred_trees.add( nj_bc );
1955 inferred_trees.add( nj_d );
1956 } // if ( ( output_file != null ) && ( number_of_genomes > 2 ) && !isEmpty( automated_pairwise_comparison_suffix ) )
1957 if ( ( out_dir != null ) && ( !perform_pwc ) ) {
1958 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
1960 if ( write_to_nexus ) {
1961 SurfacingUtil.writePresentToNexus( output_file, positive_filter_file, filter, gwcd_list );
1963 if ( ( ( intrees != null ) && ( intrees.length > 0 ) ) && ( number_of_genomes > 2 ) ) {
1964 final StringBuilder parameters_sb = SurfacingUtil.createParametersAsString( ignore_dufs,
1967 max_allowed_overlap,
1968 no_engulfing_overlaps,
1972 if ( radomize_fitch_parsimony ) {
1973 s += random_number_seed_for_fitch_parsimony + "_";
1976 for( final Phylogeny intree : intrees ) {
1977 final String outfile_name = ForesterUtil.removeSuffix( output_file.toString() ) + s
1978 + ForesterUtil.removeSuffix( intree_files[ i ].toString() );
1979 final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator.createInstance( intree,
1981 SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
1982 radomize_fitch_parsimony,
1986 domain_id_to_go_ids_map,
1989 parameters_sb.toString(),
1990 domain_id_to_secondary_features_maps,
1991 positive_filter_file == null ? null : filter,
1992 output_binary_domain_combinationsfor_graph_analysis,
1993 all_bin_domain_combinations_gained_fitch,
1994 all_bin_domain_combinations_lost_fitch,
1996 protein_length_stats_by_dc,
1997 domain_number_stats_by_dc,
1998 domain_length_stats_by_domain,
2001 use_last_in_fitch_parsimony,
2003 // Listing of all domain combinations gained is only done if only one input tree is used.
2004 if ( ( domain_id_to_secondary_features_maps != null )
2005 && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
2007 for( final Map<String, Set<String>> domain_id_to_secondary_features_map : domain_id_to_secondary_features_maps ) {
2008 final Map<Species, MappingResults> mapping_results_map = new TreeMap<Species, MappingResults>();
2009 final DomainParsimonyCalculator secondary_features_parsimony = DomainParsimonyCalculator
2010 .createInstance( intree, gwcd_list, domain_id_to_secondary_features_map );
2012 .executeParsimonyAnalysisForSecondaryFeatures( outfile_name
2014 + secondary_features_map_files[ j++ ],
2015 secondary_features_parsimony,
2017 parameters_sb.toString(),
2018 mapping_results_map,
2019 use_last_in_fitch_parsimony );
2021 System.out.println();
2022 System.out.println( "Mapping to secondary features:" );
2023 for( final Species spec : mapping_results_map.keySet() ) {
2024 final MappingResults mapping_results = mapping_results_map.get( spec );
2025 final int total_domains = mapping_results.getSumOfFailures()
2026 + mapping_results.getSumOfSuccesses();
2027 System.out.print( spec + ":" );
2028 System.out.print( " mapped domains = " + mapping_results.getSumOfSuccesses() );
2029 System.out.print( ", not mapped domains = " + mapping_results.getSumOfFailures() );
2030 if ( total_domains > 0 ) {
2031 System.out.println( ", mapped ratio = "
2032 + ( ( 100 * mapping_results.getSumOfSuccesses() ) / total_domains ) + "%" );
2035 System.out.println( ", mapped ratio = n/a (total domains = 0 )" );
2042 } // for( final Phylogeny intree : intrees ) {
2044 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
2045 SurfacingUtil.executePlusMinusAnalysis( output_file,
2046 plus_minus_analysis_high_copy_base_species,
2047 plus_minus_analysis_high_copy_target_species,
2048 plus_minus_analysis_high_low_copy_species,
2050 protein_lists_per_species,
2051 domain_id_to_go_ids_map,
2053 plus_minus_analysis_numbers );
2055 if ( output_protein_lists_for_all_domains ) {
2056 SurfacingUtil.writeProteinListsForAllSpecies( out_dir,
2057 protein_lists_per_species,
2059 output_list_of_all_proteins_per_domain_e_value_max,
2060 positive_filter_file != null ? filter : null );
2063 if ( all_bin_domain_combinations_gained_fitch != null ) {
2066 .executeFitchGainsAnalysis( new File( output_file
2067 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2068 all_bin_domain_combinations_gained_fitch,
2069 all_domains_encountered.size(),
2070 all_bin_domain_combinations_encountered,
2073 catch ( final IOException e ) {
2074 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2077 if ( all_bin_domain_combinations_lost_fitch != null ) {
2080 .executeFitchGainsAnalysis( new File( output_file
2081 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2082 all_bin_domain_combinations_lost_fitch,
2083 all_domains_encountered.size(),
2084 all_bin_domain_combinations_encountered,
2087 catch ( final IOException e ) {
2088 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2091 final Runtime rt = java.lang.Runtime.getRuntime();
2092 final long free_memory = rt.freeMemory() / 1000000;
2093 final long total_memory = rt.totalMemory() / 1000000;
2094 ForesterUtil.programMessage( PRG_NAME, "Time for analysis : " + ( new Date().getTime() - analysis_start_time )
2096 ForesterUtil.programMessage( PRG_NAME, "Total running time: " + ( new Date().getTime() - start_time ) + "ms " );
2097 ForesterUtil.programMessage( PRG_NAME, "Free memory : " + free_memory + "MB, total memory: "
2098 + total_memory + "MB" );
2099 ForesterUtil.programMessage( PRG_NAME, "If this application is useful to you, please cite:" );
2100 ForesterUtil.programMessage( PRG_NAME, surfacing.WWW );
2101 ForesterUtil.programMessage( PRG_NAME, "OK" );
2102 System.out.println();
2105 private static void printHelp() {
2106 System.out.println();
2107 System.out.println( "Usage:" );
2108 System.out.println();
2109 System.out.println( "% java -Xms256m -Xmx512m -cp forester.jar org.forester.applications." + surfacing.PRG_NAME
2110 + " [options] <phylogen(y|ies) infile> [external node name 1] [name 2] ... [name n]" );
2111 System.out.println();
2112 System.out.println( " Note: This software might need a significant amount of memory (heap space);" );
2114 .println( " hence use \"-Xms128m -Xmx512m\" (or more) to prevent a \"java.lang.OutOfMemoryError\"." );
2115 System.out.println();
2116 System.out.println( " Options: " );
2117 System.out.println( surfacing.DETAILEDNESS_OPTION + ": level of detail for similarities output file (default:"
2118 + DETAILEDNESS_DEFAULT + ")" );
2119 System.out.println( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION
2120 + ": to ignore combinations with self (default: not to ignore)" );
2122 .println( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION
2123 + ": to ignore domains without combinations in any species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2125 .println( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION
2126 + ": to ignore domains specific to one species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2127 System.out.println( surfacing.NOT_IGNORE_DUFS_OPTION
2128 + ": to _not_ ignore DUFs (domains with unknown function) (default: ignore DUFs)" );
2130 .println( surfacing.IGNORE_VIRAL_IDS
2131 + ": to ignore domains with ids containing 'vir', 'retro', 'transpos', 'phage', or starting with 'rv' or 'gag_'" );
2132 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_OPTION + ": sorting for similarities (default: "
2133 + DOMAIN_SORT_FILD_DEFAULT + ")" );
2134 System.out.println( surfacing.OUTPUT_FILE_OPTION + ": name for (main) output file (mandatory)" );
2135 System.out.println( surfacing.MAX_I_E_VALUE_OPTION + ": max (inclusive) iE-value" );
2136 System.out.println( surfacing.MAX_FS_E_VALUE_OPTION + ": max (inclusive) FS E-value" );
2137 System.out.println( surfacing.MAX_ALLOWED_OVERLAP_OPTION + ": maximal allowed domain overlap" );
2138 System.out.println( surfacing.NO_ENGULFING_OVERLAP_OPTION + ": to ignore engulfed lower confidence domains" );
2139 System.out.println( surfacing.SPECIES_MATRIX_OPTION + ": species matrix" );
2140 System.out.println( surfacing.SCORING_OPTION + ": scoring (default:" + SCORING_DEFAULT + ")" );
2141 System.out.println( surfacing.DOMAIN_COUNT_SORT_OPTION + ": sorting for domain counts (default:"
2142 + DOMAINS_SORT_ORDER_DEFAULT + ")" );
2143 System.out.println( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION + ": domain similarity print option (default:"
2144 + DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT + ")" );
2145 System.out.println( surfacing.CUTOFF_SCORE_FILE_OPTION + ": cutoff score file" );
2146 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION
2147 + ": sort by species count first" );
2148 System.out.println( surfacing.OUTPUT_DIR_OPTION + ": output directory" );
2149 System.out.println( surfacing.PFAM_TO_GO_FILE_USE_OPTION + ": Pfam to GO mapping file" );
2150 System.out.println( surfacing.GO_OBO_FILE_USE_OPTION + ": GO terms file (OBO format)" );
2151 System.out.println( surfacing.GO_NAMESPACE_LIMIT_OPTION + ": limit GO term to one GO namespace" );
2152 System.out.println( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
2153 + "[=<suffix for pairwise comparison output files>]: to perform pairwise comparison based analyses" );
2154 System.out.println( surfacing.INPUT_SPECIES_TREE_OPTION
2155 + ": species tree, to perform (Dollo, Fitch) parismony analyses" );
2157 .println( surfacing.INPUT_SPECIES_TREE_OPTION
2158 + "=<treefiles in phyloXML format, separated by #>: to infer domain/binary domain combination gains/losses on given species trees" );
2159 System.out.println( surfacing.FILTER_POSITIVE_OPTION
2160 + "=<file>: to filter out proteins not containing at least one domain listed in <file>" );
2161 System.out.println( surfacing.FILTER_NEGATIVE_OPTION
2162 + "=<file>: to filter out proteins containing at least one domain listed in <file>" );
2163 System.out.println( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION
2164 + "=<file>: to filter out (ignore) domains listed in <file>" );
2165 System.out.println( surfacing.INPUT_GENOMES_FILE_OPTION + "=<file>: to read input files from <file>" );
2167 .println( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION
2168 + "=<seed>: seed for random number generator for Fitch Parsimony analysis (type: long, default: no randomization - given a choice, prefer absence" );
2169 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS
2170 + ": to consider directedness in binary combinations: e.g. A-B != B-A" );
2171 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY
2172 + ": to consider directedness and adjacency in binary combinations" );
2174 .println( surfacing.SEQ_EXTRACT_OPTION
2175 + "=<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')" );
2176 System.out.println( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE
2177 + "=<file>: to perfom parsimony analysis on secondary features" );
2178 System.out.println( surfacing.PLUS_MINUS_ANALYSIS_OPTION + "=<file>: to presence/absence genome analysis" );
2179 System.out.println( surfacing.DOMAIN_COMBINITONS_COUNTS_OUTPUT_OPTION
2180 + ": to output binary domain counts (as individual files)" );
2181 System.out.println( surfacing.DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS
2182 + ": to output binary domain combinations for (downstream) graph analysis" );
2183 System.out.println( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS + ": to output all proteins per domain" );
2184 System.out.println( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION
2185 + ": e value max per domain for output of all proteins per domain" );
2186 System.out.println( surfacing.USE_LAST_IN_FITCH_OPTION + ": to use last in Fitch parsimony" );
2187 System.out.println( surfacing.WRITE_TO_NEXUS_OPTION + ": to output in Nexus format" );
2188 System.out.println( PERFORM_DC_FITCH + ": to perform DC Fitch parsimony" );
2189 System.out.println( PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION + ": to perform DC regain protein statistics" );
2190 System.out.println( DA_ANALYSIS_OPTION + ": to perform DA analysis" );
2191 System.out.println( PERFORM_DOMAIN_LENGTH_ANALYSIS_OPTION + ": to perform domain length analysis" );
2192 System.out.println();
2193 System.out.println();
2195 .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" );
2196 System.out.println();
2198 .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" );
2199 System.out.println();