net.sourceforge.olduvai.treejuxtaposer
Class TreeParser

java.lang.Object
  extended by net.sourceforge.olduvai.treejuxtaposer.TreeParser

public class TreeParser
extends java.lang.Object

Author:
James Parses the newick portion of a file For nexus files, additional node-number mapping is needed to rename files Identification of a file as either newick or nexus determines contents

Field Summary
private static java.lang.String beginTag
          Begin tag.
private static char commentClose
          Nexus comment close.
private static char commentOpen
          Nexus comment open.
private static boolean debugOutput
          True: show debug output.
private static java.lang.String endTag
          End tag.
private static char equals
          Equality sign.
private  javax.swing.JProgressBar jpb
          Progress bar.
private static char lineTerminator
          Line (and tree information) termination.
private static java.lang.String nexusFileID
          Nexus file identifier.
private  java.util.Vector returnVector
          For returning results inside action listeners.
private  TreeNode rootNode
          Root node of the tree being parsed.
private  javax.swing.JList selection
          For listing the selected results from the list of Nexus tree names.
private  javax.swing.JFrame selectionFrame
          Frame for selecting Nexus trees from the full set.
private  java.io.StreamTokenizer tokenizer
           
private static java.lang.String treeID
          Tree ID.
private static java.lang.String treeSectionTag
          Tree section.
private static java.lang.String utreeID
          Tree ID (same or similar to treeID?).
 
Constructor Summary
TreeParser(java.io.BufferedReader b)
          Initializes parsing of a tree by creating a tokenizer and setting default properties (such as spacing, quoting characters).
 
Method Summary
 java.util.Vector chooseNames(java.util.ArrayList treeNames)
          Pops a dialog to select the trees to load from a nexus file.
 void debugOutput(java.lang.String s)
          Debug printout function.
 javax.swing.JProgressBar getProgressBar()
          Get the progress bar object.
private  void initNexusChooser()
          Layout and listeners for the nexus chooser.
 boolean isNexusFile(java.lang.String fileName)
          Guess the type of treeFile based on the presence of nexus identifiers.
static void main(java.lang.String[] args)
          Test application function.
private  void nexusCharacterTokenize()
          Tokenize the character section of a nexus file only.
static java.util.ArrayList nexusFileTreeNames(java.lang.String fileName)
          Parses names of trees in nexus file.
private  void nexusTaxaTokenize()
          Nexus taxa tokenizer, does nothing for now, but can be used later.
 java.util.ArrayList nexusTokenize(java.util.Vector treeNumbers, javax.swing.JProgressBar progressBar)
          Tokenize a nexus file, uses newick tokenizer after identifying the region with the tree information.
private  java.util.ArrayList nexusTreeTokenize(java.util.Vector treeNumbers)
          Tokenize the tree section of a nexus file only, uses newick tokenizer.
private  TreeNode popAndName(java.lang.String name, java.util.Stack nodeStack)
          Adds node at the top of the stack to the tree.
 Tree tokenize(long fileLength, java.lang.String streamName, javax.swing.JProgressBar progressBar)
          Newick tokenizer: converts a string (tree as a string) into a tree object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nexusFileID

private static final java.lang.String nexusFileID
Nexus file identifier. We look for this as the first token to identify a tree file as Nexus, or other.

See Also:
Constant Field Values

beginTag

private static final java.lang.String beginTag
Begin tag.

See Also:
Constant Field Values

endTag

private static final java.lang.String endTag
End tag.

See Also:
Constant Field Values

treeSectionTag

private static final java.lang.String treeSectionTag
Tree section.

See Also:
Constant Field Values

treeID

private static final java.lang.String treeID
Tree ID.

See Also:
Constant Field Values

utreeID

private static final java.lang.String utreeID
Tree ID (same or similar to treeID?).

See Also:
Constant Field Values

lineTerminator

private static final char lineTerminator
Line (and tree information) termination.

See Also:
Constant Field Values

equals

private static final char equals
Equality sign.

See Also:
Constant Field Values

commentOpen

private static final char commentOpen
Nexus comment open.

See Also:
Constant Field Values

commentClose

private static final char commentClose
Nexus comment close.

See Also:
Constant Field Values

debugOutput

private static boolean debugOutput
True: show debug output. False: suppress printing.


tokenizer

private java.io.StreamTokenizer tokenizer

rootNode

private TreeNode rootNode
Root node of the tree being parsed. Must be initialized outside the tokenizer.


jpb

private javax.swing.JProgressBar jpb
Progress bar.


selection

private javax.swing.JList selection
For listing the selected results from the list of Nexus tree names.


returnVector

private java.util.Vector returnVector
For returning results inside action listeners.


selectionFrame

private javax.swing.JFrame selectionFrame
Frame for selecting Nexus trees from the full set.

Constructor Detail

TreeParser

public TreeParser(java.io.BufferedReader b)
Initializes parsing of a tree by creating a tokenizer and setting default properties (such as spacing, quoting characters). tokenize(long, String, JProgressBar) is required to start the parsing.

Parameters:
b - Buffered reader that could start in the middle of a nexus file or the start of a newick file (basically the beginning of a newick tree, is run for each tree in a nexus file)
Method Detail

getProgressBar

public javax.swing.JProgressBar getProgressBar()
Get the progress bar object.

Returns:
The progress bar object.

isNexusFile

public boolean isNexusFile(java.lang.String fileName)
Guess the type of treeFile based on the presence of nexus identifiers.

Parameters:
fileName - The name of the file.
Returns:
true when file is nexus format, false if nexus strings weren't found.

nexusFileTreeNames

public static java.util.ArrayList nexusFileTreeNames(java.lang.String fileName)
Parses names of trees in nexus file.

Parameters:
fileName - Name of nexus file.
Returns:
List of all tree names found in nexus file

initNexusChooser

private void initNexusChooser()
Layout and listeners for the nexus chooser. Allows for the population of returnVector.


chooseNames

public java.util.Vector chooseNames(java.util.ArrayList treeNames)
Pops a dialog to select the trees to load from a nexus file. Also, wrapper for initNexusChooser() dialog.

Parameters:
treeNames - arraylist of tree names.
Returns:
vector List of integers that correspond to the trees to load; not using names since trees might have the same name?

debugOutput

public void debugOutput(java.lang.String s)
Debug printout function. Avoid using the system calls and use this, and set flag debugOutput depending on debugging or not.

Parameters:
s - Display the string, for debugging.

popAndName

private TreeNode popAndName(java.lang.String name,
                            java.util.Stack nodeStack)
Adds node at the top of the stack to the tree. TreeNode is already created based on Newick properties.

Parameters:
name - Name of the node.
nodeStack - Stack of nodes that haven't been added to the tree yet. Nodes are popped when they have names and all children are processed.
Returns:
Newly added treeNode linked into the tree.

tokenize

public Tree tokenize(long fileLength,
                     java.lang.String streamName,
                     javax.swing.JProgressBar progressBar)
Newick tokenizer: converts a string (tree as a string) into a tree object. The stream tokenizer should be initialized before calling this function.

Parameters:
fileLength - Length of the file, for progress bar movements. For nexus files, this would be the relative position of the next semicolon = the size of the tree in bytes.
streamName - Name of the tree or file that is being loaded. Nexus files have names ("tree = ((...));", newick trees are named by file name.
progressBar - Reference to a progress bar widgit, embedded perhaps in place of the new canvas for this tree. If this is null, create a new progress bar here.
Returns:
Tree parsed from the stream.

nexusTaxaTokenize

private void nexusTaxaTokenize()
Nexus taxa tokenizer, does nothing for now, but can be used later.


nexusTreeTokenize

private java.util.ArrayList nexusTreeTokenize(java.util.Vector treeNumbers)
Tokenize the tree section of a nexus file only, uses newick tokenizer.

Parameters:
treeNumbers - Vector of Integers for commandline-based input of nexus trees; assume this vector is in ascending order
Returns:
arraylist of trees parsed from the tree file.

nexusCharacterTokenize

private void nexusCharacterTokenize()
Tokenize the character section of a nexus file only. Does nothing for now, but can be extended to handle sequences, for example.


nexusTokenize

public java.util.ArrayList nexusTokenize(java.util.Vector treeNumbers,
                                         javax.swing.JProgressBar progressBar)
Tokenize a nexus file, uses newick tokenizer after identifying the region with the tree information.

Parameters:
treeNumbers - Vector of Integers for commandline-based input of nexus trees; assume this vector is in ascending order.
Returns:
arraylist of trees parsed from the nexus file.

main

public static void main(java.lang.String[] args)
Test application function.

Parameters:
args - Program arguments. Only first argument used (for filename).