usametov / pgxmine

Text mining for pharmacogenomic associations for PharmGKB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PGxMine

This is the codebase for the PGxMine project that uses text-mining to identify papers for curation into PharmGKB. It is a Python3 project that makes use of the Kindred relation classifier along with the BioText project to manage the download of PubMed/PMC and alignment with PubTator.

Viewing the Data

The data can be viewed through the Shiny app. It can be downloaded as TSV files at Zenodo.

To run a local instance of the PGxmine viewer, the R Shiny code can be found in shiny/ and installation instructions are found there too.

Software Dependencies

This project depends on Kindred, scispacy and snakemake. They can be installed by:

pip install -r requirements.txt

Data Dependencies

This project uses a variety of data sources.

A few need to be downloaded as below, apart from DrugBank which needs to be download manually.

  • MeSH (only needed to update the drug list)
  • DrugBank (download manually as account is required and name it drugbank.xml)
  • PharmGKB (used for constructing the drug list and comparisons)

The prepareData.sh script downloads some of the data dependencies and runs some preprocessing to extract necessary data (such as gene name mappings). The commands that it runs are detailed below.

year=`date +"%Y"`

# Download MeSH, dbSNP, Entrez Gene metadata and pharmGKB drug info
sh downloadDataDependencies.sh

# Extract the gene names associated with rsIDs from dbSNP
python linkRSIDToGeneName.py --dbsnp <(zcat data/GCF_000001405.*.gz) --pubtator <(zcat data/bioconcepts2pubtatorcentral.gz) --outFile data/dbsnp_selected.tsv

# Create the drug list with mappings from MeSH IDs to PharmGKB IDs (with some filtering using DrugBank categories)
python createDrugList.py --meshC data/c$year.bin --meshD data/d$year.bin --drugbank drugbank.xml --pharmgkb data/drugs.tsv --outFile data/selected_chemicals.json

# Extract a mapping from Entrez Gene ID to name
zgrep -P "^9606\t" data/gene_info.gz | cut -f 2,3,10 -d $'\t' > data/gene_names.tsv

# Unzip the annotated training data of pharmacogenomics relations
gunzip -c annotations.variant_other.bioc.xml.gz > data/annotations.variant_other.bioc.xml
gunzip -c annotations.variant_star_rs.bioc.xml.gz > data/annotations.variant_star_rs.bioc.xml

Example Run

There is an example input file in the example directory which contains a couple PubMed abstracts in BioC format. The run_example.sh script does a full run extracting chemical/variant associations and is shown below with comments. The final output is three files: mini_unfiltered.tsv, mini_collated.tsv, mini_sentences.tsv.

# Parse and find sentences that mention a chemical, variant and likely a pharmacogenomic assocation (using filter terms)
python findPGxSentences.py --inBioc example/aligned.bioc.xml --filterTermsFile pgx_filter_terms.txt --outBioc example/sentences.bioc.xml

# Train relation classifiers (using the annotations* files as training data), filter for specific chemicals and apply the classifiers to extract associations and output with normalized genes, variants and chemicals
python createKB.py --trainingFiles annotations.variant_star_rs.bioc.xml,annotations.variant_other.bioc.xml --inBioC example/sentences.bioc.xml --selectedChemicals selected_chemicals.json --dbsnp dbsnp_selected.tsv --variantStopwords stopword_variants.txt --genes gene_names.tsv  --outKB example/kb.tsv

# Collate the output of createKB (which in a full run would be ~1800 files) and filter using the relation probability and collated by counting number of papers
python filterAndCollate.py --inData example --outUnfiltered example/mini_unfiltered.tsv --outCollated example/mini_collated.tsv --outSentences example/mini_sentences.tsv

Running with Snakemake

To run a small example of the pipeline using snakemake, run the command below.

MODE=test snakemake --cores 1

To do a full run, you need set up a local instance of BioText with the biocxml format. The command below will run Snakemake on the biotext. You must change BIOTEXT to point towards the biocxml directory in your local instance of BioText. The run will take a while and a cluster is recommended using snakemake's cluster support.

MODE=full BIOTEXT=/path/to/biotext/biocxml snakemake --cores 1

Script Overview

Here is a summary of the main script files. The Snakefile manages the execution of these in the correct ordering.

Main scripts

  • findPGxSentences.py: Identify star alleles then find sentences that mention a chemical and variant
  • createKB.py: Train and apply a relation classifier to extract pharmacogenomic chemical/variant associations
  • filterAndCollate.py: Filter the results to reduce false positives and collate the associations
  • utils/init.py: Big functions for variant normalization and outputting the formatted sentences

Other scripts

Paper

The paper can be recompiled using the dataset using Bookdown. All text and code for stats/figures are in the paper/ directory.

Supplementary Materials

Supplementary materials for the manuscript are found in supplementaryMaterials/.

About

Text mining for pharmacogenomic associations for PharmGKB

License:MIT License


Languages

Language:TeX 52.1%Language:Python 24.9%Language:R 20.8%Language:Shell 2.0%Language:HTML 0.1%