Package org.snpeff.util
Class Gpr
- java.lang.Object
-
- org.snpeff.util.Gpr
-
public class Gpr extends java.lang.Object
General pupose rutines- Author:
- root
-
-
Constructor Summary
Constructors Constructor Description Gpr()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
baseName(java.lang.String file)
Return file's name (without the path)static java.lang.String
baseName(java.lang.String file, java.lang.String ext)
Return file's name (without the path)static java.lang.String
bin64(long l)
Show a long as a 64 bit binary numberstatic boolean
canRead(java.lang.String fileName)
Can we read this file (either exact name or append a '.gz'static int
compareNull(java.lang.Comparable c1, java.lang.Comparable c2)
static java.lang.String
compileDate(java.lang.Class<?> cl)
static java.lang.String
compileTimeStamp()
static java.lang.String
compileTimeStamp(java.lang.Class<?> cl)
Return a time-stamp showing When was the JAR file created OR when was a class compiledstatic java.lang.String
compileTimeStamp(java.lang.Class<?> cl, java.text.SimpleDateFormat dateFormat)
Return a time-stamp showing When was the JAR file created OR when was a class compiledstatic int
countColumns(java.lang.String file)
Count number of column in a filestatic int
countLines(java.lang.String file)
Count lines in a file (same as 'wc -l file' in unix)static java.lang.String
dirName(java.lang.String file)
Return file's dirstatic boolean
exists(java.lang.String file)
Does 'file' exist?static java.lang.String
extName(java.lang.String file)
Get a file's extension (all letters after the last '.'static java.lang.String
head(java.lang.Object o)
static java.lang.StringBuffer
inputStream2StringBuffer(java.io.InputStream inputStream)
static boolean
isStdin(java.lang.String fileName)
Empty or '-' means STDINstatic boolean
isValidIp(java.lang.String ip)
static boolean
isValidRid(int i)
Is this a valid Ridstatic java.lang.String
noSpaces(java.lang.String str)
Remove spaces and tabs from string.static boolean
parseBoolSafe(java.lang.String s)
Equivalent to Boolean.parseBoolean, except it returns 0 on invalid integer (NumberFormatException)static double
parseDoubleSafe(java.lang.String s)
Equivalent to Double.parseDouble(), except it returns 0 on invalid double (NumberFormatException)static float
parseFloatSafe(java.lang.String s)
Equivalent to Float.parseFloat(), except it returns 0 on invalid double (NumberFormatException)static int
parseIntSafe(java.lang.String s)
Equivalent to Integer.parseInt, except it returns 0 on invalid integer (NumberFormatException)static long
parseLongSafe(java.lang.String s)
Equivalent to Integer.parseInt, except it returns 0 on invalid integer (NumberFormatException)static java.lang.String
prependEachLine(java.lang.String prepend, java.lang.Object lines)
Prepend a message to each linestatic java.lang.String
read(java.io.InputStream is)
Read an input streamstatic java.io.BufferedReader
reader(java.lang.String fileName)
Try to open a file (BufferedReader) using either the file or a gzip file (appending '.gz' to fileName)static java.io.BufferedReader
reader(java.lang.String fileName, boolean gzip)
Try to open a file (BufferedReader) using either the file or a gzip file (appending '.gz' to fileName)static java.lang.String
readFile(java.lang.String fileName)
Read a file as a String.static java.lang.String
readFile(java.lang.String fileName, boolean gzipped)
Read a file as a String.static java.lang.Object
readFileSerialized(java.lang.String fileName)
Read an object from a file (supposing an object was previously serialized to that file)static java.lang.Object
readFileSerializedGz(java.lang.String fileName)
Read an object from a file (supposing an object was previously serialized to that file) Note: The file is compressed using GZIPstatic java.lang.Object
readFileSerializedGzThrow(java.lang.String fileName)
Read an object from a file (supposing an object was previously serialized to that file) Note: Same as 'readFileSerializedGz' but it throws all the exceptionsstatic java.lang.String
removeBackslashR(java.lang.String line)
Remove trailing '\r'static java.lang.String
removeExt(java.lang.String file)
static java.lang.String
removeExt(java.lang.String file, java.lang.String[] fileExtensions)
Remove extension from a file (if matches one of 'fileExtensions[]')static java.lang.String
repeat(char c, int n)
Create a string of n time 'c'static java.lang.String
sanityzeFileName(java.lang.String fileName)
static java.lang.String
sanityzeName(java.lang.String fileName)
static void
showMark(int i, int showEvery)
Show a markstatic void
showMark(int i, int showEvery, java.lang.String newLineStr)
Show a markstatic void
showMarkStderr(int i, int showEvery)
Show a mark (on STDERR)static void
showStackTrace(int steps)
static void
showStackTrace(int steps, int offset)
Prints a stack trace for a number of stepsstatic java.lang.String[]
split(java.lang.String value, char delim)
Splits a separated string into an array ofString
tokens.static java.lang.String
tabs(int tabs)
static java.lang.String
tail(java.lang.Object o)
static java.lang.String
toByteSize(long l)
static void
toFile(java.lang.String fileName, java.lang.Object obj)
Write an object to a filestatic void
toFile(java.lang.String fileName, java.lang.Object obj, boolean append)
Write an object to a filestatic void
toFileGz(java.lang.String fileName, java.lang.Object obj)
Write an object to a file (as a string) Note: The file is compressed using GZIPstatic void
toFileSerialize(java.lang.String fileName, java.lang.Object obj)
Write an object to a file by invoking Serialization methodsstatic void
toFileSerializeGz(java.lang.String fileName, java.lang.Object obj)
Write an object to a file by invoking Serialization methods Note: The file is compressed using GZIPstatic java.lang.String
toString(boolean[] vals)
static java.lang.String
toString(double val)
static java.lang.String
toString(double[] vals)
static java.lang.String
toString(double[][] vals)
static java.lang.String
toString(int[] vals)
static java.lang.String
toStringHead(double[] vals)
-
-
-
Field Detail
-
KB
public static final long KB
- See Also:
- Constant Field Values
-
MB
public static final long MB
- See Also:
- Constant Field Values
-
GB
public static final long GB
- See Also:
- Constant Field Values
-
TB
public static final long TB
- See Also:
- Constant Field Values
-
NUM_CORES
public static final int NUM_CORES
-
HOME
public static final java.lang.String HOME
-
GZIP_EXTENTIONS
public static final java.lang.String[] GZIP_EXTENTIONS
-
-
Method Detail
-
baseName
public static java.lang.String baseName(java.lang.String file)
Return file's name (without the path)
-
baseName
public static java.lang.String baseName(java.lang.String file, java.lang.String ext)
Return file's name (without the path)
-
bin64
public static java.lang.String bin64(long l)
Show a long as a 64 bit binary number
-
canRead
public static boolean canRead(java.lang.String fileName)
Can we read this file (either exact name or append a '.gz'
-
compareNull
public static int compareNull(java.lang.Comparable c1, java.lang.Comparable c2)
-
compileDate
public static java.lang.String compileDate(java.lang.Class<?> cl)
-
compileTimeStamp
public static java.lang.String compileTimeStamp()
-
compileTimeStamp
public static java.lang.String compileTimeStamp(java.lang.Class<?> cl)
Return a time-stamp showing When was the JAR file created OR when was a class compiled
-
compileTimeStamp
public static java.lang.String compileTimeStamp(java.lang.Class<?> cl, java.text.SimpleDateFormat dateFormat)
Return a time-stamp showing When was the JAR file created OR when was a class compiled
-
countColumns
public static int countColumns(java.lang.String file)
Count number of column in a file
-
countLines
public static int countLines(java.lang.String file)
Count lines in a file (same as 'wc -l file' in unix)- Parameters:
file
-- Returns:
-
dirName
public static java.lang.String dirName(java.lang.String file)
Return file's dir
-
exists
public static boolean exists(java.lang.String file)
Does 'file' exist?
-
extName
public static java.lang.String extName(java.lang.String file)
Get a file's extension (all letters after the last '.'
-
head
public static java.lang.String head(java.lang.Object o)
-
inputStream2StringBuffer
public static java.lang.StringBuffer inputStream2StringBuffer(java.io.InputStream inputStream) throws java.io.IOException
- Throws:
java.io.IOException
-
isStdin
public static boolean isStdin(java.lang.String fileName)
Empty or '-' means STDIN
-
isValidIp
public static boolean isValidIp(java.lang.String ip)
-
isValidRid
public static boolean isValidRid(int i)
Is this a valid Rid
-
noSpaces
public static java.lang.String noSpaces(java.lang.String str)
Remove spaces and tabs from string.
-
parseBoolSafe
public static boolean parseBoolSafe(java.lang.String s)
Equivalent to Boolean.parseBoolean, except it returns 0 on invalid integer (NumberFormatException)
-
parseDoubleSafe
public static double parseDoubleSafe(java.lang.String s)
Equivalent to Double.parseDouble(), except it returns 0 on invalid double (NumberFormatException)
-
parseFloatSafe
public static float parseFloatSafe(java.lang.String s)
Equivalent to Float.parseFloat(), except it returns 0 on invalid double (NumberFormatException)- Parameters:
s
-- Returns:
- int
-
parseIntSafe
public static int parseIntSafe(java.lang.String s)
Equivalent to Integer.parseInt, except it returns 0 on invalid integer (NumberFormatException)- Parameters:
s
-- Returns:
- int
-
parseLongSafe
public static long parseLongSafe(java.lang.String s)
Equivalent to Integer.parseInt, except it returns 0 on invalid integer (NumberFormatException)- Parameters:
s
-- Returns:
- int
-
prependEachLine
public static java.lang.String prependEachLine(java.lang.String prepend, java.lang.Object lines)
Prepend a message to each line
-
read
public static java.lang.String read(java.io.InputStream is)
Read an input stream- Parameters:
is
-- Returns:
-
reader
public static java.io.BufferedReader reader(java.lang.String fileName)
Try to open a file (BufferedReader) using either the file or a gzip file (appending '.gz' to fileName)
-
reader
public static java.io.BufferedReader reader(java.lang.String fileName, boolean gzip)
Try to open a file (BufferedReader) using either the file or a gzip file (appending '.gz' to fileName)- Parameters:
gzip
- : If true, file is assumed to be gzipped
-
readFile
public static java.lang.String readFile(java.lang.String fileName)
Read a file as a String. Note: the file can be compressed using gzip (file name must have a ".gz" extension).- Parameters:
fileName
- : File to read (null on error)showExceptions
- : show exceptions if true
-
readFile
public static java.lang.String readFile(java.lang.String fileName, boolean gzipped)
Read a file as a String. Note: the file can be compressed using gzip (file name must have a ".gz" extension).- Parameters:
fileName
- : File to read (null on error)showExceptions
- : show exceptions if true
-
readFileSerialized
public static java.lang.Object readFileSerialized(java.lang.String fileName)
Read an object from a file (supposing an object was previously serialized to that file)- Parameters:
fileName
-- Returns:
- An object from that file
-
readFileSerializedGz
public static java.lang.Object readFileSerializedGz(java.lang.String fileName)
Read an object from a file (supposing an object was previously serialized to that file) Note: The file is compressed using GZIP- Parameters:
fileName
-- Returns:
- An object from that file
-
readFileSerializedGzThrow
public static java.lang.Object readFileSerializedGzThrow(java.lang.String fileName) throws java.io.FileNotFoundException, java.io.IOException, java.lang.ClassNotFoundException
Read an object from a file (supposing an object was previously serialized to that file) Note: Same as 'readFileSerializedGz' but it throws all the exceptions- Parameters:
fileName
-- Returns:
- An object from that file
- Throws:
java.io.IOException
java.io.FileNotFoundException
java.lang.ClassNotFoundException
-
removeBackslashR
public static java.lang.String removeBackslashR(java.lang.String line)
Remove trailing '\r'
-
removeExt
public static java.lang.String removeExt(java.lang.String file)
-
removeExt
public static java.lang.String removeExt(java.lang.String file, java.lang.String[] fileExtensions)
Remove extension from a file (if matches one of 'fileExtensions[]')
-
repeat
public static java.lang.String repeat(char c, int n)
Create a string of n time 'c'
-
sanityzeFileName
public static java.lang.String sanityzeFileName(java.lang.String fileName)
-
sanityzeName
public static java.lang.String sanityzeName(java.lang.String fileName)
-
showMark
public static void showMark(int i, int showEvery)
Show a mark
-
showMark
public static void showMark(int i, int showEvery, java.lang.String newLineStr)
Show a mark
-
showMarkStderr
public static void showMarkStderr(int i, int showEvery)
Show a mark (on STDERR)
-
showStackTrace
public static void showStackTrace(int steps)
-
showStackTrace
public static void showStackTrace(int steps, int offset)
Prints a stack trace for a number of steps- Parameters:
count
-
-
split
public static java.lang.String[] split(java.lang.String value, char delim)
Splits a separated string into an array ofString
tokens. If the input string is null, this method returns null. Implementation note: for performance reasons, this implementation uses neither StringTokenizer nor String.split(). StringTokenizer does not return all tokens for strings of the form "1,2,,3," unless you use an instance that returns the separator. By doing so, our code would need to modify the token string which would create another temporary object and would make this method very slow.
String.split does not return all tokens for strings of the form "1,2,3,,,". We simply cannot use this method. The result is a custom String splitter algorithm which performs well for large Strings.- Parameters:
value
- the string value to split into tokens- Returns:
- an array of String Objects or null if the string value is null
-
tabs
public static java.lang.String tabs(int tabs)
-
tail
public static java.lang.String tail(java.lang.Object o)
-
toByteSize
public static java.lang.String toByteSize(long l)
-
toFile
public static void toFile(java.lang.String fileName, java.lang.Object obj)
Write an object to a file
-
toFile
public static void toFile(java.lang.String fileName, java.lang.Object obj, boolean append)
Write an object to a file
-
toFileGz
public static void toFileGz(java.lang.String fileName, java.lang.Object obj)
Write an object to a file (as a string) Note: The file is compressed using GZIP- Parameters:
fileName
- : File to writeobj
- : Object
-
toFileSerialize
public static void toFileSerialize(java.lang.String fileName, java.lang.Object obj)
Write an object to a file by invoking Serialization methods- Parameters:
fileName
- : File to writeobj
- : Object
-
toFileSerializeGz
public static void toFileSerializeGz(java.lang.String fileName, java.lang.Object obj)
Write an object to a file by invoking Serialization methods Note: The file is compressed using GZIP- Parameters:
fileName
- : File to writeobj
- : Object
-
toString
public static java.lang.String toString(boolean[] vals)
-
toString
public static java.lang.String toString(double[] vals)
-
toString
public static java.lang.String toString(double[][] vals)
-
toString
public static java.lang.String toString(double val)
-
toString
public static java.lang.String toString(int[] vals)
-
toStringHead
public static java.lang.String toStringHead(double[] vals)
-
-