Package org.snpeff.util
Class Gpr
- java.lang.Object
-
- org.snpeff.util.Gpr
-
public class Gpr extends java.lang.ObjectGeneral 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.StringbaseName(java.lang.String file)Return file's name (without the path)static java.lang.StringbaseName(java.lang.String file, java.lang.String ext)Return file's name (without the path)static java.lang.Stringbin64(long l)Show a long as a 64 bit binary numberstatic booleancanRead(java.lang.String fileName)Can we read this file (either exact name or append a '.gz'static intcompareNull(java.lang.Comparable c1, java.lang.Comparable c2)static java.lang.StringcompileDate(java.lang.Class<?> cl)static java.lang.StringcompileTimeStamp()static java.lang.StringcompileTimeStamp(java.lang.Class<?> cl)Return a time-stamp showing When was the JAR file created OR when was a class compiledstatic java.lang.StringcompileTimeStamp(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 intcountColumns(java.lang.String file)Count number of column in a filestatic intcountLines(java.lang.String file)Count lines in a file (same as 'wc -l file' in unix)static java.lang.StringdirName(java.lang.String file)Return file's dirstatic booleanexists(java.lang.String file)Does 'file' exist?static java.lang.StringextName(java.lang.String file)Get a file's extension (all letters after the last '.'static java.lang.Stringhead(java.lang.Object o)static java.lang.StringBufferinputStream2StringBuffer(java.io.InputStream inputStream)static booleanisStdin(java.lang.String fileName)Empty or '-' means STDINstatic booleanisValidIp(java.lang.String ip)static booleanisValidRid(int i)Is this a valid Ridstatic java.lang.StringnoSpaces(java.lang.String str)Remove spaces and tabs from string.static booleanparseBoolSafe(java.lang.String s)Equivalent to Boolean.parseBoolean, except it returns 0 on invalid integer (NumberFormatException)static doubleparseDoubleSafe(java.lang.String s)Equivalent to Double.parseDouble(), except it returns 0 on invalid double (NumberFormatException)static floatparseFloatSafe(java.lang.String s)Equivalent to Float.parseFloat(), except it returns 0 on invalid double (NumberFormatException)static intparseIntSafe(java.lang.String s)Equivalent to Integer.parseInt, except it returns 0 on invalid integer (NumberFormatException)static longparseLongSafe(java.lang.String s)Equivalent to Integer.parseInt, except it returns 0 on invalid integer (NumberFormatException)static java.lang.StringprependEachLine(java.lang.String prepend, java.lang.Object lines)Prepend a message to each linestatic java.lang.Stringread(java.io.InputStream is)Read an input streamstatic java.io.BufferedReaderreader(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.BufferedReaderreader(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.StringreadFile(java.lang.String fileName)Read a file as a String.static java.lang.StringreadFile(java.lang.String fileName, boolean gzipped)Read a file as a String.static java.lang.ObjectreadFileSerialized(java.lang.String fileName)Read an object from a file (supposing an object was previously serialized to that file)static java.lang.ObjectreadFileSerializedGz(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.ObjectreadFileSerializedGzThrow(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.StringremoveBackslashR(java.lang.String line)Remove trailing '\r'static java.lang.StringremoveExt(java.lang.String file)static java.lang.StringremoveExt(java.lang.String file, java.lang.String[] fileExtensions)Remove extension from a file (if matches one of 'fileExtensions[]')static java.lang.Stringrepeat(char c, int n)Create a string of n time 'c'static java.lang.StringsanityzeFileName(java.lang.String fileName)static java.lang.StringsanityzeName(java.lang.String fileName)static voidshowMark(int i, int showEvery)Show a markstatic voidshowMark(int i, int showEvery, java.lang.String newLineStr)Show a markstatic voidshowMarkStderr(int i, int showEvery)Show a mark (on STDERR)static voidshowStackTrace(int steps)static voidshowStackTrace(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 ofStringtokens.static java.lang.Stringtabs(int tabs)static java.lang.Stringtail(java.lang.Object o)static java.lang.StringtoByteSize(long l)static voidtoFile(java.lang.String fileName, java.lang.Object obj)Write an object to a filestatic voidtoFile(java.lang.String fileName, java.lang.Object obj, boolean append)Write an object to a filestatic voidtoFileGz(java.lang.String fileName, java.lang.Object obj)Write an object to a file (as a string) Note: The file is compressed using GZIPstatic voidtoFileSerialize(java.lang.String fileName, java.lang.Object obj)Write an object to a file by invoking Serialization methodsstatic voidtoFileSerializeGz(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.StringtoString(boolean[] vals)static java.lang.StringtoString(double val)static java.lang.StringtoString(double[] vals)static java.lang.StringtoString(double[][] vals)static java.lang.StringtoString(int[] vals)static java.lang.StringtoStringHead(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.ClassNotFoundExceptionRead 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.IOExceptionjava.io.FileNotFoundExceptionjava.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 ofStringtokens. 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)
-
-