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 com.approximatrix.charting.coordsystem.BoxCoordSystem;
41 import com.approximatrix.charting.model.MultiScatterDataModel;
42 import com.approximatrix.charting.render.MultiScatterChartRenderer;
43 import com.approximatrix.charting.swing.ChartPanel;
45 public final class Chart extends JDialog implements ActionListener {
47 private static final long serialVersionUID = -5292420246132943515L;
48 ChartPanel _chart_panel = null;
49 final JMenuItem _m_exit = new JMenuItem();
50 List<MsaProperties> _msa_props;
52 Chart( final List<MsaProperties> msa_props ) {
54 _msa_props = msa_props;
55 setTitle( "msa compactor" );
58 final JPanel content_pane = new JPanel();
59 content_pane.setLayout( new BorderLayout() );
60 setContentPane( content_pane );
61 final JMenuBar menu_bar = new JMenuBar();
62 final JMenu file_menu = new JMenu();
63 file_menu.setText( "File" );
64 _m_exit.setText( "Exit" );
65 file_menu.add( _m_exit );
66 menu_bar.add( file_menu );
67 setJMenuBar( menu_bar );
68 setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
69 _m_exit.addActionListener( this );
70 content_pane.add( obtainChartPanel(), BorderLayout.CENTER );
74 public void actionPerformed( final java.awt.event.ActionEvent e ) {
75 if ( e.getSource() == _m_exit ) {
80 private ChartPanel obtainChartPanel() {
81 if ( _chart_panel == null ) {
82 final MultiScatterDataModel model = new MultiScatterDataModel();
83 if ( ( _msa_props == null ) || _msa_props.isEmpty() ) {
84 _msa_props = new ArrayList<MsaProperties>();
85 final MsaProperties p0 = new MsaProperties( 10, 200, 0.5, 0.1 );
86 final MsaProperties p1 = new MsaProperties( 9, 190, 0.49, 0.2 );
87 final MsaProperties p2 = new MsaProperties( 8, 150, 0.2, 0.3 );
88 final MsaProperties p3 = new MsaProperties( 7, 145, 0.2, 0.4 );
94 final double[][] seqs_length = new double[ _msa_props.size() ][ 2 ];
95 for( int i = 0; i < _msa_props.size(); ++i ) {
96 seqs_length[ i ][ 0 ] = _msa_props.get( i ).getNumberOfSequences();
97 seqs_length[ i ][ 1 ] = _msa_props.get( i ).getLength();
99 model.addData( seqs_length, "Length" );
100 model.setSeriesLine( "Series " + "Length", true );
101 model.setSeriesMarker( "Series " + "Length", true );
102 // final double[][] seqs_gaps = new double[ _msa_props.size() ][ 2 ];
103 // for( int i = 0; i < _msa_props.size(); ++i ) {
104 // seqs_gaps[ i ][ 0 ] = _msa_props.get( i ).getNumberOfSequences();
105 // seqs_gaps[ i ][ 1 ] = _msa_props.get( i ).getGapRatio();
107 // model.addData( seqs_gaps, "Gaps" );
108 // model.setSeriesLine( "Series " + "Gaps", true );
109 // model.setSeriesMarker( "Series " + "Gaps", true );
110 // final double[][] seqs_identity = new double[ _msa_props.size() ][ 2 ];
111 // for( int i = 0; i < _msa_props.size(); ++i ) {
112 // seqs_identity[ i ][ 0 ] = _msa_props.get( i ).getNumberOfSequences();
113 // seqs_identity[ i ][ 1 ] = _msa_props.get( i ).getAverageIdentityRatio();
115 // model.addData( seqs_identity, "Id" );
116 // model.setSeriesLine( "Series " + "Id", false );
117 // model.setSeriesMarker( "Series " + "Id", true );
118 final BoxCoordSystem coord = new BoxCoordSystem( model );
119 coord.setUnitFont( coord.getUnitFont().deriveFont( 20.0f ) );
120 coord.setXAxisUnit( "Number of Sequences" );
121 coord.setPaintGrid( true );
122 coord.setYAxisUnit( "MSA Length" );
123 _chart_panel = new ChartPanel( model, "msa compactor" );
124 _chart_panel.setCoordSystem( coord );
125 final MultiScatterChartRenderer renderer = new MultiScatterChartRenderer( coord, model );
126 renderer.setAllowBuffer( false );
127 _chart_panel.addChartRenderer( renderer, 0 );
132 public static void display( final List<MsaProperties> msa_props ) {
134 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
136 catch ( final Exception e ) {
139 final Chart chart = new Chart( msa_props );
140 chart.setVisible( true );
143 public static void main( final String[] args ) {
145 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
147 catch ( final Exception e ) {
150 final Chart temp = new Chart( null );
151 temp.setVisible( true );