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);
153 public static GroupSet makeGroups(ContactMatrixI matrix, boolean auto,
154 float thresh, boolean abs)
156 AverageDistanceEngine clusterer = new AverageDistanceEngine(null, null,
158 double height = clusterer.findHeight(clusterer.getTopNode());
159 Console.debug("Column tree height: " + height);
160 String newick = new jalview.io.NewickFile(clusterer.getTopNode(), false,
162 String treeType = "UPGMA";
163 Console.trace("Newick string\n" + newick);
165 List<BinaryNode> nodegroups;
171 BinaryNode bn = clusterer.getTopNode();
172 while (p-- > 0 & bn.left() != null)
174 if (bn.left() != null)
178 if (bn.left() != null)
183 thresh = Math.max((float) (rootw / height) - 0.01f, 0);
185 nodegroups = clusterer.groupNodes(thresh);
189 if (abs ? (height > thresh) : (0 < thresh && thresh < 1))
191 cut = abs ? thresh : (float) (thresh * height);
192 Console.debug("Threshold " + cut + " for height=" + height);
193 nodegroups = clusterer.groupNodes(cut);
197 nodegroups = new ArrayList<BinaryNode>();
198 nodegroups.add(clusterer.getTopNode());
202 List<BitSet> groups = new ArrayList<>();
203 for (BinaryNode root : nodegroups)
205 BitSet gpset = new BitSet();
206 for (BinaryNode leaf : clusterer.findLeaves(root))
208 gpset.set((Integer) leaf.element());
212 GroupSet grps = new GroupSet(abs, (cut == -1f) ? thresh : cut, groups,
218 public List<BitSet> getGroups()