2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
26 import java.awt.event.*;
28 import jalview.analysis.*;
29 import jalview.datamodel.*;
30 import jalview.util.MessageManager;
32 public class PairwiseAlignPanel extends Panel implements ActionListener
34 Vector sequences = new Vector();
38 public PairwiseAlignPanel(AlignmentPanel ap)
48 sequences = new Vector();
51 String[] seqStrings = ap.av.getViewAsString(true);
53 if (ap.av.getSelectionGroup() == null)
55 seqs = ap.av.getAlignment().getSequencesArray();
59 seqs = ap.av.getSelectionGroup().getSequencesInOrder(
60 ap.av.getAlignment());
63 float scores[][] = new float[seqs.length][seqs.length];
65 int count = ap.av.getSelectionGroup().getSize();
66 String type = (ap.av.getAlignment().isNucleotide()) ? AlignSeq.DNA
70 for (int i = 1; i < count; i++)
72 for (int j = 0; j < i; j++)
75 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j],
78 if (as.s1str.length() == 0 || as.s2str.length() == 0)
86 as.printAlignment(System.out);
87 scores[i][j] = (float) as.getMaxScore()
88 / (float) as.getASeq1().length;
89 totscore = totscore + scores[i][j];
91 textarea.append(as.getOutput());
92 seq = new Sequence(as.getS1().getName(), as.getAStr1(), as.getS1()
93 .getStart(), as.getS1().getEnd());
94 sequences.addElement(seq);
96 seq = new Sequence(as.getS2().getName(), as.getAStr2(), as.getS2()
97 .getStart(), as.getS2().getEnd());
98 sequences.addElement(seq);
105 .println("Pairwise alignment scaled similarity score matrix\n");
107 for (int i = 0; i < count; i++)
109 jalview.util.Format.print(System.out, "%s \n", ("" + i) + " "
110 + seqs[i].getName());
113 System.out.println("\n");
115 for (int i = 0; i < count; i++)
117 for (int j = 0; j < i; j++)
119 jalview.util.Format.print(System.out, "%7.3f", scores[i][j]
124 System.out.println("\n");
128 public void actionPerformed(ActionEvent evt)
130 if (evt.getSource() == viewInEditorButton)
132 viewInEditorButton_actionPerformed();
136 protected void viewInEditorButton_actionPerformed()
139 Sequence[] seq = new Sequence[sequences.size()];
141 for (int i = 0; i < sequences.size(); i++)
143 seq[i] = (Sequence) sequences.elementAt(i);
146 new AlignFrame(new Alignment(seq), ap.av.applet,
147 "Pairwise Aligned Sequences", false);
151 protected ScrollPane scrollPane = new ScrollPane();
153 protected TextArea textarea = new TextArea();
155 protected Button viewInEditorButton = new Button();
157 Panel jPanel1 = new Panel();
159 BorderLayout borderLayout1 = new BorderLayout();
161 private void jbInit() throws Exception
163 this.setLayout(borderLayout1);
164 textarea.setFont(new java.awt.Font("Monospaced", 0, 12));
165 textarea.setText("");
166 viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));
167 viewInEditorButton.setLabel(MessageManager
168 .getString("label.view_alignment_editor"));
169 viewInEditorButton.addActionListener(this);
170 this.add(scrollPane, BorderLayout.CENTER);
171 scrollPane.add(textarea);
172 this.add(jPanel1, BorderLayout.SOUTH);
173 jPanel1.add(viewInEditorButton, null);