def test_with_libsbml_draw(self): from collections import OrderedDict opt = OrderedDict( k=20.0, # k boundary=1, # boundary magnatism=50, # magnatism grav=5, # grav, has to be > 5 for effect baryx=500.0, # baryx baryy=500.0, # baryy autobary=1, # autobary enable_comps=0, # enable compartments // breaks the algorithm prerandomize=0, # pre-randomize padding=20.0 # padding ) s = Style() # edge attributes # s.edge.edgecolor = 'grey' # s.edge.fillcolor = 'grey' # s.edge.width = 15 # font attributes # s.font.color = 'black' # s.font.size = 35 # s.font.weight = 'bold' # node attributes # s.node.edgecolor = '#b36b00' # s.node.fillcolor = '#ffcc80' # s.node.edgewidth = 5 # compartment attributes # s.compartment.edgecolor = 'black' # s.compartment.fillcolor = '#ffebcc' # s.compartment.linewidth = 20 # arrow attributes # s.arrow.scale = 50 sl = SBMLlayout(self.sbml_fname, autoComputeLayout=True, # style=s, layout_alg_options=opt) # for i in range(10): # sl.regenerateLayout() sl.drawNetwork(self.image_fname, show=False, scaling_factor=1.0) sl.writeSBML(self.sbml_with_layout) print('saved to {}'.format(self.image_fname))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from pathlib import Path import pkg_resources from libsbml_draw import SBMLlayout model_file_name = "model.xml" model_file = Path( pkg_resources.resource_filename("libsbml_draw", "model/libs/" + model_file_name)) sl = SBMLlayout(str(model_file)) sl.describeModel()
fname = r'C:\Users\cwelsh\Downloads\graphfavb\BIO64_layout.xml' fname = r'D:\ReproduciblePaper\BIOMD64\diagram\Teusink_layout.xml' fname = r'D:\ReproduciblePaper\BIOMD64\model\JWSOnline_Teusink.xml' fnameimg = r'D:\ReproduciblePaper\BIOMD64\model\image.png' if os.path.isfile(fnameimg): os.remove(fnameimg) style = Style() style.font.size = 35 style.edge.edgecolor = '#808080' style.edge.fillcolor = '#4d4d4d' style.edge.width = 8 style.node.edgecolor = '#ff8c1a' style.node.fillcolor = '#ffe6cc' style.node.edgewidth = 8 style.arrow.scale = 75 s = SBMLlayout(fname, style=style) for i in range(1): fnameimg = fr'D:\ReproduciblePaper\BIOMD64\model\image{i}.pdf' s.regenerateLayout() # s.setReactionColor('all', 'black') # s.setReactionCurveWidth('all', 25) s.apply_style() s.drawNetwork(show=False, save_file_name=fnameimg) s.writeSBML()
def test_with_libsbml_draw2(self): sl = SBMLlayout(self.sbml_with_layout, autoComputeLayout=True) # sl.drawNetwork(self.image_fname, show=False, scaling_factor=1.0) sl.writeSBML(self.sbml_with_layout2)
return s import os from libsbml_draw import SBMLlayout, biomodels_download model_id = 'BIOMD0000000001' fname = model_id + '.xml' # download the model biomodels_download(model_id, fname) s = SBMLlayout(fname) s.drawNetwork(model_id + ".png") s.writeSBMLFile(model_id + 'layout.xml') # x = s.getBoundarySpeciesIds() # print(x) # ''' # <species boundaryCondition="true" compartment="cell" hasOnlySubstanceUnits="true" id="R5P" # initialAmount="18" metaid="metaid_0000020" name="ribose-5-phosphate"> # ''' # expected = ['ribose-5-phosphate'] # # # # draw the network
def setUp(self) -> None: self.sbml = self.get_model_from_url() self.sl = SBMLlayout(self.sbml_fname, applyRender=True)
class TestWorksWithBioModels(unittest.TestCase): base_url = "https://www.ebi.ac.uk/biomodels-main/download?mid" model_id = 'BIOMD0000000091' sbml_fname = os.path.join(os.path.dirname(__file__), 'sbmlmodel.xml') sbml_layout_fname = os.path.join(os.path.dirname(__file__), 'sbmlmodel_with_layout.xml') image_fname = os.path.join(os.path.dirname(__file__), 'network.png') expected_number_of_compartments = 0 expected_number_of_nodes = 16 expected_number_of_reactions = 23 tear_down = False def get_model_from_url(self): self.model_file_name = f"{self.model_id}_url.xml" model_url = f'{self.base_url}={self.model_id}' # get the model directly from url sbml = requests.get(model_url).content.decode('utf-8') with codecs.open(self.sbml_fname, 'w', 'utf-8') as f: f.write(sbml) return sbml def tearDown(self) -> None: if self.tear_down: for i in [self.sbml_fname, self.image_fname, self.sbml_layout_fname]: if os.path.isfile(i): os.remove(i) def setUp(self) -> None: self.sbml = self.get_model_from_url() self.sl = SBMLlayout(self.sbml_fname, applyRender=True) def test_setup(self): self.get_model_from_url() self.assertTrue(os.path.isfile(self.sbml_fname)) def test_load_from_biomodels(self): self.assertIsInstance(self.sl, SBMLlayout) def do_describe(self): desc = self.sl.describeModel() return desc def test_number_of_nodes(self): described = self.do_describe() self.assertEqual(self.expected_number_of_nodes, described['number_of_nodes']) def test_number_of_compartments(self): described = self.do_describe() self.assertEqual(self.expected_number_of_compartments, described['number_of_compartments']) def test_number_of_reactions(self): described = self.do_describe() self.assertEqual(self.expected_number_of_reactions, described['number_of_reactions']) def test_draw_network_and_save_to_pdf(self): self.sl.drawNetwork(self.image_fname, show=False, scaling_factor=1.0) self.assertTrue(os.path.isfile(self.image_fname)) def test_save_sbml_to_file(self): self.sl.drawNetwork(self.image_fname, show=False, scaling_factor=1.0) self.sl.writeSBML(self.sbml_layout_fname) self.assertTrue(os.path.isfile(self.sbml_layout_fname))