X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fdatamodel%2Falphafold%2FPAEContactMatrix.java;h=db3addc6d18eefdaed59f880f8745b85fb6fcfab;hb=fea1abc4a4d2c45a1ba6e6127bac5d2466de18fc;hp=d1a2e9daf81c4f40804782be8b82d216b3eebf4c;hpb=1f41372a2bda3efcc27abaed092495548135b6b4;p=jalview.git diff --git a/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java b/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java index d1a2e9d..db3addc 100644 --- a/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java +++ b/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java @@ -1,9 +1,14 @@ package jalview.ws.datamodel.alphafold; +import java.util.ArrayList; +import java.util.BitSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import jalview.analysis.AverageDistanceEngine; +import jalview.bin.Console; +import jalview.datamodel.BinaryNode; import jalview.datamodel.ContactListI; import jalview.datamodel.ContactListImpl; import jalview.datamodel.ContactListProviderI; @@ -248,4 +253,60 @@ public class PAEContactMatrix implements ContactMatrixI { return length; } + List groups=null; + @Override + public boolean hasGroups() + { + return groups!=null; + } + String newick=null; + public String getNewickString() + { + return newick; + } + public void makeGroups(float thresh,boolean abs) + { + AverageDistanceEngine clusterer = new AverageDistanceEngine(null, null, this); + double height = clusterer.findHeight(clusterer.getTopNode()); + newick = new jalview.io.NewickFile(clusterer.getTopNode(),false,true).print(); + + Console.trace("Newick string\n"+newick); + + List nodegroups; + if (abs ? height > thresh : 0 < thresh && thresh < 1) + { + float cut = abs ? (float) (thresh / height) : thresh; + Console.debug("Threshold "+cut+" for height="+height); + + nodegroups = clusterer.groupNodes(cut); + } + else + { + nodegroups = new ArrayList(); + nodegroups.add(clusterer.getTopNode()); + } + + groups = new ArrayList<>(); + for (BinaryNode root:nodegroups) + { + BitSet gpset=new BitSet(); + for (BinaryNode leaf:clusterer.findLeaves(root)) + { + gpset.set((Integer)leaf.element()); + } + groups.add(gpset); + } + } + + @Override + public BitSet getGroupsFor(int column) + { + for (BitSet gp:groups) { + if (gp.get(column)) + { + return gp; + } + } + return ContactMatrixI.super.getGroupsFor(column); + } }