AnnData Object Creation
pdb.create_adata
Builds three aligned AnnData objects representing bipartite (Gene-Compound) and unipartite (Gene-Gene, Compound-Compound) networks from pandas DataFrames. All networks are represented as binary adjacency/incidence matrices.
| Parameter | Type | Default | Description |
|---|---|---|---|
gene_compound_df |
pd.DataFrame | DataFrame with columns for gene and compound IDs (bipartite relations). | |
gene_relation_df |
pd.DataFrame | DataFrame defining gene-gene relations. | |
compound_relation_df |
pd.DataFrame | DataFrame defining compound-compound relations. | |
gene_col |
str | "symbol" | Column name for gene IDs in gene_compound_df (used for adata_gc obs index). |
compound_col |
str | "compound" | Column name for compound IDs in gene_compound_df (used for adata_gc var index). |
gg_cols |
Tuple[str,str] | ("symbol1","symbol2") | Column names for the two gene ID columns in gene_relation_df. |
cc_cols |
Tuple[str,str] | ("compound1","compound2") | Column names for the two compound ID columns in compound_relation_df. |
Returns
Tuple[ad.AnnData,ad.AnnData,ad.AnnData]: A tuple containing the three aligned AnnData objects:
-
adata_gc: genes×compounds (bipartite incidence matrix). -
adata_gg: genes×genes (gene-gene adjacency matrix). -
adata_cc: compounds×compounds (compound-compound adjacency matrix).
Note: The gene index is aligned across adata_gc (obs) and adata_gg (obs/var). The compound index is aligned across adata_gc (var) and adata_cc (obs/var).
Usage
# Assuming pre-processed DataFrames: gc_df, gg_df, cc_df
adata_gc, adata_gg, adata_cc = pdb.create_adata(
gene_compound_df=gc_df,
gene_relation_df=gg_df,
compound_relation_df=cc_df,
gene_col="symbol", # Use the mapped column
compound_col="chebi_id",
)