X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FNJTree.java;h=c053cb38743681188e4080b0edfa299d4eb38d28;hb=153dd62dc91da13ae732600e6ea55ddbe15eab39;hp=2fe85977b28d1ba9f953694a11c27780abd2ed4c;hpb=6cfa5983e39db21e566e8662722d231f5391e057;p=jalview.git diff --git a/src/jalview/analysis/NJTree.java b/src/jalview/analysis/NJTree.java index 2fe8597..c053cb3 100755 --- a/src/jalview/analysis/NJTree.java +++ b/src/jalview/analysis/NJTree.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1) - * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle * - * This program 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 2 - * of the License, or (at your option) any later version. + * This file is part of Jalview. * - * This program 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. + * 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. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * 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 . */ package jalview.analysis; @@ -90,11 +89,11 @@ public class NJTree * and original alignment data represented by Cigar strings. * * @param seqs - * SequenceI[] + * SequenceI[] * @param odata - * Cigar[] + * Cigar[] * @param treefile - * NewickFile + * NewickFile */ public NJTree(SequenceI[] seqs, AlignmentView odata, NewickFile treefile) { @@ -115,9 +114,9 @@ public class NJTree * Creates a new NJTree object from a tree from an external source * * @param seqs - * SequenceI which should be associated with leafs of treefile + * SequenceI which should be associated with leafs of treefile * @param treefile - * A parsed tree + * A parsed tree */ public NJTree(SequenceI[] seqs, NewickFile treefile) { @@ -196,15 +195,15 @@ public class NJTree * Creates a new NJTree object. * * @param sequence - * DOCUMENT ME! + * DOCUMENT ME! * @param type - * DOCUMENT ME! + * DOCUMENT ME! * @param pwtype - * DOCUMENT ME! + * DOCUMENT ME! * @param start - * DOCUMENT ME! + * DOCUMENT ME! * @param end - * DOCUMENT ME! + * DOCUMENT ME! */ public NJTree(SequenceI[] sequence, AlignmentView seqData, String type, String pwtype, int start, int end) @@ -228,7 +227,7 @@ public class NJTree sdata.addOperation(CigarArray.M, end - start + 1); this.seqData = new AlignmentView(sdata, start); } -// System.err.println("Made seqData");// dbg + // System.err.println("Made seqData");// dbg if (!(type.equals("NJ"))) { type = "AV"; @@ -256,15 +255,15 @@ public class NJTree distance = findDistances(this.seqData .getSequenceStrings(Comparison.GapChars.charAt(0))); -// System.err.println("Made distances");// dbg + // System.err.println("Made distances");// dbg makeLeaves(); -// System.err.println("Made leaves");// dbg - + // System.err.println("Made leaves");// dbg + noClus = cluster.size(); cluster(); -// System.err.println("Made clusters");// dbg - + // System.err.println("Made clusters");// dbg + } /** @@ -284,7 +283,7 @@ public class NJTree * used when the alignment associated to a tree has changed. * * @param alignment - * Vector + * Vector */ public void UpdatePlaceHolders(Vector alignment) { @@ -406,9 +405,9 @@ public class NJTree * DOCUMENT ME! * * @param i - * DOCUMENT ME! + * DOCUMENT ME! * @param j - * DOCUMENT ME! + * DOCUMENT ME! * * @return DOCUMENT ME! */ @@ -474,11 +473,11 @@ public class NJTree * DOCUMENT ME! * * @param tmpi - * DOCUMENT ME! + * DOCUMENT ME! * @param tmpj - * DOCUMENT ME! + * DOCUMENT ME! * @param dist - * DOCUMENT ME! + * DOCUMENT ME! */ public void findNewNJDistances(SequenceNode tmpi, SequenceNode tmpj, float dist) @@ -502,11 +501,11 @@ public class NJTree * DOCUMENT ME! * * @param tmpi - * DOCUMENT ME! + * DOCUMENT ME! * @param tmpj - * DOCUMENT ME! + * DOCUMENT ME! * @param dist - * DOCUMENT ME! + * DOCUMENT ME! */ public void findNewDistances(SequenceNode tmpi, SequenceNode tmpj, float dist) @@ -537,9 +536,9 @@ public class NJTree * DOCUMENT ME! * * @param i - * DOCUMENT ME! + * DOCUMENT ME! * @param j - * DOCUMENT ME! + * DOCUMENT ME! */ public void findClusterDistance(int i, int j) { @@ -573,9 +572,9 @@ public class NJTree * DOCUMENT ME! * * @param i - * DOCUMENT ME! + * DOCUMENT ME! * @param j - * DOCUMENT ME! + * DOCUMENT ME! */ public void findClusterNJDistance(int i, int j) { @@ -606,9 +605,9 @@ public class NJTree * DOCUMENT ME! * * @param i - * DOCUMENT ME! + * DOCUMENT ME! * @param j - * DOCUMENT ME! + * DOCUMENT ME! * * @return DOCUMENT ME! */ @@ -775,15 +774,16 @@ public class NJTree /* * else if (pwtype.equals("SW")) { float max = -1; * - * for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++) { - * AlignSeq as = new AlignSeq(sequence[i], sequence[j], "pep"); + * for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++) + * { AlignSeq as = new AlignSeq(sequence[i], sequence[j], "pep"); * as.calcScoreMatrix(); as.traceAlignment(); as.printAlignment(System.out); * distance[i][j] = (float) as.maxscore; * * if (max < distance[i][j]) { max = distance[i][j]; } } } * - * for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++) { - * distance[i][j] = max - distance[i][j]; distance[j][i] = distance[i][j]; } } }/ + * for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++) + * { distance[i][j] = max - distance[i][j]; distance[j][i] = distance[i][j]; + * } } }/ */ } @@ -814,9 +814,9 @@ public class NJTree * Search for leaf nodes. * * @param node - * root node to search from + * root node to search from * @param leaves - * Vector of leaves to add leaf node objects too. + * Vector of leaves to add leaf node objects too. * * @return Vector of leaf nodes on binary tree */ @@ -828,7 +828,7 @@ public class NJTree } if ((node.left() == null) && (node.right() == null)) // Interior node - // detection + // detection { leaves.addElement(node); @@ -851,9 +851,9 @@ public class NJTree * Find the leaf node with a particular ycount * * @param node - * initial point on tree to search from + * initial point on tree to search from * @param count - * value to search for + * value to search for * * @return null or the node with ycound=count */ @@ -866,7 +866,6 @@ public class NJTree /* * #see findLeaf(SequenceNode node, count) - * */ public Object _findLeaf(SequenceNode node, int count) { @@ -894,7 +893,7 @@ public class NJTree * printNode is mainly for debugging purposes. * * @param node - * SequenceNode + * SequenceNode */ public void printNode(SequenceNode node) { @@ -922,7 +921,7 @@ public class NJTree * DOCUMENT ME! * * @param node - * DOCUMENT ME! + * DOCUMENT ME! */ public void findMaxDist(SequenceNode node) { @@ -972,9 +971,9 @@ public class NJTree * DOCUMENT ME! * * @param node - * DOCUMENT ME! + * DOCUMENT ME! * @param threshold - * DOCUMENT ME! + * DOCUMENT ME! */ public void groupNodes(SequenceNode node, float threshold) { @@ -998,7 +997,7 @@ public class NJTree * DOCUMENT ME! * * @param node - * DOCUMENT ME! + * DOCUMENT ME! * * @return DOCUMENT ME! */ @@ -1119,7 +1118,7 @@ public class NJTree * DOCUMENT ME! * * @param node - * DOCUMENT ME! + * DOCUMENT ME! */ public void printN(SequenceNode node) { @@ -1148,28 +1147,30 @@ public class NJTree * DOCUMENT ME! * * @param node - * DOCUMENT ME! + * DOCUMENT ME! */ public void reCount(SequenceNode node) { ycount = 0; - _lycount=0; -// _lylimit = this.node.size(); + _lycount = 0; + // _lylimit = this.node.size(); _reCount(node); } - private long _lycount=0,_lylimit=0; + + private long _lycount = 0, _lylimit = 0; + /** * DOCUMENT ME! * * @param node - * DOCUMENT ME! + * DOCUMENT ME! */ public void _reCount(SequenceNode node) { -// if (_lycount<_lylimit) -// { -// System.err.println("Warning: depth of _recount greater than number of nodes."); -// } + // if (_lycount<_lylimit) + // { + // System.err.println("Warning: depth of _recount greater than number of nodes."); + // } if (node == null) { return; @@ -1178,7 +1179,7 @@ public class NJTree if ((node.left() != null) && (node.right() != null)) { - + _reCount((SequenceNode) node.left()); _reCount((SequenceNode) node.right()); @@ -1200,7 +1201,7 @@ public class NJTree * DOCUMENT ME! * * @param node - * DOCUMENT ME! + * DOCUMENT ME! */ public void swapNodes(SequenceNode node) { @@ -1219,9 +1220,9 @@ public class NJTree * DOCUMENT ME! * * @param node - * DOCUMENT ME! + * DOCUMENT ME! * @param dir - * DOCUMENT ME! + * DOCUMENT ME! */ public void changeDirection(SequenceNode node, SequenceNode dir) { @@ -1320,14 +1321,16 @@ public class NJTree { return hasRootDistance; } + /** * apply the given transform to all the nodes in the tree. + * * @param nodeTransformI */ public void applyToNodes(NodeTransformI nodeTransformI) { - for (Enumeration nodes = node.elements(); nodes.hasMoreElements(); - nodeTransformI.transform((BinaryNode)nodes.nextElement())) + for (Enumeration nodes = node.elements(); nodes.hasMoreElements(); nodeTransformI + .transform((BinaryNode) nodes.nextElement())) ; } } @@ -1346,7 +1349,7 @@ class Cluster * Creates a new Cluster object. * * @param value - * DOCUMENT ME! + * DOCUMENT ME! */ public Cluster(int[] value) {