public static void main(String[] args) {
    System.err.println(
        "Executing "
            + (new Object() {}.getClass().getEnclosingClass().getName())
            + " "
            + Arrays.toString(args)
            + "\n");
    Timer t = new Timer();

    String inPattern = args[0];

    int minChrom = -1;
    int maxChrom = -1;
    int outgenome = -1;
    Data.GENOME_BUILD = -1;
    String name = null;

    for (int i = 1; i < args.length; i++) {
      final String arg = args[i].toLowerCase();
      String[] split = arg.split("=");
      String a = split[0];
      String b = (split.length > 1 ? split[1] : null);

      if (a.equals("ingenome")) {
        Data.setGenome(Integer.parseInt(b));
        if (minChrom == -1) {
          minChrom = 1;
        }
        if (maxChrom == -1) {
          maxChrom = Data.numChroms;
        }
      } else if (a.equals("outgenome")) {
        outgenome = Integer.parseInt(b);
      } else if (a.equals("minchrom")) {
        minChrom = Integer.parseInt(b);
      } else if (a.equals("maxchrom")) {
        maxChrom = Integer.parseInt(b);
      } else if (a.equals("threads") || a.equals("t")) {
        THREADS = Integer.parseInt(b);
      } else if (a.equals("nblocksize")) {
        N_BLOCK_SIZE = Integer.parseInt(b);
      } else if (a.equals("nblocktrigger")) {
        N_BLOCK_TRIGGER = Integer.parseInt(b);
      } else if (a.equals("staynearref")) {
        STAY_NEAR_REF = Tools.parseBoolean(b);
      } else if (a.equals("append") || a.equals("app")) {
        append = ReadStats.append = Tools.parseBoolean(b);
      } else if (a.equals("overwrite") || a.equals("ow")) {
        overwrite = Tools.parseBoolean(b);
      } else if (a.startsWith("regen")) {
        REGEN_N_BLOCKS = Tools.parseBoolean(b);
      } else if (a.startsWith("name=")) {
        REGEN_N_BLOCKS = Tools.parseBoolean(b);
      } else {
        System.err.println("Unknown argument " + arg);
      }
    }

    assert (Data.GENOME_BUILD > -1);
    assert (outgenome > -1);
    //		assert(Data.GENOME_BUILD!=outgenome);
    if (Data.GENOME_BUILD == outgenome) {
      System.out.println("Warning! Overwriting input genome " + outgenome);
    }

    String fname = Data.chromFname(minChrom, outgenome);
    File f = new File(fname.substring(0, fname.lastIndexOf('/')));
    //		assert(false) : f.getAbsolutePath();
    if (!f.exists()) {
      f.mkdirs();
    }

    for (int chrom = minChrom; chrom <= maxChrom; chrom++) {
      String outName = Data.chromFname(chrom, outgenome);
      assert (overwrite || !new File(outName).exists())
          : "Destination " + outName + " already exists.";
      //			assert(false) : inPattern+", "+outName;
      process(inPattern.replaceFirst("#", "" + chrom), outName, chrom);
    }

    FastaToChromArrays2.writeInfo(
        outgenome,
        maxChrom,
        (name == null ? Data.name : name),
        "" + Data.GENOME_BUILD + "_plus_variations",
        false,
        false);

    t.stop();

    {
      String path = IndexMaker4.fname(1, 1, 12, 1);
      int lastSlash = path.lastIndexOf('/');
      path = path.substring(0, lastSlash);
      File dir = new File(path);
      if (dir.exists()) {
        System.out.println("Deleting old index for " + outgenome);
        for (File f2 : dir.listFiles()) {
          if (f2.isFile() && (f2.getName().contains(".int2d") || f2.getName().endsWith(".txt"))) {
            f2.delete();
          }
        }
      }
    }

    //		System.out.println("Vars in: \t"+VARS_IN);
    //		System.out.println("Vars out:\t"+VARS_OUT);
    System.out.println();
    System.out.println("Time: \t" + t);
  }
  public static void main(String[] args) {

    Timer t = new Timer();

    String in = args[0];
    String outF = args.length > 1 ? args[1] : null;
    String outR = args.length > 2 ? args[2] : null;
    String outU = args.length > 3 ? args[3] : null;
    if (args.length > 4) {
      if (args[4].equalsIgnoreCase("header")) {
        includeHeader = true;
      }
    }

    ByteFile tf = ByteFile.makeByteFile(in, true, false);

    Tools.testForDuplicateFiles(true, in, outF, outR, outU);
    Tools.testOutputFiles(true, false, false, outF, outR, outU);

    final ByteStreamWriter fStream, rStream, uStream;

    fStream = (outF == null ? null : new ByteStreamWriter(outF, true, false, true));
    rStream = (outR == null ? null : new ByteStreamWriter(outR, true, false, true));
    uStream = (outU == null ? null : new ByteStreamWriter(outU, true, false, true));

    if (fStream != null) {
      fStream.start();
    }
    if (rStream != null) {
      rStream.start();
    }
    if (uStream != null) {
      uStream.start();
    }

    long plus = 0;
    long minus = 0;
    long other = 0;

    byte[] s = null;
    for (s = tf.nextLine(); s != null; s = tf.nextLine()) {
      if (s.length > 0) {
        byte c = s[0];
        if (c == '@') {
          if (includeHeader) {
            if (fStream != null) {
              fStream.println(s);
            }
            if (rStream != null) {
              rStream.println(s);
            }
            if (uStream != null) {
              uStream.println(s);
            }
          }
        } else {
          int flag = SamLine.parseFlagOnly(s);
          if (SamLine.mapped(flag)) {
            if (SamLine.strand(flag) == 0) {
              if (fStream != null) {
                fStream.println(s);
              }
              plus++;
            } else {
              if (rStream != null) {
                rStream.println(s);
              }
              minus++;
            }
          } else {
            if (uStream != null) {
              uStream.println(s);
            }
            other++;
          }
        }
      }
    }
    tf.close();
    if (fStream != null) {
      fStream.poisonAndWait();
    }
    if (rStream != null) {
      rStream.poisonAndWait();
    }
    if (uStream != null) {
      uStream.poisonAndWait();
    }

    System.err.println("Total reads:   \t" + (plus + minus + other));
    System.err.println("Plus reads:    \t" + (plus));
    System.err.println("Minus reads:   \t" + (minus));
    System.err.println("Unmapped reads:\t" + (other));

    t.stop();

    System.err.println("Time:          \t" + t);
  }
  public static void main(String[] args) {
    String in1 = args[0];
    String in2 =
        (args.length < 2 || args[1].equalsIgnoreCase("null") || args[1].contains("=")
            ? null
            : args[1]);
    if (in2 != null) {
      assert (!in1.equalsIgnoreCase(in2));
      FASTQ.TEST_INTERLEAVED = false;
    } else {
      FASTQ.TEST_INTERLEAVED = true;
      FASTQ.FORCE_INTERLEAVED = true;
    }

    long maxReads = -1;
    for (int i = 1; i < args.length; i++) {
      final String arg = args[i];
      final String[] split = arg.split("=");
      String a = split[0].toLowerCase();
      String b = (split.length > 1 ? split[1] : "true");

      if (Parser.isJavaFlag(arg)) {
        // jvm argument; do nothing
      } else if (Parser.parseZip(arg, a, b)) {
        // do nothing
      } else if (Parser.parseQuality(arg, a, b)) {
        // do nothing
      } else if (Parser.parseFasta(arg, a, b)) {
        // do nothing
      } else if (a.equals("reads") || a.startsWith("maxreads")) {
        maxReads = Tools.parseKMG(b);
      } else {
        throw new RuntimeException("Unknown parameter " + args[i]);
      }
    }

    Parser.processQuality();

    assert (FastaReadInputStream.settingsOK());
    Timer t = new Timer();

    ConcurrentReadInputStream cris = getReadInputStream(maxReads, false, true, in1, in2);
    System.out.println("Fetched " + cris.getClass().getName());
    {
      Object[] p = cris.producers();
      //			while(p[0]==null){
      //				p=cris.producers();
      //			}
      System.out.print("Producers: ");
      String comma = "";
      for (Object o : p) {
        System.out.print(comma + (o == null ? "null" : o.getClass().getName()));
        comma = ", ";
      }
      System.out.println();
    }
    boolean paired = cris.paired();
    System.out.println("paired=" + paired);
    cris.start(); // 4567

    ListNum<Read> ln = cris.nextList();
    ArrayList<Read> reads = (ln != null ? ln.list : null);

    if (reads != null && !reads.isEmpty()) {
      Read r = reads.get(0);
      assert ((r.mate != null) == paired);
    }

    long readCount = 0;
    long baseCount = 0;

    while (reads != null && reads.size() > 0) {

      for (Read r : reads) {
        Read r2 = r.mate;
        if (r != null) {
          readCount++;
          if (r.bases != null) {
            baseCount += r.length();
          }
        }
        if (r2 != null) {
          readCount++;
          if (r2.bases != null) {
            baseCount += r2.length();
          }
        }
      }
      cris.returnList(ln.id, ln.list.isEmpty());
      //			System.err.println("fetching list");
      ln = cris.nextList();
      reads = (ln != null ? ln.list : null);
      //			System.out.println("reads: "+(reads==null ? "null" : reads.size()));
    }
    System.err.println("Finished reading");
    cris.returnList(ln.id, ln.list.isEmpty());

    cris.close();
    t.stop();

    System.out.println("Reads:      \t" + readCount);
    System.out.println("Bases:      \t" + baseCount);
    System.out.println("Avg Length: \t" + String.format("%.2f", baseCount * 1.0 / readCount));
    System.out.println("Time:      \t" + t);
  }