// Path: src/edu/unc/genomics/CommandLineTool.java
// public abstract class CommandLineTool {
// 
//   /**
//    * The default bite-size to use for applications that process files in chunks
//    * TODO Read from a configuration file
//    */
//   public static final int DEFAULT_CHUNK_SIZE = 10_000_000;
// 
//   /**
//    * Do the main computation of this tool
//    * 
//    * @throws IOException
//    */
//   public abstract void run() throws IOException;
// 
//   /**
//    * Parse command-line arguments and run the tool Exit on parameter exceptions
//    * 
//    * @param args
//    */
//   public void instanceMain(String[] args) throws CommandLineToolException {
//     // Initialize the command-line options parser
//     JCommander jc = new JCommander(this);
// 
//     // Add factories for parsing Paths, Assemblies, IntervalFiles, and WigFiles
//     jc.addConverterFactory(new PathFactory());
//     jc.addConverterFactory(new AssemblyFactory());
// 
//     // Set the program name to be the class name
//     String[] nameParts = getClass().getName().split("\\.");
//     String shortName = StringUtils.join(Arrays.copyOfRange(nameParts, nameParts.length - 2, nameParts.length), '.');
//     jc.setProgramName(shortName);
// 
//     try {
//       jc.parse(args);
//     } catch (ParameterException e) {
//       System.err.println(e.getMessage());
//       jc.usage();
//       System.exit(-1);
//     }
// 
//     ValidationStringency stringency = SAMFileReader.getDefaultValidationStringency();
//     try {
//       SAMFileReader.setDefaultValidationStringency(SAMFileReader.ValidationStringency.LENIENT);
//       run();
//     } catch (IOException e) {
//       throw new CommandLineToolException("IO error while running", e);
//     } finally {
//       SAMFileReader.setDefaultValidationStringency(stringency);
//     }
//   }
// }
// 
// Path: src/edu/unc/genomics/ReadablePathValidator.java
// public class ReadablePathValidator implements IParameterValidator {
// 
//   /*
//    * (non-Javadoc)
//    * 
//    * @see com.beust.jcommander.IParameterValidator#validate(java.lang.String,
//    * java.lang.String)
//    */
//   @Override
//   public void validate(String name, String value) throws ParameterException {
//     PathConverter converter = new PathConverter();
//     Path p = converter.convert(value);
//     if (!Files.isReadable(p)) {
//       throw new ParameterException("Parameter " + name + " should be a readable file");
//     }
//   }
// 
// }


import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import net.sf.picard.fastq.FastqReader;
import net.sf.picard.fastq.FastqRecord;
import org.apache.log4j.Logger;
import com.beust.jcommander.Parameter;
import edu.unc.genomics.CommandLineTool;
import edu.unc.genomics.ReadablePathValidator;
package edu.unc.genomics.converters;






/**
 * Converts a FASTQ file with Illumina quality scores (Phred+64) to Sanger
 * quality scores (Phred+33)
 * 
 * @author timpalpant
 *
 */
public class FastqIlluminaToSanger extends CommandLineTool {

  private static final Logger log = Logger.getLogger(FastqIlluminaToSanger.class);

// Path: src/edu/unc/genomics/CommandLineTool.java
// public abstract class CommandLineTool {
// 
//   /**
//    * The default bite-size to use for applications that process files in chunks
//    * TODO Read from a configuration file
//    */
//   public static final int DEFAULT_CHUNK_SIZE = 10_000_000;
// 
//   /**
//    * Do the main computation of this tool
//    * 
//    * @throws IOException
//    */
//   public abstract void run() throws IOException;
// 
//   /**
//    * Parse command-line arguments and run the tool Exit on parameter exceptions
//    * 
//    * @param args
//    */
//   public void instanceMain(String[] args) throws CommandLineToolException {
//     // Initialize the command-line options parser
//     JCommander jc = new JCommander(this);
// 
//     // Add factories for parsing Paths, Assemblies, IntervalFiles, and WigFiles
//     jc.addConverterFactory(new PathFactory());
//     jc.addConverterFactory(new AssemblyFactory());
// 
//     // Set the program name to be the class name
//     String[] nameParts = getClass().getName().split("\\.");
//     String shortName = StringUtils.join(Arrays.copyOfRange(nameParts, nameParts.length - 2, nameParts.length), '.');
//     jc.setProgramName(shortName);
// 
//     try {
//       jc.parse(args);
//     } catch (ParameterException e) {
//       System.err.println(e.getMessage());
//       jc.usage();
//       System.exit(-1);
//     }
// 
//     ValidationStringency stringency = SAMFileReader.getDefaultValidationStringency();
//     try {
//       SAMFileReader.setDefaultValidationStringency(SAMFileReader.ValidationStringency.LENIENT);
//       run();
//     } catch (IOException e) {
//       throw new CommandLineToolException("IO error while running", e);
//     } finally {
//       SAMFileReader.setDefaultValidationStringency(stringency);
//     }
//   }
// }
// 
// Path: src/edu/unc/genomics/ReadablePathValidator.java
// public class ReadablePathValidator implements IParameterValidator {
// 
//   /*
//    * (non-Javadoc)
//    * 
//    * @see com.beust.jcommander.IParameterValidator#validate(java.lang.String,
//    * java.lang.String)
//    */
//   @Override
//   public void validate(String name, String value) throws ParameterException {
//     PathConverter converter = new PathConverter();
//     Path p = converter.convert(value);
//     if (!Files.isReadable(p)) {
//       throw new ParameterException("Parameter " + name + " should be a readable file");
//     }
//   }
// 
// }


// Path: src/edu/unc/genomics/converters/FastqIlluminaToSanger.java
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import net.sf.picard.fastq.FastqReader;
import net.sf.picard.fastq.FastqRecord;
import org.apache.log4j.Logger;
import com.beust.jcommander.Parameter;
import edu.unc.genomics.CommandLineTool;
import edu.unc.genomics.ReadablePathValidator;

package edu.unc.genomics.converters;






/**
 * Converts a FASTQ file with Illumina quality scores (Phred+64) to Sanger
 * quality scores (Phred+33)
 * 
 * @author timpalpant
 *
 */
public class FastqIlluminaToSanger extends CommandLineTool {

  private static final Logger log = Logger.getLogger(FastqIlluminaToSanger.class);

  @Parameter(names = { "-i", "--input" }, description = "Input file (FASTQ, Illumina)", required = true, validateWith = ReadablePathValidator.class)