cellestial.build_frame#

build_frame(data: AnnData, *, variable_keys: str | Sequence[str] | None = None, axis: Literal[0, 1] | None = None, observations_name: str = 'barcode', variables_name: str = 'variable', include_dimensions: bool | int = False) DataFrame#

Build a DataFrame from an AnnData object.

Parameters:
  • data (AnnData) – The AnnData object containing the variables.

  • variable_keys (str | Sequence[str] | None) – Variable keys to add to the DataFrame. If None, no additional keys are added.

  • axis ({0,1} | None) – The axis to build the frame for. 0 for observations, 1 for variables.

  • observations_name (str) – The name of the observations column, default is ‘barcode’

  • variables_name (str) – Name for the variables index column, default is ‘variable’

  • include_dimensions (bool | int) – Whether to include dimensions in the DataFrame, default is False. Providing an integer will limit the number of dimensions to given number.

Returns:

DataFrame – A polars DataFrame containing the variables.

Examples

Providing axis, 0 for observations axis and 1 for variables axis.

import cellestial as cl
import scanpy as sc

data = sc.read_h5ad("data/pbmc3k_pped.h5ad")
frame = cl.build_frame(data, axis=0, include_dimensions=2)
frame.head()
shape: (5, 33)
barcodesamplen_genes_by_countslog1p_n_genes_by_countstotal_countslog1p_total_countspct_counts_in_top_50_genespct_counts_in_top_100_genespct_counts_in_top_200_genespct_counts_in_top_500_genestotal_counts_mtlog1p_total_counts_mtpct_counts_mttotal_counts_ribolog1p_total_counts_ribopct_counts_ribototal_counts_hblog1p_total_counts_hbpct_counts_hbn_genesdoublet_scorepredicted_doubletleidenleiden_res_0.02leiden_res_0.50leiden_res_2.00cell_type_lvl1X_PCA1X_PCA2X_TSNE1X_TSNE2X_UMAP1X_UMAP2
strcati32f64f32f32f64f64f64f64f32f32f32f32f32f32f32f32f32i64f64boolcatcatcatcatcatf32f32f32f32f32f32
"AAACCCAAGGATGGCT-1""s1d1"21037.6515968663.09.06693242.72192159.66755269.74489279.348955460.06.1333985.3099383650.08.20275642.13320917.02.8903720.19623721030.036113false"0""0""0""0""Lymphocytes"-2.698756-1.97092334.229698-30.396513-0.7587099.41935
"AAACCCAAGGCCTAGA-1""s1d1"39168.27308112853.09.46141135.84377244.2620452.37687762.7635571790.07.4905313.926711719.07.45007913.3743158.04.0775380.45125739120.183381false"2""1""1""1""Monocytes"-5.0511049.427238-9.45950365.0664981.472651-2.361804
"AAACCCAAGTGAGTGC-1""s1d1"6836.5279581631.07.39756256.28448862.59963270.38626688.77989581.06.3664735.62231863.04.1588833.86266113.02.6390570.7970576830.04532false"3""2""2""2""Erythroid"-2.535384-1.728063-63.691681-6.7060053.40767316.263371
"AAACCCACAAGAGGCT-1""s1d1"43308.37355417345.09.76111727.6621538.42029448.90170162.023638780.06.6605754.4969733936.08.27817422.69241744.03.8066630.25367543280.04532false"5""0""3""3""Lymphocytes"-3.8464531.094153-40.50571157.683064-0.0565423.495222
"AAACCCACATCGTGGC-1""s1d1"3255.786897555.06.32076849.9099159.45945977.477477100.0159.05.07517428.64864726.03.2958374.68468526.03.2958374.6846853230.016181false"6""0""4""4""Lymphocytes"0.211629-1.380853-26.950605-43.669479-5.4132158.537583

Providing variable_keys allows function to infer the axis as 0.

import cellestial as cl
import scanpy as sc

data = sc.read_h5ad("data/pbmc3k_pped.h5ad")
frame = cl.build_frame(data, variable_keys=["CD14", "HBA1"], include_dimensions=2)
frame.head()
shape: (5, 35)
barcodesamplen_genes_by_countslog1p_n_genes_by_countstotal_countslog1p_total_countspct_counts_in_top_50_genespct_counts_in_top_100_genespct_counts_in_top_200_genespct_counts_in_top_500_genestotal_counts_mtlog1p_total_counts_mtpct_counts_mttotal_counts_ribolog1p_total_counts_ribopct_counts_ribototal_counts_hblog1p_total_counts_hbpct_counts_hbn_genesdoublet_scorepredicted_doubletleidenleiden_res_0.02leiden_res_0.50leiden_res_2.00cell_type_lvl1X_PCA1X_PCA2X_TSNE1X_TSNE2X_UMAP1X_UMAP2CD14HBA1
strcati32f64f32f32f64f64f64f64f32f32f32f32f32f32f32f32f32i64f64boolcatcatcatcatcatf32f32f32f32f32f32f32f32
"AAACCCAAGGATGGCT-1""s1d1"21037.6515968663.09.06693242.72192159.66755269.74489279.348955460.06.1333985.3099383650.08.20275642.13320917.02.8903720.19623721030.036113false"0""0""0""0""Lymphocytes"-2.698756-1.97092334.229698-30.396513-0.7587099.419350.00.854953
"AAACCCAAGGCCTAGA-1""s1d1"39168.27308112853.09.46141135.84377244.2620452.37687762.7635571790.07.4905313.926711719.07.45007913.3743158.04.0775380.45125739120.183381false"2""1""1""1""Monocytes"-5.0511049.427238-9.45950365.0664981.472651-2.3618040.3753161.629056
"AAACCCAAGTGAGTGC-1""s1d1"6836.5279581631.07.39756256.28448862.59963270.38626688.77989581.06.3664735.62231863.04.1588833.86266113.02.6390570.7970576830.04532false"3""2""2""2""Erythroid"-2.535384-1.728063-63.691681-6.7060053.40767316.2633710.01.523574
"AAACCCACAAGAGGCT-1""s1d1"43308.37355417345.09.76111727.6621538.42029448.90170162.023638780.06.6605754.4969733936.08.27817422.69241744.03.8066630.25367543280.04532false"5""0""3""3""Lymphocytes"-3.8464531.094153-40.50571157.683064-0.0565423.4952220.00.515772
"AAACCCACATCGTGGC-1""s1d1"3255.786897555.06.32076849.9099159.45945977.477477100.0159.05.07517428.64864726.03.2958374.68468526.03.2958374.6846853230.016181false"6""0""4""4""Lymphocytes"0.211629-1.380853-26.950605-43.669479-5.4132158.5375830.00.0