1 package jalview.datamodel;
4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.BitSet;
7 import java.util.HashMap;
10 import jalview.analysis.AverageDistanceEngine;
11 import jalview.bin.Console;
13 public class GroupSet implements GroupSetI
15 List<BitSet> groups = Arrays.asList();
17 public GroupSet(GroupSet grps)
20 colorMap = new HashMap<BitSet, Color>(grps.colorMap);
21 groups = new ArrayList<BitSet>(grps.groups);
24 treeType = grps.treeType;
29 // TODO Auto-generated constructor stub
32 public GroupSet(boolean abs2, float thresh2, List<BitSet> groups2,
33 String treeType2, String newick2)
43 public boolean hasGroups()
45 return groups != null;
51 public String getNewick()
57 public boolean hasTree()
59 return newick != null && newick.length() > 0;
66 String treeType = null;
69 public void updateGroups(List<BitSet> colGroups)
71 if (colGroups != null)
78 public BitSet getGroupsFor(int column)
82 for (BitSet gp : groups)
90 // return singleton set;
91 BitSet bs = new BitSet();
96 HashMap<BitSet, Color> colorMap = new HashMap<>();
99 public Color getColourForGroup(BitSet bs)
105 Color groupCol = colorMap.get(bs);
106 if (groupCol == null)
114 public void setColorForGroup(BitSet bs, Color color)
116 colorMap.put(bs, color);
120 public void restoreGroups(List<BitSet> newgroups, String treeMethod,
121 String tree, double thresh2)
123 treeType = treeMethod;
131 public boolean hasCutHeight()
133 return groups != null && thresh != 0;
137 public double getCutHeight()
143 public String getTreeMethod()
148 public static GroupSet makeGroups(ContactMatrixI matrix, boolean autoCut)
150 return makeGroups(matrix, autoCut, 0, autoCut);
152 public static GroupSet makeGroups(ContactMatrixI matrix, boolean auto, float thresh,
155 AverageDistanceEngine clusterer = new AverageDistanceEngine(null, null,
157 double height = clusterer.findHeight(clusterer.getTopNode());
158 Console.debug("Column tree height: " + height);
159 String newick = new jalview.io.NewickFile(clusterer.getTopNode(), false,
161 String treeType = "UPGMA";
162 Console.trace("Newick string\n" + newick);
164 List<BinaryNode> nodegroups;
170 BinaryNode bn = clusterer.getTopNode();
171 while (p-- > 0 & bn.left() != null)
173 if (bn.left() != null)
177 if (bn.left() != null)
182 thresh = Math.max((float) (rootw / height) - 0.01f, 0);
184 nodegroups = clusterer.groupNodes(thresh);
188 if (abs ? (height > thresh) : (0 < thresh && thresh < 1))
190 cut = abs ? thresh : (float) (thresh * height);
191 Console.debug("Threshold " + cut + " for height=" + height);
192 nodegroups = clusterer.groupNodes(cut);
196 nodegroups = new ArrayList<BinaryNode>();
197 nodegroups.add(clusterer.getTopNode());
201 List<BitSet> groups = new ArrayList<>();
202 for (BinaryNode root : nodegroups)
204 BitSet gpset = new BitSet();
205 for (BinaryNode leaf : clusterer.findLeaves(root))
207 gpset.set((Integer) leaf.element());
211 GroupSet grps = new GroupSet(abs, (cut == -1f) ? thresh : cut, groups,
217 public List<BitSet> getGroups()