X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fuk%2Fac%2Fvamsas%2Fobjects%2Futils%2Ftrees%2FNewickFile.java;h=d38c99aa381db696c3fbfcb9c7f63982e60638ed;hb=844ccad5a3fcbedec17b2af66d460f31abc7cff1;hp=d6f5f5719634d1216e0bafb27320ff204e6bfad3;hpb=6f33f705957d674dc2ab6c994a6ea87f7a91f40f;p=vamsas.git diff --git a/src/uk/ac/vamsas/objects/utils/trees/NewickFile.java b/src/uk/ac/vamsas/objects/utils/trees/NewickFile.java index d6f5f57..d38c99a 100644 --- a/src/uk/ac/vamsas/objects/utils/trees/NewickFile.java +++ b/src/uk/ac/vamsas/objects/utils/trees/NewickFile.java @@ -1,24 +1,24 @@ /* - * originally from + * This file is part of the Vamsas Client version 0.1. + * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, + * Andrew Waterhouse and Dominik Lindner. * - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 AM Waterhouse, J Procter, 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 program is distributed in the hope that it will be useful, + * Earlier versions have also been incorporated into Jalview version 2.4 + * since 2008, and TOPALi version 2 since 2007. + * + * The Vamsas Client is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Vamsas Client 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the Vamsas Client. If not, see . */ - // NewickFile.java // Tree I/O // http://evolution.genetics.washington.edu/phylip/newick_doc.html @@ -222,9 +222,9 @@ public class NewickFile { } /** - * call this to convert the newick string into a binary node linked tree - * Note: this is automatically called by the constructors, so you normally - * wouldn't need to use this. + * call this to convert the newick string into a binary node linked tree Note: + * this is automatically called by the constructors, so you normally wouldn't + * need to use this. * * @throws IOException * if the newick string cannot be parsed. @@ -271,9 +271,9 @@ public class NewickFile { Matcher mjsyms = majorsyms.matcher(nf); char schar; - int nextcp=0; + int nextcp = 0; int ncp = cp; - while (mjsyms.find(cp) && (Error == null)) { + while (mjsyms.find(cp) && (Error == null)) { int fcp = mjsyms.start(); switch (schar = nf.charAt(fcp)) { @@ -339,29 +339,32 @@ public class NewickFile { "Wayward semicolon (depth=" + d + ")", 7, fcp, nf); } - // Skip Comment or structured/extended NH format info + // Skip Comment or structured/extended NH format info if (schar == '[') { - if ((nextcp=nf.indexOf(']', fcp)) > -1) { + if ((nextcp = nf.indexOf(']', fcp)) > -1) { // verified that comment is properly terminated. // now skip the comment field nextcp++; - break; // go and search for the next node separator, leaving ncp at beginning of node info + break; // go and search for the next node separator, leaving ncp at + // beginning of node info } else { Error = ErrorStringrange(Error, "Unterminated comment", 3, fcp, nf); nextcp = 0; break; } } - - // Parse simpler field strings from substring between ncp and node separator + + // Parse simpler field strings from substring between ncp and node + // separator String fstring = nf.substring(ncp, fcp); // extract any comments from the nodeinfo. - while (fstring.indexOf(']')>-1) - { - int cstart=fstring.indexOf('['); - int cend=fstring.indexOf(']'); - String comment = fstring.substring(cstart+1,cend); // TODO: put this somewhere ? - fstring = fstring.substring(0, cstart)+fstring.substring(cend+1); + while (fstring.indexOf(']') > -1) { + int cstart = fstring.indexOf('['); + int cend = fstring.indexOf(']'); + String comment = fstring.substring(cstart + 1, cend); // TODO: put + // this + // somewhere ? + fstring = fstring.substring(0, cstart) + fstring.substring(cend + 1); } Matcher uqnodename = Pattern.compile("^([^' :;\\](),]+).*").matcher( fstring); @@ -384,14 +387,12 @@ public class NewickFile { Matcher nbootstrap = Pattern.compile("\\s*([+0-9]+)\\s*:.*").matcher( fstring); - if (nbootstrap.matches()) - { - if (nodename!=null && nbootstrap.group(1).equals(nodename)) - { - nodename=null; // empty nodename - only bootstrap value + if (nbootstrap.matches()) { + if (nodename != null && nbootstrap.group(1).equals(nodename)) { + nodename = null; // empty nodename - only bootstrap value } - if ((nodename==null || nodename.length()==0) || nbootstrap.start(1)>=uqnodename.end(1)) - { + if ((nodename == null || nodename.length() == 0) + || nbootstrap.start(1) >= uqnodename.end(1)) { try { bootstrap = (new Integer(nbootstrap.group(1))).intValue(); HasBootstrap = true; @@ -401,7 +402,7 @@ public class NewickFile { } } } - + Matcher ndist = Pattern.compile(".*:([-0-9Ee.+]+)").matcher(fstring); boolean nodehasdistance = false; @@ -515,7 +516,8 @@ public class NewickFile { public uk.ac.vamsas.objects.core.Treenode[] matchTreeNodeNames( String[] names, Vobject[] boundObjects) { // todo! - // also - need to reconstruct a names object id mapping (or BInaryNode) mapping for the parsed tree file + // also - need to reconstruct a names object id mapping (or BInaryNode) + // mapping for the parsed tree file return null; } @@ -641,7 +643,7 @@ public class NewickFile { private String nodeName(String name) { if (NodeSafeName[0].matcher(name).find()) { return QuoteChar + NodeSafeName[1].matcher(name).replaceAll("''") - + QuoteChar; // quite + + QuoteChar; // quite } else { return NodeSafeName[2].matcher(name).replaceAll("_"); // whitespace } @@ -656,10 +658,12 @@ public class NewickFile { * @return DOCUMENT ME! */ private String printNodeField(SequenceNode c) { - return //c.getNewickNodeName() + return // c.getNewickNodeName() ((c.getName() == null) ? "" : nodeName(c.getName())) - + ((HasBootstrap) ? ((c.getBootstrap() > -1) ? (((c.getName()==null) ? " " : "") + c.getBootstrap()) - : "") : "") + ((HasDistances) ? (":" + c.dist) : ""); + + ((HasBootstrap) ? ((c.getBootstrap() > -1) ? (((c.getName() == null) ? " " + : "") + c.getBootstrap()) + : "") + : "") + ((HasDistances) ? (":" + c.dist) : ""); } /** @@ -673,9 +677,10 @@ public class NewickFile { private String printRootField(SequenceNode root) { return (printRootInfo) ? (((root.getName() == null) ? "" : nodeName(root .getName())) - + ((HasBootstrap) ? ((root.getBootstrap() > -1) ? ((root.getName()!=null ? " " : "") + root - .getBootstrap()) : "") : "") + ((RootHasDistance) ? (":" + root.dist) - : "")) + + ((HasBootstrap) ? ((root.getBootstrap() > -1) ? ((root.getName() != null ? " " + : "") + root.getBootstrap()) + : "") + : "") + ((RootHasDistance) ? (":" + root.dist) : "")) : ""; } @@ -790,10 +795,12 @@ public class NewickFile { /** * Search for leaf nodes. - * - * @param node root node to search from - * @param leaves Vector of leaves to add leaf node objects too. - * + * + * @param node + * root node to search from + * @param leaves + * Vector of leaves to add leaf node objects too. + * * @return Vector of leaf nodes on binary tree */ public Vector findLeaves(SequenceNode node, Vector leaves) { @@ -801,16 +808,17 @@ public class NewickFile { return leaves; } - if ((node.left() == null) && (node.right() == null)) // Interior node detection + if ((node.left() == null) && (node.right() == null)) // Interior node + // detection { leaves.addElement(node); return leaves; } else { - /* TODO: Identify internal nodes... if (node.isSequenceLabel()) - { - leaves.addElement(node); - }*/ + /* + * TODO: Identify internal nodes... if (node.isSequenceLabel()) { + * leaves.addElement(node); } + */ findLeaves((SequenceNode) node.left(), leaves); findLeaves((SequenceNode) node.right(), leaves); } @@ -819,7 +827,9 @@ public class NewickFile { } /** - * make tree node vector from a newick tree structure with associated vamsas objects + * make tree node vector from a newick tree structure with associated vamsas + * objects + * * @param ntree * @return Treenode definitions for nodes with associated objects */ @@ -828,8 +838,10 @@ public class NewickFile { } /** - * make treenode vector for a parsed tree with/out leaf node associations - * @param ignoreplaceholders if true means only associated nodes are returned + * make treenode vector for a parsed tree with/out leaf node associations + * + * @param ignoreplaceholders + * if true means only associated nodes are returned * @return treenode vector for associated or all leaves */ public Treenode[] makeTreeNodes(boolean ignoreplaceholders) { @@ -915,11 +927,14 @@ public class NewickFile { } /** - * - * re-decorate the newick node representation with the VorbaId of an object mapped by its corresponding TreeNode. - * Note: this only takes the first object in the first set of references. + * + * re-decorate the newick node representation with the VorbaId of an object + * mapped by its corresponding TreeNode. Note: this only takes the first + * object in the first set of references. + * * @param tn - * @return vector of mappings { treenode, SequenceNode, Vobject for VorbaId on sequence node } + * @return vector of mappings { treenode, SequenceNode, Vobject for VorbaId on + * sequence node } */ public Vector attachTreeMap(Treenode[] tn) { if (root != null || tn == null)