2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.analysis.*;
26 import jalview.datamodel.*;
28 public class PairwiseAlignPanel extends Panel implements ActionListener
30 Vector sequences = new Vector();
34 public PairwiseAlignPanel(AlignmentPanel ap)
44 sequences = new Vector();
47 String[] seqStrings = ap.av.getViewAsString(true);
49 if (ap.av.getSelectionGroup() == null)
51 seqs = ap.av.getAlignment().getSequencesArray();
55 seqs = ap.av.getSelectionGroup().getSequencesInOrder(
56 ap.av.getAlignment());
59 float scores[][] = new float[seqs.length][seqs.length];
61 int count = ap.av.getSelectionGroup().getSize();
62 String type = (ap.av.getAlignment().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);