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.api.AlignViewportI;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentView;
27 import jalview.datamodel.SequenceGroup;
28 import jalview.datamodel.SequenceI;
29 import jalview.jbgui.GPairwiseAlignPanel;
30 import jalview.util.MessageManager;
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.
55 public PairwiseAlignPanel(AlignViewportI viewport)
60 sequences = new Vector<>();
62 SequenceGroup selectionGroup = viewport.getSelectionGroup();
63 boolean isSelection = selectionGroup != null
64 && selectionGroup.getSize() > 0;
65 AlignmentView view = viewport.getAlignmentView(isSelection);
66 // String[] seqStrings = viewport.getViewAsString(true);
67 String[] seqStrings = view.getSequenceStrings(viewport
73 seqs = (SequenceI[]) view.getAlignmentAndHiddenColumns(viewport
74 .getGapCharacter())[0];
78 seqs = av.getAlignment().getSequencesArray();
81 String type = (viewport.getAlignment().isNucleotide()) ? AlignSeq.DNA
84 float[][] scores = new float[seqs.length][seqs.length];
86 int count = seqs.length;
89 for (int i = 1; i < count; i++)
91 for (int j = 0; j < i; j++)
93 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j],
96 if (as.s1str.length() == 0 || as.s2str.length() == 0)
101 as.calcScoreMatrix();
106 System.out.println(DASHES);
107 textarea.append(DASHES);
110 as.printAlignment(System.out);
111 scores[i][j] = as.getMaxScore()
112 / as.getASeq1().length;
113 totscore = totscore + scores[i][j];
115 textarea.append(as.getOutput());
116 sequences.add(as.getAlignedSeq1());
117 sequences.add(as.getAlignedSeq2());
123 printScoreMatrix(seqs, scores, totscore);
128 * Prints a matrix of seqi-seqj pairwise alignment scores to sysout
134 protected void printScoreMatrix(SequenceI[] seqs, float[][] scores,
138 .println("Pairwise alignment scaled similarity score matrix\n");
140 for (int i = 0; i < seqs.length; i++)
142 System.out.println(String.format("%3d %s", i + 1,
143 seqs[i].getDisplayId(true)));
147 * table heading columns for sequences 1, 2, 3...
149 System.out.print("\n ");
150 for (int i = 0; i < seqs.length; i++)
152 System.out.print(String.format("%7d", i + 1));
154 System.out.println();
156 for (int i = 0; i < seqs.length; i++)
158 System.out.print(String.format("%3d", i + 1));
159 for (int j = 0; j < i; j++)
162 * as a fraction of tot score, outputs are 0 <= score <= 1
164 System.out.print(String.format("%7.3f", scores[i][j] / totscore));
166 System.out.println();
169 System.out.println("\n");
179 protected void viewInEditorButton_actionPerformed(ActionEvent e)
181 SequenceI[] seq = new SequenceI[sequences.size()];
183 for (int i = 0; i < sequences.size(); i++)
185 seq[i] = sequences.elementAt(i);
188 AlignFrame af = new AlignFrame(new Alignment(seq),
189 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
191 Desktop.addInternalFrame(af,
192 MessageManager.getString("label.pairwise_aligned_sequences"),
193 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);