Package kmer.core
Class KMerUtils
java.lang.Object
kmer.core.KMerUtils
An assortment of utility methods useful for counting k-mers.
- Author:
- Dennis Cosgrove (http://www.cse.wustl.edu/~cosgroved/)
-
Method Summary
Modifier and TypeMethodDescriptionstatic longcalculatePossibleKMers(int k)Gets the number of possible k-mers that can exist with the given length.static intcalculateSumOfAllKMers(List<byte[]> sequences, int k)Gets the total number of (not necessarily unique) k-mers in all of the sequences.static intcreateIntCMask(int k)static intcreateIntGMask(int k)static intcreateIntTMask(int k)static longcreateLongCMask(int k)static longcreateLongGMask(int k)static longcreateLongTMask(int k)static byte[]nextRandom(int k)static intshiftAndUpdateLastBaseIndexOfPackedInt(int prev, byte[] sequence, int offset, int k, int T_MASK, int C_MASK, int G_MASK)static longshiftAndUpdateLastBaseIndexOfPackedLong(long prev, byte[] sequence, int offset, int k, long T_MASK, long C_MASK, long G_MASK)static inttoArrayLength(long possibleKMers)static ByteArrayRangetoByteArrayRange(byte[] kMer)static ByteArrayRangetoByteArrayRange(byte[] sequence, int offset, int k)static byte[]static byte[]toBytes(ByteArrayRange range)static inttoPackedInt(byte[] kMer)Packs the entire k-mer into an int.static inttoPackedInt(byte[] sequence, int offset, int k)"Packs" a k-mer into an int.static longtoPackedLong(byte[] sequence)Packs the entire k-mer into a long.static longtoPackedLong(byte[] sequence, int offset, int k)"Packs" a k-mer into a long.static StringtoString(byte[] kMer)Converts the given k-mer (represented as an array of bytes) into a human-readable String.static StringtoString(byte[] sequence, int offset, int k)Stores the information from the given sequence into a String.static byte[]unpackInt(int kMer, int k)Unpacks the k-mer from an integer back to an array of bytes.static byte[]unpackLong(long kMer, int k)Unpacks the k-mer from a long back to an array of bytes.
-
Method Details
-
toString
Stores the information from the given sequence into a String. For example, if you had the sequence, "ACCTGTCAAAA" and you called this method with an offset of 1 and a k of 4, it would return "CCTG".- Parameters:
sequence- the sequence of nucleobases to draw the bytes fromoffset- the offset for where to start looking for bytesk- the length of the k-mer to make a String for- Returns:
- a String representation of the k-mer at the desired position
-
toString
Converts the given k-mer (represented as an array of bytes) into a human-readable String. For example, if you had the k-mer, {'C', 'C', 'T', 'G'}, this method would return "CCTG".- Parameters:
kMer- the k-mer to generate a String for.- Returns:
- the k-mer's String reprentation
-
toBytes
-
toByteArrayRange
-
toByteArrayRange
-
toBytes
-
toPackedInt
public static int toPackedInt(byte[] sequence, int offset, int k)"Packs" a k-mer into an int. The bits of the int will be used to store individual nucleobases.- Parameters:
sequence- a sequence of nucleobasesoffset- the index of the first nucleobase in the desired k-merk- the length of the desired k-mer- Returns:
- an integer uniquely representing this k-mer
-
toPackedInt
public static int toPackedInt(byte[] kMer)Packs the entire k-mer into an int. Exactly liketoPackedInt(byte[], int, int), but treats the whole array as a single k-mer.- Parameters:
kMer- the k-mer represented as an array of bytes- Returns:
- an integer uniquely representing this k-mer
-
unpackInt
public static byte[] unpackInt(int kMer, int k)Unpacks the k-mer from an integer back to an array of bytes.- Parameters:
kMer- an integer uniquely identifying a k-merk- the length of the k-mer packed in the integer- Returns:
- an array of bytes representing the same k-mer
-
toPackedLong
public static long toPackedLong(byte[] sequence, int offset, int k)"Packs" a k-mer into a long. The bits of the long will be used to store individual nucleobases.- Parameters:
sequence- a sequence of nucleobasesoffset- the index of the first nucleobase in the desired k-merk- the length of the desired k-mer- Returns:
- a long integer uniquely representing this k-mer
-
toPackedLong
public static long toPackedLong(byte[] sequence)Packs the entire k-mer into a long. Exactly liketoPackedLong(byte[], int, int), but treats the whole array as a single k-mer.- Parameters:
sequence- the k-mer represented as an array of bytes- Returns:
- a long integer uniquely representing this k-mer
-
unpackLong
public static byte[] unpackLong(long kMer, int k)Unpacks the k-mer from a long back to an array of bytes.- Parameters:
kMer- a long integer uniquely identifying a k-merk- the length of the k-mer packed in the long- Returns:
- an array of bytes representing the same k-mer
-
createIntTMask
public static int createIntTMask(int k) -
createIntCMask
public static int createIntCMask(int k) -
createIntGMask
public static int createIntGMask(int k) -
createLongTMask
public static long createLongTMask(int k) -
createLongCMask
public static long createLongCMask(int k) -
createLongGMask
public static long createLongGMask(int k) -
shiftAndUpdateLastBaseIndexOfPackedInt
public static int shiftAndUpdateLastBaseIndexOfPackedInt(int prev, byte[] sequence, int offset, int k, int T_MASK, int C_MASK, int G_MASK) -
shiftAndUpdateLastBaseIndexOfPackedLong
public static long shiftAndUpdateLastBaseIndexOfPackedLong(long prev, byte[] sequence, int offset, int k, long T_MASK, long C_MASK, long G_MASK) -
nextRandom
public static byte[] nextRandom(int k) -
calculatePossibleKMers
public static long calculatePossibleKMers(int k)Gets the number of possible k-mers that can exist with the given length. Note that all possible k-mers with the desired length can be represented by the integers from 0 (inclusive) to the result of this method (exclusive).- Parameters:
k- the k in k-mer- Returns:
- the number of possible k-mers that could exist with the given length
-
calculateSumOfAllKMers
Gets the total number of (not necessarily unique) k-mers in all of the sequences. If a single sequence is given, this method will return n - k + 1.- Parameters:
sequences- a list of sequences of nucleobasesk- the k in k-mer- Returns:
- the sum of all k-mer counts
-
toArrayLength
public static int toArrayLength(long possibleKMers)
-