Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.viewmodel

File SpatialModel.java

 

Coverage histogram

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

Code metrics

20
66
23
1
276
184
34
0.52
2.87
23
1.48

Classes

Class Line # Actions
SpatialModel 15 66 34
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

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