1 package org.broadinstitute.hellbender.tools.walkers.haplotypecaller; 2 3 import org.broadinstitute.hellbender.exceptions.UserException; 4 import org.broadinstitute.hellbender.utils.io.IOUtils; 5 6 import java.io.IOException; 7 import java.io.PrintStream; 8 import java.nio.file.Files; 9 10 /** 11 * A short helper class that manages a singleton debug stream for HaplotypeCaller genotyping information that is useful for debugging. 12 * 13 * In order to use simply call initialize() providing a location for an output path, then call isEnabled() to evaluate if the processing 14 * for printing debug statements should be performed, and call println() to output to the file in a synchronized fashion. 15 */ 16 public class HaplotypeCallerGenotypingDebugger{ 17 private static PrintStream genotyperDebugOutStream; 18 initialize(final String debugLocation)19 public static void initialize(final String debugLocation) { 20 try { 21 genotyperDebugOutStream = new PrintStream(Files.newOutputStream(IOUtils.getPath(debugLocation))); 22 } catch (IOException e) { 23 throw new UserException.CouldNotCreateOutputFile(debugLocation, "Provided argument for genotyper debug location could not be created"); 24 } 25 } 26 27 // Is the debugger enabled isEnabled()28 public static boolean isEnabled() { 29 return genotyperDebugOutStream != null; 30 } 31 32 // Print the provided text to the debugger if it exists println(final String debug)33 public static synchronized void println(final String debug) { 34 if (genotyperDebugOutStream != null) { 35 genotyperDebugOutStream.println(debug); 36 } 37 } 38 39 // Closes out the debug output stream if necessary close()40 public static void close() { 41 if (genotyperDebugOutStream != null) { 42 genotyperDebugOutStream.close(); 43 } 44 } 45 } 46