/**
   * @param accession
   * @return
   * @throws Exception
   */
  private Document getUniprotXML(String accession) throws Exception {
    int index = accession.lastIndexOf(".");
    String key = accession;
    if (index != -1) {
      key = accession.substring(0, index);
    }
    StringBuilder sb = new StringBuilder();
    File f = null;
    if (uniprotDirectoryCache != null && uniprotDirectoryCache.length() > 0) {
      f = new File(uniprotDirectoryCache + File.separatorChar + key + ".xml");
      if (f.exists()) {
        FileReader fr = new FileReader(f);
        int size = (int) f.length();
        char[] data = new char[size];
        fr.read(data);
        fr.close();
        sb.append(data);
        index = sb.indexOf("xmlns="); // strip out name space stuff to make it easier on xpath
        if (index != -1) {
          int lastIndex = sb.indexOf(">", index);
          sb.replace(index, lastIndex, "");
        }
      }
    }

    // http://www.uniprot.org/uniprot/?query=SORBIDRAFT_03g027040&format=xml
    if (sb.length() == 0) {
      String uniprotURL = getUniprotbaseURL() + "/uniprot/?query=" + key + "&format=xml";
      // String uniprotURL = getUniprotbaseURL() + "/uniprot/" + key + ".xml";
      logger.info("Loading: {}", uniprotURL);
      URL uniprot = new URL(uniprotURL);
      URLConnection uniprotConnection = uniprot.openConnection();
      uniprotConnection.setRequestProperty("User-Agent", "BioJava");
      BufferedReader in =
          new BufferedReader(new InputStreamReader(uniprotConnection.getInputStream()));
      String inputLine;

      while ((inputLine = in.readLine()) != null) {
        sb.append(inputLine);
      }
      in.close();
      index = sb.indexOf("xmlns="); // strip out name space stuff to make it easier on xpath
      if (index != -1) {
        int lastIndex = sb.indexOf(">", index);
        sb.replace(index, lastIndex, "");
      }
      if (f != null) {
        FileWriter fw = new FileWriter(f);
        fw.write(sb.toString());
        fw.close();
      }
    }

    logger.info("Load complete");
    try {
      //       logger.debug(sb.toString());
      Document document =
          XMLHelper.inputStreamToDocument(new ByteArrayInputStream(sb.toString().getBytes()));
      return document;
    } catch (Exception e) {
      logger.error("Exception on xml parse of: {}", sb.toString());
    }
    return null;
  }