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 = "140319";
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 = null;
810 Map<String, List<GoId>> domain_id_to_go_ids_map = null;
811 int domain_id_to_go_ids_count = 0;
812 if ( cla.isOptionSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
813 if ( !cla.isOptionValueSet( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) ) {
814 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for Pfam to GO mapping file: -"
815 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>" );
817 pfam_to_go_file = new File( cla.getOptionValue( surfacing.PFAM_TO_GO_FILE_USE_OPTION ) );
818 final String error = ForesterUtil.isReadableFile( pfam_to_go_file );
819 if ( !ForesterUtil.isEmpty( error ) ) {
820 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read Pfam to GO mapping file: " + error );
823 final PfamToGoParser parser = new PfamToGoParser( pfam_to_go_file );
824 final List<PfamToGoMapping> pfam_to_go_mappings = parser.parse();
825 domain_id_to_go_ids_map = SurfacingUtil.createDomainIdToGoIdMap( pfam_to_go_mappings );
826 if ( parser.getMappingCount() < domain_id_to_go_ids_map.size() ) {
827 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME,
828 "parser.getMappingCount() < domain_id_to_go_ids_map.size()" );
830 domain_id_to_go_ids_count = parser.getMappingCount();
832 catch ( final IOException e ) {
833 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from Pfam to GO mapping file: " + e );
836 File go_obo_file = null;
837 List<GoTerm> go_terms = null;
838 if ( cla.isOptionSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
839 if ( !cla.isOptionValueSet( surfacing.GO_OBO_FILE_USE_OPTION ) ) {
840 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for GO OBO file: -"
841 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>" );
843 if ( ( domain_id_to_go_ids_map == null ) || ( domain_id_to_go_ids_map.size() < 1 ) ) {
844 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use GO OBO file (-"
845 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>) without Pfam to GO mapping file ("
846 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
848 go_obo_file = new File( cla.getOptionValue( surfacing.GO_OBO_FILE_USE_OPTION ) );
849 final String error = ForesterUtil.isReadableFile( go_obo_file );
850 if ( !ForesterUtil.isEmpty( error ) ) {
851 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read GO OBO file: " + error );
854 final OBOparser parser = new OBOparser( go_obo_file, OBOparser.ReturnType.BASIC_GO_TERM );
855 go_terms = parser.parse();
856 if ( parser.getGoTermCount() != go_terms.size() ) {
858 .unexpectedFatalError( surfacing.PRG_NAME, "parser.getGoTermCount() != go_terms.size()" );
861 catch ( final IOException e ) {
862 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read from GO OBO file: " + e );
865 Map<GoId, GoTerm> go_id_to_term_map = null;
866 if ( ( ( domain_id_to_go_ids_map != null ) && ( domain_id_to_go_ids_map.size() > 0 ) )
867 && ( ( go_terms != null ) && ( go_terms.size() > 0 ) ) ) {
868 go_id_to_term_map = GoUtils.createGoIdToGoTermMap( go_terms );
870 GoNameSpace go_namespace_limit = null;
871 if ( cla.isOptionSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
872 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
873 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot use GO namespace limit (-"
874 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<namespace>) without Pfam to GO mapping file ("
875 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>) and GO OBO file (-"
876 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
878 if ( !cla.isOptionValueSet( surfacing.GO_NAMESPACE_LIMIT_OPTION ) ) {
879 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for GO namespace limit: \"-"
880 + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
881 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
882 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
883 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
885 final String go_namespace_limit_str = cla.getOptionValue( surfacing.GO_NAMESPACE_LIMIT_OPTION )
887 if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION ) ) {
888 go_namespace_limit = GoNameSpace.createMolecularFunction();
890 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS ) ) {
891 go_namespace_limit = GoNameSpace.createBiologicalProcess();
893 else if ( go_namespace_limit_str.equals( surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT ) ) {
894 go_namespace_limit = GoNameSpace.createCellularComponent();
897 ForesterUtil.fatalError( surfacing.PRG_NAME, "unknown value \"" + go_namespace_limit_str
898 + "\" for GO namespace limit: \"-" + surfacing.GO_NAMESPACE_LIMIT_OPTION + "=<"
899 + surfacing.GO_NAMESPACE_LIMIT_OPTION_MOLECULAR_FUNCTION + "|"
900 + surfacing.GO_NAMESPACE_LIMIT_OPTION_BIOLOGICAL_PROCESS + "|"
901 + surfacing.GO_NAMESPACE_LIMIT_OPTION_CELLULAR_COMPONENT + ">\"" );
904 if ( ( domain_similarity_sort_field == DomainSimilarity.DomainSimilaritySortField.MAX_COUNTS_DIFFERENCE )
905 && ( number_of_genomes > 2 ) ) {
906 domain_similarity_sort_field = DomainSimilarity.DomainSimilaritySortField.ABS_MAX_COUNTS_DIFFERENCE;
908 File[] intree_files = null;
909 Phylogeny[] intrees = null;
910 if ( cla.isOptionSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
911 if ( number_of_genomes < 3 ) {
912 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot infer gains and losses on input species trees (-"
913 + surfacing.INPUT_SPECIES_TREE_OPTION + " without pairwise analyses ("
914 + surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
915 + "=<suffix for pairwise comparison output files>)" );
917 if ( !cla.isOptionValueSet( surfacing.INPUT_SPECIES_TREE_OPTION ) ) {
918 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for input tree: -"
919 + surfacing.INPUT_SPECIES_TREE_OPTION + "=<tree file in phyloXML format>" );
921 final String intrees_str = cla.getOptionValue( surfacing.INPUT_SPECIES_TREE_OPTION );
922 if ( intrees_str.indexOf( "#" ) > 0 ) {
923 final String[] intrees_strs = intrees_str.split( "#" );
924 intree_files = new File[ intrees_strs.length ];
926 for( final String s : intrees_strs ) {
927 intree_files[ i++ ] = new File( s.trim() );
931 intree_files = new File[ 1 ];
932 intree_files[ 0 ] = new File( intrees_str );
934 intrees = SurfacingUtil.obtainAndPreProcessIntrees( intree_files, number_of_genomes, input_file_properties );
936 final Phylogeny intree_0_orig = SurfacingUtil.obtainFirstIntree( intree_files[ 0 ] );
937 long random_number_seed_for_fitch_parsimony = 0l;
938 boolean radomize_fitch_parsimony = false;
939 if ( cla.isOptionSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
940 if ( !cla.isOptionValueSet( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION ) ) {
941 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for random number seed: -"
942 + surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION + "=<seed>" );
945 random_number_seed_for_fitch_parsimony = cla
946 .getOptionValueAsLong( RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION );
948 catch ( final IOException e ) {
949 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
951 radomize_fitch_parsimony = true;
953 SortedSet<String> filter = null;
954 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
955 || ( negative_domains_filter_file != null ) ) {
956 filter = new TreeSet<String>();
957 if ( positive_filter_file != null ) {
958 SurfacingUtil.processFilter( positive_filter_file, filter );
960 else if ( negative_filter_file != null ) {
961 SurfacingUtil.processFilter( negative_filter_file, filter );
963 else if ( negative_domains_filter_file != null ) {
964 SurfacingUtil.processFilter( negative_domains_filter_file, filter );
967 Map<String, Set<String>>[] domain_id_to_secondary_features_maps = null;
968 File[] secondary_features_map_files = null;
969 final File domain_lengths_analysis_outfile = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
970 + DOMAIN_LENGTHS_ANALYSIS_SUFFIX );
971 if ( domain_length_analysis ) {
972 SurfacingUtil.checkForOutputFileWriteability( domain_lengths_analysis_outfile );
974 if ( cla.isOptionSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
975 if ( !cla.isOptionValueSet( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ) ) {
976 ForesterUtil.fatalError( surfacing.PRG_NAME, "no value for secondary features map file: -"
977 + surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE + "=<file>" );
979 final String[] secondary_features_map_files_strs = cla
980 .getOptionValue( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE ).split( "#" );
981 secondary_features_map_files = new File[ secondary_features_map_files_strs.length ];
982 domain_id_to_secondary_features_maps = new Map[ secondary_features_map_files_strs.length ];
984 for( final String secondary_features_map_files_str : secondary_features_map_files_strs ) {
985 secondary_features_map_files[ i ] = new File( secondary_features_map_files_str );
986 final String error = ForesterUtil.isReadableFile( secondary_features_map_files[ i ] );
987 if ( !ForesterUtil.isEmpty( error ) ) {
988 ForesterUtil.fatalError( surfacing.PRG_NAME, "cannot read secondary features map file: " + error );
991 domain_id_to_secondary_features_maps[ i ] = SurfacingUtil
992 .createDomainIdToSecondaryFeaturesMap( secondary_features_map_files[ i ] );
994 catch ( final IOException e ) {
995 ForesterUtil.fatalError( surfacing.PRG_NAME,
996 "cannot read secondary features map file: " + e.getMessage() );
998 catch ( final Exception e ) {
999 ForesterUtil.fatalError( surfacing.PRG_NAME, "problem with contents of features map file ["
1000 + secondary_features_map_files[ i ] + "]: " + e.getMessage() );
1005 if ( out_dir == null ) {
1006 ForesterUtil.fatalError( surfacing.PRG_NAME, "no output directory indicated (-"
1007 + surfacing.OUTPUT_DIR_OPTION + "=<dir>)" );
1009 if ( output_file == null ) {
1010 ForesterUtil.fatalError( surfacing.PRG_NAME, "no name for (main) output file indicated (-"
1011 + surfacing.OUTPUT_FILE_OPTION + "=<file>)" );
1013 if ( ( domain_id_to_go_ids_map == null ) || domain_id_to_go_ids_map.isEmpty() ) {
1014 ForesterUtil.fatalError( surfacing.PRG_NAME,
1015 "no (acceptable) Pfam to GO id mapping file provided ('pfam2go file') (-"
1016 + surfacing.PFAM_TO_GO_FILE_USE_OPTION + "=<file>)" );
1018 if ( ( go_id_to_term_map == null ) || go_id_to_term_map.isEmpty() ) {
1019 ForesterUtil.fatalError( surfacing.PRG_NAME,
1020 "no (acceptable) go id to term mapping file provided ('GO OBO file') (-"
1021 + surfacing.GO_OBO_FILE_USE_OPTION + "=<file>)" );
1023 System.out.println( "Output directory : " + out_dir );
1024 System.out.println( "Input genomes from : " + input_genomes_file );
1025 html_desc.append( "<tr><td>Input genomes from:</td><td>" + input_genomes_file + "</td></tr>" + nl );
1026 if ( positive_filter_file != null ) {
1027 final int filter_size = filter.size();
1028 System.out.println( "Positive protein filter : " + positive_filter_file + " [" + filter_size
1030 html_desc.append( "<tr><td>Positive protein filter:</td><td>" + positive_filter_file + " [" + filter_size
1031 + " domain ids]</td></tr>" + nl );
1033 if ( negative_filter_file != null ) {
1034 final int filter_size = filter.size();
1035 System.out.println( "Negative protein filter : " + negative_filter_file + " [" + filter_size
1037 html_desc.append( "<tr><td>Negative protein filter:</td><td>" + negative_filter_file + " [" + filter_size
1038 + " domain ids]</td></tr>" + nl );
1040 if ( negative_domains_filter_file != null ) {
1041 final int filter_size = filter.size();
1042 System.out.println( "Negative domain filter : " + negative_domains_filter_file + " [" + filter_size
1044 html_desc.append( "<tr><td>Negative domain filter:</td><td>" + negative_domains_filter_file + " ["
1045 + filter_size + " domain ids]</td></tr>" + nl );
1047 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
1049 for( final String s : plus_minus_analysis_high_copy_base_species ) {
1050 plus0 += "+" + s + " ";
1053 for( final String s : plus_minus_analysis_high_copy_target_species ) {
1054 plus1 += "*" + s + " ";
1057 for( final String s : plus_minus_analysis_high_low_copy_species ) {
1058 minus += "-" + s + " ";
1060 System.out.println( "Plus-minus analysis : " + plus1 + "&& " + plus0 + "&& " + minus );
1061 html_desc.append( "<tr><td>Plus-minus analysis:</td><td>" + plus1 + "&& " + plus0 + "&& " + minus
1062 + "</td></tr>" + nl );
1064 if ( cutoff_scores_file != null ) {
1065 System.out.println( "Cutoff scores file : " + cutoff_scores_file );
1066 html_desc.append( "<tr><td>Cutoff scores file:</td><td>" + cutoff_scores_file + "</td></tr>" + nl );
1068 if ( ie_value_max >= 0.0 ) {
1069 System.out.println( "iE-value maximum (incl) : " + ie_value_max );
1070 html_desc.append( "<tr><td>iE-value maximum (inclusive):</td><td>" + ie_value_max + "</td></tr>" + nl );
1072 if ( fs_e_value_max >= 0.0 ) {
1073 System.out.println( "FS E-value maximum (incl) : " + fs_e_value_max );
1074 html_desc.append( "<tr><td>FS E-value maximum (inclusive):</td><td>" + fs_e_value_max + "</td></tr>" + nl );
1076 if ( output_protein_lists_for_all_domains ) {
1077 System.out.println( "Domain E-value max : " + output_list_of_all_proteins_per_domain_e_value_max );
1078 html_desc.append( "<tr><td>Protein lists: E-value maximum per domain (inclusive):</td><td>"
1079 + output_list_of_all_proteins_per_domain_e_value_max + "</td></tr>" + nl );
1081 System.out.println( "Ignore DUFs : " + ignore_dufs );
1082 if ( ignore_virus_like_ids ) {
1083 System.out.println( "Ignore virus like ids : " + ignore_virus_like_ids );
1084 html_desc.append( "<tr><td>Ignore virus, phage, transposition related ids:</td><td>"
1085 + ignore_virus_like_ids + "</td></tr>" + nl );
1087 html_desc.append( "<tr><td>Ignore DUFs:</td><td>" + ignore_dufs + "</td></tr>" + nl );
1088 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1089 System.out.println( "Max allowed domain overlap : " + max_allowed_overlap );
1090 html_desc.append( "<tr><td>Max allowed domain overlap:</td><td>" + max_allowed_overlap + "</td></tr>" + nl );
1092 if ( no_engulfing_overlaps ) {
1093 System.out.println( "Ignore engulfed domains : " + no_engulfing_overlaps );
1094 html_desc.append( "<tr><td>Ignore (lower confidence) engulfed domains:</td><td>" + no_engulfing_overlaps
1095 + "</td></tr>" + nl );
1097 System.out.println( "Ignore singlet domains : " + ignore_domains_without_combs_in_all_spec );
1099 .append( "<tr><td>Ignore singlet domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1100 + ignore_domains_without_combs_in_all_spec + "</td></tr>" + nl );
1101 System.out.println( "Ignore species specific doms: " + ignore_species_specific_domains );
1103 .append( "<tr><td>Ignore species specific domains for domain combination similarity analyses (not for parsimony analyses):</td><td>"
1104 + ignore_species_specific_domains + "</td></tr>" + nl );
1105 System.out.println( "Ignore combination with self: " + ignore_combination_with_same );
1106 html_desc.append( "<tr><td>Ignore combination with self for domain combination similarity analyses:</td><td>"
1107 + ignore_combination_with_same + "</td></tr>" + nl );
1108 System.out.println( "Consider directedness : "
1109 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) );
1110 html_desc.append( "<tr><td>Consider directedness of binary domain combinations:</td><td>"
1111 + ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) + "</td></tr>" + nl );
1112 if ( dc_type != BinaryDomainCombination.DomainCombinationType.BASIC ) {
1113 System.out.println( "Consider adjacency : "
1114 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) );
1115 html_desc.append( "<tr><td>Consider djacency of binary domain combinations:</td><td>"
1116 + ( dc_type == BinaryDomainCombination.DomainCombinationType.DIRECTED_ADJACTANT ) + "</td></tr>"
1119 System.out.println( "Fitch parsimony of DCs : " + perform_dc_fich );
1120 html_desc.append( "<tr><td>Fitch parsimony of DCs:</td><td>" + perform_dc_fich + "</td></tr>" + nl );
1121 if ( perform_dc_fich ) {
1122 System.out.println( "Use last in Fitch parsimony : " + use_last_in_fitch_parsimony );
1123 html_desc.append( "<tr><td>Use last in Fitch parsimony:</td><td>" + use_last_in_fitch_parsimony
1124 + "</td></tr>" + nl );
1126 System.out.println( "Write to Nexus files : " + write_to_nexus );
1127 html_desc.append( "<tr><td>Write to Nexus files:</td><td>" + write_to_nexus + "</td></tr>" + nl );
1128 if ( perform_dc_fich ) {
1129 System.out.println( "DC regain prot stats : " + perform_dc_regain_proteins_stats );
1130 html_desc.append( "<tr><td>DC regain prot stats:</td><td>" + perform_dc_regain_proteins_stats
1131 + "</td></tr>" + nl );
1133 System.out.println( "DA analysis : " + da_analysis );
1134 html_desc.append( "<tr><td>DA analysis :</td><td>" + da_analysis + "</td></tr>" + nl );
1135 System.out.print( "Domain counts sort order : " );
1136 html_desc.append( "<tr><td>Domain counts sort order:</td><td>" );
1137 switch ( dc_sort_order ) {
1138 case ALPHABETICAL_KEY_ID:
1139 System.out.println( "alphabetical" );
1140 html_desc.append( "alphabetical" + "</td></tr>" + nl );
1142 case KEY_DOMAIN_COUNT:
1143 System.out.println( "domain count" );
1144 html_desc.append( "domain count" + "</td></tr>" + nl );
1146 case KEY_DOMAIN_PROTEINS_COUNT:
1147 System.out.println( "domain proteins count" );
1148 html_desc.append( "domain proteins count" + "</td></tr>" + nl );
1150 case COMBINATIONS_COUNT:
1151 System.out.println( "domain combinations count" );
1152 html_desc.append( "domain combinations count" + "</td></tr>" + nl );
1155 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for dc sort order" );
1157 if ( domain_id_to_go_ids_map != null ) {
1158 System.out.println( "Pfam to GO mappings from : " + pfam_to_go_file + " [" + domain_id_to_go_ids_count
1160 html_desc.append( "<tr><td>Pfam to GO mappings from:</td><td>" + pfam_to_go_file + " ["
1161 + domain_id_to_go_ids_count + " mappings]" + "</td></tr>" + nl );
1163 if ( go_terms != null ) {
1164 System.out.println( "GO terms from : " + go_obo_file + " [" + go_terms.size() + " terms]" );
1165 html_desc.append( "<tr><td>GO terms from:</td><td>" + go_obo_file + " [" + go_terms.size() + " terms]"
1166 + "</td></tr>" + nl );
1168 if ( go_namespace_limit != null ) {
1169 System.out.println( "Limit GO terms to : " + go_namespace_limit.toString() );
1170 html_desc.append( "<tr><td>Limit GO terms to</td><td>" + go_namespace_limit + "</td></tr>" + nl );
1172 if ( perform_pwc ) {
1173 System.out.println( "Suffix for PWC files : " + automated_pairwise_comparison_suffix );
1174 html_desc.append( "<tr><td>Suffix for PWC files</td><td>" + automated_pairwise_comparison_suffix
1175 + "</td></tr>" + nl );
1177 if ( out_dir != null ) {
1178 System.out.println( "Output directory : " + out_dir );
1180 if ( query_domain_ids != null ) {
1181 System.out.println( "Query domains (ordered) : " + query_domain_ids );
1182 html_desc.append( "<tr><td></td><td>" + query_domain_ids + "</td></tr>" + nl );
1184 System.out.println( "Write similarities to : " + output_file );
1185 System.out.print( " Scoring method : " );
1186 html_desc.append( "<tr><td>Scoring method:</td><td>" );
1187 switch ( scoring ) {
1189 System.out.println( "domain combinations based" );
1190 html_desc.append( "domain combinations based" + "</td></tr>" + nl );
1193 System.out.println( "domain counts based" );
1194 html_desc.append( "domain counts based" + "</td></tr>" + nl );
1197 System.out.println( "domain proteins counts based" );
1198 html_desc.append( "domain proteins counts based" + "</td></tr>" + nl );
1201 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1203 System.out.print( " Sort by : " );
1204 html_desc.append( "<tr><td>Sort by:</td><td>" );
1205 switch ( domain_similarity_sort_field ) {
1207 System.out.print( "score minimum" );
1208 html_desc.append( "score minimum" );
1211 System.out.print( "score maximum" );
1212 html_desc.append( "score maximum" );
1215 System.out.print( "score mean" );
1216 html_desc.append( "score mean" );
1219 System.out.print( "score standard deviation" );
1220 html_desc.append( "score standard deviation" );
1223 System.out.print( "species number" );
1224 html_desc.append( "species number" );
1227 System.out.print( "alphabetical domain identifier" );
1228 html_desc.append( "alphabetical domain identifier" );
1230 case MAX_DIFFERENCE:
1231 System.out.print( "(maximal) difference" );
1232 html_desc.append( "(maximal) difference" );
1234 case ABS_MAX_COUNTS_DIFFERENCE:
1235 System.out.print( "absolute (maximal) counts difference" );
1236 html_desc.append( "absolute (maximal) counts difference" );
1238 case MAX_COUNTS_DIFFERENCE:
1239 System.out.print( "(maximal) counts difference" );
1240 html_desc.append( "(maximal) counts difference" );
1243 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1245 if ( sort_by_species_count_first ) {
1246 System.out.println( " (sort by species count first)" );
1247 html_desc.append( " (sort by species count first)" );
1250 System.out.println();
1252 html_desc.append( "</td></tr>" + nl );
1253 System.out.print( " Detailedness : " );
1254 switch ( detailedness ) {
1256 System.out.println( "basic" );
1258 case LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES:
1259 System.out.println( "list combining domains for each species" );
1262 System.out.println( "punctilious" );
1265 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for detailedness" );
1267 System.out.print( " Print option : " );
1268 switch ( domain_similarity_print_option ) {
1270 System.out.println( "HTML" );
1272 case SIMPLE_TAB_DELIMITED:
1273 System.out.println( "simple tab delimited" );
1276 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for print option" );
1278 System.out.print( " Species matrix : " + species_matrix );
1279 System.out.println();
1280 final File dc_data_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + DATA_FILE_SUFFIX );
1281 System.out.println( "Domain comb data output : " + dc_data_file );
1282 html_desc.append( "<tr><td>Domain combination data output:</td><td> " + dc_data_file + " </td></tr>" );
1283 System.out.println();
1284 if ( perform_pwc ) {
1285 System.out.println( "Pairwise comparisons: " );
1286 html_desc.append( "<tr><td>Pairwise comparisons:</td><td></td></tr>" );
1287 System.out.print( " Sort by : " );
1288 html_desc.append( "<tr><td>Sort by:</td><td>" );
1289 switch ( domain_similarity_sort_field_for_automated_pwc ) {
1291 System.out.print( "score mean" );
1292 html_desc.append( "score mean" );
1295 System.out.print( "alphabetical domain identifier" );
1296 html_desc.append( "alphabetical domain identifier" );
1298 case MAX_DIFFERENCE:
1299 System.out.print( "difference" );
1300 html_desc.append( "difference" );
1302 case ABS_MAX_COUNTS_DIFFERENCE:
1303 System.out.print( "absolute counts difference" );
1304 html_desc.append( "absolute counts difference" );
1306 case MAX_COUNTS_DIFFERENCE:
1307 System.out.print( "counts difference" );
1308 html_desc.append( "counts difference" );
1312 .unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for similarities" );
1314 System.out.println();
1315 html_desc.append( "</td></tr>" + nl );
1316 if ( ( intrees != null ) && ( intrees.length > 0 ) ) {
1317 for( final File intree_file : intree_files ) {
1318 html_desc.append( "<tr><td>Intree for gain/loss parsimony analysis:</td><td>" + intree_file
1319 + "</td></tr>" + nl );
1320 System.out.println( " Intree for gain/loss pars.: " + intree_file );
1323 if ( radomize_fitch_parsimony ) {
1324 html_desc.append( "<tr><td> Random number seed for Fitch parsimony analysis:</td><td>"
1325 + random_number_seed_for_fitch_parsimony + "</td></tr>" + nl );
1326 System.out.println( " Random number seed : " + random_number_seed_for_fitch_parsimony );
1328 if ( ( domain_id_to_secondary_features_maps != null ) && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
1329 for( int i = 0; i < secondary_features_map_files.length; i++ ) {
1330 html_desc.append( "<tr><td>Secondary features map file:</td><td>"
1331 + secondary_features_map_files[ i ] + "</td></tr>" + nl );
1332 System.out.println( "Secondary features map file : " + secondary_features_map_files[ i ]
1333 + " [mappings for " + domain_id_to_secondary_features_maps[ i ].size() + " domain ids]" );
1335 System.out.println();
1336 System.out.println( "Domain ids to secondary features map:" );
1337 for( final String domain_id : domain_id_to_secondary_features_maps[ i ].keySet() ) {
1338 System.out.print( domain_id );
1339 System.out.print( " => " );
1340 for( final String sec : domain_id_to_secondary_features_maps[ i ].get( domain_id ) ) {
1341 System.out.print( sec );
1342 System.out.print( " " );
1344 System.out.println();
1349 } // if ( perform_pwc ) {
1350 System.out.println();
1351 html_desc.append( "<tr><td>Command line:</td><td>" + nl + nl + cla.getCommandLineArgsAsString() + nl + nl
1352 + "</td></tr>" + nl );
1353 System.out.println( "Command line : " + cla.getCommandLineArgsAsString() );
1354 BufferedWriter[] query_domains_writer_ary = null;
1355 List<String>[] query_domain_ids_array = null;
1356 if ( query_domain_ids != null ) {
1357 final String[] query_domain_ids_str_array = query_domain_ids.split( "#" );
1358 query_domain_ids_array = new ArrayList[ query_domain_ids_str_array.length ];
1359 query_domains_writer_ary = new BufferedWriter[ query_domain_ids_str_array.length ];
1360 for( int i = 0; i < query_domain_ids_str_array.length; i++ ) {
1361 String query_domain_ids_str = query_domain_ids_str_array[ i ];
1362 final String[] query_domain_ids_str_ary = query_domain_ids_str.split( "~" );
1363 final List<String> query = new ArrayList<String>();
1364 for( final String element : query_domain_ids_str_ary ) {
1365 query.add( element );
1367 query_domain_ids_array[ i ] = query;
1368 query_domain_ids_str = query_domain_ids_str.replace( '~', '_' );
1369 String protein_names_writer_str = query_domain_ids_str + surfacing.SEQ_EXTRACT_SUFFIX;
1370 if ( out_dir != null ) {
1371 protein_names_writer_str = out_dir + ForesterUtil.FILE_SEPARATOR + protein_names_writer_str;
1374 query_domains_writer_ary[ i ] = new BufferedWriter( new FileWriter( protein_names_writer_str ) );
1376 catch ( final IOException e ) {
1377 ForesterUtil.fatalError( surfacing.PRG_NAME, "Could not open [" + protein_names_writer_str + "]: "
1378 + e.getLocalizedMessage() );
1382 SortedMap<Species, List<Protein>> protein_lists_per_species = null; //This will only be created if neede.
1383 boolean need_protein_lists_per_species = false;
1384 if ( ( plus_minus_analysis_high_copy_base_species.size() > 0 ) || output_protein_lists_for_all_domains ) {
1385 need_protein_lists_per_species = true;
1387 if ( need_protein_lists_per_species ) {
1388 protein_lists_per_species = new TreeMap<Species, List<Protein>>();
1390 List<GenomeWideCombinableDomains> gwcd_list = new ArrayList<GenomeWideCombinableDomains>( number_of_genomes );
1391 final SortedSet<String> all_domains_encountered = new TreeSet<String>();
1392 final SortedSet<BinaryDomainCombination> all_bin_domain_combinations_encountered = new TreeSet<BinaryDomainCombination>();
1393 List<BinaryDomainCombination> all_bin_domain_combinations_gained_fitch = null;
1394 List<BinaryDomainCombination> all_bin_domain_combinations_lost_fitch = null;
1395 if ( ( intrees != null ) && ( intrees.length == 1 ) ) {
1396 all_bin_domain_combinations_gained_fitch = new ArrayList<BinaryDomainCombination>();
1397 all_bin_domain_combinations_lost_fitch = new ArrayList<BinaryDomainCombination>();
1399 final File per_genome_domain_promiscuity_statistics_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR
1400 + output_file + D_PROMISCUITY_FILE_SUFFIX );
1401 BufferedWriter per_genome_domain_promiscuity_statistics_writer = null;
1403 per_genome_domain_promiscuity_statistics_writer = new BufferedWriter( new FileWriter( per_genome_domain_promiscuity_statistics_file ) );
1404 per_genome_domain_promiscuity_statistics_writer.write( "Species:\t" );
1405 per_genome_domain_promiscuity_statistics_writer.write( "Mean:\t" );
1406 per_genome_domain_promiscuity_statistics_writer.write( "SD:\t" );
1407 per_genome_domain_promiscuity_statistics_writer.write( "Median:\t" );
1408 per_genome_domain_promiscuity_statistics_writer.write( "Min:\t" );
1409 per_genome_domain_promiscuity_statistics_writer.write( "Max:\t" );
1410 per_genome_domain_promiscuity_statistics_writer.write( "N:\t" );
1411 per_genome_domain_promiscuity_statistics_writer.write( "Max Promiscuous Domains:"
1412 + ForesterUtil.LINE_SEPARATOR );
1414 catch ( final IOException e2 ) {
1415 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1417 final File log_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file + LOG_FILE_SUFFIX );
1418 BufferedWriter log_writer = null;
1420 log_writer = new BufferedWriter( new FileWriter( log_file ) );
1422 catch ( final IOException e2 ) {
1423 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1425 BufferedWriter dc_data_writer = null;
1427 dc_data_writer = new BufferedWriter( new FileWriter( dc_data_file ) );
1428 dc_data_writer.write( DATA_FILE_DESC );
1429 dc_data_writer.write( ForesterUtil.LINE_SEPARATOR );
1431 catch ( final IOException e2 ) {
1432 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getMessage() );
1434 DescriptiveStatistics protein_coverage_stats = new BasicDescriptiveStatistics();
1435 DescriptiveStatistics all_genomes_domains_per_potein_stats = new BasicDescriptiveStatistics();
1436 final SortedMap<Integer, Integer> all_genomes_domains_per_potein_histo = new TreeMap<Integer, Integer>();
1437 final SortedSet<String> domains_which_are_always_single = new TreeSet<String>();
1438 final SortedSet<String> domains_which_are_sometimes_single_sometimes_not = new TreeSet<String>();
1439 final SortedSet<String> domains_which_never_single = new TreeSet<String>();
1440 BufferedWriter domains_per_potein_stats_writer = null;
1442 domains_per_potein_stats_writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR
1443 + output_file + "_domains_per_potein_stats.txt" ) );
1444 domains_per_potein_stats_writer.write( "Genome" );
1445 domains_per_potein_stats_writer.write( "\t" );
1446 domains_per_potein_stats_writer.write( "Mean" );
1447 domains_per_potein_stats_writer.write( "\t" );
1448 domains_per_potein_stats_writer.write( "SD" );
1449 domains_per_potein_stats_writer.write( "\t" );
1450 domains_per_potein_stats_writer.write( "Median" );
1451 domains_per_potein_stats_writer.write( "\t" );
1452 domains_per_potein_stats_writer.write( "N" );
1453 domains_per_potein_stats_writer.write( "\t" );
1454 domains_per_potein_stats_writer.write( "Min" );
1455 domains_per_potein_stats_writer.write( "\t" );
1456 domains_per_potein_stats_writer.write( "Max" );
1457 domains_per_potein_stats_writer.write( "\n" );
1459 catch ( final IOException e3 ) {
1460 e3.printStackTrace();
1462 Map<String, DescriptiveStatistics> protein_length_stats_by_dc = null;
1463 Map<String, DescriptiveStatistics> domain_number_stats_by_dc = null;
1464 final Map<String, DescriptiveStatistics> domain_length_stats_by_domain = new HashMap<String, DescriptiveStatistics>();
1465 if ( perform_dc_regain_proteins_stats ) {
1466 protein_length_stats_by_dc = new HashMap<String, DescriptiveStatistics>();
1467 domain_number_stats_by_dc = new HashMap<String, DescriptiveStatistics>();
1469 DomainLengthsTable domain_lengths_table = null;
1470 if ( domain_length_analysis ) {
1471 domain_lengths_table = new DomainLengthsTable();
1474 final SortedMap<String, Set<String>> distinct_domain_architecutures_per_genome = new TreeMap<String, Set<String>>();
1475 final SortedMap<String, Integer> distinct_domain_architecuture_counts = new TreeMap<String, Integer>();
1476 for( int i = 0; i < number_of_genomes; ++i ) {
1477 System.out.println();
1478 System.out.println( ( i + 1 ) + "/" + number_of_genomes );
1479 SurfacingUtil.log( ( i + 1 ) + "/" + number_of_genomes, log_writer );
1480 System.out.println( "Processing : " + input_file_properties[ i ][ 1 ]
1481 + " [" + input_file_properties[ i ][ 0 ] + "]" );
1482 SurfacingUtil.log( "Genome : " + input_file_properties[ i ][ 1 ]
1483 + " [" + input_file_properties[ i ][ 0 ] + "]", log_writer );
1484 HmmscanPerDomainTableParser parser = null;
1485 INDIVIDUAL_SCORE_CUTOFF ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF.NONE;
1486 if ( individual_score_cutoffs != null ) {
1487 ind_score_cutoff = INDIVIDUAL_SCORE_CUTOFF_DEFAULT;
1489 if ( ( positive_filter_file != null ) || ( negative_filter_file != null )
1490 || ( negative_domains_filter_file != null ) ) {
1491 HmmscanPerDomainTableParser.FilterType filter_type = HmmscanPerDomainTableParser.FilterType.NONE;
1492 if ( positive_filter_file != null ) {
1493 filter_type = HmmscanPerDomainTableParser.FilterType.POSITIVE_PROTEIN;
1495 else if ( negative_filter_file != null ) {
1496 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_PROTEIN;
1498 else if ( negative_domains_filter_file != null ) {
1499 filter_type = HmmscanPerDomainTableParser.FilterType.NEGATIVE_DOMAIN;
1501 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1502 input_file_properties[ i ][ 1 ],
1509 parser = new HmmscanPerDomainTableParser( new File( input_file_properties[ i ][ 0 ] ),
1510 input_file_properties[ i ][ 1 ],
1514 if ( fs_e_value_max >= 0.0 ) {
1515 parser.setFsEValueMaximum( fs_e_value_max );
1517 if ( ie_value_max >= 0.0 ) {
1518 parser.setIEValueMaximum( ie_value_max );
1520 parser.setIgnoreDufs( ignore_dufs );
1521 parser.setIgnoreVirusLikeIds( ignore_virus_like_ids );
1522 parser.setIgnoreEngulfedDomains( no_engulfing_overlaps );
1523 if ( max_allowed_overlap != surfacing.MAX_ALLOWED_OVERLAP_DEFAULT ) {
1524 parser.setMaxAllowedOverlap( max_allowed_overlap );
1526 parser.setReturnType( HmmscanPerDomainTableParser.ReturnType.UNORDERED_PROTEIN_DOMAIN_COLLECTION_PER_PROTEIN );
1527 if ( individual_score_cutoffs != null ) {
1528 parser.setIndividualScoreCutoffs( individual_score_cutoffs );
1530 List<Protein> protein_list = null;
1532 protein_list = parser.parse();
1534 catch ( final IOException e ) {
1535 ForesterUtil.fatalError( surfacing.PRG_NAME, e.getMessage() );
1537 catch ( final Exception e ) {
1538 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, e.getMessage(), e );
1541 System.out.println( "Domains ignored due to negative domain filter: " );
1542 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToNegativeDomainFilterCountsMap() );
1543 System.out.println( "Domains ignored due to virus like id: " );
1544 ForesterUtil.printCountingMap( parser.getDomainsIgnoredDueToVirusLikeIdCountsMap() );
1546 final double coverage = ( double ) protein_list.size() / parser.getProteinsEncountered();
1547 protein_coverage_stats.addValue( coverage );
1548 int distinct_das = -1;
1549 if ( da_analysis ) {
1550 final String genome = input_file_properties[ i ][ 0 ];
1551 distinct_das = SurfacingUtil.storeDomainArchitectures( genome,
1552 distinct_domain_architecutures_per_genome,
1554 distinct_domain_architecuture_counts );
1556 System.out.println( "Number of proteins encountered : " + parser.getProteinsEncountered() );
1557 SurfacingUtil.log( "Number of proteins encountered : " + parser.getProteinsEncountered(),
1559 System.out.println( "Number of proteins stored : " + protein_list.size() );
1560 SurfacingUtil.log( "Number of proteins stored : " + protein_list.size(), log_writer );
1561 System.out.println( "Coverage : "
1562 + ForesterUtil.roundToInt( 100.0 * coverage ) + "%" );
1563 SurfacingUtil.log( "Coverage : "
1564 + ForesterUtil.roundToInt( 100.0 * coverage ) + "%",
1566 System.out.println( "Domains encountered : " + parser.getDomainsEncountered() );
1567 SurfacingUtil.log( "Domains encountered : " + parser.getDomainsEncountered(),
1569 System.out.println( "Domains stored : " + parser.getDomainsStored() );
1570 SurfacingUtil.log( "Domains stored : " + parser.getDomainsStored(),
1572 System.out.println( "Distinct domains stored : "
1573 + parser.getDomainsStoredSet().size() );
1574 SurfacingUtil.log( "Distinct domains stored : "
1575 + parser.getDomainsStoredSet().size(), log_writer );
1576 System.out.println( "Domains ignored due to individual score cutoffs: "
1577 + parser.getDomainsIgnoredDueToIndividualScoreCutoff() );
1578 SurfacingUtil.log( "Domains ignored due to individual score cutoffs: "
1579 + parser.getDomainsIgnoredDueToIndividualScoreCutoff(),
1581 System.out.println( "Domains ignored due to FS E-value : "
1582 + parser.getDomainsIgnoredDueToFsEval() );
1583 SurfacingUtil.log( "Domains ignored due to FS E-value : "
1584 + parser.getDomainsIgnoredDueToFsEval(),
1586 System.out.println( "Domains ignored due to iE-value : "
1587 + parser.getDomainsIgnoredDueToIEval() );
1588 SurfacingUtil.log( "Domains ignored due to iE-value : "
1589 + parser.getDomainsIgnoredDueToIEval(),
1591 System.out.println( "Domains ignored due to DUF designation : "
1592 + parser.getDomainsIgnoredDueToDuf() );
1594 .log( "Domains ignored due to DUF designation : " + parser.getDomainsIgnoredDueToDuf(),
1596 if ( ignore_virus_like_ids ) {
1597 System.out.println( "Domains ignored due virus like ids : "
1598 + parser.getDomainsIgnoredDueToVirusLikeIds() );
1599 SurfacingUtil.log( "Domains ignored due virus like ids : "
1600 + parser.getDomainsIgnoredDueToVirusLikeIds(),
1603 System.out.println( "Domains ignored due negative domain filter : "
1604 + parser.getDomainsIgnoredDueToNegativeDomainFilter() );
1605 SurfacingUtil.log( "Domains ignored due negative domain filter : "
1606 + parser.getDomainsIgnoredDueToNegativeDomainFilter(),
1608 System.out.println( "Domains ignored due to overlap : "
1609 + parser.getDomainsIgnoredDueToOverlap() );
1610 SurfacingUtil.log( "Domains ignored due to overlap : "
1611 + parser.getDomainsIgnoredDueToOverlap(),
1613 if ( negative_filter_file != null ) {
1614 System.out.println( "Proteins ignored due to negative filter : "
1615 + parser.getProteinsIgnoredDueToFilter() );
1616 SurfacingUtil.log( "Proteins ignored due to negative filter : "
1617 + parser.getProteinsIgnoredDueToFilter(),
1620 if ( positive_filter_file != null ) {
1621 System.out.println( "Proteins ignored due to positive filter : "
1622 + parser.getProteinsIgnoredDueToFilter() );
1623 SurfacingUtil.log( "Proteins ignored due to positive filter : "
1624 + parser.getProteinsIgnoredDueToFilter(),
1627 if ( da_analysis ) {
1628 System.out.println( "Distinct domain architectures stored : " + distinct_das );
1629 SurfacingUtil.log( "Distinct domain architectures stored : " + distinct_das, log_writer );
1631 System.out.println( "Time for processing : " + parser.getTime() + "ms" );
1632 SurfacingUtil.log( "", log_writer );
1635 for( final Protein protein : protein_list ) {
1636 dc_data_writer.write( SurfacingUtil.proteinToDomainCombinations( protein, count + "", "\t" )
1639 for( final Domain d : protein.getProteinDomains() ) {
1640 final String d_str = d.getDomainId().toString();
1641 if ( !domain_length_stats_by_domain.containsKey( d_str ) ) {
1642 domain_length_stats_by_domain.put( d_str, new BasicDescriptiveStatistics() );
1644 domain_length_stats_by_domain.get( d_str ).addValue( d.getLength() );
1648 catch ( final IOException e ) {
1649 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1651 SurfacingUtil.domainsPerProteinsStatistics( input_file_properties[ i ][ 1 ],
1653 all_genomes_domains_per_potein_stats,
1654 all_genomes_domains_per_potein_histo,
1655 domains_which_are_always_single,
1656 domains_which_are_sometimes_single_sometimes_not,
1657 domains_which_never_single,
1658 domains_per_potein_stats_writer );
1659 if ( domain_length_analysis ) {
1660 domain_lengths_table.addLengths( protein_list );
1662 if ( !da_analysis ) {
1663 gwcd_list.add( BasicGenomeWideCombinableDomains
1664 .createInstance( protein_list,
1665 ignore_combination_with_same,
1666 new BasicSpecies( input_file_properties[ i ][ 1 ] ),
1667 domain_id_to_go_ids_map,
1669 protein_length_stats_by_dc,
1670 domain_number_stats_by_dc ) );
1671 if ( gwcd_list.get( i ).getSize() > 0 ) {
1672 if ( output_binary_domain_combinationsfor_counts ) {
1674 .writeDomainCombinationsCountsFile( input_file_properties,
1676 per_genome_domain_promiscuity_statistics_writer,
1681 if ( output_binary_domain_combinationsfor_graph_analysis ) {
1682 SurfacingUtil.writeBinaryDomainCombinationsFileForGraphAnalysis( input_file_properties,
1688 SurfacingUtil.addAllDomainIdsToSet( gwcd_list.get( i ), all_domains_encountered );
1689 SurfacingUtil.addAllBinaryDomainCombinationToSet( gwcd_list.get( i ),
1690 all_bin_domain_combinations_encountered );
1693 if ( query_domains_writer_ary != null ) {
1694 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1696 SurfacingUtil.extractProteinNames( protein_list,
1697 query_domain_ids_array[ j ],
1698 query_domains_writer_ary[ j ],
1700 LIMIT_SPEC_FOR_PROT_EX );
1701 query_domains_writer_ary[ j ].flush();
1703 catch ( final IOException e ) {
1704 e.printStackTrace();
1708 if ( need_protein_lists_per_species ) {
1709 protein_lists_per_species.put( new BasicSpecies( input_file_properties[ i ][ 1 ] ), protein_list );
1714 catch ( final IOException e2 ) {
1715 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1718 } // for( int i = 0; i < number_of_genomes; ++i ) {
1719 ForesterUtil.programMessage( PRG_NAME, "Wrote domain promiscuities to: "
1720 + per_genome_domain_promiscuity_statistics_file );
1722 if ( da_analysis ) {
1723 SurfacingUtil.performDomainArchitectureAnalysis( distinct_domain_architecutures_per_genome,
1724 distinct_domain_architecuture_counts,
1726 new File( out_dir.toString() + "/" + output_file
1727 + "_DA_counts.txt" ),
1728 new File( out_dir.toString() + "/" + output_file
1729 + "_unique_DAs.txt" ) );
1730 distinct_domain_architecutures_per_genome.clear();
1731 distinct_domain_architecuture_counts.clear();
1735 domains_per_potein_stats_writer.write( "ALL" );
1736 domains_per_potein_stats_writer.write( "\t" );
1737 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.arithmeticMean() + "" );
1738 domains_per_potein_stats_writer.write( "\t" );
1739 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.sampleStandardDeviation() + "" );
1740 domains_per_potein_stats_writer.write( "\t" );
1741 if ( all_genomes_domains_per_potein_stats.getN() <= 300 ) {
1742 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.median() + "" );
1743 domains_per_potein_stats_writer.write( "\t" );
1745 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getN() + "" );
1746 domains_per_potein_stats_writer.write( "\t" );
1747 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getMin() + "" );
1748 domains_per_potein_stats_writer.write( "\t" );
1749 domains_per_potein_stats_writer.write( all_genomes_domains_per_potein_stats.getMax() + "" );
1750 domains_per_potein_stats_writer.write( "\n" );
1751 domains_per_potein_stats_writer.close();
1752 all_genomes_domains_per_potein_stats = null;
1753 SurfacingUtil.printOutPercentageOfMultidomainProteins( all_genomes_domains_per_potein_histo, log_writer );
1754 ForesterUtil.map2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1755 + "_all_genomes_domains_per_potein_histo.txt" ), all_genomes_domains_per_potein_histo, "\t", "\n" );
1756 ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1757 + "_domains_always_single_.txt" ), domains_which_are_always_single, "\n" );
1758 ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1759 + "_domains_single_or_combined.txt" ), domains_which_are_sometimes_single_sometimes_not, "\n" );
1760 ForesterUtil.collection2file( new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file
1761 + "_domains_always_combined.txt" ), domains_which_never_single, "\n" );
1762 ForesterUtil.programMessage( PRG_NAME,
1763 "Average of proteins with a least one domain assigned: "
1764 + ( 100 * protein_coverage_stats.arithmeticMean() ) + "% (+/-"
1765 + ( 100 * protein_coverage_stats.sampleStandardDeviation() ) + "%)" );
1766 ForesterUtil.programMessage( PRG_NAME, "Range of proteins with a least one domain assigned: "
1767 + ( 100 * protein_coverage_stats.getMin() ) + "%-" + ( 100 * protein_coverage_stats.getMax() )
1769 SurfacingUtil.log( "Average of prot with a least one dom assigned : "
1770 + ( 100 * protein_coverage_stats.arithmeticMean() ) + "% (+/-"
1771 + ( 100 * protein_coverage_stats.sampleStandardDeviation() ) + "%)",
1773 SurfacingUtil.log( "Range of prot with a least one dom assigned : "
1774 + ( 100 * protein_coverage_stats.getMin() ) + "%-"
1775 + ( 100 * protein_coverage_stats.getMax() ) + "%",
1777 protein_coverage_stats = null;
1779 catch ( final IOException e2 ) {
1780 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1782 if ( query_domains_writer_ary != null ) {
1783 for( int j = 0; j < query_domain_ids_array.length; j++ ) {
1785 query_domains_writer_ary[ j ].close();
1787 catch ( final IOException e ) {
1788 ForesterUtil.fatalError( surfacing.PRG_NAME, e.toString() );
1793 per_genome_domain_promiscuity_statistics_writer.close();
1794 dc_data_writer.close();
1797 catch ( final IOException e2 ) {
1798 ForesterUtil.fatalError( surfacing.PRG_NAME, e2.getLocalizedMessage() );
1800 if ( domain_length_analysis ) {
1802 SurfacingUtil.executeDomainLengthAnalysis( input_file_properties,
1804 domain_lengths_table,
1805 domain_lengths_analysis_outfile );
1807 catch ( final IOException e1 ) {
1808 ForesterUtil.fatalError( surfacing.PRG_NAME, e1.toString() );
1810 System.out.println();
1811 ForesterUtil.programMessage( PRG_NAME, "Wrote domain length data to: " + domain_lengths_analysis_outfile );
1812 System.out.println();
1814 domain_lengths_table = null;
1815 final long analysis_start_time = new Date().getTime();
1816 PairwiseDomainSimilarityCalculator pw_calc = null;
1817 final DomainSimilarityCalculator calc = new BasicDomainSimilarityCalculator( domain_similarity_sort_field,
1818 sort_by_species_count_first,
1819 number_of_genomes == 2,
1820 CALC_SIMILARITY_SCORES,
1822 switch ( scoring ) {
1824 pw_calc = new CombinationsBasedPairwiseDomainSimilarityCalculator();
1827 pw_calc = new DomainCountsBasedPairwiseSimilarityCalculator();
1830 pw_calc = new ProteinCountsBasedPairwiseDomainSimilarityCalculator();
1833 ForesterUtil.unexpectedFatalError( surfacing.PRG_NAME, "unknown value for sorting for scoring" );
1835 DomainSimilarityCalculator.GoAnnotationOutput go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.NONE;
1836 if ( domain_id_to_go_ids_map != null ) {
1837 go_annotation_output = DomainSimilarityCalculator.GoAnnotationOutput.ALL;
1839 final SortedSet<DomainSimilarity> similarities = calc
1840 .calculateSimilarities( pw_calc,
1842 ignore_domains_without_combs_in_all_spec,
1843 ignore_species_specific_domains );
1844 SurfacingUtil.decoratePrintableDomainSimilarities( similarities, detailedness );
1845 final Map<String, Integer> tax_code_to_id_map = SurfacingUtil.createTaxCodeToIdMap( intrees[ 0 ] );
1847 String my_outfile = output_file.toString();
1848 Map<Character, Writer> split_writers = null;
1849 Writer writer = null;
1850 if ( similarities.size() > MINIMAL_NUMBER_OF_SIMILARITIES_FOR_SPLITTING ) {
1851 if ( my_outfile.endsWith( ".html" ) ) {
1852 my_outfile = my_outfile.substring( 0, my_outfile.length() - 5 );
1854 split_writers = new HashMap<Character, Writer>();
1855 SurfacingUtil.createSplitWriters( out_dir, my_outfile, split_writers );
1857 else if ( !my_outfile.endsWith( ".html" ) ) {
1858 my_outfile += ".html";
1859 writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR + my_outfile ) );
1861 List<Species> species_order = null;
1862 if ( species_matrix ) {
1863 species_order = new ArrayList<Species>();
1864 for( int i = 0; i < number_of_genomes; i++ ) {
1865 species_order.add( new BasicSpecies( input_file_properties[ i ][ 1 ] ) );
1868 html_desc.append( "<tr><td>Sum of all distinct binary combinations:</td><td>"
1869 + all_bin_domain_combinations_encountered.size() + "</td></tr>" + nl );
1870 html_desc.append( "<tr><td>Sum of all distinct domains:</td><td>" + all_domains_encountered.size()
1871 + "</td></tr>" + nl );
1872 html_desc.append( "<tr><td>Analysis date/time:</td><td>"
1873 + new java.text.SimpleDateFormat( "yyyy.MM.dd HH:mm:ss" ).format( new java.util.Date() )
1874 + "</td></tr>" + nl );
1875 html_desc.append( "</table>" + nl );
1876 final Writer simple_tab_writer = new BufferedWriter( new FileWriter( out_dir + ForesterUtil.FILE_SEPARATOR
1877 + my_outfile + ".tsv" ) );
1878 SurfacingUtil.writeDomainSimilaritiesToFile( html_desc,
1879 new StringBuilder( number_of_genomes + " genomes" ),
1884 number_of_genomes == 2,
1886 domain_similarity_print_option,
1891 positive_filter_file != null ? filter : null );
1892 simple_tab_writer.close();
1893 ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote main output (includes domain similarities) to: \""
1894 + ( out_dir == null ? my_outfile : out_dir + ForesterUtil.FILE_SEPARATOR + my_outfile ) + "\"" );
1896 catch ( final IOException e ) {
1897 ForesterUtil.fatalError( surfacing.PRG_NAME, "Failed to write similarites to: \"" + output_file + "\" ["
1898 + e.getMessage() + "]" );
1900 System.out.println();
1901 final Species[] species = new Species[ number_of_genomes ];
1902 for( int i = 0; i < number_of_genomes; ++i ) {
1903 species[ i ] = new BasicSpecies( input_file_properties[ i ][ 1 ] );
1905 List<Phylogeny> inferred_trees = null;
1906 if ( ( number_of_genomes > 2 ) && perform_pwc ) {
1907 final PairwiseGenomeComparator pwgc = new PairwiseGenomeComparator();
1908 pwgc.performPairwiseComparisons( html_desc,
1909 sort_by_species_count_first,
1911 ignore_domains_without_combs_in_all_spec,
1912 ignore_species_specific_domains,
1913 domain_similarity_sort_field_for_automated_pwc,
1914 domain_similarity_print_option,
1916 domain_id_to_go_ids_map,
1923 automated_pairwise_comparison_suffix,
1925 surfacing.PAIRWISE_DOMAIN_COMPARISONS_PREFIX,
1930 CALC_SIMILARITY_SCORES,
1932 String matrix_output_file = new String( output_file.toString() );
1933 if ( matrix_output_file.indexOf( '.' ) > 1 ) {
1934 matrix_output_file = matrix_output_file.substring( 0, matrix_output_file.indexOf( '.' ) );
1936 if ( out_dir != null ) {
1937 matrix_output_file = out_dir + ForesterUtil.FILE_SEPARATOR + matrix_output_file;
1938 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
1940 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
1941 + surfacing.MATRIX_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc.getDomainDistanceScoresMeans() );
1943 .writeMatrixToFile( new File( matrix_output_file
1944 + surfacing.MATRIX_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ),
1945 pwgc.getSharedBinaryCombinationsBasedDistances() );
1946 SurfacingUtil.writeMatrixToFile( new File( matrix_output_file
1947 + surfacing.MATRIX_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ),
1948 pwgc.getSharedDomainsBasedDistances() );
1949 final Phylogeny nj_gd = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
1950 + surfacing.NJ_TREE_MEAN_SCORE_BASED_GENOME_DISTANCE_SUFFIX ), pwgc.getDomainDistanceScoresMeans()
1952 final Phylogeny nj_bc = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
1953 + surfacing.NJ_TREE_SHARED_BIN_COMBINATIONS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
1954 .getSharedBinaryCombinationsBasedDistances().get( 0 ) );
1955 final Phylogeny nj_d = SurfacingUtil.createNjTreeBasedOnMatrixToFile( new File( matrix_output_file
1956 + surfacing.NJ_TREE_SHARED_DOMAINS_BASED_GENOME_DISTANCE_SUFFIX ), pwgc
1957 .getSharedDomainsBasedDistances().get( 0 ) );
1958 inferred_trees = new ArrayList<Phylogeny>();
1959 inferred_trees.add( nj_gd );
1960 inferred_trees.add( nj_bc );
1961 inferred_trees.add( nj_d );
1962 } // if ( ( output_file != null ) && ( number_of_genomes > 2 ) && !isEmpty( automated_pairwise_comparison_suffix ) )
1963 if ( ( out_dir != null ) && ( !perform_pwc ) ) {
1964 output_file = new File( out_dir + ForesterUtil.FILE_SEPARATOR + output_file );
1966 if ( write_to_nexus ) {
1967 SurfacingUtil.writePresentToNexus( output_file, positive_filter_file, filter, gwcd_list );
1969 if ( ( ( intrees != null ) && ( intrees.length > 0 ) ) && ( number_of_genomes > 2 ) ) {
1970 final StringBuilder parameters_sb = SurfacingUtil.createParametersAsString( ignore_dufs,
1973 max_allowed_overlap,
1974 no_engulfing_overlaps,
1978 if ( radomize_fitch_parsimony ) {
1979 s += random_number_seed_for_fitch_parsimony + "_";
1982 for( final Phylogeny intree : intrees ) {
1983 final String outfile_name = ForesterUtil.removeSuffix( output_file.toString() ) + s
1984 + ForesterUtil.removeSuffix( intree_files[ i ].toString() );
1985 final DomainParsimonyCalculator domain_parsimony = DomainParsimonyCalculator.createInstance( intree,
1987 SurfacingUtil.executeParsimonyAnalysis( random_number_seed_for_fitch_parsimony,
1988 radomize_fitch_parsimony,
1992 domain_id_to_go_ids_map,
1995 parameters_sb.toString(),
1996 domain_id_to_secondary_features_maps,
1997 positive_filter_file == null ? null : filter,
1998 output_binary_domain_combinationsfor_graph_analysis,
1999 all_bin_domain_combinations_gained_fitch,
2000 all_bin_domain_combinations_lost_fitch,
2002 protein_length_stats_by_dc,
2003 domain_number_stats_by_dc,
2004 domain_length_stats_by_domain,
2007 use_last_in_fitch_parsimony,
2009 // Listing of all domain combinations gained is only done if only one input tree is used.
2010 if ( ( domain_id_to_secondary_features_maps != null )
2011 && ( domain_id_to_secondary_features_maps.length > 0 ) ) {
2013 for( final Map<String, Set<String>> domain_id_to_secondary_features_map : domain_id_to_secondary_features_maps ) {
2014 final Map<Species, MappingResults> mapping_results_map = new TreeMap<Species, MappingResults>();
2015 final DomainParsimonyCalculator secondary_features_parsimony = DomainParsimonyCalculator
2016 .createInstance( intree, gwcd_list, domain_id_to_secondary_features_map );
2018 .executeParsimonyAnalysisForSecondaryFeatures( outfile_name
2020 + secondary_features_map_files[ j++ ],
2021 secondary_features_parsimony,
2023 parameters_sb.toString(),
2024 mapping_results_map,
2025 use_last_in_fitch_parsimony );
2027 System.out.println();
2028 System.out.println( "Mapping to secondary features:" );
2029 for( final Species spec : mapping_results_map.keySet() ) {
2030 final MappingResults mapping_results = mapping_results_map.get( spec );
2031 final int total_domains = mapping_results.getSumOfFailures()
2032 + mapping_results.getSumOfSuccesses();
2033 System.out.print( spec + ":" );
2034 System.out.print( " mapped domains = " + mapping_results.getSumOfSuccesses() );
2035 System.out.print( ", not mapped domains = " + mapping_results.getSumOfFailures() );
2036 if ( total_domains > 0 ) {
2037 System.out.println( ", mapped ratio = "
2038 + ( ( 100 * mapping_results.getSumOfSuccesses() ) / total_domains ) + "%" );
2041 System.out.println( ", mapped ratio = n/a (total domains = 0 )" );
2048 } // for( final Phylogeny intree : intrees ) {
2050 if ( plus_minus_analysis_high_copy_base_species.size() > 0 ) {
2051 SurfacingUtil.executePlusMinusAnalysis( output_file,
2052 plus_minus_analysis_high_copy_base_species,
2053 plus_minus_analysis_high_copy_target_species,
2054 plus_minus_analysis_high_low_copy_species,
2056 protein_lists_per_species,
2057 domain_id_to_go_ids_map,
2059 plus_minus_analysis_numbers );
2061 if ( output_protein_lists_for_all_domains ) {
2062 SurfacingUtil.writeProteinListsForAllSpecies( out_dir,
2063 protein_lists_per_species,
2065 output_list_of_all_proteins_per_domain_e_value_max,
2066 positive_filter_file != null ? filter : null );
2069 if ( all_bin_domain_combinations_gained_fitch != null ) {
2072 .executeFitchGainsAnalysis( new File( output_file
2073 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_GAINED_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2074 all_bin_domain_combinations_gained_fitch,
2075 all_domains_encountered.size(),
2076 all_bin_domain_combinations_encountered,
2079 catch ( final IOException e ) {
2080 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2083 if ( all_bin_domain_combinations_lost_fitch != null ) {
2086 .executeFitchGainsAnalysis( new File( output_file
2087 + surfacing.OUTPUT_DOMAIN_COMBINATIONS_LOST_MORE_THAN_ONCE_ANALYSIS_SUFFIX ),
2088 all_bin_domain_combinations_lost_fitch,
2089 all_domains_encountered.size(),
2090 all_bin_domain_combinations_encountered,
2093 catch ( final IOException e ) {
2094 ForesterUtil.fatalError( PRG_NAME, e.getLocalizedMessage() );
2097 final Runtime rt = java.lang.Runtime.getRuntime();
2098 final long free_memory = rt.freeMemory() / 1000000;
2099 final long total_memory = rt.totalMemory() / 1000000;
2100 ForesterUtil.programMessage( PRG_NAME, "Time for analysis : " + ( new Date().getTime() - analysis_start_time )
2102 ForesterUtil.programMessage( PRG_NAME, "Total running time: " + ( new Date().getTime() - start_time ) + "ms " );
2103 ForesterUtil.programMessage( PRG_NAME, "Free memory : " + free_memory + "MB, total memory: "
2104 + total_memory + "MB" );
2105 ForesterUtil.programMessage( PRG_NAME, "If this application is useful to you, please cite:" );
2106 ForesterUtil.programMessage( PRG_NAME, surfacing.WWW );
2107 ForesterUtil.programMessage( PRG_NAME, "OK" );
2108 System.out.println();
2111 private static void printHelp() {
2112 System.out.println();
2113 System.out.println( "Usage:" );
2114 System.out.println();
2115 System.out.println( "% java -Xms256m -Xmx512m -cp forester.jar org.forester.applications." + surfacing.PRG_NAME
2116 + " [options] <phylogen(y|ies) infile> [external node name 1] [name 2] ... [name n]" );
2117 System.out.println();
2118 System.out.println( " Note: This software might need a significant amount of memory (heap space);" );
2120 .println( " hence use \"-Xms128m -Xmx512m\" (or more) to prevent a \"java.lang.OutOfMemoryError\"." );
2121 System.out.println();
2122 System.out.println( " Options: " );
2123 System.out.println( surfacing.DETAILEDNESS_OPTION + ": level of detail for similarities output file (default:"
2124 + DETAILEDNESS_DEFAULT + ")" );
2125 System.out.println( surfacing.IGNORE_COMBINATION_WITH_SAME_OPTION
2126 + ": to ignore combinations with self (default: not to ignore)" );
2128 .println( surfacing.IGNORE_DOMAINS_WITHOUT_COMBINATIONS_IN_ALL_SPECIES_OPTION
2129 + ": to ignore domains without combinations in any species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2131 .println( surfacing.IGNORE_DOMAINS_SPECIFIC_TO_ONE_SPECIES_OPTION
2132 + ": to ignore domains specific to one species (for similarity calc purposes, not for parsimony analyses) (default: not to ignore)" );
2133 System.out.println( surfacing.NOT_IGNORE_DUFS_OPTION
2134 + ": to _not_ ignore DUFs (domains with unknown function) (default: ignore DUFs)" );
2136 .println( surfacing.IGNORE_VIRAL_IDS
2137 + ": to ignore domains with ids containing 'vir', 'retro', 'transpos', 'phage', or starting with 'rv' or 'gag_'" );
2138 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_OPTION + ": sorting for similarities (default: "
2139 + DOMAIN_SORT_FILD_DEFAULT + ")" );
2140 System.out.println( surfacing.OUTPUT_FILE_OPTION + ": name for (main) output file (mandatory)" );
2141 System.out.println( surfacing.MAX_I_E_VALUE_OPTION + ": max (inclusive) iE-value" );
2142 System.out.println( surfacing.MAX_FS_E_VALUE_OPTION + ": max (inclusive) FS E-value" );
2143 System.out.println( surfacing.MAX_ALLOWED_OVERLAP_OPTION + ": maximal allowed domain overlap" );
2144 System.out.println( surfacing.NO_ENGULFING_OVERLAP_OPTION + ": to ignore engulfed lower confidence domains" );
2145 System.out.println( surfacing.SPECIES_MATRIX_OPTION + ": species matrix" );
2146 System.out.println( surfacing.SCORING_OPTION + ": scoring (default:" + SCORING_DEFAULT + ")" );
2147 System.out.println( surfacing.DOMAIN_COUNT_SORT_OPTION + ": sorting for domain counts (default:"
2148 + DOMAINS_SORT_ORDER_DEFAULT + ")" );
2149 System.out.println( surfacing.DOMAIN_SIMILARITY_PRINT_OPTION + ": domain similarity print option (default:"
2150 + DOMAIN_SIMILARITY_PRINT_OPTION_DEFAULT + ")" );
2151 System.out.println( surfacing.CUTOFF_SCORE_FILE_OPTION + ": cutoff score file" );
2152 System.out.println( surfacing.DOMAIN_SIMILARITY_SORT_BY_SPECIES_COUNT_FIRST_OPTION
2153 + ": sort by species count first" );
2154 System.out.println( surfacing.OUTPUT_DIR_OPTION + ": output directory" );
2155 System.out.println( surfacing.PFAM_TO_GO_FILE_USE_OPTION + ": Pfam to GO mapping file" );
2156 System.out.println( surfacing.GO_OBO_FILE_USE_OPTION + ": GO terms file (OBO format)" );
2157 System.out.println( surfacing.GO_NAMESPACE_LIMIT_OPTION + ": limit GO term to one GO namespace" );
2158 System.out.println( surfacing.PAIRWISE_DOMAIN_COMPARISONS_OPTION
2159 + "[=<suffix for pairwise comparison output files>]: to perform pairwise comparison based analyses" );
2160 System.out.println( surfacing.INPUT_SPECIES_TREE_OPTION
2161 + ": species tree, to perform (Dollo, Fitch) parismony analyses" );
2163 .println( surfacing.INPUT_SPECIES_TREE_OPTION
2164 + "=<treefiles in phyloXML format, separated by #>: to infer domain/binary domain combination gains/losses on given species trees" );
2165 System.out.println( surfacing.FILTER_POSITIVE_OPTION
2166 + "=<file>: to filter out proteins not containing at least one domain listed in <file>" );
2167 System.out.println( surfacing.FILTER_NEGATIVE_OPTION
2168 + "=<file>: to filter out proteins containing at least one domain listed in <file>" );
2169 System.out.println( surfacing.FILTER_NEGATIVE_DOMAINS_OPTION
2170 + "=<file>: to filter out (ignore) domains listed in <file>" );
2171 System.out.println( surfacing.INPUT_GENOMES_FILE_OPTION + "=<file>: to read input files from <file>" );
2173 .println( surfacing.RANDOM_SEED_FOR_FITCH_PARSIMONY_OPTION
2174 + "=<seed>: seed for random number generator for Fitch Parsimony analysis (type: long, default: no randomization - given a choice, prefer absence" );
2175 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS
2176 + ": to consider directedness in binary combinations: e.g. A-B != B-A" );
2177 System.out.println( surfacing.CONSIDER_DOMAIN_COMBINATION_DIRECTEDNESS_AND_ADJACENCY
2178 + ": to consider directedness and adjacency in binary combinations" );
2180 .println( surfacing.SEQ_EXTRACT_OPTION
2181 + "=<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')" );
2182 System.out.println( surfacing.SECONDARY_FEATURES_PARSIMONY_MAP_FILE
2183 + "=<file>: to perfom parsimony analysis on secondary features" );
2184 System.out.println( surfacing.PLUS_MINUS_ANALYSIS_OPTION + "=<file>: to presence/absence genome analysis" );
2185 System.out.println( surfacing.DOMAIN_COMBINITONS_COUNTS_OUTPUT_OPTION
2186 + ": to output binary domain counts (as individual files)" );
2187 System.out.println( surfacing.DOMAIN_COMBINITONS_OUTPUT_OPTION_FOR_GRAPH_ANALYSIS
2188 + ": to output binary domain combinations for (downstream) graph analysis" );
2189 System.out.println( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_OPTIONS + ": to output all proteins per domain" );
2190 System.out.println( surfacing.OUTPUT_LIST_OF_ALL_PROTEINS_PER_DOMAIN_E_VALUE_OPTION
2191 + ": e value max per domain for output of all proteins per domain" );
2192 System.out.println( surfacing.USE_LAST_IN_FITCH_OPTION + ": to use last in Fitch parsimony" );
2193 System.out.println( surfacing.WRITE_TO_NEXUS_OPTION + ": to output in Nexus format" );
2194 System.out.println( PERFORM_DC_FITCH + ": to perform DC Fitch parsimony" );
2195 System.out.println( PERFORM_DC_REGAIN_PROTEINS_STATS_OPTION + ": to perform DC regain protein statistics" );
2196 System.out.println( DA_ANALYSIS_OPTION + ": to perform DA analysis" );
2197 System.out.println( PERFORM_DOMAIN_LENGTH_ANALYSIS_OPTION + ": to perform domain length analysis" );
2198 System.out.println();
2199 System.out.println();
2201 .println( "Example: surfacing -p2g=pfam2go_130621.txt -obo=gene_onotology_130621.obo -species_tree=tol_156.xml -last -detail=punctilious -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" );
2202 System.out.println();