Package ubic.gemma.core.util
Class TsvUtils
java.lang.Object
ubic.gemma.core.util.TsvUtils
Bunch of utilities for writing data to TSV.
- Author:
- poirigui
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
appendBaseHeader
(String what, BuildInfo buildInfo, Date timestamp, Writer buf) Append a base header to a file.static String
format
(double d) static String
format
(int i) static String
format
(long l) static String
Format aDouble
for TSV.static String
static String
static String
static String
Format aString
for TSV.static String
Join multiple values into a single string, separated by theSUB_DELIMITER
.static String
format
(Collection<String> values) static String
static String
formatComment
(String comment) Format a string as a TSV comment.static String
formatComment
(String format, Object... args) static String
formatFast
(double value) Quickly format a double value.static String
formatFast
(float value) static String
formatFast
(int value) static String
formatFast
(long value) static org.apache.commons.csv.CSVFormat.Builder
getTsvFormatBuilder
(String what, BuildInfo buildInfo, Date timestamp, String... extraHeaderComments) Preconfigure aCSVFormat.Builder
with desirable defaults.ostatic Boolean
parseBoolean
(String val) static double
parseDouble
(String val) static Integer
static Long
-
Field Details
-
COMMENT
public static final char COMMENT- See Also:
-
SUB_DELIMITER
public static final char SUB_DELIMITERDelimiter 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[])
andformat(Collection)
.- See Also:
-
SUB_DELIMITER_STR
-
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 writtenbuildInfo
- build information to include in the headertimestamp
- 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 aCSVFormat.Builder
with desirable defaults.oThe format will include a header as per
appendBaseHeader(String, BuildInfo, Date, Writer)
.- Parameters:
what
- a short description of what data is being writtenbuildInfo
- build information to include in the headerextraHeaderComments
- additional header comments that will be included at the top of the TSV file, right after theConstants.GEMMA_CITATION_NOTICE
andConstants.GEMMA_LICENSE_NOTICE
-
parseDouble
-
parseLong
-
parseInt
-
parseBoolean
-
format
Join multiple values into a single string, separated by theSUB_DELIMITER
.If the delimiter appears in a value, it will be replaced with a
_
character. -
format
-
format
Format aDouble
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
-
format
-
format
-
format
-
format
-
format
Format aString
for TSV. -
format
-
format
-
formatFast
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
-
formatFast
-
formatFast
-
formatComment
Format a string as a TSV comment.This will prepend a
COMMENT
on each line that do not start with the character. -
formatComment
-