info.bioinfweb.jphyloio.formats.fasta

## Class FASTAEventWriter

- java.lang.Object
- - info.bioinfweb.jphyloio.AbstractEventWriter<P>
  - - info.bioinfweb.jphyloio.formats.text.AbstractTextEventWriter<P>
    - - info.bioinfweb.jphyloio.AbstractSingleMatrixEventWriter<TextWriterStreamDataProvider<FASTAEventWriter>>
      - - info.bioinfweb.jphyloio.formats.fasta.FASTAEventWriter

- All Implemented Interfaces:
    FASTAConstants, JPhyloIOEventWriter, JPhyloIOFormatSpecificObject

      public class FASTAEventWriter
      extends AbstractSingleMatrixEventWriter<TextWriterStreamDataProvider<FASTAEventWriter>>
      implements FASTAConstants

  Event based writer for the FASTA format.

  This write is able to write sequence data to FASTA formatted streams. It will ignore any data for phylogenetic trees and networks that are provided by `DocumentDataAdapter#getTreeNetworkIterator(ReadWriteParameterMap)`, because the FASTA format does not support such data.

  Since FASTA does not support OTU or taxon lists as well, such a list (if provided by `DocumentDataAdapter.getOTUListIterator(ReadWriteParameterMap)`) will also not be written. OTU definitions (if present) will though be used, if a sequence with a linked OTU ID but without a label is specified. In such cases `OTUListDataAdapter#getOTUStartEvent(String)` will be used to determine the according OTU label. If that OTU label is also `null`, the sequence ID will be used as the sequence name in FASTA.

  Comments and metadata nested in any of the supported elements will be ignored, with the only exception of comments before the first token of a sequence. Such comments will be included in FASTA, since this is only valid position for comments in the format.

  ### Recognized parameters

  - `ReadWriteParameterNames.KEY_LOGGER`
  - `ReadWriteParameterNames.KEY_SEQUENCE_EXTENSION_TOKEN`
  - `ReadWriteParameterNames.KEY_LINE_LENGTH`
  - `ReadWriteParameterNames.KEY_WRITER_INSTANCE`
  - `ReadWriteParameterNames.KEY_LINE_SEPARATOR`
  - `ReadWriteParameterNames.KEY_MAXIMUM_NAME_LENGTH` (If this parameter is omitted, any name length is possible.)
  - `ReadWriteParameterNames.KEY_LABEL_EDITING_REPORTER`
  Author:
    Ben Stöver

- - ### 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.fasta.FASTAConstants

      `COMMENT_START_CHAR, DEFAULT_LINE_LENGTH, FASTA_FORMAT_NAME, NAME_START_CHAR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FASTAEventWriter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected TextWriterStreamDataProvider<FASTAEventWriter>` | `createStreamDataProvider()` This method is called in the constructor of `AbstractEventWriter` to initialize the stream data provider that will be returned by `AbstractEventWriter.getStreamDataProvider()`.
    `java.lang.String` | `getFormatID()` Returns a string ID uniquely identifying the target format of this instance.
    `protected java.lang.String` | `maskReservedLabelCharacters(java.lang.String label)`
    `protected void` | `writeSingleMatrix(DocumentDataAdapter document, MatrixDataAdapter matrix, java.util.Iterator<java.lang.String> sequenceIDIterator, ReadWriteParameterMap parameters)` Implementations of this method should write a single matrix to their target format.

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

      `doWriteDocument, editSequenceOrNodeLabel`

    - ### Methods inherited from class info.bioinfweb.jphyloio.formats.text.AbstractTextEventWriter

      `getWriter`

    - ### 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`

- - ### Constructor Detail

    - #### FASTAEventWriter

          public FASTAEventWriter()

  - ### 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 TextWriterStreamDataProvider<FASTAEventWriter> 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<TextWriterStreamDataProvider<FASTAEventWriter>>`
      Returns:
        the stream data provider to be used with this instance

    - #### maskReservedLabelCharacters

          protected java.lang.String maskReservedLabelCharacters(java.lang.String label)

      Specified by:
        `maskReservedLabelCharacters` in class `AbstractSingleMatrixEventWriter<TextWriterStreamDataProvider<FASTAEventWriter>>`

    - #### writeSingleMatrix

          protected void writeSingleMatrix(DocumentDataAdapter document,
                                           MatrixDataAdapter matrix,
                                           java.util.Iterator<java.lang.String> sequenceIDIterator,
                                           ReadWriteParameterMap parameters)
                                    throws java.io.IOException

      Description copied from class: `AbstractSingleMatrixEventWriter`
      Implementations of this method should write a single matrix to their target format.
      Specified by:
        `writeSingleMatrix` in class `AbstractSingleMatrixEventWriter<TextWriterStreamDataProvider<FASTAEventWriter>>`
      Parameters:
        `document` - the document containing the matrix
        `matrix` - the (non-empty) matrix to be written
        `sequenceIDIterator` - an iterator oder all sequences in `matrix` positioned before the first sequence
        `parameters` - the parameter map for the writer implementation
      Throws:
        `java.io.IOException`