예제 #1
0
 /**
  * @param bigg
  * @param input
  * @param output
  * @param parameters
  * @throws IOException
  * @throws XMLStreamException
  */
 public void batchProcess(BiGGDB bigg, File input, File output, Parameters parameters)
     throws IOException, XMLStreamException {
   // We test if non-existing path denotes a file or directory by checking if
   // it contains at least one period in its name. If so, we assume it is a
   // file.
   if (!output.exists()
       && (output.getName().lastIndexOf('.') < 0)
       && !(input.isFile() && input.getName().equals(output.getName()))) {
     logger.info(MessageFormat.format("Creating directory {0}.", output.getAbsolutePath()));
     output.mkdir();
   }
   if (input.isFile()) {
     boolean jsonFile = SBFileFilter.hasFileType(input, SBFileFilter.FileType.JSON_FILES);
     boolean matFile = SBFileFilter.hasFileType(input, SBFileFilter.FileType.MAT_FILES);
     if (SBFileFilter.isSBMLFile(input) || matFile || jsonFile) {
       if (output.isDirectory()) {
         String fName = input.getName();
         if (matFile || jsonFile) {
           fName = FileTools.removeFileExtension(fName) + ".xml";
         }
         output = new File(Utils.ensureSlash(output.getAbsolutePath()) + fName);
       }
       polish(bigg, input, output, parameters);
     }
   } else {
     if (!output.isDirectory()) {
       throw new IOException(
           MessageFormat.format("Cannot write to file {0}.", output.getAbsolutePath()));
     }
     for (File file : input.listFiles()) {
       File target = new File(Utils.ensureSlash(output.getAbsolutePath()) + file.getName());
       batchProcess(bigg, file, target, parameters);
     }
   }
 }
예제 #2
0
 /**
  * @param bigg
  * @param input
  * @param output
  * @param parameters
  * @throws XMLStreamException
  * @throws IOException
  */
 public void polish(BiGGDB bigg, File input, File output, Parameters parameters)
     throws XMLStreamException, IOException {
   long time = System.currentTimeMillis();
   logger.info(MessageFormat.format("Reading input file {0}.", input.getAbsolutePath()));
   SBMLDocument doc = null;
   if (SBFileFilter.hasFileType(input, SBFileFilter.FileType.MAT_FILES)) {
     doc = COBRAparser.read(input, parameters.omitGenericTerms);
   } else if (SBFileFilter.hasFileType(input, SBFileFilter.FileType.JSON_FILES)) {
     doc = JSONparser.read(input);
   } else {
     doc = SBMLReader.read(input, new UpdateListener());
   }
   if (!doc.isSetLevelAndVersion()
       || (doc.getLevelAndVersion().compareTo(ValuePair.of(3, 1)) < 0)) {
     logger.info("Trying to convert the model to Level 3 Version 2.");
     org.sbml.jsbml.util.SBMLtools.setLevelAndVersion(doc, 3, 1);
   }
   SBMLPolisher polisher = new SBMLPolisher();
   polisher.setCheckMassBalance(parameters.checkMassBalance);
   polisher.setOmitGenericTerms(parameters.omitGenericTerms);
   if (parameters.includeAnyURI != null) {
     polisher.setIncludeAnyURI(parameters.includeAnyURI.booleanValue());
   }
   if (parameters.documentTitlePattern != null) {
     polisher.setDocumentTitlePattern(parameters.documentTitlePattern);
   }
   polisher.setFluxCoefficients(parameters.fluxCoefficients);
   polisher.setFluxObjectives(parameters.fluxObjectives);
   doc = polisher.polish(doc);
   if (parameters.annotateWithBiGG) {
     BiGGAnnotation annotation = new BiGGAnnotation(bigg, polisher);
     if (parameters.documentNotesFile != null) {
       annotation.setDocumentNotesFile(parameters.documentNotesFile);
     }
     if (parameters.modelNotesFile != null) {
       annotation.setModelNotesFile(parameters.modelNotesFile);
     }
     doc = annotation.annotate(doc);
   }
   // <?xml-stylesheet type="text/xsl"
   // href="/Users/draeger/Documents/workspace/BioNetView/resources/edu/ucsd/sbrg/bigg/bigg_sbml.xsl"?>
   logger.info(MessageFormat.format("Writing output file {0}", output.getAbsolutePath()));
   TidySBMLWriter.write(
       doc, output, getClass().getSimpleName(), getVersionNumber(), ' ', (short) 2);
   // SBMLWriter.write(doc, sbmlFile, ' ', (short) 2);
   if (parameters.compression != Compression.NONE) {
     String fileExtension = parameters.compression.getFileExtension();
     String archive = output.getAbsolutePath() + "." + fileExtension;
     logger.info(MessageFormat.format("Packing archive file {0}", archive));
     switch (parameters.compression) {
       case ZIP:
         ZIPUtils.ZIPcompress(
             new String[] {output.getAbsolutePath()}, archive, "SBML Archive", true);
         break;
       case GZIP:
         ZIPUtils.GZip(output.getAbsolutePath(), archive);
         break;
       default:
         break;
     }
     if ((parameters.sbmlValidation != null) && parameters.sbmlValidation) {
       validate(archive);
     }
   }
   time = System.currentTimeMillis() - time;
   Calendar calendar = Calendar.getInstance();
   calendar.setTimeInMillis(time);
   logger.info(MessageFormat.format("Done ({0,time, ssss} s).", calendar.getTime()));
 }
 /* (non-Javadoc)
  * @see de.zbit.kegg.gui.TranslatorGraphLayerPanel#getOutputFileFilterForRealDocument()
  */
 @Override
 protected List<FileFilter> getOutputFileFilterForRealDocument() {
   List<FileFilter> ff = new LinkedList<FileFilter>();
   ff.add(SBFileFilter.createSBGNFileFilter());
   return ff;
 }