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