2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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;
24 import java.awt.event.*;
26 import jalview.analysis.*;
27 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 : AlignSeq.PEP;
67 for (int i = 1; i < count; i++)
69 for (int j = 0; j < i; j++)
72 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i],
73 seqs[j], seqStrings[j], type);
75 if (as.s1str.length() == 0 || as.s2str.length() == 0)
83 as.printAlignment(System.out);
84 scores[i][j] = (float) as.getMaxScore() / (float) as.getASeq1().length;
85 totscore = totscore + scores[i][j];
87 textarea.append(as.getOutput());
88 seq = new Sequence(as.getS1().getName(),
90 as.getS1().getStart(),
93 sequences.addElement(seq);
95 seq = new Sequence(as.getS2().getName(),
97 as.getS2().getStart(),
99 sequences.addElement(seq);
106 "Pairwise alignment scaled similarity score matrix\n");
108 for (int i = 0; i < count; i++)
110 jalview.util.Format.print(System.out, "%s \n",
115 System.out.println("\n");
117 for (int i = 0; i < count; i++)
119 for (int j = 0; j < i; j++)
121 jalview.util.Format.print(System.out, "%7.3f",
122 scores[i][j] / totscore);
126 System.out.println("\n");
129 public void actionPerformed(ActionEvent evt)
131 if(evt.getSource()==viewInEditorButton)
132 viewInEditorButton_actionPerformed();
135 protected void viewInEditorButton_actionPerformed()
138 Sequence[] seq = new Sequence[sequences.size()];
140 for (int i = 0; i < sequences.size(); i++)
142 seq[i] = (Sequence) sequences.elementAt(i);
145 new AlignFrame(new Alignment(seq),
147 "Pairwise Aligned Sequences",
151 protected ScrollPane scrollPane = new ScrollPane();
152 protected TextArea textarea = new TextArea();
153 protected Button viewInEditorButton = new Button();
154 Panel jPanel1 = new Panel();
155 BorderLayout borderLayout1 = new BorderLayout();
157 private void jbInit() throws Exception {
158 this.setLayout(borderLayout1);
159 textarea.setFont(new java.awt.Font("Monospaced", 0, 12));
160 textarea.setText("");
161 viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));
162 viewInEditorButton.setLabel("View in alignment editor");
163 viewInEditorButton.addActionListener(this);
164 this.add(scrollPane, BorderLayout.CENTER);
165 scrollPane.add(textarea);
166 this.add(jPanel1, BorderLayout.SOUTH);
167 jPanel1.add(viewInEditorButton, null);