예제 #1
1
 private static String getAbsoluteExecutablePath(final Config config) {
   if (Strings.isNullOrEmpty(config.getWrapperScript())) {
     return "";
   }
   return FileUtilities.getAbsoluteFileForExecutables(new File(config.getWrapperScript()))
       .getPath();
 }
예제 #2
0
 @Override
 public Worker create(final Config config, final DependencyResolver dependencies) {
   final MSMSEvalWorker worker = new MSMSEvalWorker();
   worker.setMsmsEvalExecutable(
       FileUtilities.getAbsoluteFileForExecutables(new File(config.get(MSMS_EVAL_EXECUTABLE))));
   worker.setConverter(getConverter());
   return worker;
 }
예제 #3
0
  @Override
  public ExitCode run(final SwiftEnvironment environment) {
    if (environment.getParameters().size() < 1) {
      throw new MprcException(
          "Missing path to configuration file.\nUsage: reformat-config <config> [<result>]");
    }

    final File file = new File(environment.getParameters().get(0));

    final PrintWriter printWriter;
    if (environment.getParameters().size() >= 2) {
      String pathname = environment.getParameters().get(1);
      try {
        printWriter = new PrintWriter(new File(pathname));
      } catch (FileNotFoundException e) {
        environment.logCommandError(
            "Could not open file for writing: "
                + pathname
                + "\n"
                + MprcException.getDetailedMessage(e));
        return ExitCode.Error;
      }
    } else {
      printWriter = new PrintWriter(System.out);
    }

    final AppConfigReader reader = new AppConfigReader(file, getFactory());
    try {
      reader.load(environment.getApplicationConfig());
    } finally {
      FileUtilities.closeQuietly(reader);
    }

    AppConfigWriter writer = null;

    try {
      writer = new AppConfigWriter(printWriter, getFactory());
      writer.save(environment.getApplicationConfig());
    } finally {
      FileUtilities.closeQuietly(writer);
      FileUtilities.closeQuietly(printWriter);
    }
    return ExitCode.Ok;
  }
예제 #4
0
 /**
  * goes to the first sequence in the sequence database file so that the next call to getHeader()
  * will return the first header in the file.
  */
 public void beforeFirst() {
   try {
     FileUtilities.closeQuietly(this.reader);
     reopenReader();
     this.nextHeader = this.reader.readLine();
   } catch (Exception e) {
     throw new MprcException(
         "Cannot open FASTA file [" + this.fastaFile.getAbsolutePath() + "]", e);
   }
 }
예제 #5
0
  private static void writeWorkerAllocatorInputObject(final File file, final SgePacket object)
      throws IOException {
    BufferedWriter bufferedWriter = null;

    try {
      final XStream xStream = new XStream(new DomDriver());
      bufferedWriter = new BufferedWriter(new FileWriter(file));
      bufferedWriter.write(xStream.toXML(object));
    } finally {
      FileUtilities.closeQuietly(bufferedWriter);
    }
  }
  /** Start reading from the beginning */
  public void resetCurrentRowPointer() throws IOException {
    currentRowValue = null;

    FileUtilities.closeQuietly(reader);

    reader = new BufferedReader(new FileReader(file), BUFFER_SIZE);

    // Initialize by reading the first row
    nextRow();

    // Next call to nextRow will return the line we just read
    previousRow();
  }
예제 #7
0
 /**
  * @param mgf .mgf file
  * @return List of all spectra titles.
  */
 public static List<String> getTitles(final File mgf) {
   PeakListReader sourceMgfReader = new MgfPeakListReader(mgf, false);
   List<String> titles = new ArrayList<String>(1000);
   try {
     MascotGenericFormatPeakList peakList;
     while ((peakList = sourceMgfReader.nextPeakList()) != null) {
       titles.add(peakList.getTitle());
     }
   } finally {
     FileUtilities.closeQuietly(sourceMgfReader);
   }
   return titles;
 }
예제 #8
0
  private GridWorkPacket getBaseGridWorkPacket(final String command) {
    final GridWorkPacket gridWorkPacket = new GridWorkPacket(command, null);

    gridWorkPacket.setNativeSpecification(nativeSpecification);
    gridWorkPacket.setQueueName(queueName);
    gridWorkPacket.setMemoryRequirement(memoryRequirement);

    gridWorkPacket.setWorkingFolder(new File(".").getAbsolutePath());
    gridWorkPacket.setLogFolder(
        FileUtilities.getDateBasedDirectory(getDaemonLoggerFactory().getLogFolder(), new Date())
            .getAbsolutePath());

    return gridWorkPacket;
  }
예제 #9
0
 /**
  * Process message from the grid engine itself. In case the process failed, we keep the work
  * packet around so the developer can reproduce the error.
  *
  * @param w Work packet whose state changed
  */
 @Override
 public void stateChanged(final GridWorkPacket w) {
   if (w == null) {
     return;
   }
   // We report state change just once.
   if (!reported) {
     try {
       if (w.getPassed()) {
         // This is the last response we will send - request is completed.
         // There might have been an error from RMI, check that
         if (allocatorListener.getLastThrowable() == null) {
           sendResponse(
               request, new DaemonProgressMessage(DaemonProgress.RequestCompleted), true);
         } else {
           sendResponse(
               request, new DaemonException(allocatorListener.getLastThrowable()), true);
         }
       } else if (w.getFailed()) {
         // This is the last response we will send - request failed
         if (allocatorListener.getLastThrowable() == null) {
           sendResponse(request, new DaemonException(w.getErrorMessage()), true);
         } else {
           sendResponse(
               request,
               new DaemonException(w.getErrorMessage(), allocatorListener.getLastThrowable()),
               true);
         }
       }
       reported = true;
     } finally {
       if (!w.getFailed()) {
         // Delete workPacket file
         LOGGER.debug("Deleting sge packet file: " + sgePacketFile.getAbsolutePath());
         FileUtilities.quietDelete(sgePacketFile);
       } else {
         LOGGER.warn("Retaining sge packet file: " + sgePacketFile.getAbsolutePath());
       }
     }
   }
 }
예제 #10
0
 /** Process failure, return more descriptive exception */
 private DaemonException processFailedJob(
     final GridWorkPacket gridWorkPacket, final File packageFile, final Exception exception) {
   final DaemonException daemonException;
   final File storedFile = failedJobManager.storeFile(packageFile);
   if (storedFile != null) {
     daemonException =
         new DaemonException(
             MessageFormat.format(
                 "Failed passing work packet to grid engine:\n{0}\nUse {1} for the --sge parameter",
                 gridWorkPacket.toString(), storedFile.getAbsolutePath()),
             exception);
   } else {
     daemonException =
         new DaemonException(
             "Failed passing work packet to grid engine:\n" + gridWorkPacket.toString(),
             exception);
   }
   FileUtilities.quietDelete(packageFile);
   LOGGER.error(MprcException.getDetailedMessage(daemonException), daemonException);
   return daemonException;
 }
예제 #11
0
  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
      throws ServletException {

    PrintWriter out = null;
    try {

      swiftDao.begin(); // Transaction-per-request

      final SearchRunFilter searchRunFilter = new SearchRunFilter();
      searchRunFilter.setStart("0");
      searchRunFilter.setCount("50");

      out = resp.getWriter();

      final StringBuilder response = new StringBuilder(TYPICAL_RESPONSE_SIZE);
      response.append("[");

      final List<SearchRun> searchRuns = swiftDao.getSearchRunList(searchRunFilter);
      for (int i = 0; i < searchRuns.size(); i++) {
        final SearchRun searchRun = searchRuns.get(i);
        final int runningTasks = swiftDao.getNumberRunningTasksForSearchRun(searchRun);
        JsonWriter.appendSearchRunJson(response, i, searchRun, runningTasks, null, false);
        if (i + 1 < searchRuns.size()) {
          response.append(",\n");
        }
      }
      response.append("]");

      out.print(response.toString());

      swiftDao.commit();

    } catch (Exception e) {
      swiftDao.rollback();
      throw new MprcException("Could not obtain list of search runs", e);
    } finally {
      FileUtilities.closeQuietly(out);
    }
  }
예제 #12
0
 /**
  * goes through each header in a fasta file and checks to make sure it is a valid fasta header. If
  * any problems are encountered or a header does not check out then false is returned
  *
  * @param toCheck the file you want to see is a valid FASTA file
  * @return true if the file is a valid fasta file else false
  */
 public static boolean isFASTAFileValid(final File toCheck) {
   DBInputStream in = null;
   try {
     in = new FASTAInputStream(toCheck);
     int sequenceCount = 0;
     in.beforeFirst();
     while (in.gotoNextSequence()) {
       if (isHeader(in.getHeader())) {
         sequenceCount++;
       } else {
         return false;
       }
     }
     return (sequenceCount != 0);
   } catch (Exception e) {
     // SWALLOWED: We just return false as in "not valid"
     LOGGER.warn(e);
     return false;
   } finally {
     FileUtilities.closeQuietly(in);
   }
 }
예제 #13
0
 /** performs any cleaning up that may be necessary. Always call when you are done. */
 public void close() {
   FileUtilities.closeQuietly(this.reader);
 }
예제 #14
0
 @Override
 public void close() throws IOException {
   FileUtilities.closeQuietly(reader);
 }
예제 #15
0
  @Override
  public void process(
      final WorkPacket workPacket, final File tempWorkFolder, final UserProgressReporter reporter) {
    if (!MSMSEvalWorkPacket.class.isInstance(workPacket)) {
      throw new DaemonException(
          "Unknown request type ["
              + workPacket.getClass().getName()
              + "] expecting ["
              + MSMSEvalWorkPacket.class.getName()
              + "]");
    }

    final MSMSEvalWorkPacket msmsEvalWorkPacket = (MSMSEvalWorkPacket) workPacket;

    /** MGF source file. */
    final File sourceFile = msmsEvalWorkPacket.getSourceFile();
    checkFile(sourceFile, false, "The source file");

    /** MsmsEval parameter file. */
    final File msmsEvalParamFile = msmsEvalWorkPacket.getMsmsEvalParamFile();
    checkFile(msmsEvalParamFile, false, "The msmsEval parameter file");

    /** Output directory. */
    final File outputDirectory = msmsEvalWorkPacket.getOutputFile().getParentFile();
    FileUtilities.ensureFolderExists(outputDirectory);
    checkFile(outputDirectory, true, "The msmsEval output directory");

    /** Temporary files. */
    final File outputMzXMLFile =
        MSMSEvalWorkPacket.getExpectedMzXMLOutputFileName(sourceFile, tempWorkFolder);
    final File msmsEvalOutputFile =
        MSMSEvalWorkPacket.getExpectedMsmsEvalOutputFileName(sourceFile, tempWorkFolder);

    /** Files to be published. */
    final File finalOutputFile = msmsEvalWorkPacket.getOutputFile();
    final File outputFile = getTempOutputFile(tempWorkFolder, finalOutputFile);

    final File finalEmFile = msmsEvalWorkPacket.getOutputEmFile();
    final File emFile = getTempOutputFile(tempWorkFolder, finalEmFile);

    // If msmsEval has been executed, skip operation.
    if (!msmsEvalWorkPacket.isFromScratch() && hasMSMSEvalFilterWorkerRun(finalOutputFile)) {
      skippedExecution = true;
      return;
    }

    MSMSEval msmsEval = null;

    try {
      LOGGER.info("Converting mgf to mzxml.");

      final Map<Integer, String> mzXMLScanToMGFTitle =
          getConverter().convert(sourceFile, outputMzXMLFile, true);

      LOGGER.info("Convertion mgf to mzxml completed.");
      LOGGER.info("Created mzxml file: " + outputMzXMLFile.getAbsolutePath());

      LOGGER.info("Running msmsEval on the mzxml file.");

      msmsEval = new MSMSEval(outputMzXMLFile, msmsEvalParamFile, msmsEvalExecutable);

      msmsEval.execute(reporter);

      LOGGER.info("Command msmsEval execution completed.");

      LOGGER.info("Formatting msmsEval output file with mgf scan numbers.");

      MSMSEvalOutputFileFormatter.replaceMzXMLScanIdsWithMgfNumbers(
          msmsEvalOutputFile, outputFile, mzXMLScanToMGFTitle);

      LOGGER.info("Formatted msmsEval output file " + outputFile.getAbsolutePath() + " created.");

      publish(outputFile, finalOutputFile);
      publish(emFile, finalEmFile);
    } catch (Exception e) {
      throw new DaemonException(e);
    } finally {
      // Clean up.
      LOGGER.info(
          "Deleting files: ["
              + msmsEvalOutputFile.getAbsolutePath()
              + ", "
              + outputMzXMLFile.getAbsolutePath()
              + "]");
      FileUtilities.deleteNow(msmsEvalOutputFile);
      FileUtilities.deleteNow(outputMzXMLFile);
    }
  }
예제 #16
0
 /** performs any cleaning up that may be necessary. */
 public void close() {
   FileUtilities.closeQuietly(this.out);
 }
예제 #17
0
 @AfterTest
 public void teardown() throws IOException {
   FileUtilities.cleanupTempFile(logFile);
 }