Class TSVWriter


  • public class TSVWriter
    extends SSSOMWriter
    A writer to serialise a SSSOM mapping set into the TSV format.

    If the mapping set has a CURIE map (MappingSet.getCurieMap()), it is automatically used to shorten identifiers when they are written to the file.

    Usage:

     MappingSet mappingSet = ...;
     try {
         TSVWriter writer = new TSVWriter("my-mappings.sssom.tsv");
         writer.write(mappingSet);
     } catch ( IOException ioe ) {
         // Generic I/O error
     }
     
    • Constructor Detail

      • TSVWriter

        public TSVWriter​(File tsvFile,
                         File metaFile)
                  throws IOException
        Creates a new instance that will write data to the specified files.
        Parameters:
        tsvFile - The file to write the TSV section to.
        metaFile - The file to write the metadata block to. If null, the metadata block will be embedded in the same file as the TSV section.
        Throws:
        IOException - If any of the files cannot be opened for any reason.
      • TSVWriter

        public TSVWriter​(File file)
                  throws IOException
        Creates a new instance that will write data to the specified file in embedded mode (metadata block and TSV section in the same file).
        Parameters:
        file - The file to write to.
        Throws:
        IOException - If the file cannot be opened for any reason.
      • TSVWriter

        public TSVWriter​(OutputStream tsvStream,
                         OutputStream metaStream)
        Creates a new instance that will write data to the specified streams.
        Parameters:
        tsvStream - The stream to write the TSV section to.
        metaStream - The stream to write the metadata block to. If null, the metadata block will be embedded in the same stream as the TSV section.
      • TSVWriter

        public TSVWriter​(OutputStream stream)
        Creates a new instance that will write data to the specified stream in embedded mode.
        Parameters:
        stream - The stream to write to.
      • TSVWriter

        public TSVWriter​(String tsvFilename,
                         String metaFilename)
                  throws IOException
        Creates a new instance that will write data to files with the specified filenames.
        Parameters:
        tsvFilename - The name of the file to write the TSV section to.
        metaFilename - The name of the file to write the metadata block to. If null, the metadata block will be embedded in the same file as the TSV section.
        Throws:
        IOException - If any of the files cannot be opened for any reason.
      • TSVWriter

        public TSVWriter​(String filename)
                  throws IOException
        Creates a new instance that will write data to a file with the specified filename, in embedded mode.
        Parameters:
        filename - The name of the file to write to.
        Throws:
        IOException - If the file cannot be opened for any reason.
    • Method Detail

      • enableCSV

        public void enableCSV​(boolean csv)
        Enables CSV mode. This makes the writer use a comma to separate columns, rather than a tab.

        This is not officially supported by the SSSOM specification, which only specifies the tab-separated format. But the comma-separated variant is accepted by SSSOM-Py.

        Parameters:
        csv - If true, the writer will produce a CSV file.
      • doWrite

        protected void doWrite​(MappingSet mappingSet)
                        throws IOException
        Description copied from class: SSSOMWriter
        Actually serialises a mapping set. This method should be overridden by derived classes to implement the serialisation in a specific format.
        Specified by:
        doWrite in class SSSOMWriter
        Parameters:
        mappingSet - The mapping set to serialise.
        Throws:
        IOException - If an I/O error occurs.