2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
\r
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3
\r
10 * of the License, or (at your option) any later version.
\r
12 * Jalview is distributed in the hope that it will be useful, but
\r
13 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
15 * PURPOSE. See the GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
\r
21 package jalview.appletgui;
\r
23 import jalview.analysis.AlignSeq;
\r
24 import jalview.datamodel.Alignment;
\r
25 import jalview.datamodel.Sequence;
\r
26 import jalview.datamodel.SequenceI;
\r
27 import jalview.util.Format;
\r
28 import jalview.util.MessageManager;
\r
30 import java.awt.BorderLayout;
\r
31 import javax.swing.JButton;
\r
32 import javax.swing.JPanel;
\r
33 import javax.swing.JScrollPane;
\r
34 import javax.swing.JTextArea;
\r
35 import java.awt.event.ActionEvent;
\r
36 import java.awt.event.ActionListener;
\r
37 import java.util.Vector;
\r
39 public class PairwiseAlignPanel extends JPanel implements ActionListener
\r
41 Vector sequences = new Vector();
\r
45 public PairwiseAlignPanel(AlignmentPanel ap)
\r
50 } catch (Exception e)
\r
52 e.printStackTrace();
\r
55 sequences = new Vector();
\r
58 String[] seqStrings = ap.av.getViewAsString(true);
\r
60 if (ap.av.getSelectionGroup() == null)
\r
62 seqs = ap.av.getAlignment().getSequencesArray();
\r
66 seqs = ap.av.getSelectionGroup().getSequencesInOrder(
\r
67 ap.av.getAlignment());
\r
70 float scores[][] = new float[seqs.length][seqs.length];
\r
71 double totscore = 0;
\r
72 int count = ap.av.getSelectionGroup().getSize();
\r
73 String type = (ap.av.getAlignment().isNucleotide()) ? AlignSeq.DNA
\r
77 for (int i = 1; i < count; i++)
\r
79 for (int j = 0; j < i; j++)
\r
82 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j],
\r
83 seqStrings[j], type);
\r
85 if (as.s1str.length() == 0 || as.s2str.length() == 0)
\r
90 as.calcScoreMatrix();
\r
91 as.traceAlignment();
\r
93 as.printAlignment(System.out);
\r
94 scores[i][j] = (float) as.getMaxScore()
\r
95 / (float) as.getASeq1().length;
\r
96 totscore = totscore + scores[i][j];
\r
98 textarea.append(as.getOutput());
\r
99 sequences.add(as.getAlignedSeq1());
\r
100 sequences.add(as.getAlignedSeq1());
\r
107 .println("Pairwise alignment scaled similarity score matrix\n");
\r
109 for (int i = 0; i < count; i++)
\r
111 Format.print(System.out, "%s \n",
\r
113 + seqs[i].getName());
\r
116 System.out.println("\n");
\r
118 for (int i = 0; i < count; i++)
\r
120 for (int j = 0; j < i; j++)
\r
122 Format.printDouble(System.out, "%7.3f", scores[i][j]
\r
127 System.out.println("\n");
\r
131 public void actionPerformed(ActionEvent evt)
\r
133 if (evt.getSource() == viewInEditorButton)
\r
135 viewInEditorButton_actionPerformed();
\r
139 protected void viewInEditorButton_actionPerformed()
\r
142 Sequence[] seq = new Sequence[sequences.size()];
\r
144 for (int i = 0; i < sequences.size(); i++)
\r
146 seq[i] = (Sequence) sequences.elementAt(i);
\r
149 new AlignFrame(new Alignment(seq), ap.av.applet,
\r
150 "Pairwise Aligned Sequences", false);
\r
154 protected JScrollPane scrollPane = new JScrollPane();
\r
156 protected JTextArea textarea = new JTextArea();
\r
158 protected JButton viewInEditorButton = new JButton();
\r
160 JPanel jPanel1 = new JPanel();
\r
162 BorderLayout borderLayout1 = new BorderLayout();
\r
164 private void jbInit() throws Exception
\r
166 this.setLayout(borderLayout1);
\r
167 textarea.setFont(new java.awt.Font("Monospaced", 0, 12));
\r
168 textarea.setText("");
\r
169 viewInEditorButton.setFont(new java.awt.Font("Verdana", 0, 12));
\r
170 viewInEditorButton.setLabel(MessageManager
\r
171 .getString("label.view_alignment_editor"));
\r
172 viewInEditorButton.addActionListener(this);
\r
173 this.add(scrollPane, BorderLayout.CENTER);
\r
174 scrollPane.add(textarea);
\r
175 this.add(jPanel1, BorderLayout.SOUTH);
\r
176 jPanel1.add(viewInEditorButton, null);
\r