Jupyter Notebook

Gene Ontology (GO)#

Pathways represent interconnected molecular networks of signaling cascades that govern critical cellular processes. They provide understandings cellular behavior mechanisms, insights of disease progression and treatment responses. In an R&D organization, managing pathways across different datasets are crucial for gaining insights of potential therapeutic targets and intervention strategies.

In this notebook we manage a pathway registry based on “2023 GO Biological Process” ontology. We’ll walk you through the steps of registering pathways and link them to genes.

In the following Standardize metadata on-the-fly notebook, we’ll demonstrate how to perform a pathway enrichment analysis and track the dataset with LaminDB.

Setup#

Warning

Please ensure that you have created or loaded a LaminDB instance before running the remaining part of this notebook!

This notebook follows the [CellTypist], which populate the CellType registry.

!lamin init --storage ./use-cases-registries --schema bionty
Hide code cell output
✅ saved: User(uid='DzTjkKse', handle='testuser1', name='Test User1', updated_at=2024-01-24 13:34:52 UTC)
✅ saved: Storage(uid='AhiNmQW5', root='/home/runner/work/lamin-usecases/lamin-usecases/docs/use-cases-registries', type='local', updated_at=2024-01-24 13:34:52 UTC, created_by_id=1)
💡 loaded instance: testuser1/use-cases-registries
💡 did not register local instance on hub
import lamindb as ln
import lnschema_bionty as lb
import gseapy as gp

lb.settings.organism = "human"  # globally set organism
💡 lamindb instance: testuser1/use-cases-registries
2024-01-24 13:34:53,678:INFO - Failed to extract font properties from /usr/share/fonts/truetype/noto/NotoColorEmoji.ttf: In FT2Font: Can not load face (unknown file format; error code 0x2)
2024-01-24 13:34:53,717:INFO - generated new fontManager

Fetch GO pathways annotated with human genes using Enrichr#

First we fetch the “GO_Biological_Process_2023” pathways for humans using GSEApy which wraps GSEA and Enrichr.

go_bp = gp.get_library(name="GO_Biological_Process_2023", organism="Human")
print(f"Number of pathways {len(go_bp)}")
2024-01-24 13:34:55,380:INFO - Downloading and generating Enrichr library gene sets...
2024-01-24 13:35:11,029:INFO - 0001 gene_sets have been filtered out when max_size=2000 and min_size=0
Number of pathways 5406
go_bp["ATF6-mediated Unfolded Protein Response (GO:0036500)"]
['MBTPS1', 'MBTPS2', 'XBP1', 'ATF6B', 'DDIT3', 'CREBZF']

Parse out the ontology_id from keys, convert into the format of {ontology_id: (name, genes)}

def parse_ontology_id_from_keys(key):
    """Parse out the ontology id.

    "ATF6-mediated Unfolded Protein Response (GO:0036500)" -> ("GO:0036500", "ATF6-mediated Unfolded Protein Response")
    """
    id = key.split(" ")[-1].replace("(", "").replace(")", "")
    name = key.replace(f" ({id})", "")
    return (id, name)
go_bp_parsed = {}

for key, genes in go_bp.items():
    id, name = parse_ontology_id_from_keys(key)
    go_bp_parsed[id] = (name, genes)
go_bp_parsed["GO:0036500"]
('ATF6-mediated Unfolded Protein Response',
 ['MBTPS1', 'MBTPS2', 'XBP1', 'ATF6B', 'DDIT3', 'CREBZF'])

Register pathway ontology in LaminDB#

bionty = lb.Pathway.public()
bionty
PublicOntology
Entity: Pathway
Organism: all
Source: go, 2023-05-10
#terms: 47514

📖 .df(): ontology reference table
🔎 .lookup(): autocompletion of terms
🎯 .search(): free text search of terms
✅ .validate(): strictly validate values
🧐 .inspect(): full inspection of values
👽 .standardize(): convert to standardized names
🪜 .diff(): difference between two versions
🔗 .to_pronto(): Pronto.Ontology object

Next, we register all the pathways and genes in LaminDB to finally link pathways to genes.

Register pathway terms#

To register the pathways we make use of .from_values to directly parse the annotated GO pathway ontology IDs into LaminDB.

pathway_records = lb.Pathway.from_values(go_bp_parsed.keys(), lb.Pathway.ontology_id)
lb.Pathway.from_public(ontology_id="GO:0015868")
Pathway(uid='5bQIT2QT', name='purine ribonucleotide transport', ontology_id='GO:0015868', description='The Directed Movement Of A Purine Ribonucleotide, Any Compound Consisting Of A Purine Ribonucleoside (A Purine Organic Base Attached To A Ribose Sugar) Esterified With (Ortho)Phosphate, Into, Out Of Or Within A Cell.', public_source_id=44, created_by_id=1)
ln.save(pathway_records, parents=False)  # not recursing through parents

Register gene symbols#

Similarly, we use .from_values for all Pathway associated genes to register them with LaminDB.

all_genes = {g for genes in go_bp.values() for g in genes}
gene_records = lb.Gene.from_values(all_genes, lb.Gene.symbol)
Hide code cell output
❗ ambiguous validation in Bionty for 1082 records: 'IGHG1', 'CTAGE15', 'SIRT2', 'SLC27A3', 'LILRA1', 'ADIPOR2', 'HAPLN2', 'MATR3', 'CARMIL3', 'TINF2', 'SPATA13', 'GOLGA8N', 'GLIS2', 'CLN8', 'ACTG1', 'DPY19L2P2', 'APEX1', 'SPPL2C', 'PCDHA7', 'SERPINF2', ...
did not create Gene records for 37 non-validated symbols: 'AFD1', 'AZF1', 'CCL4L1', 'DGS2', 'DUX3', 'DUX5', 'FOXL3-OT1', 'IGL', 'LOC100653049', 'LOC102723475', 'LOC102723996', 'LOC102724159', 'LOC107984156', 'LOC112268384', 'LOC122319436', 'LOC122513141', 'LOC122539214', 'LOC344967', 'MDRV', 'MTRNR2L1', ...
gene_records[:3]
[Gene(uid='5PZ7x0iOBIXq', symbol='MARCO', ensembl_gene_id='ENSG00000019169', ncbi_gene_ids='8685', biotype='protein_coding', description='macrophage receptor with collagenous structure ', synonyms='SR-A6|SCARA2', organism_id=1, public_source_id=9, created_by_id=1),
 Gene(uid='5ftC9bd3Pv3Q', symbol='UHRF1', ensembl_gene_id='ENSG00000276043', ncbi_gene_ids='29128', biotype='protein_coding', description='ubiquitin like with PHD and ring finger domains 1 ', synonyms='FLJ21925|ICBP90|RNF106|TDRD22|NP95', organism_id=1, public_source_id=9, created_by_id=1),
 Gene(uid='4xCj2Jf8wa3B', symbol='TBXT', ensembl_gene_id='ENSG00000164458', ncbi_gene_ids='6862', biotype='protein_coding', description='T-box transcription factor T ', synonyms='T', organism_id=1, public_source_id=9, created_by_id=1)]
ln.save(gene_records);