/** Setup - Set up a test BEL {@link Document}. */
  @Before
  public void setupTest() {
    NamespaceGroup namespaceGroup = new NamespaceGroup();
    Namespace entrezGeneNs = new Namespace("EG", "http://www.belscript.org/ns/entrez-gene");
    Namespace hgncNs = new Namespace("HGNC", "http://www.belscript.org/ns/hgnc");
    namespaceGroup.setNamespaces(asList(entrezGeneNs, hgncNs));

    StatementGroup statementGroup = new StatementGroup();

    AnnotationDefinition speciesDefinition =
        new AnnotationDefinition("species", "Description", "Usage", asList("9606"));
    AnnotationDefinition tissueDefinition =
        new AnnotationDefinition("tissue", "Description", "Usage", asList("TH1", "TH2", "AB3"));

    AnnotationGroup annotationGroup = new AnnotationGroup();
    annotationGroup.setAnnotations(
        asList(
            CommonModelFactory.getInstance().createAnnotation("9606", speciesDefinition),
            CommonModelFactory.getInstance().createAnnotation("TH1", tissueDefinition)));
    annotationGroup.setEvidence(
        CommonModelFactory.getInstance()
            .createEvidence(
                "the elevation of intracellular cAMP concentration that results from increased glucagon production also plays a role in the down-regulation process"));

    statementGroup.setAnnotationGroup(annotationGroup);

    FunctionEnum p = FunctionEnum.PROTEIN_ABUNDANCE;
    List<BELObject> args = new ArrayList<BELObject>();

    args.add(CommonModelFactory.getInstance().createParameter(hgncNs, "NFKB"));
    Term t = new Term(p, args);

    FunctionEnum r = FunctionEnum.RNA_ABUNDANCE;
    args = new ArrayList<BELObject>();
    args.add(CommonModelFactory.getInstance().createParameter(hgncNs, "FAS"));
    Term t2 = new Term(r, args);

    Statement simpleIncrease =
        new Statement(
            t,
            "",
            annotationGroup,
            new org.openbel.framework.common.model.Statement.Object(t2),
            RelationshipType.INCREASES);
    statementGroup.setStatements(asList(simpleIncrease));

    Header header = new Header("", asList("Unladen"), asList("Swallow"), "", "", "", "", "");
    Document document = new Document(header, statementGroup);
    document.setDefinitions(asList(speciesDefinition, tissueDefinition));
    document.setNamespaceGroup(namespaceGroup);

    protoNetwork = new ProtoNetworkBuilder(document).buildProtoNetwork();
  }
예제 #2
0
  @Override
  public Token parse() {
    funcName = first.getNext();
    if (!funcName.isIdentifier())
      throw new RuntimeException("Expected identifier for function name, found: " + funcName);

    GluonFunction.registerFunction(funcName.getValue());

    Token test = funcName.getNext();
    if (!test.isOperator(Operator.BRACKET_LEFT))
      throw new RuntimeException("Expected '(' for function parmater list, found: " + test);

    test = test.getNext();
    while (test.isIdentifier()) {
      Variable param = new Variable(test, scope, true);
      parameters.add(param);
      test = param.parse(true);
      if (test.isOperator(Operator.COMMA)) test = test.getNext();
    }

    if (!test.isOperator(Operator.BRACKET_RIGHT))
      throw new RuntimeException("Expected ')' for function parmater list, found: " + test);

    test = test.getNext();
    if (!test.isOperator(Operator.COLON) && !test.isOperator(Operator.BRACE_LEFT))
      throw new RuntimeException("Expected ':' or '{' in function def, found: " + test);

    if (test.isOperator(Operator.COLON)) {
      test = funcName.getNext();
      if (!test.isOperator(Operator.BRACKET_LEFT))
        throw new RuntimeException("Expected '(' for function return list, found: " + test);

      test = test.getNext();
      while (test.isIdentifier()) {
        returns.add(test);
        test = test.getNext();
        if (test.isOperator(Operator.COMMA)) test = test.getNext();
      }

      if (!test.isOperator(Operator.BRACKET_RIGHT))
        throw new RuntimeException("Expected ')' for function return list, found: " + test);
    }

    if (!test.isOperator(Operator.BRACE_LEFT))
      throw new RuntimeException("Expected opening brace for function logic, found: " + test);

    test = test.getNext();
    if (!test.isNewline())
      throw new RuntimeException("Expected newline before function logic, found: " + test);

    test = test.getNext();
    Operator[] targets = {Operator.BRACE_RIGHT};
    logic = new StatementGroup(test, targets, scope);
    test = logic.parse();

    if (!test.isOperator(Operator.BRACE_RIGHT))
      throw new RuntimeException("Expected closing brace for function logic, found: " + test);

    return test.getNext();
  }
예제 #3
0
  @Override
  public Token parse() {
    Token next = first.getNext();

    if (!next.isOperator(Operator.BRACKET_LEFT))
      throw new RuntimeException("Expected '(' after WHILE, found: " + next);

    next = next.getNext();
    testExp = new BooleanExpression(next, scope);
    next = testExp.parse();

    if (!next.isOperator(Operator.BRACKET_RIGHT))
      throw new RuntimeException("Expected ')' after WHILE condition, found: " + next);

    next = next.getNext();
    if (!next.isNewline()) throw new RuntimeException("Expected newline, found: " + next);

    next = next.getNext();

    Keyword[] target = {Keyword.END};
    statements = new StatementGroup(next, target, scope);
    next = statements.parse();

    return next.getNext();
  }
예제 #4
0
  @Override
  public void print(int level) {
    printLevel(level);
    printLn("WHILE");
    testExp.print(level + 1);

    printLevel(level);
    printLn("DO");
    statements.print(level + 1);
  }
예제 #5
0
  @Override
  public void emitCode(GluonOutput code) {
    code.comment("Function: " + funcName.getValue());
    String funcLabel = GluonFunction.getLabel(funcName.getValue());
    // Setup variables passed in on stack for use
    int offset = 4; // + 4 * parameters.size();
    int used = 4;
    for (Variable parameter : parameters) {
      int stackOffset = offset + used;
      used += 4;
      code.code(parameter.getLabel() + " EQU EBP + " + stackOffset);
    }
    // Function
    code.label(funcLabel);
    // Push BP
    code.code("PUSH EBP");
    // Mov BP, SP
    code.code("MOV EBP, ESP");
    // Local variables
    scope.emitCreateScope(code);
    // Push all reg
    code.code("PUSH EAX");
    code.code("PUSH EBX");
    code.code("PUSH ECX");
    code.code("PUSH EDX");
    // Actual function logic
    code.comment("Function code start");
    logic.emitCode(code);
    code.comment("Function code end");
    // Pop all reg
    code.code("POP EDX");
    code.code("POP ECX");
    code.code("POP EBX");
    code.code("POP EAX");
    // Local variables
    scope.emitDistroyScope(code);
    // Pop BP
    code.code("POP EBP");
    // Ret paramaters
    code.code("RET");

    scope.buildRestore(code, parameters, true);
    code.comment("Function end: " + funcName.getValue());
  }
예제 #6
0
  @Override
  public void emitCode(GluonOutput code) {
    // Creae labels
    String labelStart = GluonLabels.createLabel(first, "start");
    String labelEnd = GluonLabels.createLabel(first, "end");
    GluonLabels.addEndLabel(labelEnd);

    code.comment("While Statement");
    code.label(labelStart);
    testExp.emitCode(code);
    code.code("TEST AL, AL ;EAX, EAX");
    code.code("JZ " + labelEnd);
    statements.emitCode(code);
    code.code("JMP " + labelStart);
    code.label(labelEnd);
    code.comment("End While");

    GluonLabels.removeEndLabel(labelEnd);
  }