Package bgu.bio.io.file.json

Examples of bgu.bio.io.file.json.JSONObject


  }

  @Override
  public boolean isEnd(String msg) {
    try {
      JSONObject obj = new JSONObject(msg);
      String command = obj.getString("command");
      return command.equals("terminate");
    } catch (JSONException ex) {
      ex.printStackTrace();
    }
    return false;
View Full Code Here


      }
      if (this.isEnd(msg)) {
        this._shouldClose = true;
        return "{\"message\":\"TERM\"}";
      }
      JSONObject obj = new JSONObject(msg);

      String command = obj.getString("command");
      JSONObject result = new JSONObject();
      if (command.equals("script.reverse")) {
        String str1 = obj.optString("string1");
        if (str1 == null)
          return error("got no string");

        StringBuilder sb = new StringBuilder();
        for (int i = str1.length() - 1; i >= 0; i--) {
          sb.append(str1.charAt(i));
        }

        result.put("command", "OK");
        result.put("result", sb.toString());

        return result.toString();
      } else if (command.equals("script.complement")) {
        String str1 = obj.optString("string1");
        boolean rev = obj.optBoolean("reverse");
        if (str1 == null)
          return error("got no string");
        if (rev) {
          StringBuilder sb = new StringBuilder();
          for (int i = str1.length() - 1; i >= 0; i--) {
            sb.append(str1.charAt(i));
          }
          str1 = sb.toString();
        }

        RnaAlphabet alphabet = RnaAlphabet.getInstance();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str1.length(); i++) {
          sb.append(alphabet.complement(str1.charAt(i)));
        }

        result.put("command", "OK");
        result.put("result", sb.toString());

        return result.toString();
      } else if (command.equals("script.ed")) {
        String str1 = obj.optString("string1").toUpperCase();
        String str2 = obj.optString("string2").toUpperCase();
        EditDistance ed = new EditDistance(str1, str2,
            new IdentityEditDistanceScoringMatrix());
        if (str1 == null || str2 == null)
          return error("got no strings");

        ed.buildMatrix();
        int score = (int) ed.getAlignmentScore();
        String[] res = ed.printAlignments();

        result.put("command", "OK");
        result.put("score", score);
        result.put("line1", res[0]);
        result.put("middle", res[1]);
        result.put("line2", res[2]);

        return result.toString();
      } else {
        this.data.log.info("Mainframe got a unknown command " + msg);
        return "{\"command\":\"error\",\"reason\":\"unknown command\"}";
      }
View Full Code Here

    return table;
  }

  public static FixedStepRangesTable BuildFromJSON(String json) {
    try {
      return BuildFromJSON(new JSONObject(json));
    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }
  } 
View Full Code Here

        structure.setCharAt(pair.getSecond()
            - current.get(0).getFirst(), ')');
      }
      String newHeader = this.header;
      try {
        JSONObject json = new JSONObject();
        json.put("header", this.header.substring(1).trim());
        json.put("start", current.get(0).getFirst());
        newHeader = json.toString();
      } catch (JSONException ex) {

      }

      ans.add(new RNA(ans.size(), newHeader, sequence, structure
View Full Code Here

    for (int i = 0; i < files.length; i++) {
      try {
        String json = content(files[i].getAbsolutePath());
        FlexibleUndirectedGraph graph = FlexibleUndirectedGraph
            .fromJSON(new JSONObject(json));
        System.out.println(files[i].getName() + " " + graph.stats());
        /*
        FileWriter writer = new FileWriter(files[i].getName() + ".dot");
        writer.write(graph.toDOTFormat());
        writer.close();
View Full Code Here

      i = 0;
      for (String string : sp) {
        expected[i] = Integer.parseInt(string.trim());
        i++;
      }
      JSONObject jsonData = new JSONObject(json.trim());
      FlexibleUndirectedGraph graph = FlexibleUndirectedGraph
          .fromJSON(jsonData);
      MaximalWeightedClique maximalWeightedClique = new MaximalWeightedClique();
      maximalWeightedClique.setGraph(graph);
      if (useTimeout) {
View Full Code Here

    for (int i = 0; i < edges.length; i++) {
      graph.addEdge(edges[i][0], edges[i][1]);
    }

    try {
      JSONObject json = graph.toJSON();
      FlexibleUndirectedGraph graph2 = FlexibleUndirectedGraph
          .fromJSON(json);
      Assert.assertEquals("Wrong number of nodes", graph.getNodeNum(),
          graph2.getNodeNum());
      Assert.assertEquals("Wrong number of edges", graph.getEdgeNum(),
View Full Code Here

      }
    }
  }

  public JSONObject toJSON() throws JSONException {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("nodes", this.getNodeNum());
    JSONArray array = new JSONArray();
    for (int i = 0; i < nodeNum; i++) {
      JSONArray inner = new JSONArray();
      TIntArrayList adj = adjLists.get(i);
      for (int d = 0; d < adj.size(); d++) {
        if (adj.get(d) > i) {
          inner.put(adj.get(d));
        }
      }
      array.put(inner);
    }
    jsonObject.put("edges", array);
    return jsonObject;
  }
View Full Code Here

  public ArrayList<Pair<RNA, ArrayList<StemInfo>>> loadFile(String filename)
      throws FileNotFoundException, JSONException, IOException {
    ArrayList<Pair<RNA, ArrayList<StemInfo>>> list = new ArrayList<Pair<RNA, ArrayList<StemInfo>>>();
    // load the file

    JSONObject json = new JSONObject(readFileToString(filename));
   
    return list;
  }
View Full Code Here

TOP

Related Classes of bgu.bio.io.file.json.JSONObject

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.