/**
   * {@inheritDoc}
   *
   * @return
   */
  @Override
  public ReturnValue clean_up() {
    try {
      writer.flush();
      writer.close();
      if (options.has("stdout")) {
        Log.stdout(writer.toString());
      }

    } catch (IOException ex) {
      Log.error("Writer is already closed.", ex);
    }
    return ret;
  }
Пример #2
0
 /**
  * getHtml.
  *
  * @param obj a {@link java.lang.Object} object.
  * @param registration a {@link net.sourceforge.seqware.common.model.Registration} object.
  * @param listSeqencerRunNodeId a {@link java.util.List} object.
  * @param treeType a {@link java.lang.String} object.
  * @return a {@link java.lang.String} object.
  */
 public static String getHtml(
     Object obj, Registration registration, List<String> listSeqencerRunNodeId, String treeType) {
   String html = "";
   if (obj instanceof SequencerRun) {
     html = getAllHtml((SequencerRun) obj, registration, null, treeType);
   }
   if (obj instanceof Lane) {
     html = getAllHtml((Lane) obj, registration, null, treeType);
   }
   if (obj instanceof IUS) {
     Log.info("ius call");
     html = getAllHtml((IUS) obj, registration, null, false, false, treeType);
   }
   if (obj instanceof Processing) {
     html =
         getAllHtml(
             (Processing) obj,
             registration,
             null,
             0,
             listSeqencerRunNodeId,
             true,
             false,
             treeType);
   }
   return html;
 }
Пример #3
0
  /** getXml. */
  @Get
  public void getXml() {
    JaxbObject<Lane> jaxbTool = new JaxbObject<>();
    Hibernate3DtoCopier copier = new Hibernate3DtoCopier();

    Lane dto;
    authenticate();

    LaneService ss = BeanFactory.getLaneServiceBean();
    Lane lane = testIfNull(ss.findBySWAccession(getId()));
    CollectionPropertyName<Lane>[] createCollectionPropertyNames =
        CollectionPropertyName.createCollectionPropertyNames(
            Lane.class, new String[] {"laneAttributes"});
    dto =
        copier.hibernate2dto(
            Lane.class,
            lane,
            new Class<?>[] {LibraryStrategy.class, LibrarySource.class, LibrarySelection.class},
            createCollectionPropertyNames);

    if (fields.contains("sequencerRun")) {
      SequencerRun sr = lane.getSequencerRun();
      if (sr != null) {
        SequencerRun copySR = copier.hibernate2dto(SequencerRun.class, sr);
        dto.setSequencerRun(copySR);
      } else {
        Log.info("Could not be found sequencer run");
      }
    }

    Document line = XmlTools.marshalToDocument(jaxbTool, dto);
    getResponse().setEntity(XmlTools.getRepresentation(line));
  }
 private void reportWorkflowRunStdErrOut(String workflowRunAccession, int streamType)
     throws IOException {
   String title = "workflowrun_" + workflowRunAccession;
   if (streamType == 1) {
     title = title + "_STDOUT";
     initWriter(title);
     writer.write(metadata.getWorkflowRunReportStdOut(Integer.parseInt(workflowRunAccession)));
   } else if (streamType == 2) {
     title = title + "_STDERR";
     initWriter(title);
     writer.write(metadata.getWorkflowRunReportStdErr(Integer.parseInt(workflowRunAccession)));
   } else {
     Log.error(
         "Unknown stream type: "
             + streamType
             + " should be "
             + WorkflowRunReporter.STDERR
             + " for stderr or "
             + WorkflowRunReporter.STDOUT
             + " for stdout!");
     initWriter(title);
     writer.write(
         "Unknown stream type: "
             + streamType
             + " should be "
             + WorkflowRunReporter.STDERR
             + " for stderr or "
             + WorkflowRunReporter.STDOUT
             + " for stdout!");
   }
 }
 private void reportOnWorkflow(
     String workflowAccession, WorkflowRunStatus status, Date earlyDate, Date lateDate)
     throws IOException {
   String title = "";
   if (workflowAccession != null) {
     title = "workflow_" + workflowAccession;
   }
   if (status != null) {
     title += "status_" + status.name();
   }
   if (earlyDate != null) {
     title += "from" + dateFormat.format(earlyDate);
   }
   if (lateDate != null) {
     title += "to" + dateFormat.format(lateDate);
   }
   initWriter(title);
   String report;
   try {
     Integer workflowParameter = null;
     if (workflowAccession != null) {
       workflowParameter = Integer.parseInt(workflowAccession);
     }
     report = metadata.getWorkflowRunReport(workflowParameter, status, earlyDate, lateDate);
   } catch (RuntimeException e) {
     Log.fatal("Workflow not found", e);
     ret = new ReturnValue(ReturnValue.INVALIDPARAMETERS);
     return;
   }
   if (options.has("human")) {
     writer.write(TabExpansionUtil.expansion(report));
     return;
   }
   writer.write(report);
 }
Пример #6
0
  /** getXml. */
  @Get
  public void getXml() {
    authenticate();
    WorkflowService ss = BeanFactory.getWorkflowServiceBean();
    Hibernate3DtoCopier copier = new Hibernate3DtoCopier();
    JaxbObject<Workflow> jaxbTool = new JaxbObject<Workflow>();
    Workflow workflow = (Workflow) testIfNull(ss.findBySWAccession(Integer.parseInt(getId())));
    Workflow dto = copier.hibernate2dto(Workflow.class, workflow);

    if (fields.contains("params")) {
      SortedSet<WorkflowParam> wps = workflow.getWorkflowParams();
      if (wps != null) {
        SortedSet<WorkflowParam> copiedParams = new TreeSet<WorkflowParam>();
        for (WorkflowParam param : workflow.getWorkflowParams()) {
          copiedParams.add(copier.hibernate2dto(WorkflowParam.class, param));
        }
        dto.setWorkflowParams(copiedParams);
      } else {
        Log.info("Could not be found: workflow params");
      }
    }
    if (fields.contains("attributes")) {
      Set<WorkflowAttribute> was = workflow.getWorkflowAttributes();
      if (was != null && !was.isEmpty()) {
        Set<WorkflowAttribute> newwas = new TreeSet<WorkflowAttribute>();
        for (WorkflowAttribute wa : was) {
          newwas.add(copier.hibernate2dto(WorkflowAttribute.class, wa));
        }
        dto.setWorkflowAttributes(newwas);
      }
    }

    Document line = XmlTools.marshalToDocument(jaxbTool, dto);
    getResponse().setEntity(XmlTools.getRepresentation(line));
  }
Пример #7
0
 @Test
 public void testMonitoring() throws IOException {
   String listCommand =
       "-p net.sourceforge.seqware.pipeline.plugins.WorkflowStatusChecker -- --tp 1000";
   String listOutput = ITUtility.runSeqWareJar(listCommand, ReturnValue.SUCCESS);
   Log.info(listOutput);
 }
Пример #8
0
 @Test
 public void testLaunchScheduled() throws IOException {
   // launch-scheduled
   String schedCommand =
       "-p net.sourceforge.seqware.pipeline.plugins.WorkflowLauncher -- --launch-scheduled";
   String schedOutput = ITUtility.runSeqWareJar(schedCommand, ReturnValue.SUCCESS);
   Log.info(schedOutput);
 }
Пример #9
0
 /** close. */
 public static synchronized void close() {
   if (metadataDBWrapper.get() != null) {
     Log.debug(metadataDBWrapper.get().toString() + " was closed ");
     metadataDBWrapper.get().clean_up();
     metadataDBWrapper.set(null);
     // db = null;
   }
 }
  private String getNameNode(Integer id, String typeNode) {
    String name = "";

    if ("st".equals(typeNode)) {
      Log.info("find Study");
      name = getStudyService().findByID(id).getTitle();
    }
    if ("exp".equals(typeNode)) {
      Log.info("find Experiment");
      name = getExperimentService().findByID(id).getTitle();
    }
    if ("sam".equals(typeNode)) {
      Log.info("find Sample");
      name = getSampleService().findByID(id).getTitle();
    }
    if ("seq".equals(typeNode)) {
      Log.info("find Lane");
      name = getLaneService().findByID(id).getName();
    }
    if ("ius".equals(typeNode)) {
      Log.info("find IUS");
      name = getIUSService().findByID(id).getName();
    }
    if ("ae".equals(typeNode)) {
      Log.info("find Study");
      name = "SWID " + getProcessingService().findByID(id).getSwAccession().toString();
    }
    if ("sr".equals(typeNode)) {
      Log.info("find Seq Run");
      name = getSequencerRunService().findByID(id).getName();
    }

    return name;
  }
Пример #11
0
  /** getXml. */
  @Get
  public void getXml() {
    authenticate();

    JaxbObject<Lane> jaxbTool = new JaxbObject<>();
    Hibernate3DtoCopier copier = new Hibernate3DtoCopier();

    SampleService ss = BeanFactory.getSampleServiceBean();
    Sample sample = testIfNull(ss.findBySWAccession(getId()));
    CollectionPropertyName<Sample>[] createCollectionPropertyNames =
        CollectionPropertyName.createCollectionPropertyNames(
            Sample.class, new String[] {"sampleAttributes"});
    Sample dto =
        copier.hibernate2dto(
            Sample.class, sample, new Class<?>[] {}, createCollectionPropertyNames);

    if (fields.contains("lanes")) {
      SortedSet<Lane> lanes = sample.getLanes();
      if (lanes != null) {
        SortedSet<Lane> copiedLanes = new TreeSet<>();
        for (Lane lane : lanes) {
          copiedLanes.add(copier.hibernate2dto(Lane.class, lane));
        }
        dto.setLanes(copiedLanes);
      } else {
        Log.info("Could not be found: lanes");
      }
    }
    if (fields.contains("ius")) {
      SortedSet<IUS> ius = sample.getIUS();
      if (ius != null) {
        SortedSet<IUS> copiedIUS = new TreeSet<>();
        for (IUS i : ius) {
          copiedIUS.add(copier.hibernate2dto(IUS.class, i));
        }
        dto.setIUS(copiedIUS);
      }
      {
        Log.info("Could not be found : ius");
      }
    }

    Document line = XmlTools.marshalToDocument(jaxbTool, dto);
    getResponse().setEntity(XmlTools.getRepresentation(line));
  }
  /**
   * {@inheritDoc}
   *
   * @return
   */
  @Override
  public String get_syntax() {

    try {
      parser.printHelpOn(System.err);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      Log.fatal(e);
    }
    return ("");
  }
Пример #13
0
 /**
  * getInstance.
  *
  * @return a {@link net.sourceforge.seqware.common.ContextImpl} object.
  */
 public static synchronized ContextImpl getInstance() {
   if (ctx == null) {
     ApplicationContext c = ContextLoader.getCurrentWebApplicationContext();
     if (c == null) {
       Log.info("ContextImpl: Could not find web context. Switching to XML context.");
       c = new ClassPathXmlApplicationContext("applicationContext.xml");
     }
     ctx = (ContextImpl) c.getBean("contextImpl");
   }
   return ctx;
 }
 /**
  * Given a workflowRunAcc returns a list of file paths that were used in that run using
  * effectively, the workflow run reporter.
  *
  * <p>Hopefully, this is the last we'll use this approach!
  *
  * @param workflowRunAcc
  * @param filesToRun
  * @return
  */
 private List<Integer> getListOfFiles(int workflowRunAcc) {
   Map<String, String> map = generateWorkflowRunMap(workflowRunAcc);
   List<Integer> ranOnList = new ArrayList<>();
   if (map.isEmpty()) {
     return ranOnList;
   }
   String ranOnString = map.get("Immediate Input File SWIDs");
   if (ranOnString == null) {
     return ranOnList;
   }
   String[] ranOnArr = ranOnString.split(",");
   if (ranOnString.isEmpty()) {
     return ranOnList;
   }
   for (String i : ranOnArr) {
     ranOnList.add(Integer.valueOf(i.trim()));
     Log.trace("Adding item: " + i);
   }
   Log.debug("Got list of files: " + StringUtils.join(ranOnList, ','));
   return ranOnList;
 }
Пример #15
0
 @Test
 public void runDatabaseCheck() throws IOException {
   String listCommand = "-p net.sourceforge.seqware.pipeline.plugins.checkdb.CheckDB";
   String listOutput = ITUtility.runSeqWareJar(listCommand, ReturnValue.SUCCESS, null);
   Log.info(listOutput);
   String[] split = listOutput.split("Printed report to ");
   File report = new File(split[split.length - 1].trim());
   String readFileToString = FileUtils.readFileToString(report, (Charset) null);
   Assert.assertTrue("report empty", readFileToString.length() > 0);
   Assert.assertTrue(
       "report does not contain report", readFileToString.contains("CheckDB Report"));
   Assert.assertTrue("report contains exceptions", !readFileToString.contains("Exception"));
   FileUtils.deleteQuietly(report);
 }
Пример #16
0
 /**
  * get.
  *
  * @return a {@link net.sourceforge.seqware.common.metadata.MetadataDB} object.
  */
 public static synchronized MetadataDB get() {
   try {
     if (metadataDBWrapper.get() != null
         && ((metadataDBWrapper.get().getDb() != null
             && metadataDBWrapper.get().getDb().isClosed())))
     // || db.getSql()!=null && db.getSql().isClosed()))
     {
       metadataDBWrapper.get().clean_up();
       metadataDBWrapper.set(null);
       // db = null;
     }
   } catch (SQLException ex) {
     Log.error("Closing DB connection and creating a new one failed", ex);
   }
   if (metadataDBWrapper.get() == null) {
     metadataDBWrapper.set(new MetadataDB());
     // Log.debug("DBAccess is using " + user + " " + pass + " on " + connection);
     DataSource ds = null;
     try {
       InitialContext initCtx = new InitialContext();
       ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/SeqWareMetaDB");
     } catch (NamingException ex) {
       Log.fatal(ex);
       ex.printStackTrace();
     }
     if (ds != null) {
       Log.debug("init via db.init(ds), datasource is " + ds.getClass());
       metadataDBWrapper.get().init(ds);
     } else {
       Log.debug("init via init(user,pass,connection)");
       Map<String, String> settings = null;
       try {
         settings = ConfigTools.getSettings();
         String connection =
             "jdbc:postgresql://" + settings.get("SW_DB_SERVER") + "/" + settings.get("SW_DB");
         String user = settings.get("SW_DB_USER");
         String pass = settings.get("SW_DB_PASS");
         Log.debug("DBAccess is using " + user + " " + pass + " on " + connection);
         metadataDBWrapper.get().init(connection, user, pass);
       } catch (Exception ex) {
         Log.fatal("get()  could not init ", ex);
         Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex);
       }
     }
   }
   Log.debug(metadataDBWrapper.get().toString() + " was returned ");
   return metadataDBWrapper.get();
 }
Пример #17
0
  /** {@inheritDoc} */
  @Override
  @Put
  public Representation put(Representation entity) {
    authenticate();
    Representation representation = null;
    Experiment newObj = null;
    JaxbObject<Experiment> jo = new JaxbObject<Experiment>();
    try {
      String text = entity.getText();
      newObj = (Experiment) XmlTools.unMarshal(jo, new Experiment(), text);
    } catch (SAXException ex) {
      ex.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, ex);
    } catch (IOException e) {
      e.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e);
    }
    try {
      ExperimentService service = BeanFactory.getExperimentServiceBean();
      Experiment exp = (Experiment) testIfNull(service.findByID(newObj.getExperimentId()));
      exp.givesPermission(registration);

      // simple types
      String title = newObj.getTitle();
      String name = newObj.getName();
      String desc = newObj.getDescription();
      String alias = newObj.getAlias();
      String accession = newObj.getAccession();
      String status = newObj.getStatus();
      String centerName = newObj.getCenterName();
      String sequencerSpace = newObj.getSequenceSpace();
      String baseCaller = newObj.getBaseCaller();
      String qualityScorer = newObj.getQualityScorer();
      Integer qualityNumberLevels = newObj.getQualityNumberOfLevels();
      Integer qualityMultiplier = newObj.getQualityMultiplier();
      Long expectedNumberSpots = newObj.getExpectedNumberSpots();
      Long expectedNumberReads = newObj.getExpectedNumberReads();

      // foreign keys
      Study study = newObj.getStudy();
      Registration owner = newObj.getOwner();

      // sets
      Set<ExperimentAttribute> expAttributes = newObj.getExperimentAttributes();

      if (title != null) {
        exp.setTitle(title);
      }
      if (name != null) {
        exp.setName(name);
      }
      if (desc != null) {
        exp.setDescription(desc);
      }
      if (alias != null) {
        exp.setAlias(alias);
      }
      if (accession != null) {
        exp.setAccession(accession);
      }
      if (status != null) {
        exp.setStatus(status);
      }
      if (centerName != null) {
        exp.setCenterName(centerName);
      }
      if (sequencerSpace != null) {
        exp.setSequenceSpace(sequencerSpace);
      }
      if (baseCaller != null) {
        exp.setBaseCaller(baseCaller);
      }
      if (qualityScorer != null) {
        exp.setQualityScorer(qualityScorer);
      }
      if (qualityNumberLevels != null) {
        exp.setQualityNumberOfLevels(qualityNumberLevels);
      }
      if (qualityMultiplier != null) {
        exp.setQualityMultiplier(qualityMultiplier);
      }
      if (expectedNumberSpots != null) {
        exp.setExpectedNumberSpots(expectedNumberSpots);
      }
      if (expectedNumberReads != null) {
        exp.setExpectedNumberReads(expectedNumberReads);
      }

      if (study != null) {
        StudyService ss = BeanFactory.getStudyServiceBean();
        Study newStudy = ss.findByID(study.getStudyId());
        if (newStudy != null && newStudy.givesPermission(registration)) {
          exp.setStudy(newStudy);
        } else if (newStudy == null) {
          Log.info("Could not be found " + study);
        }
      }

      if (owner != null) {
        RegistrationService rs = BeanFactory.getRegistrationServiceBean();
        Registration newReg = rs.findByEmailAddress(owner.getEmailAddress());
        if (newReg != null) {
          exp.setOwner(newReg);
        } else {
          Log.info("Could not be found " + owner);
        }
      } else if (exp.getOwner() == null) {
        exp.setOwner(registration);
      }

      if (null != expAttributes) {
        exp.getExperimentAttributes().clear();
        for (ExperimentAttribute ea : expAttributes) {
          ea.setExperiment(exp);
          exp.getExperimentAttributes().add(ea);
        }
      }

      service.update(registration, exp);

      Hibernate3DtoCopier copier = new Hibernate3DtoCopier();
      Experiment detachedLane = copier.hibernate2dto(Experiment.class, exp);

      Document line = XmlTools.marshalToDocument(jo, detachedLane);
      representation = XmlTools.getRepresentation(line);
      getResponse().setEntity(representation);
      getResponse()
          .setLocationRef(
              getRequest().getRootRef() + "/experiments/" + detachedLane.getSwAccession());
      getResponse().setStatus(Status.SUCCESS_CREATED);
    } catch (SecurityException e) {
      getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN, e.getMessage());
    } catch (Exception e) {
      e.printStackTrace();
      getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }

    return representation;
  }
Пример #18
0
  /** {@inheritDoc} */
  @Override
  public Representation put(Representation entity) {
    authenticate();
    Representation representation = null;
    Workflow newWorkflow = null;
    JaxbObject<Workflow> jo = new JaxbObject<Workflow>();
    try {
      String text = entity.getText();
      newWorkflow = (Workflow) XmlTools.unMarshal(jo, new Workflow(), text);
    } catch (SAXException ex) {
      ex.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, ex.getMessage());
    } catch (IOException e) {
      e.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage());
    }
    try {
      WorkflowService fs = BeanFactory.getWorkflowServiceBean();
      Workflow workflow = (Workflow) testIfNull(fs.findByID(newWorkflow.getWorkflowId()));
      workflow.givesPermission(registration);
      // simple types
      String name = newWorkflow.getName();
      String desc = newWorkflow.getDescription();
      String baseIniFile = newWorkflow.getBaseIniFile();
      String command = newWorkflow.getCommand();
      String cwd = newWorkflow.getCwd();
      String host = newWorkflow.getHost();
      String inputAlgorithm = newWorkflow.getInputAlgorithm();
      String permanentBundleLocation = newWorkflow.getPermanentBundleLocation();
      String seqwareVersion = newWorkflow.getSeqwareVersion();
      String template = newWorkflow.getTemplate();
      String username = newWorkflow.getUsername();
      String version = newWorkflow.getVersion();
      // foreign keys
      Registration owner = newWorkflow.getOwner();

      workflow.setName(name);
      workflow.setDescription(desc);
      workflow.setBaseIniFile(baseIniFile);
      workflow.setCommand(command);
      workflow.setCwd(cwd);
      workflow.setHost(host);
      workflow.setInputAlgorithm(inputAlgorithm);
      workflow.setPermanentBundleLocation(permanentBundleLocation);
      workflow.setSeqwareVersion(seqwareVersion);
      workflow.setTemplate(template);
      workflow.setUsername(username);
      workflow.setVersion(version);
      workflow.setUpdateTimestamp(new Date());
      workflow.setWorkflowClass(newWorkflow.getWorkflowClass());
      workflow.setWorkflowType(newWorkflow.getWorkflowType());
      workflow.setWorkflowEngine(newWorkflow.getWorkflowEngine());

      if (owner != null) {
        RegistrationService rs = BeanFactory.getRegistrationServiceBean();
        Registration newReg = rs.findByEmailAddress(owner.getEmailAddress());
        if (newReg != null) {
          workflow.setOwner(newReg);
        } else {
          Log.info("Could not be found: " + owner);
        }
      } else if (workflow.getOwner() == null) {
        workflow.setOwner(registration);
      }

      if (newWorkflow.getWorkflowAttributes() != null) {
        workflow.getWorkflowAttributes().clear();
        for (WorkflowAttribute wfa : newWorkflow.getWorkflowAttributes()) {
          wfa.setWorkflow(workflow);
          workflow.getWorkflowAttributes().add(wfa);
        }
      }
      fs.update(registration, workflow);
      Hibernate3DtoCopier copier = new Hibernate3DtoCopier();
      Workflow detachedWorkflow = copier.hibernate2dto(Workflow.class, workflow);

      Document line = XmlTools.marshalToDocument(jo, detachedWorkflow);
      representation = XmlTools.getRepresentation(line);
      getResponse().setEntity(representation);
      getResponse()
          .setLocationRef(
              getRequest().getRootRef() + "/workflows/" + detachedWorkflow.getSwAccession());
      getResponse().setStatus(Status.SUCCESS_CREATED);
    } catch (SecurityException e) {
      getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN, e.getMessage());
    } catch (Exception e) {
      e.printStackTrace();
      getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }

    return representation;
  }
Пример #19
0
  /** {@inheritDoc} */
  @Override
  public ReturnValue do_run() {
    ReturnValue ret = new ReturnValue();
    ret.setRunStartTstmp(new Date());

    // Append initial command and options
    StringBuffer cmd = new StringBuffer(srf2FastqPath);
    cmd.append(" -c ");

    // filter bad reads if requested
    if (filter) {
      cmd.append(" -C ");
    }

    // If multiple ends, they should be sequential if bfast
    if (ends > 1 && "bfast".equals(aligner)) {
      cmd.append(" -S ");
    }
    // for bwa should be two different files, give the base as the first outputFile
    // NOTE: this means BWA output is one or two files, there's not shreading implemented for large
    // inputs
    else if (ends > 1 && "bwa".equals(aligner)) {
      cmd.append(" -n -s " + outputFiles.get(0) + " ");
    }

    // For paired end Illumina runs, add options to reverse compliments ends
    // great than 1
    /* Brian 20101215: I don't think this is actually needed
    if (ends > 1 && sequencer.compareTo("illumina-ga2") == 0) {
      cmd.append(" -r 1");

      for (int i = 2; i < ends; i++)
        cmd.append("," + i);

      cmd.append(" ");
    }*/

    // For Solid, have to add option to append Primer to Sequence
    if (sequencer.indexOf("AB_SOLiD_") > -1) {
      cmd.append(" -e ");
    }

    // Add file name to the end
    cmd.append(" " + input);

    // Run command
    Process p = null;

    Log.error("Starting srf2fastq"); // FIXME
    try {
      Log.error("Executing: " + cmd.toString());
      p = Runtime.getRuntime().exec(cmd.toString());
    } catch (IOException e) {
      return new ReturnValue(null, e.toString(), 4);
    }
    Log.error("srf2fastq launched"); // FIXME

    // we're only parsing stdout and managing file creation for BFAST output (all one file)
    if ("bfast".equals(aligner) || ("bwa".equals(aligner) && ends == 1)) {
      // Read from stdout and write to output files. Each output file gets 4 *
      // ends before moving to next entry. This assures all ends for a given
      // read are together
      try {
        // FIXME: This first function call is just for now, srf2fastq strips
        // primer automatically
        if (sequencer.indexOf("AB_SOLiD_") > -1) {
          StdOut.stdout2fileEncodedStripQualPrimer(p, outputFiles, ends * 4);
        } else {
          StdOut.stdout2file(p, outputFiles, false, ends * 4);
        }
      } catch (IOException e) {
        // FIXME: Need to clean up error codes and all
        p.destroy();
        return new ReturnValue(null, "stdout2file encountered an error", 4);
      }
    }
    // else we let srf2fastq make the files for us
    else if ("bwa".equals(aligner) && ends > 1) {
      // the command will just run as prepared, don't need to process stdout
    }

    // Wait on process
    try {
      p.waitFor();
    } catch (InterruptedException e) {
      p.destroy();
      return new ReturnValue(null, e.toString(), 4);
    }

    Log.error("srf2fastq done"); // FIXME

    // Otherwise return exit code
    ret.setExitStatus(p.exitValue());
    try {
      ret.setStderr(StdErr.stderr2string(p));
      ret.setExitStatus(p.exitValue());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    ret.setRunStopTstmp(new Date());
    return ret;
  }
Пример #20
0
  /** {@inheritDoc} */
  @Override
  public ReturnValue init() {
    ReturnValue ret = new ReturnValue();

    // some basics
    ret.setAlgorithm("SRF2Fastq");
    ret.setDescription(
        "This module converts an SRF file to a Fastq for use with aligners. The output is Sanger scaled.");
    ret.setVersion("0.7.1");

    // Parse relevant parameters
    for (int i = 0; i < this.getParameters().size(); i++) {
      if (this.getParameters().get(i).compareTo("-a") == 0
          || this.getParameters().get(i).compareTo("--aligner") == 0) {
        aligner = this.getParameters().get(++i).toLowerCase();
      } else if (this.getParameters().get(i).compareTo("-s") == 0
          || this.getParameters().get(i).compareTo("--sequencer") == 0) {
        sequencer = this.getParameters().get(++i).toLowerCase();
      } else if (this.getParameters().get(i).compareTo("-b") == 0
          || this.getParameters().get(i).compareTo("--bin") == 0) {
        srf2FastqPath = this.getParameters().get(++i);
      } else if (this.getParameters().get(i).compareTo("-f") == 0
          || this.getParameters().get(i).compareTo("--filter") == 0) {
        filter = true;
      } else if (this.getParameters().get(i).compareTo("-e") == 0
          || this.getParameters().get(i).compareTo("--ends") == 0) {
        try {
          ends = Integer.parseInt(this.getParameters().get(++i));
        } catch (NumberFormatException e) {
          ends = 0;
        }
      } else if (this.getParameters().get(i).compareTo("-i") == 0
          || this.getParameters().get(i).compareTo("--input") == 0) {
        input = this.getParameters().get(++i);
      } else if (this.getParameters().get(i).compareTo("-n") == 0
          || this.getParameters().get(i).compareTo("--num-output-files") == 0) {
        try {
          numOut = Integer.parseInt(this.getParameters().get(++i));
        } catch (NumberFormatException e) {
          numOut = 1;
        }
      } else if (this.getParameters().get(i).compareTo("-o") == 0
          || this.getParameters().get(i).compareTo("--output-prefix") == 0) {
        outputPrefix = this.getParameters().get(++i);
      }
    }

    // Set prefix if not defined
    if (outputPrefix == null) {
      // Strip off directories before
      Log.error("INPUT: " + input);
      int start = input.lastIndexOf(System.getProperty("file.separator"));
      if (start < 0) start = 0;

      // Strip off .srf ending
      int end = input.lastIndexOf(".srf");
      if (end > 0) outputPrefix = input.substring(start + 1, end);
    }

    // for bwa output only make 1 output file (single end) or 2 output files (paired end)
    if ("bwa".equals(aligner)) {
      File file = new File(outputPrefix);
      if (file.getParentFile() != null) file.getParentFile().mkdirs();
      if (ends > 1) {
        outputFiles.add(file);
      } else {
        String outputFileName = new String(outputPrefix + ".fastq");
        file = new File(outputFileName);
        outputFiles.add(file);
      }
    } else if ("bfast".equals(aligner)) {
      // Setup output files for BFAST, supports multiple output files for large inputs
      for (int i = 0; i < numOut; i++) {

        String outputFileName = new String(outputPrefix + "." + i + ".fastq");
        File file = new File(outputFileName);

        // Make directory if needed
        if (file.getParentFile() != null) file.getParentFile().mkdirs();

        // Make sure we can write to this file
        try {
          file.createNewFile();
        } catch (IOException e) {
          // FIXME: If file exists, continue anyway. Should we do this?
        }

        if (!file.canWrite()) {
          ret.setStderr("File " + outputFileName + " could not be created in a writable manner\n");
          ret.setExitStatus(ReturnValue.FILENOTWRITABLE);
          return ret;
        }

        // Otherwise we are in the clear, so add to file array
        outputFiles.add(file);
      }
    }

    // If we got here, no problems, so we are good
    ret.setExitStatus(ReturnValue.SUCCESS);
    return ret;
  }
Пример #21
0
  /**
   * {@inheritDoc}
   *
   * @return
   */
  @Override
  public ReturnValue do_run() {

    try {

      String timePeriod = null;
      WorkflowRunStatus status = options.valueOf(statusSpec);

      if (options.has("time-period")) {
        timePeriod = (String) options.valueOf("time-period");
      }

      /*
       * FIXME: I think this is problematic since the DB may use GMT whereas the Date() command returns something localized (I think).
       * We need to standardize on date/time across out DB and Java code.
       */
      Date firstDate = null, lastDate = null;
      if (timePeriod != null) {
        String[] dates = timePeriod.trim().split(":");
        SimpleDateFormat localDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
          firstDate = localDateFormat.parse(dates[0].trim());
          if (dates.length != 1) {
            lastDate = localDateFormat.parse(dates[1].trim());
          }
        } catch (ParseException ex) {
          Log.warn(
              "Date not found. Date must be in format YYYY-MM-DD or YYYY-MM-DD:YYYY-MM-DD.", ex);
          println("Incorrect date");
          ret = new ReturnValue(ReturnValue.INVALIDPARAMETERS);
          return ret;
        }
        if (lastDate == null) {
          lastDate = new Date();
        }
      }

      if (options.has(WRSTDERR) && options.has(WRSTDOUT)) {
        println("Combination of both stdout and stderr not recognized");
        ret.setExitStatus(ReturnValue.INVALIDPARAMETERS);
        return ret;
      }

      if (options.has("workflow-run-accession")) {
        String wra = (String) options.valueOf("workflow-run-accession");
        if (options.has(WRSTDERR)) {
          reportWorkflowRunStdErrOut(wra, STDERR);
        } else if (options.has(WRSTDOUT)) {
          reportWorkflowRunStdErrOut(wra, STDOUT);
        } else {
          reportOnWorkflowRun(wra);
        }
      } else if (options.has("workflow-accession") || options.has(statusSpec)) {
        String tp = (String) options.valueOf("workflow-accession");
        reportOnWorkflow(tp, status, firstDate, lastDate);
      }
      /**
       * SEQWARE-863 ability to query without specifying a specific workflow-accession was removed
       * else if (firstDate != null || lastDate != null) { reportOnWorkflowRuns(firstDate,
       * lastDate);
       */
      else {
        println("Combination of parameters not recognized!");
        println(this.get_syntax());
        ret.setExitStatus(ReturnValue.INVALIDPARAMETERS);
        return ret;
      }
    } catch (IOException e) {
      Log.error(e.getMessage(), e);
      ret.setExitStatus(ReturnValue.FILENOTREADABLE);
      ret.setDescription(e.getMessage());
    }
    return ret;
  }
  /**
   * {@inheritDoc}
   *
   * @return
   */
  @Override
  public ReturnValue do_run() {
    ReturnValue ret = new ReturnValue();
    ResultSet rs = null;
    MetadataDB mdb = null;
    PreparedStatement prepareStatement = null;
    try {
      String query =
          new StringBuilder()
              .append(
                  "select w.sw_accession, w.workflow_run_id, w.status, f.* FROM workflow_run w LEFT OUTER JOIN workflow_run_input_files f ")
              .append(
                  "ON w.workflow_run_id = f.workflow_run_id WHERE (status = 'completed' OR status= 'failed') AND ")
              .append("f.workflow_run_id IS NULL ORDER BY w.sw_accession;")
              .toString();

      Log.info("Executing query: " + query);
      mdb = DBAccess.get();

      List<int[]> ids =
          mdb.executeQuery(
              query,
              new ResultSetHandler<List<int[]>>() {
                @Override
                public List<int[]> handle(ResultSet rs) throws SQLException {
                  List<int[]> ids = new ArrayList<>();
                  while (rs.next()) {
                    ids.add(new int[] {rs.getInt("sw_accession"), rs.getInt("workflow_run_id")});
                  }
                  return ids;
                }
              });

      mdb.getDb().setAutoCommit(false);
      prepareStatement =
          mdb.getDb()
              .prepareStatement(
                  "INSERT INTO workflow_run_input_files (workflow_run_id, file_id) VALUES(?,?)");
      for (int[] i : ids) {
        int workflowSWID = i[0];
        int workflowRunID = i[1];
        Log.stdout("Working on workflow_run " + workflowSWID);

        // populate input files
        List<Integer> listOfFiles = this.getListOfFiles(workflowSWID);
        Log.stdout("Found " + listOfFiles.size() + " input files for workflow_run " + workflowSWID);
        // insert into new workflow_run_input_files table
        for (Integer fSWID : listOfFiles) {
          Integer fileID = this.metadata.getFile(fSWID).getFileId();
          prepareStatement.setInt(1, workflowRunID);
          prepareStatement.setInt(2, fileID);
          prepareStatement.executeUpdate();
        }
      }
      Log.stdout("Success!");
      mdb.getDb().commit();
      return ret;
    } catch (SQLException ex) {
      Log.fatal("Population failed, aborting.");
      Logger.getLogger(WorkflowRunFilesInitialPopulationPlugin.class.getName())
          .log(Level.SEVERE, null, ex);
      ret.setExitStatus(ReturnValue.FAILURE);
    } finally {
      if (mdb != null) {
        DbUtils.closeQuietly(mdb.getDb(), mdb.getSql(), rs);
      }
      DBAccess.close();
      DbUtils.closeQuietly(prepareStatement);
    }
    ret.setExitStatus(ReturnValue.FAILURE);
    return ret;
  }
Пример #23
0
  /**
   * getAllHtml.
   *
   * @param processing a {@link net.sourceforge.seqware.common.model.Processing} object.
   * @param registration a {@link net.sourceforge.seqware.common.model.Registration} object.
   * @param openingNodeId a {@link java.lang.String} object.
   * @param currPosId a {@link java.lang.Integer} object.
   * @param listNodeId a {@link java.util.List} object.
   * @param isFirstCall a boolean.
   * @param isViewCurrentNode a boolean.
   * @param treeType a {@link java.lang.String} object.
   * @return a {@link java.lang.String} object.
   */
  public static String getAllHtml(
      Processing processing,
      Registration registration,
      String openingNodeId,
      Integer currPosId,
      List<String> listNodeId,
      boolean isFirstCall,
      boolean isViewCurrentNode,
      String treeType) {
    currPosId++;
    String id = getParentId(currPosId, listNodeId);

    if (id.indexOf("wfr_") != -1) {
      currPosId++;
      id = getParentId(currPosId, listNodeId);
    }

    if (id.indexOf("sr_") != -1 && !isViewCurrentNode) {
      SequencerRun sequencerRun = getParentSequencerRun(processing, Constant.getId(id));
      if (sequencerRun == null) {
        return "";
      }
      Log.info("openingNodeId = " + openingNodeId);
      return getAllHtml(
          sequencerRun, registration, openingNodeId /*processing.getProcessingId()*/, treeType);
    } else if (id.indexOf("seq_") != -1 && !isViewCurrentNode) {
      Lane lane = getParentLane(processing, Constant.getId(id));
      if (lane == null) {
        return "";
      }
      return getAllHtml(lane, registration, openingNodeId, treeType);
      // 1	return getAllHtml(lane, registration, processing.getProcessingId());
      // 2	return getAllHtml(lane, registration, processing.getProcessingId(), isOpenProc, true);
    } else if (id.indexOf("ius_") != -1 && !isViewCurrentNode) {
      Log.info("Proc IUS HTML");
      IUS ius = getParentIUS(processing, Constant.getId(id));
      if (ius == null) {
        return "";
      }
      return getAllHtml(ius, registration, openingNodeId, !isFirstCall, true, treeType);
    } else {
      Processing currProc;
      if (isFirstCall) {
        currProc = processing;
      } else {
        currProc = getParentProcessing(processing, Constant.getId(id));
        if (currProc == null) {
          return "";
        }
        openingNodeId = getParentId(currPosId - 1, listNodeId);
        if (openingNodeId.indexOf("wfr_") != -1) {
          openingNodeId = getParentId(currPosId - 2, listNodeId);
        }
      }

      Log.info("  -> openingNodeId Proc = " + openingNodeId);

      String childHtml =
          NodeHtmlUtil.getProcessingHtml(
              currProc, registration, TYPE_TREE, openingNodeId, treeType);

      String parentHtml =
          getAllHtml(currProc, registration, id, currPosId, listNodeId, false, false, treeType);
      String parentId = Constant.PROCESSING_PREFIX + currProc.getProcessingId();
      return NodeHtmlUtil.pasteHtmlIntoParentNode(childHtml, parentHtml, parentId, true);

      //			Log.info("currProcId = " + currProc.getProcessingId());

      //			String childHtml = NodeHtmlUtil.getProcessingHtml(currProc, registration, TYPE_TREE,
      // openingNodeId);

      //			String parentHtml = getAllHtml(currProc, registration, currProc.getProcessingId(),
      // currPosId, listNodeId, false, false);
      //			String parentId = Constant.PROCESSING_PREFIX + currProc.getProcessingId();
      //			return NodeHtmlUtil.pasteHtmlIntoParentNode(childHtml, parentHtml, parentId, true);
    }
  }
  /**
   * Handles the user's request to submit a new study.
   *
   * @param request HttpServletRequest
   * @param response HttpServletResponse
   * @param command Study command object
   * @return ModelAndView
   * @throws java.lang.Exception if any.
   */
  public ModelAndView handleSubmit(
      HttpServletRequest request, HttpServletResponse response, UploadFile command)
      throws Exception {

    Registration registration = Security.getRegistration(request);
    if (registration == null) return new ModelAndView("redirect:/login.htm");

    ServletContext context = this.getServletContext();
    command.setFolderStore(context.getInitParameter("path.to.upload.directory"));
    command.setStrStartURL(context.getInitParameter("true.protocols"));

    ModelAndView modelAndView = null;
    BindingResult errors = this.validate(request, command);
    if (errors.hasErrors()) {
      Map model = errors.getModel();
      Integer id = getRequestedId(request);
      String typeNode = getRequestedTypeNode(request);
      String nameNode = getNameNode(id, typeNode);
      List<FileType> listFileType = getFileTypeService().list();

      model.put("id", id);
      model.put("tn", typeNode);
      model.put("nameNode", nameNode);
      model.put("listFileType", listFileType);

      modelAndView = new ModelAndView("UploadFile", model);
    } else {
      String folderStore = context.getInitParameter("path.to.upload.directory");

      // MultipartFile file = command.getFile();

      // MultipartFile file = command.getFileFromURL();

      Log.info("URL = " + command.getFileURL());
      Log.info("USE URL ? = " + command.getUseURL());

      FileType fileType = getFileTypeService().findByID(command.getFileTypeId());

      Integer id = getRequestedId(request);
      String typeNode = getRequestedTypeNode(request);

      Log.info("ID = " + id);
      Log.info("typeNode = " + typeNode);

      if ("st".equals(typeNode)) {
        Study study = getStudyService().findByID(id);
        getFileUploadService().uploadFile(study, command, fileType, registration);
      }

      if ("exp".equals(typeNode)) {
        Experiment experiment = getExperimentService().findByID(id);
        getFileUploadService().uploadFile(experiment, command, fileType, registration);
      }
      if ("sam".equals(typeNode)) {
        Sample sample = getSampleService().findByID(id);
        getFileUploadService().uploadFile(sample, command, fileType, registration);
      }
      if ("seq".equals(typeNode)) {
        Lane lane = getLaneService().findByID(id);
        getFileUploadService().uploadFile(lane, command, fileType, registration);
      }
      if ("ius".equals(typeNode)) {
        IUS ius = getIUSService().findByID(id);
        getFileUploadService().uploadFile(ius, command, fileType, registration);
      }
      if ("ae".equals(typeNode)) {
        Processing processing = getProcessingService().findByID(id);
        getFileUploadService().uploadFile(processing, command, fileType, registration);
      }
      if ("sr".equals(typeNode)) {
        SequencerRun sequencerRun = getSequencerRunService().findByID(id);
        getFileUploadService().uploadFile(sequencerRun, command, fileType, registration);
      }
      modelAndView = new ModelAndView(getViewName(request));
    }

    return modelAndView;
  }
Пример #25
0
  /**
   * {@inheritDoc}
   *
   * @return
   */
  @Override
  @Put
  public Representation put(Representation entity) {
    authenticate();
    Representation representation = null;
    Lane newLane = null;
    JaxbObject<Lane> jo = new JaxbObject<>();
    try {

      String text = entity.getText();
      newLane = (Lane) XmlTools.unMarshal(jo, new Lane(), text);
    } catch (SAXException | IOException ex) {
      ex.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, ex);
    }
    try {
      LaneService fs = BeanFactory.getLaneServiceBean();
      Lane lane = testIfNull(fs.findByID(newLane.getLaneId()));
      lane.givesPermission(registration);
      // simple types
      String name = newLane.getName();
      String desc = newLane.getDescription();
      Integer laneIndex = newLane.getLaneIndex();
      String cycleDescriptor = newLane.getCycleDescriptor();
      Boolean skip = newLane.getSkip();
      String tags = newLane.getTags();
      String regions = newLane.getRegions();
      // foreign keys
      Sample sample = newLane.getSample();
      Registration owner = newLane.getOwner();

      Set<LaneAttribute> newAttributes = newLane.getLaneAttributes();

      if (name != null) {
        lane.setName(name);
      }
      if (desc != null) {
        lane.setDescription(desc);
      }
      if (laneIndex != null) {
        lane.setLaneIndex(laneIndex);
      }
      if (cycleDescriptor != null) {
        lane.setCycleDescriptor(cycleDescriptor);
      }
      if (skip != null) {
        lane.setSkip(skip);
      }
      if (tags != null) {
        lane.setTags(tags);
      }
      if (regions != null) {
        lane.setRegions(regions);
      }

      if (sample != null) {
        SampleService ss = BeanFactory.getSampleServiceBean();
        Sample newSample = ss.findByID(sample.getSampleId());
        if (newSample != null && newSample.givesPermission(registration)) {
          lane.setSample(newSample);
        } else if (newSample == null) {
          Log.info("Could not be found " + sample);
        }
      }

      if (owner != null) {
        RegistrationService rs = BeanFactory.getRegistrationServiceBean();
        Registration newReg = rs.findByEmailAddress(owner.getEmailAddress());
        if (newReg != null) {
          lane.setOwner(newReg);
        } else {
          Log.info("Could not be found " + owner);
        }
      } else if (lane.getOwner() == null) {
        lane.setOwner(registration);
      }
      if (newAttributes != null) {
        // SEQWARE-1577 - AttributeAnnotator cascades deletes when annotating
        LaneIDResource.mergeAttributes(lane.getLaneAttributes(), newAttributes, lane);
      }

      fs.update(registration, lane);

      Hibernate3DtoCopier copier = new Hibernate3DtoCopier();

      Lane detachedLane =
          copier.hibernate2dto(
              Lane.class,
              lane,
              new Class<?>[] {LibraryStrategy.class, LibrarySource.class, LibrarySelection.class},
              new CollectionPropertyName<?>[] {});

      Document line = XmlTools.marshalToDocument(jo, detachedLane);
      representation = XmlTools.getRepresentation(line);
      getResponse().setEntity(representation);
      getResponse()
          .setLocationRef(getRequest().getRootRef() + "/lanes/" + detachedLane.getSwAccession());
      getResponse().setStatus(Status.SUCCESS_CREATED);
    } catch (SecurityException e) {
      getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN, e.getMessage());
    } catch (Exception e) {
      e.printStackTrace();
      getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }

    return representation;
  }
Пример #26
0
  @Test
  public void testPackageBundleAndInstallSeparately() throws IOException {

    separateTempDir = Files.createTempDir();
    Log.info("Trying to package archetype at: " + separateTempDir.getAbsolutePath());
    PluginRunner it = new PluginRunner();
    String SEQWARE_VERSION = it.getClass().getPackage().getImplementationVersion();
    Assert.assertTrue("unable to detect seqware version", SEQWARE_VERSION != null);
    Log.info("SeqWare version detected as: " + SEQWARE_VERSION);

    File packageDir = Files.createTempDir();

    // for this test, we're going to create, install and package just one archetype. Doing more
    // seems redundant for this test
    String[] archetypes = {
      "java-workflow" /*, "simplified-ftl-workflow", "legacy-ftl-workflow", "simple-legacy-ftl-workflow"*/
    };
    for (String archetype : archetypes) {
      String workflow = "seqware-archetype-" + archetype;
      // generate and install archetypes to local maven repo
      String command =
          "mvn archetype:generate -DarchetypeCatalog=local -Dpackage=com.seqware.github -DgroupId=com.github.seqware -DarchetypeArtifactId="
              + workflow
              + " -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=com.github.seqware -DartifactId="
              + workflow
              + " -DworkflowDirectoryName="
              + workflow
              + " -DworkflowName="
              + workflow
              + " -DworkflowVersion=1.0-SNAPSHOT -B -Dgoals=install";
      String genOutput = ITUtility.runArbitraryCommand(command, 0, separateTempDir);
      Log.info(genOutput);
      // install the workflows to the database and record their information
      File workflowDir = new File(separateTempDir, workflow);
      File targetDir = new File(workflowDir, "target");
      File bundleDir =
          new File(
              targetDir,
              "Workflow_Bundle_" + workflow + "_1.0-SNAPSHOT_SeqWare_" + SEQWARE_VERSION);

      String packageCommand =
          "-p net.sourceforge.seqware.pipeline.plugins.BundleManager -verbose -- -b "
              + packageDir
              + " -p "
              + bundleDir.getAbsolutePath();
      String packageOutput = ITUtility.runSeqWareJar(packageCommand, ReturnValue.SUCCESS);
      Log.info(packageOutput);

      // locate the zip bundle and then install it
      File zippedBundle = new File(packageDir, bundleDir.getName() + ".zip");
      Assert.assertTrue(
          "zipped bundle " + zippedBundle.getAbsolutePath() + ".zip", zippedBundle.exists());

      String installCommand =
          "-p net.sourceforge.seqware.pipeline.plugins.BundleManager -verbose -- -b "
              + zippedBundle
              + " -i";
      String installOutput = ITUtility.runSeqWareJar(installCommand, ReturnValue.SUCCESS);
      Log.info(installOutput);
    }

    FileUtils.deleteDirectory(packageDir);
  }