Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 10:11:34 GMT
  2. Package jalview.analysis

File TreeBuilder.java

 

Coverage histogram

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

Code metrics

12
50
10
1
214
126
16
0.32
5
10
1.6

Classes

Class Line # Actions
TreeBuilder 40 50 16
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.analysis;
22   
23    import jalview.api.analysis.ScoreModelI;
24    import jalview.api.analysis.SimilarityParamsI;
25    import jalview.datamodel.AlignmentView;
26    import jalview.datamodel.BinaryNode;
27    import jalview.datamodel.CigarArray;
28    import jalview.datamodel.SeqCigar;
29    import jalview.datamodel.SequenceI;
30    import jalview.datamodel.SequenceNode;
31    import jalview.util.MessageManager;
32    import jalview.viewmodel.AlignmentViewport;
33   
34   
35    import java.util.ArrayList;
36    import java.util.BitSet;
37    import java.util.List;
38    import java.util.Vector;
39   
 
40    public abstract class TreeBuilder extends TreeEngine
41    {
42    public static final String AVERAGE_DISTANCE = "AV";
43   
44    public static final String NEIGHBOUR_JOINING = "NJ";
45   
46    protected SequenceI[] sequences;
47   
48    protected List<String> labels;
49   
50    public AlignmentView seqData;
51   
52    private AlignmentView seqStrings;
53   
54    /**
55    * Constructor
56    *
57    * @param av
58    * @param sm
59    * @param scoreParameters
60    */
 
61  0 toggle public TreeBuilder(AlignmentViewport av, ScoreModelI sm,
62    SimilarityParamsI scoreParameters)
63    {
64  0 int start, end;
65  0 boolean selview = av.getSelectionGroup() != null
66    && av.getSelectionGroup().getSize() > 1;
67  0 seqStrings = av.getAlignmentView(selview);
68  0 if (!selview)
69    {
70  0 start = 0;
71  0 end = av.getAlignment().getWidth();
72  0 this.sequences = av.getAlignment().getSequencesArray();
73    }
74    else
75    {
76  0 start = av.getSelectionGroup().getStartRes();
77  0 end = av.getSelectionGroup().getEndRes() + 1;
78  0 this.sequences = av.getSelectionGroup()
79    .getSequencesInOrder(av.getAlignment());
80    }
81   
82  0 init(seqStrings, start, end);
83   
84  0 computeTree(sm, scoreParameters);
85    }
86   
 
87  0 toggle public SequenceI[] getSequences()
88    {
89  0 return sequences;
90    }
91   
92    /**
93    *
94    * @return true if tree has real distances
95    */
 
96  0 toggle public boolean hasDistances()
97    {
98  0 return true;
99    }
100   
101    /**
102    *
103    * @return true if tree has real bootstrap values
104    */
 
105  0 toggle public boolean hasBootstrap()
106    {
107  0 return false;
108    }
109   
 
110  0 toggle public boolean hasRootDistance()
111    {
112  0 return true;
113    }
114   
 
115  0 toggle public List<String> getLabels(){
116  0 return this.labels;
117    }
118   
119    /**
120    * Calculates the tree using the given score model and parameters, and the
121    * configured tree type
122    * <p>
123    * If the score model computes pairwise distance scores, then these are used
124    * directly to derive the tree
125    * <p>
126    * If the score model computes similarity scores, then the range of the scores
127    * is reversed to give a distance measure, and this is used to derive the tree
128    *
129    * @param sm
130    * @param scoreOptions
131    */
 
132  0 toggle protected void computeTree(ScoreModelI sm, SimilarityParamsI scoreOptions)
133    {
134  0 labels = new ArrayList<String>();
135  0 sequences = sm.expandSeqData(sequences, seqData, scoreOptions, labels);
136  0 noseqs = sequences.length;
137   
138  0 distances = sm.findDistances(seqData, scoreOptions);
139   
140  0 makeLeaves();
141   
142  0 noClus = clusters.size();
143   
144  0 cluster();
145    }
146   
 
147  0 toggle protected void init(AlignmentView seqView, int start, int end)
148    {
149  0 this.node = new Vector<BinaryNode>();
150  0 if (seqView != null)
151    {
152  0 this.seqData = seqView;
153    }
154    else
155    {
156  0 SeqCigar[] seqs = new SeqCigar[sequences.length];
157  0 for (int i = 0; i < sequences.length; i++)
158    {
159  0 seqs[i] = new SeqCigar(sequences[i], start, end);
160    }
161  0 CigarArray sdata = new CigarArray(seqs);
162  0 sdata.addOperation(CigarArray.M, end - start + 1);
163  0 this.seqData = new AlignmentView(sdata, start);
164    }
165   
166    /*
167    * count the non-null sequences
168    */
169  0 noseqs = 0;
170   
171  0 done = new BitSet();
172   
173  0 for (SequenceI seq : sequences)
174    {
175  0 if (seq != null)
176    {
177  0 noseqs++;
178    }
179    }
180    }
181   
182    /**
183    * Start by making a cluster for each individual sequence
184    */
 
185  0 toggle void makeLeaves()
186    {
187  0 clusters = new Vector<BitSet>();
188   
189  0 for (int i = 0; i < noseqs; i++)
190    {
191  0 SequenceNode sn = new SequenceNode();
192   
193  0 sn.setElement(sequences[i]);
194   
195  0 if (labels.size() == noseqs)
196    {
197  0 sn.setLabel(labels.get(i));
198    }
199   
200  0 sn.setName(sequences[i].getName());
201   
202  0 node.addElement(sn);
203  0 BitSet bs = new BitSet();
204  0 bs.set(i);
205  0 clusters.addElement(bs);
206    }
207    }
208   
 
209  0 toggle public AlignmentView getOriginalData()
210    {
211  0 return seqStrings;
212    }
213   
214    }