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;
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" );
}
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" );
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;
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,
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" );
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,
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();
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();
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;
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,