2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.analysis.*;
27 import jalview.datamodel.*;
29 public class PairwiseAlignPanel extends Panel implements ActionListener
31 Vector sequences = new Vector();
35 public PairwiseAlignPanel(AlignmentPanel ap)
45 sequences = new Vector();
48 String[] seqStrings = ap.av.getViewAsString(true);
50 if (ap.av.getSelectionGroup() == null)
52 seqs = ap.av.alignment.getSequencesArray();
56 seqs = ap.av.getSelectionGroup().getSequencesInOrder(ap.av.alignment);
59 float scores[][] = new float[seqs.length][seqs.length];
61 int count = ap.av.getSelectionGroup().getSize();
62 String type = (ap.av.alignment.isNucleotide()) ? AlignSeq.DNA
66 for (int i = 1; i < count; i++)
68 for (int j = 0; j < i; j++)
71 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j],
74 if (as.s1str.length() == 0 || as.s2str.length() == 0)
82 as.printAlignment(System.out);
83 scores[i][j] = (float) as.getMaxScore()
84 / (float) as.getASeq1().length;
85 totscore = totscore + scores[i][j];
87 textarea.append(as.getOutput());
88 seq = new Sequence(as.getS1().getName(), as.getAStr1(), as.getS1()
89 .getStart(), as.getS1().getEnd());
90 sequences.addElement(seq);
92 seq = new Sequence(as.getS2().getName(), as.getAStr2(), as.getS2()
93 .getStart(), as.getS2().getEnd());
94 sequences.addElement(seq);
101 .println("Pairwise alignment scaled similarity score matrix\n");
103 for (int i = 0; i < count; i++)
105 jalview.util.Format.print(System.out, "%s \n", ("" + i) + " "
106 + seqs[i].getName());
109 System.out.println("\n");
111 for (int i = 0; i < count; i++)
113 for (int j = 0; j < i; j++)
115 jalview.util.Format.print(System.out, "%7.3f", scores[i][j]
120 System.out.println("\n");
124 public void actionPerformed(ActionEvent evt)
126 if (evt.getSource() == viewInEditorButton)
128 viewInEditorButton_actionPerformed();
132 protected void viewInEditorButton_actionPerformed()
135 Sequence[] seq = new Sequence[sequences.size()];
137 for (int i = 0; i < sequences.size(); i++)
139 seq[i] = (Sequence) sequences.elementAt(i);
142 new AlignFrame(new Alignment(seq), ap.av.applet,
143 "Pairwise Aligned Sequences", false);
147 protected ScrollPane scrollPane = new ScrollPane();
149 protected TextArea textarea = new TextArea();
151 protected Button viewInEditorButton = new Button();
153 Panel jPanel1 = new Panel();
155 BorderLayout borderLayout1 = new BorderLayout();
157 private void jbInit() throws Exception
159 this.setLayout(borderLayout1);
160 textarea.setFont(new java.awt.Font("Monospaced", 0, 12));
161 textarea.setText("");
162 viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));
163 viewInEditorButton.setLabel("View in alignment editor");
164 viewInEditorButton.addActionListener(this);
165 this.add(scrollPane, BorderLayout.CENTER);
166 scrollPane.add(textarea);
167 this.add(jPanel1, BorderLayout.SOUTH);
168 jPanel1.add(viewInEditorButton, null);