d5243e314ec08646b5f560e984e6401bbfe05b1d
[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 jalview.jbappletgui.*;\r
29 \r
30 public class PairwiseAlignPanel\r
31     extends GPairwiseAlignPanel\r
32 {\r
33   Vector sequences = new Vector();\r
34   AlignmentPanel ap;\r
35 \r
36   public PairwiseAlignPanel(AlignmentPanel ap)\r
37   {\r
38     super();\r
39     this.ap = ap;\r
40     float scores[][] = new float[ap.av.alignment.getHeight()][ap.av.alignment.\r
41         getHeight()];\r
42     double totscore = 0;\r
43     int count = ap.av.getSelectionGroup().getSize();\r
44 \r
45     int acount = 0;\r
46     for (int i = 1; i < count; i++)\r
47     {\r
48       for (int j = 0; j < i; j++)\r
49       {\r
50         acount++;\r
51         AlignSeq as = new AlignSeq(ap.av.getSelectionGroup().getSequenceAt(i),\r
52                                    ap.av.getSelectionGroup().getSequenceAt(j),\r
53                                    "pep");\r
54 \r
55         as.calcScoreMatrix();\r
56         as.traceAlignment();\r
57         as.printAlignment();\r
58         scores[i][j] = (float) as.getMaxScore() / (float) as.getASeq1().length;\r
59         totscore = totscore + scores[i][j];\r
60 \r
61         textarea.append(as.getOutput());\r
62         sequences.addElement(new Sequence(as.getS1().getName(), as.getAStr1()));\r
63         sequences.addElement(new Sequence(as.getS2().getName(), as.getAStr2()));\r
64 \r
65       }\r
66     }\r
67 \r
68     if (count > 2)\r
69     {\r
70       for (int i = 0; i < count; i++)\r
71       {\r
72         for (int j = 0; j < i; j++)\r
73         {\r
74           jalview.util.Format.print(System.out, "%7.3f",\r
75                                     scores[i][j] / totscore);\r
76         }\r
77       }\r
78     }\r
79   }\r
80 \r
81   protected void viewInEditorButton_actionPerformed(ActionEvent e)\r
82   {\r
83 \r
84     Sequence[] seq = new Sequence[sequences.size()];\r
85 \r
86     for (int i = 0; i < sequences.size(); i++)\r
87     {\r
88       seq[i] = (Sequence) sequences.elementAt(i);\r
89     }\r
90 \r
91     new AlignFrame(new Alignment(seq),\r
92                                    ap.alignFrame.applet,\r
93                                    "Pairwise Aligned Sequences");\r
94 \r
95   }\r
96 \r
97 }\r