Package org.snpeff.util

# Class Gpr

java.lang.Object
org.snpeff.util.Gpr

public class Gpr extends Object
General pupose rutines

Author:
  root

## Field Summary

Fields
Modifier and Type
Field
Description
`static final long`
`GB`
`static final String[]`
`GZIP_EXTENTIONS`
`static final String`
`HOME`
`static final long`
`KB`
`static final long`
`MB`
`static final int`
`NUM_CORES`
`static final long`
`TB`

## Constructor Summary

Constructors
Constructor
Description
`Gpr()`

## Method Summary

Modifier and Type
Method
Description
`static String`
`baseName(String file)`
Return file's name (without the path)
`static String`
`baseName(String file, String ext)`
Return file's name (without the path)
`static String`
`bin64(long l)`
Show a long as a 64 bit binary number
`static boolean`
`canRead(String fileName)`
Can we read this file (either exact name or append a '.gz'
`static int`
`compareNull(Comparable c1, Comparable c2)`
`static String`
`compileDate(Class<?> cl)`
`static String`
`compileTimeStamp()`
`static String`
`compileTimeStamp(Class<?> cl)`
Return a time-stamp showing When was the JAR file created OR when was a class compiled
`static String`
`compileTimeStamp(Class<?> cl, SimpleDateFormat dateFormat)`
Return a time-stamp showing When was the JAR file created OR when was a class compiled
`static int`
`countColumns(String file)`
Count number of column in a file
`static int`
`countLines(String file)`
Count lines in a file (same as 'wc -l file' in unix)
`static String`
`dirName(String file)`
Return file's dir
`static boolean`
`exists(String file)`
Does 'file' exist?
`static String`
`extName(String file)`
Get a file's extension (all letters after the last '.'
`static String`
`head(Object o)`
`static StringBuffer`
`inputStream2StringBuffer(InputStream inputStream)`
`static boolean`
`isStdin(String fileName)`
Empty or '-' means STDIN
`static boolean`
`isValidIp(String ip)`
`static boolean`
`isValidRid(int i)`
Is this a valid Rid
`static String`
`noSpaces(String str)`
Remove spaces and tabs from string.
`static boolean`
`parseBoolSafe(String s)`
Equivalent to Boolean.parseBoolean, except it returns 0 on invalid integer (NumberFormatException)
`static double`
`parseDoubleSafe(String s)`
Equivalent to Double.parseDouble(), except it returns 0 on invalid double (NumberFormatException)
`static float`
`parseFloatSafe(String s)`
Equivalent to Float.parseFloat(), except it returns 0 on invalid double (NumberFormatException)
`static int`
`parseIntSafe(String s)`
Equivalent to Integer.parseInt, except it returns 0 on invalid integer (NumberFormatException)
`static long`
`parseLongSafe(String s)`
Equivalent to Integer.parseInt, except it returns 0 on invalid integer (NumberFormatException)
`static String`
`prependEachLine(String prepend, Object lines)`
Prepend a message to each line
`static String`
`read(InputStream is)`
Read an input stream
`static BufferedReader`
`reader(String fileName)`
Try to open a file (BufferedReader) using either the file or a gzip file (appending '.gz' to fileName)
`static BufferedReader`
`reader(String fileName, boolean gzip)`
Try to open a file (BufferedReader) using either the file or a gzip file (appending '.gz' to fileName)
`static String`
`readFile(String fileName)`
Read a file as a String.
`static String`
`readFile(String fileName, boolean gzipped)`
Read a file as a String.
`static Object`
`readFileSerialized(String fileName)`
Read an object from a file (supposing an object was previously serialized to that file)
`static Object`
`readFileSerializedGz(String fileName)`
Read an object from a file (supposing an object was previously serialized to that file) Note: The file is compressed using GZIP
`static Object`
`readFileSerializedGzThrow(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 exceptions
`static String`
`removeBackslashR(String line)`
Remove trailing '\r'
`static String`
`removeExt(String file)`
`static String`
`removeExt(String file, String[] fileExtensions)`
Remove extension from a file (if matches one of 'fileExtensions[]')
`static String`
`repeat(char c, int n)`
Create a string of n time 'c'
`static String`
`sanityzeFileName(String fileName)`
`static String`
`sanityzeName(String fileName)`
`static void`
`showMark(int i, int showEvery)`
Show a mark
`static void`
`showMark(int i, int showEvery, String newLineStr)`
Show a mark
`static 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 steps
`static String[]`
`split(String value, char delim)`
Splits a separated string into an array of `String` tokens.
`static String`
`tabs(int tabs)`
`static String`
`tail(Object o)`
`static String`
`toByteSize(long l)`
`static void`
`toFile(String fileName, Object obj)`
Write an object to a file
`static void`
`toFile(String fileName, Object obj, boolean append)`
Write an object to a file
`static void`
`toFileGz(String fileName, Object obj)`
Write an object to a file (as a string) Note: The file is compressed using GZIP
`static void`
`toFileSerialize(String fileName, Object obj)`
Write an object to a file by invoking Serialization methods
`static void`
`toFileSerializeGz(String fileName, Object obj)`
Write an object to a file by invoking Serialization methods Note: The file is compressed using GZIP
`static String`
`toString(boolean[] vals)`
`static String`
`toString(double val)`
`static String`
`toString(double[] vals)`
`static String`
`toString(double[][] vals)`
`static String`
`toString(int[] vals)`
`static String`
`toStringHead(double[] vals)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### 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 String HOME

### GZIP_EXTENTIONS

public static final String[] GZIP_EXTENTIONS

## Constructor Details

### Gpr

public Gpr()

## Method Details

### baseName

public static String baseName(String file)
Return file's name (without the path)

### baseName

public static String baseName(String file, String ext)
Return file's name (without the path)

### bin64

public static String bin64(long l)
Show a long as a 64 bit binary number

### canRead

public static boolean canRead(String fileName)
Can we read this file (either exact name or append a '.gz'

### compareNull

public static int compareNull(Comparable c1, Comparable c2)

### compileDate

public static String compileDate(Class<?> cl)

### compileTimeStamp

public static String compileTimeStamp()

### compileTimeStamp

public static String compileTimeStamp(Class<?> cl)
Return a time-stamp showing When was the JAR file created OR when was a class compiled

### compileTimeStamp

public static String compileTimeStamp(Class<?> cl, SimpleDateFormat dateFormat)
Return a time-stamp showing When was the JAR file created OR when was a class compiled

### countColumns

public static int countColumns(String file)
Count number of column in a file

### countLines

public static int countLines(String file)
Count lines in a file (same as 'wc -l file' in unix)

Parameters:
  `file` -
Returns:

### dirName

public static String dirName(String file)
Return file's dir

### exists

public static boolean exists(String file)
Does 'file' exist?

### extName

public static String extName(String file)
Get a file's extension (all letters after the last '.'

### head

public static String head(Object o)

### inputStream2StringBuffer

public static StringBuffer inputStream2StringBuffer(InputStream inputStream) throws IOException

Throws:
  `IOException`

### isStdin

public static boolean isStdin(String fileName)
Empty or '-' means STDIN

### isValidIp

public static boolean isValidIp(String ip)

### isValidRid

public static boolean isValidRid(int i)
Is this a valid Rid

### noSpaces

public static String noSpaces(String str)
Remove spaces and tabs from string.

### parseBoolSafe

public static boolean parseBoolSafe(String s)
Equivalent to Boolean.parseBoolean, except it returns 0 on invalid integer (NumberFormatException)

### parseDoubleSafe

public static double parseDoubleSafe(String s)
Equivalent to Double.parseDouble(), except it returns 0 on invalid double (NumberFormatException)

### parseFloatSafe

public static float parseFloatSafe(String s)
Equivalent to Float.parseFloat(), except it returns 0 on invalid double (NumberFormatException)

Parameters:
  `s` -
Returns:
  int

### parseIntSafe

public static int parseIntSafe(String s)
Equivalent to Integer.parseInt, except it returns 0 on invalid integer (NumberFormatException)

Parameters:
  `s` -
Returns:
  int

### parseLongSafe

public static long parseLongSafe(String s)
Equivalent to Integer.parseInt, except it returns 0 on invalid integer (NumberFormatException)

Parameters:
  `s` -
Returns:
  int

### prependEachLine

public static String prependEachLine(String prepend, Object lines)
Prepend a message to each line

### read

public static String read(InputStream is)
Read an input stream

Parameters:
  `is` -
Returns:

### reader

public static BufferedReader reader(String fileName)
Try to open a file (BufferedReader) using either the file or a gzip file (appending '.gz' to fileName)

### reader

public static BufferedReader reader(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 String readFile(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 String readFile(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 Object readFileSerialized(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 Object readFileSerializedGz(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 Object readFileSerializedGzThrow(String fileName) throws FileNotFoundException, IOException, 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:
  `IOException`
  `FileNotFoundException`
  `ClassNotFoundException`

### removeBackslashR

public static String removeBackslashR(String line)
Remove trailing '\r'

### removeExt

public static String removeExt(String file)

### removeExt

public static String removeExt(String file, String[] fileExtensions)
Remove extension from a file (if matches one of 'fileExtensions[]')

### repeat

public static String repeat(char c, int n)
Create a string of n time 'c'

### sanityzeFileName

public static String sanityzeFileName(String fileName)

### sanityzeName

public static String sanityzeName(String fileName)

### showMark

public static void showMark(int i, int showEvery)
Show a mark

### showMark

public static void showMark(int i, int showEvery, 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 String[] split(String value, char delim)
Splits a separated string into an array of `String` 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 String tabs(int tabs)

### tail

public static String tail(Object o)

### toByteSize

public static String toByteSize(long l)

### toFile

public static void toFile(String fileName, Object obj)
Write an object to a file

### toFile

public static void toFile(String fileName, Object obj, boolean append)
Write an object to a file

### toFileGz

public static void toFileGz(String fileName, Object obj)
Write an object to a file (as a string) Note: The file is compressed using GZIP

Parameters:
  `fileName` - : File to write
  `obj` - : Object

### toFileSerialize

public static void toFileSerialize(String fileName, Object obj)
Write an object to a file by invoking Serialization methods

Parameters:
  `fileName` - : File to write
  `obj` - : Object

### toFileSerializeGz

public static void toFileSerializeGz(String fileName, Object obj)
Write an object to a file by invoking Serialization methods Note: The file is compressed using GZIP

Parameters:
  `fileName` - : File to write
  `obj` - : Object

### toString

public static String toString(boolean[] vals)

### toString

public static String toString(double[] vals)

### toString

public static String toString(double[][] vals)

### toString

public static String toString(double val)

### toString

public static String toString(int[] vals)

### toStringHead

public static String toStringHead(double[] vals)