How to load the PathwayCommons OWL file into a local QLever instance?
What are we talking about?
QLever (pronounced “clever”) is a graph database for RDF triplets supporting the SPARQL query language.
PathwayCommons is an initiative to gather multiple sources of metabolic pathways, from multiple databases, and merge them in a single entrypoint, using the standard BioPAX ontology. Pathway-Commons provides a compressed OWL file for each release, as well as an API.
What do we want to do?
The objective of this tutorial is to show how one can load the Pathway-Commons OWL file in a local QLever instance, for unlimited local SPARQL queries.
Steps
Install QLever
QLever default installation methods uses a Docker container and an eponym companion Python wrapper.
You can install the Python wrapper from PyPI:
python3 -m venv .venv/
source .venv/bin/activate
pip install qlever
Install podman or Docker
qlever relies on a container to run. You will need a working install of Docker or podman. In my case, I chose podman.
If you chose Docker, you will need to adapt the Qleverfile sample below.
Prepare the QLeverfile QLever configuration file
# Qleverfile for PathwayCommons BioPAX, use with https://github.com/ad-freiburg/qlever-control
#
# qlever get-data #
# qlever index #
# qlever start #
[data]
NAME = pathwaycommons
PATHWAYCOMMONS_FILE = resource/pc-biopax_v14.ttl
PATHWAYCOMMONS_VERSION = "v14"
GET_DATA_CMD = mkdir -p rdf-input && cp "${PATHWAYCOMMONS_FILE}" rdf-input/
DESCRIPTION = BioPAX data from PathwayCommons "${PATHWAYCOMMONS_VERSION}"
[index]
INPUT_FILES = rdf-input/*
# Before running qlever index, convert the rdf from OWL format to ttl:
# robot convert --input "INPUT.{rdf,owl}" --format ttl --output "rdf-input/OUTPUT.ttl"
# As there is multiline statements, run qlever with --parallel-indexing false:
# qlever index --parallel-indexing false
CAT_INPUT_FILES = cat rdf-input/*.ttl
SETTINGS_JSON = { "ascii-prefixes-only": true, "num-triples-per-batch": 1000000, "prefixes-external": [""] }
WITH_TEXT_INDEX = false
[server]
PORT = 7012
ACCESS_TOKEN = ${data:NAME}_3xq0t73sEtbb
MEMORY_FOR_QUERIES = 10G
CACHE_MAX_SIZE = 5G
[runtime]
SYSTEM = podman
IMAGE = docker.io/adfreiburg/qlever:commit-305daf3
[ui]
UI_CONFIG = Qleverfile-ui.yml
Get the PathwayCommons OWL file
The PathwayCommons OWL file can be downloaded from https://download.baderlab.org/PathwayCommons/. We will use the latest PathwayCommons version (v14):
wget -O resource/pc-biopax_v14.owl.gz https://download.baderlab.org/PathwayCommons/PC2/v14/pc-biopax.owl.gz
Convert the OWL file in turtle format
QLever does not support the Web Ontology Language format as input. So we will first need to convert the .owl file into a .ttl (Turtle) ontology format.
To do so, we will use Apache Jena riot CLI, that allows to stream the input OWL file into a turtle file, thus avoiding to load the complete knowledge graph in memory, which could be a problem for local machine, and even regular server.
So, you will need to download a Apache Jena release from https://jena.apache.org/download/index.cgi. riot CLI is in archive bin folder.
To avoid an error during the conversion, we will replace the square braquets in an “rdf:about” string, and into the corresponding URL encoded equivalent:
15:55:16 ERROR riot :: [line: 50708930, col: 64] <panther:_[GnRH_GnRHR]_gnas_s808_csa54_> : [Posn 10] Bad character in IRI path: '[' (U+005B)
import urllib.parse
safe_string = urllib.parse.quote_plus("[GnRH_GnRHR]")
print(safe_string)
%5BGnRH_GnRHR%5D
# First, unzip the archive
gunzip -k resource/pc-biopax_v14.owl.gz
sed 's|panther:_\[GnRH_GnRHR\]|panther:_%5BGnRH_GnRHR%5D|g' ./resource/pc-biopax_v14.owl > ./resource/pc-biopax_v14_urlencode_brackets.owl
Then, to convert the owl file into ttl format with riot, run
riot --nocheck --out=ttl ./resource/pc-biopax_v14_urlencode_brackets.owl > ./resource/pc-biopax_v14.ttl
Build the QLever index
qlever get-data
qlever index --parallel-parsing false
Warning: you might need to disable SELinux temporarily to avoid permission error with qlever container.
Start the QLever server
qlever start
Start the QLever user interface
To create a Qleverfile-ui.yml configuration file, comment the UI_CONFIG line in the Qleverfile and launch the following command: it will create a new default Qleverfile-ui.yml file from the container image. Then, uncomment back the line in Qleverfile and relaunch the command.
qlever ui --name pathwaycommons
Open https://localhost:8176 and enjoy your local Qlever instance of PathwayCommons!