use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class GATKReport method addRow.
/**
* This method provides an efficient way to populate a simplified GATK report. This method will only work on reports
* that qualify as simplified GATK reports. See the newSimpleReport() constructor for more information.
*
* @param values the row of data to be added to the table.
* Note: the number of arguments must match the columns in the table.
*/
public void addRow(final Object... values) {
// Must be a simple report
if (tables.size() != 1)
throw new GATKException("Cannot write a row to a complex GATK Report");
GATKReportTable table = tables.firstEntry().getValue();
if (table.getNumColumns() != values.length)
throw new GATKException("The number of arguments in writeRow (" + values.length + ") must match the number of columns in the table (" + table.getNumColumns() + ")");
final int rowIndex = table.getNumRows();
for (int i = 0; i < values.length; i++) table.set(rowIndex, i, values[i]);
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class GATKReportTable method write.
/**
* Write the table to the PrintStream, formatted nicely to be human-readable, AWK-able, and R-friendly.
*
* @param out the PrintStream to which the table should be written
* @param sortingWay how to sort the table
*/
void write(final PrintStream out, Sorting sortingWay) {
/*
* Table header:
* #:GATKTable:nColumns:nRows:(DataType for each column):;
* #:GATKTable:TableName:Description :;
* key colA colB
* row1 xxxx xxxxx
*/
// write the table definition
out.printf(GATKTABLE_HEADER_PREFIX + ":%d:%d", getNumColumns(), getNumRows());
// write the formats for all the columns
for (final GATKReportColumn column : columnInfo) out.print(SEPARATOR + column.getFormat());
out.println(ENDLINE);
// write the table name & description
out.printf(GATKTABLE_HEADER_PREFIX + ":%s:%s\n", tableName, tableDescription);
// write the column names
boolean needsPadding = false;
for (final GATKReportColumn column : columnInfo) {
if (needsPadding)
out.printf(" ");
needsPadding = true;
out.printf(column.getColumnFormat().getNameFormat(), column.getColumnName());
}
out.println();
// write the table body
switch(sortingWay) {
case SORT_BY_COLUMN:
Collections.sort(underlyingData, ROW_COMPARATOR);
for (final Object[] row : underlyingData) {
writeRow(out, row);
}
break;
case SORT_BY_ROW:
// make sure that there are exactly the correct number of ID mappings
if (rowIdToIndex.size() != underlyingData.size())
throw new GATKException("There isn't a 1-to-1 mapping from row ID to index; this can happen when rows are not created consistently");
final TreeMap<Object, Integer> sortedMap;
try {
sortedMap = new TreeMap<>(rowIdToIndex);
} catch (ClassCastException e) {
throw new GATKException("Unable to sort the rows based on the row IDs because the ID Objects are of different types");
}
for (final Map.Entry<Object, Integer> rowKey : sortedMap.entrySet()) writeRow(out, underlyingData.get(rowKey.getValue()));
break;
case DO_NOT_SORT:
for (final Object[] row : underlyingData) writeRow(out, row);
}
out.println();
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class GATKReportTable method increment.
/**
* Increment the value for a given position in the table.
* Throws an exception if the value in the cell is not an integer.
*
* @param rowID the row ID
* @param columnName the name of the column
*/
public void increment(final Object rowID, final String columnName) {
int prevValue;
if (!rowIdToIndex.containsKey(rowID)) {
rowIdToIndex.put(rowID, underlyingData.size());
underlyingData.add(new Object[getNumColumns()]);
prevValue = 0;
} else {
Object obj = get(rowID, columnName);
if (!(obj instanceof Integer))
throw new GATKException("Attempting to increment a value in a cell that is not an integer");
prevValue = (Integer) obj;
}
set(rowIdToIndex.get(rowID), columnNameToIndex.get(columnName), prevValue + 1);
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class BaseRecalibrationEngine method calculateIsSNPOrIndel.
/**
* Locates all SNP and indel events, storing them in the provided snp, isIns, and isDel arrays, and returns
* the total number of SNP/indel events.
*
* @param read read to inspect
* @param ref source of reference bses
* @param snp storage for snp events (must be of length read.getBases().length and initialized to all 0's)
* @param isIns storage for insertion events (must be of length read.getBases().length and initialized to all 0's)
* @param isDel storage for deletion events (must be of length read.getBases().length and initialized to all 0's)
* @return the total number of SNP and indel events
*/
protected static int calculateIsSNPOrIndel(final GATKRead read, final ReferenceDataSource ref, int[] snp, int[] isIns, int[] isDel) {
final byte[] refBases = ref.queryAndPrefetch(read.getContig(), read.getStart(), read.getEnd()).getBases();
int readPos = 0;
int refPos = 0;
int nEvents = 0;
for (final CigarElement ce : read.getCigarElements()) {
final int elementLength = ce.getLength();
switch(ce.getOperator()) {
case M:
case EQ:
case X:
for (int i = 0; i < elementLength; i++) {
int snpInt = (BaseUtils.basesAreEqual(read.getBase(readPos), refBases[refPos]) ? 0 : 1);
snp[readPos] = snpInt;
nEvents += snpInt;
readPos++;
refPos++;
}
break;
case D:
{
final int index = (read.isReverseStrand() ? readPos : readPos - 1);
updateIndel(isDel, index);
refPos += elementLength;
break;
}
case N:
refPos += elementLength;
break;
case I:
{
final boolean forwardStrandRead = !read.isReverseStrand();
if (forwardStrandRead) {
updateIndel(isIns, readPos - 1);
}
readPos += elementLength;
if (!forwardStrandRead) {
updateIndel(isIns, readPos);
}
break;
}
case // ReferenceContext doesn't have the soft clipped bases!
S:
readPos += elementLength;
break;
case H:
case P:
break;
default:
throw new GATKException("Unsupported cigar operator: " + ce.getOperator());
}
}
// we don't sum those as we go because they might set the same place to 1 twice
nEvents += MathUtils.sum(isDel) + MathUtils.sum(isIns);
return nEvents;
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class ReadEndsForMarkDuplicatesCodec method decode.
@Override
public ReadEndsForMarkDuplicates decode() {
final ReadEndsForMarkDuplicates read = new ReadEndsForMarkDuplicates();
try {
// If the first read results in an EOF we've exhausted the stream
try {
read.score = this.in.readShort();
} catch (final EOFException eof) {
return null;
}
read.libraryId = this.in.readShort();
read.orientation = this.in.readByte();
read.read1ReferenceIndex = this.in.readInt();
read.read1Coordinate = this.in.readInt();
read.read1IndexInFile = this.in.readLong();
read.read2ReferenceIndex = this.in.readInt();
if (read.orientation > ReadEnds.R) {
read.read2Coordinate = this.in.readInt();
read.read2IndexInFile = this.in.readLong();
}
read.readGroup = this.in.readShort();
read.tile = this.in.readShort();
read.x = this.in.readShort();
read.y = this.in.readShort();
read.orientationForOpticalDuplicates = this.in.readByte();
return read;
} catch (final IOException ioe) {
throw new GATKException("Exception writing ReadEnds to file.", ioe);
}
}
Aggregations