GithubHelp home page GithubHelp logo

matthiaskoenig / libsbgn-python Goto Github PK

View Code? Open in Web Editor NEW
6.0 7.0 0.0 10.49 MB

Python bindings for libsbgn

License: GNU Lesser General Public License v3.0

Python 23.30% XSLT 19.98% HTML 3.18% Makefile 0.07% Jupyter Notebook 44.54% Batchfile 0.10% Game Maker Language 8.84%

libsbgn-python's Introduction

libsbgnpy : Python library for SBGN

GitHub Actions CI/CD Status Current PyPI Version Supported Python Versions GNU Lesser General Public License 3 Codecov Documentation Status Zenodo DOI Black

Python library to work with the Systems Biology Graphical Notation (SBGN). This library is based on the SBGN XML schema and supports reading, writing and validation of SBGN files.

The initial library was generated using generateDS. Additional utility functions for reading, writing, and rendering SBGN documents are provided.

Documentation with examples is available at https://libsbgn-python.readthedocs.io.

  • libsbgn.py python library
  • libsbgnTypes.py SBGN type definitions (GlyphClasses, ArcClasses, Languages)
  • utils.py SBGN utility function like writing & reading of files
  • render.py SBGN rendering
  • test/ unittests
  • examples/ python examples
  • validation/ validation of SBGN files

How to cite

Zenodo DOI

Installation

libsbgnpy is available from pypi and can be installed via:

pip install libsbgnpy

Support

To report bugs, request features or asking questions please file an issue.

License

The libsbgnpy source is released under both the GPL and LGPL licenses version 2 or later. You may choose which license to use the software under.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License or the GNU Lesser General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Funding

Matthias König is supported by the Federal Ministry of Education and Research (BMBF, Germany) within the research network Systems Medicine of the Liver (LiSyM, grant number 031L0054).

Software using libsbgnpy

  • Mimoza takes a model in SBML format and visualizes it in several formats (downloadable as a COMBINE archive).

Python Language Bindings

The python language bindings were created from the XML schema using generateDS and than adapted to include GlyphClasses and ArcClasses.:

/usr/local/bin/generateDS.py -o "libsbgn.py" -s "libsbgnSubs.py" SBGN.xsd

The necessary constraints for GlyphClasses, ArcClasses and Languages were added and some utility functions created.

© 2016-2020 Matthias König

libsbgn-python's People

Contributors

matthiaskoenig avatar

Stargazers

Liao Weiheng avatar  avatar Carissa Bleker avatar Vivek Ruhela avatar sheep avatar Kozo Nishida avatar

Watchers

Kozo Nishida avatar Adrien Rougny avatar Augustin Luna avatar James Cloos avatar  avatar sheep avatar  avatar

libsbgn-python's Issues

PermissionError raise in notes_example.py

When I run the script, I got a error (PermissionError). I think the tempfile creator is the reason. The notations of the error are writen in below:

  File "D:\...\sbgn.py", line 58, in <module>
    write_glyph_notes(fn)
  File "D:\...\sbgn.py", line 34, in write_glyph_notes
    print(utils.write_to_string(sbgn))
  File "C:\...\libsbgnpy\utils.py", line 40, in write_to_string
    write_to_file(sbgn, f.name)
  File "C:\...\libsbgnpy\utils.py", line 27, in write_to_file
    sbgn.write_file(f)
  File "C:\...\libsbgnpy\libsbgn.py", line 794, in write_file
    f = open(outfile, "w")
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\...\\Local\\Temp\\tmpt2he5ted.sbgn'

I run this script using Windows 10. In Windows, no close file no permission to open it, but close the file, file is clean.

render function is down

I believe the service that render_sbgn relies on is down, do you have any recommendations for alternate ways to render these maps? Thanks!

Coverage report

Create coverage report and add unit tests.

  • find which parts are not py3 compatible yet

Supporting SBGN-ML 0.3

Currently, libsbgn-python suports v0.2. Are there any plans to support 0.3? I'm using web based SBGN editor Newt which validates the input against 0.3 so the files generated with libsbgn-python cannot be loaded.

docs not building with nbsphinx on readthedocs

Somehow during the readthedocs build process the libsbgnpy cannot be imported.

ImportError: No module named libsbgnpy.libsbgn

You can ignore this error by setting the following in conf.py:

    nbsphinx_allow_errors = True

This is strange, because it is build from within the git repository having access to the libsbgnpy package via

sys.path.insert(0, os.path.abspath('..'))

Create logo

  • logo for project based on python and SBGN logo

line break not working

Hi,

I am trying to use libsbgnpy library in my project, everything is working good, but line break is not working.
If I read xml file and then render image it's working good, but in case I will create glyph, using library and add into label text attribute with &#xA; like this:

g = libsbgn.glyph(class_=GlyphClass.MACROMOLECULE, id='glyph1')
g.set_label(libsbgn.label(text='structured&#xA;protein'))
g.set_bbox(libsbgn.bbox(x=40, y=120, w=60, h=60))
map.add_glyph(g)

it's not working and in final image is structured&#xA;protein, instead of
structured
protein

Is it bug or I'm just using it in wrong way?

I'm using mac os and python 3.6.5

ConnectionError "sysbioapps.dyndns.org" when rendering an SBGN.

Executing this code from the documentation:

from libsbgnpy import render, utils
import tempfile

sbgn = utils.read_from_file("backend/data/sbgn/R-HSA-15869.sbgn")
f_png = tempfile.NamedTemporaryFile(suffix=".png")
render.render_sbgn(sbgn, image_file=f_png.name,
                   file_format="png")
Image(f_png.name, width=500)

Getting this exception:

Traceback (most recent call last):
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/urllib3/util/connection.py", line 57, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/urllib3/connection.py", line 181, in connect
    conn = self._new_conn()
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/urllib3/connection.py", line 168, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7ffae01fb080>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='sysbioapps.dyndns.org', port=80): Max retries exceeded with url: /Layout/GenerateImage (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ffae01fb080>: Failed to establish a new connection: [Errno -2] Name or service not known',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    file_format="png")
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/libsbgnpy/render.py", line 44, in render_sbgn
    r = requests.post('http://sysbioapps.dyndns.org/Layout/GenerateImage', files=files)
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/requests/api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/home/lance/git/2019/April/biomed-workbench2/venv/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='sysbioapps.dyndns.org', port=80): Max retries exceeded with url: /Layout/GenerateImage (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ffae01fb080>: Failed to establish a new connection: [Errno -2] Name or service not known',))

XML schematron validation

I could not get the schematron validation working with python so far.
I tried the XSLT transformation approach and directly using lxml schematron.

Schema can be transformed, but validation results in

Traceback (most recent call last):
  File "/home/mkoenig/git/libsbgn-python/libsbgnpy/validation/validator.py", line 141, in <module>
    sct_valid = validate_schematron(f)
  File "/home/mkoenig/git/libsbgn-python/libsbgnpy/validation/validator.py", line 123, in validate_schematron
    doc_svrlt = transform_2(doc_sbgn)
  File "src/lxml/xslt.pxi", line 599, in lxml.etree.XSLT.__call__ (src/lxml/lxml.etree.c:175596)
lxml.etree.XSLTApplyError: Failed to evaluate the expression of variable 'arc-count-distinct-1'.

Orientation Enum is lacking the tags' orientations

Orientation of tags (up, right, down, left) are currently not taken into account.
They are just lacking in the Orientation Enum, that could be changed to:

class Orientation(Enum):
    HORIZONTAL = "horizontal"
    VERTICAL = "vertical"
    UP = "up"
    DOWN = "down"
    RIGHT = "right"
    LEFT = "left"

Preventing markup being re-marked-up

Is there any way to mark text as safe (in labels). I have labels with already replaced text, and when saving the xml, the &'s are again replaced as &amp; for example

&beta; is changed to &amp;beta; in the export.

I think the issue lies in this function:

def quote_attrib(inStr):
s1 = isinstance(inStr, BaseStrType_) and inStr or "%s" % inStr
s1 = s1.replace("&", "&amp;")
s1 = s1.replace("<", "&lt;")
s1 = s1.replace(">", "&gt;")
if '"' in s1:
if "'" in s1:
s1 = '"%s"' % s1.replace('"', "&quot;")
else:
s1 = "'%s'" % s1
else:
s1 = '"%s"' % s1
return s1

called here:

quote_attrib(self.text), input_name="text"

libsbgnpy with Python 3

Hi Matthias,

I am trying to switch to Python 3.5.1 from Python 2.7.11 (where libsbgn-python worked perfectly) and having some troubles:

...
    from libsbgnpy import libsbgn
  File "/usr/local/lib/python3.5/dist-packages/libsbgnpy/__init__.py", line 4, in <module>
    from _version import __version__
ImportError: No module named '_version'

It seems to be sort of a relative path issue as if I change inside "/usr/local/lib/python3.5/dist-packages/libsbgnpy/init.py":
from _version import __version__ to from ._version import __version__ this issue disappears. However then it starts complaining about not finding libsbgnTypes (that are present inside my /usr/local/lib/python3.5/dist-packages/libsbgnpy/ folder).

Thanks,
Anna

Update CI

  • automatic releases
  • github actions
  • tox, isort, black

Example for extension & notes

Hi Matthias,

I am using libsbgnpy and I was wondering if you could provide me with
an example illustrating the extension node in a SBGN-ML file.

Say we have the following snippet:

sbgn = ls.sbgn()
map = ls.map()
map.set_language(Language.PD)
sbgn.set_map(map)

g1 = ls.glyph()
g1.set_id("glyph1")
g1.set_class(GlyphClass.MACROMOLECULE)

ext = ls.extensionType( ??? )
g1.set_extension(ext)

map.add_glyph(g1)

What could be a valid input for the method extensionType() ?

Best,
Gael

tox for CI

add tox.ini for local testing (and later CI)

notes and extension values are not decoded

Values of notes and extension are stored as bytes in Notes and Extension objects.
It causes issues when those values are exported to an SBGN-ML file (written as strings of bytes).
They should probably be decoded and stored as strings?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.