Skip to main content

BioC data structures and encoder/decoder for Python

Project description

Build status Latest version on PyPI License

BioC XML format can be used to share text documents and annotations.

bioc exposes an API familiar to users of the standard library marshal and pickle modules.

Development of bioc happens on GitHub: https://github.com/yfpeng/bioc

Getting started

Installing bioc

$ pip install bioc

XML

Encoding the BioC collection object collection:

import bioc
# Serialize ``collection`` to a BioC formatted ``str``.
bioc.dumps(collection)

# Serialize ``collection`` as a BioC formatted stream to ``fp``.
with open(filename, 'w') as fp
    bioc.dump(collection, fp)

Compact encoding:

import bioc
bioc.dumps(collection, pretty_print=False)

Incremental BioC serialisation:

import bioc
with bioc.iterwrite(filename, collection) as writer:
    for document in collection.documents:
        writer.writedocument(document)

Decoding the BioC XML file:

import bioc
# Deserialize ``s`` to a BioC collection object.
collection = bioc.loads(s)

# Deserialize ``fp`` to a BioC collection object.
with open(filename, 'r') as fp:
    collection = bioc.load(fp)

Incrementally decoding the BioC XML file:

import bioc
with bioc.iterparse(filename) as parser:
    collection_info = parser.get_collection_info()
    for document in parser:
        # process document
        ...

get_collection_info can be called after the construction of the iterparse anytime.

Together with Python coroutines, this can be used to generate BioC XML in an asynchronous, non-blocking fashion.

import bioc
with bioc.iterparse(filename) as parser:
    with bioc.iterwrite(dst, parser.get_collection_info()) as writer:
        for document in parser:
            # modify the document
            ...
            writer.writedocument(document)

Json

Encoding the BioC collection object collection:

import biocjson
# Serialize ``collection`` to a BioC Json formatted ``str``.
biocjson.dumps(collection, indent=2)

# Serialize ``collection`` as a BioC Json formatted stream to ``fp``.
with open(filename, 'w') as fp
    biocjson.dump(collection, fp, indent=2)

Compact encoding:

import biocjson
biocjson.dumps(collection)

Decoding the BioC Json file:

import biocjson
# Deserialize ``s`` to a BioC collection object.
collection = biocjson.loads(s)

# Deserialize ``fp`` to a BioC collection object.
with open(filename, 'r') as fp:
    collection = biocjson.load(fp)

Json Lines

Incrementally encoding the BioC structure:

with biocjson.iterparse(filename, level=bioc.PASSAGE) as reader:
    for passage in reader:
        # process passage
        ...

Incrementally decoding the BioC Json lines file:

with biocjson.iterwrite(filename, level=bioc.PASSAGE) as writer:
    for doc in collection.documents:
         for passage in doc.passages:
             writer.write(passage)

Requirements

Developers

Acknowledgment

Webpage

The official BioC webpage is available with all up-to-date instructions, code, and corpora in the BioC format, and other research on, based on and related to BioC.

Reference

  • Comeau,D.C., Doğan,R.I., Ciccarese,P., Cohen,K.B., Krallinger,M., Leitner,F., Lu,Z., Peng,Y., Rinaldi,F., Torii,M., Valencia,V., Verspoor,K., Wiegers,T.C., Wu,C.H., Wilbur,W.J. (2013) BioC: A minimalist approach to interoperability for biomedical text processing. Database: The Journal of Biological Databases and Curation.

  • Peng,Y., Tudor,C., Torii,M., Wu,C.H., Vijay-Shanker,K. (2014) iSimp in BioC standard format: Enhancing the interoperability of a sentence simplification system. Database: The Journal of Biological Databases and Curation.

  • Marques,M., Rinaldi,F. (2012) PyBioC: a python implementation of the BioC core. In Proceedings of BioCreative IV workshop.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bioc-1.2.4.tar.gz (14.1 kB view details)

Uploaded Source

File details

Details for the file bioc-1.2.4.tar.gz.

File metadata

  • Download URL: bioc-1.2.4.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for bioc-1.2.4.tar.gz
Algorithm Hash digest
SHA256 8eb4848c006f829eab1d1f9235e241db461ba956636e0800f23666bc71e2b84b
MD5 8def7155a1839d727c3482a6566d6fe0
BLAKE2b-256 1acfb3aa35c4fc145245a2c42280201a4fedecb02e8beb6e5f7c04df8e9dd9a4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page