public static void printLines(
      ArrayList<String[]> lines, boolean uniqueOnly, boolean filterSubOpt) {
    double numHits = 0;
    ArrayList<String[]> linesToPrint;
    // First count the number of (valid) hits
    if (filterSubOpt && lines.size() > 1) {
      linesToPrint = new ArrayList<String[]>();
      int minMis = Integer.MAX_VALUE;
      // Find minimum number of mismatchs
      int[] mismatches = new int[lines.size()];
      int i = 0;
      for (String[] pieces : lines) {
        int mis = 0;
        if (pieces.length > 7 && pieces[7].length() > 1) mis = pieces[7].split(",").length;
        mismatches[i] = mis;
        if (mis < minMis) minMis = mis;
        i++;
      }
      // Only add minimum mismatch hits
      i = 0;
      for (String[] pieces : lines) {
        if (mismatches[i] == minMis) linesToPrint.add(pieces);
        i++;
      }
      numHits = linesToPrint.size();
    } else {
      linesToPrint = lines;
      numHits = lines.size();
    }

    // Now add the hits!
    if (!uniqueOnly || linesToPrint.size() == 1) {
      double weight = 1.0 / numHits;
      for (String[] pieces : linesToPrint) {
        if (readLength == -1) readLength = pieces[4].length();

        Integer coord =
            pieces[1].equals("+")
                ? Integer.valueOf(pieces[3])
                : Integer.valueOf(pieces[3]) + readLength - 1;
        coord += 1; // Bowtie default output is 0-based - we want 1-based.
        System.out.println(
            String.format(
                "%s\t%s\t%s\t%d\t%f", pieces[2], coord, pieces[1], pieces[4].length(), weight));
      }
    }
  }
Exemple #2
0
 private boolean startLauncher(File dir) {
   try {
     Runtime rt = Runtime.getRuntime();
     ArrayList<String> command = new ArrayList<String>();
     command.add("java");
     command.add("-jar");
     command.add("Launcher.jar");
     String[] cmdarray = command.toArray(new String[command.size()]);
     Process proc = rt.exec(cmdarray, null, dir);
     return true;
   } catch (Exception ex) {
     System.err.println("Unable to start the Launcher program.\n" + ex.getMessage());
     return false;
   }
 }