2 package org.forester.application;
5 import java.io.FileInputStream;
7 import org.forester.io.parsers.GeneralMsaParser;
8 import org.forester.msa.Msa;
9 import org.forester.msa.MsaMethods;
10 import org.forester.util.BasicDescriptiveStatistics;
11 import org.forester.util.CommandLineArguments;
12 import org.forester.util.DescriptiveStatistics;
14 public class msa_quality {
16 public static void main( final String args[] ) {
18 final CommandLineArguments cla = new CommandLineArguments( args );
19 // if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) || ( args.length == 0 ) ) {
23 final File in = cla.getFile( 0 );
28 if ( cla.isOptionSet( "f" ) && cla.isOptionSet( "t" ) ) {
29 from = cla.getOptionValueAsInt( "f" );
30 to = cla.getOptionValueAsInt( "t" );
32 else if ( cla.isOptionSet( "s" ) && cla.isOptionSet( "w" ) ) {
33 step = cla.getOptionValueAsInt( "s" );
34 window = cla.getOptionValueAsInt( "w" );
39 msa = GeneralMsaParser.parse( new FileInputStream( in ) );
40 if ( cla.isOptionSet( "f" ) && cla.isOptionSet( "t" ) ) {
41 singleCalc( in, from, to, msa );
44 windowedCalcs( window, step, msa );
47 catch ( final Exception e ) {
49 // ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
53 private static void windowedCalcs( int window, int step, final Msa msa ) {
64 for( int i = 0; i <= msa.getLength() - 1; i += step ) {
65 int to = i + window - 1;
66 if ( to > ( msa.getLength() - 1 ) ) {
67 to = msa.getLength() - 1;
69 final DescriptiveStatistics stats = calc( i, to, msa );
70 final double mean = stats.arithmeticMean();
71 final String pos = i + "-" + to;
72 System.out.print( pos );
73 System.out.print( ":\t" );
74 System.out.print( mean );
75 if ( stats.getN() > 2 ) {
76 System.out.print( "\t" );
77 System.out.print( stats.median() );
78 System.out.print( "\t" );
79 System.out.print( stats.sampleStandardDeviation() );
91 System.out.println( "Min: " + min_pos + ": " + min );
92 System.out.println( "Max: " + max_pos + ": " + max );
95 private static void singleCalc( final File in, int from, int to, final Msa msa ) {
99 if ( to > ( msa.getLength() - 1 ) ) {
100 to = msa.getLength() - 1;
102 final DescriptiveStatistics stats = calc( from, to, msa );
103 System.out.println( in.toString() + ": " + from + "-" + to + ":" );
104 System.out.println();
105 System.out.println( stats.toString() );
108 private static DescriptiveStatistics calc( final int from, final int to, final Msa msa ) {
109 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
110 for( int c = from; c <= to; ++c ) {
111 stats.addValue( MsaMethods.calculateIdentityRatio( msa, c ) );