2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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(ap.av.getAlignment());
58 float scores[][] = new float[seqs.length][seqs.length];
60 int count = ap.av.getSelectionGroup().getSize();
61 String type = (ap.av.getAlignment().isNucleotide()) ? AlignSeq.DNA
65 for (int i = 1; i < count; i++)
67 for (int j = 0; j < i; j++)
70 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j],
73 if (as.s1str.length() == 0 || as.s2str.length() == 0)
81 as.printAlignment(System.out);
82 scores[i][j] = (float) as.getMaxScore()
83 / (float) as.getASeq1().length;
84 totscore = totscore + scores[i][j];
86 textarea.append(as.getOutput());
87 seq = new Sequence(as.getS1().getName(), as.getAStr1(), as.getS1()
88 .getStart(), as.getS1().getEnd());
89 sequences.addElement(seq);
91 seq = new Sequence(as.getS2().getName(), as.getAStr2(), as.getS2()
92 .getStart(), as.getS2().getEnd());
93 sequences.addElement(seq);
100 .println("Pairwise alignment scaled similarity score matrix\n");
102 for (int i = 0; i < count; i++)
104 jalview.util.Format.print(System.out, "%s \n", ("" + i) + " "
105 + seqs[i].getName());
108 System.out.println("\n");
110 for (int i = 0; i < count; i++)
112 for (int j = 0; j < i; j++)
114 jalview.util.Format.print(System.out, "%7.3f", scores[i][j]
119 System.out.println("\n");
123 public void actionPerformed(ActionEvent evt)
125 if (evt.getSource() == viewInEditorButton)
127 viewInEditorButton_actionPerformed();
131 protected void viewInEditorButton_actionPerformed()
134 Sequence[] seq = new Sequence[sequences.size()];
136 for (int i = 0; i < sequences.size(); i++)
138 seq[i] = (Sequence) sequences.elementAt(i);
141 new AlignFrame(new Alignment(seq), ap.av.applet,
142 "Pairwise Aligned Sequences", false);
146 protected ScrollPane scrollPane = new ScrollPane();
148 protected TextArea textarea = new TextArea();
150 protected Button viewInEditorButton = new Button();
152 Panel jPanel1 = new Panel();
154 BorderLayout borderLayout1 = new BorderLayout();
156 private void jbInit() throws Exception
158 this.setLayout(borderLayout1);
159 textarea.setFont(new java.awt.Font("Monospaced", 0, 12));
160 textarea.setText("");
161 viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));
162 viewInEditorButton.setLabel("View in alignment editor");
163 viewInEditorButton.addActionListener(this);
164 this.add(scrollPane, BorderLayout.CENTER);
165 scrollPane.add(textarea);
166 this.add(jPanel1, BorderLayout.SOUTH);
167 jPanel1.add(viewInEditorButton, null);