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 voidappendBaseHeader(String what, BuildInfo buildInfo, Date timestamp, Writer buf) Append a base header to a file.static Stringformat(double d) static Stringformat(int i) static Stringformat(long l) static StringFormat aDoublefor TSV.static Stringstatic Stringstatic Stringstatic StringFormat aStringfor TSV.static StringJoin multiple values into a single string, separated by theSUB_DELIMITER.static Stringformat(Collection<String> values) static Stringstatic StringformatComment(String comment) Format a string as a TSV comment.static StringformatComment(String format, Object... args) static StringformatFast(double value) Quickly format a double value.static StringformatFast(float value) static StringformatFast(int value) static StringformatFast(long value) static org.apache.commons.csv.CSVFormat.BuildergetTsvFormatBuilder(String what, BuildInfo buildInfo, Date timestamp, String... extraHeaderComments) Preconfigure aCSVFormat.Builderwith desirable defaults.ostatic BooleanparseBoolean(String val) static doubleparseDouble(String val) static Integerstatic 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.Builderwith 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_NOTICEandConstants.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 aDoublefor 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 aStringfor 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
COMMENTon each line that do not start with the character. -
formatComment
-