コード例 #1
0
  /**
   * create an (modified) amino acid node
   *
   * @param monomerID
   * @return amino acid node graph
   */
  @Deprecated
  public static Graph2D createAminoAcidNode(String monomerID)
      throws MonomerException, IOException, JDOMException {

    MonomerFactory monomerFactory = MonomerFactory.getInstance();
    Map<String, Map<String, Monomer>> monomerDB = monomerFactory.getMonomerDB();

    Graph2D graph = new Graph2D();

    MonomerInfo monomerKeys = new MonomerInfo(Monomer.PEPTIDE_POLYMER_TYPE, monomerID);
    Monomer monomer = monomerDB.get(monomerKeys.getPolymerType()).get(monomerKeys.getMonomerID());
    if (monomer == null) {
      throw new MonomerException("Invalid HELM notation " + monomerID);
    }

    MonomerNodeRealizer nodeRealizer = new MonomerNodeRealizer(MonomerNodeRealizer.DIAMOND);
    nodeRealizer.setSize(size, size);
    nodeRealizer.setLabelText(monomerID);
    nodeRealizer.setFillColor(ColorMap.getAminoAcidColor(monomer.getNaturalAnalog()));
    nodeRealizer.getLabel().setFontSize(calculateFontSize(monomerID));

    Node node = graph.createNode(nodeRealizer);
    NodeMap nodeMap = graph.createNodeMap();
    nodeMap.set(node, monomerKeys);

    graph.addDataProvider(NodeMapKeys.MONOMER_REF, nodeMap);

    return graph;
  }
コード例 #2
0
  /**
   * create a registared chemical structure node
   *
   * @param monomerID
   * @return chemcial modifier node graph
   */
  @Deprecated
  public static Graph2D createChemNode(String monomerID)
      throws MonomerException, IOException, JDOMException {

    MonomerFactory monomerFactory = MonomerFactory.getInstance();
    Map<String, Map<String, Monomer>> monomerDB = monomerFactory.getMonomerDB();

    MonomerInfo monomerKeys = new MonomerInfo(Monomer.CHEMICAL_POLYMER_TYPE, monomerID);
    Monomer monomer = monomerDB.get(monomerKeys.getPolymerType()).get(monomerKeys.getMonomerID());
    if (monomer == null) {
      throw new MonomerException("Invalid chemical ID " + monomerID);
    }

    Graph2D graph = new Graph2D();

    MonomerNodeRealizer nodeRealizer = new MonomerNodeRealizer(MonomerNodeRealizer.HEXAGON);
    nodeRealizer.setSize(size, size);
    nodeRealizer.setLabelText(monomerID);
    nodeRealizer.getLabel().setFontSize(calculateFontSize(monomerID));

    nodeRealizer.setFillColor(new Color(200, 0, 255)); // was Color.magenta;

    Node node = graph.createNode(nodeRealizer);

    NodeMap nodeMap = graph.createNodeMap();
    nodeMap.set(node, monomerKeys);

    graph.addDataProvider(NodeMapKeys.MONOMER_REF, nodeMap);

    return graph;
  }
コード例 #3
0
 public static String getStructureImageFilePath(Node node) {
   Graph2D graph = (Graph2D) node.getGraph();
   NodeRealizer nr = graph.getRealizer(node);
   String fileName = nr.getLabelText();
   fileName = fileName + ".png";
   return NUCLEOTIDE_DIRECTORY + System.getProperty("file.separator") + fileName;
 }
コード例 #4
0
  private Node createNode(String label, Graph2D graph) {
    Node node = graph.createNode();

    NodeRealizer nodeRealizer = graph.getRealizer(node);
    nodeRealizer.getLabel().setText(label);

    return node;
  }
コード例 #5
0
  private void realizeChemEdge(
      Graph2D graph, Edge newEdge, Attachment sourceAttachment, Attachment targetAttachment) {

    EdgeMap edgeTypeMap = (EdgeMap) graph.getDataProvider(EdgeMapKeys.EDGE_INFO);

    EdgeRealizer er = graph.getRealizer(newEdge);
    er.setLineColor(Color.BLACK);
    er.setLineType(LineType.LINE_1);
    edgeTypeMap.set(newEdge, new SViewEdgeInfo(EdgeType.CHEM, sourceAttachment, targetAttachment));
  }
コード例 #6
0
  private void addBranchToBranchEdge(
      Edge currentEdge, Attachment sourceAttachment, Attachment targetAttachment) {
    EdgeMap edgeTypeMap = (EdgeMap) _graph.getDataProvider(EdgeMapKeys.EDGE_INFO);

    Node sourceNode = _viewModel.getViewNode(currentEdge.source());
    Node targetNode = _viewModel.getViewNode(currentEdge.target());

    Edge newEdge = _graph.createEdge(sourceNode, targetNode);
    edgeTypeMap.set(
        newEdge, new SViewEdgeInfo(EdgeType.BRANCH_BRANCH, sourceAttachment, targetAttachment));

    sourceNode = getViewStartingNode(newEdge.source(), _graph);
    targetNode = getViewStartingNode(newEdge.target(), _graph);

    _viewModel.addComplentaryViewNodes(sourceNode, targetNode);
  }
コード例 #7
0
  private Edge addSimpleEdge(Edge currentEdge) {
    Node sourceFrom = currentEdge.source();
    Node from = _viewModel.getViewNode(sourceFrom);

    if (from == null) {
      from = realizeNeigbour(_graph, sourceFrom);
    }

    Node sourceTo = currentEdge.target();
    Node to = _viewModel.getViewNode(sourceTo);
    if (to == null) {
      to = realizeNeigbour(_graph, sourceTo);
    }

    Edge newEdge = _graph.createEdge(from, to);
    return newEdge;
  }
コード例 #8
0
  private Node createChemNode(String label, Graph2D graph) {
    Node chem = createNode(label, graph);
    NodeRealizer nodeRealizer = graph.getRealizer(chem);
    nodeRealizer.setTransparent(false);

    NodeLabel nl = nodeRealizer.getLabel(0);
    // nodeRealizer.setSize(_layoutMetrics.getChemNodeSize(),
    // _layoutMetrics.getChemNodeSize());
    nodeRealizer.setSize(nl.getBox().getWidth() + 10, nl.getBox().getHeight());
    nl.setFontSize(_layoutMetrics.getChemNodeFontSize());
    nl.setFontStyle(Font.BOLD);
    nl.setModel(NodeLabel.INTERNAL);
    nl.setPosition(NodeLabel.CENTER);
    nl.setAlignment(NodeLabel.ALIGN_CENTER);
    nl.setTextColor(Color.BLACK);

    return chem;
  }
コード例 #9
0
  private Node createErrorNode(String label, Graph2D graph) {
    Node node = createNode(label, graph);

    NodeRealizer nodeRealizer = graph.getRealizer(node);
    nodeRealizer.setTransparent(true);
    nodeRealizer.setLineColor(Color.white);

    NodeLabel nl = nodeRealizer.getLabel(0);
    nl.setFontSize(_layoutMetrics.getLabelFontSize() + 15);
    nl.setFontStyle(Font.PLAIN);
    nl.setModel(NodeLabel.INTERNAL);
    nl.setPosition(NodeLabel.CENTER);
    nl.setAlignment(NodeLabel.ALIGN_LEFT);
    nl.setTextColor(Color.cyan);

    nodeRealizer.setSize(nl.getBox().getWidth(), nl.getBox().getHeight());

    return node;
  }
コード例 #10
0
  /**
   * get the starting node of the sequence in where the current node is sitting in
   *
   * @deprecated use getViewStartingNode
   * @param node
   * @param graph
   * @return
   */
  @Deprecated
  private Node getStartingNode(Node node, Graph2D graph) {

    if (_viewModel.getStartingViewNodeList().contains(node)) {
      return node;
    } else {
      NodeCursor pres = node.predecessors();
      Edge edge;
      Node currentNode = node;

      EdgeMap edgeMap = (EdgeMap) graph.getDataProvider(EdgeMapKeys.EDGE_INFO);
      Node preNode = currentNode;
      while (pres.ok()) {
        for (; pres.ok(); pres.next()) {
          edge = currentNode.getEdge(pres.node());

          EdgeType edgeType = ((SViewEdgeInfo) edgeMap.get(edge)).getType();
          if ((edgeType == EdgeType.REGULAR) || (edgeType == EdgeType.MODIFIED_P)) {
            currentNode = pres.node();
            break;
          }
        }
        if (currentNode != preNode) {
          pres = currentNode.predecessors();
          preNode = currentNode;
        } else {
          break;
        }
      }
      if (_viewModel.getStartingViewNodeList().contains(currentNode)) {
        return currentNode;
      } else {
        return null;
      }
    }
  }
コード例 #11
0
  /**
   * Build a (modified) nucleic acid base node, this node should already registared in the database
   *
   * @param monomerID : the name of the base node
   * @return a graph contains a single (base) node
   */
  @Deprecated
  public static Graph2D createNucleicAcidBaseNode(String monomerID)
      throws MonomerException, IOException, JDOMException {

    MonomerFactory monomerFactory = MonomerFactory.getInstance();
    Map<String, Map<String, Monomer>> monomerDB = monomerFactory.getMonomerDB();

    Graph2D graph = new Graph2D();
    MonomerNodeRealizer baseNodeRealizer = new MonomerNodeRealizer(MonomerNodeRealizer.DIAMOND);
    graph.setDefaultNodeRealizer(baseNodeRealizer);

    baseNodeRealizer.setSize(size, size);

    MonomerInfo monomerKeys = new MonomerInfo(Monomer.NUCLIEC_ACID_POLYMER_TYPE, monomerID);
    Monomer baseMonomer =
        monomerDB.get(monomerKeys.getPolymerType()).get(monomerKeys.getMonomerID());

    if (baseMonomer == null) {
      throw new MonomerException("Invalid base monomer " + monomerID);
    }

    Node baseNode = graph.createNode();

    Color fillColor = ColorMap.getNucleotidesColor(baseMonomer.getNaturalAnalog());
    baseNodeRealizer.setFillColor(fillColor);

    Color textColor = Color.BLACK;
    // was: Color textColor = new Color(23 - fillColor.getRGB());
    // but we want identical view at left panel and at sequence panel, so
    // textColor is always set to black.

    baseNodeRealizer.setLabelText(monomerID);
    baseNodeRealizer.getLabel().setTextColor(textColor);
    baseNodeRealizer.getLabel().setFontSize(calculateFontSize(monomerID));

    graph.setRealizer(baseNode, baseNodeRealizer);

    NodeMap nodePropertiesNodeMap = graph.createNodeMap();
    graph.addDataProvider(NodeMapKeys.MONOMER_REF, nodePropertiesNodeMap);
    nodePropertiesNodeMap.set(baseNode, monomerKeys);

    return graph;
  }
コード例 #12
0
  /**
   * create a (modified) nucleic acid backbone node. this monomer should already registared in the
   * monomer database
   *
   * @param monomerID
   * @return A graph contains a nucleic acid backbone node
   */
  @Deprecated
  public static Graph2D createNucleicAcidBackboneNode(String monomerID, String naturalAnalog)
      throws MonomerException, IOException, JDOMException {

    final String url = MacromoleculeEditor.class.getResource("resource/").getFile();

    MonomerFactory monomerFactory = MonomerFactory.getInstance();
    Map<String, Map<String, Monomer>> monomerDB = monomerFactory.getMonomerDB();

    Graph2D graph = new Graph2D();
    MonomerNodeRealizer backboneNodeRealizer = null;
    if (naturalAnalog.equalsIgnoreCase(Monomer.ID_R)) {
      backboneNodeRealizer = new MonomerNodeRealizer(MonomerNodeRealizer.ROUND_RECT);
    } else if (naturalAnalog.equalsIgnoreCase(Monomer.ID_P)) {
      backboneNodeRealizer = new MonomerNodeRealizer(MonomerNodeRealizer.ELLIPSE);
    } else {
      backboneNodeRealizer = new MonomerNodeRealizer(MonomerNodeRealizer.OCTAGON);
    }

    backboneNodeRealizer.setFillColor(ColorMap.getNucleotidesColor(naturalAnalog));
    backboneNodeRealizer.setSize(size, size);

    graph.setDefaultNodeRealizer(backboneNodeRealizer);

    MonomerInfo monomerKeys = new MonomerInfo(Monomer.NUCLIEC_ACID_POLYMER_TYPE, monomerID);
    Monomer monomer = monomerDB.get(monomerKeys.getPolymerType()).get(monomerKeys.getMonomerID());

    if (monomer == null) {
      throw new MonomerException("Invalid backbone monomer ID " + monomerID);
    }
    Node baseNode = graph.createNode();
    backboneNodeRealizer.setLabelText(monomerID);
    backboneNodeRealizer.setFillColor(ColorMap.getNucleotidesColor(monomer.getNaturalAnalog()));
    graph.setRealizer(baseNode, backboneNodeRealizer);

    NodeMap nodePropertiesNodeMap = graph.createNodeMap();
    graph.addDataProvider(NodeMapKeys.MONOMER_REF, nodePropertiesNodeMap);
    nodePropertiesNodeMap.set(baseNode, monomerKeys);
    return graph;
  }
コード例 #13
0
  /**
   * a dummy base node with no monomer attached to it
   *
   * @param monomerID
   * @return dummy nucleic acid base node graph
   */
  public static Graph2D createDummyNucleicAcidBaseNode(String monomerID) {

    Graph2D graph = new Graph2D();
    MonomerNodeRealizer baseNodeRealizer = new MonomerNodeRealizer(MonomerNodeRealizer.DIAMOND);
    graph.setDefaultNodeRealizer(baseNodeRealizer);

    final int size = 30;
    baseNodeRealizer.setSize(size, size);

    MonomerInfo monomerKeys = new MonomerInfo(Monomer.NUCLIEC_ACID_POLYMER_TYPE, monomerID);

    Node baseNode = graph.createNode();

    Color fillColor = ColorMap.getNucleotidesColor("X");
    baseNodeRealizer.setFillColor(fillColor);

    Color textColor = new Color(23 - fillColor.getRGB());
    baseNodeRealizer.setLabelText(monomerID);
    baseNodeRealizer.getLabel().setTextColor(textColor);
    baseNodeRealizer.getLabel().setFontSize(14);

    graph.setRealizer(baseNode, baseNodeRealizer);

    NodeMap nodePropertiesNodeMap = graph.createNodeMap();
    graph.addDataProvider(NodeMapKeys.MONOMER_REF, nodePropertiesNodeMap);
    nodePropertiesNodeMap.set(baseNode, monomerKeys);

    NodeLabel anotationLabel = new NodeLabel("");
    anotationLabel.setModel(NodeLabel.FREE);
    anotationLabel.setFreeOffset(
        -baseNodeRealizer.getHeight() / 2, -baseNodeRealizer.getWidth() / 4);
    anotationLabel.setTextColor(ANOTATION_COLOR);
    anotationLabel.setFontSize(baseNodeRealizer.getLabel().getFontSize() + 2);

    baseNodeRealizer.addLabel(anotationLabel);

    return graph;
  }
コード例 #14
0
  /**
   * Create a standard graph. Each graph contains 3 nodes, base<-R->P where R and P are standard
   * monomers
   *
   * @param notation : the base monomer id. A, T, C, G, U
   * @return a graph that represents a notation
   */
  @Deprecated
  public static Graph2D createNucleictideNodeGraph(String notation)
      throws MonomerException, IOException, JDOMException {

    // a graph is used in here because we need to associate data with every nodes
    Graph2D graph = new Graph2D();
    graph.setDefaultNodeRealizer(new MonomerNodeRealizer());
    NodeMap nodePropertiesNodeMap = graph.createNodeMap();
    graph.addDataProvider(NodeMapKeys.MONOMER_REF, nodePropertiesNodeMap);

    EdgeMap edgeMap = graph.createEdgeMap();
    graph.addDataProvider(EdgeMapKeys.EDGE_INFO, edgeMap);

    GraphCopier copier = new GraphCopier(graph.getGraphCopyFactory());
    copier.setDataProviderContentCopying(true);
    copier.setEdgeMapCopying(true);
    copier.setNodeMapCopying(true);

    String baseMonomerID = notation.substring(notation.indexOf("(") + 1, notation.indexOf(")"));
    baseMonomerID = baseMonomerID.replace("[", "");
    baseMonomerID = baseMonomerID.replace("]", "");

    Node baseNode = copier.copy(createNucleicAcidBaseNode(baseMonomerID), graph).firstNode();
    NodeRealizer baseNodeRealizer = graph.getRealizer(baseNode);
    baseNodeRealizer.setCenter(centerX, centerY + size + distance);

    String r = notation.substring(0, notation.indexOf("("));
    r = r.replace("[", "");
    r = r.replace("]", "");

    Node rNode = copier.copy(createNucleicAcidBackboneNode(r, Monomer.ID_R), graph).firstNode();
    NodeRealizer rNodeRealizer = graph.getRealizer(rNode);
    rNodeRealizer.setCenter(centerX, centerY);

    String p = notation.substring(notation.indexOf(")") + 1);
    p = p.replace("[", "");
    p = p.replace("]", "");

    Node pNode = copier.copy(createNucleicAcidBackboneNode(p, Monomer.ID_P), graph).firstNode();
    NodeRealizer pNodeRealizer = graph.getRealizer(pNode);
    pNodeRealizer.setCenter(centerX + size + distance, centerY);

    MonomerInfo pKeys = (MonomerInfo) nodePropertiesNodeMap.get(pNode);
    MonomerInfo rKeys = (MonomerInfo) nodePropertiesNodeMap.get(rNode);
    MonomerInfo baseKeys = (MonomerInfo) nodePropertiesNodeMap.get(baseNode);

    // r->p
    Edge edge = graph.createEdge(rNode, pNode);
    Attachment sourceAttachment =
        rKeys.getAttachment(Attachment.BACKBONE_MONOMER_RIGHT_ATTACHEMENT);
    Attachment targetAttachment = pKeys.getAttachment(Attachment.BACKBONE_MONOMER_LEFT_ATTACHEMENT);
    rKeys.setConnection(sourceAttachment, true);
    pKeys.setConnection(targetAttachment, true);

    edgeMap.set(edge, new EditorEdgeInfoData(sourceAttachment, targetAttachment));

    // r->base
    edge = graph.createEdge(rNode, baseNode);

    sourceAttachment = rKeys.getAttachment(Attachment.BACKBONE_MONOMER_BRANCH_ATTACHEMENT);
    targetAttachment = baseKeys.getAttachment(Attachment.BRANCH_MONOMER_ATTACHEMENT);
    rKeys.setConnection(sourceAttachment, true);
    baseKeys.setConnection(targetAttachment, true);

    edgeMap.set(edge, new EditorEdgeInfoData(sourceAttachment, targetAttachment));

    return graph;
  }
コード例 #15
0
 public static String getNotation(Node node) {
   Graph2D graph = (Graph2D) node.getGraph();
   NodeMap nodeMap = (NodeMap) graph.getDataProvider(NodeMapKeys.FOLDER_NODE_NOTATION);
   return (String) nodeMap.get(node);
 }
コード例 #16
0
 private Node getViewStartingNode(Node node, Graph2D view) {
   NodeMap startingNodeMap = (NodeMap) _graph.getDataProvider(NodeMapKeys.NODE2STARTING_NODE);
   return (Node) startingNodeMap.get(node);
 }