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