Class TsvUtils

java.lang.Object
ubic.gemma.core.util.TsvUtils

public class TsvUtils extends Object
Bunch of utilities for writing data to TSV.
Author:
poirigui
  • Field Details

    • COMMENT

      public static final char COMMENT
      See Also:
    • SUB_DELIMITER

      public static final char SUB_DELIMITER
      Delimiter used when printing a list of strings in a column.

      When replacing the delimiter in a value, the occurrences of the delimiter itself should be replaced with an '_'. This is done automatically in format(String[]) and format(Collection).

      See Also:
    • SUB_DELIMITER_STR

      public static final String SUB_DELIMITER_STR
    • NA

      public static final String NA
      Indicator used for a missing value (e.g. NaN or null) in a TSV file.
      See Also:
  • Constructor Details

    • TsvUtils

      public TsvUtils()
  • Method Details

    • appendBaseHeader

      public static void appendBaseHeader(String what, BuildInfo buildInfo, Date timestamp, Writer buf) throws IOException
      Append a base header to a file.
      Parameters:
      what - a short description of what data is being written
      buildInfo - build information to include in the header
      timestamp - a timestamp to include in the header that reflect the time of file generation
      Throws:
      IOException
    • getTsvFormatBuilder

      public static org.apache.commons.csv.CSVFormat.Builder getTsvFormatBuilder(String what, BuildInfo buildInfo, Date timestamp, String... extraHeaderComments)
      Preconfigure a CSVFormat.Builder with desirable defaults.o

      The format will include a header as per appendBaseHeader(String, BuildInfo, Date, Writer).

      Parameters:
      what - a short description of what data is being written
      buildInfo - build information to include in the header
      extraHeaderComments - additional header comments that will be included at the top of the TSV file, right after the Constants.GEMMA_CITATION_NOTICE and Constants.GEMMA_LICENSE_NOTICE
    • parseDouble

      public static double parseDouble(@Nullable String val)
    • parseLong

      @Nullable public static Long parseLong(@Nullable String val)
    • parseInt

      @Nullable public static Integer parseInt(@Nullable String val)
    • parseBoolean

      @Nullable public static Boolean parseBoolean(@Nullable String val)
    • format

      public static String format(@Nullable String[] values)
      Join multiple values into a single string, separated by the SUB_DELIMITER.

      If the delimiter appears in a value, it will be replaced with a _ character.

    • format

      public static String format(@Nullable Collection<String> values)
    • format

      public static String format(@Nullable Double d)
      Format a Double for TSV.
      Parameters:
      d - a double to format
      Returns:
      a formatted double, an empty string if d is null or NaN or inf/-inf if infinite
    • format

      public static String format(double d)
    • format

      public static String format(@Nullable Integer i)
    • format

      public static String format(int i)
    • format

      public static String format(@Nullable Long l)
    • format

      public static String format(long l)
    • format

      public static String format(@Nullable String s)
      Format a String for TSV.
    • format

      public static String format(@Nullable Date d)
    • format

      public static String format(@Nullable Object object)
    • formatFast

      public static String formatFast(double value)
      Quickly format a double value.

      If writing a large number of doubles, format(double) is usually way too slow. This method will use Java's native number formatting instead.

    • formatFast

      public static String formatFast(float value)
    • formatFast

      public static String formatFast(long value)
    • formatFast

      public static String formatFast(int value)
    • formatComment

      public static String formatComment(@Nullable String comment)
      Format a string as a TSV comment.

      This will prepend a COMMENT on each line that do not start with the character.

    • formatComment

      public static String formatComment(String format, Object... args)