Addressing Eric's comments

-- added @param docs to the new variables
-- made all variables final
-- switched to string builder instead of String for performance.

GSATDG-83
This commit is contained in:
Mauricio Carneiro 2013-02-25 13:33:47 -05:00
parent 9e5a31b595
commit 0ff3343282
1 changed files with 12 additions and 6 deletions

View File

@ -626,21 +626,27 @@ public class ReduceReads extends ReadWalker<ObjectArrayList<GATKSAMRecord>, Redu
* Compresses the read name using the readNameHash if we have already compressed * Compresses the read name using the readNameHash if we have already compressed
* this read name before. * this read name before.
* *
* @param read any read * @param hash the hash table containing the read name to compressed read name map
* @param read any read
* @param nextReadNumber the number to use in the compressed read name in case this is a new read name
* @return the next number to use in the compressed read name
*/ */
protected static long compressReadName(Object2LongOpenHashMap<String> hash, GATKSAMRecord read, long nextReadNumber) { protected static long compressReadName(final Object2LongOpenHashMap<String> hash, final GATKSAMRecord read, final long nextReadNumber) {
final String name = read.getReadName(); final String name = read.getReadName();
final StringBuilder compressedName = new StringBuilder();
long result = nextReadNumber; long result = nextReadNumber;
String compressedName = read.isReducedRead() ? "C" : ""; if (read.isReducedRead()) {
compressedName.append("C");
}
final Long readNumber = hash.get(name); final Long readNumber = hash.get(name);
if (readNumber != null) { if (readNumber != null) {
compressedName += readNumber.toString(); compressedName.append(readNumber);
} else { } else {
hash.put(name, nextReadNumber); hash.put(name, nextReadNumber);
compressedName += "" + nextReadNumber; compressedName.append(nextReadNumber);
result++; result++;
} }
read.setReadName(compressedName); read.setReadName(compressedName.toString());
return result; return result;
} }