2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignSeq;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentView;
26 import jalview.datamodel.SequenceGroup;
27 import jalview.datamodel.SequenceI;
28 import jalview.jbgui.GPairwiseAlignPanel;
29 import jalview.util.MessageManager;
30 import jalview.viewmodel.AlignmentViewport;
32 import java.awt.event.ActionEvent;
33 import java.util.Vector;
41 public class PairwiseAlignPanel extends GPairwiseAlignPanel
44 private static final String DASHES = "---------------------\n";
48 Vector<SequenceI> sequences;
51 * Creates a new PairwiseAlignPanel object.
56 public PairwiseAlignPanel(AlignmentViewport viewport)
61 sequences = new Vector<SequenceI>();
63 SequenceGroup selectionGroup = viewport.getSelectionGroup();
64 boolean isSelection = selectionGroup != null
65 && selectionGroup.getSize() > 0;
66 AlignmentView view = viewport.getAlignmentView(isSelection);
67 // String[] seqStrings = viewport.getViewAsString(true);
68 String[] seqStrings = view.getSequenceStrings(viewport
74 seqs = (SequenceI[]) view.getAlignmentAndHiddenColumns(viewport
75 .getGapCharacter())[0];
79 seqs = av.getAlignment().getSequencesArray();
82 String type = (viewport.getAlignment().isNucleotide()) ? AlignSeq.DNA
85 float[][] scores = new float[seqs.length][seqs.length];
87 int count = seqs.length;
90 for (int i = 1; i < count; i++)
92 for (int j = 0; j < i; j++)
94 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j],
97 if (as.s1str.length() == 0 || as.s2str.length() == 0)
102 as.calcScoreMatrix();
107 System.out.println(DASHES);
108 textarea.append(DASHES);
111 as.printAlignment(System.out);
112 scores[i][j] = as.getMaxScore()
113 / as.getASeq1().length;
114 totscore = totscore + scores[i][j];
116 textarea.append(as.getOutput());
117 sequences.add(as.getAlignedSeq1());
118 sequences.add(as.getAlignedSeq2());
124 printScoreMatrix(seqs, scores, totscore);
129 * Prints a matrix of seqi-seqj pairwise alignment scores to sysout
135 protected void printScoreMatrix(SequenceI[] seqs, float[][] scores,
139 .println("Pairwise alignment scaled similarity score matrix\n");
141 for (int i = 0; i < seqs.length; i++)
143 System.out.println(String.format("%3d %s", i + 1,
144 seqs[i].getDisplayId(true)));
148 * table heading columns for sequences 1, 2, 3...
150 System.out.print("\n ");
151 for (int i = 0; i < seqs.length; i++)
153 System.out.print(String.format("%7d", i + 1));
155 System.out.println();
157 for (int i = 0; i < seqs.length; i++)
159 System.out.print(String.format("%3d", i + 1));
160 for (int j = 0; j < i; j++)
163 * as a fraction of tot score, outputs are 0 <= score <= 1
165 System.out.print(String.format("%7.3f", scores[i][j] / totscore));
167 System.out.println();
170 System.out.println("\n");
180 protected void viewInEditorButton_actionPerformed(ActionEvent e)
182 SequenceI[] seq = new SequenceI[sequences.size()];
184 for (int i = 0; i < sequences.size(); i++)
186 seq[i] = sequences.elementAt(i);
189 AlignFrame af = new AlignFrame(new Alignment(seq),
190 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
192 Desktop.addInternalFrame(af,
193 MessageManager.getString("label.pairwise_aligned_sequences"),
194 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);