Package org.biojava.bio.seq.io

Examples of org.biojava.bio.seq.io.ParseException


          
           return ontology;
          
      
     } catch (AlreadyExistsException ex) {
              throw new ParseException(ex, "Duplication in ontology");
          } catch (OntologyException ex) {
              throw new ParseException(ex);
          } catch (ChangeVetoException ex) {
              throw new BioError("Error accessing newly created ontology",ex);
          }
         
  }
View Full Code Here


      if (line.length() == 0)
        continue;

      if ( line.charAt(0) == '[') {
        if (line.charAt(line.length() - 1) != ']')
          throw new ParseException("Unclosed stanza: \"" + line + "\"" );
        String stanzaname = line.substring(1, line.length() - 1);
        if (stanzaname.length() < 1)
          throw new ParseException("Empty stanza: \"" +line+"\"");
        currentStanza = stanzaname;       

        //System.out.println("stanza: " + currentStanza);
        triggerNewStanza(currentStanza);

      } else {
        // a content line
        SOPair pair;

        pair = unescape(line, ':', 0, true);

        //sSystem.out.println(pair);
        String name = pair.str;
        int lineEnd = findUnescaped(line, '!', 0, line.length(), true);
        if (lineEnd == -1)
          lineEnd = line.length();

        // find nested values
        NestedValue nv = null;

        int trailingStartIndex = -1;
        int trailingEndIndex = -1;
        for (int i = lineEnd - 1; i >= 0; i--) {
          if (Character.isWhitespace(line.charAt(i))) {
            // keep going until we see non-whitespace
          } else if (line.charAt(i) == '}') {
            // if the first thing we see is a closing brace,
            // we have a trailing modifier
            if (i >= 1 && line.charAt(i - 1) == '\\')
              continue;
            trailingEndIndex = i;
            break;
          } else
            break;
        }

        if (trailingEndIndex != -1) {
          for (int i = trailingEndIndex - 1; i >= 0; i--) {
            if (line.charAt(i) == '{') {
              if (i >= 1 && line.charAt(i - 1) == '\\')
                continue;
              trailingStartIndex = i + 1;
            }
          }
        }

        int valueStopIndex;
        if (trailingStartIndex == -1 && trailingEndIndex != -1)
          throw new ParseException("Unterminated trailing modifier. " + line);
        else if (trailingStartIndex != -1) {
          valueStopIndex = trailingStartIndex - 1;
          String trailing = line.substring(trailingStartIndex,
              trailingEndIndex).trim();
          nv = new NestedValue();
          getNestedValue(nv, trailing, 0);
        } else
          valueStopIndex = lineEnd;

        String value = line.substring(pair.index + 1, valueStopIndex).trim();
        /*
         * if (nv != null) System.err.println("nv = "+nv+", value =
         * |"+value+"|");
         */
        if (value.length() == 0)
          throw new ParseException("Tag found with no value "+ line);

        if ( isSynonym(name)){
          Synonym synonym = parseSynonym(name,value);
          triggerNewSynonym(synonym);
        } else {
View Full Code Here

  private Synonym parseSynonym(String key, String value) throws ParseException{

    //System.out.println("PARSE SYNONYM " + key +  " " + value);
    int startIndex = findUnescaped(value, '"', 0, value.length());
    if (startIndex == -1)
      throw new ParseException("Expected \"" +  line + " " + linenum);
    SOPair p = unescape(value, '"', startIndex + 1, value.length(),
        true);
    int defIndex = findUnescaped(value, '[', p.index, value.length());
    if (defIndex == -1) {
      throw new ParseException("Badly formatted synonym. "
          + "No dbxref list found." + line + " " + linenum );
    }
    String leftovers = value.substring(p.index + 1, defIndex).trim();
    StringTokenizer tokenizer = new StringTokenizer(leftovers, " \t");
    int scope = Synonym.RELATED_SYNONYM;
   
    if ( key.equals(OboFileHandler.EXACT_SYNONYM))
      scope = Synonym.EXACT_SYNONYM;
    else if ( key.equals(OboFileHandler.BROAD_SYNONYM))
      scope = Synonym.BROAD_SYNONYM;
    else if ( key.equals(OboFileHandler.NARROW_SYNONYM))     
      scope = Synonym.NARROW_SYNONYM;
   
   
    String catID = null;
    for (int i = 0; tokenizer.hasMoreTokens(); i++) {
      String token = tokenizer.nextToken();
      //System.out.println("TOKEN:" +token);
      if (i == 0) {
        if (token.equals("RELATED"))
          scope = Synonym.RELATED_SYNONYM;
        else if (token.equals("UNSPECIFIED"))
          scope = Synonym.RELATED_SYNONYM;
        else if (token.equals("EXACT"))
          scope = Synonym.EXACT_SYNONYM;
        else if (token.equals("BROAD"))
          scope = Synonym.BROAD_SYNONYM;
        else if (token.equals("NARROW"))
          scope = Synonym.NARROW_SYNONYM;
        else
          throw new ParseException("Found unexpected scope "
              + "identifier " + token + line);
      } else if (i == 1) {
        catID = token;
      } else
        throw new ParseException("Expected dbxref list,"
            + " instead found " + token +   line );
    }

    Synonym synonym = new Synonym();
    synonym.setScope(scope);
View Full Code Here

      boolean trailing = false;
      if (endIndex == -1) {
        endIndex = findUnescaped(line, ']', startoffset, endoffset,
            true);
        if (endIndex == -1) {
          throw new ParseException("Unterminated xref list " + line);
        }
        stop = true;
      }
      if (braceIndex != -1 && braceIndex < endIndex) {
        endIndex = braceIndex;
        trailing = true;
      }

      Map<String, Object> pair = parseXref(line,
          startoffset,
          endIndex);
      if (pair == null) {
        startoffset++;
        continue;
      }
      NestedValue nv = null;
      if (trailing) {
        nv = new NestedValue();
        endIndex = getNestedValue(nv, line, endIndex + 1);
        if (endIndex == -1) {
          throw new ParseException("Badly formatted "
              + "trailing properties " + line);
        }
        pair.put("nv",nv);
      }
View Full Code Here

        i++;
        c = str.charAt(i);
        Character mapchar = escapeChars
        .get(new Character(c));
        if (mapchar == null)
          throw new ParseException("Unrecognized escape"
              + " character " + c + " found.");
        out.append(mapchar);
      } else if (c == toChar) {
        endValue = i;
        break;
      } else {
        out.append(c);
      }
    }
    if (endValue == -1 && mustFindChar) {
      throw new ParseException("Expected " + toChar + "." + str);
    }
    return new SOPair(out.toString(), endValue);
  }
View Full Code Here

      // if the first non-whitespace character is not a quote,
      // proceed in non-quoted mode       
      else if (!isQuote(value.charAt(i))) {
        if (requireQuotes)
          throw new ParseException(
              "Expected start of quoted string. " +
              line + " " +  value+ " at linenr " + linenum);
        useQuotes = false;
        break;
      } else {
        useQuotes = true;
        quoteChar = value.charAt(i);
        i++;
        break;
      }
    }

    // look for a closing quote or final delimiter
    for (; i < stopIndex; i++) {
      if (isEscapeStarter(value.charAt(i))) {
        i++;
        if (i >= value.length())
          throw new ParseException("Incomplete escape sequence. " + line);
        out.append(value.charAt(i));
      } else if ((useQuotes && value.charAt(i) == quoteChar)
          || (!useQuotes && value.charAt(i) == terminatingChar)) {
        if (!useQuotes)
          return new SOPair(out.toString().trim(), startIndex, i - 1);
        else
          return new SOPair(out.toString(), startIndex, i);
      } else {
        out.append(value.charAt(i));
      }
    }
    if (!useQuotes && legalEndOfLine)
      return new SOPair(out.toString().trim(), startIndex, i);
    else
      throw new ParseException("Unterminated quoted string. " +line);
  }
View Full Code Here

  protected int getNestedValue(NestedValue nv, String str, int startIndex)
  throws ParseException {
    while (startIndex < str.length()) {
      int equalsIndex = findUnescaped(str, '=', startIndex, str.length());
      if (equalsIndex == -1)
        throw new ParseException("Expected = in trailing modifier " +line);
      String name = str.substring(startIndex, equalsIndex).trim();
      SOPair value = readQuotedString(str, equalsIndex + 1, str.length(),
          ',', false, true);

      Properties pv = new Properties();
      pv.setProperty(unescape(name),value.str);


      nv.addPropertyValue(pv);
      startIndex = value.endIndex + 1;
      for (; startIndex < str.length(); startIndex++) {
        if (Character.isWhitespace(str.charAt(startIndex)))
          continue;
        else if (str.charAt(startIndex) == ',') {
          startIndex++;
          break;
        } else {
          System.err.println("found character |"
              + str.charAt(startIndex) + "|");
          throw new ParseException("Expected comma in trailing modifier. " +
              line + " linenr: " + linenum);
        }
      }
    }
    return str.length();
View Full Code Here

TOP

Related Classes of org.biojava.bio.seq.io.ParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.