from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "model.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) applyRender = True sl = SBMLlayout(str(model_file), applyRender=applyRender) sl._describeModel() sl.drawNetwork() assert sl.getNodeFontSize("X0") == 10 sl.setNodeFontSize("X0", 24) assert sl.getNodeFontSize("X0") == 24 sl.drawNetwork() sl.regenerateLayout() sl.drawNetwork()
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "model.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout() sl.loadSBMLFile(str(model_file)) def test_model_load_file_separately(): assert sl.getNumberOfNodes() == 6 assert sl.getNumberOfReactions() == 6
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "model.xml" model_file = Path(pkg_resources.resource_filename( "libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) fr_alg = sl.getLayoutAlgorithmOptions() def test_fr_alg_options_defaults(): assert fr_alg.k == 20 assert fr_alg.gravity == 0 assert fr_alg.baryx == 500 assert fr_alg.baryy == 500 assert fr_alg.autobary == 1 assert fr_alg.padding == 20 sl2 = SBMLlayout(str(model_file)) sl2.setLayoutAlgorithm_k(15) sl2.setLayoutAlgorithm_gravity(20) sl2.setLayoutAlgorithm_baryx(100)
import platform from libsbml_draw.model.sbml_layout import SBMLlayout if platform.system() == "Windows": model_file = "C:\\Users\\nrhaw\\Documents\\repos\\libsbml-draw\\model_files\\render_sbml_pink_green.xml" elif platform.system() == "Linux": model_file = "/home/radix/repos/libsbml-draw/model_files/render_sbml.xml" else: model_file = "/Users/natalieh/repos/libsbml-draw/model_files/render_sbml.xml" sl = SBMLlayout(model_file) #sl.describeModel() sl.drawNetwork() print("node ids: ", sl.getNodeIds()) print("reaction ids: ", sl.getReactionIds())
#import libsbml from libsbml_draw.model.sbml_layout import SBMLlayout #from libsbml_draw.model.render import Render #model_file = "C:\\tmp\\copasi.xml" model_file = "C:\\tmp\\largerpathway.xml" #doc = libsbml.readSBMLFromFile(model_file) #model = doc.getModel() #layout_plugin = model.getPlugin("layout") #if layout_plugin: # print("num layouts: ", layout_plugin.getNumLayouts()) sl = SBMLlayout(model_file) sl._describeModel() sl.drawNetwork() #r = Render(model_file, sl.layout_number) #r._describeRenderInfo() #print("render: ", type(r)) #print("num layouts: ", r.layout_plugin.getNumLayouts()) #sl._applyRenderInformation(None) #a0e0a030 reactionIds = sl.getReactionIds()
Node5 = 0; Node6 = 0; Node7 = 0; Node8888888 = 0; Node9 = 0; Node10 = 0; Node11 = 0; Node12 = 0; Node13 = 0; Node14 = 0; end ''') from libsbml_draw.model.sbml_layout import SBMLlayout sl = SBMLlayout(r.getSBML()) sl._describeModel() sl.drawNetwork() #sl.drawNetwork(figsize=(8,8)) #sl.drawNetwork(figsize=(8,8), node_mutation_scale=5) #sl.drawNetwork("complicated_nodes_antimony.png", show=False) # plt.show? # import IPython.display as display # display.Image("complicated_nodes_antimony.png", width=300)
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "simple-L2-render-local.xml" #model_file_name = "simple-L2-render-local-L3V1.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl._describeModel() sl.drawNetwork() sl.setCompartmentEdgeColor("vol1", "#0000ff") sl.setCompartmentFillColor("vol1", "#ff000010") sl.setCompartmentLineWidth("vol1", 5) assert sl.getCompartmentEdgeColor("vol1") == "#0000ffff" assert sl.getCompartmentFillColor("vol1") == "#ff000010" assert sl.getCompartmentLineWidth("vol1") == 5 sl.drawNetwork("simple_render_local.png") sl.writeSBMLFile("simple_render_local_out.xml") slr = SBMLlayout("simple_render_local_out.xml")
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "simple-L2-render-local-L3V1-fixed.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl._describeModel() sl.drawNetwork() sl.writeSBMLFile("fixed.xml")
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout #model_file_name = "complicated_nodes-L3V1.xml" model_file_name = "complicated_nodes.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl._describeModel() sl.drawNetwork("complicated_nodes.png")
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "model.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl._describeModel() print("node ids: ", sl.getNodeIds()) print("reaction ids: ", sl.getReactionIds()) sl.drawNetwork() sl._describeReaction(0) sl.setNodeEdgeWidth("all", 2) out_file = "model_out.xml" sl.writeSBMLFile("model_out.xml") sl2 = SBMLlayout(out_file) print("sl2 layoutSpecified: ", sl2._SBMLlayout__layoutSpecified)
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "model.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) s = SBMLlayout(str(model_file)) # s._describeModel() s.setNodeFontSize('all', 15) s.setReactionCurveWidth('all', 3) s.setNodeColor('all', 'red') s.setNodeFontColor('all', 'white') s.drawNetwork() s.regenerateLayout() s.drawNetwork()
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "BorisEJB.xml" model_file = Path(pkg_resources.resource_filename( "libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file), autoComputeLayout=False) def test_boris_model_default_layout(): assert sl.getNumberOfNodes() == 8 assert sl.getNumberOfReactions() == 10 model_file_name = "test_layout_override.xml" model_file = Path(pkg_resources.resource_filename( "libsbml_draw", "model/data/" + model_file_name)) slr = SBMLlayout(str(model_file), autoComputeLayout=False) def test_boris_model_back_in(): assert slr.getNumberOfNodes() == 8 assert slr.getNumberOfReactions() == 10
Node5 = 0; Node6 = 0; Node7 = 0; Node8888888 = 0; Node9 = 0; Node10 = 0; Node11 = 0; Node12 = 0; Node13 = 0; Node14 = 0; end ''') from libsbml_draw.model.sbml_layout import SBMLlayout sl = SBMLlayout(r.getSBML()) sl._describeModel() sl.drawNetwork() assert sl.getNumberOfNodes() == 12 assert sl.getNumberOfReactions() == 8 slsl = SBMLlayout() slsl.loadSBMLString(r.getSBML()) slsl._describeModel() slsl.drawNetwork()
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout MODEL_FILE_NAME = "largerpathway.xml" MODEL_FILE = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + MODEL_FILE_NAME)) print("model file: ", str(MODEL_FILE)) sl = SBMLlayout(str(MODEL_FILE)) #sl.describeModel() sl.setReactionColor("all", "#0000ff50") sl.setNodeColor("all", "#00ff0030") #sl.setNodeFontSize("all", 24) sl.drawNetwork("largerpathway.png") #sl.drawNetwork(figsize=(12,12)) print("node ids: ", sl.getNodeIds()) print("reaction ids: ", sl.getReactionIds()) print() for node in sl._SBMLlayout__network.nodes.values():
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "modexmpl.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl._describeModel() sl.drawNetwork("ftest_line_endings.pdf")
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "model.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout() sl.loadSBMLFile(str(model_file)) sl._describeModel() sl.drawNetwork() sl_str = sl.getSBMLString() ss = SBMLlayout() ss.loadSBMLString(sl_str) ss._describeModel() ss.drawNetwork()
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout #chance glycolysis 1960 #model_file_name = "chance_glycolysis_1960.xml" #model_file_name = "repressilator_BIOMD12.xml" model_file_name = "glycolysis_BIOMD176.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl._describeModel() sl.drawNetwork() sl.aliasNode("ATP") sl.aliasNode("ADP") sl.drawNetwork() sl.regenerateLayout() sl.drawNetwork() loo = sl.getLayoutAlgorithmOptions()
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "GlycolysisOriginal.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl._describeModel() assert sl.getNumberOfNodes() == 23 assert sl.getNumberOfReactions() == 11 sl.drawNetwork("GlycolysisOriginal.png") assert sl.getNodeEdgeWidth("External_glucose") == 3 assert sl.getNodeEdgeWidth("Glucose") == 1 # in this case, bottom means top assert sl.getNodeVTextAnchor("pyruvate") == "bottom" assert sl.getNodeVTextAnchor("ADP") == "bottom" assert sl.getNodeFillColor("NAD") == "#7fff55" assert sl.getNodeFillColor("NADH") == "#d4ffaa" assert sl.getNodeFillColor("ATP") == "#ff7faa" assert sl.getNodeFillColor("ADP") == "#ffd4d4"
regenerate layout causes network properties to revert back to default setArrowheadScale funciton does not work, but changing the default value does Sometimes run into problems with a canvas which is too big (like in the schmerier 2008 model) SBO term unexpected warning. Where does it come from Gradient colours are cool. Would like to see them. Font size should scale with scaling factor ''' layout = SBMLlayout('Kholodenko2000.xml') # print(layout.getNumberOfRoles()) layout.regenerateLayout() [layout.setCompartmentEdgeColor(i, 'grey') for i in layout.getCompartmentIds()] [layout.setNodeEdgeWidth(i, 10) for i in layout.getNodeIds()] [layout.setNodeFontSize(i, 40) for i in layout.getNodeIds()] [layout.setCompartmentLineWidth(i, 25) for i in layout.getCompartmentIds()] # [layout.setReactionEdgeColor(i, edge_color='black') for i in layout.getReactionIds()] [layout.setReactionCurveWidth(i, 10) for i in layout.getReactionIds()] [layout.setArrowheadScale(i, 50) for i in range(layout.getNumberOfRoles())] # [layout.setNodeColor(i, 'white') for i in layout.getNodeIds()] # [layout.setNodeEdgeColor(i, 'black') for i in layout.getNodeIds()] layout.drawNetwork('Kholodenko2000Layout.png', scaling_factor=1.5)
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "TCA_ecoli_glucose_BIOMD222_url.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl._describeModel() sl.drawNetwork("TCA_ecoli_glucose.pdf")
""" """ from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "model.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout() sl.loadSBMLFile(str(model_file)) sl._describeModel() sl.drawNetwork() ss = SBMLlayout() sbmlString = sl.getSBMLString() ss.loadSBMLString(sbmlString) ss._describeModel() ss.drawNetwork()
from pathlib import Path import pkg_resources import pytest from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "BorisEJB.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file), autoComputeLayout=True) sl._describeModel() sl.drawNetwork("boris_ejb_override.pdf") def test_write_file_raises(): with pytest.raises(ValueError): sl.writeSBMLFile("ftest_layout_override.xml") # This will write if allowed, and when it is read back in, it displays as # a single blob of garbage because everything is plotted with the same centers # sl.writeSBMLFile("test_layout_override.xml") # slr = SBMLlayout("test_layout_override.xml", autoComputeLayout=False) slr = SBMLlayout(str(model_file), autoComputeLayout=False)
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "TCA_ecoli_glucose_BIOMD222_url.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl._describeModel() sl.drawNetwork()
#from libsbml import readSBMLFromFile, read`SBMLFromString #import libsbml_draw.c_api.sbnw_c_api as sbnw from libsbml_draw.model.sbml_layout import SBMLlayout #model_file = "C:\\tmp\\model.xml" #model_file = "C:\\tmp\\copasi.xml" #model_file = "C:\\tmp\\render_sbml.xml" #model_file = "C:\\tmp\\largerpathway.xml" model_file = "C:\\tmp\\simple-L2-render-global.xml" # read model sl = SBMLlayout(model_file) # generate layout if not sl.layoutSpecified: sl._randomizeLayout() sl._doLayoutAlgorithm() # describe network print("num nodes: ", sl.getNumberOfNodes()) print("num reactions: ", sl.getNumberOfReactions()) # create network sl._createNetwork() # draw network sl.drawNetwork() # print node id's print("node ids: ", sl.getNodeIds())
from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "rabies.xml" sl = SBMLlayout(model_file_name, applyRender=False) sl._describeModel() sl.drawNetwork("rabies_China.pdf")
from pathlib import Path import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "model.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl.setNodeFontSize("X0", 24) def test_font_size_api_singles(): assert sl.getNodeFontSize("A") == 10 assert sl.getNodeFontSize("X0") == 24 sl2 = SBMLlayout(str(model_file)) sl2.setNodeFontSize("all", 18) def test_font_size_api_all(): assert sl2.getNodeFontSize("X0") == 18 assert sl2.getNodeFontSize("A") == 18 assert sl2.getNodeFontSize("B") == 18 assert sl2.getNodeFontSize("C") == 18
if platform.system() == "Windows": model_dir = "C:\\Users\\nrhaw\\Documents\\repos\\libsbml-draw\\model_files\\" # model_file = "C:\\tmp\\copasi.xml" model_file = model_dir + "copasi.xml" #model_file = model_dir + "render_sbml_pink_green.xml" elif platform.system() == "Linux": model_dir = "/home/radix/repos/libsbml-draw/model_files/" model_file = "/home/radix/repos/libsbml-draw/model_files/copasi.xml" else: model_dir = "/Users/natalieh/repos/libsbml-draw/model_files/" model_file = "/Users/natalieh/repos/libsbml-draw/model_files/copasi.xml" #model_file = Path(pkg_resources.resource_filename("libsbml_draw", "model_files/model.xml")) print("model file: \n", model_file) sl = SBMLlayout(model_file) sl._describeModel() ## Draw Original copasi.xml sl.drawNetwork() print("node ids: ", sl.getNodeIds()) print("reaction ids: ", sl.getReactionIds()) sl.setNodeFontStyle("S1", "italic") sl.setNodeColor("S1", "lightpink") sl.setNodeColor("S2", "lightgreen") sl.setNodeFontColor("S1", "white") sl.setNodeFontStyle("S1", "italic")
from libsbml_draw.model.sbml_layout import SBMLlayout model_file_name = "BIOMD0000000013_url.xml" # Poolman2004_CalvinCycle sl = SBMLlayout(model_file_name, applyRender=False) sl._describeModel() #sl.drawNetwork("plant_metabolism.pdf") sl.aliasNode("ATP_ch") sl.aliasNode("ADP_ch") sl.aliasNode("GAP_ch") sl.aliasNode("PGA_ch") sl.regenerateLayout() sl.drawNetwork("plant_metabolism_alias.pdf")
import pkg_resources from libsbml_draw.model.sbml_layout import SBMLlayout #model_file_name = "complicated_nodes-L3V1.xml" model_file_name = "complicated_nodes.xml" model_file = Path(pkg_resources.resource_filename( "libsbml_draw", "model/data/" + model_file_name)) # https://stackoverflow.com/questions/33635439/matplotlib-patch-size-in-points #print("validate: ", SBMLlayout._validate_sbml_filename(str(model_file))) sl = SBMLlayout(str(model_file)) sl._describeModel() #sl.drawNetwork("complicated_nodes.png", figsize=(6,6)) #sl.drawNetwork("complicated_nodes.png", figsize=(8,8)) sl.drawNetwork("complicated_nodes.png") #sl.setNodeFontSize("all", 6) #sl.drawNetwork() #for node in sl.getNodeIds(): # centroid = sl.getNodeCentroid(node)
from libsbml_draw.model.sbml_layout import SBMLlayout file_name = "veronica-network.xml" if platform.system() == "Windows": model_dir = "C:\\Users\\nrhaw\\Documents\\repos\\libsbml-draw\\model_files\\" elif platform.system() == "Linux": model_dir = "/home/radix/repos/libsbml-draw/model_files/" else: model_dir = "/Users/natalieh/repos/libsbml-draw/model_files/" model_file = model_dir + file_name print("model file: \n", model_file) sl = SBMLlayout(model_file) sl._describeModel() my_fig = sl.drawNetwork() color1 = ["S6", "S7", "S5", "S4", "S8"] color2 = ["S0", "S1", "S2", "S3", "S9", "S10", "S11"] for node in color1: sl.setNodeFillColor(node, "lightblue") for node in color2: sl.setNodeFillColor(node, "lightgreen") for reaction in sl.getReactionIds():