コード例 #1
0
  @Before
  public void setup() {
    nw = new Network();
    nw.setName("test network");

    dp = new DensityMap();

    nw.setNodes(new ArrayList<edu.berkeley.path.model_elements_base.Node>());
    nw.setLinks(new ArrayList<edu.berkeley.path.model_elements_base.Link>());

    Node nd1;
    Node nd2;
    Link ln;

    nd1 = new Node();
    nd1.setId(1L);
    nd1.setName("one");
    nd1.setType("Highway");
    nw.getNodes().add(nd1);

    nd2 = new Node();
    nd2.setId(2L);
    nd2.setName("two");
    nd2.setType("Highway");
    nw.getNodes().add(nd2);

    ln = new Link();
    ln.setId(3L);
    ln.setName("three");
    ln.setType("Highway");
    ln.setLaneCount(4.0);
    ln.setLength(1000.0);

    ln.setBegin(nd1);
    ln.setEnd(nd2);

    nw.getLinks().add(ln);
  }
コード例 #2
0
  /**
   * a network is a collection of (possibly degenerate) interactions. the R client should pass 3
   * arrays of strings, having the following structure
   *
   * <p>edges consist of strings like "VNG0723G::VNG1233G::PhylogeneticProfile" node attributes:
   * "VNG1233G::commonName::pepq2" edge attributes:
   * "VNG0723G::VNG1233G::PhylogeneticProfile::confidence::0.533"
   */
  public void createAndBroadcastNetwork(
      String[] interactionStrings,
      String[] nodeAttributeStrings,
      String[] edgeAttributeStrings,
      String name) {

    Network network = new Network();
    addMetaDataToNetwork(network);
    network.setName(name);
    network.setSpecies(defaultSpecies);

    for (String interactionString : interactionStrings) {
      String[] tokens = interactionString.split("::");
      int tokenCount = tokens.length;
      // for (int t=0; t < tokens.length; t++)
      //  System.out.println ("  edge token " + t + ": " + tokens [t]);
      if (tokenCount == 1 && tokens[0].trim().length() > 0) {
        // System.out.println ("adding one orphan node to network: " + tokens [0]);
        network.add(tokens[0]);
      } else if (tokenCount == 3) {
        String sourceNode = tokens[0];
        String targetNode = tokens[1];
        String interactionType = tokens[2];
        network.add(new Interaction(sourceNode, targetNode, interactionType));
      } // else:  good interaction
    } // for i

    // System.out.println ("nodeAttributeStrings count: " + nodeAttributeStrings.length);
    for (String nodeAttributeString : nodeAttributeStrings) {
      // System.out.println ("   " + nodeAttributeStrings [i]);
      String[] tokens = nodeAttributeString.split("::");
      if (tokens.length == 3) {
        String nodeName = tokens[0].trim();
        String attributeName = tokens[1].trim();
        String rawValue = tokens[2].trim();
        Object value = StringToObjectConverter.convert(rawValue);
        network.addNodeAttribute(nodeName, attributeName, value);
      } // if 3 tokens
    } // for i

    // System.out.println ("edgeAttributeStrings count: " + edgeAttributeStrings.length);
    for (String edgeAttributeString : edgeAttributeStrings) {
      // System.out.println ("   " + edgeAttributeStrings [i]);
      String[] tokens = edgeAttributeString.split("::");
      if (tokens.length == 5) {
        String sourceNode = tokens[0].trim();
        String targetNode = tokens[1].trim();
        String edgeType = tokens[2].trim();
        String attributeName = tokens[3].trim();
        String rawValue = tokens[4].trim();
        Object value = StringToObjectConverter.convert(rawValue);
        String edgeName = sourceNode + " (" + edgeType + ") " + targetNode;
        network.addEdgeAttribute(edgeName, attributeName, value);
      } // if 5 tokens
    } // for i

    // System.out.println ("RShellGoose, about to broadcast network");
    // System.out.println ("     node count: " + network.getNodes().length);
    // System.out.println ("      connected: " + network.getConnectedNodes ().size ());
    // System.out.println ("         orphan: " + network.getOrphanNodes().length);

    try {
      gaggleBoss.broadcastNetwork(myGaggleName, targetGoose, network);
    } catch (RemoteException rex) {
      System.err.println("error broadcasting network from RShellGoose " + myGaggleName);
      rex.printStackTrace();
    }
  } // createAndBroadcastNetwork