diff --git a/dist/PathSBML.jar_1.0.0.jar b/dist/PathSBML.jar_1.0.0.jar deleted file mode 100644 index 1617ddb..0000000 Binary files a/dist/PathSBML.jar_1.0.0.jar and /dev/null differ diff --git a/src/org/pathvisio/sbml/Activator.java b/src/org/pathvisio/sbml/Activator.java index de53ea5..6965ecd 100644 --- a/src/org/pathvisio/sbml/Activator.java +++ b/src/org/pathvisio/sbml/Activator.java @@ -1,6 +1,6 @@ -// PathVisio, -// a tool for data visualization and analysis using Biological Pathways -// Copyright 2006-2014 BiGCaT Bioinformatics +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/org/pathvisio/sbml/BioModelPanel.java b/src/org/pathvisio/sbml/BioModelPanel.java index a191da3..abc037f 100644 --- a/src/org/pathvisio/sbml/BioModelPanel.java +++ b/src/org/pathvisio/sbml/BioModelPanel.java @@ -1,6 +1,6 @@ -// PathVisio, -// a tool for data visualization and analysis using Biological Pathways -// Copyright 2006-2009 BiGCaT Bioinformatics +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,6 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // + package org.pathvisio.sbml; import java.awt.Component; @@ -49,6 +50,7 @@ import javax.swing.SwingWorker; import javax.swing.border.Border; import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; import org.pathvisio.core.debug.Logger; @@ -67,6 +69,7 @@ * @author anwesha * @version 1.0.0 */ +@SuppressWarnings("serial") public class BioModelPanel extends JPanel { SBMLPlugin plugin; @@ -74,7 +77,7 @@ public class BioModelPanel extends JPanel { static Border etch = BorderFactory.createEtchedBorder(); private JComboBox clientDropdown; private JTable resultTable; - private JScrollPane resultspane; + JScrollPane resultspane; private JRadioButton Browse; private JRadioButton All; @@ -90,6 +93,9 @@ public class BioModelPanel extends JPanel { private JTextField taxonomyId; private JButton search; + /** + * @param plugin + */ public BioModelPanel(final SBMLPlugin plugin) { this.plugin = plugin; @@ -114,13 +120,13 @@ public BioModelPanel(final SBMLPlugin plugin) { group2.add(NonCurated); // biomodel search terms - bioModelName = new JTextField(); - chebiId = new JTextField(); - uniprotId = new JTextField(); - pubTitId = new JTextField(); - personName = new JTextField(); - goId = new JTextField(); - taxonomyId = new JTextField(); + setBioModelName(new JTextField()); + setChebiId(new JTextField()); + setUniprotId(new JTextField()); + setPubTitId(new JTextField()); + setPersonName(new JTextField()); + setGoId(new JTextField()); + setTaxonomyId(new JTextField()); //tooltips for browse buttons and search choice button All.setToolTipText("Browse all submitted models at Biomodels"); @@ -130,13 +136,13 @@ public BioModelPanel(final SBMLPlugin plugin) { Search.setToolTipText("Choose to browse models in Biomodels"); //tooltips for all the search boxes - bioModelName.setToolTipText("Tip:Use Biomodel name (e.g.:'Tyson1991 - Cell Cycle 6 var')"); - pubTitId.setToolTipText("Tip:Use publication name(e.g.:'sbml')"); - chebiId.setToolTipText("Tip:Use Chebi id (e.g.:'24996')"); - personName.setToolTipText("Tip:Use person/encoder name (e.g.:'Rainer','Nicolas')"); - uniprotId.setToolTipText("Tip:Use Uniprot id (e.g.:'P04637','P10113')"); - goId.setToolTipText("Tip:Use GO id (e.g.:'0006915')"); - taxonomyId.setToolTipText("Tip:Use Taxonomy id (e.g.:'9606')"); + getBioModelName().setToolTipText("Tip:Use Biomodel name (e.g.:'Tyson1991 - Cell Cycle 6 var')"); + getPubTitId().setToolTipText("Tip:Use publication name(e.g.:'sbml')"); + getChebiId().setToolTipText("Tip:Use Chebi id (e.g.:'24996')"); + getPersonName().setToolTipText("Tip:Use person/encoder name (e.g.:'Rainer','Nicolas')"); + getUniprotId().setToolTipText("Tip:Use Uniprot id (e.g.:'P04637','P10113')"); + getGoId().setToolTipText("Tip:Use GO id (e.g.:'0006915')"); + getTaxonomyId().setToolTipText("Tip:Use Taxonomy id (e.g.:'9606')"); // browse biomodel action Action browseBioModelAction = new AbstractAction("browseBioModels") { @@ -242,37 +248,37 @@ public void actionPerformed(ActionEvent e) { cc2.gridx = 1; cc2.gridy = 0; cc2.gridwidth =2; - searchOptBox.add(bioModelName, cc2); + searchOptBox.add(getBioModelName(), cc2); cc2.fill = GridBagConstraints.HORIZONTAL; cc2.gridx = 1; cc2.gridy = 1; cc2.gridwidth =2; - searchOptBox.add(pubTitId,cc2); + searchOptBox.add(getPubTitId(),cc2); cc2.fill = GridBagConstraints.HORIZONTAL; cc2.gridx = 1; cc2.gridy = 2; cc2.gridwidth =2; - searchOptBox.add(chebiId,cc2); + searchOptBox.add(getChebiId(),cc2); cc2.fill = GridBagConstraints.HORIZONTAL; cc2.gridx = 1; cc2.gridy = 3; cc2.gridwidth =2; - searchOptBox.add(personName,cc2); + searchOptBox.add(getPersonName(),cc2); cc2.fill = GridBagConstraints.HORIZONTAL; cc2.gridx = 1; cc2.gridy = 4; cc2.gridwidth =2; - searchOptBox.add(uniprotId,cc2); + searchOptBox.add(getUniprotId(),cc2); cc2.fill = GridBagConstraints.HORIZONTAL; cc2.gridx = 1; cc2.gridy = 5; cc2.gridwidth =2; - searchOptBox.add(goId,cc2); + searchOptBox.add(getGoId(),cc2); cc2.fill = GridBagConstraints.HORIZONTAL; cc2.gridx = 1; cc2.gridy = 6; cc2.gridwidth =2; - searchOptBox.add(taxonomyId,cc2); + searchOptBox.add(getTaxonomyId(),cc2); cc2.fill = GridBagConstraints.HORIZONTAL; cc2.gridx = 1; cc2.gridy = 7; @@ -414,7 +420,8 @@ public void mouseClicked(MouseEvent e) { * @throws InterruptedException * @throws ExecutionException */ - private void browse(final String command) throws RemoteException, InterruptedException, + void browse(final String command) throws RemoteException, + InterruptedException, ExecutionException { String clientName = clientDropdown.getSelectedItem().toString(); @@ -506,7 +513,7 @@ else if(pk.isCancelled()) resultTable.setModel(new ResultTableModel(sw.get(), clientName)); resultTable - .setRowSorter(new TableRowSorter(resultTable.getModel())); + .setRowSorter(new TableRowSorter(resultTable.getModel())); } @@ -517,17 +524,17 @@ else if(pk.isCancelled()) * @throws InterruptedException * @throws ExecutionException */ - private void search() throws RemoteException, InterruptedException, + void search() throws RemoteException, InterruptedException, ExecutionException { // search terms typed in the search boxes are trimmed and stored in the following respective variables. - final String sbmlName = bioModelName.getText().trim(); - final String sbmlPub = pubTitId.getText().trim(); - final String sbmlChebi = chebiId.getText().trim(); - final String sbmlPerson = personName.getText().trim(); - final String sbmlUniprot = uniprotId.getText().trim(); - final String sbmlGo = goId.getText().trim(); - final String sbmlTaxonomy = taxonomyId.getText().trim(); + final String sbmlName = getBioModelName().getText().trim(); + final String sbmlPub = getPubTitId().getText().trim(); + final String sbmlChebi = getChebiId().getText().trim(); + final String sbmlPerson = getPersonName().getText().trim(); + final String sbmlUniprot = getUniprotId().getText().trim(); + final String sbmlGo = getGoId().getText().trim(); + final String sbmlTaxonomy = getTaxonomyId().getText().trim(); if (!(sbmlPub.isEmpty()&&sbmlName.isEmpty()&&sbmlChebi.isEmpty()&&sbmlPerson.isEmpty()&&sbmlUniprot.isEmpty()&&sbmlGo.isEmpty()&&sbmlTaxonomy.isEmpty())) { String clientName = clientDropdown.getSelectedItem().toString(); @@ -552,7 +559,7 @@ protected String[] doInBackground() throws Exception { String[] results7 = null; try { // getting the models id by name. - if(!bioModelName.getText().equalsIgnoreCase("")) + if(!getBioModelName().getText().equalsIgnoreCase("")) { results1 = client.getModelsIdByName(sbmlName); @@ -565,7 +572,7 @@ protected String[] doInBackground() throws Exception { } //getting the models id by publication title or id. - if(!pubTitId.getText().equalsIgnoreCase("")) + if(!getPubTitId().getText().equalsIgnoreCase("")) { results2= client.getModelsIdByPublication(sbmlPub); if(results2!=null){ @@ -577,7 +584,7 @@ protected String[] doInBackground() throws Exception { } //getting models id by chebi id. - if(!chebiId.getText().equalsIgnoreCase("")) + if(!getChebiId().getText().equalsIgnoreCase("")) { results3= client.getModelsIdByChEBIId(sbmlChebi); if(results3!=null){ @@ -589,7 +596,7 @@ protected String[] doInBackground() throws Exception { } //getting models id by person or encoder or author name. - if(!personName.getText().equalsIgnoreCase("")) + if(!getPersonName().getText().equalsIgnoreCase("")) { results4= client.getModelsIdByPerson(sbmlPerson); if(results4!=null){ @@ -601,7 +608,7 @@ protected String[] doInBackground() throws Exception { } //getting models id by uniprot id. - if(!uniprotId.getText().equalsIgnoreCase("")) + if(!getUniprotId().getText().equalsIgnoreCase("")) { results5= client.getModelsIdByUniprot(sbmlUniprot); if(results5!=null){ @@ -613,7 +620,7 @@ protected String[] doInBackground() throws Exception { } //getting models id by go id. - if(!goId.getText().equalsIgnoreCase("")) + if(!getGoId().getText().equalsIgnoreCase("")) { results6 = client.getModelsIdByGOId(sbmlGo); @@ -626,7 +633,7 @@ protected String[] doInBackground() throws Exception { } //getting models id by taxonomy id. - if(!taxonomyId.getText().equalsIgnoreCase("")) + if(!getTaxonomyId().getText().equalsIgnoreCase("")) { results7 = client.getModelsIdByTaxonomyId(sbmlTaxonomy); @@ -675,7 +682,7 @@ else if(pk.isCancelled()) resultTable.setModel(new ResultTableModel(sw.get(), clientName)); resultTable - .setRowSorter(new TableRowSorter(resultTable.getModel())); + .setRowSorter(new TableRowSorter(resultTable.getModel())); } else { JOptionPane.showMessageDialog(null, "Please Enter a Search Query", "ERROR", JOptionPane.ERROR_MESSAGE); @@ -683,7 +690,7 @@ else if(pk.isCancelled()) } //enable search - private void enableFrame(JPanel container, boolean enable) { + void enableFrame(JPanel container, boolean enable) { Component[] components = container.getComponents(); for (Component component : components) { component.setEnabled(enable); @@ -692,6 +699,97 @@ private void enableFrame(JPanel container, boolean enable) { } } } + /** + * @return the pubTitId + */ + public JTextField getPubTitId() { + return pubTitId; + } + + /** + * @param pubTitId the pubTitId to set + */ + public void setPubTitId(JTextField pubTitId) { + this.pubTitId = pubTitId; + } + /** + * @return the bioModelName + */ + public JTextField getBioModelName() { + return bioModelName; + } + + /** + * @param bioModelName the bioModelName to set + */ + public void setBioModelName(JTextField bioModelName) { + this.bioModelName = bioModelName; + } + /** + * @return the chebiId + */ + public JTextField getChebiId() { + return chebiId; + } + + /** + * @param chebiId the chebiId to set + */ + public void setChebiId(JTextField chebiId) { + this.chebiId = chebiId; + } + /** + * @return the personName + */ + public JTextField getPersonName() { + return personName; + } + + /** + * @param personName the personName to set + */ + public void setPersonName(JTextField personName) { + this.personName = personName; + } + /** + * @return the goId + */ + public JTextField getGoId() { + return goId; + } + + /** + * @param goId the goId to set + */ + public void setGoId(JTextField goId) { + this.goId = goId; + } + /** + * @return the taxonomyId + */ + public JTextField getTaxonomyId() { + return taxonomyId; + } + + /** + * @param taxonomyId the taxonomyId to set + */ + public void setTaxonomyId(JTextField taxonomyId) { + this.taxonomyId = taxonomyId; + } + /** + * @return the uniprotId + */ + public JTextField getUniprotId() { + return uniprotId; + } + + /** + * @param uniprotId the uniprotId to set + */ + public void setUniprotId(JTextField uniprotId) { + this.uniprotId = uniprotId; + } /** * This class creates the result table model * based on the results. diff --git a/src/org/pathvisio/sbml/DocumentPanel.java b/src/org/pathvisio/sbml/DocumentPanel.java index 8152953..20b64f5 100644 --- a/src/org/pathvisio/sbml/DocumentPanel.java +++ b/src/org/pathvisio/sbml/DocumentPanel.java @@ -1,6 +1,6 @@ -// PathVisio, -// a tool for data visualization and analysis using Biological Pathways -// Copyright 2006-2014 BiGCaT Bioinformatics +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ // See the License for the specific language governing permissions and // limitations under the License. // + package org.pathvisio.sbml; import java.awt.BorderLayout; -import java.awt.Desktop; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -28,11 +28,8 @@ import javax.swing.tree.TreeModel; import org.pathvisio.core.ApplicationEvent; -import org.pathvisio.core.ApplicationEvent.Type; import org.pathvisio.core.Engine; import org.pathvisio.core.Engine.ApplicationEventListener; -import org.pathvisio.gui.SwingEngine; -import org.sbml.jsbml.SBMLDocument; /** * This class adds action to the SBML side pane. @@ -45,18 +42,20 @@ * @version 1.0.0 * */ -public class DocumentPanel extends JPanel implements ApplicationEventListener { - private SBMLDocument lastImported = null; - Engine engine; - Desktop desktop; - private JScrollPane treePane = new JScrollPane(); +public class DocumentPanel extends JPanel implements ApplicationEventListener +{ + // private SBMLDocument lastImported = null; + // Desktop desktop; + JScrollPane treePane = new JScrollPane(); private final ExecutorService executor; - public DocumentPanel(SwingEngine eng) { + // SBMLDocument document; + + public DocumentPanel(Engine engine) { setLayout(new BorderLayout()); treePane = new JScrollPane(new JTree(SBMLFormat.modelDoc)); add(treePane); - eng.getEngine().addApplicationEventListener(this); + engine.addApplicationEventListener(this); executor = Executors.newSingleThreadExecutor(); } @@ -67,27 +66,26 @@ public DocumentPanel(SwingEngine eng) { */ @Override public void applicationEvent(ApplicationEvent e) { - if (e.getType() == Type.PATHWAY_NEW) { + switch(e.getType()) { + case PATHWAY_NEW: clean(); - } - if (e.getType() == Type.PATHWAY_OPENED) - - { - setInput(SBMLFormat.modelDoc); - + break; + case PATHWAY_OPENED: + doQuery(); + break; } } - /** - * This method is invoked in the applicationEvent if a new model is opened - * - * @param modelDoc - */ - private void setInput(SBMLDocument doc) { - lastImported = doc; - doQuery(); - } + // /** + // * This method is invoked in the applicationEvent if a new model is opened + // * + // * @param modelDoc + // */ + // private void setInput() { + // // lastImported = doc; + // doQuery(); + // } /** * This method is invoked by the setInput function. @@ -96,11 +94,10 @@ private void setInput(SBMLDocument doc) { * */ private void doQuery() { - executor.execute(new Runnable() { @Override public void run() { - if (lastImported == null) + if (SBMLFormat.modelDoc == null) return; SwingUtilities.invokeLater(new Runnable() { @@ -113,6 +110,8 @@ public void run() { elementTree.setModel(elementModel); treePane = new JScrollPane(elementTree); add(treePane); + revalidate(); + repaint(); } }); } @@ -129,10 +128,13 @@ public void run() { @Override public void run() { remove(treePane); + revalidate(); + repaint(); } }); } }); } + } \ No newline at end of file diff --git a/src/org/pathvisio/sbml/JSBMLvisualizer.java b/src/org/pathvisio/sbml/JSBMLvisualizer.java index 935ae9b..16682e5 100644 --- a/src/org/pathvisio/sbml/JSBMLvisualizer.java +++ b/src/org/pathvisio/sbml/JSBMLvisualizer.java @@ -1,19 +1,20 @@ -// PathVisio, -// a tool for data visualization and analysis using Biological Pathways -// Copyright 2006-2009 BiGCaT Bioinformatics +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and // limitations under the License. // + package org.pathvisio.sbml; import java.awt.Component; @@ -24,11 +25,11 @@ import org.sbml.jsbml.SBMLDocument; -/** Displays the content of an SBML file in a {@link JTree} +/** Displays the content of an SBML file in a {@link JTree} *

* Derived from org.sbml.jsbml.test.gui.JSBMLvisualizer, with significant changes. */ -public class JSBMLvisualizer extends JFrame +public class JSBMLvisualizer extends JFrame { /** @param document The sbml root node of an SBML file */ @@ -37,11 +38,11 @@ public JSBMLvisualizer(SBMLDocument document) { getContentPane().add(new JScrollPane(new JTree(document))); pack(); } - + public void createAndShow (Component parent) { setLocationRelativeTo(parent); setVisible(true); } - + } \ No newline at end of file diff --git a/src/org/pathvisio/sbml/LayoutAbstract.java b/src/org/pathvisio/sbml/LayoutAbstract.java index 1d7145d..00e282c 100644 --- a/src/org/pathvisio/sbml/LayoutAbstract.java +++ b/src/org/pathvisio/sbml/LayoutAbstract.java @@ -1,3 +1,19 @@ +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// package org.pathvisio.sbml; @@ -217,8 +233,6 @@ private String getSpecies(String graphId) { protected String getReaction(String graphId) { for (PathwayElement pe : pwy.getDataObjects()){ if (pe.getObjectType().equals(ObjectType.LINE) ){ - System.out.println(pe - .getDynamicProperty(SbgnFormat.PROPERTY_SBGN_IS_PORT)); if (("true".equals (pe.getDynamicProperty(SbgnFormat.PROPERTY_SBGN_IS_PORT)))) { if(pe.getMAnchors().get(0).getGraphId().equalsIgnoreCase(graphId)) diff --git a/src/org/pathvisio/sbml/NavigationTree.java b/src/org/pathvisio/sbml/NavigationTree.java index 1c17bd3..66f8a86 100644 --- a/src/org/pathvisio/sbml/NavigationTree.java +++ b/src/org/pathvisio/sbml/NavigationTree.java @@ -1,19 +1,20 @@ -// PathVisio, -// a tool for data visualization and analysis using Biological Pathways -// Copyright 2006-2009 BiGCaT Bioinformatics +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and // limitations under the License. // + package org.pathvisio.sbml; import java.util.HashMap; @@ -22,6 +23,7 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; + import org.sbml.jsbml.Compartment; import org.sbml.jsbml.ListOf; import org.sbml.jsbml.Model; @@ -30,7 +32,7 @@ import org.sbml.jsbml.SBMLDocument; import org.sbml.jsbml.Species; /** - * This class helps to visualize the components of the SBML document in the + * This class helps to visualize the components of the SBML document in the * tree model format. * @author applecool * @@ -39,8 +41,8 @@ public class NavigationTree { public static final String COMPARTMENTS = "Compartments"; public static final String SPECIES = "Species"; public static final String REACTIONS = "Reactions"; - private Map objectMap; - private Map objectPathMap; + private final Map objectMap; + private final Map objectPathMap; private DefaultTreeModel treeModel; public Map getObjectMap() { @@ -62,7 +64,7 @@ public NavigationTree() { this.treeModel = new DefaultTreeModel( new DefaultMutableTreeNode("sbml")); } - + /** * * @param document @@ -82,12 +84,11 @@ public NavigationTree(SBMLDocument document) { public NamedSBase getNamedSBaseById(String id) { NamedSBase nsb = null; - if (this.objectMap.containsKey(id)) { - return (NamedSBase) this.objectMap.get(id); - } + if (this.objectMap.containsKey(id)) + return this.objectMap.get(id); return nsb; } - + /** * This method adds the list of components to the tree model. * @@ -99,7 +100,7 @@ private void addListOfCompartmentsToTreeModel(DefaultMutableTreeNode top, addListOfNamedSBaseToTreeModel(top, createTreeNodeForName("Compartments"), compartmentList); } - + /** * This method adds the list of species to the tree model. * @param top @@ -110,7 +111,7 @@ private void addListOfSpeciesToTreeModel(DefaultMutableTreeNode top, addListOfNamedSBaseToTreeModel(top, createTreeNodeForName("Species"), speciesList); } - + /** * This methods adds the list of reactions to the tree model. * @param top @@ -121,7 +122,7 @@ private void addListOfReactionsToTreeModel(DefaultMutableTreeNode top, addListOfNamedSBaseToTreeModel(top, createTreeNodeForName("Reactions"), reactionList); } - + /** * This method adds the list of namedSbase to the tree model. * @param top @@ -144,7 +145,7 @@ private void addListOfNamedSBaseToTreeModel(DefaultMutableTreeNode top, } } } - + /** * This method creates a tree node with the name which will be SBML model name in general. * @@ -154,7 +155,7 @@ private void addListOfNamedSBaseToTreeModel(DefaultMutableTreeNode top, private DefaultMutableTreeNode createTreeNodeForName(String name) { return new DefaultMutableTreeNode(name, true); } - + /** * This method gets the name of the model which is imported. * @param model diff --git a/src/org/pathvisio/sbml/Prefuse.java b/src/org/pathvisio/sbml/Prefuse.java index fbc9a10..942d2d1 100644 --- a/src/org/pathvisio/sbml/Prefuse.java +++ b/src/org/pathvisio/sbml/Prefuse.java @@ -1,3 +1,19 @@ +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// package org.pathvisio.sbml; @@ -5,8 +21,10 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; + import org.pathvisio.core.model.PathwayElement; import org.pathvisio.gui.SwingEngine; + import prefuse.action.layout.graph.ForceDirectedLayout; import prefuse.util.force.DragForce; import prefuse.util.force.ForceItem; @@ -21,7 +39,7 @@ * */ public class Prefuse extends LayoutAbstract{ - + public int numIterations = 100; public float defaultSpringCoefficient = 1e-4f; public float defaultSpringLength = 100.0f; @@ -47,33 +65,33 @@ public Prefuse(SwingEngine swingEngine, boolean selection){ item.location[1] = (float) pe.getMCenterY(); nodes.put(pe.getGraphId(),item); f.addItem(item); - + } - - + + for (PathwayElement pe: pwyLines){ String start="",end=""; if( pwy.getElementById(pe.getStartGraphRef())==null ) { - start =(getReaction(pe.getStartGraphRef())); + start =(getReaction(pe.getStartGraphRef())); }else{ - start=pe.getStartGraphRef(); + start=pe.getStartGraphRef(); } if( pwy.getElementById(pe.getEndGraphRef())==null ) { - end =(getReaction(pe.getEndGraphRef())); + end =(getReaction(pe.getEndGraphRef())); } else{ end=pe.getEndGraphRef(); } - + float springLength = pythagoras(pwy.getElementById(start).getMWidth()/2, pwy.getElementById(start).getMHeight()/2) + pythagoras(pwy.getElementById(end).getMWidth()/2,pwy.getElementById(end).getMHeight()/2); f.addSpring(nodes.get(start), nodes.get(end), defaultSpringCoefficient, springLength); } - - - + + + l.setForceSimulator(f); long timestep = 1000L; for (int i=0;i MODEL_FORMAT_ONLY = Utils .setOf((PathwayIO) new SBMLFormat(this)); - private final File tmpDir = new File(GlobalPreference.getPluginDir(), "models-cache"); + final File tmpDir = new File(GlobalPreference.getPluginDir(), + "models-cache"); private final ValidateAction validateAction = new ValidateAction(); @@ -92,10 +85,14 @@ public class SBMLPlugin implements Plugin { private final ImportModelAction importmodelAction = new ImportModelAction(); + // private final ExportModelAction exportmodelAction = new + // ExportModelAction(); + private final BioModelsAction biomodelAction = new BioModelsAction(); - private final Map clients = new HashMap(); + final Map clients = new HashMap(); + @SuppressWarnings("serial") private class BioModelsAction extends AbstractAction { BioModelsAction() { @@ -144,8 +141,9 @@ public void actionPerformed(ActionEvent arg0) { } } + /** - * @author anwesha + * * */ public static enum PlPreference implements Preference { @@ -189,6 +187,7 @@ public String getDefault() { * @author applecool * */ + @SuppressWarnings("serial") private class ValidateAction extends AbstractAction { ValidateAction() { @@ -197,7 +196,7 @@ private class ValidateAction extends AbstractAction { @Override public void actionPerformed(ActionEvent arg0) { - System.out.println("here"); + ValidatePanel vp = new ValidatePanel(SBMLPlugin.this); JDialog d = new JDialog(desktop.getFrame(), "Validate"); d.getContentPane().add(vp); @@ -208,6 +207,8 @@ public void actionPerformed(ActionEvent arg0) { } } + + @SuppressWarnings("serial") private class ImportModelAction extends AbstractAction { ImportModelAction() { @@ -232,16 +233,41 @@ public void actionPerformed(ActionEvent arg0) { } } + @SuppressWarnings("serial") + private class ExportModelAction extends AbstractAction { - public static String shortClientName(String clientName) { + ExportModelAction() { + putValue(NAME, "Export"); + } + + @Override + public void actionPerformed(ActionEvent arg0) { + modelChooser = new JFileChooser( + GlobalPreference.DIR_LAST_USED_IMPORT.toString()); + modelChooser.setVisible(true); + // filtering the files based on their extensions. + FileNameExtensionFilter filter = new FileNameExtensionFilter( + "SBML(Systems Biology Markup Language) (.sbml,.xml)", + "sbml", "xml"); + modelChooser.setFileFilter(filter); + int returnVal = modelChooser.showOpenDialog(desktop + .getSwingEngine().getApplicationPanel()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = modelChooser.getSelectedFile(); + desktop.getSwingEngine().exportPathway(file); + } + } + } + protected static String shortClientName(String clientName) { Pattern pattern = Pattern.compile("http://(.*?)/"); - Matcher matcher = pattern.matcher(clientName); + String clientName2 = clientName; + Matcher matcher = pattern.matcher(clientName2); if (matcher.find()) { - clientName = matcher.group(1); + clientName2 = matcher.group(1); } - return clientName; + return clientName2; } @@ -250,69 +276,38 @@ public static String shortClientName(String clientName) { * @author anwesha */ public void createSbmlMenu() { - exportmenu = new JMenu("A submenu"); sbmlmenu = new JMenu("SBML Plugin"); + // egModel = new JMenuItem("Open Example Model"); sbmlImport = new JMenuItem("Import Local Model"); biomodels = new JMenuItem("Import Biomodel.org Model"); layout = new JMenuItem("Force Directed Layout"); validate = new JMenuItem("Validate"); - sbmlExport = new JMenuItem("Export Model"); - // asSBML = new JMenuItem("SBML"); - // asGPML = new JMenuItem("GPML"); - // asPNG = new JMenuItem("PNG"); - // asSVG = new JMenuItem("SVG"); - // asTIFF = new JMenuItem("TIFF"); - // asPDF = new JMenuItem("PDF"); - - // asSBML.addActionListener(actions.exportAction); - // asGPML.addActionListener(actions.exportAction); - // asPNG.addActionListener(actions.exportAction); - // asSVG.addActionListener(actions.exportAction); - // asTIFF.addActionListener(actions.exportAction); - // asPDF.addActionListener(actions.exportAction); - - // sbmlExport.add(asSBML); - // sbmlExport.add(asGPML); - // sbmlExport.add(asPNG); - // sbmlExport.add(asSVG); - // sbmlExport.add(asPDF); - // sbmlExport.add(asTIFF); - - // sbmlImport - // .addActionListener(desktop.getSwingEngine().getActions().importAction); + + sbmlImport.addActionListener(importmodelAction); biomodels.addActionListener(biomodelAction); layout.addActionListener(layoutAction); validate.addActionListener(validateAction); - sbmlExport - .addActionListener(desktop.getSwingEngine().getActions().exportAction); + // sbmlExport.addActionListener(exportmodelAction); + // sbmlmenu.add(egModel); sbmlmenu.add(sbmlImport); sbmlmenu.add(biomodels); sbmlmenu.add(layout); sbmlmenu.add(validate); - sbmlmenu.add(sbmlExport); + // sbmlmenu.add(sbmlExport); desktop.registerSubMenu("Plugins", sbmlmenu); } - @Override - public void done() { - desktop.getSideBarTabbedPane().remove(sbmlPanel); - - desktop.unregisterSubMenu("Plugins", sbmlmenu); - if(tmpDir.exists()) { - tmpDir.delete(); - } - } - public Map getClients() { + protected Map getClients() { return clients; } - public File getTmpDir() { + protected File getTmpDir() { return tmpDir; } @@ -326,15 +321,16 @@ public void init(PvDesktop desktop) { this.desktop = desktop; // register importer / exporter - SBMLFormat sbmlFormat = new SBMLFormat(this); - desktop.getSwingEngine().getEngine().addPathwayExporter(sbmlFormat); - desktop.getSwingEngine().getEngine().addPathwayImporter(sbmlFormat); + sbmlformat = new SBMLFormat(this); + // desktop.getSwingEngine().getEngine().addPathwayExporter(sbmlformat); + desktop.getSwingEngine().getEngine().addPathwayImporter(sbmlformat); // register menu items createSbmlMenu(); // add new SBML side pane - DocumentPanel pane = new DocumentPanel(desktop.getSwingEngine()); + DocumentPanel pane = new DocumentPanel(desktop.getSwingEngine() + .getEngine()); JTabbedPane sidebarTabbedPane = desktop.getSideBarTabbedPane(); sbmlPanel = sidebarTabbedPane.add("SBML", pane); @@ -350,8 +346,7 @@ public void init(PvDesktop desktop) { } } - private void loadClient() throws MalformedURLException, ServiceException, - BioModelsWSException { + private void loadClient() { BioModelsWSClient client = new BioModelsWSClient(); clients.put( "http://www.ebi.ac.uk/biomodels-main/services/BioModelsWebServices?wsdl", @@ -359,40 +354,48 @@ private void loadClient() throws MalformedURLException, ServiceException, } - protected void openPathway(BioModelsWSClient client, String id, int rev, - File tmpDir) throws ConverterException, BioModelsWSException, + private void openPathway(BioModelsWSClient client, String id, File tmpDir) + throws + BioModelsWSException, IOException { - String p = client.getModelSBMLById(id); - File tmp = new File(tmpDir, id + ".xml"); + File tmp = new File(tmpDir, id + ".sbml"); BufferedWriter output = new BufferedWriter(new FileWriter(tmp)); output.write(p.toString()); output.close(); - SBMLDocument doc; try { - doc = new SBMLReader().readSBML(tmp.getAbsolutePath()); - PeerModel br = PeerModel.createFromDoc(doc, tmp); - Pathway pw = br.getPathway(); + Pathway pw = sbmlformat.doImport(tmp); - File tmp2 = new File(tmpDir, id + ".xml"); + File tmp2 = new File(tmpDir, id + ".sbml"); pw.writeToXml(tmp2, true); Engine engine = desktop.getSwingEngine().getEngine(); engine.setWrapper(desktop.getSwingEngine().createWrapper()); - SBMLFormat.modelDoc = doc; engine.openPathway(tmp2); - } catch (XMLStreamException e) { - e.printStackTrace(); + } catch (Exception e) { + JOptionPane.showMessageDialog(null, + "The model file can't be imported!", + "Unsupported model file", + JOptionPane.ERROR_MESSAGE); } } + /** + * @param client + * @param id + * @param rev + * @param tmpDir + * @throws InterruptedException + * @throws ExecutionException + */ public void openPathwayWithProgress(final BioModelsWSClient client, final String id, final int rev, final File tmpDir) throws InterruptedException, ExecutionException { + final ProgressKeeper pk = new ProgressKeeper(); final ProgressDialog d = new ProgressDialog( JOptionPane.getFrameForComponent(desktop.getSwingEngine() @@ -403,12 +406,12 @@ public void openPathwayWithProgress(final BioModelsWSClient client, protected Boolean doInBackground() throws Exception { pk.setTaskName("Opening Model"); try { - openPathway(client, id, rev, tmpDir); + openPathway(client, id, tmpDir); } catch (Exception e) { Logger.log.error("The Model is not found", e); JOptionPane.showMessageDialog(null, - "The Pathway is not found", "ERROR", + "The Model is not found", "ERROR", JOptionPane.ERROR_MESSAGE); } finally { pk.finished(); @@ -422,14 +425,42 @@ protected Boolean doInBackground() throws Exception { sw.get(); } - /** - * This method is called in the SBMLFormat.java This method sets the - * imported document to the lastImported variable. - * - * @param document - */ - public void setLastImported(SBMLDocument document) { + // /** + // * This method is called in the SBMLFormat.java This method sets the + // * imported document to the lastImported variable. + // * + // * @param sbmlDocument + // */ + // public void setLastImported(SBMLDocument sbmlDocument) { + // last_model_imported = sbmlDocument; + // } + + + @Override + public void done() { + /* + * Remove sidebar + */ + desktop.getSideBarTabbedPane().remove(sbmlPanel); + /* + * Unregister menu + */ + desktop.unregisterSubMenu("Plugins", sbmlmenu); + /* + * Delete cache even if not empty and contains non-empty sub folders + */ + if(tmpDir.exists()) { + for (File file : tmpDir.listFiles()) { + if (file.isDirectory()) { + for (File file2 : file.listFiles()) { + file2.delete(); + } + } + file.delete(); + } + tmpDir.delete(); + } } } diff --git a/src/org/pathvisio/sbml/SbmlExportHelper.java b/src/org/pathvisio/sbml/SbmlExportHelper.java index 8de5823..10a79e5 100644 --- a/src/org/pathvisio/sbml/SbmlExportHelper.java +++ b/src/org/pathvisio/sbml/SbmlExportHelper.java @@ -1,26 +1,43 @@ +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + package org.pathvisio.sbml; import java.io.File; import java.io.IOException; - import java.util.HashMap; - - import java.util.Map; +import javax.swing.JOptionPane; import javax.xml.stream.XMLStreamException; - +import org.bridgedb.Xref; import org.pathvisio.core.model.ConverterException; import org.pathvisio.core.model.ObjectType; import org.pathvisio.core.model.Pathway; import org.pathvisio.core.model.PathwayElement; import org.pathvisio.sbgn.SbgnFormat; - import org.sbgn.ArcClazz; import org.sbgn.GlyphClazz; +import org.sbml.jsbml.Annotation; +import org.sbml.jsbml.CVTerm; import org.sbml.jsbml.ListOf; import org.sbml.jsbml.Model; +import org.sbml.jsbml.Reaction; import org.sbml.jsbml.SBMLDocument; import org.sbml.jsbml.SBMLException; import org.sbml.jsbml.SBMLWriter; @@ -29,195 +46,339 @@ -public class SbmlExportHelper -{ +public class SbmlExportHelper { + private SBMLPlugin sib; + /** + * @throws ConverterException + */ + public void doExport() { + /* + * Only export if all interactions are connected + */ + if (testInteractionConnectivity()) { + + makePorts(); + for (PathwayElement elt : pathway.getDataObjects()) { + addSpeciesReferences(elt); + + } + for (PathwayElement elt : pathway.getDataObjects()) { + sbgn2sbml(elt); + + } + + // createfromPathway(); + + SBMLDocument doc = new SBMLDocument(); + + doc.setLevel(Integer.parseInt(pathway.getMappInfo() + .getDynamicProperty("SBML_Level"))); + doc.setVersion(Integer.parseInt(pathway.getMappInfo() + .getDynamicProperty("SBML_Version"))); + doc.setModel(doModel()); + + try { + SBMLWriter w = new SBMLWriter(); + + w.writeSBMLToFile(doc, file.getAbsolutePath()); + } catch (SBMLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (XMLStreamException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + JOptionPane.showMessageDialog(null, + "Unconnected interactions found! Model cannot be exported"); + } + } + + + private final Pathway pathway; private final File file; - - private Map portmatrix = new HashMap(); - private Map reactionmatrix = new HashMap(); + private boolean UpdatingSbml = false; + + private final Map portmatrix = new HashMap(); + private final Map reactionmatrix = new HashMap(); ListOf listOfSpeciesReferences = new ListOf(); ListOf listOfSpecies = new ListOf(); - private ListOf listOfReactions = new ListOf(); + private final ListOf listOfReactions = new ListOf(); - SbmlExportHelper (Pathway pathway, File file) - { + SbmlExportHelper(File file, Pathway pathway) { this.pathway = pathway; - this.file = file; + this.file = file; } - - public void doExport() throws ConverterException - { - - makePorts(); - for (PathwayElement elt : pathway.getDataObjects()) - { - addSpeciesReferences(elt); - + private void addReactions(PathwayElement elt) { + Reaction r = new Reaction(); + r.setId(elt.getGraphId()); + for (Map.Entry entry : reactionmatrix.entrySet()) { + System.out.println("Reaction : " + entry); + String[] s = entry.getKey().split("-", 3); + if (s[2].equalsIgnoreCase("2")) { + System.out.println("s2 = " + s[2]); + if (elt.getGraphId().equals(s[0])) { + System.out.println("graphid = " + s[0]); + SpeciesReference sr = r.createReactant(); + try { + sr.setSpecies(new Species(s[1])); + } catch (NullPointerException ne) { + System.err + .println("Reactant not connected properly... Skipping reaction"); + } + System.out.println("reactant = " + s[1]); + } + } + if (s[2].equalsIgnoreCase("1")) + { + if (elt.getGraphId().equals(s[0])) { + System.out.println("graphid = " + s[0]); + SpeciesReference sr = r.createProduct(); + try { + sr.setSpecies(new Species(s[1])); + } catch (NullPointerException ne) { + System.err + .println("Product not connected properly... Skipping reaction"); + } + + System.out.println("product = " + s[1]); + + } + } } - for (PathwayElement elt : pathway.getDataObjects()) - { - addElement(elt); - + + listOfReactions.add(r); + } + + + private void addSpecies(PathwayElement elt, GlyphClazz gc) { + try { + Species sp = new Species(); + sp.setId(elt.getGraphId()); + if (!elt.getElementID().isEmpty() + || elt.getDataSource().getFullName().isEmpty()) { + if (sbmlAnnotate(elt).isSetAnnotation()) { + sp.setAnnotation(sbmlAnnotate(elt)); + } else { + System.out.println("Annotation element not properly set"); + } + } + listOfSpecies.add(sp); + } catch (NullPointerException e) { + System.err.println("Null species... Skipping"); } - SBMLDocument doc= new SBMLDocument(); - doc.setModel(doModel()); - doc.setLevelAndVersion(3, 1); - - try { - SBMLWriter w=new SBMLWriter(); - - w.writeSBMLToFile(doc, file.getAbsolutePath()); - } catch (SBMLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (XMLStreamException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } + + public void addSpeciesReferences(PathwayElement elt) { + for (Map.Entry entry : portmatrix.entrySet()) { + if (entry.getKey().equals(elt.getStartGraphRef())) { + reactionmatrix.put( + entry.getValue() + "-" + elt.getEndGraphRef() + "-1", + elt.getEndGraphRef());// reaction,species + } + if (entry.getKey().equals(elt.getEndGraphRef())) { + reactionmatrix.put( + entry.getValue() + "-" + elt.getStartGraphRef() + "-2", + elt.getStartGraphRef());// reaction,species + } + + } } - - public void addSpeciesReferences(PathwayElement elt) - { - for (Map.Entry entry : portmatrix.entrySet()) { - if(entry.getKey().equals(elt.getStartGraphRef())) - reactionmatrix.put( entry.getValue()+"-"+elt.getEndGraphRef()+"-1",elt.getEndGraphRef());//reaction,species - if(entry.getKey().equals(elt.getEndGraphRef())) - reactionmatrix.put(entry.getValue()+"-"+elt.getStartGraphRef()+"-2",elt.getStartGraphRef());//reaction,species - - + + // private void createfromPathway() { + // SBMLDocument doc = new SBMLDocument(); + // + // doc.setLevel(Integer.parseInt(pathway.getMappInfo().getDynamicProperty( + // "SBML_Level"))); + // doc.setVersion(Integer.parseInt(pathway.getMappInfo() + // .getDynamicProperty("SBML_Version"))); + // doc.setModel(doModel()); + // + // try { + // SBMLWriter w = new SBMLWriter(); + // + // w.writeSBMLToFile(doc, file.getAbsolutePath()); + // } catch (SBMLException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } catch (XMLStreamException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } catch (IOException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + // } + private boolean testInteractionConnectivity() { + boolean answer = true; + for (PathwayElement pe : pathway.getDataObjects()) { + if (pe.getObjectType() == ObjectType.LINE) { + String grs = pe.getStartGraphRef(); + String gre = pe.getEndGraphRef(); + if (grs == null || "".equals(grs) || gre == null + || "".equals(gre)) { + answer = false; + } + } } + return answer; + } - public void addElement(PathwayElement elt) - { - String sbgnClass = elt.getDynamicProperty(SbgnFormat.PROPERTY_SBGN_CLASS); - - if (sbgnClass != null) - { - if (elt.getObjectType() == ObjectType.LINE) - { + + /** + * checks if the given SBML document uses the SBML-layout extension + */ + private Model doModel() { + Model model = new Model(); + model.setId(pathway.getMappInfo().getMapInfoName()); + model.setListOfSpecies(listOfSpecies); + model.setListOfReactions(listOfReactions); + return model; + } + + /** + * Creates the Map for each ProcessNode (i.e) Map of each ProcessNode with + * its COnnected line-GraphId, starting Graph Reference, + * + * @param pwy + */ + protected void makePorts() { + int i = 0; + + for (PathwayElement elt : pathway.getDataObjects()) { + switch (elt.getObjectType()) { + case LINE: { + // ports have been dealt with already, skip. + if ("true".equals(elt + .getDynamicProperty(SbgnFormat.PROPERTY_SBGN_IS_PORT))) { + portmatrix.put(elt.getMAnchors().get(0).getGraphId(), + elt.getStartGraphRef()); + } + + } + } + } + + } + + // @Override + // public void pathwayModified(PathwayEvent e) { + // if (updatingSbml) + // return; + // switch (e.getType()) { + // case PathwayEvent.ADDED: + // addElement(e.getAffectedData()); + // break; + // case PathwayEvent.DELETED: + // removeElement(e.getAffectedData()); + // break; + // } + // } + /** + * @param e + * Pathwayevents + */ + // @Override + // public void pathwayModified(PathwayEvent e) { + // setUpdatingSbml(true); + // switch (e.getType()) { + // case PathwayEvent.ADDED: + // sbgn2sbml(e.getAffectedData()); + // // br.getDoc().fireNodeAddedEvent(); + // break; + // case PathwayEvent.DELETED: + // sbgn2sbml(e.getAffectedData()); + // // br.getDoc().fireNodeRemovedEvent(); + // break; + // + // + // } + // } + + /** + * Converts a SBGN pathway diagram to SBML format + * + * @param elt + * pathway elements + */ + public void sbgn2sbml(PathwayElement elt) { + String sbgnClass = elt + .getDynamicProperty(SbgnFormat.PROPERTY_SBGN_CLASS); + + if (sbgnClass != null) { + if (elt.getObjectType() == ObjectType.LINE) { ArcClazz ac = ArcClazz.fromClazz(sbgnClass); - switch (ac) - { + switch (ac) { case CONSUMPTION: case PRODUCTION: case CATALYSIS: case STIMULATION: - // addSpeciesReference (elt); + addReactions(elt); } - } - else - { + } else { GlyphClazz gc = GlyphClazz.fromClazz(sbgnClass); - switch (gc) - { + switch (gc) { case PROCESS: case UNCERTAIN_PROCESS: case OMITTED_PROCESS: case ASSOCIATION: case DISSOCIATION: - addReaction (elt); + addReactions(elt); break; case SIMPLE_CHEMICAL: case SIMPLE_CHEMICAL_MULTIMER: case MACROMOLECULE: - case MACROMOLECULE_MULTIMER: - { - addSpecies (elt, gc); - + case MACROMOLECULE_MULTIMER: { + addSpecies(elt, gc); + } - break; + break; } } - } - } - - - - /** - * Creates the Map for each ProcessNode (i.e) Map of each ProcessNode with - * its COnnected line-GraphId, starting Graph Reference, - */ - protected void makePorts() { - int i = 0; - - for (PathwayElement elt : pathway.getDataObjects()) - { - switch (elt.getObjectType()) - { - case LINE: - { - // ports have been dealt with already, skip. - if ("true".equals (elt.getDynamicProperty(SbgnFormat.PROPERTY_SBGN_IS_PORT))) - portmatrix.put(elt.getMAnchors().get(0).getGraphId(),elt.getStartGraphRef()); - - - } - } } - - } - - - private void addSpecies(PathwayElement elt, GlyphClazz gc) - { - Species sp= new Species(); - sp.setId(elt.getGraphId()); - listOfSpecies.add(sp); - } - private void addReaction(PathwayElement elt) - { - org.sbml.jsbml.Reaction r= new org.sbml.jsbml.Reaction(); - r.setId(elt.getGraphId()); - for (Map.Entry entry : reactionmatrix.entrySet()) { - - String[] s = entry.getKey().split("-",3); - if(s[2].equalsIgnoreCase("2")) - { - if(elt.getGraphId().equals(s[0])) - { - - SpeciesReference sr= r.createReactant(); - sr.setSpecies(new Species(s[1])); - - - } - } - if(s[2].equalsIgnoreCase("1")) - { - if(elt.getGraphId().equals(s[0])) - { - - SpeciesReference sr= r.createProduct(); - sr.setSpecies(new Species(s[1])); - - - } - } - } - - listOfReactions.add(r); + + private void setUpdatingSbml(boolean b) { + UpdatingSbml = b; } - - /** checks if the given SBML document uses the SBML-layout extension */ - private Model doModel() - { - Model model =new Model(); - model.setListOfSpecies(listOfSpecies); - model.setListOfReactions(listOfReactions); - - - return model; + private Annotation sbmlAnnotate(PathwayElement elt) { + Annotation annotation = new Annotation(); + CVTerm term = new CVTerm(); + Xref xref = elt.getXref(); + // term.setBiologicalQualifierType(Qualifier.BQB_IS); + // term.fireNodeRemovedEvent(); + // CVTerm.Qualifier.BQB_IS, "miriam"; + // String xrefString = "http://identifiers.org/"; + // String identifier = ""; + // String database = ""; + + // identifier = elt.getElementID(); + // database = elt.getDataSource().getFullName(); + // + // if (database.contains("chebi")) { + // database = database.replace("chebi", "obo.chebi"); + // } + // if (database.contains("pubchem")) { + // database = database.replace("pubchem", "pubchem.compound"); + // } + // System.out.println("Xref - URN" + xrefString + database + "/" + // + identifier); + term.addResource(xref.getURN()); + annotation.addCVTerm(term); + annotation.setAbout("#metaid_" + elt.getTextLabel()); + System.out.println("urn - about = " + annotation.getAbout()); + return annotation; } } \ No newline at end of file diff --git a/src/org/pathvisio/sbml/SbmlImportHelper.java b/src/org/pathvisio/sbml/SbmlImportHelper.java index 1d09c8a..41673b8 100644 --- a/src/org/pathvisio/sbml/SbmlImportHelper.java +++ b/src/org/pathvisio/sbml/SbmlImportHelper.java @@ -1,6 +1,6 @@ -// PathVisio, -// a tool for data visualization and analysis using Biological Pathways -// Copyright 2006-2014 BiGCaT Bioinformatics +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,45 +14,37 @@ // See the License for the specific language governing permissions and // limitations under the License. // + package org.pathvisio.sbml; import java.io.File; -import java.io.IOException; - -import javax.xml.stream.XMLStreamException; -import org.pathvisio.core.model.ConverterException; import org.pathvisio.core.model.Pathway; import org.pathvisio.sbml.peer.PeerModel; import org.sbml.jsbml.SBMLDocument; import org.sbml.jsbml.xml.stax.SBMLReader; -public class SbmlImportHelper -{ +public class SbmlImportHelper { private PeerModel br; + SBMLDocument doc; - public Pathway doImport(File file) throws ConverterException - { + public Pathway doImport(File file) { try { - SBMLDocument doc = new SBMLReader().readSBML(file.getAbsolutePath()); + doc = new SBMLReader() + .readSBML(file.getAbsolutePath()); - br = PeerModel.createFromDoc(doc, file); - return br.getPathway(); - } - catch (IOException ex) - { - throw new ConverterException (ex); + br = PeerModel.createFromDoc(doc); } - catch (XMLStreamException ex) - { - throw new ConverterException (ex); + catch (Exception ex) { + System.out.println("WARNING :" + doc.getModel().getName() + + "could not be converted"); } + return br.getPathway(); } - public SBMLDocument getDocument() - { + public SBMLDocument getDocument() { return br.getDoc(); } -} +} \ No newline at end of file diff --git a/src/org/pathvisio/sbml/ValidatePanel.java b/src/org/pathvisio/sbml/ValidatePanel.java index 02214d1..a63d3c9 100644 --- a/src/org/pathvisio/sbml/ValidatePanel.java +++ b/src/org/pathvisio/sbml/ValidatePanel.java @@ -1,6 +1,6 @@ -// PathVisio, -// a tool for data visualization and analysis using Biological Pathways -// Copyright 2006-2014 BiGCaT Bioinformatics +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,6 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // + package org.pathvisio.sbml; import java.awt.Color; diff --git a/src/org/pathvisio/sbml/peer/PeerModel.java b/src/org/pathvisio/sbml/peer/PeerModel.java index 76c8701..eaadabd 100644 --- a/src/org/pathvisio/sbml/peer/PeerModel.java +++ b/src/org/pathvisio/sbml/peer/PeerModel.java @@ -1,6 +1,6 @@ -// PathVisio, -// a tool for data visualization and analysis using Biological Pathways -// Copyright 2006-2014 BiGCaT Bioinformatics +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ // See the License for the specific language governing permissions and // limitations under the License. // + package org.pathvisio.sbml.peer; -import java.io.File; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -24,12 +24,8 @@ import org.bridgedb.DataSource; import org.bridgedb.Xref; import org.pathvisio.core.model.DataNodeType; -import org.pathvisio.core.model.ObjectType; import org.pathvisio.core.model.Pathway; import org.pathvisio.core.model.PathwayElement; -import org.pathvisio.core.model.PathwayEvent; -import org.pathvisio.core.model.PathwayListener; -import org.pathvisio.sbgn.SbgnFormat; import org.pathvisio.sbgn.SbgnTemplates; import org.sbgn.ArcClazz; import org.sbgn.GlyphClazz; @@ -52,175 +48,131 @@ import org.sbml.jsbml.ext.qual.QualitativeSpecies; import org.sbml.jsbml.ext.qual.Transition; -public class PeerModel implements PathwayListener -{ +public class PeerModel { + private final SBMLDocument doc; private final Pathway pwy; private boolean updatingSbml = false; - public PeerModel (SBMLDocument doc, Pathway pwy) - { + /** + * @param doc + * @param pwy + */ + public PeerModel(SBMLDocument doc, Pathway pwy) { this.doc = doc; this.pwy = pwy; - pwy.addListener(this); - } - public Pathway getPathway() { return pwy; } - public SBMLDocument getDoc() { return doc; } - - public void addElement(PathwayElement elt) - { - String sbgnClass = elt.getDynamicProperty(SbgnFormat.PROPERTY_SBGN_CLASS); - if (sbgnClass != null) - { - if (elt.getObjectType() == ObjectType.LINE) - { - ArcClazz ac = ArcClazz.fromClazz(sbgnClass); - switch (ac) - { - case CONSUMPTION: - case PRODUCTION: - case CATALYSIS: - case STIMULATION: - addSpeciesReference (elt); - } - } - else - { - GlyphClazz gc = GlyphClazz.fromClazz(sbgnClass); - switch (gc) - { - case PROCESS: - case UNCERTAIN_PROCESS: - case OMITTED_PROCESS: - case ASSOCIATION: - case DISSOCIATION: - addReaction (elt); - break; - case SIMPLE_CHEMICAL: - case SIMPLE_CHEMICAL_MULTIMER: - case MACROMOLECULE: - case MACROMOLECULE_MULTIMER: - addSpecies (elt, gc); - break; - } - } - } - else - { - // we only handle SBGN elements for now. - } + } + public Pathway getPathway() { + return pwy; } - private void addSpeciesReference(PathwayElement elt) - { + public SBMLDocument getDoc() { + return doc; + } + public Model getModel() { + return doc.getModel(); } - private void addSpecies(PathwayElement elt, GlyphClazz gc) - { + private void addSpecies(PathwayElement elt, GlyphClazz gc) { PeerSpecies bs = PeerSpecies.createFromElt(this, elt, gc); speciesPeers.put(elt.getGraphId(), bs); } - private void addReaction(PathwayElement elt) - { - - } - private final Map speciesPeers = new HashMap(); - public void putSpeciesPeer(String sId, PeerSpecies sbr) - { + public void putSpeciesPeer(String sId, PeerSpecies sbr) { speciesPeers.put(sId, sbr); } - public PeerSpecies getSpeciesPeer(String sid) - { + public PeerSpecies getSpeciesPeer(String sid) { return speciesPeers.get(sid); } - public Model getModel() - { - return doc.getModel(); - } - - @Override - public void pathwayModified(PathwayEvent e) - { - if (updatingSbml) return; - switch (e.getType()) - { - case PathwayEvent.ADDED: - addElement(e.getAffectedData()); - break; - case PathwayEvent.DELETED: - removeElement(e.getAffectedData()); - break; - } - } - - private void removeElement(PathwayElement affectedData) - { - // TODO Auto-generated method stub - } - - public static PeerModel createFromDoc(SBMLDocument doc, File file) - { + /** + * Converts SBML doc to SBGN-PD pathway + * + * @param doc + * SBML document + * @return + */ + public static PeerModel createFromDoc(SBMLDocument doc) { Pathway pathway = new Pathway(); - pathway.getMappInfo().setMapInfoName(file.getName()); + pathway.getMappInfo().setMapInfoName(doc.getModel().getId()); pathway.getMappInfo().setMapInfoDataSource("Converted from SBML"); - PeerModel bm = new PeerModel (doc, pathway); - bm.updateModel(); + PeerModel bm = new PeerModel(doc, pathway); + /* + * Save notes as comments + */ + if (doc.isSetNotes()) { + pathway.getMappInfo().addComment(doc.getNotesString(), "SBML"); + } + /* + * Save Annotation + */ + if (doc.isSetAnnotation()) { + pathway.getMappInfo().addComment(doc.getAnnotationString(), + "Annotation"); + } + if (doc.isSetLevel()) { + pathway.getMappInfo().setDynamicProperty("SBML_Level", + String.valueOf(doc.getLevel())); + } else { + pathway.getMappInfo().setDynamicProperty("SBML_Level", + String.valueOf(doc.getDefaultLevel())); + } + if (doc.isSetVersion()) { + pathway.getMappInfo().setDynamicProperty("SBML_Version", + String.valueOf(doc.getVersion())); + } else { + pathway.getMappInfo().setDynamicProperty("SBML_Version", + String.valueOf(doc.getDefaultVersion())); + } + bm.sbml2sbgn(); return bm; } - private void updateModel() - { + private void sbml2sbgn() { updatingSbml = true; doReactions(); doSpecies(); - doQual(); doLayout(); updatingSbml = false; } - private void doSpecies() - { + private void doSpecies() { // do remaining species - for (Species s : doc.getModel().getListOfSpecies()) - { + for (Species s : doc.getModel().getListOfSpecies()) { // check it it was already added before String sid = s.getId(); - if (pwy.getElementById(sid) == null) - { + if (pwy.getElementById(sid) == null) { nextLocation(); - createOrGetSpecies(sid, xco, yco, GlyphClazz.BIOLOGICAL_ACTIVITY); + createOrGetSpecies(sid, xco, yco, + GlyphClazz.BIOLOGICAL_ACTIVITY); } } } /** checks if the given SBML document uses the SBML-layout extension */ - private void doLayout() - { + private void doLayout() { Model model = doc.getModel(); - ExtendedLayoutModel sbase = (ExtendedLayoutModel)model.getExtension(LayoutConstants.namespaceURI); - if (sbase != null) - { - for (Layout l : sbase.getListOfLayouts()) - { + ExtendedLayoutModel sbase = (ExtendedLayoutModel) model + .getExtension(LayoutConstants.namespaceURI); + if (sbase != null) { + for (Layout l : sbase.getListOfLayouts()) { // TODO: list of compartment glyphs, text glyphs, etc... - for (SpeciesGlyph g : l.getListOfSpeciesGlyphs()) - { + for (SpeciesGlyph g : l.getListOfSpeciesGlyphs()) { String sid = g.getSpecies(); PeerSpecies sbr = getSpeciesPeer(sid); if (sbr != null) { sbr.setSpeciesGlyph(g); + } } } @@ -228,12 +180,11 @@ private void doLayout() } /** checks if the given SBML document uses the SBML-qual extension */ - private void doQual() - { + private void doQual() { Model model = doc.getModel(); - QualitativeModel qualModel = (QualitativeModel)model.getExtension(QualConstant.namespaceURI); - if (qualModel != null) - { + QualitativeModel qualModel = (QualitativeModel) model + .getExtension(QualConstant.namespaceURI); + if (qualModel != null) { doQualitativeSpecies(qualModel); doTransitions(qualModel); } @@ -241,25 +192,23 @@ private void doQual() /** used only in the SBML-qual extension */ - private void doQualitativeSpecies(QualitativeModel qualModel) - { - for (QualitativeSpecies qs : qualModel.getListOfQualitativeSpecies()) - { - // PathwayElement pelt = createOrGetSpecies(qs.getId(), xco, yco, GlyphClazz.BIOLOGICAL_ACTIVITY); - PathwayElement pelt = SbgnTemplates.createGlyph(GlyphClazz.BIOLOGICAL_ACTIVITY, pwy, xco, yco); + private void doQualitativeSpecies(QualitativeModel qualModel) { + for (QualitativeSpecies qs : qualModel.getListOfQualitativeSpecies()) { + // PathwayElement pelt = createOrGetSpecies(qs.getId(), xco, yco, + // GlyphClazz.BIOLOGICAL_ACTIVITY); + PathwayElement pelt = SbgnTemplates.createGlyph( + GlyphClazz.BIOLOGICAL_ACTIVITY, pwy, xco, yco); pelt.setGraphId(qs.getId()); pelt.setTextLabel(qs.getName()); - List t = qs.filterCVTerms(CVTerm.Qualifier.BQB_IS, "miriam"); - if (t.size() > 0) - { + List t = qs + .filterCVTerms(CVTerm.Qualifier.BQB_IS, "miriam"); + if (t.size() > 0) { Xref ref = Xref.fromUrn(t.get(0)); - if (ref == null) - { - System.out.println ("WARNING: couldn't convert " + t.get(0) + " to Xref"); - } - else - { + if (ref == null) { + System.out.println("WARNING: couldn't convert " + t.get(0) + + " to Xref"); + } else { pelt.setGeneID(ref.getId()); pelt.setDataSource(ref.getDataSource()); } @@ -272,59 +221,58 @@ private void doQualitativeSpecies(QualitativeModel qualModel) } /** used only in the SBML-qual extension */ - private void doTransitions(QualitativeModel qualModel) - { - for (Transition t : qualModel.getListOfTransitions()) - { - if (t.getListOfInputs().size() == 1 && - t.getListOfOutputs().size() == 1) - { + private void doTransitions(QualitativeModel qualModel) { + for (Transition t : qualModel.getListOfTransitions()) { + if (t.getListOfInputs().size() == 1 + && t.getListOfOutputs().size() == 1) { Input i = t.getListOfInputs().get(0); Output o = t.getListOfOutputs().get(0); - PathwayElement iElt = pwy.getElementById(i.getQualitativeSpecies()); - PathwayElement oElt = pwy.getElementById(o.getQualitativeSpecies()); + PathwayElement iElt = pwy.getElementById(i + .getQualitativeSpecies()); + PathwayElement oElt = pwy.getElementById(o + .getQualitativeSpecies()); - if (iElt == null || oElt == null) - { - System.out.println ("WARNING: missing input or output qualitative species"); - } - else - { + if (iElt == null || oElt == null) { + System.out + .println("WARNING: missing input or output qualitative species"); + } else { ArcClazz ac = null; - switch (i.getSign()) - { - case dual: ac = ArcClazz.UNKNOWN_INFLUENCE; break; - case positive: ac = ArcClazz.POSITIVE_INFLUENCE; break; - case negative: ac = ArcClazz.NEGATIVE_INFLUENCE; break; - case unknown: ac = ArcClazz.UNKNOWN_INFLUENCE; break; + switch (i.getSign()) { + case dual: + ac = ArcClazz.UNKNOWN_INFLUENCE; + break; + case positive: + ac = ArcClazz.POSITIVE_INFLUENCE; + break; + case negative: + ac = ArcClazz.NEGATIVE_INFLUENCE; + break; + case unknown: + ac = ArcClazz.UNKNOWN_INFLUENCE; + break; } - PathwayElement arc = SbgnTemplates.createArc(pwy, ac, iElt.getMCenterX(), iElt.getMCenterY(), iElt, oElt.getMCenterX(), oElt.getMCenterY(), oElt); - pwy.add(arc); + PathwayElement arc = SbgnTemplates.createArc(pwy, ac, + iElt.getMCenterX(), iElt.getMCenterY(), iElt, + oElt.getMCenterX(), oElt.getMCenterY(), oElt); + pwy.add(sbgnAnnotate(arc, i.getId())); } - } - else - { - //TODO more complex transition functions. + } else { + // TODO more complex transition functions. } } } - private void doReactions() - { - for (Reaction re : doc.getModel().getListOfReactions()) - { + private void doReactions() { + for (Reaction re : doc.getModel().getListOfReactions()) { double x = xco; double y = yco; PeerReaction pr = PeerReaction.createFromSbml(this, re, x, y); - boolean next = true; - if (re.getListOfReactants().size() > 0) - { + if (re.getListOfReactants().size() > 0) { String sid = re.getProduct(0).getSpecies(); PathwayElement pelt = pwy.getElementById(sid); - if (pelt != null) - { + if (pelt != null) { xco = pelt.getMCenterX() + 100; yco = pelt.getMCenterY(); next = false; @@ -334,136 +282,133 @@ private void doReactions() nextLocation(); } - double yy = y; - for (SpeciesReference j : re.getListOfProducts()) - { + for (SpeciesReference j : re.getListOfProducts()) { String sid = j.getSpecies(); - PathwayElement pelt = createOrGetSpecies(sid, x + 80, yy, GlyphClazz.SIMPLE_CHEMICAL); - PeerSpeciesReference bsref = PeerSpeciesReference.createFromSpeciesReference (this, j, ArcClazz.PRODUCTION, x + M_PN, y, pr.getPortId(1), pelt.getMLeft(), pelt.getMCenterY(), pelt); - pwy.add(bsref.getElement()); + PathwayElement pelt = createOrGetSpecies(sid, x + 80, yy, + GlyphClazz.SIMPLE_CHEMICAL); + PeerSpeciesReference bsref = PeerSpeciesReference + .createFromSpeciesReference(this, j, + ArcClazz.PRODUCTION, x + M_PN, y, + pr.getPortId(1), pelt.getMLeft(), + pelt.getMCenterY(), pelt); + pwy.add(sbgnAnnotate(bsref.getElement(), sid)); yy += 20; } yy = y; - for (SpeciesReference j : re.getListOfReactants()) - { + for (SpeciesReference j : re.getListOfReactants()) { String sid = j.getSpecies(); - PathwayElement pelt = createOrGetSpecies(sid, x - 80, yy, GlyphClazz.SIMPLE_CHEMICAL); - PeerSpeciesReference bsref = PeerSpeciesReference.createFromSpeciesReference (this, j, ArcClazz.CONSUMPTION, pelt.getMLeft() + pelt.getMWidth(), pelt.getMCenterY(), pelt, x - M_PN, y, pr.getPortId(0)); - pwy.add(bsref.getElement()); + PathwayElement pelt = createOrGetSpecies(sid, x - 80, yy, + GlyphClazz.SIMPLE_CHEMICAL); + PeerSpeciesReference bsref = PeerSpeciesReference + .createFromSpeciesReference(this, j, + ArcClazz.CONSUMPTION, + pelt.getMLeft() + pelt.getMWidth(), + pelt.getMCenterY(), pelt, x - M_PN, y, + pr.getPortId(0)); + pwy.add(sbgnAnnotate(bsref.getElement(), sid)); yy += 20; } - for (ModifierSpeciesReference j : re.getListOfModifiers()) - { + for (ModifierSpeciesReference j : re.getListOfModifiers()) { String sid = j.getSpecies(); - PathwayElement pelt = createOrGetSpecies(sid, x, y - 80, GlyphClazz.MACROMOLECULE); - PeerSpeciesReference bsref = PeerSpeciesReference.createFromSpeciesReference (this, j, ArcClazz.CATALYSIS, pelt.getMCenterX(), pelt.getMTop() + pelt.getMHeight(), pelt, x, y, pr.getProcessNodeElt()); - pwy.add(bsref.getElement()); + PathwayElement pelt = createOrGetSpecies(sid, x, y - 80, + GlyphClazz.MACROMOLECULE); + PeerSpeciesReference bsref = PeerSpeciesReference + .createFromSpeciesReference(this, j, + ArcClazz.CATALYSIS, pelt.getMCenterX(), + pelt.getMTop() + pelt.getMHeight(), pelt, x, y, + pr.getProcessNodeElt()); + pwy.add(sbgnAnnotate(bsref.getElement(), sid)); } } } - private void nextLocation() - { + private void nextLocation() { yco += 150; - if (yco > 1000) - { + if (yco > 1000) { yco = 30; xco += 300; } } - private PathwayElement createOrGetSpecies (String sId, double prefX, double prefY, GlyphClazz gc) - { + + private PathwayElement createOrGetSpecies(String sId, double prefX, + double prefY, GlyphClazz gc) { PathwayElement pelt = pwy.getElementById(sId); - if (pelt == null) - { + if (pelt == null) { Species sp = doc.getModel().getSpecies(sId); PeerSpecies sbr = PeerSpecies.createFromSpecies(this, sp, gc); - putSpeciesPeer (sId, sbr); + putSpeciesPeer(sId, sbr); pelt = sbr.getSpeciesElement(); pelt.setMCenterX(prefX); pelt.setMCenterY(prefY); pelt.setTextLabel(sId); - // for (DataSource ds : DataSource.getDataSources()) { - // System.out - // .println(ds.getSystemCode() + "\t" + ds.getFullName()); - // } - Annotation annotation = doc.getModel().getSpecies(sId).getAnnotation(); - for (int i = 0; i < annotation.getCVTermCount(); i++) { - - List annotationList = annotation.getCVTerm(i).getResources(); - for (String xrefString : annotationList) { - System.out.println("here"); - System.out.println(xrefString); - String[] de = xrefString.split("org/", 2); - String[] xe = de[1].split("/", 2); - - String database = xe[0]; - String identifier = xe[1]; - DataSource ds; - if (database.contains("obo.")) { - database = database.replaceAll("obo.", ""); - ds = DataSource.getBySystemCode("Ce"); - pelt.setDataSource(ds); - pelt.setElementID(identifier); - if (ds.getType().equalsIgnoreCase("Protein")) { - pelt.setDataNodeType(DataNodeType.PROTEIN); - } else if (ds.getType().equalsIgnoreCase("Metabolite")) { - pelt.setDataNodeType(DataNodeType.METABOLITE); - } else { - pelt.setDataNodeType(DataNodeType.GENEPRODUCT); - } - } else { - if (database.contains(".compound")) { - database = database.replaceAll(".compound", ""); - ds = DataSource.getBySystemCode("Cpc"); - pelt.setDataSource(ds); - pelt.setElementID(identifier); - if (ds.getType().equalsIgnoreCase("Protein")) { - pelt.setDataNodeType(DataNodeType.PROTEIN); - } else if (ds.getType().equalsIgnoreCase( - "Metabolite")) { - pelt.setDataNodeType(DataNodeType.METABOLITE); - } else { - pelt.setDataNodeType(DataNodeType.GENEPRODUCT); - } + pelt = sbgnAnnotate(pelt, sId); + pwy.add(pelt); + } + return pelt; + } + + + + PathwayElement sbgnAnnotate(PathwayElement pelt, String sId) { + Boolean datasourceset = false; + DataSource ds = DataSource.getBySystemCode("L"); + if (doc.getModel().getSpecies(sId).isSetAnnotation()) { + Annotation annotation = doc.getModel().getSpecies(sId) + .getAnnotation(); + List annotationList = annotation.getCVTerm(0) + .getResources(); + String xrefString = annotationList.get(0); + + String[] de = xrefString.split("org/", 2); + String[] xe = de[1].split("/", 2); + + String database = xe[0]; + String identifier = xe[1]; + /* + * Ontology databases + */ + if (database.contains("chebi")) { + datasourceset = true; + ds = DataSource.getBySystemCode("Ce"); + } else { + if (database.equals("obo.go") || database.equals("go")) { + datasourceset = true; + ds = DataSource.getBySystemCode("T"); + }else { + if (database.contains("uniprot")) { + datasourceset = true; + ds = DataSource.getBySystemCode("S"); + }else { + try { + ds = DataSource.getByFullName(database); + datasourceset = true; + } catch (Exception e) { + System.out + .println("WARNING : Could not find a match for " + + database); } } - // xe[0] = xe[0].replaceFirst("obo.", ""); - // xe[0] = xe[0].replaceFirst(".", ""); - // - System.out.println("database " + database); - System.out.println("identifier " + identifier); - - - // for (DataSource ds : DataSource.getDataSources()) { - // System.out.println(ds.); - // // if (xe[0].equalsIgnoreCase(ds.getFullName())) { - // if (database.contains(ds.getFullName())) { - // System.out - // .println("database2" + ds.getSystemCode()); - // pelt.setDataSource(ds); - // pelt.setElementID(xe[1]); - // if (ds.getType().equalsIgnoreCase("Protein")) { - // pelt.setDataNodeType(DataNodeType.PROTEIN); - // } else if (ds.getType().equalsIgnoreCase( - // "Metabolite")) { - // pelt.setDataNodeType(DataNodeType.METABOLITE); - // } else { - // pelt.setDataNodeType(DataNodeType.GENEPRODUCT); - // } - // } - // } } } - - pwy.add(pelt); + if (datasourceset) { + pelt.setDataSource(ds); + pelt.setElementID(identifier); + if (ds.getType().equalsIgnoreCase("Protein")) { + pelt.setDataNodeType(DataNodeType.PROTEIN); + } else if (ds.getType().equalsIgnoreCase("Metabolite")) { + pelt.setDataNodeType(DataNodeType.METABOLITE); + } else { + pelt.setDataNodeType(DataNodeType.GENEPRODUCT); + } + datasourceset = false; + } } return pelt; } @@ -474,4 +419,4 @@ private PathwayElement createOrGetSpecies (String sId, double prefX, double pref final static double M_HEIGHT = 30; final static double M_PN = 20; -} +} \ No newline at end of file diff --git a/src/org/pathvisio/sbml/peer/PeerReaction.java b/src/org/pathvisio/sbml/peer/PeerReaction.java index 08ab135..65b42b6 100644 --- a/src/org/pathvisio/sbml/peer/PeerReaction.java +++ b/src/org/pathvisio/sbml/peer/PeerReaction.java @@ -1,3 +1,20 @@ +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + package org.pathvisio.sbml.peer; import org.pathvisio.core.model.GraphLink.GraphIdContainer; @@ -10,6 +27,7 @@ public class PeerReaction { + private PathwayElement pn; private PathwayElement port1; private PathwayElement port2; @@ -18,14 +36,18 @@ public class PeerReaction private MAnchor pid1; private MAnchor pid2; - public static PeerReaction createFromSbml(PeerModel parent, Reaction re, double x, double y) + public static PeerReaction createFromSbml(PeerModel parent, Reaction re, + double x, double y) { PeerReaction pr = new PeerReaction(); // create a process node for the reaction. Pathway pwy = parent.getPathway(); - PathwayElement[] process = SbgnTemplates.createProcessNode(pwy, GlyphClazz.PROCESS, x, y, PeerModel.M_PN, re.getId()); - for (PathwayElement elt : process) pwy.add(elt); + PathwayElement[] process = SbgnTemplates.createProcessNode(pwy, + GlyphClazz.PROCESS, x, y, PeerModel.M_PN, re.getId()); + for (PathwayElement elt : process) { + pwy.add(elt); + } pr.pn = process[2]; pr.port1 = process[0]; pr.port2 = process[1]; @@ -36,6 +58,8 @@ public static PeerReaction createFromSbml(PeerModel parent, Reaction re, double } + + public GraphIdContainer getPortId(int i) { switch (i) @@ -49,9 +73,8 @@ public GraphIdContainer getPortId(int i) } } - - public GraphIdContainer getProcessNodeElt() - { + public PathwayElement getProcessNodeElt() { return pn; } -} + +} \ No newline at end of file diff --git a/src/org/pathvisio/sbml/peer/PeerSpecies.java b/src/org/pathvisio/sbml/peer/PeerSpecies.java index 0e9aa26..197d81d 100644 --- a/src/org/pathvisio/sbml/peer/PeerSpecies.java +++ b/src/org/pathvisio/sbml/peer/PeerSpecies.java @@ -1,6 +1,6 @@ -// PathVisio, -// a tool for data visualization and analysis using Biological Pathways -// Copyright 2006-2014 BiGCaT Bioinformatics +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -41,16 +41,37 @@ public PeerSpecies(PathwayElement elt, Species sp) elt.addListener(this); } - public static PeerSpecies createFromSpecies(PeerModel parent, Species sp, GlyphClazz gc) + public static PeerSpecies createFromSpecies(PeerModel parent, Species sp, + GlyphClazz gc) { - PathwayElement elt = SbgnTemplates.createGlyph(gc, parent.getPathway(), 0, 0); + PathwayElement elt = SbgnTemplates.createGlyph(gc, parent.getPathway(), + 0, 0); elt.setGraphId(sp.getId()); + PeerSpecies bs = new PeerSpecies(elt, sp); bs.updateElt(); return bs; } - public static PeerSpecies createFromElt (PeerModel parent, PathwayElement elt, GlyphClazz gc) + /* + * Save all infiormation available in the model in the pathway + */ + private void addInfo(PathwayElement elt, Species sp) { + if (sp.isSetName()) { + elt.setTextLabel(sp.getName()); + } + if (sp.isSetBoundaryCondition()) { + elt.setDynamicProperty("BoundaryCondition", + String.valueOf(sp.getBoundaryCondition())); + } + if (sp.isHasOnlySubstanceUnits()) { + elt.setDynamicProperty("HasOnlySubstanceUnits", + sp.getSubstanceUnits()); + } + + } + public static PeerSpecies createFromElt(PeerModel parent, + PathwayElement elt, GlyphClazz gc) { Species sp = parent.getModel().createSpecies(elt.getGraphId()); PeerSpecies bs = new PeerSpecies(elt, sp); @@ -148,4 +169,4 @@ public void setSpeciesGlyph(SpeciesGlyph g) updateElt(); } -} +} \ No newline at end of file diff --git a/src/org/pathvisio/sbml/peer/PeerSpeciesReference.java b/src/org/pathvisio/sbml/peer/PeerSpeciesReference.java index 0ac1153..a8b6ce3 100644 --- a/src/org/pathvisio/sbml/peer/PeerSpeciesReference.java +++ b/src/org/pathvisio/sbml/peer/PeerSpeciesReference.java @@ -1,6 +1,6 @@ -// PathVisio, -// a tool for data visualization and analysis using Biological Pathways -// Copyright 2006-2014 BiGCaT Bioinformatics +// PathSBML Plugin +// SBML Plugin for PathVisio. +// Copyright 2013 developed for Google Summer of Code // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -28,17 +28,22 @@ public class PeerSpeciesReference implements PathwayElementListener { private final PathwayElement pathwayELement; - public PeerSpeciesReference(PeerModel parent, PathwayElement elt, SimpleSpeciesReference sref) + + public PeerSpeciesReference(PeerModel parent, PathwayElement elt, + SimpleSpeciesReference sref) { this.pathwayELement = elt; elt.addListener(this); } - public static PeerSpeciesReference createFromSpeciesReference(PeerModel parent, SimpleSpeciesReference sref, ArcClazz arcClazz, + public static PeerSpeciesReference createFromSpeciesReference( + PeerModel parent, SimpleSpeciesReference sref, ArcClazz arcClazz, double sx, double sy, GraphIdContainer sid, double ex, double ey, GraphIdContainer eid) { - PathwayElement elt = SbgnTemplates.createArc(parent.getPathway(), arcClazz, sx, sy, sid, ex, ey, eid); - PeerSpeciesReference result = new PeerSpeciesReference(parent, elt, sref); + PathwayElement elt = SbgnTemplates.createArc(parent.getPathway(), + arcClazz, sx, sy, sid, ex, ey, eid); + PeerSpeciesReference result = new PeerSpeciesReference(parent, elt, + sref); result.updatePv(); return result; } @@ -64,4 +69,4 @@ public PathwayElement getElement() return pathwayELement; } -} +} \ No newline at end of file