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