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