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.*;
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.getAlignment().getSequencesArray();
56 seqs = ap.av.getSelectionGroup().getSequencesInOrder(
57 ap.av.getAlignment());
60 float scores[][] = new float[seqs.length][seqs.length];
62 int count = ap.av.getSelectionGroup().getSize();
63 String type = (ap.av.getAlignment().isNucleotide()) ? AlignSeq.DNA
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], seqs[j],
75 if (as.s1str.length() == 0 || as.s2str.length() == 0)
83 as.printAlignment(System.out);
84 scores[i][j] = (float) as.getMaxScore()
85 / (float) as.getASeq1().length;
86 totscore = totscore + scores[i][j];
88 textarea.append(as.getOutput());
89 seq = new Sequence(as.getS1().getName(), as.getAStr1(), as.getS1()
90 .getStart(), as.getS1().getEnd());
91 sequences.addElement(seq);
93 seq = new Sequence(as.getS2().getName(), as.getAStr2(), as.getS2()
94 .getStart(), as.getS2().getEnd());
95 sequences.addElement(seq);
102 .println("Pairwise alignment scaled similarity score matrix\n");
104 for (int i = 0; i < count; i++)
106 jalview.util.Format.print(System.out, "%s \n", ("" + i) + " "
107 + seqs[i].getName());
110 System.out.println("\n");
112 for (int i = 0; i < count; i++)
114 for (int j = 0; j < i; j++)
116 jalview.util.Format.print(System.out, "%7.3f", scores[i][j]
121 System.out.println("\n");
125 public void actionPerformed(ActionEvent evt)
127 if (evt.getSource() == viewInEditorButton)
129 viewInEditorButton_actionPerformed();
133 protected void viewInEditorButton_actionPerformed()
136 Sequence[] seq = new Sequence[sequences.size()];
138 for (int i = 0; i < sequences.size(); i++)
140 seq[i] = (Sequence) sequences.elementAt(i);
143 new AlignFrame(new Alignment(seq), ap.av.applet,
144 "Pairwise Aligned Sequences", false);
148 protected ScrollPane scrollPane = new ScrollPane();
150 protected TextArea textarea = new TextArea();
152 protected Button viewInEditorButton = new Button();
154 Panel jPanel1 = new Panel();
156 BorderLayout borderLayout1 = new BorderLayout();
158 private void jbInit() throws Exception
160 this.setLayout(borderLayout1);
161 textarea.setFont(new java.awt.Font("Monospaced", 0, 12));
162 textarea.setText("");
163 viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));
164 viewInEditorButton.setLabel("View in alignment editor");
165 viewInEditorButton.addActionListener(this);
166 this.add(scrollPane, BorderLayout.CENTER);
167 scrollPane.add(textarea);
168 this.add(jPanel1, BorderLayout.SOUTH);
169 jPanel1.add(viewInEditorButton, null);