Author: rodche
Date: 2010-01-27 18:16:22 -0800 (Wed, 27 Jan 2010)
New Revision: 19057

Added:
   
csplugins/trunk/toronto/rodche/BioPAX/src/cytoscape/coreplugins/biopax/util/ParentFinder.java
Modified:
   
csplugins/trunk/toronto/rodche/BioPAX/src/cytoscape/coreplugins/biopax/util/BioPaxUtil.java
Log:
Improved/optimized "parent finder" code

Modified: 
csplugins/trunk/toronto/rodche/BioPAX/src/cytoscape/coreplugins/biopax/util/BioPaxUtil.java
===================================================================
--- 
csplugins/trunk/toronto/rodche/BioPAX/src/cytoscape/coreplugins/biopax/util/BioPaxUtil.java
 2010-01-28 01:27:03 UTC (rev 19056)
+++ 
csplugins/trunk/toronto/rodche/BioPAX/src/cytoscape/coreplugins/biopax/util/BioPaxUtil.java
 2010-01-28 02:16:22 UTC (rev 19057)
@@ -39,14 +39,11 @@
 import cytoscape.logger.CyLogger;
 
 import org.biopax.paxtools.controller.EditorMap;
-import org.biopax.paxtools.controller.Fetcher;
 import org.biopax.paxtools.io.simpleIO.SimpleEditorMap;
 import org.biopax.paxtools.io.simpleIO.SimpleReader;
 import org.biopax.paxtools.model.BioPAXElement;
-import org.biopax.paxtools.model.BioPAXFactory;
 import org.biopax.paxtools.model.BioPAXLevel;
 import org.biopax.paxtools.model.Model;
-import org.biopax.paxtools.controller.PropertyEditor;
 import org.biopax.paxtools.model.level3.*;
 import org.biopax.paxtools.model.level2.*;
 import org.biopax.paxtools.util.ClassFilterSet;
@@ -779,7 +776,7 @@
 
        /**
         * For a BioPAX element, 
-        * find parent pathway or interaction name.
+        * find parent pathways names.
         * 
         * @param bpe
         * @param model 
@@ -791,13 +788,12 @@
                Set<? extends BioPAXElement> procs = 
BioPaxUtil.getObjects(model, pathway.class, Pathway.class);
                Set<BioPAXElement> pathways = fetchParentNodeNames(bpe, procs);
                
-               /*
-               if(pathways.isEmpty()) {
-                       procs = BioPaxUtil.getObjects(model, interaction.class, 
Interaction.class);
-                       pathways = fetchParentNodeNames(bpe, procs);
-               }
-               */
-               
+               //if(pathways.isEmpty()) {
+               //  // then find interactions
+               //      procs = BioPaxUtil.getObjects(model, interaction.class, 
Interaction.class);
+               //      pathways = fetchParentNodeNames(bpe, procs);
+               //}
+                               
                if(!pathways.isEmpty()) {
                        for(BioPAXElement pw : pathways) {
                                pathwayNames.add(getNodeName(pw));
@@ -820,42 +816,12 @@
         */
        public static Set<BioPAXElement> fetchParentNodeNames(BioPAXElement 
bpe, Set<? extends BioPAXElement> procs) {
                Set<BioPAXElement> parents = new HashSet<BioPAXElement>();
-               Fetcher fetcher;
-               BioPAXFactory factory;
-               /*
-                * Customized Fetcher is to fix the issue with Level2 - when 
NEXT-STEP
-                * leads out of the pathway... (do not worry - those pathway 
steps that
-                * are part of the pathway must be in the PATHWAY-COMPONENTS 
set)
-                * Also, skipping sub-pathways
-                */
-               if((bpe instanceof Level2Element)) {
-                       fetcher = new Fetcher(editorMapLevel2) 
-                       {
-                               public void visit(BioPAXElement bpe, Model 
model,
-                                       PropertyEditor editor) {
-                                       if 
(!editor.getProperty().equals("NEXT-STEP")) 
-                                       {
-                                               super.visit(bpe, model, editor);
-                                       }
-                               }
-                  };
-                  factory = BioPAXLevel.L2.getDefaultFactory();
-               } else if(bpe instanceof Level3Element) {
-                       fetcher = new Fetcher(editorMapLevel3);
-                       factory = BioPAXLevel.L3.getDefaultFactory(); 
-               } else {
-                       return parents;
-               }
-
+               EditorMap editorMap = (bpe instanceof Level2Element) ? 
editorMapLevel2 : editorMapLevel3;
+               ParentFinder parentFinder = new ParentFinder(editorMap);
                for (BioPAXElement proc : procs) {
-                       Model m = factory.createModel();
-                       fetcher.fetch(proc, m);
-                       //System.out.println(bpe + " " + bpe.getRDFId() + "; 
proc: " + proc + " " + proc.getModelInterface().getSimpleName() );
-                       if (m.containsID(bpe.getRDFId())) {
+                       if(!parents.contains(proc) && 
parentFinder.isParentChild(proc, bpe))
                                parents.add(proc);
-                       }
                }
-               
                return parents;
        }
        
@@ -974,4 +940,5 @@
 
         return (b1 != null && b1) || (b2 != null && b2);
        }
+       
 }
\ No newline at end of file

Added: 
csplugins/trunk/toronto/rodche/BioPAX/src/cytoscape/coreplugins/biopax/util/ParentFinder.java
===================================================================
--- 
csplugins/trunk/toronto/rodche/BioPAX/src/cytoscape/coreplugins/biopax/util/ParentFinder.java
                               (rev 0)
+++ 
csplugins/trunk/toronto/rodche/BioPAX/src/cytoscape/coreplugins/biopax/util/ParentFinder.java
       2010-01-28 02:16:22 UTC (rev 19057)
@@ -0,0 +1,53 @@
+package cytoscape.coreplugins.biopax.util;
+
+import org.biopax.paxtools.controller.AbstractTraverser;
+import org.biopax.paxtools.controller.EditorMap;
+import org.biopax.paxtools.controller.PropertyEditor;
+import org.biopax.paxtools.model.BioPAXElement;
+import org.biopax.paxtools.model.Model;
+
+/**
+ * 
+ * 
+ * @author rodch
+ *
+ */
+public final class ParentFinder extends AbstractTraverser {
+       private BioPAXElement query;
+       private boolean found;
+       
+       public ParentFinder(EditorMap editorMap) {
+               super(editorMap);
+       }
+
+       @Override
+       protected void visitValue(Object value, BioPAXElement parent, Model 
model,
+                       PropertyEditor editor) {
+               // skip if already found or it's not a object property
+               if(!found && value instanceof BioPAXElement 
+                               // explicit fix for the Level2: do not follow 
next steps...
+                               && !editor.getProperty().equals("NEXT-STEP")) {
+                       if(query.equals(value)) {
+                               found = true;
+                       } else {
+                               // continue into the value's values:
+                               traverse((BioPAXElement)value, model);
+                       }
+               }
+       }
+
+       /**
+        * True if the 'parent' element is in fact contains 'child'
+        * (recursively) 
+        * 
+        * @param parent
+        * @return
+        */
+       public boolean isParentChild(BioPAXElement parent, BioPAXElement child) 
{
+               query = child;
+               found = false;
+               run(parent, null);
+               return found;
+       }
+       
+}
\ No newline at end of file


Property changes on: 
csplugins/trunk/toronto/rodche/BioPAX/src/cytoscape/coreplugins/biopax/util/ParentFinder.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to