Rule inference from pseudotime
Fit BoBa-T rules from a single snapshot of cells ordered by pseudotime / RNA velocity, using the ordering to define the direction of change.
Starter notebook. The cells below are a scaffold: real function calls with placeholder paths/arguments and
TODOmarkers. Fill in your own data and run top-to-bottom. Anything markedTODOis a choice you need to make for your dataset.
Setup and imports
[ ]:
import os
import os.path as op
import time
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import bobaT as bb
sns.set_style('whitegrid')
plt.rcParams['figure.dpi'] = 100
import warnings
warnings.filterwarnings('ignore')
Configure paths
[ ]:
# Input data
DATA_DIR = './test_data'
# Output directories
OUTPUT_DIR = './output'
VAL_DIR = './output/validation'
ATTRACTOR_DIR = './output/attractors'
PERTURB_DIR = './output/perturbations'
os.makedirs(OUTPUT_DIR, exist_ok=True)
data_path = 'data.csv' # TODO: your expression matrix
cellID_table = 'cellID-lookuptable_x1.csv'
Load network and data
[ ]:
# Load the base network as a graph-tool graph
network_path = 'tf-lit-network.csv' # TODO: your base network CSV
graph, vertex_dict = bb.load.load_network(
f'{DATA_DIR}/{network_path}',
remove_sinks=False, remove_selfloops=True, remove_sources=False,
)
v_names, nodes = bb.utils.get_nodes(vertex_dict, graph)
data = bb.load.load_data(f'{DATA_DIR}/{data_path}', nodes, norm=0.3,
delimiter=',', log1p=False, transpose=True,
sample_order=False, fillna=0)
clusters = bb.utils.get_clusters(data, cellID_table=f'{DATA_DIR}/{cellID_table}',
cluster_header_list=['CellStage', 'class', 'CellProtocol'])
Build the next-state matrix from velocity/pseudotime
TODO: compute
data_t1— the projected next state for each cell — from your scVelo / pseudotime results. This is the input that encodes the direction of change.
[ ]:
# TODO: replace with your velocity-projected next-state matrix
data_t1 = None # e.g. from scVelo latent time / velocity graph
Fit rules from the ordering
[ ]:
rules, regulators_dict, strengths, signed_strengths = bb.tl.get_rules_scvelo(
data=data, data_t1=data_t1, vertex_dict=vertex_dict,
plot=True, show_plot=False, save_plot=True,
save_dir=f'{OUTPUT_DIR}/rules/rule_plots', threshold=0,
)
bb.tl.save_rules(rules, regulators_dict, fname=f'{OUTPUT_DIR}/rules.txt')
Next steps
Validate the rules, then find attractors.