Exemple #1
0
 public String doIndex(String ifile, String outputDir, int indexType, int binSize)
     throws IOException {
   String typeString = Preprocessor.getExtension(ifile);
   return doIndex(ifile, typeString, outputDir, indexType, binSize);
 }
Exemple #2
0
  void run(String[] argv) {

    if (argv.length == 0) {
      System.out.println(usageString());
      System.out.println("Error: No arguments provided");
      return;
    }

    String command = argv[0].toLowerCase();

    if (command.equals(CMD_HELP)) {
      if (argv.length > 1) {
        System.out.println(usageString(argv[1]));
      } else {
        System.out.println(usageString());
      }
      return;
    }

    if (command.equals(CMD_GUI)) {
      launchGUI();
      Runtime.getRuntime().halt(0);
    }

    // Do "version" now, its the only command with no arguments
    if (command.equals(CMD_VERSION)) {
      System.out.println(getVersionString());
      return;
    }

    CmdLineParser parser = initParser(command);

    // Parse optional arguments (switches, etc)
    try {
      parser.parse(argv);
    } catch (CmdLineParser.OptionException e) {
      System.err.println(e.getMessage());
      System.out.println("Enter igvtools help " + command + " for help on this command");
      return;
    }

    String tmpDirName = null;
    if (tmpDirOption != null) {
      tmpDirName = (String) parser.getOptionValue(tmpDirOption, null);
    }
    int maxRecords = MAX_RECORDS_IN_RAM;
    if (maxRecordsOption != null) {
      maxRecords = (Integer) parser.getOptionValue(maxRecordsOption, MAX_RECORDS_IN_RAM);
    }
    String[] nonOptionArgs = parser.getRemainingArgs();

    try {
      String basic_syntax =
          "Error in syntax. Enter igvtools help " + command + " for usage instructions.";

      // All remaining commands require an input file, and most need the file extension.  Do that
      // here.
      validateArgsLength(nonOptionArgs, 2, "Error: No input file provided");
      String ifile = nonOptionArgs[1];

      boolean isList = ifile.indexOf(",") > 0;
      if (!isList && !FileUtils.resourceExists(ifile)) {
        throw new PreprocessingException("File not found: " + ifile);
      }

      String typeString = null;
      if (typeOption != null) {
        typeString = (String) parser.getOptionValue(typeOption);
      }
      if (typeString == null || typeString.length() == 0) {
        typeString = Preprocessor.getExtension(ifile).toLowerCase();
      } else {
        typeString = typeString.toLowerCase();
      }

      if (command.equals(CMD_COUNT) || command.equals(CMD_TILE) || command.equals(CMD_TOTDF)) {
        // Parse out options common to both count and tile
        validateArgsLength(nonOptionArgs, 4, basic_syntax);
        int maxZoomValue = (Integer) parser.getOptionValue(maxZoomOption, MAX_ZOOM);
        String ofile = nonOptionArgs[2];
        String genomeId = nonOptionArgs[3];

        boolean isGCT = typeString.endsWith("gct") || typeString.equals("mage-tab");
        String wfsString = (String) parser.getOptionValue(windowFunctions);
        Collection<WindowFunction> wfList = parseWFS(wfsString, isGCT);

        if (command.equals(CMD_COUNT)) {

          String trackLine = null;
          String color = (String) parser.getOptionValue(colorOption);

          if (color != null) {
            trackLine = "track color=\"" + color + "\"";
          }

          int extFactorValue = (Integer) parser.getOptionValue(extFactorOption, EXT_FACTOR);

          int countFlags = parseCountFlags(parser);
          String queryString = (String) parser.getOptionValue(queryStringOpt);
          int minMapQuality = (Integer) parser.getOptionValue(minMapQualityOpt, 0);

          int windowSizeValue = (Integer) parser.getOptionValue(windowSizeOption, WINDOW_SIZE);
          doCount(
              ifile,
              ofile,
              genomeId,
              maxZoomValue,
              wfList,
              windowSizeValue,
              extFactorValue,
              trackLine,
              queryString,
              minMapQuality,
              countFlags);
        } else {
          String probeFile = (String) parser.getOptionValue(probeFileOption, PROBE_FILE);
          toTDF(
              typeString,
              ifile,
              ofile,
              probeFile,
              genomeId,
              maxZoomValue,
              wfList,
              tmpDirName,
              maxRecords);
        }

      } else if (command.equals(CMD_SORT)) {
        validateArgsLength(nonOptionArgs, 3, basic_syntax);
        String ofile = nonOptionArgs[2];
        doSort(ifile, ofile, tmpDirName, maxRecords);
      } else if (command.equals(CMD_INDEX)) {
        int indexType = (Integer) parser.getOptionValue(indexTypeOption, LINEAR_INDEX);
        int defaultBinSize = indexType == LINEAR_INDEX ? LINEAR_BIN_SIZE : INTERVAL_SIZE;
        int binSize = (Integer) parser.getOptionValue(binSizeOption, defaultBinSize);
        String outputDir = (String) parser.getOptionValue(outputDirOption, null);
        doIndex(ifile, typeString, outputDir, indexType, binSize);
      } else if (command.equals(CMD_FORMATEXP)) {
        validateArgsLength(nonOptionArgs, 3, basic_syntax);
        File inputFile = new File(nonOptionArgs[1]);
        File outputFile = new File(nonOptionArgs[2]);
        (new ExpressionFormatter()).convert(inputFile, outputFile);
      } else if (command.equals("wibtowig")) {
        validateArgsLength(
            nonOptionArgs,
            4,
            "Error in syntax. Expected: " + command + " [options] txtfile wibfile wigfile");
        File txtFile = new File(nonOptionArgs[1]);
        File wibFile = new File(nonOptionArgs[2]);
        File wigFile = new File(nonOptionArgs[3]);
        String trackLine = nonOptionArgs.length > 4 ? nonOptionArgs[4] : null;
        doWIBtoWIG(txtFile, wibFile, wigFile, trackLine);
      } else if (command.equals("splitgff")) {
        validateArgsLength(
            nonOptionArgs,
            3,
            "Error in syntax. Expected: " + command + " [options] inputfile outputdir");
        String outputDirectory = nonOptionArgs[2];
        GFFParser.splitFileByType(ifile, outputDirectory);
      } else if (command.toLowerCase().equals("gcttoigv")) {
        validateArgsLength(nonOptionArgs, 4, basic_syntax + " genomeId");
        String ofile = nonOptionArgs[2];
        // Output files must have .igv extension
        if (!ofile.endsWith(".igv")) {
          ofile = ofile + ".igv";
        }
        String genomeId = nonOptionArgs[3];
        Genome genome = loadGenome(genomeId, true);
        if (genome == null) {
          throw new PreprocessingException("Genome could not be loaded: " + genomeId);
        }
        String probeFile = (String) parser.getOptionValue(probeFileOption, PROBE_FILE);
        doGCTtoIGV(typeString, ifile, new File(ofile), probeFile, maxRecords, tmpDirName, genome);
      } else if (command.toLowerCase().equals("tdftobedgraph")) {
        validateArgsLength(nonOptionArgs, 3, basic_syntax);
        String ofile = nonOptionArgs[2];
        TDFUtils.tdfToBedgraph(ifile, ofile);
      } else if (command.equals("wigtobed")) {
        validateArgsLength(
            nonOptionArgs, 2, "Error in syntax. Expected: " + command + " [options] inputfile");
        String inputFile = nonOptionArgs[1];
        float hetThreshold = 0.17f;
        if (nonOptionArgs.length > 2) {
          hetThreshold = Float.parseFloat(nonOptionArgs[2]);
        }
        float homThreshold = 0.55f;
        if (nonOptionArgs.length > 3) {
          homThreshold = Float.parseFloat(nonOptionArgs[3]);
        }
        WigToBed.run(inputFile, hetThreshold, homThreshold);
      } else if (command.equals("vcftobed")) {
        validateArgsLength(nonOptionArgs, 3, basic_syntax);
        String inputFile = nonOptionArgs[1];
        String outputFile = nonOptionArgs[2];
        VCFtoBed.convert(inputFile, outputFile);
      } else if (command.equals("sumwigs")) {
        sumWigs(nonOptionArgs[1], nonOptionArgs[2]);
      } else if (command.equals("densitiestobedgraph")) {
        validateArgsLength(
            nonOptionArgs,
            3,
            "Error in syntax. Expected: " + command + " [options] inputdir outputdir");
        File inputDir = new File(nonOptionArgs[1]);
        File outputDir = new File(nonOptionArgs[2]);
        if (inputDir.isDirectory() && outputDir.isDirectory()) {
          DensitiesToBedGraph.convert(inputDir, outputDir);
        } else if (inputDir.isFile() && outputDir.isFile()) {
          DensitiesToBedGraph.convert(inputDir, outputDir);
        }

      } else if (command.equals(CMD_BAMTOBED)) {
        validateArgsLength(nonOptionArgs, 3, basic_syntax);
        String ofile = nonOptionArgs[2];
        Boolean pairOption = (Boolean) parser.getOptionValue(pairedCoverageOpt, false);
        BamToBed.convert(new File(ifile), new File(ofile), pairOption);
      } else if (command.equalsIgnoreCase("genGenomeList")) {
        // Generate a genomes.txt list file based on a directory
        // TODO Probably a better place for this. Users won't generally use it
        File inDir = new File(ifile);
        GenomeManager manager = GenomeManager.getInstance();
        manager.generateGenomeList(inDir, nonOptionArgs[2], nonOptionArgs[3]);
      } else {
        throw new PreprocessingException("Unknown command: " + argv[EXT_FACTOR]);
      }
    } catch (PreprocessingException e) {
      System.err.println(e.getMessage());
    } catch (IOException e) {
      throw new PreprocessingException("Unexpected IO error: ", e);
    }
  }