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.analysis;
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.viewmodel.AlignmentViewport;
33 import java.util.BitSet;
34 import java.util.Vector;
36 public abstract class TreeBuilder extends TreeEngine
38 public static final String AVERAGE_DISTANCE = "AV";
40 public static final String NEIGHBOUR_JOINING = "NJ";
42 protected SequenceI[] sequences;
44 public AlignmentView seqData;
46 private AlignmentView seqStrings;
53 * @param scoreParameters
55 public TreeBuilder(AlignmentViewport av, ScoreModelI sm,
56 SimilarityParamsI scoreParameters)
59 boolean selview = av.getSelectionGroup() != null
60 && av.getSelectionGroup().getSize() > 1;
61 seqStrings = av.getAlignmentView(selview);
65 end = av.getAlignment().getWidth();
66 this.sequences = av.getAlignment().getSequencesArray();
70 start = av.getSelectionGroup().getStartRes();
71 end = av.getSelectionGroup().getEndRes() + 1;
72 this.sequences = av.getSelectionGroup()
73 .getSequencesInOrder(av.getAlignment());
76 init(seqStrings, start, end);
78 computeTree(sm, scoreParameters);
81 public SequenceI[] getSequences()
88 * @return true if tree has real distances
90 public boolean hasDistances()
97 * @return true if tree has real bootstrap values
99 public boolean hasBootstrap()
104 public boolean hasRootDistance()
110 * Calculates the tree using the given score model and parameters, and the
111 * configured tree type
113 * If the score model computes pairwise distance scores, then these are used
114 * directly to derive the tree
116 * If the score model computes similarity scores, then the range of the scores
117 * is reversed to give a distance measure, and this is used to derive the tree
120 * @param scoreOptions
122 protected void computeTree(ScoreModelI sm, SimilarityParamsI scoreOptions)
124 distances = sm.findDistances(seqData, scoreOptions);
128 noClus = clusters.size();
133 protected void init(AlignmentView seqView, int start, int end)
135 this.node = new Vector<BinaryNode>();
138 this.seqData = seqView;
142 SeqCigar[] seqs = new SeqCigar[sequences.length];
143 for (int i = 0; i < sequences.length; i++)
145 seqs[i] = new SeqCigar(sequences[i], start, end);
147 CigarArray sdata = new CigarArray(seqs);
148 sdata.addOperation(CigarArray.M, end - start + 1);
149 this.seqData = new AlignmentView(sdata, start);
153 * count the non-null sequences
159 for (SequenceI seq : sequences)
169 * Start by making a cluster for each individual sequence
173 clusters = new Vector<BitSet>();
175 for (int i = 0; i < noseqs; i++)
177 SequenceNode sn = new SequenceNode();
179 sn.setElement(sequences[i]);
180 sn.setName(sequences[i].getName());
182 BitSet bs = new BitSet();
184 clusters.addElement(bs);
188 public AlignmentView getOriginalData()