inprogress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 18 Apr 2014 23:51:33 +0000 (23:51 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 18 Apr 2014 23:51:33 +0000 (23:51 +0000)
forester/java/src/org/forester/application/msa_compactor.java
forester/java/src/org/forester/msa_compactor/Chart.java
forester/java/src/org/forester/msa_compactor/MsaCompactor.java

index 45f66c1..f9c86a3 100644 (file)
@@ -158,7 +158,7 @@ public class msa_compactor {
                 MsaCompactor.reduceLength( msa, length, step, realign, norm, path_to_mafft, out );
             }
             else {
-                MsaCompactor.chart( msa, realign, norm, path_to_mafft );
+                MsaCompactor.chart( msa, step, realign, norm, path_to_mafft );
             }
         }
         catch ( final Exception e ) {
index 75f3a04..73f569c 100644 (file)
@@ -37,6 +37,8 @@ import javax.swing.JPanel;
 import javax.swing.UIManager;
 import javax.swing.WindowConstants;
 
+import org.forester.util.ForesterUtil;
+
 import com.approximatrix.charting.coordsystem.BoxCoordSystem;
 import com.approximatrix.charting.model.MultiScatterDataModel;
 import com.approximatrix.charting.render.MultiScatterChartRenderer;
@@ -44,12 +46,12 @@ import com.approximatrix.charting.swing.ChartPanel;
 
 public final class Chart extends JDialog implements ActionListener {
 
-    private static final long serialVersionUID = -5292420246132943515L;
-    ChartPanel                _chart_panel     = null;
-    final JMenuItem           _m_exit          = new JMenuItem();
-    List<MsaProperties>       _msa_props;
+    private static final long   serialVersionUID = -5292420246132943515L;
+    private ChartPanel          _chart_panel     = null;
+    private final JMenuItem     _m_exit          = new JMenuItem();
+    private List<MsaProperties> _msa_props;
 
-    Chart( final List<MsaProperties> msa_props ) {
+    private Chart( final List<MsaProperties> msa_props ) {
         super();
         _msa_props = msa_props;
         setTitle( "msa compactor" );
@@ -98,23 +100,23 @@ public final class Chart extends JDialog implements ActionListener {
             }
             model.addData( seqs_length, "Length" );
             model.setSeriesLine( "Series " + "Length", true );
-            model.setSeriesMarker( "Series " + "Length", true );
-            //            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 ][ 1 ] = _msa_props.get( i ).getGapRatio();
-            //            }
-            //            model.addData( seqs_gaps, "Gaps" );
-            //            model.setSeriesLine( "Series " + "Gaps", true );
-            //            model.setSeriesMarker( "Series " + "Gaps", true );
-            //            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 ][ 1 ] = _msa_props.get( i ).getAverageIdentityRatio();
-            //            }
-            //            model.addData( seqs_identity, "Id" );
-            //            model.setSeriesLine( "Series " + "Id", false );
-            //            model.setSeriesMarker( "Series " + "Id", true );
+            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 ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getGapRatio() * 100 );
+            }
+            model.addData( seqs_gaps, "Gaps" );
+            model.setSeriesLine( "Series " + "Gaps", true );
+            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 ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getAverageIdentityRatio() * 100 );
+            }
+            model.addData( seqs_identity, "Id" );
+            model.setSeriesLine( "Series " + "Id", true );
+            model.setSeriesMarker( "Series " + "Id", false );
             final BoxCoordSystem coord = new BoxCoordSystem( model );
             coord.setUnitFont( coord.getUnitFont().deriveFont( 20.0f ) );
             coord.setXAxisUnit( "Number of Sequences" );
index 4eff35e..210e9e9 100644 (file)
@@ -58,7 +58,8 @@ public class MsaCompactor {
 
     final private static NumberFormat NF_3         = new DecimalFormat( "#.###" );
     final private static NumberFormat NF_4         = new DecimalFormat( "#.####" );
-    private final String              _maffts_opts = "--retree 1";
+    //   private final String              _maffts_opts = "--retree 1";
+    private final String              _maffts_opts = "--auto";
     private Msa                       _msa;
     private File                      _out_file_base;
     private String                    _path_to_mafft;
@@ -157,6 +158,42 @@ public class MsaCompactor {
         return gappiness;
     }
 
+    final private List<MsaProperties> chart( final int step,
+                                             final boolean realign,
+                                             final boolean norm,
+                                             final boolean verbose ) throws IOException, InterruptedException {
+        final GapContribution stats[] = calcGapContribtionsStats( norm );
+        final List<String> to_remove_ids = new ArrayList<String>();
+        final List<MsaProperties> msa_props = new ArrayList<MsaProperties>();
+        for( final GapContribution gap_gontribution : stats ) {
+            to_remove_ids.add( gap_gontribution.getId() );
+        }
+        if ( verbose ) {
+            printTableHeader();
+        }
+        int i = 0;
+        final int x = ForesterUtil.roundToInt( _msa.getNumberOfSequences() / 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 ) {
+                    realignWithMafft();
+                }
+            }
+            if ( verbose ) {
+                System.out.println();
+            }
+            ++i;
+        }
+        return msa_props;
+    }
+
     private Phylogeny inferNJphylogeny( final PWD_DISTANCE_METHOD pwd_distance_method,
                                         final Msa msa,
                                         final boolean write_matrix,
@@ -208,6 +245,21 @@ public class MsaCompactor {
         System.out.print( "\t" );
     }
 
+    final private void printMsaStatsWriteOutfileAndRealign( final boolean realign,
+                                                            final boolean verbose,
+                                                            final String id ) throws IOException, InterruptedException {
+        if ( realign ) {
+            realignWithMafft();
+        }
+        if ( verbose ) {
+            printMsaStats( id );
+        }
+        final String s = writeOutfile();
+        if ( verbose ) {
+            System.out.print( "-> " + s + ( realign ? " (realigned)" : "" ) );
+        }
+    }
+
     final private void realignWithMafft() throws IOException, InterruptedException {
         //  final MsaInferrer mafft = Mafft
         //       .createInstance( "/home/czmasek/SOFTWARE/MSA/MAFFT/mafft-7.130-without-extensions/scripts/mafft" );
@@ -245,56 +297,18 @@ public class MsaCompactor {
             final String id = to_remove_ids.get( i );
             _msa = MsaMethods.removeSequence( _msa, id );
             removeGapColumns();
-            if ( verbose ) {
-                printMsaStats( id );
-            }
             if ( ( ( step > 0 ) && ( ( ( i + 1 ) % step ) == 0 ) )
                     || ( MsaMethods.calcGapRatio( _msa ) <= mean_gapiness ) ) {
-                if ( realign ) {
-                    realignWithMafft();
-                }
-                final String s = writeOutfile();
-                if ( verbose ) {
-                    System.out.print( "-> " + s );
-                }
-            }
-            if ( verbose ) {
-                System.out.println();
+                printMsaStatsWriteOutfileAndRealign( realign, verbose, id );
             }
-            ++i;
-        }
-    }
-
-    final private List<MsaProperties> chart( final boolean realign, final boolean norm, final boolean verbose )
-            throws IOException, InterruptedException {
-        final GapContribution stats[] = calcGapContribtionsStats( norm );
-        final List<String> to_remove_ids = new ArrayList<String>();
-        final List<MsaProperties> msa_props = new ArrayList<MsaProperties>();
-        for( final GapContribution gap_gontribution : stats ) {
-            to_remove_ids.add( gap_gontribution.getId() );
-        }
-        if ( verbose ) {
-            printTableHeader();
-        }
-        int i = 0;
-        final int x = ForesterUtil.roundToInt( _msa.getNumberOfSequences() / 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 ) {
+            else if ( verbose ) {
                 printMsaStats( id );
             }
-            if ( realign ) {
-                realignWithMafft();
-            }
             if ( verbose ) {
                 System.out.println();
             }
             ++i;
         }
-        return msa_props;
     }
 
     final private void removeViaLength( final int length,
@@ -315,17 +329,11 @@ public class MsaCompactor {
             final String id = to_remove_ids.get( i );
             _msa = MsaMethods.removeSequence( _msa, id );
             removeGapColumns();
-            if ( verbose ) {
-                printMsaStats( id );
-            }
             if ( ( ( step > 0 ) && ( ( ( i + 1 ) % step ) == 0 ) ) || ( _msa.getLength() <= length ) ) {
-                if ( realign ) {
-                    realignWithMafft();
-                }
-                final String s = writeOutfile();
-                if ( verbose ) {
-                    System.out.print( "-> " + s );
-                }
+                printMsaStatsWriteOutfileAndRealign( realign, verbose, id );
+            }
+            else if ( verbose ) {
+                printMsaStats( id );
             }
             if ( verbose ) {
                 System.out.println();
@@ -352,17 +360,11 @@ public class MsaCompactor {
             final String id = to_remove_ids.get( i );
             _msa = MsaMethods.removeSequence( _msa, id );
             removeGapColumns();
-            if ( verbose ) {
-                printMsaStats( id );
-            }
             if ( ( ( step > 0 ) && ( ( ( i + 1 ) % step ) == 0 ) ) || ( i == ( to_remove_ids.size() - 1 ) ) ) {
-                if ( realign ) {
-                    realignWithMafft();
-                }
-                final String s = writeOutfile();
-                if ( verbose ) {
-                    System.out.print( "-> " + s );
-                }
+                printMsaStatsWriteOutfileAndRealign( realign, verbose, id );
+            }
+            else if ( verbose ) {
+                printMsaStats( id );
             }
             if ( verbose ) {
                 System.out.println();
@@ -386,6 +388,20 @@ public class MsaCompactor {
         return s;
     }
 
+    public final static MsaCompactor chart( final Msa msa,
+                                            final int step,
+                                            final boolean realign,
+                                            final boolean norm,
+                                            final String path_to_mafft ) throws IOException, InterruptedException {
+        final MsaCompactor mc = new MsaCompactor( msa );
+        if ( realign ) {
+            mc.setPathToMafft( path_to_mafft );
+        }
+        final List<MsaProperties> msa_props = mc.chart( step, realign, norm, true );
+        Chart.display( msa_props );
+        return mc;
+    }
+
     // Returns null if not path found.
     final public static String guessPathToMafft() {
         String path;
@@ -450,19 +466,6 @@ public class MsaCompactor {
         return mc;
     }
 
-    public final static MsaCompactor chart( final Msa msa,
-                                            final boolean realign,
-                                            final boolean norm,
-                                            final String path_to_mafft ) throws IOException, InterruptedException {
-        final MsaCompactor mc = new MsaCompactor( msa );
-        if ( realign ) {
-            mc.setPathToMafft( path_to_mafft );
-        }
-        final List<MsaProperties> msa_props = mc.chart( realign, norm, true );
-        Chart.display( msa_props );
-        return mc;
-    }
-
     public final static MsaCompactor removeWorstOffenders( final Msa msa,
                                                            final int worst_offenders_to_remove,
                                                            final int step,