X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FGroupSet.java;h=95d012797b6a45f9979ca6e275486d41af764f8f;hb=a3f65dbb5ba8bd470a31ba2af72db6d8ddf60546;hp=c7a73b76580e03017d7ae5a20ebecd6db17d290a;hpb=80b889f0cca49103e1b20ed806755a0719789906;p=jalview.git diff --git a/src/jalview/datamodel/GroupSet.java b/src/jalview/datamodel/GroupSet.java index c7a73b7..95d0127 100644 --- a/src/jalview/datamodel/GroupSet.java +++ b/src/jalview/datamodel/GroupSet.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.datamodel; import java.awt.Color; @@ -145,30 +165,60 @@ public class GroupSet implements GroupSetI return treeType; } - public static GroupSet makeGroups(ContactMatrixI matrix, float thresh, - boolean abs) + public static GroupSet makeGroups(ContactMatrixI matrix, boolean autoCut) + { + return makeGroups(matrix, autoCut, 0, autoCut); + } + + public static GroupSet makeGroups(ContactMatrixI matrix, boolean auto, + float thresh, boolean abs) { AverageDistanceEngine clusterer = new AverageDistanceEngine(null, null, - matrix); + matrix, true); double height = clusterer.findHeight(clusterer.getTopNode()); + Console.debug("Column tree height: " + height); String newick = new jalview.io.NewickFile(clusterer.getTopNode(), false, true).print(); String treeType = "UPGMA"; Console.trace("Newick string\n" + newick); List nodegroups; - if (abs ? height > thresh : 0 < thresh && thresh < 1) + float cut = -1f; + if (auto) { - float cut = abs ? (float) (thresh / height) : thresh; - Console.debug("Threshold " + cut + " for height=" + height); - - nodegroups = clusterer.groupNodes(cut); + double rootw = 0; + int p = 2; + BinaryNode bn = clusterer.getTopNode(); + while (p-- > 0 & bn.left() != null) + { + if (bn.left() != null) + { + bn = bn.left(); + } + if (bn.left() != null) + { + rootw = bn.height; + } + } + thresh = Math.max((float) (rootw / height) - 0.01f, 0); + cut = thresh; + nodegroups = clusterer.groupNodes(thresh); } else { - nodegroups = new ArrayList(); - nodegroups.add(clusterer.getTopNode()); + if (abs ? (height > thresh) : (0 < thresh && thresh < 1)) + { + cut = abs ? thresh : (float) (thresh * height); + Console.debug("Threshold " + cut + " for height=" + height); + nodegroups = clusterer.groupNodes(cut); + } + else + { + nodegroups = new ArrayList(); + nodegroups.add(clusterer.getTopNode()); + } } + List groups = new ArrayList<>(); for (BinaryNode root : nodegroups) { @@ -179,7 +229,8 @@ public class GroupSet implements GroupSetI } groups.add(gpset); } - GroupSet grps = new GroupSet(abs, thresh, groups, treeType, newick); + GroupSet grps = new GroupSet(abs, (cut == -1f) ? thresh : cut, groups, + treeType, newick); return grps; }