2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
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.
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.
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
20 package jalview.appletgui;
25 import java.awt.event.*;
27 import jalview.analysis.*;
28 import jalview.datamodel.*;
30 public class PairwiseAlignPanel
31 extends Panel implements ActionListener
33 Vector sequences = new Vector();
36 public PairwiseAlignPanel(AlignmentPanel ap)
47 sequences = new Vector();
50 String[] seqStrings = ap.av.getViewAsString(true);
52 if (ap.av.getSelectionGroup() == null)
54 seqs = ap.av.alignment.getSequencesArray();
58 seqs = ap.av.getSelectionGroup().getSequencesInOrder(ap.av.alignment);
61 float scores[][] = new float[seqs.length][seqs.length];
63 int count = ap.av.getSelectionGroup().getSize();
64 String type = (ap.av.alignment.isNucleotide()) ? AlignSeq.DNA :
68 for (int i = 1; i < count; i++)
70 for (int j = 0; j < i; j++)
73 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i],
74 seqs[j], seqStrings[j], type);
76 if (as.s1str.length() == 0 || as.s2str.length() == 0)
84 as.printAlignment(System.out);
85 scores[i][j] = (float) as.getMaxScore() / (float) as.getASeq1().length;
86 totscore = totscore + scores[i][j];
88 textarea.append(as.getOutput());
89 seq = new Sequence(as.getS1().getName(),
91 as.getS1().getStart(),
94 sequences.addElement(seq);
96 seq = new Sequence(as.getS2().getName(),
98 as.getS2().getStart(),
100 sequences.addElement(seq);
107 "Pairwise alignment scaled similarity score matrix\n");
109 for (int i = 0; i < count; i++)
111 jalview.util.Format.print(System.out, "%s \n",
116 System.out.println("\n");
118 for (int i = 0; i < count; i++)
120 for (int j = 0; j < i; j++)
122 jalview.util.Format.print(System.out, "%7.3f",
123 scores[i][j] / totscore);
127 System.out.println("\n");
131 public void actionPerformed(ActionEvent evt)
133 if (evt.getSource() == viewInEditorButton)
135 viewInEditorButton_actionPerformed();
139 protected void viewInEditorButton_actionPerformed()
142 Sequence[] seq = new Sequence[sequences.size()];
144 for (int i = 0; i < sequences.size(); i++)
146 seq[i] = (Sequence) sequences.elementAt(i);
149 new AlignFrame(new Alignment(seq),
151 "Pairwise Aligned Sequences",
156 protected ScrollPane scrollPane = new ScrollPane();
157 protected TextArea textarea = new TextArea();
158 protected Button viewInEditorButton = new Button();
159 Panel jPanel1 = new Panel();
160 BorderLayout borderLayout1 = new BorderLayout();
162 private void jbInit()
165 this.setLayout(borderLayout1);
166 textarea.setFont(new java.awt.Font("Monospaced", 0, 12));
167 textarea.setText("");
168 viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));
169 viewInEditorButton.setLabel("View in alignment editor");
170 viewInEditorButton.addActionListener(this);
171 this.add(scrollPane, BorderLayout.CENTER);
172 scrollPane.add(textarea);
173 this.add(jPanel1, BorderLayout.SOUTH);
174 jPanel1.add(viewInEditorButton, null);