Exemplo n.º 1
0
  /**
   * Compute coverage or density of an alignment or feature file.
   *
   * @param ifile Alignment or feature file
   * @param ofile Output file
   * @param genomeId Genome id (e.g. hg18) or full path to a .genome file (e.g.
   *     /xchip/igv/scer2.genome)
   * @param maxZoomValue Maximum zoom level to precompute. Default value is 7
   * @param windowFunctions
   * @param windowSizeValue
   * @param extFactorValue
   * @param trackLine
   * @param queryString
   * @param minMapQuality
   * @param countFlags
   * @throws IOException
   */
  public void doCount(
      String ifile,
      String ofile,
      String genomeId,
      int maxZoomValue,
      Collection<WindowFunction> windowFunctions,
      int windowSizeValue,
      int extFactorValue,
      String trackLine,
      String queryString,
      int minMapQuality,
      int countFlags)
      throws IOException {

    System.out.println("Computing coverage.  File = " + ifile);
    System.out.println("Max zoom = " + maxZoomValue);
    System.out.println("Window size = " + windowSizeValue);
    System.out.print("Window functions: ");
    for (WindowFunction wf : windowFunctions) {
      System.out.print(wf.toString() + " ");
    }
    System.out.println();
    System.out.println("Ext factor = " + extFactorValue);

    Genome genome = loadGenome(genomeId, false);
    if (genome == null) {
      throw new PreprocessingException("Genome could not be loaded: " + genomeId);
    }

    // Multiple files allowed for count command (a tdf and a wig)
    File tdfFile = null;
    File wigFile = null;
    String[] files = ofile.split(",");
    if (files[0].endsWith("wig")) {
      wigFile = new File(files[0]);
    } else {
      tdfFile = new File(files[0]);
    }
    if (files.length > 1) {
      if (files[1].endsWith("wig")) {
        wigFile = new File(files[1]);
      } else if (files[1].endsWith("tdf")) {
        tdfFile = new File(files[1]);
      }
    }

    if (tdfFile != null && !tdfFile.getName().endsWith(".tdf")) {
      tdfFile = new File(tdfFile.getAbsolutePath() + ".tdf");
    }

    Preprocessor p = new Preprocessor(tdfFile, genome, windowFunctions, -1, null);
    // p.count(ifile, windowSizeValue, extFactorValue, maxZoomValue, wigFile, coverageOpt,
    // trackLine);
    p.count(
        ifile,
        windowSizeValue,
        extFactorValue,
        maxZoomValue,
        wigFile,
        trackLine,
        queryString,
        minMapQuality,
        countFlags);

    p.finish();

    System.out.flush();
  }
Exemplo n.º 2
0
  public void toTDF(
      String typeString,
      String ifile,
      String ofile,
      String probeFile,
      String genomeId,
      int maxZoomValue,
      Collection<WindowFunction> windowFunctions,
      String tmpDirName,
      int maxRecords)
      throws IOException, PreprocessingException {

    if (!ifile.endsWith(".affective.csv")) validateIsTilable(typeString);

    System.out.println("toTDF.  File = " + ifile);
    System.out.println("Max zoom = " + maxZoomValue);
    if (probeFile != null && probeFile.trim().length() > 0) {
      System.out.println("Probe file = " + probeFile);
    }
    System.out.print("Window functions: ");
    for (WindowFunction wf : windowFunctions) {
      System.out.print(wf.toString() + " ");
    }
    System.out.println();

    boolean isGCT = isGCT(typeString);
    Genome genome = loadGenome(genomeId, isGCT);
    if (genome == null) {
      throw new PreprocessingException("Genome could not be loaded: " + genomeId);
    }
    File inputFileOrDir = new File(ifile);

    // Estimae the total number of lines to be parsed, for progress updates
    int nLines = estimateLineCount(inputFileOrDir);

    // TODO -- move this block of code out of here, this should be done before calling this method
    // Convert  gct files to igv format first
    File deleteme = null;
    if (isGCT(typeString)) {
      File tmpDir = null;
      if (tmpDirName != null && tmpDirName.length() > 0) {
        tmpDir = new File(tmpDirName);
        if (!tmpDir.exists() || !tmpDir.isDirectory()) {
          throw new PreprocessingException(
              "Specified tmp directory does not exist or is not directory: " + tmpDirName);
        }
      } else {
        tmpDir = new File(System.getProperty("java.io.tmpdir"), System.getProperty("user.name"));
      }
      if (!tmpDir.exists()) {
        tmpDir.mkdir();
      }

      String baseName = (new File(ifile)).getName();
      File igvFile = new File(tmpDir, baseName + ".igv");
      igvFile.deleteOnExit();
      doGCTtoIGV(typeString, ifile, igvFile, probeFile, maxRecords, tmpDirName, genome);

      inputFileOrDir = igvFile;
      deleteme = igvFile;
      typeString = ".igv";
    }

    // Convert to tdf
    File outputFile = new File(ofile);
    try {
      Preprocessor p = new Preprocessor(outputFile, genome, windowFunctions, nLines, null);
      if (inputFileOrDir.isDirectory() || inputFileOrDir.getName().endsWith(".list")) {
        List<File> files = getFilesFromDirOrList(inputFileOrDir);
        for (File f : files) {
          p.preprocess(f, maxZoomValue, typeString);
        }
      } else {
        p.preprocess(inputFileOrDir, maxZoomValue, typeString);
      }
      p.finish();
    } catch (IOException e) {
      e.printStackTrace();
      // Delete output file as its probably corrupt
      if (outputFile.exists()) {
        outputFile.delete();
      }
    } finally {
      if (deleteme != null && deleteme.exists()) {
        deleteme.delete();
      }
    }

    System.out.flush();
  }