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 ["
private ChartPanel _chart_panel = null;
private final JMenuItem _m_exit = new JMenuItem();
private List<MsaProperties> _msa_props;
+ private final int _initial_number_of_seqs;
- private Chart( final List<MsaProperties> msa_props ) {
+ private Chart( final List<MsaProperties> 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 );
}
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" );
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" );
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" );
return _chart_panel;
}
- public static void display( final List<MsaProperties> msa_props ) {
+ public static void display( final List<MsaProperties> 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 );
}
catch ( final Exception e ) {
e.printStackTrace();
}
- final Chart temp = new Chart( null );
+ final Chart temp = new Chart( null, 0 );
temp.setVisible( true );
}
}
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;
}
}
final String s = writeOutfile();
if ( verbose ) {
- System.out.print( "-> " + s + ( realign ? " (realigned)" : "" ) );
+ System.out.print( "-> " + s + ( realign ? "\t(realigned)" : "" ) );
}
}
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<MsaProperties> msa_props = mc.chart( step, realign, norm, true );
- Chart.display( msa_props );
+ Chart.display( msa_props, initial_number_of_seqs );
return mc;
}