Skip to content

Parsing databases for creating a comprehensive metabolite-gene interaction network

This tutorial demonstrates how to parse and integrate data from the Human Metabolome Database (HMDB), Reactome, and KEGG to create a comprehensive metabolite-gene interaction network (in AnnData format). The resulting network can be used for various bioinformatics analyses, including enrichment analysis and subsequent graph-based analyses.

Installation

From PyPI

pip install cospa

From Source

pip install git+https://github.com/compbioclub/COSPA.git@main

Importing Required Libraries

import os
import pandas as pd
import numpy as np
import cospa.parsing_database as pdb

Human Metabolome Database (HMDB)

Data Download

HMDB XML files can be downloaded from https://hmdb.ca/downloads

e.g., All Metabolites: https://hmdb.ca/system/downloads/current/hmdb_metabolites.zip

Parsing HMDB XML Files

Once we have downloaded and extracted the HMDB XML files, we can parse them to extract compound mapping information and metabolite-gene interactions by using the pdb.parse_hmdb_xml() function.

# filename = "hmdb_serum_metabolites.xml"
filename = "./hmdb/hmdb_all_metabolites.xml"
df = pdb.parse_hmdb_xml(filename)

The df DataFrame contains information about metabolites, including their IDs (HMDB, KEGG, CHEBI), names, chemical formulas, and associated genes.

df
accession name chemical_formula average_molecular_weight monisotopic_molecular_weight chebi_id kegg_id pubchem_compound_id protein_associations_protein_accession protein_associations_uniprot_id protein_associations_gene_name
0 HMDB0000001 1-Methylhistidine C7H11N3O2 169.1811 169.085127 50599 C01152 92105 [HMDBP00473, HMDBP00474] [Q96KN2, O60678] [CNDP1, PRMT3]
1 HMDB0000002 1,3-Diaminopropane C3H10N2 74.1249 74.084398 15725 C00986 428 [HMDBP00217, HMDBP00219, HMDBP00390, HMDBP0039... [P52788, P49366, P19801, Q16853, O75106, P1770... [SMS, DHPS, ABP1, AOC3, AOC2, AMD1, ODC1]
2 HMDB0000005 2-Ketobutyric acid C4H6O3 102.0886 102.031694 30831 C00109 58 [HMDBP00012, HMDBP00046, HMDBP00050, HMDBP0029... [P11177, P08559, P29803, P21953, P12694, Q0221... [PDHB, PDHA1, PDHA2, BCKDHB, BCKDHA, OGDH, CTH...
3 HMDB0000008 2-Hydroxybutyric acid C4H8O3 104.1050 104.047344 50613 C05984 440864 [HMDBP00054, HMDBP00355, HMDBP00483, HMDBP0089... [P09622, O00204, P22309, Q6ZMR3, P07195, P0786... [DLD, SULT2B1, UGT1A1, LDHAL6A, LDHB, LDHC, LD...
4 HMDB0000010 2-Methoxyestrone C19H24O3 300.3921 300.172545 1189 C05299 440624 [HMDBP00272, HMDBP00449, HMDBP00458, HMDBP0047... [P21964, Q9BY64, P06133, P22310, P36537, P1666... [COMT, UGT2B28, UGT2B4, UGT1A4, UGT2B10, UGT2B...
... ... ... ... ... ... ... ... ... ... ... ...
217915 HMDB0304947 Nordeoxycholic acid C23H38O4 378.5530 378.277010 314374 [] [] []
217916 HMDB0304950 3-Oxo-5beta-cholanoic acid C24H38O3 374.5650 374.282095 543448 [] [] []
217917 HMDB0304951 Glycerol 1-myristate C17H34O4 302.4550 302.245710 75562 79050 [] [] []
217918 HMDB0304953 O-Phenolsulfonic acid C6H6O4S 174.1700 173.998680 71049 11867 [] [] []
217919 HMDB0304954 d-Fucitol C6H14O5 166.1724 166.084124 445724 [] [] []

217920 rows * 11 columns

We can save the parsed data to a CSV file for future reference (CHEBI-KEGG mapping).

df.to_csv("hmdb_all_metabolites.csv", index=False)

Extracting Metabolite-Gene Interactions from HMDB

We can extract metabolite-gene interactions gene_compound_df (pairwise), gene-gene interactions gene_relation_df (pairwise, second-order neighbors connected via metabolites), and compound-compound interactions compound_relation_df (pairwise, second-order neighbors connected via genes) from the parsed HMDB data using the pdb.extract_hmdb_relations() function.

gene_compound_df, gene_relation_df, compound_relation_df = pdb.extract_hmdb_relations(df)
gene_compound_df
gene compound
0 Q96KN2 50599
1 O60678 50599
2 P52788 15725
3 P49366 15725
4 P19801 15725
... ... ...
148851 nan 29476
148852 nan 29507
148853 nan 17397
148854 nan 75562
148855 nan 71049

148856 rows * 2 columns

gene_relation_df
gene1 gene2
0 O60678 Q96KN2
1 P52788 Q16853
2 P49366 P52788
3 P49366 Q16853
4 P19801 P52788
... ... ...
2437291 A0A2U8U2L6 A0A2U8U2M1
2437292 A0A2U8U2L5 A5PHD6
2437293 A0A2U8U2L5 A0A2U8U2M8
2437294 A0A2U8U2L5 A0A2U8U2M1
2437295 A0A2U8U2L5 A0A2U8U2L6

2437296 rows * 2 columns

compound_relation_df
compound1 compound2
0 50599 85981
1 50599 5764
2 15725 17509
3 15725 17312
4 15725 15746
... ... ...
43649065 71049 83094
43649066 71049 75228
43649067 71049 90227
43649068 71049 71267
43649069 71049 75562

43649070 rows * 2 columns

Mapping Uniprot gene id to gene symbol

We can map the Uniprot gene IDs to gene symbols using the pdb.apply_mapping_and_cleanup() function. This function takes a DataFrame, a mapping file path, and other parameters to perform the mapping and cleanup.

# all_gene_compound_df, all_gene_relation_df
gene_compound_df = pdb.apply_mapping_and_cleanup(
    df=gene_compound_df,
    mapping_file_path="./hgnc_complete_set.txt",
    mapping_sep="\t",
    origin_col="gene",
    target_col="symbol",
    origin_ref_col="uniprot_ids",
    target_ref_col="symbol",
    origin_col_dtype=str,
    origin_ref_dtype=str,
)
gene_relation_df = pdb.apply_mapping_and_cleanup(
    df=gene_relation_df,
    mapping_file_path="./hgnc_complete_set.txt",
    mapping_sep="\t",
    origin_col="gene1",
    target_col="symbol1",
    origin_ref_col="uniprot_ids",
    target_ref_col="symbol",
)
gene_relation_df = pdb.apply_mapping_and_cleanup(
    df=gene_relation_df,
    mapping_file_path="./hgnc_complete_set.txt",
    mapping_sep="\t",
    origin_col="gene2",
    target_col="symbol2",
    origin_ref_col="uniprot_ids",
    target_ref_col="symbol",
)
Mapping applied. 'symbol' column created.
Cleanup: Dropped 16026 rows due to missing data in ['symbol'].
Mapping applied. 'symbol1' column created.
Cleanup: Dropped 115100 rows due to missing data in ['symbol1'].
Mapping applied. 'symbol2' column created.
Cleanup: Dropped 50324 rows due to missing data in ['symbol2'].

gene_compound_df
gene compound symbol
0 Q96KN2 50599 CNDP1
1 O60678 50599 PRMT3
2 P52788 15725 SMS
3 P49366 15725 DHPS
4 P19801 15725 AOC1
... ... ... ...
132825 P60484 32849 PTEN
132826 Q3V6T2 32849 CCDC88A
132827 Q9NRI5 32849 DISC1
132828 P18283 64090 GPX2
132829 Q96FZ2 50120 HMCES

132830 rows * 3 columns

gene_relation_df
gene1 gene2 symbol1 symbol2
0 O60678 Q96KN2 PRMT3 CNDP1
1 P52788 Q16853 SMS AOC3
2 P49366 P52788 DHPS SMS
3 P49366 Q16853 DHPS AOC3
4 P19801 P52788 AOC1 SMS
... ... ... ... ...
2271867 P31749 Q3V6T2 AKT1 CCDC88A
2271868 P31749 Q9NRI5 AKT1 DISC1
2271869 P60484 Q3V6T2 PTEN CCDC88A
2271870 P60484 Q9NRI5 PTEN DISC1
2271871 Q3V6T2 Q9NRI5 CCDC88A DISC1

2271872 rows * 4 columns

gene_relation_df
gene1 gene2 symbol1 symbol2
0 O60678 Q96KN2 PRMT3 CNDP1
1 P52788 Q16853 SMS AOC3
2 P49366 P52788 DHPS SMS
3 P49366 Q16853 DHPS AOC3
4 P19801 P52788 AOC1 SMS
... ... ... ... ...
2271867 P31749 Q3V6T2 AKT1 CCDC88A
2271868 P31749 Q9NRI5 AKT1 DISC1
2271869 P60484 Q3V6T2 PTEN CCDC88A
2271870 P60484 Q9NRI5 PTEN DISC1
2271871 Q3V6T2 Q9NRI5 CCDC88A DISC1

2271872 rows * 4 columns

Creating three corresponding AnnData objects

After obtaining the cleaned DataFrames for gene-compound, gene-gene, and compound-compound interactions, we can convert them into AnnData objects using the pdb.create_adata() function. These AnnData objects can be used for various downstream analyses.

adata_gc, adata_gg, adata_cc = pdb.create_adata(gene_compound_df, gene_relation_df, compound_relation_df)
adata_gc, adata_gg, adata_cc
(AnnData object with n_obs * n_vars = 5314 * 13545
     uns: 'gene_col', 'compound_col', 'alignment', 'gene_compound_df',
 AnnData object with n_obs * n_vars = 5314 * 5314
     uns: 'edge_columns', 'alignment', 'gene_relation_df',
 AnnData object with n_obs * n_vars = 13545 * 13545
     uns: 'edge_columns', 'alignment', 'compound_relation_df')

KEGG pathway database

Data Download

KEGG pathway data can be fetched using the KEGG REST API. We can download pathway XML files for a specific species (e.g., human) using the pdb.download_all_pathway_xml() function.

This function takes the species code (e.g., "hsa" for human) and the directory path where the XML files will be saved. If no species code is provided, it defaults to downloading KEGG Orthology (KO) pathways.

The XML files will be saved in the specified directory ($kgml_path/$species_code).

species_code = "hsa" # Change to desired species code or None for all pathways
kgml_path = "./kegg"
pdb.download_all_kegg_pathway_xml(species_code, kgml_path)
Fetching pathway list from: http://rest.kegg.jp/list/pathway/hsa
Using existing directory: ./kegg\hsa
Starting download of 367 KGML files...

Completed download for species 'hsa'. Total files downloaded/skipped: 367 of 367.

Parsing one KEGG pathway XML file

Once we have downloaded the KGML XML files, we can parse a specific pathway XML file to extract metabolite-gene interactions using the pdb.parse_kegg_relations() function. This function takes the path to a KGML XML file and returns a DataFrame containing gene-compound interactions.

species_code = "hsa"  # Change to desired species code or None for all pathways
pathway_id = "hsa01100"  # Example pathway ID for Glycolysis / Gluconeogenesis
kgml_path = f"./kegg/{species_code}/{pathway_id}.xml"
gene_compound_df = pdb.parse_kegg_relations(kgml_path)

The resulting DataFrame contains KEGG gene IDs and compound IDs (KEGG CIDs).

gene_compound_df
kegg_gene_id kegg_compound_id
0 6718 C05471
1 6718 C00735
2 1584 C00280
3 1584 C05284
4 1585 C00280
... ... ...
3859 2805 C05527
3860 2805 C00606
3861 2806 C05527
3862 2806 C00606
3863 1585 C01780

3864 rows * 2 columns

Parsing all KEGG pathway XML files for a species

We can parse all KGML XML files for a specific species using the pdb.parse_all_kegg_pathways() function.

This function takes the species code and the directory path where the XML files are stored. It returns a DataFrame containing all gene-compound interactions for the specified species.

species_code = "hsa"  # Change to desired species code or None for all pathways
all_gene_compound_df = pdb.parse_all_kegg_pathways(species_code, "./kegg")
Processing 367 KGML files in './kegg\hsa'...
  Processed 50/367 files.
  Processed 100/367 files.
  Processed 150/367 files.
  Processed 200/367 files.
  Processed 250/367 files.
  Processed 300/367 files.
  Processed 350/367 files.
  Processed 367/367 files.
Aggregating results...
Completed. Extracted 8724 unique gene-compound relations (removed 6480 duplicates).

all_gene_compound_df
kegg_gene_id kegg_compound_id
0 226 C00354
1 226 C00118
2 226 C00111
3 229 C00354
4 229 C00118
... ... ...
14781 84618 C05512
14782 93034 C06196
14783 93034 C05512
15149 2582 C00043
15150 2582 C00203

8724 rows * 2 columns

Mapping KEGG gene id & compound id to gene symbol & CHEBI id

For the consistency of all data formats, we need to map the KEGG gene IDs to gene symbols and KEGG compound IDs to CHEBI IDs using the pdb.apply_mapping_and_cleanup() function.

all_gene_compound_df = pdb.apply_mapping_and_cleanup(
    df=all_gene_compound_df,
    mapping_file_path="./hgnc_complete_set.txt",
    mapping_sep="\t",
    origin_col="kegg_gene_id",
    target_col="symbol",
    origin_ref_col="entrez_id",
    target_ref_col="symbol",
    cleanup_subset_cols=None,
    origin_col_dtype=str,
    origin_ref_dtype=str,
)
all_gene_compound_df = pdb.apply_mapping_and_cleanup(
    df=all_gene_compound_df,
    mapping_file_path="./hmdb/hmdb_all_metabolites.csv",
    mapping_sep=",",
    origin_col="kegg_compound_id",
    target_col="compound",
    origin_ref_col="kegg_id",
    target_ref_col="chebi_id",
    cleanup_subset_cols=None,
    origin_col_dtype=str,
    origin_ref_dtype=str,
)
Mapping applied. 'symbol' column created.
Cleanup: Dropped 0 rows due to missing data in ['symbol'].
Mapping applied. 'compound' column created.
Cleanup: Dropped 2703 rows due to missing data in ['compound'].

all_gene_compound_df
kegg_gene_id kegg_compound_id symbol compound
0 226 C00118 ALDOA 29052
1 226 C00111 ALDOA 16108
2 229 C00118 ALDOB 29052
3 229 C00111 ALDOB 16108
4 230 C00118 ALDOC 29052
... ... ... ... ...
5952 84618 C05512 NT5C1A 28997
5953 93034 C06196 NT5C1B 28806
5954 93034 C05512 NT5C1B 28997
5955 2582 C00043 GALE 16264
5956 2582 C00203 GALE 25001

5957 rows * 4 columns

Constructing gene/compound relations

We can construct gene-gene and compound-compound interaction DataFrames from the gene-compound interaction DataFrame using the pdb.construct_kegg_relations() function. This function takes the gene-compound DataFrame and returns two DataFrames: one for gene-gene interactions gene_relation_df (pairwise, second-order neighbors connected via metabolites), and another for compound-compound interactions compound_relation_df (pairwise, second-order neighbors connected via genes)

all_gene_relation_df, all_compound_relation_df = pdb.construct_kegg_relations(all_gene_compound_df, gene_col="symbol", compound_col="compound", output_gene_col="symbol", output_compound_col="compound")
all_gene_relation_df
symbol1 symbol2 shared_compounds shared_compound_count
0 AACS ACAA1 [15345] 1
1 AACS ACAA2 [15345] 1
2 AACS ACAT1 [15345] 1
3 AACS ACAT2 [15345] 1
4 AACS BDH1 [15344] 1
... ... ... ... ...
17571 VARS1 VARS2 [16414] 1
17572 VKORC1 VKORC1L1 [78277] 1
17573 VNN1 VNN2 [16753, 46905] 2
17574 WARS1 WARS2 [16828] 1
17575 YARS1 YARS2 [17895] 1

17576 rows * 4 columns

all_compound_relation_df
compound1 compound2 shared_genes shared_symbol_count
0 10049 15422 [NUDT2] 1
1 10049 15652 [ITPA] 1
2 10049 15713 [NUDT2] 1
3 10049 15883 [NUDT2] 1
4 10049 15996 [NUDT2] 1
... ... ... ... ...
7895 89405 8990 [GUSB, UGT1A1, UGT1A10, UGT1A3, UGT1A4, UGT1A5... 20
7896 8988 8990 [GUSB, UGT1A1, UGT1A10, UGT1A3, UGT1A4, UGT1A5... 20
7897 9532 9533 [NTPCR] 1
7898 9532 9534 [AK1, AK2, AK4, AK5, AK7, AK8, THTPA] 7
7899 9532 978 [PDHA1, PDHA2, PDHB] 3

7900 rows * 4 columns

Creating three corresponding AnnData objects

Same as HMDB, after obtaining the cleaned DataFrames for gene-compound, gene-gene, and compound-compound interactions, we can convert them into AnnData objects using the pdb.create_adata() function. These AnnData objects can be used for various downstream analyses.

adata_gc, adata_gg, adata_cc = pdb.create_adata(all_gene_compound_df, all_gene_relation_df, all_compound_relation_df)
adata_gc, adata_gg, adata_cc
(AnnData object with n_obs * n_vars = 1273 * 1007
     uns: 'gene_col', 'compound_col', 'alignment', 'gene_compound_df',
 AnnData object with n_obs * n_vars = 1273 * 1273
     uns: 'edge_columns', 'alignment', 'gene_relation_df',
 AnnData object with n_obs * n_vars = 1007 * 1007
     uns: 'edge_columns', 'alignment', 'compound_relation_df')

Reactome pathway database

Data Download

The Reactome SBML files can be fetched from: https://reactome.org/download-data

e.g., for human pathways: https://download.reactome.org/94/homo_sapiens.3.1.sbml.tgz, for all pathways: https://download.reactome.org/94/all_species.3.1.sbml.tgz

Parsing Reactome Pathway Files

Once we have downloaded and extracted the Reactome pathway files, we can parse them to extract pathway information and gene-metabolite interactions by using the pdb.parse_reactome_sbml() function.

df_compartments, df_species, df_reactions = pdb.parse_reactome_sbml('./reactome/reactome_hsa/R-HSA-15869.sbml')
df_compartments
compartment_id compartment_name constant go_term
0 70101 cytosol true 0005829
1 984 extracellular region true 0005576
2 7660 nucleoplasm true 0005654
3 5460 mitochondrial matrix true 0005759
4 528865 endocytic vesicle lumen true 0071682
5 17963 Golgi lumen true 0005796
6 876 plasma membrane true 0005886
7 70616 mitochondrial inner membrane true 0005743
8 20699 Golgi membrane true 0000139
9 17927 mitochondrial intermembrane space true 0005758
10 24337 endocytic vesicle membrane true 0030666
df_species
species_id species_name compartment_id sboTerm hasOnlySubstanceUnits boundaryCondition constant reactome_id chebi_id uniprot_id part_id compartment_name
0 111292 PRA 70101 0000247 false false false R-ALL-111292 58681 [] [] cytosol
1 109277 Pi 984 0000247 false false false R-ALL-109277 43474 [] [] extracellular region
2 500077 (d)GDP 70101 None false false false R-ALL-500077 None [] [CHEBI:58595, CHEBI:58189] cytosol
3 500739 dUTP 7660 0000247 false false false R-ALL-500739 61555 [] [] nucleoplasm
4 6788790 AK5,7,8,9 70101 None false false false R-HSA-6788790 None [Q96MA6, Q96M32, Q5TCS8, Q9Y6K8] [uniprot:Q96MA6, uniprot:Q96M32, uniprot:Q5TCS... cytosol
... ... ... ... ... ... ... ... ... ... ... ... ...
305 9731302 8-oxo-dGTP(4-) 70101 0000247 false false false R-ALL-9731302 77896 [] [] cytosol
306 73473 NADH 70101 0000247 false false false R-ALL-73473 57945 [] [] cytosol
307 500104 Ade-Rib, dA, Gua-Rib, Ino 984 None false false false R-ALL-500104 None [] [CHEBI:17596, CHEBI:16335, CHEBI:17256, CHEBI:... extracellular region
308 83962 Ura 70101 0000247 false false false R-ALL-83962 17568 [] [] cytosol
309 6786373 5idCMP 70101 0000247 false false false R-ALL-6786373 43263 [] [] cytosol

310 rows * 12 columns

df_reactions
reaction_id reaction_name reaction_compartment_id reversible fast reactants products modifiers reaction_compartment_name reactants_name products_name modifiers_name
0 8851356 NTPDase5 hydrolyzes nucleoside diphosphates 984 false false [8936165, 109276] [109277, 351626, 8851369] [8851367] extracellular region [ADP,GDP,CDP,UDP, H2O] [Pi, H+, AMP,GMP,CMP,UMP] [NPTDase5:Ca2+,Mg2+]
1 111742 RNR (M1M2) reduces nucleotide diphosphates to ... 70101 false false [55729, 8866401] [8866399, 29356, 111740] [73640, 113592, 110644] cytosol [GLRX, NDP(3-)] [dNDP(3-), H2O, 2xHC-GLRX] [RNR (M1M2), ATP, dATP]
2 5696049 ADPRM hydrolyses ADP-ribose to R5P and AMP 70101 false false [1131972, 29356] [73578, 76577] [5696039] cytosol [ADP-D-ribose, H2O] [R5P, AMP] [ADPRM:Mn2+]
3 2395879 NUDT18 hydrolyses 8-oxo-dGDP to 8-oxo-dGMP 70101 false false [9731300, 29356] [9731296, 29372, 70106] [2394013] cytosol [8-oxo-dGDP(3-), H2O] [8-oxo-dGMP(2-), Pi, H+] [NUDT18-1]
4 9727347 XDH dehydrogenates hypoxanthine to form xanthine 70101 false false [113599, 29356, 29360] [73473, 30064, 70106] [74244] cytosol [Hyp, H2O, NAD+] [NADH, XAN, H+] [XDH dimer]
... ... ... ... ... ... ... ... ... ... ... ... ...
137 2395849 NUDT1 hydrolyses 8-oxo-dGTP to 8-oxo-dGMP 70101 false false [9731302, 29356] [9731296, 111294, 70106] [2395830] cytosol [8-oxo-dGTP(4-), H2O] [8-oxo-dGMP(2-), PPi, H+] [NUDT1]
138 73599 cytidine or uridine + ATP => CMP or UMP + ADP ... 70101 false false [500759, 113592] [29370, 500761] [73504] cytosol [Cyt-Rib, Ura-Rib, ATP] [ADP, CMP, UMP] [UCK1 tetramer]
139 74241 ADA catalyzes the deamination of (deoxy)adenosine 70101 false false [500173, 29356] [31633, 500172] [49701] cytosol [Ade-Rib, dA, H2O] [NH4+, Ino, dI] [ADA]
140 109671 deoxyadenosine or deoxyguanosine + ATP => dAMP... 70101 false false [113592, 500201] [29370, 500199] [73516] cytosol [ATP, dA, dG] [ADP, dAMP, dGMP] [DCK dimer]
141 109449 (d)CMP, TMP, or (d)UMP + H2O => (deoxy)cytidin... 70101 false false [500347, 29356] [29372, 500346] [109433] cytosol [(d)CMP, TMP, (d)UMP, H2O] [Pi, (d)C, T, (d)U] [NT5C3 holoenzyme]

142 rows * 12 columns

Extracting Metabolite-Gene Interactions from Reactome

From df_species and df_reactions these two DataFrames, we can extract metabolite-gene interactions gene_compound_df (pairwise), gene-gene interactions gene_relation_df (pairwise, second-order neighbors connected via metabolites), and compound-compound interactions compound_relation_df (pairwise, second-order neighbors connected via genes) from the parsed Reactome data using the pdb.extract_reactome_relations() function.

gene_compound_df, gene_relation_df, compound_relation_df = pdb.extract_reactome_relations(df_species, df_reactions)

Parsing all Reactome Pathways

We can parse all KGML XML files for a specific species using the pdb.parse_all_kegg_pathways() function.

This function takes the species code and the directory path where the XML files are stored. It returns a DataFrame containing all gene-compound interactions for the specified species.

all_gene_compound_df, all_gene_relation_df, all_compound_relation_df = pdb.process_all_reactome_pathways('hsa', pathway_dir="./reactome/reactome_hsa")
Processed 50/2769 files
Processed 100/2769 files
Processed 150/2769 files
Processed 200/2769 files
Processed 250/2769 files
Processed 300/2769 files
Processed 350/2769 files
Processed 400/2769 files
Processed 450/2769 files
Processed 500/2769 files
Processed 550/2769 files
Processed 600/2769 files
Warning: No valid genes/proteins or compounds found.
...
Processed 2650/2769 files
Processed 2700/2769 files
Warning: No valid genes/proteins or compounds found.
Processed 2750/2769 files
Processed 2769/2769 files

Mapping Reactome uniprot gene id to gene symbol

For the consistency of all data formats, we need to map the uniprot gene IDs to gene symbols using the pdb.apply_mapping_and_cleanup() function.

all_gene_compound_df = pdb.apply_mapping_and_cleanup(
    df=all_gene_compound_df,
    mapping_file_path="./hgnc_complete_set.txt",
    mapping_sep="\t",
    origin_col="gene",
    target_col="symbol",
    origin_ref_col="uniprot_ids",
    target_ref_col="symbol",
    origin_col_dtype=str,
    origin_ref_dtype=str,
)
all_gene_relation_df = pdb.apply_mapping_and_cleanup(
    df=all_gene_relation_df,
    mapping_file_path="./hgnc_complete_set.txt",
    mapping_sep="\t",
    origin_col="gene1",
    target_col="symbol1",
    origin_ref_col="uniprot_ids",
    target_ref_col="symbol",
    origin_col_dtype=str,
    origin_ref_dtype=str,
)
all_gene_relation_df = pdb.apply_mapping_and_cleanup(
    df=all_gene_relation_df,
    mapping_file_path="./hgnc_complete_set.txt",
    mapping_sep="\t",
    origin_col="gene2",
    target_col="symbol2",
    origin_ref_col="uniprot_ids",
    target_ref_col="symbol",
    origin_col_dtype=str,
    origin_ref_dtype=str,
)
Mapping applied. 'symbol' column created.
Cleanup: Dropped 906 rows due to missing data in ['symbol'].
Mapping applied. 'symbol1' column created.
Cleanup: Dropped 49444 rows due to missing data in ['symbol1'].
Mapping applied. 'symbol2' column created.
Cleanup: Dropped 36131 rows due to missing data in ['symbol2'].

Creating three corresponding AnnData objects

Same as HMDB & KEGG, after obtaining the cleaned DataFrames for gene-compound, gene-gene, and compound-compound interactions, we can convert them into AnnData objects using the pdb.create_adata() function. These AnnData objects can be used for various downstream analyses.

adata_gc, adata_gg, adata_cc = pdb.create_adata(all_gene_compound_df, all_gene_relation_df, all_compound_relation_df)
adata_gc, adata_gg, adata_cc
(AnnData object with n_obs * n_vars = 10254 * 1690
     obs: 'compartment_id', 'compartment_name'
     var: 'compartment_id', 'compartment_name'
     uns: 'gene_col', 'compound_col', 'alignment', 'gene_compound_df',
 AnnData object with n_obs * n_vars = 10254 * 10254
     uns: 'edge_columns', 'alignment', 'gene_relation_df',
 AnnData object with n_obs * n_vars = 1690 * 1690
     uns: 'edge_columns', 'alignment', 'compound_relation_df')