public Object tryArgument(String arg) throws Exception { try { ArrayList<Object> retval = new ArrayList<Object>(); String[] values = arg.split(separator); if (values.length == 0) { throw new Exception("Invalid argument"); } if (values.length == 1) { return handler.tryArgument(values[0]); } if (values.length > maxEntries) { throw new Exception(String.format("Cannot exceed %d entries", maxEntries)); } for (String v : values) { Object param = handler.tryArgument(v); if (param == null) { throw new Exception(String.format("Invalid member of list: %s", v)); } retval.add(param); } return retval; } catch (Exception e) { throw e; } }
public String toUsageString(String prepend) { StringBuilder builder = new StringBuilder(); builder.append(prepend); builder.append(String.format("%s: %s", name, description)); builder.append("\n"); if (defaultValue != null) { builder.append(prepend); builder.append(String.format("\tDefault: %s", defaultValue.toString())); builder.append("\n"); } String handlerUsage = handler.toUsageString(prepend); if (handlerUsage != null && handlerUsage.length() > 0) { builder.append("\t"); builder.append(handlerUsage); builder.append("\n"); } return builder.toString(); }
public static void main(String[] argv) { OpalLogWriter.setLogger(new DefaultLogger()); ArgumentHandler argHandler = new ArgumentHandler(argv); if (argHandler.getVerbosity() > 0) { OpalLogWriter.printVersion(); OpalLogWriter.stdErrLogln(""); } /*String fileA = argHandler.getFileA(); String fileB = argHandler.getFileB(); String structFileA = argHandler.getStructFileA(); String structFileB = argHandler.getStructFileB(); String costName = argHandler.getCostName(); int gamma = argHandler.getGamma(); int lambda = argHandler.getLambda(); int gammaTerm = argHandler.getGammaTerm(); int lambdaTerm = argHandler.getLambdaTerm(); int verbosity = argHandler.getVerbosity(); boolean toUpper = argHandler.isToUpper(); boolean justDoConvert= argHandler.isJustDoConvert(); boolean justDoSubOpt= argHandler.isJustDoSubOpt(); boolean justTree= argHandler.isJustTree();*/ Date start = new Date(); Configuration[] advising_config = argHandler.getAdvisingConfigs(); Configuration[] realignment_config = argHandler.getRealignmentConfigs(); Inputs input = argHandler.getInputs(); runAlignment[] thread = new runAlignment[advising_config.length]; int last_joined = -1; int max_threads = Runtime.getRuntime().availableProcessors(); if (argHandler.getMaxThreads() > -1) max_threads = argHandler.getMaxThreads(); if (input.verbosity > 0) { OpalLogWriter.stdErrLogln( "The number of available threads is " + Runtime.getRuntime().availableProcessors() + ", Opal will use " + max_threads); } int maxIndex = 0; int maxPreRealignmentIndex = 0; for (int i = 0; i < advising_config.length; i++) { thread[i] = new runAlignment(advising_config[i], input, realignment_config); // thread[i] = new printLine(config[i],i); thread[i].start(); if (i - last_joined >= max_threads) { last_joined++; try { thread[last_joined].join(); if (input.configOutputFile != null) thread[last_joined].print(); if (input.configOutputFile != null && realignment_config != null) thread[last_joined].printPreRealignment(); if (thread[last_joined].facetScore > thread[maxIndex].facetScore) { if (maxPreRealignmentIndex != maxIndex) thread[maxIndex] = null; maxIndex = last_joined; } if (thread[last_joined].preRealignmentFacetScore > thread[maxPreRealignmentIndex].preRealignmentFacetScore) { if (maxPreRealignmentIndex != maxIndex) thread[maxPreRealignmentIndex] = null; maxPreRealignmentIndex = last_joined; } if (last_joined != maxIndex && last_joined != maxPreRealignmentIndex) thread[last_joined] = null; } catch (InterruptedException e) { OpalLogWriter.stdErrLogln("InterruptedException " + e.toString()); throw new GenericOpalException("InterruptedException " + e.toString()); } } } for (last_joined++; last_joined < advising_config.length; last_joined++) { try { thread[last_joined].join(); if (input.configOutputFile != null) thread[last_joined].print(); if (input.configOutputFile != null && realignment_config != null) thread[last_joined].printPreRealignment(); if (thread[last_joined].facetScore > thread[maxIndex].facetScore) { if (maxPreRealignmentIndex != maxIndex) thread[maxIndex] = null; maxIndex = last_joined; } if (thread[last_joined].preRealignmentFacetScore > thread[maxPreRealignmentIndex].preRealignmentFacetScore) { if (maxPreRealignmentIndex != maxIndex) thread[maxPreRealignmentIndex] = null; maxPreRealignmentIndex = last_joined; } if (last_joined != maxIndex && last_joined != maxPreRealignmentIndex) thread[last_joined] = null; } catch (InterruptedException e) { OpalLogWriter.stdErrLogln("InterruptedException " + e.toString()); throw new GenericOpalException("InterruptedException " + e.toString()); } } // if(advising_config.length>1 && thread[maxIndex]!=null && thread[maxIndex].facetScore>=0) if (!thread[maxIndex].printBest()) System.err.println("Print returned false"); if (advising_config.length > 1 && realignment_config != null && thread[maxPreRealignmentIndex] != null && thread[maxPreRealignmentIndex].facetScore >= 0) { if (input.bestPreRealignmentOutputFile != null) if (!thread[maxPreRealignmentIndex].printBestPreRealignment()) System.err.println("Print returned false"); if (input.bestPreRealignmentsRealignmentOutputFile != null) if (!thread[maxPreRealignmentIndex].printBestPreRealignmentsRealignment()) System.err.println("Print returned false"); if (input.bestPreRealignmentsRealignmentOutputFileIncludePreRealignment != null) if (!thread[maxPreRealignmentIndex] .printBestPreRealignmentsRealignmentIncludePreRealignment()) System.err.println("Print returned false"); } if (advising_config.length > 1 && realignment_config != null && thread[maxIndex] != null && thread[maxIndex].facetScore >= 0 && thread[maxPreRealignmentIndex] != null && thread[maxPreRealignmentIndex].facetScore >= 0 && thread[maxPreRealignmentIndex].preRealignmentFacetScore < thread[maxIndex].facetScore) { if (input.bestOutputFileIncludePreRealignment != null) if (!thread[maxIndex].printBestIncludePreRealignment()) System.err.println("Print returned false"); } else if (advising_config.length > 1 && thread[maxPreRealignmentIndex] != null && thread[maxPreRealignmentIndex].facetScore >= 0) { if (input.bestOutputFileIncludePreRealignment != null) if (!thread[maxPreRealignmentIndex].printBestIncludePreRealignment()) System.err.println("Print returned false"); } if (input.verbosity > 0) { Date now = new Date(); long diff = now.getTime() - start.getTime(); System.err.printf("Total time for job: %.1f seconds\n\n", ((float) diff / 1000 + .05)); } System.exit(0); }