info.bioinfweb.jphyloio.formats.newick

## Class NewickStringWriter

- java.lang.Object
- - info.bioinfweb.jphyloio.formats.newick.NewickStringWriter

- All Implemented Interfaces:
    NewickConstants

      public class NewickStringWriter
      extends java.lang.Object
      implements NewickConstants

  Implementation to write Newick tree definitions to be used by `NewickEventWriter` and `NexusEventWriter`.
  Author:
    Ben Stöver
  See Also:
    `NewickEventWriter`, `NexusEventWriter`, Metadata demo application

- - ### Field Summary

    - ### Fields inherited from interface info.bioinfweb.jphyloio.formats.newick.NewickConstants

      `ALLOCATION_SEPARATOR_SYMBOL, ALLOCATION_SYMBOL, ALTERNATIVE_NAME_DELIMITER, COMMENT_END, COMMENT_START, DATA_TYPE_NEWICK_ARRAY, E_NEWICK_EDGE_TYPE_HYBRIDIZATION, E_NEWICK_EDGE_TYPE_LATERAL_GENE_TRANSFER, E_NEWICK_EDGE_TYPE_RECOMBINATION, E_NEWICK_NAMESPACE_PREFIX, E_NEWICK_NETWORK_DATA_SEPARATOR, ELEMENT_SEPERATOR, FIELD_END_SYMBOL, FIELD_START_SYMBOL, FIELD_VALUE_SEPARATOR_SYMBOL, FREE_NAME_BLANK, HOT_COMMENT_START_SYMBOL, INDEX_END_SYMBOL, INDEX_START_SYMBOL, LENGTH_SEPERATOR, NAME_DELIMITER, NEWICK_DATA_TYPE_NAMESPACE, NEWICK_FORMAT_NAME, NEWICK_NAMESPACE_PREFIX, NHX_KEY_CONFIDENCE, NHX_KEY_EVENT, NHX_KEY_GENE_NAME, NHX_KEY_PREFIX, NHX_KEY_SCIENTIFIC_NAME, NHX_KEY_SEQUENCE_ACCESSION, NHX_KEY_TAXONOMY_ID, NHX_START, NHX_VALUE_SEPARATOR_SYMBOL, PREDICATE_E_NEWICK_EDGE_TYPE, ROOTED_HOT_COMMENT, SUBTREE_END, SUBTREE_START, TERMINAL_SYMBOL, UNROOTED_HOT_COMMENT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NewickStringWriter(TextWriterStreamDataProvider<?> streamDataProvider, TreeNetworkDataAdapter tree, NewickWriterNodeLabelProcessor nodeLabelProcessor, ReadWriteParameterMap parameters)` Creates a new instance of this class.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `formatToken(java.lang.String token, char delimiter)`
    `static boolean` | `isFreeNameCharForWriting(char c)`
    `void` | `write()` Writes the tree data specified in the constructor to the specified stream.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NewickStringWriter

          public NewickStringWriter(TextWriterStreamDataProvider<?> streamDataProvider,
                                    TreeNetworkDataAdapter tree,
                                    NewickWriterNodeLabelProcessor nodeLabelProcessor,
                                    ReadWriteParameterMap parameters)

      Creates a new instance of this class.
      Parameters:
        `writer` - the writer to write the Newick string to
        `tree` - the tree data adapter providing the tree data to be written
        `otuList` - the list of OTU definitions to be used to label unlabeled tree nodes (Maybe `null`.)
        `useOTUFirst` - Specify `true` here, if `AbstractEventWriter#getLinkedOTUNameOTUFirst(LinkedLabeledIDEvent, OTUListDataAdapter)` shall be used to determine node names (e.g. for writing Nexus) or `false` if `AbstractEventWriter#getLinkedOTUNameOwnFirst(LinkedLabeledIDEvent, OTUListDataAdapter)` should be used instead (e.g. for writing Newick).
        `parameters` - the write parameter map specified to the calling reader

  - ### Method Detail

    - #### isFreeNameCharForWriting

          public static boolean isFreeNameCharForWriting(char c)

    - #### formatToken

          public static java.lang.String formatToken(java.lang.String token,
                                                     char delimiter)

    - #### write

          public void write()
                     throws java.io.IOException

      Writes the tree data specified in the constructor to the specified stream.

      If the specified tree/network data adapter models a phylogenetic network and not a tree, nothing is written and an according warning is logged. Additionally warnings are logged, if the tree adapter provides metadata or if multiple root edges are available.

      If an empty tree definition (with no root edge) is specified, the written Newick string only consists of the terminal symbol `';'`.

      Throws:
        `java.io.IOException` - if an I/O error occurs while writing to specified writer