From d0bb37d418d945966304afe70431185c3873635a Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Sat, 19 Apr 2014 02:19:02 +0000 Subject: [PATCH] inprogress --- forester/java/src/org/forester/msa/BasicMsa.java | 6 ++-- .../java/src/org/forester/msa_compactor/Chart.java | 16 +++++---- .../org/forester/msa_compactor/MsaCompactor.java | 37 +++++++++++++------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/forester/java/src/org/forester/msa/BasicMsa.java b/forester/java/src/org/forester/msa/BasicMsa.java index daeef6b..bda6424 100644 --- a/forester/java/src/org/forester/msa/BasicMsa.java +++ b/forester/java/src/org/forester/msa/BasicMsa.java @@ -192,10 +192,12 @@ public class BasicMsa implements Msa { for( int row = 0; row < seqs.size(); ++row ) { final Sequence seq = seqs.get( row ); if ( seq.getLength() != length ) { - throw new IllegalArgumentException( "illegal attempt to build msa from sequences of unequal length" ); + throw new IllegalArgumentException( "illegal attempt to build msa from sequences of unequal length [" + + seq.getIdentifier() + "]" ); } if ( seq.getType() != msa.getType() ) { - throw new IllegalArgumentException( "illegal attempt to build msa from sequences of different type" ); + throw new IllegalArgumentException( "illegal attempt to build msa from sequences of different type [" + + seq.getIdentifier() + "]" ); } if ( ids.contains( seq.getIdentifier() ) ) { throw new IllegalArgumentException( "illegal attempt to create msa with non-unique identifiers [" diff --git a/forester/java/src/org/forester/msa_compactor/Chart.java b/forester/java/src/org/forester/msa_compactor/Chart.java index 73f569c..48e959d 100644 --- a/forester/java/src/org/forester/msa_compactor/Chart.java +++ b/forester/java/src/org/forester/msa_compactor/Chart.java @@ -50,10 +50,12 @@ public final class Chart extends JDialog implements ActionListener { private ChartPanel _chart_panel = null; private final JMenuItem _m_exit = new JMenuItem(); private List _msa_props; + private final int _initial_number_of_seqs; - private Chart( final List msa_props ) { + private Chart( final List msa_props, final int initial_number_of_seqs ) { super(); _msa_props = msa_props; + _initial_number_of_seqs = initial_number_of_seqs; setTitle( "msa compactor" ); setSize( 500, 400 ); setResizable( true ); @@ -95,7 +97,7 @@ public final class Chart extends JDialog implements ActionListener { } final double[][] seqs_length = new double[ _msa_props.size() ][ 2 ]; for( int i = 0; i < _msa_props.size(); ++i ) { - seqs_length[ i ][ 0 ] = _msa_props.get( i ).getNumberOfSequences(); + seqs_length[ i ][ 0 ] = _initial_number_of_seqs - _msa_props.get( i ).getNumberOfSequences(); seqs_length[ i ][ 1 ] = _msa_props.get( i ).getLength(); } model.addData( seqs_length, "Length" ); @@ -103,7 +105,7 @@ public final class Chart extends JDialog implements ActionListener { model.setSeriesMarker( "Series " + "Length", false ); final double[][] seqs_gaps = new double[ _msa_props.size() ][ 2 ]; for( int i = 0; i < _msa_props.size(); ++i ) { - seqs_gaps[ i ][ 0 ] = _msa_props.get( i ).getNumberOfSequences(); + seqs_gaps[ i ][ 0 ] = _initial_number_of_seqs - _msa_props.get( i ).getNumberOfSequences(); seqs_gaps[ i ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getGapRatio() * 100 ); } model.addData( seqs_gaps, "Gaps" ); @@ -111,7 +113,7 @@ public final class Chart extends JDialog implements ActionListener { model.setSeriesMarker( "Series " + "Gaps", false ); final double[][] seqs_identity = new double[ _msa_props.size() ][ 2 ]; for( int i = 0; i < _msa_props.size(); ++i ) { - seqs_identity[ i ][ 0 ] = _msa_props.get( i ).getNumberOfSequences(); + seqs_identity[ i ][ 0 ] = _initial_number_of_seqs - _msa_props.get( i ).getNumberOfSequences(); seqs_identity[ i ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getAverageIdentityRatio() * 100 ); } model.addData( seqs_identity, "Id" ); @@ -131,14 +133,14 @@ public final class Chart extends JDialog implements ActionListener { return _chart_panel; } - public static void display( final List msa_props ) { + public static void display( final List msa_props, final int initial_number_of_seqs ) { try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ); } catch ( final Exception e ) { e.printStackTrace(); } - final Chart chart = new Chart( msa_props ); + final Chart chart = new Chart( msa_props, initial_number_of_seqs ); chart.setVisible( true ); } @@ -149,7 +151,7 @@ public final class Chart extends JDialog implements ActionListener { catch ( final Exception e ) { e.printStackTrace(); } - final Chart temp = new Chart( null ); + final Chart temp = new Chart( null, 0 ); temp.setVisible( true ); } } diff --git a/forester/java/src/org/forester/msa_compactor/MsaCompactor.java b/forester/java/src/org/forester/msa_compactor/MsaCompactor.java index 210e9e9..0ba6b88 100644 --- a/forester/java/src/org/forester/msa_compactor/MsaCompactor.java +++ b/forester/java/src/org/forester/msa_compactor/MsaCompactor.java @@ -172,22 +172,32 @@ public class MsaCompactor { printTableHeader(); } int i = 0; - final int x = ForesterUtil.roundToInt( _msa.getNumberOfSequences() / 20.0 ); + final int s = _msa.getNumberOfSequences(); + final int x = ForesterUtil.roundToInt( s / 20.0 ); while ( _msa.getNumberOfSequences() > x ) { final String id = to_remove_ids.get( i ); _msa = MsaMethods.removeSequence( _msa, id ); - removeGapColumns(); - msa_props.add( new MsaProperties( _msa ) ); - if ( verbose ) { - printMsaStats( id ); - } - if ( ( step > 0 ) && ( ( ( i + 1 ) % step ) == 0 ) ) { - if ( realign ) { + if ( ( s < 500 ) || ( ( step > 0 ) && ( ( ( i + 1 ) % step ) == 0 ) ) ) { + removeGapColumns(); + if ( realign && ( ( step > 0 ) && ( ( ( i + 1 ) % step ) == 0 ) ) ) { realignWithMafft(); + msa_props.add( new MsaProperties( _msa ) ); + if ( verbose ) { + printMsaStats( id ); + } + if ( verbose ) { + System.out.print( "(realigned)" ); + } + } + else { + msa_props.add( new MsaProperties( _msa ) ); + if ( verbose ) { + printMsaStats( id ); + } + } + if ( verbose ) { + System.out.println(); } - } - if ( verbose ) { - System.out.println(); } ++i; } @@ -256,7 +266,7 @@ public class MsaCompactor { } final String s = writeOutfile(); if ( verbose ) { - System.out.print( "-> " + s + ( realign ? " (realigned)" : "" ) ); + System.out.print( "-> " + s + ( realign ? "\t(realigned)" : "" ) ); } } @@ -393,12 +403,13 @@ public class MsaCompactor { final boolean realign, final boolean norm, final String path_to_mafft ) throws IOException, InterruptedException { + final int initial_number_of_seqs = msa.getNumberOfSequences(); final MsaCompactor mc = new MsaCompactor( msa ); if ( realign ) { mc.setPathToMafft( path_to_mafft ); } final List msa_props = mc.chart( step, realign, norm, true ); - Chart.display( msa_props ); + Chart.display( msa_props, initial_number_of_seqs ); return mc; } -- 1.7.10.2