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