/**
   * Builds the SRA {@link SpotDescriptorType}, this is taken from the ISATAB "sequencing" protocol
   * that has been used for this assay.
   *
   * <p>Some of these parameters are mandatory in SRA, and/or constrained to certain values, so the
   * method raises an exception in case they're not defined.
   */
  protected SpotDescriptorType buildExportedSpotDescriptor(Assay assay) {
    ProtocolApplication pApp = getProtocol(assay, "sequencing");
    if (pApp == null) {
      return null;
    }

    String barcode = getParameterValue(assay, pApp, "barcode", false);

    System.out.println("barcode: " + barcode);

    String adapterSpec = getParameterValue(assay, pApp, "Adapter Spec", false);
    String numOfSpotReads = getParameterValue(assay, pApp, "Number of reads per spot", false);

    boolean usesBarcode = (barcode != null);

    SRATemplate sraTemplateToInject =
        getSRATemplateToInject(SRASection.SPOT_DESCRIPTOR, assay, pApp, usesBarcode);

    SpotDescriptorType xspotd = SpotDescriptorType.Factory.newInstance();

    Map<SRAAttributes, String> userDefinedAttributes = new HashMap<SRAAttributes, String>();

    if (!StringUtils.isEmpty(adapterSpec)) {
      userDefinedAttributes.put(SRAAttributes.ADAPTER_SPEC, adapterSpec);
    }

    if (!StringUtils.isEmpty(numOfSpotReads)) {
      userDefinedAttributes.put(SRAAttributes.NUMBER_OF_READS_PER_SPOT, numOfSpotReads);
    }

    if (!StringUtils.isEmpty(barcode)) {
      userDefinedAttributes.put(SRAAttributes.READ_GROUP_TAG, barcode);
    }

    try {
      String sraTemplate =
          sraTemplateLoader.getSRAProcessingTemplate(sraTemplateToInject, userDefinedAttributes);

      System.out.println(sraTemplate);

      XmlOptions xmlOptions = new XmlOptions();
      xmlOptions.setDocumentType(SpotDescriptorType.Factory.newInstance().schemaType());

      XmlObject parsedAttr = XmlObject.Factory.parse(sraTemplate, xmlOptions);

      xspotd.set(parsedAttr);

      return xspotd;

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (XmlException e) {
      e.printStackTrace();
    }

    return xspotd;
  }
  /**
   * Builds the SRA {@link PROCESSING}, this is taken from the ISATAB "sequencing" protocol that has
   * been used for this assay.
   *
   * <p>Some of these parameters are mandatory in SRA, and/or constrained to certain values, so the
   * method raises an exception in case they're not defined.
   */
  protected PROCESSING buildExportedProcessing(final Assay assay) {
    ProtocolApplication pApp = getProtocol(assay, "sequencing");

    SRATemplate sraTemplateToInject = getSRATemplateToInject(SRASection.PROCESSING, assay, pApp);

    String seqSpaceStr = getParameterValue(assay, pApp, "Sequence space", false);

    String baseCaller = getParameterValue(assay, pApp, "Base caller", false);

    String qualityScorer = getParameterValue(assay, pApp, "Quality scorer", false);

    String numberOfLevels = getParameterValue(assay, pApp, "Number of levels", false);

    String multiplier = getParameterValue(assay, pApp, "Multiplier", false);

    Map<SRAAttributes, String> userDefinedAttributes = new HashMap<SRAAttributes, String>();

    if (!StringUtils.isEmpty(seqSpaceStr)) {
      userDefinedAttributes.put(SRAAttributes.SEQUENCE_SPACE, seqSpaceStr);
    }

    if (!StringUtils.isEmpty(baseCaller)) {
      userDefinedAttributes.put(SRAAttributes.BASE_CALLER, baseCaller);
    }

    if (!StringUtils.isEmpty(qualityScorer)) {
      userDefinedAttributes.put(SRAAttributes.QUALITY_SCORER, qualityScorer);
    }

    if (!StringUtils.isEmpty(numberOfLevels)) {
      userDefinedAttributes.put(SRAAttributes.NUMBER_OF_LEVELS, numberOfLevels);
    }

    if (!StringUtils.isEmpty(multiplier)) {
      userDefinedAttributes.put(SRAAttributes.MULTIPLIER, multiplier);
    }

    // TODO: modify to pull out the technology and library using Parameter Value[platform] &
    // ParameterValue[library layout] respectively
    // TODO: PRS-> according to new configuration for sequencing, Parameter Value[library layout] is
    // moved to the library construction protocol
    // TODO: PRS-> replace Parameter Value[platform] with Parameter Value[sequencing instrument] and
    // checks on values.
    // TODO: PRS-> add support for Immunoprecipitation techniques, requires detection of Protocol
    // TODO: PRS-> add support for 'Targeted Loci' in SRA experiment and find in ISA-TAB file if
    // assay is environmental gene survey

    try {
      String sraTemplate =
          sraTemplateLoader.getSRAProcessingTemplate(sraTemplateToInject, userDefinedAttributes);

      XmlOptions xmlOptions = new XmlOptions();
      xmlOptions.setDocumentType(PROCESSING.Factory.newInstance().schemaType());

      PROCESSING processing = PROCESSING.Factory.newInstance();

      XmlObject processingObject = XmlObject.Factory.parse(sraTemplate, xmlOptions);

      processing.set(processingObject);
      return processing;

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (XmlException e) {
      e.printStackTrace();
    }

    return PROCESSING.Factory.newInstance();
  }