Exemple #1
0
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")
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)
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")

sl.setReactionColor("_J0", "blue")
sl.setReactionCurveWidth("_J0", 1)

# Draw Pink and Green 
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=True)

sl._describeModel()

sl.drawNetwork("Boris_EJB.png")
sl.drawNetwork("Boris_EJB.pdf")

sl2 = SBMLlayout(str(model_file))

sl2._describeModel()

sl2.drawNetwork()
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")
Exemple #6
0
#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()

sl.setNodeColor("all", "#0000ff30")
sl.setReactionColor("all", "blue")
Exemple #7
0
        "model/data/" + MODEL_FILE_NAME))


sl = SBMLlayout(str(MODEL_FILE))

sl._describeModel()

assert sl.getNumberOfNodes() == 6
assert sl.getNumberOfReactions() == 5

assert sl.getNodeFontSize("ABCDEFG") == 12
assert sl.getNodeFontWeight("F") == "normal"

assert sl.getNodeFillColor("E") == "#a0e0a030"

sl.drawNetwork("larger_pathway.png")

# sl.setReactionCurveWidth("all", 12)

sl.drawNetwork()


sl.writeSBMLFile("ftest_larger_pathway.xml")


slr =  SBMLlayout("ftest_larger_pathway.xml")

slr.drawNetwork()

assert sl.getNumberOfNodes() == 6
assert sl.getNumberOfReactions() == 5
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")
Exemple #9
0
from pathlib import Path
import pkg_resources

from libsbml_draw.model.sbml_layout import SBMLlayout

#model_file_name = "GlycolysisOriginal_L3V1.xml"
#model_file_name = "GlycolysisOriginal-L3V1.xml"
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()

print("node font size: ", sl.getNodeFontSize("ATP"))

sl.drawNetwork("GlycolysisOriginal.pdf")

#sl.drawNetwork(figsize=(20,20))

#sl.setNodeFontSize("all", 8)

#sl.drawNetwork()

#for node in sl._SBMLlayout__network.nodes.values():
#    print("node id, name: ", node.id, node.name)
from pathlib import Path
import pkg_resources

from libsbml_draw.model.sbml_layout import SBMLlayout

model_file_name = "random_network.xml"

#model_file = Path(pkg_resources.resource_filename("libsbml_draw", "model/data/" + model_file_name))


sl = SBMLlayout(model_file_name, applyRender=False)

sl._describeModel()

sl.drawNetwork("random_4s_2r.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))

applyRender = True

sl = SBMLlayout(str(model_file), applyRender=applyRender)

sl._describeModel()

sl.drawNetwork()

sl.lockNode("X0")
sl.lockNode("A")    

sl.aliasNode("B")

sl.regenerateLayout()

sl.drawNetwork("model_simple_alias_B_lock_A_X0.pdf")    

print("node ids: ", sl.getNodeIds())
print()

#print("string: ", sl._SBMLlayout__getSBMLWithLayoutString())
Exemple #12
0
assert sl.getReactionCurveWidth("_J1")[0] == ("A", "SUBSTRATE", 5)
assert sl.getReactionCurveWidth("_J1")[1] == ("B", "PRODUCT", 5)

assert sl.getReactionCurveWidth("_J2")[0] == ('B', 'SUBSTRATE', 5)
assert sl.getReactionCurveWidth("_J2")[1] == ('D', 'PRODUCT', 5)

assert sl.getReactionCurveWidth("_J5")[0] == ('D', 'SUBSTRATE', 5)
assert sl.getReactionCurveWidth("_J5")[1] == ('X1', 'PRODUCT', 5)

assert sl.getReactionCurveWidth("_J3")[0] == ('A', 'SUBSTRATE', 5)
assert sl.getReactionCurveWidth("_J3")[1] == ('C', 'PRODUCT', 5)

assert sl.getReactionCurveWidth("_J4")[0] == ('C', 'SUBSTRATE', 5)
assert sl.getReactionCurveWidth("_J4")[1] == ('D', 'PRODUCT', 5)

sl.drawNetwork(scaling_factor=0.75)

assert sl.getNumberOfNodes() == 6
assert sl.getNumberOfReactions() == 6

sl.setNodeEdgeColor("X1", "#ff0000")
sl.setNodeFillColor("X1", "#ff000030")
sl.setNodeEdgeWidth("X1", 3)

assert sl.getNodeEdgeColor("X1") == "#ff0000ff"
assert sl.getNodeFillColor("X1") == "#ff000030"
assert sl.getNodeEdgeWidth("X1") == 3

assert sl.getNodeEdgeColor("A") == "#0000ff"
assert sl.getNodeFillColor("A") == "#c9e0fb"
Exemple #13
0
layout.regenerateLayout()
layout.regenerateLayout()
layout.regenerateLayout()
[layout.setCompartmentEdgeColor(i, 'grey') for i in layout.getCompartmentIds()]
[layout.setCompartmentLineWidth(i, 10) for i in layout.getCompartmentIds()]
[layout.setNodeEdgeWidth(i, 10) for i in layout.getNodeIds()]
[layout.setNodeFontSize(i, 40) for i in layout.getNodeIds()]
[
    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('compartment_network.png')

# layout.regenerateLayout()
# layout.regenerateLayout()
# layout.regenerateLayout()
# layout.regenerateLayout()
# layout.regenerateLayout()
# layout.drawNetwork('compartment_network.png')
#
# layout.writeSBMLFile('2CompartmentModelWithLayout.xml')
#
# from libsbml_draw.model.sbml_layout import SBMLlayout
#
# # Create a SBMLlayout object.
# layout = SBMLlayout('2CompartmentModel.xml')
#
Exemple #14
0
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())

if "copasi" in model_file:
    # set node properties
    sl.setNodeColor("S1", "pink")
    sl.setNodeColor("S2", "green")
    sl.setNodeColor("S1", "Verdana")
    sl.setNodeColor("S1", "white")
    sl.setNodeFontsize("S1", 18)
    sl.setNodeFontstyle("S1", "italic")

    sl.setNodeFontsize("S2", 24)
    sl.setNodeFontstyle("S2", "oblique")
Exemple #15
0
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():
    sl.setReactionCurveWidth(reaction, 2)

sl.drawNetwork()
Exemple #16
0
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")
Exemple #17
0
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():
    print("node fs: ", node.font_size, node.font_family)

sl.writeSBMLFile("largerpathway_out.xml")

#sl.drawNetwork(scaling_factor=.5)
Exemple #18
0
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)

# layout.regenerateLayout()
# layout.regenerateLayout()
# layout.regenerateLayout()
# layout.regenerateLayout()
# layout.regenerateLayout()
# layout.drawNetwork('compartment_network.png')
#
# layout.writeSBMLFile('2CompartmentModelWithLayout.xml')
#
# from libsbml_draw.model.sbml_layout import SBMLlayout
#
# # Create a SBMLlayout object.
# layout = SBMLlayout('2CompartmentModel.xml')
#
Exemple #19
0
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 = "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()
Exemple #21
0
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"

assert sl.getNodeEdgeColor("glycerate_3_phosphate") == "#969696"
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")
Exemple #23
0
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()

fig = sl.drawNetwork()
#fig = sl.drawNetwork(node_mutation_scale=5)

#sl.setArrowheadScale(1, 15)
#sl.setArrowheadScale(4, 15)

#fig = sl.drawNetwork(node_mutation_scale=5)
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)
#    print("centroid: ", centroid[0], ", ", centroid[1])
#    print("width: ", sl.getNodeWidth(node))
#    print("height: ", sl.getNodeHeight(node))
    
#for node in sl._SBMLlayout__network.nodes.values():
#    print("edge_color: ", node.edge_color)    
#    print("fill_color: ", node.fill_color) 
from libsbml_draw.model.sbml_layout import SBMLlayout

model_file_name = "BIOMD0000000091_url.xml"
# Proctor2005 - Actions of chaperones and their role in ageing

sl = SBMLlayout(model_file_name, applyRender=False)

sl._describeModel()

sl.drawNetwork("alzheimers_chaperones_aging.pdf")