2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.analysis.*;
27 import jalview.datamodel.*;
28 import jalview.util.MessageManager;
30 public class PairwiseAlignPanel extends Panel implements ActionListener
32 Vector sequences = new Vector();
36 public PairwiseAlignPanel(AlignmentPanel ap)
46 sequences = new Vector();
49 String[] seqStrings = ap.av.getViewAsString(true);
51 if (ap.av.getSelectionGroup() == null)
53 seqs = ap.av.getAlignment().getSequencesArray();
57 seqs = ap.av.getSelectionGroup().getSequencesInOrder(
58 ap.av.getAlignment());
61 float scores[][] = new float[seqs.length][seqs.length];
63 int count = ap.av.getSelectionGroup().getSize();
64 String type = (ap.av.getAlignment().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], seqs[j],
76 if (as.s1str.length() == 0 || as.s2str.length() == 0)
84 as.printAlignment(System.out);
85 scores[i][j] = (float) as.getMaxScore()
86 / (float) as.getASeq1().length;
87 totscore = totscore + scores[i][j];
89 textarea.append(as.getOutput());
90 seq = new Sequence(as.getS1().getName(), as.getAStr1(), as.getS1()
91 .getStart(), as.getS1().getEnd());
92 sequences.addElement(seq);
94 seq = new Sequence(as.getS2().getName(), as.getAStr2(), as.getS2()
95 .getStart(), as.getS2().getEnd());
96 sequences.addElement(seq);
103 .println("Pairwise alignment scaled similarity score matrix\n");
105 for (int i = 0; i < count; i++)
107 jalview.util.Format.print(System.out, "%s \n", ("" + i) + " "
108 + seqs[i].getName());
111 System.out.println("\n");
113 for (int i = 0; i < count; i++)
115 for (int j = 0; j < i; j++)
117 jalview.util.Format.print(System.out, "%7.3f", scores[i][j]
122 System.out.println("\n");
126 public void actionPerformed(ActionEvent evt)
128 if (evt.getSource() == viewInEditorButton)
130 viewInEditorButton_actionPerformed();
134 protected void viewInEditorButton_actionPerformed()
137 Sequence[] seq = new Sequence[sequences.size()];
139 for (int i = 0; i < sequences.size(); i++)
141 seq[i] = (Sequence) sequences.elementAt(i);
144 new AlignFrame(new Alignment(seq), ap.av.applet,
145 "Pairwise Aligned Sequences", false);
149 protected ScrollPane scrollPane = new ScrollPane();
151 protected TextArea textarea = new TextArea();
153 protected Button viewInEditorButton = new Button();
155 Panel jPanel1 = new Panel();
157 BorderLayout borderLayout1 = new BorderLayout();
159 private void jbInit() throws Exception
161 this.setLayout(borderLayout1);
162 textarea.setFont(new java.awt.Font("Monospaced", 0, 12));
163 textarea.setText("");
164 viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));
165 viewInEditorButton.setLabel(MessageManager.getString("label.view_alignment_editor"));
166 viewInEditorButton.addActionListener(this);
167 this.add(scrollPane, BorderLayout.CENTER);
168 scrollPane.add(textarea);
169 this.add(jPanel1, BorderLayout.SOUTH);
170 jPanel1.add(viewInEditorButton, null);