Skip to main content

A Python package to generate BEL statements and CX2 networks.

Project description

textToKnowledgeGraph

A Python package to generate BEL statements and CX2 networks.

Table of Contents

Project Description

textToKnowledgeGraph is a Python package that converts natural language scientific text into structured knowledge graphs using the capabilities of advanced language models (LLMs). It can be used for:

  • Generating BEL statements.
  • Extracting entities and interactions from scientific text.
  • Uploading the generated CX2 networks to NDEx.

Dependecies

  • "Python>=3.11",
  • "langchain==0.3.13",
  • "langchain_core==0.3.27",
  • "langchain_openai==0.2.13",
  • "lxml==5.2.1",
  • "ndex2>=3.8.0,<4.0.0",
  • "pandas",
  • "pydantic==2.10.4",
  • "python-dotenv==1.0.1",
  • "Requests==2.32.3"

Glossary

These discusses terms that would be used in this documentation:

  • BEL (Biological Expression Language): BEL is a structured language used to represent scientific findings, especially in the biomedical domain, in a computable format. Learn More: BEL Documentation
  • CX2 (Cytoscape Exchange Format 2): CX2 is a JSON-based format used for storing and exchanging network data in Cytoscape. Learn More: CX2 Specification
  • PMCID (PubMed Central Identifier): A unique identifier for articles archived in PubMed Central (PMC), a free digital repository of biomedical and life sciences journal literature. Learn More: PubMed Central
  • NDEx (Network Data Exchange): NDEx is an online resource that facilitates the sharing, storage, and visualization of biological networks. Learn More: NDEx
  • LangChain: LangChain is a framework for developing applications powered by language models. It allows easy integration of language models with data sources and APIs, enabling workflows like knowledge extraction and retrieval. Learn More: LangChain
  • Cytoscape: Cytoscape is an open-source platform for visualizing and analyzing complex networks, including biological pathways, protein interaction networks, and more. Learn More: Cytoscape
  • Knowledge Graph: A knowledge graph is a structured representation of knowledge in a graph format, where entities are nodes and relationships are edges. It enables intuitive querying, reasoning, and visualization of complex biological data, aiding in understanding biological systems and facilitating discoveries.
  • Pubtator: PubTator is a web-based tool that extracts and annotates biomedical entities and relations from scientific literature. It provides a user-friendly interface for exploring and analyzing scientific texts. Learn More: PubTator
  • OpenAI: OpenAI is an artificial intelligence research lab that develops advanced language models and other AI technologies. It provides APIs for accessing language models and other AI capabilities. In this project, we are making use of gpt-4o model. Other tests were carried out with gpt-3, gpt-4, and gpt-4o-mini. Learn More: OpenAI

Installation

Install the package via pip:

pip install textToKnowledgeGraph

Methodology

  • Features Available

    • BEL Generation: Extracts biological interactions from scientific papers and generates BEL statements.
    • CX2 Network Generation: Converts extracted interactions into CX2 network format for visualization in Cytoscape.
    • Uploading to NDEx: Uploads the generated CX2 networks to NDEx for sharing and visualization.
  • BEL Generation

    • The user provides a PMC ID and an openai API key as input. This PMC ID is used to fetch the XML version of the scientific paper from pubtator's API. The XML version of the paper is then processed and broken down into a list of dictionaries where each entry contains the index and the text of the paragraph from the XML file. Each entry also contains annotations from the pubtator XML file. This result is saved to a json file.
    • The prompt that directs the model on what to do is defined in a prompt file called prompt_file_v5.txt which is processed to extract the prompt that is being passed to the model for instructions on how to extract the BEL statements.
    • Model Creation:
      • The bel_model.py script defines and initializes the model used to extract BEL statements.
      • It includes schema definitions, API call handling, and model initialization.
      • The get_interactions.py script handles the extraction of interactions, prompt processing, and chain initialization.
  • CX2 Network Generation

    • Converts extracted interactions into CX2 network format for visualization in Cytoscape.
  • Uploading to NDEx

    • Uploads the generated CX2 networks to NDEx for sharing and visualization. In order to use this function, you need to provide your NDEx email and password as an argument.

Usage

To install python package:

pip install textToKnowledgeGraph

Required parameters:

  • pmc_id: can only process one at a time

  • api_key: open_ai api key

Optional parameters:

  • ndex_email: The NDEx email for authentication. ndex_password: The NDEx password for authentication.

Expected output:

  • BEL statements: extracted from the paper
  • CX2 network: generated from the extracted BEL statements
  • Example of CX2 network: CX2 network image of paper:PMC8354587

To run in an interactive python environment:

# Process pmcid without uploading to ndex
from textToKnowledgeGraph import process_paper
 
process_paper("PMC8354587","sk-....") 

# Process pmcid and upload to ndex

from textToKnowledgeGraph import process_paper

process_paper("PMC8354587","sk-..", "john_doe@gmail.com", "xxxx", upload_to_ndex=True)

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

texttoknowledgegraph-0.2.1.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

textToKnowledgeGraph-0.2.1-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file texttoknowledgegraph-0.2.1.tar.gz.

File metadata

  • Download URL: texttoknowledgegraph-0.2.1.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for texttoknowledgegraph-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3fe6c6440f66235325364864da0b276547e7ea30409832485f1eb5e0b6da3481
MD5 35aa721da7527635384a9a2414258522
BLAKE2b-256 bf7fed896e324ead279769827858a7b4a4f771994dd69ddbb77f8b99ef93e10f

See more details on using hashes here.

File details

Details for the file textToKnowledgeGraph-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for textToKnowledgeGraph-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ce6f95042bafc5791b3e7f556d99ddd15b8ce4d3377f6391ffe3924f59a32a3
MD5 b9a879a9f4ae647b0ab35b383698e96a
BLAKE2b-256 1ddb3f83110fec55a103e20b84fdce4c8f1877dedb12ff11556059d605f0f905

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