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.
21 package jalview.viewmodel;
23 import jalview.analysis.PaSiMap;
24 import jalview.api.RotatableCanvasI;
25 import jalview.api.analysis.ScoreModelI;
26 import jalview.api.analysis.SimilarityParamsI;
27 import jalview.datamodel.AlignmentView;
28 import jalview.datamodel.Point;
29 import jalview.datamodel.SequenceI;
30 import jalview.datamodel.SequencePoint;
31 import jalview.viewmodel.AlignmentViewport;
33 import java.util.List;
34 import java.util.Vector;
36 public class PaSiMapModel
41 private AlignmentViewport inputData;
43 private final SequenceI[] seqs;
45 private final SimilarityParamsI similarityParams;
48 * options - score model, nucleotide / protein
50 private ScoreModelI scoreModel;
52 private boolean nucleotide = false;
57 private PaSiMap pasimap;
61 private List<SequencePoint> points;
64 * Constructor given sequence data, score model and score calculation
73 public PaSiMapModel(AlignmentViewport seqData, SequenceI[] sqs, boolean nuc,
74 ScoreModelI modelName, SimilarityParamsI params)
79 scoreModel = modelName;
80 similarityParams = params;
84 * Performs the PaSiMap calculation (in the same thread) and extracts result data
85 * needed for visualisation by PaSiMapPanel
87 public void calculate()
89 pasimap = new PaSiMap(inputData, scoreModel, similarityParams);
90 pasimap.run(); // executes in same thread, wait for completion
92 // Now find the component coordinates
95 while ((ii < seqs.length) && (seqs[ii] != null))
100 int width = pasimap.getWidth();
101 int height = pasimap.getHeight();
104 points = new Vector<>();
105 Point[] scores = pasimap.getComponents(width - 1, width - 2, width - 3, 1);
107 for (int i = 0; i < height; i++)
109 SequencePoint sp = new SequencePoint(seqs[i], scores[i]);
114 public void updateRc(RotatableCanvasI rc)
116 rc.setPoints(points, pasimap.getHeight());
119 public boolean isNucleotide()
124 public void setNucleotide(boolean nucleotide)
126 this.nucleotide = nucleotide;
130 * Answers the index of the principal dimension of the PaSiMap
139 public void setTop(int t)
145 * Updates the 3D coordinates for the list of points to the given dimensions.
146 * Principal dimension is getTop(). Next greatest eigenvector is getTop()-1.
147 * Note - pasimap.getComponents starts counting the spectrum from rank-2 to zero,
148 * rather than rank-1, so getComponents(dimN ...) == updateRcView(dimN+1 ..)
154 public void updateRcView(int dim1, int dim2, int dim3)
156 // note: actual indices for components are dim1-1, etc (patch for JAL-1123)
157 Point[] scores = pasimap.getComponents(dim1 - 1, dim2 - 1, dim3 - 1, 1);
159 for (int i = 0; i < pasimap.getHeight(); i++)
161 points.get(i).coord = scores[i];
165 public String getDetails()
167 return pasimap.getDetails();
170 public AlignmentViewport getInputData()
175 public void setInputData(AlignmentViewport data)
180 public String getPointsasCsv(boolean transformed, int xdim, int ydim,
183 StringBuffer csv = new StringBuffer();
184 csv.append("\"Sequence\"");
196 for (int d = 1, dmax = pasimap.component(1).length; d <= dmax; d++)
202 for (int s = 0; s < seqs.length; s++)
204 csv.append("\"" + seqs[s].getName() + "\"");
205 Point p = points.get(s).coord;
206 csv.append(",").append(p.x);
207 csv.append(",").append(p.y);
208 csv.append(",").append(p.z);
211 return csv.toString();
214 public String getScoreModelName()
216 return scoreModel == null ? "" : scoreModel.getName();
219 public void setScoreModel(ScoreModelI sm)
221 this.scoreModel = sm;
225 * Answers the parameters configured for pairwise similarity calculations
229 public SimilarityParamsI getSimilarityParameters()
231 return similarityParams;
234 public List<SequencePoint> getSequencePoints()
239 public void setSequencePoints(List<SequencePoint> sp)
245 * Answers the object holding the values of the computed PaSiMap
249 public PaSiMap getPasimapData()
254 public void setPaSiMap(PaSiMap data)