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