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, float thresh,
151 AverageDistanceEngine clusterer = new AverageDistanceEngine(null, null,
153 double height = clusterer.findHeight(clusterer.getTopNode());
154 String newick = new jalview.io.NewickFile(clusterer.getTopNode(), false,
156 String treeType = "UPGMA";
157 Console.trace("Newick string\n" + newick);
159 List<BinaryNode> nodegroups;
160 if (abs ? height > thresh : 0 < thresh && thresh < 1)
162 float cut = abs ? (float) (thresh / height) : thresh;
163 Console.debug("Threshold " + cut + " for height=" + height);
165 nodegroups = clusterer.groupNodes(cut);
169 nodegroups = new ArrayList<BinaryNode>();
170 nodegroups.add(clusterer.getTopNode());
172 List<BitSet> groups = new ArrayList<>();
173 for (BinaryNode root : nodegroups)
175 BitSet gpset = new BitSet();
176 for (BinaryNode leaf : clusterer.findLeaves(root))
178 gpset.set((Integer) leaf.element());
182 GroupSet grps = new GroupSet(abs, thresh, groups, treeType, newick);
187 public List<BitSet> getGroups()