From: cmzmasek@gmail.com Date: Fri, 18 May 2012 00:07:40 +0000 (+0000) Subject: in progress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e0b6eebbd1187d9e0b985c9c0813b2ba62b5299b;p=jalview.git in progress --- diff --git a/forester/java/src/org/forester/application/msa_quality.java b/forester/java/src/org/forester/application/msa_quality.java index 3f3d745..821cdbc 100644 --- a/forester/java/src/org/forester/application/msa_quality.java +++ b/forester/java/src/org/forester/application/msa_quality.java @@ -3,8 +3,6 @@ package org.forester.application; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; import org.forester.io.parsers.GeneralMsaParser; import org.forester.msa.Msa; @@ -16,35 +14,102 @@ import org.forester.util.DescriptiveStatistics; public class msa_quality { public static void main( final String args[] ) { - CommandLineArguments cla = null; try { - cla = new CommandLineArguments( args ); + final CommandLineArguments cla = new CommandLineArguments( args ); + // if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) || ( args.length == 0 ) ) { + // printHelp(); + // System.exit( 0 ); + // } + final File in = cla.getFile( 0 ); + int from = 0; + int to = 0; + int window = 0; + int step = 0; + if ( cla.isOptionSet( "f" ) && cla.isOptionSet( "t" ) ) { + from = cla.getOptionValueAsInt( "f" ); + to = cla.getOptionValueAsInt( "t" ); + } + else if ( cla.isOptionSet( "s" ) && cla.isOptionSet( "w" ) ) { + step = cla.getOptionValueAsInt( "s" ); + window = cla.getOptionValueAsInt( "w" ); + } + else { + } + Msa msa = null; + msa = GeneralMsaParser.parse( new FileInputStream( in ) ); + if ( cla.isOptionSet( "f" ) && cla.isOptionSet( "t" ) ) { + singleCalc( in, from, to, msa ); + } + else { + windowedCalcs( window, step, msa ); + } } catch ( final Exception e ) { + e.printStackTrace(); // ForesterUtil.fatalError( PRG_NAME, e.getMessage() ); } - // if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) || ( args.length == 0 ) ) { - // printHelp(); - // System.exit( 0 ); - // } - final File in = cla.getFile( 0 ); - Msa msa = null; - try { - msa = GeneralMsaParser.parse( new FileInputStream( in ) ); + } + + private static void windowedCalcs( int window, int step, final Msa msa ) { + if ( window < 1 ) { + window = 1; } - catch ( final FileNotFoundException e ) { - // TODO Auto-generated catch block - e.printStackTrace(); + if ( step < 1 ) { + step = 1; } - catch ( final IOException e ) { - // TODO Auto-generated catch block - e.printStackTrace(); + String min_pos = ""; + String max_pos = ""; + double min = 1; + double max = 0; + for( int i = 0; i <= msa.getLength() - 1; i += step ) { + int to = i + window - 1; + if ( to > ( msa.getLength() - 1 ) ) { + to = msa.getLength() - 1; + } + final DescriptiveStatistics stats = calc( i, to, msa ); + final double mean = stats.arithmeticMean(); + final String pos = i + "-" + to; + System.out.print( pos ); + System.out.print( ":\t" ); + System.out.print( mean ); + if ( window > 2 ) { + System.out.print( "\t" ); + System.out.print( stats.median() ); + System.out.print( "\t" ); + System.out.print( stats.sampleStandardDeviation() ); + } + System.out.println(); + if ( mean > max ) { + max = mean; + max_pos = pos; + } + if ( mean < min ) { + min = mean; + min_pos = pos; + } + } + System.out.println( "Min: " + min_pos + ": " + min ); + System.out.println( "Max: " + max_pos + ": " + max ); + } + + private static void singleCalc( final File in, int from, int to, final Msa msa ) { + if ( from < 0 ) { + from = 0; } - final int end = 2; - final int start = 6; + if ( to > ( msa.getLength() - 1 ) ) { + to = msa.getLength() - 1; + } + final DescriptiveStatistics stats = calc( from, to, msa ); + System.out.println( in.toString() + ": " + from + "-" + to + ":" ); + System.out.println(); + System.out.println( stats.toString() ); + } + + private static DescriptiveStatistics calc( final int from, final int to, final Msa msa ) { final DescriptiveStatistics stats = new BasicDescriptiveStatistics(); - for( int c = start; c <= end; ++c ) { + for( int c = from; c <= to; ++c ) { stats.addValue( MsaMethods.calculateIdentityRatio( msa, c ) ); } + return stats; } }