Search in sources :

Example 91 with GATKException

use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.

the class SVVCFWriter method writeVariants.

private static void writeVariants(final PipelineOptions pipelineOptions, final String fileName, final List<VariantContext> variantsArrayList, final SAMSequenceDictionary referenceSequenceDictionary) {
    try (final OutputStream outputStream = new BufferedOutputStream(BucketUtils.createFile(fileName))) {
        final VariantContextWriter vcfWriter = getVariantContextWriter(outputStream, referenceSequenceDictionary);
        vcfWriter.writeHeader(getVcfHeader(referenceSequenceDictionary));
        variantsArrayList.forEach(vcfWriter::add);
        vcfWriter.close();
    } catch (final IOException e) {
        throw new GATKException("Could not create output file", e);
    }
}
Also used : OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) IOException(java.io.IOException) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 92 with GATKException

use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.

the class RunSGAViaProcessBuilderOnSpark method loadFASTQFiles.

/**
     * Load the FASTQ files in the user specified directory and returns an RDD that satisfies the same requirement
     * as described in {@link JavaSparkContext#wholeTextFiles(String, int)}.
     * @param ctx
     * @param pathToAllInterleavedFASTQFiles path to the directory where all FASTQ files to perform local assembly upon are located
     * @throws GATKException when getting the file count in the specified directory
     * @return
     */
private static JavaPairRDD<String, String> loadFASTQFiles(final JavaSparkContext ctx, final String pathToAllInterleavedFASTQFiles) {
    try {
        final FileSystem hadoopFileSystem = FileSystem.get(ctx.hadoopConfiguration());
        final ContentSummary cs = hadoopFileSystem.getContentSummary(new org.apache.hadoop.fs.Path(pathToAllInterleavedFASTQFiles));
        final int fileCount = (int) cs.getFileCount();
        return ctx.wholeTextFiles(pathToAllInterleavedFASTQFiles, fileCount);
    } catch (final IOException e) {
        throw new GATKException(e.getMessage());
    }
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) ContentSummary(org.apache.hadoop.fs.ContentSummary) IOException(java.io.IOException) GATKException(org.broadinstitute.hellbender.exceptions.GATKException)

Example 93 with GATKException

use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.

the class SVFastqUtils method readFastqFile.

public static List<FastqRead> readFastqFile(final String fileName) {
    // absolute guess, just something not too crazy small
    final int INITIAL_CAPACITY = 10000;
    final List<FastqRead> reads = new ArrayList<>(INITIAL_CAPACITY);
    try (final BufferedReader reader = new BufferedReader(new InputStreamReader(BucketUtils.openFile(fileName)))) {
        String seqIdLine;
        int lineNo = 0;
        while ((seqIdLine = reader.readLine()) != null) {
            lineNo += 1;
            if (seqIdLine.length() < 1 || seqIdLine.charAt(0) != '@') {
                throw new GATKException("In FASTQ file " + fileName + " sequence identifier line does not start with @ on line " + lineNo);
            }
            final String callLine = reader.readLine();
            lineNo += 1;
            if (callLine == null) {
                throw new GATKException("In FASTQ file " + fileName + " file truncated: missing calls.");
            }
            final String sepLine = reader.readLine();
            lineNo += 1;
            if (sepLine == null) {
                throw new GATKException("In FASTQ file " + fileName + " file truncated: missing + line.");
            }
            if (sepLine.length() < 1 || sepLine.charAt(0) != '+') {
                throw new GATKException("In FASTQ file " + fileName + " separator line does not start with + on line " + lineNo);
            }
            final String qualLine = reader.readLine();
            lineNo += 1;
            if (qualLine == null) {
                throw new GATKException("In FASTQ file " + fileName + " file truncated: missing quals.");
            }
            if (callLine.length() != qualLine.length()) {
                throw new GATKException("In FASTQ file " + fileName + " there are " + qualLine.length() + " quality scores on line " + lineNo + " but there are " + callLine.length() + " base calls.");
            }
            final byte[] quals = qualLine.getBytes();
            SAMUtils.fastqToPhred(quals);
            reads.add(new FastqRead(seqIdLine.substring(1), callLine.getBytes(), quals));
        }
    } catch (final IOException ioe) {
        throw new GATKException("Can't read " + fileName, ioe);
    }
    return reads;
}
Also used : ArrayList(java.util.ArrayList) GATKException(org.broadinstitute.hellbender.exceptions.GATKException)

Example 94 with GATKException

use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.

the class IntegrationTestSpec method executeTest.

public void executeTest(final String name, CommandLineProgramTester test) throws IOException {
    List<File> tmpFiles = new ArrayList<>();
    for (int i = 0; i < nOutputFiles; i++) {
        String ext = DEFAULT_TEMP_EXTENSION;
        File fl = BaseTest.createTempFile(String.format(DEFAULT_TEMP_PREFIX + ".%d", i), ext);
        tmpFiles.add(fl);
    }
    final String preFormattedArgs = getArgs();
    final String formattedArgs = String.format(preFormattedArgs, tmpFiles.toArray());
    System.out.println(StringUtils.repeat('-', 80));
    if (expectsException()) {
        // this branch handles the case were we are testing that a walker will fail as expected
        executeTest(name, test, null, null, tmpFiles, formattedArgs, getExpectedException());
    } else {
        final List<String> expectedFileNames = new ArrayList<>(expectedFileNames());
        if (!expectedFileNames.isEmpty() && preFormattedArgs.equals(formattedArgs)) {
            throw new GATKException("Incorrect test specification - you're expecting " + expectedFileNames.size() + " file(s) the specified arguments do not contain the same number of \"%s\" placeholders");
        }
        executeTest(name, test, null, expectedFileNames, tmpFiles, formattedArgs, null);
    }
}
Also used : ArrayList(java.util.ArrayList) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) File(java.io.File)

Example 95 with GATKException

use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.

the class TextFormattingUtils method splitFixedWidth.

/**
     * Parses a fixed width line of text.
     * @param line Text to parse.
     * @param columnStarts the column starting positions within line, excluding the first position 0.
     * @return The parsed string array with each entry trimmed.
     */
public static String[] splitFixedWidth(String line, List<Integer> columnStarts) {
    if (line == null)
        throw new GATKException("line is null");
    if (columnStarts == null)
        throw new GATKException("columnStarts is null");
    int startCount = columnStarts.size();
    String[] row = new String[startCount + 1];
    if (startCount == 0) {
        row[0] = line.trim();
    } else {
        row[0] = line.substring(0, columnStarts.get(0)).trim();
        for (int i = 1; i < startCount; i++) row[i] = line.substring(columnStarts.get(i - 1), columnStarts.get(i)).trim();
        row[startCount] = line.substring(columnStarts.get(startCount - 1)).trim();
    }
    return row;
}
Also used : GATKException(org.broadinstitute.hellbender.exceptions.GATKException)

Aggregations

GATKException (org.broadinstitute.hellbender.exceptions.GATKException)96 IOException (java.io.IOException)19 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)13 CigarElement (htsjdk.samtools.CigarElement)12 ArrayList (java.util.ArrayList)10 UserException (org.broadinstitute.hellbender.exceptions.UserException)10 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)8 Cigar (htsjdk.samtools.Cigar)7 File (java.io.File)6 SAMFileHeader (htsjdk.samtools.SAMFileHeader)5 OutputStream (java.io.OutputStream)5 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Utils (org.broadinstitute.hellbender.utils.Utils)4 Tuple2 (scala.Tuple2)4 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)3 BufferedOutputStream (java.io.BufferedOutputStream)3 InputStream (java.io.InputStream)3 BigInteger (java.math.BigInteger)3 java.util (java.util)3