Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 GMT
  2. Package jalview.viewmodel

File PaSiMapModel.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

22
67
22
1
289
185
35
0.52
3.05
22
1.59

Classes

Class Line # Actions
PaSiMapModel 37 67 35
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.viewmodel;
22   
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.gui.PairwiseAlignPanel;
32    import jalview.viewmodel.AlignmentViewport;
33   
34    import java.util.List;
35    import java.util.Vector;
36   
 
37    public class PaSiMapModel
38    {
39    /*
40    * inputs
41    */
42    private AlignmentViewport inputData;
43   
44    private final SequenceI[] seqs;
45   
46    /*
47    * options - score model, nucleotide / protein
48    */
49    private ScoreModelI scoreModel;
50   
51    private boolean nucleotide = false;
52   
53    /*
54    * outputs
55    */
56    private PaSiMap pasimap;
57   
58    int top;
59   
60    private List<SequencePoint> points;
61   
62    /**
63    * Constructor given sequence data, score model and score calculation
64    * parameter options.
65    *
66    * @param seqData
67    * @param sqs
68    * @param nuc
69    * @param modelName
70    * @param params
71    */
 
72  0 toggle public PaSiMapModel(AlignmentViewport seqData, SequenceI[] sqs,
73    boolean nuc, ScoreModelI modelName)
74    {
75  0 inputData = seqData;
76  0 seqs = sqs;
77  0 nucleotide = nuc;
78  0 scoreModel = modelName;
79    }
80   
81    /**
82    * Performs the PaSiMap calculation (in the same thread) and extracts result
83    * data needed for visualisation by PaSiMapPanel
84    */
 
85  0 toggle public void calculate(PairwiseAlignPanel pap)
86    {
87  0 pasimap = new PaSiMap(inputData, scoreModel, pap);
88  0 pasimap.run(); // executes in same thread, wait for completion
89  0 if (pasimap.isCancelled())
90    {
91    // no more work to do
92  0 return;
93    }
94   
95    // Now find the component coordinates
96  0 int ii = 0;
97   
98  0 while ((ii < seqs.length) && (seqs[ii] != null))
99    {
100  0 ii++;
101    }
102   
103  0 int width = pasimap.getWidth();
104  0 int height = pasimap.getHeight();
105  0 top = width;
106   
107  0 points = new Vector<>();
108  0 Point[] scores = pasimap.getComponents(width - 1, width - 2, width - 3,
109    1);
110   
111  0 for (int i = 0; i < height; i++)
112    {
113  0 SequencePoint sp = new SequencePoint(seqs[i], scores[i]);
114  0 points.add(sp);
115    }
116    }
117   
 
118  0 toggle public void updateRc(RotatableCanvasI rc)
119    {
120  0 rc.setPoints(points, pasimap.getHeight());
121    }
122   
 
123  0 toggle public boolean isNucleotide()
124    {
125  0 return nucleotide;
126    }
127   
 
128  0 toggle public void setNucleotide(boolean nucleotide)
129    {
130  0 this.nucleotide = nucleotide;
131    }
132   
133    /**
134    * Answers the index of the principal dimension of the PaSiMap
135    *
136    * @return
137    */
 
138  0 toggle public int getTop()
139    {
140  0 return top;
141    }
142   
 
143  0 toggle public void setTop(int t)
144    {
145  0 top = t;
146    }
147   
148    /**
149    * Updates the 3D coordinates for the list of points to the given dimensions.
150    * Principal dimension is getTop(). Next greatest eigenvector is getTop()-1.
151    * Note - pasimap.getComponents starts counting the spectrum from rank-2 to
152    * zero, rather than rank-1, so getComponents(dimN ...) == updateRcView(dimN+1
153    * ..)
154    *
155    * @param dim1
156    * @param dim2
157    * @param dim3
158    */
 
159  0 toggle public void updateRcView(int dim1, int dim2, int dim3)
160    {
161    // note: actual indices for components are dim1-1, etc (patch for JAL-1123)
162  0 Point[] scores = pasimap.getComponents(dim1 - 1, dim2 - 1, dim3 - 1, 1);
163   
164  0 for (int i = 0; i < pasimap.getHeight(); i++)
165    {
166  0 points.get(i).coord = scores[i];
167    }
168    }
169   
 
170  0 toggle public String getDetails()
171    {
172  0 return pasimap.getDetails();
173    }
174   
 
175  0 toggle public String getAlignmentOutput()
176    {
177  0 return pasimap.getAlignmentOutput();
178    }
179   
 
180  0 toggle public AlignmentViewport getInputData()
181    {
182  0 return inputData;
183    }
184   
 
185  0 toggle public void setInputData(AlignmentViewport data)
186    {
187  0 inputData = data;
188    }
189   
 
190  0 toggle public String getPointsasCsv(boolean transformed, int xdim, int ydim,
191    int zdim)
192    {
193  0 StringBuffer csv = new StringBuffer();
194  0 csv.append("\"Sequence\"");
195  0 if (transformed)
196    {
197  0 csv.append(",");
198  0 csv.append(xdim);
199  0 csv.append(",");
200  0 csv.append(ydim);
201  0 csv.append(",");
202  0 csv.append(zdim);
203    }
204    else
205    {
206  0 for (int d = 1, dmax = (int) pasimap.getDim(); d <= dmax; d++)
207    {
208  0 csv.append("," + d);
209    }
210    }
211  0 csv.append("\n");
212  0 for (int s = 0; s < seqs.length; s++)
213    {
214  0 csv.append("\"" + seqs[s].getName() + "\"");
215  0 if (!transformed)
216    {
217  0 double[] fl = pasimap.component(s);
218  0 for (int d = fl.length - 1; d >= 0; d--)
219    {
220  0 csv.append(",");
221  0 csv.append(fl[d]);
222    }
223    }
224    else
225    {
226  0 Point p = points.get(s).coord;
227  0 csv.append(",").append(p.x);
228  0 csv.append(",").append(p.y);
229  0 csv.append(",").append(p.z);
230    }
231  0 csv.append("\n");
232    }
233  0 return csv.toString();
234    }
235   
 
236  0 toggle public String getScoreModelName()
237    {
238  0 return scoreModel == null ? "" : scoreModel.getName();
239    }
240   
 
241  0 toggle public void setScoreModel(ScoreModelI sm)
242    {
243  0 this.scoreModel = sm;
244    }
245   
 
246  0 toggle public List<SequencePoint> getSequencePoints()
247    {
248  0 return points;
249    }
250   
 
251  0 toggle public void setSequencePoints(List<SequencePoint> sp)
252    {
253  0 points = sp;
254    }
255   
256    /**
257    * Answers the object holding the values of the computed PaSiMap
258    *
259    * @return
260    */
 
261  0 toggle public PaSiMap getPasimapData()
262    {
263  0 return pasimap;
264    }
265   
 
266  0 toggle public void setPaSiMap(PaSiMap data)
267    {
268  0 pasimap = data;
269    }
270   
 
271  0 toggle public boolean isCancelled()
272    {
273  0 if (pasimap==null || pasimap.isCancelled())
274    {
275  0 return true;
276    }
277  0 return false;
278    }
279   
 
280  0 toggle public void cancel()
281    {
282  0 pasimap.cancel();
283    }
284   
 
285  0 toggle public boolean canCancel()
286    {
287  0 return (!isCancelled() && pasimap.isCancellable());
288    }
289    }