Sequence numbering maintained
[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     Sequence seq;\r
54     for (int i = 1; i < count; i++)\r
55     {\r
56       for (int j = 0; j < i; j++)\r
57       {\r
58         acount++;\r
59         AlignSeq as = new AlignSeq(ap.av.getSelectionGroup().getSequenceAt(i),\r
60                                    ap.av.getSelectionGroup().getSequenceAt(j),\r
61                                    "pep");\r
62 \r
63         as.calcScoreMatrix();\r
64         as.traceAlignment();\r
65         as.printAlignment(System.out);\r
66         scores[i][j] = (float) as.getMaxScore() / (float) as.getASeq1().length;\r
67         totscore = totscore + scores[i][j];\r
68 \r
69         textarea.append(as.getOutput());\r
70 \r
71         seq = new Sequence(as.getS1().getName(),\r
72                            as.getAStr1(),\r
73                            as.getS1().getStart(), as.getS1().getEnd()\r
74             );\r
75         sequences.addElement(seq);\r
76 \r
77         seq = new Sequence(as.getS2().getName(),\r
78                            as.getAStr2(),\r
79                            as.getS2().getStart(), as.getS2().getEnd()\r
80             );\r
81 \r
82         sequences.addElement(seq);\r
83       }\r
84     }\r
85 \r
86     if (count > 2)\r
87     {\r
88       for (int i = 0; i < count; i++)\r
89       {\r
90         for (int j = 0; j < i; j++)\r
91         {\r
92           jalview.util.Format.print(System.out, "%7.3f",\r
93                                     scores[i][j] / totscore);\r
94         }\r
95       }\r
96     }\r
97   }\r
98 \r
99   public void actionPerformed(ActionEvent evt)\r
100   {\r
101     if(evt.getSource()==viewInEditorButton)\r
102       viewInEditorButton_actionPerformed();\r
103   }\r
104 \r
105   protected void viewInEditorButton_actionPerformed()\r
106   {\r
107 \r
108     Sequence[] seq = new Sequence[sequences.size()];\r
109 \r
110     for (int i = 0; i < sequences.size(); i++)\r
111     {\r
112       seq[i] = (Sequence) sequences.elementAt(i);\r
113     }\r
114 \r
115     new AlignFrame(new Alignment(seq),\r
116                                    ap.alignFrame.applet,\r
117                                    "Pairwise Aligned Sequences",\r
118                                    false);\r
119 \r
120   }\r
121   protected ScrollPane scrollPane = new ScrollPane();\r
122   protected TextArea textarea = new TextArea();\r
123   protected Button viewInEditorButton = new Button();\r
124   Panel jPanel1 = new Panel();\r
125   BorderLayout borderLayout1 = new BorderLayout();\r
126 \r
127   private void jbInit() throws Exception {\r
128       this.setLayout(borderLayout1);\r
129       textarea.setFont(new java.awt.Font("Monospaced", 0, 12));\r
130       textarea.setText("");\r
131       viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));\r
132       viewInEditorButton.setLabel("View in alignment editor");\r
133       viewInEditorButton.addActionListener(this);\r
134       this.add(scrollPane, BorderLayout.CENTER);\r
135       scrollPane.add(textarea);\r
136       this.add(jPanel1, BorderLayout.SOUTH);\r
137       jPanel1.add(viewInEditorButton, null);\r
138   }\r
139 \r
140 }\r