in progress
[jalview.git] / forester / java / src / org / forester / application / msa_compactor.java
index 4e51675..15c2d4c 100644 (file)
@@ -46,6 +46,12 @@ import org.forester.util.CommandLineArguments;
 import org.forester.util.DescriptiveStatistics;
 import org.forester.util.ForesterUtil;
 
+
+/*
+java -cp C:\Users\czmasek\SOFTWARE_DEV\ECLIPSE\forester\java\fo
+rester.jar org.forester.application.msa_compactor Bcl-2_e1_20_mafft -t
+*/
+
 public class msa_compactor {
 
     final private static NumberFormat NF_1                                   = new DecimalFormat( "0.#" );
@@ -61,6 +67,7 @@ public class msa_compactor {
     final static private String       STEP_OPTION                            = "s";
     final static private String       LENGTH_OPTION                          = "l";
     final static private String       REALIGN_OPTION                         = "a";
+    final static private String       INFO_ONLY_OPTION                       = "i";
     //
     final static private String       STEP_FOR_DIAGNOSTICS_OPTION            = "sd";
     final static private String       MIN_LENGTH_OPTION                      = "ml";
@@ -70,7 +77,7 @@ public class msa_compactor {
     final static private String       OUTPUT_REMOVED_SEQS_OPTION             = "ro";
     final static private String       MAFFT_OPTIONS                          = "mo";
     final static private String       PERFORM_PHYLOGENETIC_INFERENCE         = "t";
-    //        
+    //
     final static private String       PATH_TO_MAFFT_OPTION                   = "mafft";
     final static private String       DO_NOT_NORMALIZE_FOR_EFF_LENGTH_OPTION = "nn";
     final static private String       PRG_NAME                               = "msa_compactor";
@@ -124,6 +131,7 @@ public class msa_compactor {
             allowed_options.add( OUTPUT_REMOVED_SEQS_OPTION );
             allowed_options.add( MAFFT_OPTIONS );
             allowed_options.add( PERFORM_PHYLOGENETIC_INFERENCE );
+            allowed_options.add( INFO_ONLY_OPTION );
             final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
             if ( dissallowed_options.length() > 0 ) {
                 ForesterUtil.fatalError( PRG_NAME, "unknown option(s): " + dissallowed_options );
@@ -137,6 +145,11 @@ public class msa_compactor {
                 msa = DeleteableMsa.createInstance( GeneralMsaParser.parse( is ) );
             }
             final DescriptiveStatistics initial_msa_stats = MsaMethods.calculateEffectiveLengthStatistics( msa );
+            if (cla.isOptionSet( INFO_ONLY_OPTION ) ) {
+                printInfo( in, msa, initial_msa_stats );
+                System.exit( 0 );
+            }
+            
             final boolean chart_only = ( !cla.isOptionSet( LENGTH_OPTION ) )
                     && ( !cla.isOptionSet( REMOVE_WORST_OFFENDERS_OPTION ) )
                     && ( !cla.isOptionSet( AV_GAPINESS_OPTION ) && ( !cla.isOptionSet( MIN_LENGTH_OPTION ) ) );
@@ -145,7 +158,7 @@ public class msa_compactor {
             }
             if ( cla.isOptionSet( REMOVE_WORST_OFFENDERS_OPTION ) ) {
                 worst_remove = cla.getOptionValueAsInt( REMOVE_WORST_OFFENDERS_OPTION );
-                if ( ( worst_remove < 1 ) || ( worst_remove >= msa.getNumberOfSequences() - 1 ) ) {
+                if ( ( worst_remove < 1 ) || ( worst_remove >= ( msa.getNumberOfSequences() - 1 ) ) ) {
                     ForesterUtil.fatalError( PRG_NAME, "number of worst offender sequences to remove is out of range: "
                             + worst_remove );
                 }
@@ -169,7 +182,7 @@ public class msa_compactor {
                 if ( length >= msa.getLength() ) {
                     ForesterUtil.fatalError( PRG_NAME,
                                              "target length is out of range [longer than MSA (" + msa.getLength()
-                                                     + ")]: " + length );
+                                             + ")]: " + length );
                 }
                 else if ( length < initial_msa_stats.getMin() ) {
                     ForesterUtil.fatalError( PRG_NAME,
@@ -269,8 +282,8 @@ public class msa_compactor {
             if ( chart_only ) {
                 if ( ( out != null ) || ( removed_seqs_out_base != null ) ) {
                     ForesterUtil
-                            .fatalError( PRG_NAME,
-                                         "chart only, no outfile(s) produced, thus no need to indicate output file(s)" );
+                    .fatalError( PRG_NAME,
+                                 "chart only, no outfile(s) produced, thus no need to indicate output file(s)" );
                 }
                 if ( !realign && cla.isOptionSet( STEP_OPTION ) ) {
                     ForesterUtil.fatalError( PRG_NAME,
@@ -281,34 +294,14 @@ public class msa_compactor {
             if ( perform_phylogenetic_inference ) {
                 if ( step_for_diagnostics != 1 ) {
                     ForesterUtil.fatalError( PRG_NAME,
-                                             "step for diagnostics reports needs to be set to 1 for tree calculation" );
-                }
-            }
-            ForesterUtil.printProgramInformation( PRG_NAME,
-                                                  PRG_DESC,
-                                                  PRG_VERSION,
-                                                  PRG_DATE,
-                                                  E_MAIL,
-                                                  WWW,
-                                                  ForesterUtil.getForesterLibraryInformation() );
-            System.out.println( "Input MSA                            : " + in );
-            System.out.println( "  MSA length                         : " + msa.getLength() );
-            System.out.println( "  Number of sequences                : " + msa.getNumberOfSequences() );
-            System.out.println( "  Median sequence length             : " + NF_1.format( initial_msa_stats.median() ) );
-            System.out.println( "  Mean sequence length               : "
-                    + NF_1.format( initial_msa_stats.arithmeticMean() ) );
-            System.out.println( "  Max sequence length                : " + ( ( int ) initial_msa_stats.getMax() ) );
-            System.out.println( "  Min sequence length                : " + ( ( int ) initial_msa_stats.getMin() ) );
-            System.out.println( "  Gap ratio                          : "
-                    + NF_4.format( MsaMethods.calcGapRatio( msa ) ) );
-            System.out.println( "  Normalized Shannon Entropy (entn21): "
-                    + NF_4.format( MsaMethods.calcNormalizedShannonsEntropy( 21, msa ) ) );
+                            "step for diagnostics reports needs to be set to 1 for tree calculation" );
+                }
+            }
+            printInfo( in, msa, initial_msa_stats );
             if ( !chart_only ) {
                 System.out.println( "Output                               : " + out );
             }
-            else {
-                System.out.println( "Output                               : n/a" );
-            }
+            
             if ( removed_seqs_out_base != null ) {
                 System.out.println( "Write removed sequences to           : " + removed_seqs_out_base );
             }
@@ -416,13 +409,39 @@ public class msa_compactor {
         }
     }
 
+    private static void printInfo( final File in, DeleteableMsa msa, final DescriptiveStatistics initial_msa_stats ) {
+        ForesterUtil.printProgramInformation( PRG_NAME,
+                                              PRG_DESC,
+                                              PRG_VERSION,
+                                              PRG_DATE,
+                                              E_MAIL,
+                                              WWW,
+                                              ForesterUtil.getForesterLibraryInformation() );
+        System.out.println( "Input MSA                            : " + in );
+        System.out.println( "  MSA length                         : " + msa.getLength() );
+        System.out.println( "  Number of sequences                : " + msa.getNumberOfSequences() );
+        System.out.println( "  Median sequence length             : " + NF_1.format( initial_msa_stats.median() ) );
+        System.out.println( "  Mean sequence length               : "
+                + NF_1.format( initial_msa_stats.arithmeticMean() ) );
+        System.out.println( "  Max sequence length                : " + ( ( int ) initial_msa_stats.getMax() ) );
+        System.out.println( "  Min sequence length                : " + ( ( int ) initial_msa_stats.getMin() ) );
+        System.out.println( "  Gap ratio                          : "
+                + NF_4.format( MsaMethods.calcGapRatio( msa ) ) );
+        System.out.println( "  Mean gap count per 100 residues    : "
+                + NF_1.format( MsaMethods.calcNumberOfGapsPer100Stats( msa ).arithmeticMean() ) );
+        System.out.println( "  Normalized Shannon Entropy (entn7) : "
+                + NF_4.format( MsaMethods.calcNormalizedShannonsEntropy( 7, msa ) ) );
+        System.out.println( "  Normalized Shannon Entropy (entn21): "
+                + NF_4.format( MsaMethods.calcNormalizedShannonsEntropy( 21, msa ) ) );
+    }
+
     private static void checkPathToMafft( final String path_to_mafft ) {
         if ( !ForesterUtil.isEmpty( path_to_mafft ) && MsaInferrer.isInstalled( path_to_mafft ) ) {
         }
         else {
             if ( ForesterUtil.isEmpty( path_to_mafft ) ) {
                 ForesterUtil.fatalError( PRG_NAME, "no MAFFT executable found, use -\"" + PATH_TO_MAFFT_OPTION
-                        + "=<path to MAFFT>\" option" );
+                                         + "=<path to MAFFT>\" option" );
             }
             else {
                 ForesterUtil.fatalError( PRG_NAME, "no MAFFT executable at \"" + path_to_mafft + "\"" );
@@ -448,30 +467,32 @@ public class msa_compactor {
         }
         System.out.println( "Usage:" );
         System.out.println();
-        System.out.println( PRG_NAME + " <options> <msa input file> <output file base>" );
+        System.out.println( PRG_NAME + " [options] <msa input file> [output file base]" );
         System.out.println();
         System.out.println( " options: " );
         System.out.println();
+        System.out.println( "   -" + INFO_ONLY_OPTION
+                            + "             to only display same basic information about the MSA" );
         System.out.println( "   -" + REMOVE_WORST_OFFENDERS_OPTION
-                + "=<integer>   number of worst offender sequences to remove" );
+                            + "=<integer>   number of worst offender sequences to remove" );
         System.out.println( "   -" + LENGTH_OPTION + "=<integer>   target MSA length" );
         System.out.println( "   -" + AV_GAPINESS_OPTION + "=<decimal>   target gap-ratio (0.0-1.0)" );
         System.out.println( "   -" + REALIGN_OPTION + "             to realign using MAFFT" + mafft_comment );
         System.out.println( "   -" + MAFFT_OPTIONS + "=<string>   options for MAFFT (default: --auto)" );
         System.out.println( "   -" + STEP_OPTION + "=<integer>   step for output and re-aligning (default: 1)" );
         System.out.println( "   -" + STEP_FOR_DIAGNOSTICS_OPTION
-                + "=<integer>  step for diagnostics reports (default: 1)" );
+                            + "=<integer>  step for diagnostics reports (default: 1)" );
         System.out.println( "   -" + REPORT_ENTROPY
-                + "             to calculate normalized Shannon Entropy (not recommended for very large alignments)" );
+                            + "             to calculate normalized Shannon Entropy (not recommended for very large alignments)" );
         System.out.println( "   -" + OUTPUT_FORMAT_OPTION
-                + "=<f|p|n>     format for output alignments: f for fasta (default), p for phylip, or n for nexus" );
+                            + "=<f|p|n>     format for output alignments: f for fasta (default), p for phylip, or n for nexus" );
         System.out.println( "   -" + OUTPUT_REMOVED_SEQS_OPTION + "=<file>     to output the removed sequences" );
         System.out.println( "   -" + MIN_LENGTH_OPTION
-                + "=<integer>  minimal effecive sequence length (for deleting of shorter sequences)" );
+                            + "=<integer>  minimal effecive sequence length (for deleting of shorter sequences)" );
         System.out.println( "   -" + GAP_RATIO_LENGTH_OPTION
-                + "=<decimal>  maximal allowed gap ratio per column (for deleting of columms) (0.0-1.0)" );
+                            + "=<decimal>  maximal allowed gap ratio per column (for deleting of columms) (0.0-1.0)" );
         System.out.println( "   -" + PERFORM_PHYLOGENETIC_INFERENCE
-                + "             to calculate a simple phylogenetic tree (Kimura distances, NJ)" );
+                            + "             to calculate a simple phylogenetic tree (Kimura distances, NJ)" );
         System.out.println();
         System.out.println();
         System.out.println();