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