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";
46 private float[][] scores;
48 private float[][] alignmentScores; // scores used by PaSiMap
52 Vector<SequenceI> sequences;
55 * Creates a new PairwiseAlignPanel object.
60 public PairwiseAlignPanel(AlignmentViewport viewport)
65 sequences = new Vector<SequenceI>();
67 SequenceGroup selectionGroup = viewport.getSelectionGroup();
68 boolean isSelection = selectionGroup != null
69 && selectionGroup.getSize() > 0;
70 AlignmentView view = viewport.getAlignmentView(isSelection);
71 // String[] seqStrings = viewport.getViewAsString(true);
72 String[] seqStrings = view
73 .getSequenceStrings(viewport.getGapCharacter());
78 seqs = (SequenceI[]) view
79 .getAlignmentAndHiddenColumns(viewport.getGapCharacter())[0];
83 seqs = av.getAlignment().getSequencesArray();
86 String type = (viewport.getAlignment().isNucleotide()) ? AlignSeq.DNA
89 float[][] scores = new float[seqs.length][seqs.length];
90 float[][] alignmentScores = new float[seqs.length][seqs.length];
92 int count = seqs.length;
95 for (int i = 1; i < count; i++)
97 // fill diagonal alignmentScores with Float.NaN
98 alignmentScores[i-1][i-1] = Float.NaN;
99 for (int j = 0; j < i; j++)
101 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j],
102 seqStrings[j], type);
104 if (as.s1str.length() == 0 || as.s2str.length() == 0)
109 as.calcScoreMatrix();
115 System.out.println(DASHES);
116 textarea.append(DASHES);
119 as.printAlignment(System.out);
120 scores[i][j] = as.getMaxScore() / as.getASeq1().length;
121 alignmentScores[i][j] = as.getAlignmentScore();
123 totscore = totscore + scores[i][j];
125 textarea.append(as.getOutput());
126 sequences.add(as.getAlignedSeq1());
127 sequences.add(as.getAlignedSeq2());
130 alignmentScores[count-1][count-1] = Float.NaN;
132 this.scores = scores;
133 this.alignmentScores = alignmentScores;
137 printScoreMatrix(seqs, scores, totscore);
141 public float[][] getScores()
146 public float[][] getAlignmentScores()
148 return this.alignmentScores;
152 * Prints a matrix of seqi-seqj pairwise alignment scores to sysout
158 protected void printScoreMatrix(SequenceI[] seqs, float[][] scores,
162 .println("Pairwise alignment scaled similarity score matrix\n");
164 for (int i = 0; i < seqs.length; i++)
167 String.format("%3d %s", i + 1, seqs[i].getDisplayId(true)));
171 * table heading columns for sequences 1, 2, 3...
173 System.out.print("\n ");
174 for (int i = 0; i < seqs.length; i++)
176 System.out.print(String.format("%7d", i + 1));
178 System.out.println();
180 for (int i = 0; i < seqs.length; i++)
182 System.out.print(String.format("%3d", i + 1));
183 for (int j = 0; j < i; j++)
186 * as a fraction of tot score, outputs are 0 <= score <= 1
188 System.out.print(String.format("%7.3f", scores[i][j] / totscore));
190 System.out.println();
193 System.out.println("\n");
203 protected void viewInEditorButton_actionPerformed(ActionEvent e)
205 SequenceI[] seq = new SequenceI[sequences.size()];
207 for (int i = 0; i < sequences.size(); i++)
209 seq[i] = sequences.elementAt(i);
212 AlignFrame af = new AlignFrame(new Alignment(seq),
213 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
215 Desktop.addInternalFrame(af,
216 MessageManager.getString("label.pairwise_aligned_sequences"),
217 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);