use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class HDF5PCACoveragePoN method readMatrixAndCheckDimensions.
/**
* Reads a matrix from the underlying PoN file and check its dimensions.
* @param fullPath the target data-set full path within the HDF5 file.
* @param expectedRowCount a predicate that returns true iff its argument is an expected number of rows.
* @param expectedColumnCount a predicate that returns true iff its argument is an expected number of columns.
* @return GATKException if the result matrix dimensions do not match the expectations or
* any other cause as described in {@link #readMatrix(String)}.
*/
private RealMatrix readMatrixAndCheckDimensions(final String fullPath, final IntPredicate expectedRowCount, final IntPredicate expectedColumnCount) {
final RealMatrix result = readMatrix(fullPath);
if (expectedRowCount.test(result.getRowDimension()) && expectedColumnCount.test(result.getColumnDimension())) {
return result;
}
final RealMatrix transpose = result.transpose();
if (!expectedRowCount.test(transpose.getRowDimension())) {
throw new GATKException(String.format("wrong number of rows in '%s' matrix from file '%s': %d", fullPath, file.getFile(), result.getRowDimension()));
}
if (!expectedColumnCount.test(transpose.getColumnDimension())) {
throw new GATKException(String.format("wrong number of columns in '%s' from file '%s': %d", fullPath, file.getFile(), result.getColumnDimension()));
}
return transpose;
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class GATKReportTable method concat.
/**
* Concatenates the rows from the table to this one
*
* @param table another GATK table
*/
public void concat(final GATKReportTable table) {
if (!isSameFormat(table))
throw new GATKException("Error trying to concatenate tables with different formats");
// add the data
underlyingData.addAll(table.underlyingData);
// update the row index map
final int currentNumRows = getNumRows();
for (Map.Entry<Object, Integer> entry : table.rowIdToIndex.entrySet()) rowIdToIndex.put(entry.getKey(), entry.getValue() + currentNumRows);
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class PedReader method parse.
public final List<Sample> parse(Reader reader, EnumSet<MissingPedField> missingFields, SampleDB sampleDB) {
// Determine field position ordinals
final int familyPos = missingFields.contains(MissingPedField.NO_FAMILY_ID) ? -1 : 0;
final int samplePos = familyPos + 1;
final int paternalPos = missingFields.contains(MissingPedField.NO_PARENTS) ? -1 : samplePos + 1;
final int maternalPos = missingFields.contains(MissingPedField.NO_PARENTS) ? -1 : paternalPos + 1;
final int sexPos = missingFields.contains(MissingPedField.NO_SEX) ? -1 : Math.max(maternalPos, samplePos) + 1;
final int phenotypePos = missingFields.contains(MissingPedField.NO_PHENOTYPE) ? -1 : Math.max(sexPos, Math.max(maternalPos, samplePos)) + 1;
final int nExpectedFields = IntStream.of(samplePos, paternalPos, maternalPos, sexPos, phenotypePos).max().getAsInt() + 1;
List<String> lines;
try (final XReadLines sourceReader = new XReadLines(reader, false, commentMarker)) {
lines = sourceReader.readLines();
} catch (IOException e) {
throw new UserException.CouldNotReadInputFile("Error reading pedigree input");
}
final List<String[]> lineParts = splitLines(reader, lines, nExpectedFields);
boolean isQT = isQT(lineParts, phenotypePos);
int lineNo = 1;
final List<Sample> samples = new ArrayList<>(lineParts.size());
for (final String[] parts : lineParts) {
String individualID = parts[samplePos];
String familyID = familyPos == -1 ? null : maybeMissing(parts[familyPos]);
String paternalID = paternalPos == -1 ? null : maybeMissing(parts[paternalPos]);
String maternalID = maternalPos == -1 ? null : maybeMissing(parts[maternalPos]);
Sex sex = determineSex(parts, sexPos);
Affection affection = Affection.UNKNOWN;
String quantitativePhenotype = null;
if (phenotypePos != -1) {
if (isQT) {
if (parts[phenotypePos].equals(MISSING_VALUE1)) {
affection = Affection.UNKNOWN;
} else {
affection = Affection.OTHER;
quantitativePhenotype = parts[phenotypePos];
}
} else {
switch(parts[phenotypePos]) {
case MISSING_VALUE1:
affection = Affection.UNKNOWN;
break;
case MISSING_VALUE2:
affection = Affection.UNKNOWN;
break;
case PHENOTYPE_UNAFFECTED:
affection = Affection.UNAFFECTED;
break;
case PHENOTYPE_AFFECTED:
affection = Affection.AFFECTED;
break;
default:
throw new GATKException("Unexpected phenotype type " + parts[phenotypePos] + " at line " + lineNo);
}
}
}
final Sample s = new Sample(individualID, familyID, paternalID, maternalID, sex, affection);
samples.add(s);
sampleDB.addSample(s);
lineNo++;
}
for (final Sample sample : new ArrayList<>(samples)) {
final Sample dad = maybeAddImplicitSample(sampleDB, sample.getPaternalID(), sample.getFamilyID(), Sex.MALE);
if (dad != null) {
samples.add(dad);
}
final Sample mom = maybeAddImplicitSample(sampleDB, sample.getMaternalID(), sample.getFamilyID(), Sex.FEMALE);
if (mom != null) {
samples.add(mom);
}
}
return samples;
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class RecalUtils method generateCsv.
/**
* Prints out a collection of reports into a file in Csv format in a way
* that can be used by R scripts (such as the plot generator script).
* <p/>
* The set of covariates is take as the minimum common set from all reports.
*
* @param out the output file. It will be overridden.
* @param reports map where keys are the unique 'mode' (ORIGINAL, RECALIBRATED, ...)
* of each report and the corresponding value the report itself.
* @throws FileNotFoundException if <code>out</code> could not be created anew.
*/
public static void generateCsv(final File out, final Map<String, RecalibrationReport> reports) throws FileNotFoundException {
if (reports.isEmpty()) {
throw new GATKException("no reports");
}
final RecalibrationReport firstReport = reports.values().iterator().next();
final StandardCovariateList covariates = firstReport.getCovariates();
writeCsv(out, reports, covariates);
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class MultiHitAlignedReadIterator method nextMaybeEmpty.
private HitsForInsert nextMaybeEmpty() {
Utils.validate(peekIterator.hasNext(), "iterator has no next");
final String readName = peekIterator.peek().getReadName();
final HitsForInsert hits = new HitsForInsert();
Boolean isPaired = null;
// Accumulate the alignments matching readName.
do {
final SAMRecord rec = peekIterator.next();
replaceHardWithSoftClips(rec);
// if the aligned input needs to be sorted.
if (peekIterator.hasNext() && queryNameComparator.fileOrderCompare(rec, peekIterator.peek()) > 0) {
throw new IllegalStateException("Underlying iterator is not queryname sorted: " + rec + " > " + peekIterator.peek());
}
if (isPaired == null) {
isPaired = rec.getReadPairedFlag();
} else if (isPaired != rec.getReadPairedFlag()) {
throw new GATKException("Got a mix of paired and unpaired alignments for read " + readName);
}
// been determined, and then re-added into the process later
if (!rec.getReadPairedFlag() || rec.getFirstOfPairFlag()) {
if (rec.getSupplementaryAlignmentFlag()) {
hits.addSupplementalFirstOfPairOrFragment(rec);
} else {
hits.addFirstOfPairOrFragment(rec);
}
} else if (rec.getSecondOfPairFlag()) {
if (rec.getSupplementaryAlignmentFlag()) {
hits.addSupplementalSecondOfPair(rec);
} else {
hits.addSecondOfPair(rec);
}
} else
throw new GATKException("Read is marked as pair but neither first or second: " + readName);
} while (peekIterator.hasNext() && peekIterator.peek().getReadName().equals(readName));
// If there is no more than one alignment for each end, no need to do any coordination.
if (hits.numHits() <= 1) {
// No HI tags needed if only a single hit
if (hits.getFirstOfPair(0) != null) {
hits.getFirstOfPair(0).setAttribute(SAMTag.HI.name(), null);
hits.getFirstOfPair(0).setNotPrimaryAlignmentFlag(false);
}
if (hits.getSecondOfPair(0) != null) {
hits.getSecondOfPair(0).setAttribute(SAMTag.HI.name(), null);
hits.getSecondOfPair(0).setNotPrimaryAlignmentFlag(false);
}
} else {
primaryAlignmentSelectionStrategy.pickPrimaryAlignment(hits);
}
// Used to check that alignments for first and second were correlated, but this is no longer required.
return hits;
}
Aggregations