private List<String> initIdentifiedSpectrumList() {
    // 1. create an empty list for storing identified spectrum ids.
    List<String> identifiedList = new ArrayList<String>();

    // 2. get all gel free peptide spectrum references
    Collection<IndexElement> gelFreeSpectrumRefElements =
        indexer.getIndexElements(PrideXmlXpath.GELFREE_PEPTIDE_SPEC_REF.getXpath());

    // 3. iterate over each spectrum reference
    for (IndexElement spectrumRefElement : gelFreeSpectrumRefElements) {
      // get id from index element using pattern
      String id = getIDByPattern(spectrumRefElement, TAG_PATTERN, false);
      identifiedList.add(id);
    }

    // 4. get all two dimentional peptide spectrum references
    Collection<IndexElement> twoDimSpectrumRefElements =
        indexer.getIndexElements(PrideXmlXpath.TWOD_PEPTIDE_SPEC_REF.getXpath());

    // 5. iterate over each spectrum reference
    for (IndexElement twoDimSpectrumRefElement : twoDimSpectrumRefElements) {
      String id = getIDByPattern(twoDimSpectrumRefElement, TAG_PATTERN, false);
      identifiedList.add(id);
    }

    return identifiedList;
  }
  /**
   * Get the number of peptides.
   *
   * @return int the count of entries
   */
  public int getNumberOfPeptides() {
    int cnt = 0;
    // gel free
    Collection<IndexElement> gelFreePeptides =
        indexer.getIndexElements(PrideXmlXpath.GELFREE_PEPTIDE.getXpath());
    cnt += gelFreePeptides == null ? 0 : gelFreePeptides.size();
    // two dim
    Collection<IndexElement> twoDimPeptides =
        indexer.getIndexElements(PrideXmlXpath.TWOD_PEPTIDE.getXpath());
    cnt += twoDimPeptides == null ? 0 : twoDimPeptides.size();

    return cnt;
  }
 /**
  * Get all peptide xml strings within an identifiation.
  *
  * @param identId identificatio id
  * @return List<String> a list of peptide xml strings
  */
 public List<String> getPeptideXmlStrings(String identId) {
   List<String> peptides = new ArrayList<String>();
   List<IndexElement> elements = identToPeptideMap.get(identId);
   for (IndexElement element : elements) {
     peptides.add(indexer.getXmlByIndexElement(element));
   }
   return peptides;
 }
  public String getTwoDimIdentXmlString(String id) {
    String result = null;

    if (twoDimAccMap != null && twoDimAccMap.containsKey(id)) {
      result = indexer.getXmlByIndexElement(twoDimAccMap.get(id));
    }

    return result;
  }
  public String getGelFreeIdentXmlString(String id) {
    String result = null;

    if (gelFreeAccMap != null && gelFreeAccMap.containsKey(id)) {
      result = indexer.getXmlByIndexElement(gelFreeAccMap.get(id));
    }

    return result;
  }
  public String getSpectrumXmlString(String id) {
    String result = null;

    if (spectrumIdMap != null && spectrumIdMap.containsKey(id)) {
      result = indexer.getXmlByIndexElement(spectrumIdMap.get(id));
    }

    return result;
  }
  /**
   * Get the XML of the first element matched by xpath and within the experiment range.
   *
   * @param xpath xpath to find the element.
   * @return String XML string matched.
   */
  private String getFirstXmlString(String xpath) {
    String xml = null;

    Iterator<String> xmlStrs = indexer.getXmlStringIterator(xpath);

    if (xmlStrs != null && xmlStrs.hasNext()) {
      xml = xmlStrs.next();
    }
    return xml;
  }
  /**
   * Get the corresponding xml string for a peptide.
   *
   * @param identId identification id.
   * @param index peptide index within the identification
   * @return String xml string
   */
  public String getPeptideXmlString(String identId, int index) {
    String xml = null;

    List<IndexElement> elements = identToPeptideMap.get(identId);
    if (elements != null && index >= 0 && index < elements.size()) {
      xml = indexer.getXmlByIndexElement(elements.get(index));
    }

    return xml;
  }
 public String getExpCollectionVersionString() {
   Collection<IndexElement> indexElements =
       indexer.getIndexElements(PrideXmlXpath.EXP_COLLECTION.getXpath());
   String version = null;
   for (IndexElement indexElement : indexElements) {
     version = getIDByPattern(indexElement, VERSION_PATTERN, true);
     break;
   }
   return version;
 }
  private Map<String, List<IndexElement>> initPeptideCacheMap() {
    // 1. create a empty identification to peptide mapping map
    Map<String, List<IndexElement>> identPeptideMap =
        new LinkedHashMap<String, List<IndexElement>>();
    // 2. get all gel free peptide index element
    Collection<IndexElement> gelFreePeptideElements =
        indexer.getIndexElements(PrideXmlXpath.GELFREE_PEPTIDE.getXpath());
    // 3. iterate over each gel free peptide index element
    for (IndexElement gelFreePeptideElement : gelFreePeptideElements) {
      String identId = searchForId(gelFreePeptideElement, gelFreeAccMap);
      addIdentPeptide(identId, gelFreePeptideElement, identPeptideMap);
    }
    // 4. get all two dimensional peptide index element
    Collection<IndexElement> twoDimPeptideElements =
        indexer.getIndexElements(PrideXmlXpath.TWOD_PEPTIDE.getXpath());
    // 5. iterate over each peptide index element
    for (IndexElement twoDimPeptideElement : twoDimPeptideElements) {
      String identId = searchForId(twoDimPeptideElement, twoDimAccMap);
      addIdentPeptide(identId, twoDimPeptideElement, identPeptideMap);
    }

    return identPeptideMap;
  }
  /**
   * Find the id from xml string based indexElement's range.
   *
   * @param indexElement index element.
   * @param pattern This pattern should only match once.
   * @return String id or accession.
   */
  private String getIDByPattern(IndexElement indexElement, Pattern pattern, boolean quickMatch) {
    String id = null;

    // first get the XML string (only the first bit) from which to extract the ID
    long start = indexElement.getStart();
    long stop = quickMatch ? start + XML_CHAR_INCREMENT : indexElement.getStop();
    String xml = indexer.getXmlSnippet(start, stop);
    // then apply the regex pattern to find the ID
    Matcher m = pattern.matcher(xml);
    if (m.find()) {
      id = m.group(1);
    }

    return id;
  }
  private Map<String, IndexElement> initCacheMap(String xpath, Pattern idPattern) {
    // 1. create a empty id map
    Map<String, IndexElement> idMap = new LinkedHashMap<String, IndexElement>();
    // 2. get index elements from xpath
    Collection<IndexElement> indexElements = indexer.getIndexElements(xpath);

    for (IndexElement indexElement : indexElements) {
      // get id from index element using pattern
      String id = getIDByPattern(indexElement, idPattern, true);
      if (idMap.containsKey(id)) {
        logger.error("Ambiguous ID Exception: " + xpath + " \nID: " + id);
      } else {
        idMap.put(id, indexElement);
      }
    }
    return idMap;
  }
  private Map<String, IndexElement> initIdentificationCacheMap(String xpath) {
    // 1. create a empty id map
    Map<String, IndexElement> idMap = new LinkedHashMap<String, IndexElement>();
    // 2. get index elements from xpath
    Collection<IndexElement> indexElements = indexer.getIndexElements(xpath);
    // 3. generated Id index

    for (IndexElement indexElement : indexElements) {
      // get id from index element using pattern
      if (idMap.containsKey(identificationId + "")) {
        logger.error("Ambiguous ID Exception: " + xpath + " \nID: " + identificationId);
      } else {
        idMap.put(identificationId + "", indexElement);
      }
      identificationId++;
    }

    return idMap;
  }
 /**
  * @param xpath
  * @return
  */
 public Iterator<String> getPrideXmlEntries(String xpath) {
   return indexer.getXmlStringIterator(xpath);
 }
 public List<String> getCvLookupXmlStrings() {
   return indexer.getXmlStringList(PrideXmlXpath.MZDATA_CVLOOKUP.getXpath());
 }
 public List<String> getReferenceXmlStrings() {
   return indexer.getXmlStringList(PrideXmlXpath.EXP_REF.getXpath());
 }