2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25 package org.forester.msa_compactor;
27 import java.awt.BorderLayout;
28 import java.awt.event.ActionListener;
29 import java.util.ArrayList;
30 import java.util.List;
32 import javax.swing.JDialog;
33 import javax.swing.JMenu;
34 import javax.swing.JMenuBar;
35 import javax.swing.JMenuItem;
36 import javax.swing.JPanel;
37 import javax.swing.UIManager;
38 import javax.swing.WindowConstants;
40 import org.forester.util.ForesterUtil;
42 import com.approximatrix.charting.coordsystem.BoxCoordSystem;
43 import com.approximatrix.charting.model.MultiScatterDataModel;
44 import com.approximatrix.charting.render.MultiScatterChartRenderer;
45 import com.approximatrix.charting.swing.ChartPanel;
47 public final class Chart extends JDialog implements ActionListener {
49 private static final long serialVersionUID = -5292420246132943515L;
50 private ChartPanel _chart_panel = null;
51 private final JMenuItem _m_exit = new JMenuItem();
52 private List<MsaProperties> _msa_props;
54 private Chart( final List<MsaProperties> msa_props ) {
56 _msa_props = msa_props;
57 setTitle( "msa compactor" );
60 final JPanel content_pane = new JPanel();
61 content_pane.setLayout( new BorderLayout() );
62 setContentPane( content_pane );
63 final JMenuBar menu_bar = new JMenuBar();
64 final JMenu file_menu = new JMenu();
65 file_menu.setText( "File" );
66 _m_exit.setText( "Exit" );
67 file_menu.add( _m_exit );
68 menu_bar.add( file_menu );
69 setJMenuBar( menu_bar );
70 setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
71 _m_exit.addActionListener( this );
72 content_pane.add( obtainChartPanel(), BorderLayout.CENTER );
76 public void actionPerformed( final java.awt.event.ActionEvent e ) {
77 if ( e.getSource() == _m_exit ) {
82 private ChartPanel obtainChartPanel() {
83 if ( _chart_panel == null ) {
84 final MultiScatterDataModel model = new MultiScatterDataModel();
85 if ( ( _msa_props == null ) || _msa_props.isEmpty() ) {
86 _msa_props = new ArrayList<MsaProperties>();
87 final MsaProperties p0 = new MsaProperties( 10, 200, 0.5, 0.1 );
88 final MsaProperties p1 = new MsaProperties( 9, 190, 0.49, 0.2 );
89 final MsaProperties p2 = new MsaProperties( 8, 150, 0.2, 0.3 );
90 final MsaProperties p3 = new MsaProperties( 7, 145, 0.2, 0.4 );
96 final double[][] seqs_length = new double[ _msa_props.size() ][ 2 ];
97 for( int i = 0; i < _msa_props.size(); ++i ) {
98 seqs_length[ i ][ 0 ] = _msa_props.get( i ).getNumberOfSequences();
99 seqs_length[ i ][ 1 ] = _msa_props.get( i ).getLength();
101 model.addData( seqs_length, "Length" );
102 model.setSeriesLine( "Series " + "Length", true );
103 model.setSeriesMarker( "Series " + "Length", false );
104 final double[][] seqs_gaps = new double[ _msa_props.size() ][ 2 ];
105 for( int i = 0; i < _msa_props.size(); ++i ) {
106 seqs_gaps[ i ][ 0 ] = _msa_props.get( i ).getNumberOfSequences();
107 seqs_gaps[ i ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getGapRatio() * 100 );
109 model.addData( seqs_gaps, "Gaps" );
110 model.setSeriesLine( "Series " + "Gaps", true );
111 model.setSeriesMarker( "Series " + "Gaps", false );
112 final double[][] seqs_identity = new double[ _msa_props.size() ][ 2 ];
113 for( int i = 0; i < _msa_props.size(); ++i ) {
114 seqs_identity[ i ][ 0 ] = _msa_props.get( i ).getNumberOfSequences();
115 seqs_identity[ i ][ 1 ] = ForesterUtil.roundToInt( _msa_props.get( i ).getAverageIdentityRatio() * 100 );
117 model.addData( seqs_identity, "Id" );
118 model.setSeriesLine( "Series " + "Id", true );
119 model.setSeriesMarker( "Series " + "Id", false );
120 final BoxCoordSystem coord = new BoxCoordSystem( model );
121 coord.setUnitFont( coord.getUnitFont().deriveFont( 20.0f ) );
122 coord.setXAxisUnit( "Number of Sequences" );
123 coord.setPaintGrid( true );
124 coord.setYAxisUnit( "MSA Length" );
125 _chart_panel = new ChartPanel( model, "msa compactor" );
126 _chart_panel.setCoordSystem( coord );
127 final MultiScatterChartRenderer renderer = new MultiScatterChartRenderer( coord, model );
128 renderer.setAllowBuffer( false );
129 _chart_panel.addChartRenderer( renderer, 0 );
134 public static void display( final List<MsaProperties> msa_props ) {
136 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
138 catch ( final Exception e ) {
141 final Chart chart = new Chart( msa_props );
142 chart.setVisible( true );
145 public static void main( final String[] args ) {
147 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
149 catch ( final Exception e ) {
152 final Chart temp = new Chart( null );
153 temp.setVisible( true );