X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fmsa_compactor%2FChart.java;h=3ea86f472b3d53d95857ee45cdc9499fb711986c;hb=b6366fd2ac865514d2ceacb63432dac532147a85;hp=ccb6a0bc281d1cf99b889a949f05f7b54335ee99;hpb=7c0f14dccfa95a3f709da6eff6ebe635390d1841;p=jalview.git diff --git a/forester/java/src/org/forester/msa_compactor/Chart.java b/forester/java/src/org/forester/msa_compactor/Chart.java index ccb6a0b..3ea86f4 100644 --- a/forester/java/src/org/forester/msa_compactor/Chart.java +++ b/forester/java/src/org/forester/msa_compactor/Chart.java @@ -26,7 +26,8 @@ package org.forester.msa_compactor; import java.awt.BorderLayout; import java.awt.event.ActionListener; -import java.util.ArrayList; +import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.List; import javax.swing.JDialog; @@ -46,13 +47,14 @@ import com.approximatrix.charting.swing.ChartPanel; public final class Chart extends JDialog implements ActionListener { - private static final long serialVersionUID = -5292420246132943515L; - private ChartPanel _chart_panel = null; - private final JMenuItem _m_exit = new JMenuItem(); - private List _msa_props; - private final boolean _show_msa_qual; - private final int _initial_number_of_seqs; - private final String _title; + final private static NumberFormat NF_1 = new DecimalFormat( "0.##" ); + private static final long serialVersionUID = -5292420246132943515L; + private ChartPanel _chart_panel = null; + private final int _initial_number_of_seqs; + private final JMenuItem _m_exit = new JMenuItem(); + private final List _msa_props; + private final boolean _show_msa_qual; + private final String _title; private Chart( final List msa_props, final int initial_number_of_seqs, @@ -91,43 +93,106 @@ public final class Chart extends JDialog implements ActionListener { private ChartPanel obtainChartPanel() { if ( _chart_panel == null ) { final MultiScatterDataModel model = new MultiScatterDataModel(); - if ( ( _msa_props == null ) || _msa_props.isEmpty() ) { - _msa_props = new ArrayList(); - final MsaProperties p0 = new MsaProperties( 10, 200, 0.5, 0.1 ); - final MsaProperties p1 = new MsaProperties( 9, 190, 0.49, 0.2 ); - final MsaProperties p2 = new MsaProperties( 8, 150, 0.2, 0.3 ); - final MsaProperties p3 = new MsaProperties( 7, 145, 0.2, 0.4 ); - _msa_props.add( p0 ); - _msa_props.add( p1 ); - _msa_props.add( p2 ); - _msa_props.add( p3 ); - } final double[][] seqs_length = new double[ _msa_props.size() ][ 2 ]; + int max_length = -1; + int min_length = Integer.MAX_VALUE; + double max_gap_ratio = -1; + double min_gap_ratio = Double.MAX_VALUE; + double max_avg_gap_count = -1; + double min_avg_gap_count = Double.MAX_VALUE; for( int i = 0; i < _msa_props.size(); ++i ) { seqs_length[ i ][ 0 ] = _initial_number_of_seqs - _msa_props.get( i ).getNumberOfSequences(); - seqs_length[ i ][ 1 ] = _msa_props.get( i ).getLength(); + // + final int length = _msa_props.get( i ).getLength(); + seqs_length[ i ][ 1 ] = length; + if ( length > max_length ) { + max_length = length; + } + if ( length < min_length ) { + min_length = length; + } + // + final double gap_ratio = _msa_props.get( i ).getGapRatio(); + if ( gap_ratio > max_gap_ratio ) { + max_gap_ratio = gap_ratio; + } + if ( gap_ratio < min_gap_ratio ) { + min_gap_ratio = gap_ratio; + } + // + final double avg_gap_count = _msa_props.get( i ).getAvgNumberOfGaps(); + if ( avg_gap_count > max_avg_gap_count ) { + max_avg_gap_count = avg_gap_count; + } + if ( avg_gap_count < min_avg_gap_count ) { + min_avg_gap_count = avg_gap_count; + } } - model.addData( seqs_length, "Length" ); + model.addData( seqs_length, "Length" + " (" + minMaxToString( min_length, max_length ) + ")" ); model.setSeriesLine( "Series " + "Length", true ); model.setSeriesMarker( "Series " + "Length", false ); final double[][] seqs_gaps = new double[ _msa_props.size() ][ 2 ]; + double max_ent7 = -1; + double max_ent21 = -1; + double min_ent7 = Double.MAX_VALUE; + double min_ent21 = Double.MAX_VALUE; + if ( _show_msa_qual ) { + for( int i = 0; i < _msa_props.size(); ++i ) { + final double ent7 = _msa_props.get( i ).getEntropy7(); + if ( ent7 > max_ent7 ) { + max_ent7 = ent7; + } + if ( ent7 < max_ent7 ) { + min_ent7 = ent7; + } + final double ent21 = _msa_props.get( i ).getEntropy21(); + if ( ent21 > min_ent21 ) { + max_ent21 = ent21; + } + if ( ent21 < min_ent21 ) { + min_ent21 = ent21; + } + } + } + final double gap_ratio_factor = ( max_length / 2.0 ) / max_gap_ratio; + final double avg_gaps_counts_factor = ( max_length / 2.0 ) / max_avg_gap_count; + final double ent7_factor = ( max_length / 2.0 ) / max_ent7; + final double ent21_factor = ( max_length / 2.0 ) / max_ent21; for( int i = 0; i < _msa_props.size(); ++i ) { seqs_gaps[ i ][ 0 ] = _initial_number_of_seqs - _msa_props.get( i ).getNumberOfSequences(); - seqs_gaps[ i ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getGapRatio() * 200 ); + seqs_gaps[ i ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getGapRatio() * gap_ratio_factor ); + } + model.addData( seqs_gaps, "Gap Ratio" + " (" + minMaxToString( min_gap_ratio, max_gap_ratio ) + ")" ); + model.setSeriesLine( "Series " + "Gap Ratio", true ); + model.setSeriesMarker( "Series " + "Gap Ratio", false ); + final double[][] gap_counts = new double[ _msa_props.size() ][ 2 ]; + for( int i = 0; i < _msa_props.size(); ++i ) { + gap_counts[ i ][ 0 ] = _initial_number_of_seqs - _msa_props.get( i ).getNumberOfSequences(); + gap_counts[ i ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getAvgNumberOfGaps() + * avg_gaps_counts_factor ); } - model.addData( seqs_gaps, "Gap ratio" ); - model.setSeriesLine( "Series " + "Gap ratio", true ); - model.setSeriesMarker( "Series " + "Gap ratio", false ); + model.addData( gap_counts, "Mean Gap Count" + " (" + minMaxToString( min_avg_gap_count, max_avg_gap_count ) + + ")" ); + model.setSeriesLine( "Series " + "Mean Gap Count", true ); + model.setSeriesMarker( "Series " + "Mean Gap Count", false ); if ( _show_msa_qual ) { - final double[][] seqs_identity = new double[ _msa_props.size() ][ 2 ]; + final double[][] entropy7 = new double[ _msa_props.size() ][ 2 ]; for( int i = 0; i < _msa_props.size(); ++i ) { - seqs_identity[ i ][ 0 ] = _initial_number_of_seqs - _msa_props.get( i ).getNumberOfSequences(); - seqs_identity[ i ][ 1 ] = ForesterUtil - .roundToInt( _msa_props.get( i ).getAverageIdentityRatio() * 200 ); + entropy7[ i ][ 0 ] = _initial_number_of_seqs - _msa_props.get( i ).getNumberOfSequences(); + entropy7[ i ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getEntropy7() * ent7_factor ); } - model.addData( seqs_identity, "mean MSA column identity" ); - model.setSeriesLine( "Series " + "mean MSA column identity", true ); - model.setSeriesMarker( "Series " + "mean MSA column identity", false ); + model.addData( entropy7, "Entropy norm 7" + " (" + minMaxToString( min_ent7, max_ent7 ) + ")" ); + model.setSeriesLine( "Series " + "Entropy norm 7", true ); + model.setSeriesMarker( "Series " + "Entropy norm 7", false ); + // + final double[][] entropy21 = new double[ _msa_props.size() ][ 2 ]; + for( int i = 0; i < _msa_props.size(); ++i ) { + entropy21[ i ][ 0 ] = _initial_number_of_seqs - _msa_props.get( i ).getNumberOfSequences(); + entropy21[ i ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getEntropy21() * ent21_factor ); + } + model.addData( entropy21, "Entropy norm 21" + " (" + minMaxToString( min_ent21, max_ent21 ) + ")" ); + model.setSeriesLine( "Series " + "Entropy norm 21", true ); + model.setSeriesMarker( "Series " + "Entropy norm 21", false ); } final BoxCoordSystem coord = new BoxCoordSystem( model ); coord.setUnitFont( coord.getUnitFont().deriveFont( 16.0f ) ); @@ -143,6 +208,10 @@ public final class Chart extends JDialog implements ActionListener { return _chart_panel; } + private final static String minMaxToString( final double min, final double max ) { + return NF_1.format( min ) + "-" + NF_1.format( max ); + } + public static void display( final List msa_props, final int initial_number_of_seqs, final boolean show_msa_qual,