// 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/ngs/Autocorrelation.java
// public class Autocorrelation extends CommandLineTool {
// 
//   private static final Logger log = Logger.getLogger(Autocorrelation.class);
// 
//   @Parameter(names = { "-i", "--input" }, description = "Input file", required = true, validateWith = ReadablePathValidator.class)
//   public Path inputFile;
//   @Parameter(names = { "-l", "--loci" }, description = "Genomic loci (Bed format)", required = true, validateWith = ReadablePathValidator.class)
//   public Path lociFile;
//   @Parameter(names = { "-o", "--output" }, description = "Output file", required = true)
//   public Path outputFile;
//   @Parameter(names = { "-m", "--max" }, description = "Autocorrelation limit (bp)")
//   public int limit = 200;
// 
//   @Override
//   public void run() throws IOException {
//     try (WigFileReader wig = WigFileReader.autodetect(inputFile);
//         IntervalFileReader<? extends Interval> loci = IntervalFileReader.autodetect(lociFile);
//         BufferedWriter writer = Files.newBufferedWriter(outputFile, Charset.defaultCharset())) {
//       log.debug("Computing autocorrelation for each window");
//       int skipped = 0;
//       for (Interval interval : loci) {
//         float[] data;
//         try {
//           data = wig.query(interval).getValues();
//         } catch (IOException | WigFileException e) {
//           log.debug("Skipping interval: " + interval.toString());
//           skipped++;
//           continue;
//         }
// 
//         // Compute the autocorrelation
//         float[] auto = FFTUtils.autocovariance(data, limit);
// 
//         // Write to output
//         writer.write(interval.toBed());
//         for (int i = 0; i < auto.length; i++) {
//           writer.write("\t" + auto[i]);
//         }
//         writer.newLine();
//       }
// 
//       log.info("Skipped " + skipped + " intervals");
//     }
//   }
// 
//   public static void main(String[] args) {
//     new Autocorrelation().instanceMain(args);
//   }
// }


import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.log4j.Logger;
import com.beust.jcommander.Parameter;
import edu.unc.genomics.CommandLineTool;
import edu.unc.genomics.ReadablePathValidator;
import edu.unc.genomics.io.WigFileReader;
import edu.unc.genomics.io.WigFileException;
import edu.unc.genomics.ngs.Autocorrelation;
package edu.unc.genomics.wigmath;





/**
 * Output a summary of a (Big)Wig file with information about the chromosomes,
 * contigs, and statistics about the data.
 * 
 * @author timpalpant
 *
 */
public class Summary extends CommandLineTool {

  private static final Logger log = Logger.getLogger(Autocorrelation.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/ngs/Autocorrelation.java
// public class Autocorrelation extends CommandLineTool {
// 
//   private static final Logger log = Logger.getLogger(Autocorrelation.class);
// 
//   @Parameter(names = { "-i", "--input" }, description = "Input file", required = true, validateWith = ReadablePathValidator.class)
//   public Path inputFile;
//   @Parameter(names = { "-l", "--loci" }, description = "Genomic loci (Bed format)", required = true, validateWith = ReadablePathValidator.class)
//   public Path lociFile;
//   @Parameter(names = { "-o", "--output" }, description = "Output file", required = true)
//   public Path outputFile;
//   @Parameter(names = { "-m", "--max" }, description = "Autocorrelation limit (bp)")
//   public int limit = 200;
// 
//   @Override
//   public void run() throws IOException {
//     try (WigFileReader wig = WigFileReader.autodetect(inputFile);
//         IntervalFileReader<? extends Interval> loci = IntervalFileReader.autodetect(lociFile);
//         BufferedWriter writer = Files.newBufferedWriter(outputFile, Charset.defaultCharset())) {
//       log.debug("Computing autocorrelation for each window");
//       int skipped = 0;
//       for (Interval interval : loci) {
//         float[] data;
//         try {
//           data = wig.query(interval).getValues();
//         } catch (IOException | WigFileException e) {
//           log.debug("Skipping interval: " + interval.toString());
//           skipped++;
//           continue;
//         }
// 
//         // Compute the autocorrelation
//         float[] auto = FFTUtils.autocovariance(data, limit);
// 
//         // Write to output
//         writer.write(interval.toBed());
//         for (int i = 0; i < auto.length; i++) {
//           writer.write("\t" + auto[i]);
//         }
//         writer.newLine();
//       }
// 
//       log.info("Skipped " + skipped + " intervals");
//     }
//   }
// 
//   public static void main(String[] args) {
//     new Autocorrelation().instanceMain(args);
//   }
// }


// Path: src/edu/unc/genomics/wigmath/Summary.java
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.log4j.Logger;
import com.beust.jcommander.Parameter;
import edu.unc.genomics.CommandLineTool;
import edu.unc.genomics.ReadablePathValidator;
import edu.unc.genomics.io.WigFileReader;
import edu.unc.genomics.io.WigFileException;
import edu.unc.genomics.ngs.Autocorrelation;

package edu.unc.genomics.wigmath;





/**
 * Output a summary of a (Big)Wig file with information about the chromosomes,
 * contigs, and statistics about the data.
 * 
 * @author timpalpant
 *
 */
public class Summary extends CommandLineTool {

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

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