X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fapplication%2Fmsa_compactor.java;h=e555593a94468ac63332e0a5b9b509d3142075d2;hb=876ced97014fafe54ff51dcc17da8bf25913fec7;hp=d48df0547d9ce0d29c32f393f9d3a0a0fe87acf5;hpb=10297bd8b8a4b4ab198a17a42fc6ff24ae2ed49b;p=jalview.git diff --git a/forester/java/src/org/forester/application/msa_compactor.java b/forester/java/src/org/forester/application/msa_compactor.java index d48df05..e555593 100644 --- a/forester/java/src/org/forester/application/msa_compactor.java +++ b/forester/java/src/org/forester/application/msa_compactor.java @@ -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"; @@ -98,7 +105,7 @@ public class msa_compactor { int length = -1; int step = 1; boolean realign = false; - boolean norm = true; + boolean normalize_for_effective_seq_length = true; String path_to_mafft = null; int step_for_diagnostics = 1; int min_length = -1; @@ -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 ) ) ); @@ -210,7 +223,7 @@ public class msa_compactor { path_to_mafft = cla.getOptionValueAsCleanString( PATH_TO_MAFFT_OPTION ); } if ( cla.isOptionSet( DO_NOT_NORMALIZE_FOR_EFF_LENGTH_OPTION ) ) { - norm = false; + normalize_for_effective_seq_length = false; } if ( cla.isOptionSet( STEP_FOR_DIAGNOSTICS_OPTION ) ) { step_for_diagnostics = cla.getOptionValueAsInt( STEP_FOR_DIAGNOSTICS_OPTION ); @@ -284,31 +297,11 @@ public class msa_compactor { "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 ) ) ); + 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 ); } @@ -353,8 +346,11 @@ public class msa_compactor { } System.out.println( "Step for diagnostics reports : " + step_for_diagnostics ); System.out.println( "Calculate normalized Shannon Entropy : " + report_entropy ); - if ( !norm ) { - System.out.println( "Normalize : " + norm ); + if ( normalize_for_effective_seq_length ) { + System.out.println( "Normalize : with individual, effective sequence lenghts" ); + } + else { + System.out.println( "Normalize : with MSA length" ); } System.out.println( "Realign with MAFFT : " + realign ); if ( realign ) { @@ -379,7 +375,7 @@ public class msa_compactor { if ( removed_seqs_out_base != null ) { mc.setRemovedSeqsOutBase( removed_seqs_out_base ); } - mc.setNorm( norm ); + mc.setNorm( normalize_for_effective_seq_length ); mc.setRealign( realign ); if ( realign ) { mc.setPathToMafft( path_to_mafft ); @@ -398,9 +394,12 @@ public class msa_compactor { msa_props = mc.removeViaLength( length ); } else { - msa_props = mc.chart( step, realign, norm ); + msa_props = mc.chart( step, realign, normalize_for_effective_seq_length ); } Chart.display( msa_props, initial_number_of_seqs, report_entropy, in.getName() ); + System.out.println(); + System.out.println( "Final MSA properties" ); + printMsaInfo( msa, MsaMethods.calculateEffectiveLengthStatistics( msa )); } } catch ( final IllegalArgumentException iae ) { @@ -416,6 +415,36 @@ 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 ); + printMsaInfo( msa, initial_msa_stats ); + } + + private static void printMsaInfo( DeleteableMsa msa, final DescriptiveStatistics msa_stats ) { + System.out.println( "MSA length : " + msa.getLength() ); + System.out.println( "Number of sequences : " + msa.getNumberOfSequences() ); + System.out.println( "Median sequence length : " + NF_1.format( msa_stats.median() ) ); + System.out.println( "Mean sequence length : " + + NF_1.format( msa_stats.arithmeticMean() ) ); + System.out.println( "Max sequence length : " + ( ( int ) msa_stats.getMax() ) ); + System.out.println( "Min sequence length : " + ( ( int ) msa_stats.getMin() ) ); + System.out.println( "Gap ratio : " + + NF_4.format( MsaMethods.calcGapRatio( msa ) ) ); + System.out.println( "Mean gap count per sequence : " + + NF_1.format( MsaMethods.calcNumberOfGapsStats( 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 ) ) { } @@ -448,10 +477,12 @@ public class msa_compactor { } System.out.println( "Usage:" ); System.out.println(); - System.out.println( PRG_NAME + " " ); + System.out.println( PRG_NAME + " [options] [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 + "= number of worst offender sequences to remove" ); System.out.println( " -" + LENGTH_OPTION + "= target MSA length" ); @@ -472,6 +503,9 @@ public class msa_compactor { + "= 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)" ); + System.out.println( " -" + DO_NOT_NORMALIZE_FOR_EFF_LENGTH_OPTION + + " to normalize gap-contributions with MSA length, instead of individual effective sequence lenghts" ); + System.out.println(); System.out.println(); System.out.println();