예제 #1
0
파일: SequenceGC.java 프로젝트: kshakir/IGV
  public static void main(String args[]) {

    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option inFile = parser.addStringOption('f', "file");
    CmdLineParser.Option outFile = parser.addStringOption('o', "output");
    CmdLineParser.Option window = parser.addIntegerOption('w', "window");
    CmdLineParser.Option step = parser.addIntegerOption('s', "step");
    try {
      parser.parse(args);
    } catch (CmdLineParser.OptionException e) {
      System.err.println(e.getMessage());
      printUsage();
      System.exit(2);
    }

    windowSize = (Integer) parser.getOptionValue(window, 5);
    windowStep = (Integer) parser.getOptionValue(step, 1);

    SequenceGC sequence = new SequenceGC();
    String inPath = (String) parser.getOptionValue(inFile);
    String outPath = (String) parser.getOptionValue(outFile);

    if (!(inPath == null)) sequence.ProcessPath(inPath, outPath);
    else printUsage();
  }
예제 #2
0
  /** Main client entry point for stand-alone operation. */
  public static void main(String[] args) {
    BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d [%-25t] %-5p: %m%n")));

    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option help = parser.addBooleanOption('h', "help");
    CmdLineParser.Option output = parser.addStringOption('o', "output");
    CmdLineParser.Option iface = parser.addStringOption('i', "iface");

    try {
      parser.parse(args);
    } catch (CmdLineParser.OptionException oe) {
      System.err.println(oe.getMessage());
      usage(System.err);
      System.exit(1);
    }

    // Display help and exit if requested
    if (Boolean.TRUE.equals(parser.getOptionValue(help))) {
      usage(System.out);
      System.exit(0);
    }

    String outputValue = (String) parser.getOptionValue(output, DEFAULT_OUTPUT_DIRECTORY);
    String ifaceValue = (String) parser.getOptionValue(iface);

    String[] otherArgs = parser.getRemainingArgs();
    if (otherArgs.length != 1) {
      usage(System.err);
      System.exit(1);
    }

    try {
      Client c = new Client(getIPv4Address(ifaceValue));
      SharedTorrent torrent =
          SharedTorrent.fromFile(new File(otherArgs[0]), new File(outputValue), false);
      c.addTorrent(torrent);

      // Set a shutdown hook that will stop the sharing/seeding and send
      // a STOPPED announce request.
      Runtime.getRuntime().addShutdownHook(new Thread(new ClientShutdown(c, null)));

      c.share();
      if (ClientState.ERROR.equals(torrent.getClientState())) {
        System.exit(1);
      }
    } catch (Exception e) {
      logger.error("Fatal error: {}", e.getMessage(), e);
      System.exit(2);
    }
  }
예제 #3
0
  /** @param args */
  public static void main(String[] args) {
    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option server = parser.addBooleanOption("server");
    CmdLineParser.Option list = parser.addBooleanOption("list");
    CmdLineParser.Option download = parser.addBooleanOption("download");
    CmdLineParser.Option multidownload = parser.addBooleanOption("multidownload");
    CmdLineParser.Option upload = parser.addBooleanOption("upload");
    CmdLineParser.Option port = parser.addIntegerOption('p', "port");
    CmdLineParser.Option dir = parser.addStringOption('d', "dir");
    CmdLineParser.Option hostname = parser.addStringOption('h', "hostname");
    CmdLineParser.Option file = parser.addStringOption('f', "file");

    try {
      parser.parse(args);
    } catch (CmdLineParser.OptionException e) {
      LOGGER.info(e.getMessage());
      printUsage();
      System.exit(2);
    }

    Boolean serverValue = (Boolean) parser.getOptionValue(server, new Boolean(false));
    Boolean listValue = (Boolean) parser.getOptionValue(list, new Boolean(false));
    Boolean downloadValue = (Boolean) parser.getOptionValue(download, new Boolean(false));
    Boolean uploadValue = (Boolean) parser.getOptionValue(upload, new Boolean(false));

    Boolean multidownloadValue = (Boolean) parser.getOptionValue(multidownload, new Boolean(false));
    Integer portValue =
        (Integer) parser.getOptionValue(port, new Integer(FtperSettings.INSTANCE.getServerPort()));

    if (serverValue.booleanValue()) {
      String current = new File(".").getAbsolutePath();
      String dirValue =
          (String) parser.getOptionValue(dir, current.substring(0, current.length() - 1));
      LOGGER.info("Creating ftper server at port {} with root in {}", portValue, dirValue);
      FtperSettings.INSTANCE.setServerPort(portValue.intValue());
      FtperSettings.INSTANCE.setServerMode(serverValue.booleanValue());
      FtperSettings.INSTANCE.setServerRoot(dirValue);

      FtperServer serverInstance = new FtperServer();
      serverInstance.start();
    } else {

      FtperSettings.INSTANCE.setServerMode(serverValue.booleanValue());
      String hostnameValue = (String) parser.getOptionValue(hostname);
      String fileValue = (String) parser.getOptionValue(file);

      String[] otherArgs = parser.getRemainingArgs();
      if (listValue.booleanValue()) {
        String dirValue = (String) parser.getOptionValue(dir, "");

        ListClient client = new ListClient();
        client.init(hostnameValue, portValue.intValue(), dirValue);
      } else if (downloadValue.booleanValue()
          && hostnameValue != null
          && otherArgs.length % 2 == 0
          && otherArgs.length >= 2) {
        SingleModeClient client = new SingleModeClient();
        Map<String, String> uploads = new HashMap<String, String>();

        Map<String, String> downloads = new HashMap<String, String>();

        for (int i = 0; i + 1 < otherArgs.length; i = i + 2) {
          LOGGER.info("Requested transfer of {} as {}", otherArgs[i], otherArgs[i + 1]);
          downloads.put(otherArgs[i], otherArgs[i + 1]);
        }
        client.init(hostnameValue, portValue.intValue(), uploads, downloads);

      } else if (uploadValue.booleanValue()
          && hostnameValue != null
          && otherArgs.length % 2 == 0
          && otherArgs.length >= 2) {
        SingleModeClient client = new SingleModeClient();
        Map<String, String> uploads = new HashMap<String, String>();
        Map<String, String> downloads = new HashMap<String, String>();
        for (int i = 0; i + 1 < otherArgs.length; i = i + 2) {
          LOGGER.info("Requested transfer of {} to {}", otherArgs[i + 1], otherArgs[i]);
          uploads.put(otherArgs[i + 1], otherArgs[i]);
        }
        client.init(hostnameValue, portValue.intValue(), uploads, downloads);

      } else if (multidownloadValue.booleanValue()
          && fileValue != null
          && otherArgs.length % 2 == 0
          && otherArgs.length >= 2) {
        MultiModeClient client = new MultiModeClient();
        Map<String, String> requests = new HashMap<String, String>();
        for (int i = 0; i + 1 < otherArgs.length; i = i + 2) {
          LOGGER.info(
              "Requested transfer of {} to {}",
              otherArgs[i + 1] + " at " + otherArgs[i],
              fileValue);
          requests.put(otherArgs[i], otherArgs[i + 1]);
        }
        client.init(fileValue, requests);
      } else {
        printUsage();
        System.exit(2);
      }
    }
  }
예제 #4
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);
    }
  }
예제 #5
0
  public static void main(String[] args) {

    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option help = parser.addBooleanOption('h', "help");
    CmdLineParser.Option urdfFile = parser.addStringOption('u', "urdf");
    CmdLineParser.Option groupsFile = parser.addStringOption('g', "groups");
    CmdLineParser.Option srdlFile = parser.addStringOption('s', "srdl");
    CmdLineParser.Option targetUri = parser.addStringOption('i', "uri");
    CmdLineParser.Option capsList = parser.addStringOption('c', "caps");

    System.out.println();

    try {
      parser.parse(args);
    } catch (CmdLineParser.OptionException e) {
      System.out.println("[ERROR]\t" + e.getMessage());
      printUsage();
      System.exit(2);
    }

    boolean showUsage = (Boolean) parser.getOptionValue(help, Boolean.FALSE);
    String urdfValue = (String) parser.getOptionValue(urdfFile);
    String groupsValue = (String) parser.getOptionValue(groupsFile);
    String srdlValue = (String) parser.getOptionValue(srdlFile);
    String uriValue = (String) parser.getOptionValue(targetUri);
    String capsValue = (String) parser.getOptionValue(capsList);
    ArrayList<Capability> caps = new ArrayList<Capability>();

    String[] otherArgs = parser.getRemainingArgs();
    for (String s : otherArgs) {
      System.out.println("[INFO]\tIgnoring other argument '" + s + "'");
    }

    if (!showUsage) {
      if (urdfValue == null || urdfValue.length() == 0) {
        System.out.println("[ERROR]\tNo URDF file specified (-u / --urdf)");
        showUsage = true;
      }
      if (srdlValue == null || srdlValue.length() == 0) {
        System.out.println("[ERROR]\tNo target SRDL file specified (-s / --srdl)");
        showUsage = true;
      }
      if (uriValue == null || uriValue.length() == 0) {
        System.out.println("[ERROR]\tNo URI specified to use for SRDL description (-i / --uri)");
        showUsage = true;
      } else {
        if (!uriValue.endsWith("#")) {
          uriValue += "#";
        }
      }
      if (capsValue == null) {
        System.out.println("[WARN]\tNo SRDL capabilities specified (-c / --caps)");
      } else {
        StringTokenizer t = new StringTokenizer(capsValue, ",");
        while (t.hasMoreTokens()) {
          String token = t.nextToken().trim();
          Capability c = null;
          try {
            c = Capability.valueOf(token);
          } catch (Exception e) {
            System.out.println("[ERROR]\tUnknown SRDL capability '" + token + "'");
            showUsage = true;
          }
          if (c != null) {
            caps.add(c);
          }
        }
      }
    }

    if (showUsage) {
      printUsage();
      System.exit(2);
    }

    URDF2SRDL ui = new URDF2SRDL();
    if (ui.loadURDF(urdfValue)) {
      ArrayList<PlanningGroup> parsedGroups = null;
      if (groupsValue != null) {
        parsedGroups = ui.loadPlanningGroups(groupsValue);
      }
      ui.saveSRDL(srdlValue, uriValue, caps, parsedGroups);
    }

    System.out.println();
  }