Skip to main content

JATS XML generator.

Project description

jats-generator

Generate JATS XML file from journal article data.

Using objects defined in elifearticle as data structure, this library generates JATS XML output for a research article.

No article body content is supported yet, though this library can output at least the following:

  • Journal metadata (journal title, publisher name, issn, volume)
  • Article metadata (title, doi, pub date, history dates, abstract, copyright, subject categories, research organisms)
  • Authors, editors, group authors, author affiliations, correspondence, conflicts of interest
  • Permissions (copyright statement, copyright year, copyright holder, license)
  • Datasets
  • Funding data
  • Ethics

One way to populate the elifearticle objects with data, as is used by eLife from CSV files, relies on using the ejpcsvparser library by using generate.build_article_from_csv(), resulting in an Article object. The Article can then be used as input to generate.build_xml() or generate.build_xml_to_disk() which will produce the JATS XML output.

A configparser object can be populated from the jatsgenerator.cfg file, where a different config section per journal name can be included, and building it using the jatsgenerator.config module,

Some sample CSV data input and JATS XML output files can be found in the tests/test_data/ folder, which are the basis for the automated tests.

Requirements and install

a) Install from pypi package index

pip install jatsgenerator

b) Install locally

Clone the git repo

git clone https://github.com/elifesciences/jats-generator.git

Create a python virtual environment and activate it

./install.sh

Configuration

The jatsgenerator.cfg configuration file provided in this repository can be changed in order to write slightly different JATS XML output, depending on the journal.

Example usage

This library is meant to be integrated into another operational system, where the elifearticle objects can be populated with sufficient data to produce complete JATS XMl output, however the following is a simple example using interactive Python:

>>> from elifearticle.article import Article, Contributor
>>> from jatsgenerator import generate
>>> from jatsgenerator.conf import raw_config, parse_raw_config
>>> article_object = Article("10.7554/eLife.00666", "Article title")
>>> article_object.abstract = "An abstract."
>>> article_object.add_contributor(Contributor("author", "Surname", "Given"))
>>> article_object.add_contributor(Contributor("editor", "Orr", "Edit"))
>>> jats_config = parse_raw_config(raw_config("elife"))
>>> article_xml_object = generate.build_xml(None, article_object, jats_config)
>>> print(article_xml_object.output_xml())

The JATS XML output, pretty formatted, will look something like this:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.1d3 20150301//EN"  "JATS-archivearticle1.dtd">
<article article-type="research-article" dtd-version="1.1d3" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">
<!--generated by jats-generator at 2021-09-02 14:18:33 from version 6cd2bf35c814117f5e5966ec415e01cedbdcd7de-->
    <front>
        <journal-meta>
            <journal-id journal-id-type="nlm-ta">elife</journal-id>
            <journal-id journal-id-type="publisher-id">eLife</journal-id>
            <journal-title-group>
                <journal-title>eLife</journal-title>
            </journal-title-group>
            <issn publication-format="electronic">2050-084X</issn>
            <publisher>
                <publisher-name>eLife Sciences Publications, Ltd</publisher-name>
            </publisher>
        </journal-meta>
        <article-meta>
            <article-id pub-id-type="doi">10.7554/eLife.00666</article-id>
            <title-group>
                <article-title>Article title</article-title>
            </title-group>
            <contrib-group>
                <contrib contrib-type="author">
                    <name>
                        <surname>Surname</surname>
                        <given-names>Given</given-names>
                    </name>
                </contrib>
            </contrib-group>
            <contrib-group content-type="section">
                <contrib contrib-type="editor">
                    <name>
                        <surname>Orr</surname>
                        <given-names>Edit</given-names>
                    </name>
                    <role>Reviewing editor</role>
                </contrib>
            </contrib-group>
            <abstract>
                <p>An abstract.</p>
            </abstract>
        </article-meta>
    </front>
    <back>
        <sec id="s1" sec-type="additional-information">
            <title>Additional information</title>
        </sec>
    </back>
</article>

Run code tests

Use pytest for testing, install it if missing:

pip install pytest

Run tests

pytest

Run tests with coverage

coverage run -m pytest

then report on code coverage

converage report -m

License

Licensed under MIT.

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

jatsgenerator-0.12.0.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jatsgenerator-0.12.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file jatsgenerator-0.12.0.tar.gz.

File metadata

  • Download URL: jatsgenerator-0.12.0.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.10

File hashes

Hashes for jatsgenerator-0.12.0.tar.gz
Algorithm Hash digest
SHA256 65a4e44d4e4530202c4911e426a6e555d58172f46dc0beb8e7d977c4f173a4f0
MD5 3c6d7f08fc35ef0e4eeceda7c64295b2
BLAKE2b-256 c3cbe4674c7791d7e9ecae8417c634b53fd585d316693b7e38379dc9a5f86733

See more details on using hashes here.

File details

Details for the file jatsgenerator-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: jatsgenerator-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.10

File hashes

Hashes for jatsgenerator-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e2f0bc60ca89d5eb900759f9556ed921b63d4d6a86bd1824d8ddd43c61cbf3c
MD5 1f767d6dc28c16a16128ad9b15ffffd0
BLAKE2b-256 881efca1549937ad8e1d7ee4c26c8fc1eccd1653eb1c2f6e448c976fb7c94fca

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