package jalview.datamodel;
+ import java.awt.Color;
-import java.math.BigInteger;
import java.util.ArrayList;
+ import java.util.BitSet;
+ import java.util.HashMap;
import java.util.List;
-import java.util.Spliterator;
import java.util.StringTokenizer;
import jalview.bin.Console;
{
return "Contact Matrix";
}
- List<BitSet> groups=null;
+
++ List<BitSet> groups = null;
++
+ @Override
+ public void updateGroups(List<BitSet> colGroups)
+ {
+ groups = colGroups;
- colorMap=new HashMap<>();
++ colorMap = new HashMap<>();
+ }
++
+ @Override
+ public boolean hasGroups()
+ {
- return groups!=null && groups.size()>0;
++ return groups != null && groups.size() > 0;
+ }
++
+ @Override
+ public List<BitSet> getGroups()
+ {
+ return groups;
+ }
++
+ @Override
+ public BitSet getGroupsFor(int column)
+ {
- for (BitSet gp:groups) {
++ for (BitSet gp : groups)
++ {
+ if (gp.get(column))
+ {
+ return gp;
+ }
+ }
+ return ContactMatrixI.super.getGroupsFor(column);
+ }
- HashMap<BitSet,Color> colorMap = new HashMap<>();
- @Override
++
++ HashMap<BitSet, Color> colorMap = new HashMap<>();
++
++ @Override
+ public Color getColourForGroup(BitSet bs)
+ {
- if (bs==null) {
++ if (bs == null)
++ {
+ return Color.white;
+ }
- Color groupCol=colorMap.get(bs);
- if (groupCol==null)
++ Color groupCol = colorMap.get(bs);
++ if (groupCol == null)
+ {
+ return Color.white;
+ }
+ return groupCol;
+ }
- @Override
- public void setColorForGroup(BitSet bs,Color color)
++
++ @Override
++ public void setColorForGroup(BitSet bs, Color color)
+ {
- colorMap.put(bs,color);
++ colorMap.put(bs, color);
+ }
++
public static String contactToFloatString(ContactMatrixI cm)
{
StringBuilder sb = new StringBuilder();
String getType();
int getWidth();
+
int getHeight();
+
+ default boolean hasGroups() {
+ return false;
+ }
+ default BitSet getGroupsFor(int column) {
+ BitSet colbitset = new BitSet();
+ colbitset.set(column);
+ return colbitset;
+ }
+
+ default List<BitSet> getGroups() {
+ return Arrays.asList();
+ }
+
+ default boolean hasTree() {
+ return false;
+ }
+
+ /**
+ * Newick representation of clustered matrix
+ * @return null unless hasTree is true
+ */
+ default String getNewick() {
+ return null;
+ }
+
+ default String getTreeMethod() {
+ return null;
+ }
+
+ default boolean hasCutHeight() {
+ return false;
+ }
+
+ default double getCutHeight() {
+ return 0;
+ }
+
+ void updateGroups(List<BitSet> colGroups);
+
+ void setColorForGroup(BitSet bs, Color color);
+ default Color getColourForGroup(BitSet bs) { return Color.white;};
}
import com.stevesoft.pat.Regex;
+import jalview.bin.Jalview;
++import jalview.datamodel.BinaryNode;
+import jalview.datamodel.SequenceNode;
+import jalview.util.MessageManager;
+
/**
* Parse a new hanpshire style tree Caveats: NHX files are NOT supported and the
* tree distances and topology are unreliable when they are parsed. TODO: on
{
if (root.isDummy())
{
- _print(tf, (SequenceNode) root.right());
- _print(tf, (SequenceNode) root.left());
- _print(tf, root.right());
- _print(tf, root.left());
++ _print(tf, root.right());
++ _print(tf, root.left());
}
else
{
tf.append("(");
- _print(tf, (SequenceNode) root.right());
- _print(tf, root.right());
++ _print(tf, root.right());
if (root.left() != null)
{
tf.append(",");
}
- _print(tf, (SequenceNode) root.left());
- _print(tf, root.left());
++ _print(tf, root.left());
tf.append(")" + printRootField(root));
}
}
{
if (c.isDummy())
{
- _print(tf, (SequenceNode) c.left());
- _print(tf, c.left());
++ _print(tf, c.left());
if (c.left() != null)
{
tf.append(",");
}
- _print(tf, (SequenceNode) c.right());
- _print(tf, c.right());
++ _print(tf, c.right());
}
else
{
tf.append("(");
- _print(tf, (SequenceNode) c.right());
- _print(tf, c.right());
++ _print(tf, c.right());
if (c.left() != null)
{
tf.append(",");
}
- _print(tf, (SequenceNode) c.left());
- _print(tf, c.left());
++ _print(tf, c.left());
tf.append(")" + printNodeField(c));
}
}
@Override
public String getAnnotDescr()
{
- return "Predicted Alignment Error for " + refSeq.getName();
- return "Predicted Alignment Error"+((refSeq==null) ? "" : (" for " + refSeq.getName()));
++ return "Predicted Alignment Error"
++ + ((refSeq == null) ? "" : (" for " + refSeq.getName()));
}
@Override
public String getAnnotLabel()
{
- StringBuilder label = new StringBuilder("pAE Matrix");
+ StringBuilder label = new StringBuilder("PAE Matrix");
- //if (this.getReferenceSeq() != null)
- //{
- // label.append(":").append(this.getReferenceSeq().getDisplayId(false));
- //}
+ // if (this.getReferenceSeq() != null)
++ // {
+ // label.append(":").append(this.getReferenceSeq().getDisplayId(false));
++ // }
return label.toString();
}
{
return length;
}
- List<BitSet> groups=null;
++
++ List<BitSet> groups = null;
++
+ @Override
+ public boolean hasGroups()
+ {
- return groups!=null;
++ return groups != null;
+ }
- String newick=null;
++
++ String newick = null;
++
+ @Override
+ public String getNewick()
+ {
+ return newick;
+ }
++
+ @Override
+ public boolean hasTree()
+ {
- return newick!=null && newick.length()>0;
++ return newick != null && newick.length() > 0;
+ }
++
+ boolean abs;
++
+ double thresh;
- String treeType=null;
- public void makeGroups(float thresh,boolean abs)
++
++ String treeType = null;
++
++ public void makeGroups(float thresh, boolean abs)
+ {
- AverageDistanceEngine clusterer = new AverageDistanceEngine(null, null, this);
++ AverageDistanceEngine clusterer = new AverageDistanceEngine(null, null,
++ this);
+ double height = clusterer.findHeight(clusterer.getTopNode());
- newick = new jalview.io.NewickFile(clusterer.getTopNode(),false,true).print();
++ newick = new jalview.io.NewickFile(clusterer.getTopNode(), false, true)
++ .print();
+ treeType = "UPGMA";
- Console.trace("Newick string\n"+newick);
++ Console.trace("Newick string\n" + newick);
+
+ List<BinaryNode> nodegroups;
+ if (abs ? height > thresh : 0 < thresh && thresh < 1)
+ {
+ float cut = abs ? (float) (thresh / height) : thresh;
- Console.debug("Threshold "+cut+" for height="+height);
++ Console.debug("Threshold " + cut + " for height=" + height);
+
+ nodegroups = clusterer.groupNodes(cut);
+ }
+ else
+ {
+ nodegroups = new ArrayList<BinaryNode>();
+ nodegroups.add(clusterer.getTopNode());
+ }
- this.abs=abs;
- this.thresh=thresh;
++ this.abs = abs;
++ this.thresh = thresh;
+ groups = new ArrayList<>();
- for (BinaryNode root:nodegroups)
++ for (BinaryNode root : nodegroups)
+ {
- BitSet gpset=new BitSet();
- for (BinaryNode leaf:clusterer.findLeaves(root))
++ BitSet gpset = new BitSet();
++ for (BinaryNode leaf : clusterer.findLeaves(root))
+ {
- gpset.set((Integer)leaf.element());
++ gpset.set((Integer) leaf.element());
+ }
+ groups.add(gpset);
+ }
+ }
++
+ @Override
+ public void updateGroups(List<BitSet> colGroups)
+ {
- if (colGroups!=null)
++ if (colGroups != null)
+ {
- groups=colGroups;
- }
++ groups = colGroups;
++ }
+ }
++
+ @Override
+ public BitSet getGroupsFor(int column)
+ {
- for (BitSet gp:groups) {
++ for (BitSet gp : groups)
++ {
+ if (gp.get(column))
+ {
+ return gp;
+ }
+ }
+ return ContactMatrixI.super.getGroupsFor(column);
+ }
+
- HashMap<BitSet,Color> colorMap = new HashMap<>();
- @Override
++ HashMap<BitSet, Color> colorMap = new HashMap<>();
++
++ @Override
+ public Color getColourForGroup(BitSet bs)
+ {
- if (bs==null) {
++ if (bs == null)
++ {
+ return Color.white;
+ }
- Color groupCol=colorMap.get(bs);
- if (groupCol==null)
++ Color groupCol = colorMap.get(bs);
++ if (groupCol == null)
+ {
+ return Color.white;
+ }
+ return groupCol;
+ }
- @Override
- public void setColorForGroup(BitSet bs,Color color)
++
++ @Override
++ public void setColorForGroup(BitSet bs, Color color)
+ {
- colorMap.put(bs,color);
++ colorMap.put(bs, color);
+ }
++
+ public void restoreGroups(List<BitSet> newgroups, String treeMethod,
+ String tree, double thresh2)
+ {
- treeType=treeMethod;
++ treeType = treeMethod;
+ groups = newgroups;
- thresh=thresh2;
- newick =tree;
-
++ thresh = thresh2;
++ newick = tree;
++
+ }
++
+ @Override
- public boolean hasCutHeight() {
- return groups!=null && thresh!=0;
++ public boolean hasCutHeight()
++ {
++ return groups != null && thresh != 0;
+ }
++
+ @Override
+ public double getCutHeight()
+ {
+ return thresh;
+ }
++
+ @Override
+ public String getTreeMethod()
+ {
+ return treeType;
+ }
}
}
ContactMatrixI matrix = new PAEContactMatrix(sequence,
(Map<String, Object>) paeDict);
+ ((PAEContactMatrix) matrix).makeGroups(5f, true);
AlignmentAnnotation cmannot = sequence.addContactList(matrix);
+ if (label != null)
+ cmannot.label = label;
pdbAlignment.addAnnotation(cmannot);
return true;
return false;
}
- ContactMatrixI matrix = new PAEContactMatrix(sm.getSequence(),
+ SequenceI seq = sm.getSequence();
+ Console.debug("##### SEQUENCE FOUND=" + seq.getName());
- Map<String, Object> paeObject = (Map<String, Object>) pae_obj;
-
- ContactMatrixI matrix = new PAEContactMatrix(seq, paeObject);
++ ContactMatrixI matrix = new PAEContactMatrix(seq,
+ (Map<String, Object>) pae_obj);
+ ((PAEContactMatrix) matrix).makeGroups(5f, true);
- AlignmentAnnotation cmannot = sm.getSequence().addContactList(matrix);
- sm.getSequence().addAlignmentAnnotation(cmannot);
+ AlignmentAnnotation cmannot = seq.addContactList(matrix);
- if (label != null)
- {
- cmannot.label = label;
- }
++ seq.addAlignmentAnnotation(cmannot);
+ // seq.addAlignmentAnnotation(cmannot);
return true;
}
}
PAEContactMatrix dummyMat = new PAEContactMatrix(sq, paevals);
String content = ContactMatrix.contactToFloatString(dummyMat);
- Assert.assertTrue(content.contains("\t1.")); // at least one element must be 1
- float[][] vals = ContactMatrix.fromFloatStringToContacts(content, sq.getLength(), sq.getLength());
- assertEquals(vals[3][4],paevals[3][4]);
+ Assert.assertTrue(content.contains("\t1.")); // at least one element must be
+ // 1
+ float[][] vals = ContactMatrix.fromFloatStringToContacts(content,
+ sq.getLength(), sq.getLength());
+ assertEquals(vals[3][4], paevals[3][4]);
-
+ dummyMat.makeGroups(0.5f, false);
+ Assert.assertNotSame(dummyMat.getNewick(), "");
AlignmentAnnotation paeCm = sq.addContactList(dummyMat);
al.addAnnotation(paeCm);
File tfile = File.createTempFile("testStoreAndRecoverPAEmatrix",
Assert.assertEquals(oldCM.getContactAt(j), newCM.getContactAt(j));
}
}
+ Assert.assertEquals(restoredMat.hasGroups(), dummyMat.hasGroups());
+ Assert.assertEquals(restoredMat.getGroups(), dummyMat.getGroups());
+ Assert.assertEquals(restoredMat.hasTree(), dummyMat.hasTree());
- Assert.assertEquals( restoredMat.getNewick(),dummyMat.getNewick());
-
-
++ Assert.assertEquals(restoredMat.getNewick(), dummyMat.getNewick());
+
}
}