info.bioinfweb.jphyloio.formats.nexml

## Class NeXMLEventWriter

- java.lang.Object
- - info.bioinfweb.jphyloio.AbstractEventWriter<P>
  - - info.bioinfweb.jphyloio.formats.xml.AbstractXMLEventWriter<NeXMLWriterStreamDataProvider>
    - - info.bioinfweb.jphyloio.formats.nexml.NeXMLEventWriter

- All Implemented Interfaces:
    NeXMLConstants, JPhyloIOXMLEventWriter, JPhyloIOEventWriter, JPhyloIOFormatSpecificObject

      public class NeXMLEventWriter
      extends AbstractXMLEventWriter<NeXMLWriterStreamDataProvider>
      implements NeXMLConstants

  Event based writer for the NeXML format.

  All data elements modeled by JPhyloIO are supported by this writer, since the data model of JPhyloIO is heavily influenced by the data model of NeXML.

  Comments and meta information can be written under all modeled elements. Meta elements only present to group meta information, e.g. nested under elements not modeled in JPhyloIO, are ignored by this writer and the nested content is written to the according position. The ID of a `JPhyloIOEvent` will be written to the file unchanged.

  Namespaces used or declared in custom XML elements are managed according to `ReadWriteParameterNames.KEY_CUSTOM_XML_NAMESPACE_HANDLING`. More information about this can be found in the documentation of `XMLReadWriteUtils#manageLiteralContentMetaNamespaces()`.

  If no OTUs or OTU list are found in the data, but elements that need to reference either of those, the writer will write a new OTU list or OTU with the ID prefix `NeXMLConstants.UNDEFINED_OTU_ID_PREFIX` or `NeXMLConstants.UNDEFINED_OTUS_ID_PREFIX`. If no token set is present in the data, a new token set with the type `CharacterStateSetType.DISCRETE` and the ID prefix `NeXMLConstants.DEFAULT_TOKEN_DEFINITION_SET_ID_PREFIX` will be written to the file. If not all alignment characters are defined in the document data, missing definitions will be add.

  Before writing, the token definitions and sequence data are checked if they fit the specified `CharacterStateSetType`. If this is not the case, the `CharacterStateSetType.DISCRETE` is assumed. In case of `DNA`, `RNA` or `NUCLEOTIDE` data it is first checked if the data could also be of another nucleotide data type. All molecular data token definition sets contain all token definitions defined in the IUPAC standards. If single token definitions are missing, they are add. Token definitions of standard tokens found in the sequence data but not defined previously are also add in case of standard data.

  Restriction data can not be written, since it is not modeled by JPhyloIO. If the `CharacterStateSetType` of the sequence data is `DSICRETE` tokens are translated to integers as required by NeXML.

  ### Recognized parameters

  - `ReadWriteParameterNames.KEY_WRITER_INSTANCE`
  - `ReadWriteParameterNames.KEY_LOGGER`
  - `ReadWriteParameterNames.KEY_OBJECT_TRANSLATOR_FACTORY`
  - `ReadWriteParameterNames.KEY_APPLICATION_NAME`
  - `ReadWriteParameterNames.KEY_APPLICATION_VERSION`
  - `ReadWriteParameterNames.KEY_APPLICATION_URL`
  - `ReadWriteParameterNames.KEY_NEXML_TOKEN_DEFINITION_LABEL`
  - `ReadWriteParameterNames.KEY_NEXML_TOKEN_DEFINITION_LABEL_METADATA`
  - `ReadWriteParameterNames.KEY_CUSTOM_XML_NAMESPACE_HANDLING`
  Since:
    0.0.0
  Author:
    Sarah Wiechers, Ben Stöver
  See Also:
    Metadata demo application

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class info.bioinfweb.jphyloio.AbstractEventWriter

      `AbstractEventWriter.NoEditUniqueLabelHandler, AbstractEventWriter.UniqueLabelHandler`

  - ### Field Summary

    - ### Fields inherited from class info.bioinfweb.jphyloio.AbstractEventWriter

      `EDITED_LABEL_SEPARATOR`

    - ### Fields inherited from interface info.bioinfweb.jphyloio.formats.nexml.NeXMLConstants

      `ATTR_ABOUT, ATTR_CELL_SET_LINKED_IDS, ATTR_CHAR_SET_LINKED_IDS, ATTR_CODON_POSITION, ATTR_CONTENT, ATTR_DATATYPE, ATTR_GENERATOR, ATTR_HREF, ATTR_ID, ATTR_LABEL, ATTR_LENGTH, ATTR_NODE_EDGE_SET_LINKED_EDGE_IDS, ATTR_NODE_EDGE_SET_LINKED_NODE_IDS, ATTR_NODE_EDGE_SET_LINKED_ROOTEDGE_IDS, ATTR_OTU_SET_LINKED_IDS, ATTR_OTUS, ATTR_PROPERTY, ATTR_REL, ATTR_ROOT, ATTR_SEQUENCE_SET_LINKED_IDS, ATTR_SINGLE_CHAR_LINK, ATTR_SINGLE_OTU_LINK, ATTR_SINGLE_STATE_LINK, ATTR_SOURCE, ATTR_STATE_SET_LINKED_IDS, ATTR_STATES, ATTR_SYMBOL, ATTR_TARGET, ATTR_TOKENS, ATTR_TREE_SET_LINKED_NETWORK_IDS, ATTR_TREE_SET_LINKED_TREE_IDS, ATTR_VERSION, ATTR_XSI_TYPE, DEFAULT_TOKEN_DEFINITION_SET_ID_PREFIX, NEXML_DEFAULT_NAMESPACE_PREFIX, NEXML_FORMAT_NAME, NEXML_NAMESPACE, NEXML_NAMESPACE_PREFIX, NEXML_PREDICATE_NAMESPACE, NEXML_VERSION, PREDICATE_CHAR_ATTR_CODON_POSITION, PREDICATE_CHAR_ATTR_TOKENS, PREDICATE_FORMAT, PREDICATE_MATRIX, PREDICATE_ORIGINAL_LABEL, PREDICATE_ORIGINAL_TOKEN_NAME, TAG_CELL, TAG_CHAR, TAG_CHARACTERS, TAG_EDGE, TAG_FORMAT, TAG_MATRIX, TAG_MEMBER, TAG_META, TAG_NETWORK, TAG_NODE, TAG_OTU, TAG_OTUS, TAG_POLYMORPHIC, TAG_ROOT, TAG_ROOTEDGE, TAG_ROW, TAG_SEQ, TAG_SET, TAG_STATE, TAG_STATES, TAG_TREE, TAG_TREES, TAG_UNCERTAIN, TYPE_CONTIN_CELLS, TYPE_CONTIN_SEQ, TYPE_DNA_CELLS, TYPE_DNA_SEQS, TYPE_FLOAT_NETWORK, TYPE_FLOAT_TREE, TYPE_INT_NETWORK, TYPE_INT_TREE, TYPE_LITERAL_META, TYPE_PROTEIN_CELLS, TYPE_PROTEIN_SEQS, TYPE_RESOURCE_META, TYPE_RESTRICTION_CELLS, TYPE_RESTRICTION_SEQS, TYPE_RNA_CELLS, TYPE_RNA_SEQS, TYPE_STANDARD_CELLS, TYPE_STANDARD_SEQ, UNDEFINED_OTU_ID_PREFIX, UNDEFINED_OTU_LABEL, UNDEFINED_OTUS_ID_PREFIX, UNDEFINED_OTUS_LABEL`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NeXMLEventWriter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected NeXMLWriterStreamDataProvider` | `createStreamDataProvider()` This method is called in the constructor of `AbstractEventWriter` to initialize the stream data provider that will be returned by `AbstractEventWriter.getStreamDataProvider()`.
    `protected void` | `doWriteDocument()`
    `java.lang.String` | `getFormatID()` Returns a string ID uniquely identifying the target format of this instance.

    - ### Methods inherited from class info.bioinfweb.jphyloio.formats.xml.AbstractXMLEventWriter

      `createMetaXMLEventWriter, createMetaXMLStreamWriter, doWriteDocument, getDocument, getLogger, getNamespaceContext, getParameters, getXMLWriter`

    - ### Methods inherited from class info.bioinfweb.jphyloio.AbstractEventWriter

      `createUniqueLabel, createUniqueLabel, createUniqueLabel, createUniqueLinkedOTULabel, decreaseIndention, determineMaxSequenceLength, extendSequence, getFileStartInfo, getIndention, getLabeledIDName, getLinkedOTUNameOTUFirst, getLinkedOTUNameOwnFirst, getReferencedOTUList, getStreamDataProvider, increaseIndention, logIngnoredOTULists, writeDocument, writeDocument, writeDocument, writeLineBreak, writeLineStart`

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

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

    - ### Methods inherited from interface info.bioinfweb.jphyloio.JPhyloIOEventWriter

      `writeDocument, writeDocument, writeDocument`

- - ### Constructor Detail

    - #### NeXMLEventWriter

          public NeXMLEventWriter()

  - ### Method Detail

    - #### getFormatID

          public java.lang.String getFormatID()

      Description copied from interface: `JPhyloIOFormatSpecificObject`
      Returns a string ID uniquely identifying the target format of this instance. Additional information on the format can be retrieved by passing the returned ID to `JPhyloIOReaderWriterFactory.getFormatInfo(String)`.

      Third party developers that create readers or writers for additional formats must make sure to use a globally unique format ID. It is strongly recommended to use owned reverse domain names for this (e.g. `org.example.additionalformat`).

      Specified by:
        `getFormatID` in interface `JPhyloIOFormatSpecificObject`
      Returns:
        the ID of the target format of this instance
      See Also:
        `JPhyloIOReaderWriterFactory.getFormatInfo(String)`

    - #### createStreamDataProvider

          protected NeXMLWriterStreamDataProvider createStreamDataProvider()

      Description copied from class: `AbstractEventWriter`
      This method is called in the constructor of `AbstractEventWriter` to initialize the stream data provider that will be returned by `AbstractEventWriter.getStreamDataProvider()`. Inheriting classes that use their own stream data provider implementation should overwrite this method.

      This default implementation creates a new instance of `WriterStreamDataProvider`.

      Overrides:
        `createStreamDataProvider` in class `AbstractEventWriter<NeXMLWriterStreamDataProvider>`
      Returns:
        the stream data provider to be used with this instance

    - #### doWriteDocument

          protected void doWriteDocument()
                                  throws java.io.IOException,
                                         javax.xml.stream.XMLStreamException

      Specified by:
        `doWriteDocument` in class `AbstractXMLEventWriter<NeXMLWriterStreamDataProvider>`
      Throws:
        `java.io.IOException`
        `javax.xml.stream.XMLStreamException`