updated to jalview 2.1 and begun ArchiveClient/VamsasClient/VamsasStore updates.
[jalview.git] / src / jalview / gui / PairwiseAlignPanel.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.gui;
20
21 import jalview.analysis.*;
22
23 import jalview.datamodel.*;
24
25 import jalview.jbgui.*;
26
27 import java.awt.event.*;
28
29 import java.util.*;
30
31
32 /**
33  * DOCUMENT ME!
34  *
35  * @author $author$
36  * @version $Revision$
37  */
38 public class PairwiseAlignPanel extends GPairwiseAlignPanel
39 {
40
41     AlignViewport av;
42     Vector sequences;
43
44     /**
45      * Creates a new PairwiseAlignPanel object.
46      *
47      * @param av DOCUMENT ME!
48      */
49     public PairwiseAlignPanel(AlignViewport av)
50     {
51         super();
52         this.av = av;
53
54         sequences = new Vector();
55
56         SequenceI [] seqs;
57         String []  seqStrings = av.getViewAsString(true);
58
59         if(av.getSelectionGroup()==null)
60         {
61           seqs = av.alignment.getSequencesArray();
62         }
63         else
64         {
65           seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);
66         }
67
68
69         float[][] scores = new float[seqs.length][seqs.length];
70         double totscore = 0;
71         int count = seqs.length;
72
73         Sequence seq;
74
75         for (int i = 1; i < count; i++)
76         {
77             for (int j = 0; j < i; j++)
78             {
79
80                 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i],
81                         seqs[j], seqStrings[j], "pep");
82
83                 if(as.s1str.length()==0 || as.s2str.length()==0)
84                 {
85                   continue;
86                 }
87
88                 as.calcScoreMatrix();
89                 as.traceAlignment();
90
91
92                 as.printAlignment(System.out);
93                 scores[i][j] = (float) as.getMaxScore() / (float) as.getASeq1().length;
94                 totscore = totscore + scores[i][j];
95
96                 textarea.append(as.getOutput());
97                 seq = new Sequence(as.getS1().getName(),
98                                    as.getAStr1(),
99                                    as.getS1().getStart(),
100                                    as.getS1().getEnd()
101                 );
102                 sequences.add(seq);
103
104                 seq = new Sequence(as.getS2().getName(),
105                                    as.getAStr2(),
106                                    as.getS2().getStart(),
107                                    as.getS2().getEnd() );
108                 sequences.add(seq);
109             }
110         }
111
112         if (count > 2)
113         {
114             System.out.println(
115                 "Pairwise alignment scaled similarity score matrix\n");
116
117             for (int i = 0; i < count; i++)
118             {
119                 jalview.util.Format.print(System.out, "%s \n",
120                     ("" + i) + " " +
121                     seqs[i].getName());
122             }
123
124             System.out.println("\n");
125
126             for (int i = 0; i < count; i++)
127             {
128                 for (int j = 0; j < i; j++)
129                 {
130                     jalview.util.Format.print(System.out, "%7.3f",
131                         scores[i][j] / totscore);
132                 }
133             }
134
135             System.out.println("\n");
136         }
137     }
138
139     /**
140      * DOCUMENT ME!
141      *
142      * @param e DOCUMENT ME!
143      */
144     protected void viewInEditorButton_actionPerformed(ActionEvent e)
145     {
146         Sequence[] seq = new Sequence[sequences.size()];
147
148         for (int i = 0; i < sequences.size(); i++)
149         {
150             seq[i] = (Sequence) sequences.elementAt(i);
151         }
152
153         AlignFrame af = new AlignFrame(new Alignment(seq));
154         Desktop.addInternalFrame(af, "Pairwise Aligned Sequences",
155             AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);
156     }
157 }