import jalview.schemes.ResidueProperties;\r
import java.util.*;\r
\r
+import jalview.io.NewickFile;\r
+\r
public class NJTree {\r
\r
Vector cluster;\r
public NJTree(SequenceNode node) {\r
top = node;\r
maxheight = findHeight(top);\r
+\r
+ }\r
+ // Private SequenceID class to do fuzzy .equals() method for Hashtable.\r
+\r
+ private class SeqIdname {\r
+ String id;\r
+\r
+ SeqIdname(String s) {\r
+ id = new String(s);\r
+ }\r
+ public int hashCode() {\r
+ return (id.substring(0,4).hashCode());\r
+ }\r
+ public boolean equals(Object s) {\r
+ if (s instanceof SeqIdname) {\r
+ return this.equals((SeqIdname) s);\r
+ } else {\r
+ if (s instanceof String) {\r
+ return this.equals((String) s);\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+\r
+\r
+ public boolean equals(SeqIdname s) {\r
+ if (id.startsWith(s.id) || s.id.startsWith(id)) {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ public boolean equals(String s) {\r
+ if (id.startsWith(s) || s.startsWith(id)) {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public NJTree(SequenceI[] seqs, NewickFile treefile) {\r
+ top = treefile.getTree();\r
+ maxheight = findHeight(top);\r
+ Hashtable names = new Hashtable();\r
+ for (int i = 0; i < seqs.length; i++)\r
+ {\r
+ names.put(new SeqIdname(seqs[i].getDisplayId()), seqs[i]);\r
+ }\r
+ Vector leaves = new Vector();\r
+ findLeaves(top, leaves);\r
+ int i = 0;\r
+ int namesleft = seqs.length;\r
+ SequenceNode j;\r
+ SeqIdname nam;\r
+ while (i < leaves.size())\r
+ {\r
+ j = (SequenceNode) leaves.elementAt(i++);\r
+ nam = new SeqIdname(j.getName());\r
+ if ((namesleft>-1)\r
+ && names.containsKey(nam))\r
+ {\r
+ j.setElement(names.get(nam));\r
+ namesleft--;\r
+ } else {\r
+ j.setElement(new Sequence(nam.id, "THISISAPLACEHLDER"));\r
+ }\r
+ }\r
}\r
\r
public NJTree(SequenceI[] sequence,int start, int end) {\r