Fixing alignment issue with the GATKReportColumn algorithm

Numeric columns were being left-aligned when they should be right-aligned. Fixed it.
This commit is contained in:
Mauricio Carneiro 2012-03-29 12:27:23 -04:00
parent f80bd4276a
commit cf364f26a0
2 changed files with 34 additions and 32 deletions

View File

@ -213,8 +213,10 @@ public class GATKReportColumn extends LinkedHashMap<Object, Object> {
public Object put(Object key, Object value) { public Object put(Object key, Object value) {
if (value != null) { if (value != null) {
String formatted = formatValue(value); String formatted = formatValue(value);
updateMaxWidth(formatted); if (!formatted.equals("")) {
updateFormat(formatted); updateMaxWidth(formatted);
updateFormat(formatted);
}
} }
return super.put(key, value); return super.put(key, value);
} }
@ -224,7 +226,7 @@ public class GATKReportColumn extends LinkedHashMap<Object, Object> {
} }
private void updateFormat(String formatted) { private void updateFormat(String formatted) {
if (!isRightAlign(formatted)) if (alignment == GATKReportColumnFormat.Alignment.RIGHT)
alignment = GATKReportColumnFormat.Alignment.LEFT; alignment = isRightAlign(formatted) ? GATKReportColumnFormat.Alignment.RIGHT : GATKReportColumnFormat.Alignment.LEFT;
} }
} }

View File

@ -313,7 +313,7 @@ public class RecalDataManager {
* @param read The read to adjust * @param read The read to adjust
* @param RAC The list of shared command line arguments * @param RAC The list of shared command line arguments
*/ */
public static void parseSAMRecord(final GATKSAMRecord read, final RecalibrationArgumentCollection RAC) { public static void parsePlatformForRead(final GATKSAMRecord read, final RecalibrationArgumentCollection RAC) {
GATKSAMReadGroupRecord readGroup = read.getReadGroup(); GATKSAMReadGroupRecord readGroup = read.getReadGroup();
if (RAC.FORCE_PLATFORM != null && (readGroup.getPlatform() == null || !readGroup.getPlatform().equals(RAC.FORCE_PLATFORM))) { if (RAC.FORCE_PLATFORM != null && (readGroup.getPlatform() == null || !readGroup.getPlatform().equals(RAC.FORCE_PLATFORM))) {
@ -337,47 +337,47 @@ public class RecalDataManager {
} }
/** /**
* Parse through the color space of the read and add a new tag to the SAMRecord that says which bases are inconsistent with the color space * Parse through the color space of the read and add a new tag to the SAMRecord that says which bases are
* inconsistent with the color space. If there is no call in the color space, this method returns true meaning
* this read should be skipped
* *
* @param read The SAMRecord to parse * @param strategy the strategy used for SOLID no calls
* @param read The SAMRecord to parse
* @return whether or not this read should be skipped
*/ */
public static void parseColorSpace(final GATKSAMRecord read) { public static boolean checkColorSpace(final SOLID_NOCALL_STRATEGY strategy, final GATKSAMRecord read) {
if (ReadUtils.isSOLiDRead(read)) { // If this is a SOLID read then we have to check if the color space is inconsistent. This is our only sign that SOLID has inserted the reference base
// If this is a SOLID read then we have to check if the color space is inconsistent. This is our only sign that SOLID has inserted the reference base if (read.getAttribute(RecalDataManager.COLOR_SPACE_INCONSISTENCY_TAG) == null) { // Haven't calculated the inconsistency array yet for this read
if (ReadUtils.isSOLiDRead(read)) {
if (read.getAttribute(RecalDataManager.COLOR_SPACE_INCONSISTENCY_TAG) == null) { // Haven't calculated the inconsistency array yet for this read
final Object attr = read.getAttribute(RecalDataManager.COLOR_SPACE_ATTRIBUTE_TAG); final Object attr = read.getAttribute(RecalDataManager.COLOR_SPACE_ATTRIBUTE_TAG);
if (attr != null) { if (attr != null) {
byte[] colorSpace; byte[] colorSpace;
if (attr instanceof String) { if (attr instanceof String)
colorSpace = ((String) attr).getBytes(); colorSpace = ((String) attr).getBytes();
} else
else {
throw new UserException.MalformedBAM(read, String.format("Value encoded by %s in %s isn't a string!", RecalDataManager.COLOR_SPACE_ATTRIBUTE_TAG, read.getReadName())); throw new UserException.MalformedBAM(read, String.format("Value encoded by %s in %s isn't a string!", RecalDataManager.COLOR_SPACE_ATTRIBUTE_TAG, read.getReadName()));
}
// Loop over the read and calculate first the inferred bases from the color and then check if it is consistent with the read byte[] readBases = read.getReadBases(); // Loop over the read and calculate first the inferred bases from the color and then check if it is consistent with the read
byte[] readBases = read.getReadBases(); if (read.getReadNegativeStrandFlag())
if (read.getReadNegativeStrandFlag()) {
readBases = BaseUtils.simpleReverseComplement(read.getReadBases()); readBases = BaseUtils.simpleReverseComplement(read.getReadBases());
}
final byte[] inconsistency = new byte[readBases.length]; final byte[] inconsistency = new byte[readBases.length];
int iii; int i;
byte prevBase = colorSpace[0]; // The sentinel byte prevBase = colorSpace[0]; // The sentinel
for (iii = 0; iii < readBases.length; iii++) { for (i = 0; i < readBases.length; i++) {
final byte thisBase = getNextBaseFromColor(read, prevBase, colorSpace[iii + 1]); final byte thisBase = getNextBaseFromColor(read, prevBase, colorSpace[i + 1]);
inconsistency[iii] = (byte) (thisBase == readBases[iii] ? 0 : 1); inconsistency[i] = (byte) (thisBase == readBases[i] ? 0 : 1);
prevBase = readBases[iii]; prevBase = readBases[i];
} }
read.setAttribute(RecalDataManager.COLOR_SPACE_INCONSISTENCY_TAG, inconsistency); read.setAttribute(RecalDataManager.COLOR_SPACE_INCONSISTENCY_TAG, inconsistency);
}
else if (strategy == SOLID_NOCALL_STRATEGY.THROW_EXCEPTION) // if the strategy calls for an exception, throw it
throw new UserException.MalformedBAM(read, "Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() + " Unfortunately this .bam file can not be recalibrated without color space information because of potential reference bias.");
} else
else { return false; // otherwise, just skip the read
throw new UserException.MalformedBAM(read, "Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() +
" Unfortunately this .bam file can not be recalibrated without color space information because of potential reference bias.");
}
} }
} }
return true;
} }
/** /**