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.analysis.scoremodels.ScoreMatrix;
25 import jalview.api.analysis.ScoreModelI;
26 import jalview.api.analysis.SimilarityParamsI;
27 import jalview.datamodel.Alignment;
28 import jalview.datamodel.AlignmentView;
29 import jalview.datamodel.SequenceGroup;
30 import jalview.datamodel.SequenceI;
31 import jalview.jbgui.GPairwiseAlignPanel;
32 import jalview.util.MessageManager;
33 import jalview.viewmodel.AlignmentViewport;
35 import java.awt.event.ActionEvent;
36 import java.util.Vector;
44 public class PairwiseAlignPanel extends GPairwiseAlignPanel
47 private static final String DASHES = "---------------------\n";
51 Vector<SequenceI> sequences;
54 * Creates a new PairwiseAlignPanel object.
57 * contains selected sequences to align
59 public PairwiseAlignPanel(AlignmentViewport viewport)
65 * Creates a new PairwiseAlignPanel object.
68 * contains selected sequences to align
71 public PairwiseAlignPanel(AlignmentViewport viewport, ScoreMatrix params)
76 sequences = new Vector<SequenceI>();
78 SequenceGroup selectionGroup = viewport.getSelectionGroup();
79 boolean isSelection = selectionGroup != null
80 && selectionGroup.getSize() > 0;
81 AlignmentView view = viewport.getAlignmentView(isSelection);
82 // String[] seqStrings = viewport.getViewAsString(true);
83 String[] seqStrings = view
84 .getSequenceStrings(viewport.getGapCharacter());
89 seqs = (SequenceI[]) view
90 .getAlignmentAndHiddenColumns(viewport.getGapCharacter())[0];
94 seqs = av.getAlignment().getSequencesArray();
97 String type = (viewport.getAlignment().isNucleotide()) ? AlignSeq.DNA
100 float[][] scores = new float[seqs.length][seqs.length];
101 double totscore = 0D;
102 int count = seqs.length;
103 boolean first = true;
105 for (int i = 1; i < count; i++)
107 for (int j = 0; j < i; j++)
109 AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j],
110 seqStrings[j], type);
112 if (as.s1str.length() == 0 || as.s2str.length() == 0)
118 as.setScoreMatrix(params);
120 as.calcScoreMatrix();
125 jalview.bin.Console.outPrintln(DASHES);
126 textarea.append(DASHES);
129 as.printAlignment(System.out);
130 scores[i][j] = as.getMaxScore() / as.getASeq1().length;
131 totscore = totscore + scores[i][j];
133 textarea.append(as.getOutput());
134 sequences.add(as.getAlignedSeq1());
135 sequences.add(as.getAlignedSeq2());
141 printScoreMatrix(seqs, scores, totscore);
146 * Prints a matrix of seqi-seqj pairwise alignment scores to sysout
152 protected void printScoreMatrix(SequenceI[] seqs, float[][] scores,
156 .println("Pairwise alignment scaled similarity score matrix\n");
158 for (int i = 0; i < seqs.length; i++)
160 jalview.bin.Console.outPrintln(
161 String.format("%3d %s", i + 1, seqs[i].getDisplayId(true)));
165 * table heading columns for sequences 1, 2, 3...
167 System.out.print("\n ");
168 for (int i = 0; i < seqs.length; i++)
170 System.out.print(String.format("%7d", i + 1));
172 jalview.bin.Console.outPrintln();
174 for (int i = 0; i < seqs.length; i++)
176 System.out.print(String.format("%3d", i + 1));
177 for (int j = 0; j < i; j++)
180 * as a fraction of tot score, outputs are 0 <= score <= 1
182 System.out.print(String.format("%7.3f", scores[i][j] / totscore));
184 jalview.bin.Console.outPrintln();
187 jalview.bin.Console.outPrintln("\n");
197 protected void viewInEditorButton_actionPerformed(ActionEvent e)
199 SequenceI[] seq = new SequenceI[sequences.size()];
201 for (int i = 0; i < sequences.size(); i++)
203 seq[i] = sequences.elementAt(i);
206 AlignFrame af = new AlignFrame(new Alignment(seq),
207 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
209 Desktop.addInternalFrame(af,
210 MessageManager.getString("label.pairwise_aligned_sequences"),
211 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);