/**
  * Lookup a Software product and return it or return a new one if not found.
  *
  * @param name the name of the software product to lookup
  * @return a new or existing Software product associated with this Company
  */
 public Software lookupOrCreateSoftware(String name) {
   Software s = (Software) lnkSoftware.get(name);
   if (s == null) {
     s = new Software(name);
     lnkSoftware.put(s.getName(), s);
   }
   return s;
 }
Esempio n. 2
0
  /**
   * Helper to handle metadata in the document
   *
   * @throws CheckedIOException
   */
  private void writeMetaData(PeakList peaklist) {
    // skip if previously done
    if (hasWrittenMetaData) {
      return;
    }
    // flag meta-data as writter
    hasWrittenMetaData = true;

    // try to get meta-data if it is available
    if (peaklist instanceof MzXMLPeakList) {
      MzXMLPeakList mzxml = (MzXMLPeakList) peaklist;
      msRun = mzxml.getMsRun();
    } else {
      msRun = new MsRun();
    }

    try {
      // write out all the parent files
      for (ParentFile pf : msRun.getParentFiles()) {
        xmlw.writeEmptyElement("parentFile");
        writeNonNull(xmlw, "fileName", pf.getFileName());
        writeNonNull(xmlw, "fileType", pf.getFileType());
        writeNonNull(xmlw, "fileSha1", pf.getFileSHA());
      }

      // write out all the msInstrument information
      MsInstrument msInstrument = msRun.getMsInstrument();
      if (msInstrument != null) {
        xmlw.writeStartElement("msInstrument");

        // write out msManufacture
        if (msInstrument.getMsManufacturer() != null) {
          xmlw.writeEmptyElement("msManufacturer");
          writeNonNull(xmlw, "category", msInstrument.getMsManufacturer().getCategory());
          if (msInstrument.getMsManufacturer().getValue() != null)
            writeNonNull(xmlw, "value", msInstrument.getMsManufacturer().getValue());
        }

        // write out msModel
        if (msInstrument.getMsModel() != null) {
          xmlw.writeEmptyElement("msModel");
          writeNonNull(xmlw, "category", msInstrument.getMsModel().getCategory());
          writeNonNull(xmlw, "value", msInstrument.getMsModel().getValue());
        }

        // write out msManufacture
        if (msInstrument.getMsIonisation() != null) {
          xmlw.writeEmptyElement("msIonisation");
          writeNonNull(xmlw, "category", msInstrument.getMsIonisation().getCategory());
          writeNonNull(xmlw, "value", msInstrument.getMsIonisation().getValue());
        }

        // write out msManufacture
        if (msInstrument.getMsMassAnalyzer() != null) {
          xmlw.writeEmptyElement("msMassAnalyzer");
          writeNonNull(xmlw, "category", msInstrument.getMsMassAnalyzer().getCategory());
          writeNonNull(xmlw, "value", msInstrument.getMsMassAnalyzer().getValue());
        }

        // write out msManufacture
        if (msInstrument.getMsDetector() != null) {
          xmlw.writeEmptyElement("msDetector");
          writeNonNull(xmlw, "category", msInstrument.getMsDetector().getCategory());
          writeNonNull(xmlw, "value", msInstrument.getMsDetector().getValue());
        }

        // write out software
        if (msInstrument.getSoftware() != null) {
          xmlw.writeEmptyElement("software");
          writeNonNull(xmlw, "type", msInstrument.getSoftware().getType());
          writeNonNull(xmlw, "name", msInstrument.getSoftware().getName());
          writeNonNull(xmlw, "version", msInstrument.getSoftware().getVersion());
          writeNonNull(xmlw, "completionTime", msInstrument.getSoftware().getCompletionTime());
        }

        // write out msResolution
        if (msInstrument.getMsResolution() != null) {
          xmlw.writeEmptyElement("msResolution");
          writeNonNull(xmlw, "category", msInstrument.getMsResolution().getCategory());
          writeNonNull(xmlw, "value", msInstrument.getMsResolution().getValue());
        }

        // write out operator
        if (msInstrument.getOperator() != null) {
          xmlw.writeEmptyElement("operator");
          writeNonNull(xmlw, "first", msInstrument.getOperator().getFirst());
          writeNonNull(xmlw, "last", msInstrument.getOperator().getLast());
          writeNonNull(xmlw, "email", msInstrument.getOperator().getEmail());
          writeNonNull(xmlw, "phone", msInstrument.getOperator().getPhone());
          writeNonNull(xmlw, "URI", msInstrument.getOperator().getURI());
        }

        xmlw.writeEndElement();
      }

      // write out all the dataProcessing information
      for (DataProcessing dp : msRun.getDataProcessings()) {
        xmlw.writeStartElement("dataProcessing");
        writeNonNull(xmlw, "intensityCutoff", dp.getIntensityCutoff());
        writeNonNull(xmlw, "centroided", dp.getCentroided());
        writeNonNull(xmlw, "deisotoped", dp.getDeisotoped());
        writeNonNull(xmlw, "chargeDeconvoluted", dp.getChargeDeconvoluted());
        writeNonNull(xmlw, "spotIntegration", dp.getSpotIntegration());

        // get all software
        Software software = dp.getSoftware();
        // write out software
        if (software != null) {
          xmlw.writeEmptyElement("software");
          writeNonNull(xmlw, "type", software.getType());
          writeNonNull(xmlw, "name", software.getName());
          writeNonNull(xmlw, "version", software.getVersion());
          writeNonNull(xmlw, "completionTime", software.getCompletionTime());
        }

        xmlw.writeEndElement();
      }
    } catch (XMLStreamException e) {
      throw new RuntimeException("Can't write mzXML meta-data!", e);
    }
  }