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);
}
}
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());
}
}
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;
}
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);
}
}
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;
}
Aggregations