FORESTER 1.8

forester.tree
Class TreeHelper

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

public class TreeHelper
extends java.lang.Object

Version:
1.110 -- last modified: 07/03/01
Author:
Christian M. Zmasek

Constructor Summary
TreeHelper()
           
 
Method Summary
static double[] calculateMeanBoostrapValue(Tree t)
          Calculates the mean and standard deviation of all nodes of Tree t which have a boostrap values zero or more.
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 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 createUnbalancedTree(int i)
          Creates a completely unbalanced Tree with i external nodes.
static void extractSpeciesNameFromSeqName(Tree tree)
          Copies the content of the sequence name field to the species name field (if empty - does not overwrite!) for each node of Tree tree.
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.String s)
          Checks whether String s 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)
          Reads a Tree in NH or NHX format from a textfile f.
static Tree readNHtree(java.net.URL url)
          Reads a Tree in NH or NHX format from a URL url.
static java.lang.String removeComments(java.lang.String s)
          Removes everythin between '[' and ']' -- except between '[&&NHX' and ']'.
static java.lang.String removeWhiteSpace(java.lang.String s)
          Removes all white space from String s.
static int roundToInt(double d)
          Rounds d to an int.
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

roundToInt

public static int roundToInt(double d)
Rounds d to an int.

readNHtree

public static Tree readNHtree(java.io.File f)
                       throws java.lang.Exception
Reads a Tree in NH or NHX format from a textfile f.

readNHtree

public static Tree readNHtree(java.net.URL url)
                       throws java.lang.Exception
Reads a Tree in NH or NHX format from a URL url.

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 array of Trees.
Parameters:
multipletreefile - Textfile containg Tree descriptions in NH or NHX format separated by semicolons followd by a newline
Returns:
Tree[]

extractSpeciesNameFromSeqName

public static void extractSpeciesNameFromSeqName(Tree tree)
Copies the content of the sequence name field to the species name field (if empty - does not overwrite!) for each node of Tree tree.

If the sequence name appears to be (contain) a SWISS-PROT name, the species name is extracted in the following manner: It extracts all characters after the last<\b> "_" and before any potential "/", "-", "\", ";", ".".

If the sequence name appears not to be (contain) a SWISS-PROT, name it is just copied unchanged to the species name field. (last modified: 03/01/01)

Parameters:
tree - the Tree for which species names are to be extracted/copied

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.

calculateMeanBoostrapValue

public static double[] calculateMeanBoostrapValue(Tree t)
Calculates the mean and standard deviation of all nodes of Tree t which have a boostrap values zero or more. Returns null in case of failure (e.g t has no bootstrap values, or just one).

(Last modified: 05/28/01)

Parameters:
t - reference to a tree with bootstrap values
Returns:
Array of doubles, [0] is the mean, [1] the standard deviation

isEmpty

public static boolean isEmpty(java.lang.String s)
Checks whether String s is empty.
Returns:
true if empty, false otherwise

removeWhiteSpace

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

removeComments

public static java.lang.String removeComments(java.lang.String s)
Removes everythin between '[' and ']' -- except between '[&&NHX' and ']'.

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

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, ...

createUnbalancedTree

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

FORESTER 1.8