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