/** * Scans the given command-line options for a specific file option and returns the corresponding * file if it exists, {@code null} otherwise. * * @param args command-line options. * @param option a specific file option to look for. * @return a {@link File} object that corresponds to a desired command-line option, or {@code * null} if it does not exist. */ private File parseFileOption(SBProperties args, Option<File> option) { if (args.containsKey(option)) { File notesFile = new File(args.getProperty(option)); if ((notesFile != null) && notesFile.exists() && notesFile.canRead()) { return notesFile; } } return null; }
/* * (non-Javadoc) * @see de.zbit.Launcher#commandLineMode(de.zbit.AppConf) */ @Override public void commandLineMode(AppConf appConf) { SBProperties args = appConf.getCmdArgs(); if (args.containsKey(LogOptions.LOG_FILE)) { LogUtil.addHandler( new ConsoleHandler() { /** Formatter */ OneLineFormatter formatter = new OneLineFormatter(false, false, false); /* * (non-Javadoc) * @see java.util.logging.StreamHandler#flush() */ @Override public synchronized void flush() { System.out.flush(); } /* * (non-Javadoc) * @see * java.util.logging.ConsoleHandler#publish(java.util.logging.LogRecord) */ @Override public void publish(LogRecord record) { if (record.getLevel().intValue() == Level.INFO.intValue()) { try { String message = formatter.format(record); System.out.write(message.getBytes()); } catch (IOException exc) { reportError(null, exc, ErrorManager.FORMAT_FAILURE); return; } } } }, getLogPackages()); } BiGGDB bigg = null; Parameters parameters = new Parameters(); parameters.annotateWithBiGG = args.getBooleanProperty(ModelPolisherOptions.ANNOTATE_WITH_BIGG); if (parameters.annotateWithBiGG) { try { // Connect to database and launch application: String passwd = args.getProperty(DBOptions.PASSWD); bigg = new BiGGDB( new PostgreSQLConnector( args.getProperty(DBOptions.HOST), args.getIntProperty(DBOptions.PORT), args.getProperty(DBOptions.USER), passwd != null ? passwd : "", args.getProperty(DBOptions.DBNAME))); } catch (SQLException | ClassNotFoundException exc) { exc.printStackTrace(); } } // Gives users the choice to pass an alternative model notes XHTML file to // the program. File modelNotesFile = parseFileOption(args, ModelPolisherOptions.MODEL_NOTES_FILE); File documentNotesFile = parseFileOption(args, ModelPolisherOptions.DOCUMENT_NOTES_FILE); String documentTitlePattern = null; if (args.containsKey(ModelPolisherOptions.DOCUMENT_TITLE_PATTERN)) { documentTitlePattern = args.getProperty(ModelPolisherOptions.DOCUMENT_TITLE_PATTERN); } double[] coefficients = null; if (args.containsKey(ModelPolisherOptions.FLUX_COEFFICIENTS)) { String c = args.getProperty(ModelPolisherOptions.FLUX_COEFFICIENTS); String coeff[] = c.substring(1, c.length() - 1).split(","); coefficients = new double[coeff.length]; for (int i = 0; i < coeff.length; i++) { coefficients[i] = Double.parseDouble(coeff[i].trim()); } } String fObj[] = null; if (args.containsKey(ModelPolisherOptions.FLUX_OBJECTIVES)) { String fObjectives = args.getProperty(ModelPolisherOptions.FLUX_OBJECTIVES); fObj = fObjectives.substring(1, fObjectives.length() - 1).split(":"); } parameters.includeAnyURI = args.getBooleanProperty(ModelPolisherOptions.INCLUDE_ANY_URI); parameters.checkMassBalance = args.getBooleanProperty(ModelPolisherOptions.CHECK_MASS_BALANCE); parameters.compression = ModelPolisherOptions.Compression.valueOf( args.getProperty(ModelPolisherOptions.COMPRESSION_TYPE)); parameters.documentNotesFile = documentNotesFile; parameters.documentTitlePattern = documentTitlePattern; parameters.fluxCoefficients = coefficients; parameters.fluxObjectives = fObj; parameters.modelNotesFile = modelNotesFile; parameters.omitGenericTerms = args.getBooleanProperty(ModelPolisherOptions.OMIT_GENERIC_TERMS); parameters.sbmlValidation = args.getBooleanProperty(ModelPolisherOptions.SBML_VALIDATION); // run polishing operations in background and parallel. try { batchProcess( bigg, new File(args.getProperty(IOOptions.INPUT)), new File(args.getProperty(IOOptions.OUTPUT)), parameters); } catch (SBMLException | XMLStreamException | IOException exc) { exc.printStackTrace(); } }