forester v1.3

forester.tree
Class TreeHelper

java.lang.Object
  |
  +--forester.tree.TreeHelper

public class TreeHelper
extends java.lang.Object

Version:
1.05 -- last modified: 07/17/00
Author:
Christian M. Zmasek

Constructor Summary
TreeHelper()
           
 
Method Summary
static boolean checkCommas(java.lang.String nh_string)
          Checks the commas of a String nh_string potentially representing a Tree in NH or NHX format.
static java.lang.String checkForUnnessaryParentheses(java.lang.String nh_string, int openparantheses)
          Checks for unnessary parentheses in a String nh_string potentially representing a Tree in NH or NHX format.
static java.lang.String checkNHformat(java.lang.String s)
          Checks a String s potentially representing a Tree in NH or NHX format.
static void cleanSpeciesNamesInExtNodes(Tree tree)
          For each external node of Tree tree: Cleans up SWISS-PROT species names: It removes everything (including ) after a potential "/", "_", "-", "\", ";", ".".
static int countAndCheckParantheses(java.lang.String nh_string)
          Checks whether number of "(" equals number of ")" in String nh_string potentially representing a Tree in NH or NHX format.
static Tree createBalancedTree(int i)
          Creates a completely balanced Tree with 2^i external nodes.
static Tree createUnbalancedTree(int i)
          Creates a completely unbalanced Tree with i external nodes.
static void extractSpeciesNameFromSPseqName(Tree tree)
          For each node of Tree tree: Extracts the species name (as SWISS-PROT abbreviation) from the sequence name (if SWISS-PROT names are used) and writes it to the species name field if this is empty.
static void intervalNumberSpecies(Tree t, int i)
          Sets the species name of the external Nodes of Tree t to 1, 1+i, 2, 2+i, 3, 3+i, ....
static boolean isEmpty(java.lang.StringBuffer sb)
          Checks whether StringBuffer sb is empty.
static void numberSpeciesInDescOrder(Tree t)
          Sets the species namea of the external Nodes of Tree t to descending integers, ending with 1.
static void numberSpeciesInOrder(Tree t)
          Sets the species namea of the external Nodes of Tree t to ascending integers, starting with 1.
static void randomizeSpecies(int min, int max, Tree t)
          Sets the species names of the external Nodes of Tree t to a random positive integer number between (and including) min and max.
static Tree[] readMultipleNHTrees(java.io.File multipletreefile)
          Reads in multiple Trees from a File multipletreefile, containing Tree descriptions in New Hampshire (NH) or New Hampshire X (NHX) format separated by semicolons followed by a newline.
static Tree readNHtree(java.io.File f, boolean check)
          Reads a Tree in NH or NHX format from a textfile f.
static Tree readNHtree(java.net.URL url, boolean check)
          Reads a Tree in NH or NHX format from a URL url.
static java.lang.StringBuffer removeCstyleComments(java.lang.StringBuffer sb)
          Removes C-style comments from StringBuffer sb.
static java.lang.StringBuffer removeWhiteSpace(java.lang.StringBuffer sb)
          Removes all white space from StringBuffer sb.
static void writeNHtree(Tree t, java.io.File f, boolean nhx, boolean overwrite1, boolean overwrite2)
          Writes a Tree t to a textfile f.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeHelper

public TreeHelper()
Method Detail

readNHtree

public static Tree readNHtree(java.io.File f,
                              boolean check)
                       throws java.lang.Exception
Reads a Tree in NH or NHX format from a textfile f. If boolean check is true it will validate the correctness of the NH/NHX format (slow).

readNHtree

public static Tree readNHtree(java.net.URL url,
                              boolean check)
                       throws java.lang.Exception
Reads a Tree in NH or NHX format from a URL url. If boolean check is true it will validate the correctness of the NH/NHX format (slow).

writeNHtree

public static void writeNHtree(Tree t,
                               java.io.File f,
                               boolean nhx,
                               boolean overwrite1,
                               boolean overwrite2)
                        throws java.lang.Exception
Writes a Tree t to a textfile f. Set boolean nhx to true to write Tree in New Hampshire X (NHX) format. Set boolean nhx to false to write Tree in New Hampshire (NH) format. Both overwrite1 and overwrite2 need to be true to allow for overwriting.

readMultipleNHTrees

public static Tree[] readMultipleNHTrees(java.io.File multipletreefile)
                                  throws java.lang.Exception
Reads in multiple Trees from a File multipletreefile, containing Tree descriptions in New Hampshire (NH) or New Hampshire X (NHX) format separated by semicolons followed by a newline. Returns a Tree array.
Parameters:
multipletreefile - Textfile containg Tree descriptions in NH or NHX format separated by semicolons followd by a newline
Returns:
array of Trees

extractSpeciesNameFromSPseqName

public static void extractSpeciesNameFromSPseqName(Tree tree)
For each node of Tree tree: Extracts the species name (as SWISS-PROT abbreviation) from the sequence name (if SWISS-PROT names are used) and writes it to the species name field if this is empty. It extracts no more than five letters after a "_" (which must be present) and before potential "/", "_", "-", "\", ";", ".".

cleanSpeciesNamesInExtNodes

public static void cleanSpeciesNamesInExtNodes(Tree tree)
For each external node of Tree tree: Cleans up SWISS-PROT species names: It removes everything (including ) after a potential "/", "_", "-", "\", ";", ".". It removes everything which comes after the fifth letter and it changes everything to upper case.

checkNHformat

public static java.lang.String checkNHformat(java.lang.String s)
Checks a String s potentially representing a Tree in NH or NHX format. Is quite slow.
Returns:
empty String if no error detected, error message for faulty string

isEmpty

public static boolean isEmpty(java.lang.StringBuffer sb)
Checks whether StringBuffer sb is empty.
Returns:
true if empty, false for not empty StringBuffer

removeWhiteSpace

public static java.lang.StringBuffer removeWhiteSpace(java.lang.StringBuffer sb)
Removes all white space from StringBuffer sb.
Returns:
StringBuffer with white space removed

removeCstyleComments

public static java.lang.StringBuffer removeCstyleComments(java.lang.StringBuffer sb)
Removes C-style comments from StringBuffer sb.
Returns:
StringBuffer with C-style comments removed

countAndCheckParantheses

public static int countAndCheckParantheses(java.lang.String nh_string)
Checks whether number of "(" equals number of ")" in String nh_string potentially representing a Tree in NH or NHX format.
Returns:
total number of open parantheses if no error detected, -1 for faulty string

checkCommas

public static boolean checkCommas(java.lang.String nh_string)
Checks the commas of a String nh_string potentially representing a Tree in NH or NHX format. Checks for "()", "(" not preceded by a "(" or ",", ",,", "(,", and ",)".
Returns:
true if no error detected, false for faulty string

checkForUnnessaryParentheses

public static java.lang.String checkForUnnessaryParentheses(java.lang.String nh_string,
                                                            int openparantheses)
Checks for unnessary parentheses in a String nh_string potentially representing a Tree in NH or NHX format. Such as: (((X,Y)),Z)
Parameters:
nh_string - NH or NHX
openparantheses - total number of open parantheses (int)
Returns:
empty String if no error detected, error message for faulty string

randomizeSpecies

public static void randomizeSpecies(int min,
                                    int max,
                                    Tree t)
Sets the species names of the external Nodes of Tree t to a random positive integer number between (and including) min and max.
Parameters:
t - whose external species names are to be randomized
min - minimal value for random numbers
max - maximum value for random numbers

numberSpeciesInOrder

public static void numberSpeciesInOrder(Tree t)
Sets the species namea of the external Nodes of Tree t to ascending integers, starting with 1.

numberSpeciesInDescOrder

public static void numberSpeciesInDescOrder(Tree t)
Sets the species namea of the external Nodes of Tree t to descending integers, ending with 1.

intervalNumberSpecies

public static void intervalNumberSpecies(Tree t,
                                         int i)
Sets the species name of the external Nodes of Tree t to 1, 1+i, 2, 2+i, 3, 3+i, .... Examples: i=2: 1, 3, 2, 4 i=4: 1, 5, 2, 6, 3, 7, 4, 8 i=8: 1, 9, 2, 10, 3, 11, 4, 12, ...

createBalancedTree

public static Tree createBalancedTree(int i)
Creates a completely balanced Tree with 2^i external nodes.
Returns:
a newly created balanced Tree

createUnbalancedTree

public static Tree createUnbalancedTree(int i)
Creates a completely unbalanced Tree with i external nodes.
Returns:
a newly created unbalanced Tree

forester v1.3