Reduced jar size by 20%
[jalview.git] / src / jalview / appletgui / PairwiseAlignPanel.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 \r
20 package jalview.appletgui;\r
21 \r
22 import java.util.*;\r
23 \r
24 import java.awt.event.*;\r
25 \r
26 import jalview.analysis.*;\r
27 import jalview.datamodel.*;\r
28 import java.awt.*;\r
29 \r
30 public class PairwiseAlignPanel\r
31     extends Panel implements ActionListener\r
32 {\r
33   Vector sequences = new Vector();\r
34   AlignmentPanel ap;\r
35 \r
36   public PairwiseAlignPanel(AlignmentPanel ap)\r
37   {\r
38     try\r
39     {\r
40       jbInit();\r
41     }\r
42     catch (Exception e)\r
43     {\r
44       e.printStackTrace();\r
45   }\r
46     this.ap = ap;\r
47     float scores[][] = new float[ap.av.alignment.getHeight()][ap.av.alignment.\r
48         getHeight()];\r
49     double totscore = 0;\r
50     int count = ap.av.getSelectionGroup().getSize();\r
51 \r
52     int acount = 0;\r
53     for (int i = 1; i < count; i++)\r
54     {\r
55       for (int j = 0; j < i; j++)\r
56       {\r
57         acount++;\r
58         AlignSeq as = new AlignSeq(ap.av.getSelectionGroup().getSequenceAt(i),\r
59                                    ap.av.getSelectionGroup().getSequenceAt(j),\r
60                                    "pep");\r
61 \r
62         as.calcScoreMatrix();\r
63         as.traceAlignment();\r
64         as.printAlignment(System.out);\r
65         scores[i][j] = (float) as.getMaxScore() / (float) as.getASeq1().length;\r
66         totscore = totscore + scores[i][j];\r
67 \r
68         textarea.append(as.getOutput());\r
69         sequences.addElement(new Sequence(as.getS1().getName(), as.getAStr1()));\r
70         sequences.addElement(new Sequence(as.getS2().getName(), as.getAStr2()));\r
71 \r
72       }\r
73     }\r
74 \r
75     if (count > 2)\r
76     {\r
77       for (int i = 0; i < count; i++)\r
78       {\r
79         for (int j = 0; j < i; j++)\r
80         {\r
81           jalview.util.Format.print(System.out, "%7.3f",\r
82                                     scores[i][j] / totscore);\r
83         }\r
84       }\r
85     }\r
86   }\r
87 \r
88   public void actionPerformed(ActionEvent evt)\r
89   {\r
90     if(evt.getSource()==viewInEditorButton)\r
91       viewInEditorButton_actionPerformed();\r
92   }\r
93 \r
94   protected void viewInEditorButton_actionPerformed()\r
95   {\r
96 \r
97     Sequence[] seq = new Sequence[sequences.size()];\r
98 \r
99     for (int i = 0; i < sequences.size(); i++)\r
100     {\r
101       seq[i] = (Sequence) sequences.elementAt(i);\r
102     }\r
103 \r
104     new AlignFrame(new Alignment(seq),\r
105                                    ap.alignFrame.applet,\r
106                                    "Pairwise Aligned Sequences");\r
107 \r
108   }\r
109   protected ScrollPane scrollPane = new ScrollPane();\r
110   protected TextArea textarea = new TextArea();\r
111   protected Button viewInEditorButton = new Button();\r
112   Panel jPanel1 = new Panel();\r
113   BorderLayout borderLayout1 = new BorderLayout();\r
114 \r
115   private void jbInit() throws Exception {\r
116       this.setLayout(borderLayout1);\r
117       textarea.setFont(new java.awt.Font("Monospaced", 0, 12));\r
118       textarea.setText("");\r
119       viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));\r
120       viewInEditorButton.setLabel("View in alignment editor");\r
121       viewInEditorButton.addActionListener(this);\r
122       this.add(scrollPane, BorderLayout.CENTER);\r
123       scrollPane.add(textarea);\r
124       this.add(jPanel1, BorderLayout.SOUTH);\r
125       jPanel1.add(viewInEditorButton, null);\r
126   }\r
127 \r
128 }\r