After merge
[jalview.git] / src / jalview / gui / 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 package jalview.gui;\r
20 \r
21 import jalview.analysis.*;\r
22 \r
23 import jalview.datamodel.*;\r
24 \r
25 import jalview.jbgui.*;\r
26 \r
27 import java.awt.event.*;\r
28 \r
29 import java.util.*;\r
30 \r
31 \r
32 /**\r
33  * DOCUMENT ME!\r
34  *\r
35  * @author $author$\r
36  * @version $Revision$\r
37  */\r
38 public class PairwiseAlignPanel extends GPairwiseAlignPanel\r
39 {\r
40     Vector sequences = new Vector();\r
41     AlignViewport av;\r
42 \r
43     /**\r
44      * Creates a new PairwiseAlignPanel object.\r
45      *\r
46      * @param av DOCUMENT ME!\r
47      */\r
48     public PairwiseAlignPanel(AlignViewport av)\r
49     {\r
50         super();\r
51         this.av = av;\r
52 \r
53         Vector selsubset = new Vector();\r
54 \r
55         for (int i = 0, j = av.getSelectionGroup().getSize(); i < j; i++)\r
56         {\r
57             if (av.getAlignment().getSequences().contains(av.getSelectionGroup()\r
58                                                                 .getSequenceAt(i)))\r
59             {\r
60                 selsubset.add(av.getSelectionGroup().getSequenceAt(i));\r
61             }\r
62         }\r
63 \r
64         float[][] scores = new float[selsubset.size()][selsubset.size()];\r
65         double totscore = 0;\r
66         int count = selsubset.size();\r
67 \r
68         int acount = 0;\r
69 \r
70         for (int i = 1; i < count; i++)\r
71         {\r
72             for (int j = 0; j < i; j++)\r
73             {\r
74                 acount++;\r
75 \r
76                 AlignSeq as = new AlignSeq((SequenceI) selsubset.elementAt(i),\r
77                         (SequenceI) selsubset.elementAt(j), "pep");\r
78                 as.calcScoreMatrix();\r
79                 as.traceAlignment();\r
80                 as.printAlignment(System.out);\r
81                 scores[i][j] = (float) as.getMaxScore() / (float) as.getASeq1().length;\r
82                 totscore = totscore + scores[i][j];\r
83 \r
84                 textarea.append(as.getOutput());\r
85                 sequences.add(new Sequence(as.getS1().getName(), as.getAStr1()));\r
86                 sequences.add(new Sequence(as.getS2().getName(), as.getAStr2()));\r
87             }\r
88         }\r
89 \r
90         if (count > 2)\r
91         {\r
92             System.out.println(\r
93                 "Pairwise alignment scaled similarity score matrix\n");\r
94 \r
95             for (int i = 0; i < count; i++)\r
96             {\r
97                 jalview.util.Format.print(System.out, "%s \n",\r
98                     ("" + i) + " " +\r
99                     ((SequenceI) selsubset.elementAt(i)).getName());\r
100             }\r
101 \r
102             System.out.println("\n");\r
103 \r
104             for (int i = 0; i < count; i++)\r
105             {\r
106                 for (int j = 0; j < i; j++)\r
107                 {\r
108                     jalview.util.Format.print(System.out, "%7.3f",\r
109                         scores[i][j] / totscore);\r
110                 }\r
111             }\r
112 \r
113             System.out.println("\n");\r
114         }\r
115     }\r
116 \r
117     /**\r
118      * DOCUMENT ME!\r
119      *\r
120      * @param e DOCUMENT ME!\r
121      */\r
122     protected void viewInEditorButton_actionPerformed(ActionEvent e)\r
123     {\r
124         Sequence[] seq = new Sequence[sequences.size()];\r
125 \r
126         for (int i = 0; i < sequences.size(); i++)\r
127         {\r
128             seq[i] = (Sequence) sequences.elementAt(i);\r
129         }\r
130 \r
131         AlignFrame af = new AlignFrame(new Alignment(seq));\r
132         Desktop.addInternalFrame(af, "Pairwise Aligned Sequences",\r
133             AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);\r
134     }\r
135 }\r