/** Split objects into normal and disease components */
  private void splitObjects() {
    normalIds = new HashSet<Long>();
    diseaseIds = new HashSet<Long>();
    RenderablePathway diagram = (RenderablePathway) getRenderable();
    if (pathway == null || diagram.getReactomeDiagramId() == null) return;
    try {
      GKInstance pdInst = adaptor.fetchInstance(diagram.getReactomeDiagramId());
      // Get the disease pathway instance
      List<GKInstance> pathways =
          pdInst.getAttributeValuesList(ReactomeJavaConstants.representedPathway);

      GKInstance diseasePathway = null;
      GKInstance normalPathway = null;
      GKInstance disease = (GKInstance) pathway.getAttributeValue(ReactomeJavaConstants.disease);
      if (disease == null && contains(pathway, pathways)) {
        normalPathway = pathway;
      } else {
        diseasePathway = pathway;
        // There should be a normal pathway contained by a disease pathway
        List<?> subPathways = diseasePathway.getAttributeValuesList(ReactomeJavaConstants.hasEvent);
        for (Object obj : subPathways) {
          GKInstance subPathway = (GKInstance) obj;
          disease = (GKInstance) subPathway.getAttributeValue(ReactomeJavaConstants.disease);
          if (disease == null && contains(subPathway, pathways)) {
            normalPathway = subPathway;
            break;
          }
        }
      }
      if (normalPathway != null) {
        // Get all disease related objects
        Set<GKInstance> normalEvents = InstanceUtilities.grepPathwayEventComponents(normalPathway);
        for (GKInstance inst : normalEvents) normalIds.add(inst.getDBID());
        Set<GKInstance> normalEntities = InstanceUtilities.grepPathwayParticipants(normalPathway);
        for (GKInstance inst : normalEntities) normalIds.add(inst.getDBID());
        if (diseasePathway != null) {
          Set<GKInstance> allEvents = InstanceUtilities.grepPathwayEventComponents(diseasePathway);
          allEvents.removeAll(normalEvents);
          for (GKInstance inst : allEvents) {
            diseaseIds.add(inst.getDBID());
            // Want to make sure disease pathways are connected to objects
            if (inst.getSchemClass().isa(ReactomeJavaConstants.ReactionlikeEvent)) {
              Set<GKInstance> rxtEntities = InstanceUtilities.getReactionParticipants(inst);
              for (GKInstance rxtEntity : rxtEntities) {
                diseaseIds.add(rxtEntity.getDBID());
              }
            }
          }
          //                    Set<GKInstance> allEntities =
          // InstanceUtilities.grepPathwayParticipants(diseasePathway);
          //                    allEntities.removeAll(normalEntities);
          //                    for (GKInstance inst : allEntities)
          //                        diseaseIds.add(inst.getDBID());
        }
      }
      splitComponents();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 protected List getSynchronizingClassList(XMLFileAdaptor fileAdaptor) {
   GKSchemaClass topCls = selectedCls;
   if (topCls == null)
     topCls = (GKSchemaClass) ((GKSchema) fileAdaptor.getSchema()).getRootClass();
   List clsList = new ArrayList();
   InstanceUtilities.getDescendentClasses(clsList, topCls);
   return clsList;
 }
 /**
  * Overlay a single disease reaction onto a normal reaction.
  *
  * @param normalReaction
  * @param diseaseReaction
  * @param overlaidObjects
  */
 private void overlayDiseaseReaction(HyperEdge normalReaction, GKInstance diseaseReaction)
     throws Exception {
   // Make a copy of the HyperEdge for future process that is related to Vertex and JSON generation
   HyperEdge reactionCopy = normalReaction.shallowCopy();
   reactionCopy.setReactomeId(diseaseReaction.getDBID());
   reactionCopy.setDisplayName(diseaseReaction.getDisplayName());
   reactionCopy.setLineColor(DefaultRenderConstants.DEFAULT_DISEASE_BACKGROUND);
   displayedObject.addComponent(reactionCopy);
   overlaidObjects.add(reactionCopy);
   // Want to handle inputs, outputs and catalysts since regulators can
   // be ignored
   List<Node> nodes = new ArrayList<Node>();
   nodes.addAll(normalReaction.getInputNodes());
   nodes.addAll(normalReaction.getOutputNodes());
   nodes.addAll(normalReaction.getHelperNodes());
   // List objects not listed in the disease reaction as crossed objects
   Set<GKInstance> participants = InstanceUtilities.getReactionParticipants(diseaseReaction);
   Set<Long> diseaseIds = new HashSet<Long>();
   for (GKInstance participant : participants) {
     diseaseIds.add(participant.getDBID());
     if (participant.getSchemClass().isValidAttribute(ReactomeJavaConstants.hasMember)) {
       List<GKInstance> list = participant.getAttributeValuesList(ReactomeJavaConstants.hasMember);
       if (list != null && list.size() > 0) {
         for (GKInstance inst : list) diseaseIds.add(inst.getDBID());
       }
     }
     if (participant.getSchemClass().isValidAttribute(ReactomeJavaConstants.hasCandidate)) {
       List<GKInstance> list =
           participant.getAttributeValuesList(ReactomeJavaConstants.hasCandidate);
       if (list != null && list.size() > 0) {
         for (GKInstance inst : list) diseaseIds.add(inst.getDBID());
       }
     }
   }
   Set<GKInstance> lofInstances = new HashSet<GKInstance>();
   Map<Node, GKInstance> normalToDiseaseEntity =
       mapMutatedToNormalNodes(diseaseReaction, normalReaction, nodes, lofInstances);
   for (Node node : nodes) {
     if (!diseaseIds.contains(node.getReactomeId())) {
       // Check if it should be mapped to a normal entity
       GKInstance diseaseEntity = normalToDiseaseEntity.get(node);
       if (diseaseEntity == null) crossedObjects.add(node); // Just crossed out
       else {
         Node diseaseNode =
             replaceNormalNode(node, diseaseEntity, contains(diseaseEntity, lofInstances));
         if (diseaseNode == null) continue; // Just in case
         // Re-link to diseaseNode
         ConnectInfo connectInfo = reactionCopy.getConnectInfo();
         List<?> widgets = connectInfo.getConnectWidgets();
         for (Object obj : widgets) {
           ConnectWidget widget = (ConnectWidget) obj;
           if (widget.getConnectedNode() == node) widget.replaceConnectedNode(diseaseNode);
         }
       }
     } else overlaidObjects.add(node);
   }
 }
 private void buildTree(Collection instances, DefaultMutableTreeNode parentNode) throws Exception {
   if (instances == null || instances.size() == 0) return;
   List list = new ArrayList(instances);
   InstanceUtilities.sortInstances(list);
   for (Iterator it = list.iterator(); it.hasNext(); ) {
     GKInstance inst = (GKInstance) it.next();
     DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(inst);
     parentNode.add(treeNode);
   }
 }
  private InstanceListPane initInstanceListPane(List instances, String title) {
    InstanceListPane instanceList = new InstanceListPane();
    instanceList.getInstanceList().addListSelectionListener(selectionListener);
    instanceList.setIsViewable(false);
    if (mouseAdaptor == null) {
      // To view instances
      mouseAdaptor =
          new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
              if (e.isPopupTrigger()) doPopup(e);
            }

            public void mouseReleased(MouseEvent e) {
              if (e.isPopupTrigger()) doPopup(e);
            }

            // Use mouseClicked method. See InstanceListPane.init().
            public void mouseClicked(MouseEvent e) {
              if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                JList list = (JList) e.getSource();
                if (list.getSelectedValues().length != 1) return;
                InstanceListPane instanceList = figureOutInstanceListPane(list);
                if (instanceList == changedList || instanceList == localHasMoreIEList) {
                  showComparison();
                } else {
                  GKInstance instance = (GKInstance) list.getSelectedValue();
                  JDialog parentDialog =
                      (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, centerPane);
                  FrameManager.getManager().showInstance(instance, parentDialog);
                }
              }
            }
          };
    }
    instanceList.getInstanceList().addMouseListener(mouseAdaptor);
    InstanceUtilities.sortInstances(instances);
    instanceList.setDisplayedInstances(instances);
    // instanceList.setTitle(title);
    instanceList.setListCellRenderer(cellRenderer);
    instanceList.hideTitle();
    SectionTitlePane titlePane = new SectionTitlePane(title);
    titlePane.setSectionPane(instanceList);
    centerPane.add(titlePane);
    centerPane.add(instanceList);
    listToTitle.put(instanceList, titlePane);
    return instanceList;
  }
 private Set<GKInstance> getReferenceEntity(GKInstance pe) throws Exception {
   Set<GKInstance> rtn = new HashSet<GKInstance>();
   if (pe.getSchemClass().isValidAttribute(ReactomeJavaConstants.referenceEntity)) {
     GKInstance ref = (GKInstance) pe.getAttributeValue(ReactomeJavaConstants.referenceEntity);
     if (ref != null) rtn.add(ref);
     return rtn;
   }
   Set<GKInstance> contained =
       InstanceUtilities.getContainedInstances(
           pe,
           ReactomeJavaConstants.hasMember,
           ReactomeJavaConstants.hasCandidate,
           ReactomeJavaConstants.hasComponent);
   // Check member or complex subunits
   for (GKInstance tmp : contained) {
     if (tmp.getSchemClass().isValidAttribute(ReactomeJavaConstants.referenceEntity)) {
       GKInstance ref = (GKInstance) tmp.getAttributeValue(ReactomeJavaConstants.referenceEntity);
       if (ref != null) rtn.add(ref);
     }
   }
   return rtn;
 }
예제 #7
0
 public boolean shouldEscape(GKInstance inst) {
   if (!needEscapePermissioin) return false;
   if (needEscape && escapedDbIds.contains(inst.getDBID())) {
     if (cutoffDate != null) {
       try {
         // Check if the latest IEs is later than the cutoff date
         GKInstance latestIE = InstanceUtilities.getLatestIEFromInstance(inst);
         // Just in case
         if (latestIE == null) return true;
         String ieDateValue = (String) latestIE.getAttributeValue(ReactomeJavaConstants.dateTime);
         // Have to make sure default date instance is used!
         DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
         Date ieDate = df.parse(ieDateValue);
         return !ieDate.after(cutoffDate);
       } catch (Exception e) {
         // Don't want to show a GUI here. Just generate error message silently.
         System.err.println("QAEscapeHelper.shouldEscape(): " + e);
         e.printStackTrace();
         return false;
       }
     } else return true;
   }
   return false;
 }
 private void updateFromDB() {
   InstanceListPane touchedList = null;
   // Find out which instances have been selected in all relevant lists
   // Update the attribute values for changed list.
   try {
     if (changedList != null) {
       java.util.List list = new ArrayList(changedList.getSelection()); // To support it.remove()
       // Use a new ArrayList.
       if (list != null && list.size() > 0) {
         for (Iterator it = list.iterator(); it.hasNext(); ) {
           GKInstance instance = (GKInstance) it.next();
           // Fetch GKInstance based on its DB_ID since SchemaClass might be changed.
           GKInstance localCopy = fileAdaptor.fetchInstance(instance.getDBID());
           dbAdaptor.setUseCache(false);
           GKInstance dbCopy = dbAdaptor.fetchInstance(instance.getDBID());
           dbAdaptor.setUseCache(true);
           if (SynchronizationManager.getManager().updateFromDB(localCopy, dbCopy, this)) {
             AttributeEditManager.getManager().attributeEdit(localCopy);
             fileAdaptor.removeDirtyFlag(localCopy);
           } else it.remove(); // Remove from the list
         }
         // Remove all selected instances
         changedList.deleteInstances(list);
         touchedList = changedList;
       }
     }
     if (localHasMoreIEList != null && localHasMoreIEList.getSelection().size() > 0) {
       List list = new ArrayList(localHasMoreIEList.getSelection());
       for (Iterator it = list.iterator(); it.hasNext(); ) {
         GKInstance localCopy = (GKInstance) it.next();
         dbAdaptor.setUseCache(false);
         GKInstance dbCopy = dbAdaptor.fetchInstance(localCopy.getDBID());
         dbAdaptor.setUseCache(true);
         if (SynchronizationManager.getManager().updateFromDB(localCopy, dbCopy, this)) {
           AttributeEditManager.getManager().attributeEdit(localCopy);
           fileAdaptor.removeDirtyFlag(localCopy);
         } else it.remove(); // Remove from the list, if it it cancelled by the user.
       }
       localHasMoreIEList.deleteInstances(list);
       touchedList = localHasMoreIEList;
     }
     // Delete the local copy for deleteInDBList.
     if (deleteInDBList != null) {
       java.util.List list = deleteInDBList.getSelection();
       if (list != null && list.size() > 0) {
         for (Iterator it = list.iterator(); it.hasNext(); ) {
           GKInstance instance = (GKInstance) it.next();
           fileAdaptor.deleteInstance(instance);
         }
       }
       deleteInDBList.deleteInstances(list);
       touchedList = deleteInDBList;
     }
     // Get another copy for the local repository
     if (deleteList != null) {
       java.util.List<?> list = deleteList.getSelection();
       if (list != null && list.size() > 0) {
         Map<SchemaClass, Set<GKInstance>> checkOutMap =
             new HashMap<SchemaClass, Set<GKInstance>>(); // All checked out Instances
         for (Iterator<?> it = list.iterator(); it.hasNext(); ) {
           GKInstance instance = (GKInstance) it.next();
           Map<SchemaClass, List<GKInstance>> schemaMap =
               InstanceUtilities.listDownloadableInstances(instance);
           // Have to merge schemaMap to checkOutMap
           for (SchemaClass key : schemaMap.keySet()) {
             List<GKInstance> list1 = schemaMap.get(key);
             if (list1 != null && list1.size() > 0) {
               Set<GKInstance> list2 = checkOutMap.get(key);
               if (list2 == null) {
                 list2 = new HashSet<GKInstance>();
                 checkOutMap.put(key, list2);
               }
               // Remove first to avoid any duplication
               list2.addAll(list1);
             }
           }
         }
         fileAdaptor.store(checkOutMap);
         InstanceUtilities.clearShellFlags(checkOutMap);
         // There are maybe more than selected instances after checking out
         List<GKInstance> checkedOut = new ArrayList<GKInstance>();
         for (Set<GKInstance> set : checkOutMap.values()) {
           checkedOut.addAll(set);
         }
         deleteList.deleteInstances(checkedOut);
         // deleteList.deleteInstances(list);
         // Need to clear out these deletion records
         List<Long> dbIds = new ArrayList<Long>();
         for (GKInstance inst : checkedOut) dbIds.add(inst.getDBID());
         fileAdaptor.clearDeleteRecord(dbIds);
         touchedList = deleteList;
       }
     }
   } catch (Exception e) {
     System.err.println("SynchronizationDialog.updateFromDB(): " + e);
     e.printStackTrace();
   }
   updateInstanceList(touchedList);
 }