In silico cellular reprogramming
Remove any old copy, then install the latest version from GitHub with pak.
# 1. remove an old copy (if present)
if ("CellReprogramR" %in% rownames(installed.packages())) {
remove.packages("CellReprogramR")
}
# 2. install pak, then the newest CellReprogramR from GitHub
if (!requireNamespace("pak", quietly = TRUE)) install.packages("pak")
pak::pkg_install("louwenyuan/CellReprogramR", upgrade = TRUE)
# 3. load it and fix the random seed
library(CellReprogramR)
set.seed(2026)Confirm you really have the newest build: packageDescription("CellReprogramR")$RemoteSha should match the latest commit on GitHub.
One line, no arguments. The built-in demo runs end to end.
library(CellReprogramR)
# runs the packaged demo: four tumour states -> Oligodendrocyte
results <- run_reprogramming_pipeline()It loads the example Seurat object and the small L1000 tables shipped in inst/extdata. The start cells are MES-like, AC-like, NPC-like and OPC-like, and the end cell is Oligodendrocyte. Only labels that really exist in the object are used.
results is a list holding synergy_table, combo_res, phase_space, flow_df, selected_drugs, plots, run_log and output_dir.
Every route calls the same function. Pick the tab that matches how much you want to decide yourself.
You want to see the whole pipeline work before touching your own data.
results <- run_reprogramming_pipeline()You have a Seurat file but are not sure which column or labels to use. Give only the file paths. In an interactive R session the wizard lists your metadata columns, then the cell types, and lets you pick the end cell and the start cells.
results <- run_reprogramming_pipeline(
rds_path = "D:/second/npj_glioma/infercnv/GBM_scRNA_annotated_v4_CNV.rds", # your single-cell object
meta_parquet_path = "D:/Cell/data/l1000_cns_meta.parquet", # your L1000 metadata
output_dir = "./Output"
)Complex Seurat objects often carry several annotation levels. In the first menu pick the column that holds the states you care about (here CellState).
You know exactly what you want, or you are running a script without a keyboard. Always name the column with cell_type_col.
One start state
results <- run_reprogramming_pipeline(
rds_path = "D:/second/npj_glioma/infercnv/GBM_scRNA_annotated_v4_CNV.rds",
meta_parquet_path = "D:/Cell/data/l1000_cns_meta.parquet",
cell_type_col = "CellState", # the column that holds your labels
source_types = c("MES-like"), # start
target_type = "Oligodendrocyte", # end
output_dir = "./Output"
)Several start states at once (a candidate must move all of them towards the target)
results <- run_reprogramming_pipeline(
rds_path = "D:/second/npj_glioma/infercnv/GBM_scRNA_annotated_v4_CNV.rds",
meta_parquet_path = "D:/Cell/data/l1000_cns_meta.parquet",
cell_type_col = "CellState",
source_types = c("MES-like", "AC-like", "NPC-like", "OPC-like"),
target_type = "Oligodendrocyte",
output_dir = "./Output"
)Write the slots once for the whole session
options(
CellReprogramR.target_type = "Oligodendrocyte",
CellReprogramR.source_types = c("MES-like", "AC-like")
)
results <- run_reprogramming_pipeline(rds_path = "path/to/object.rds", cell_type_col = "CellState")Matching ignores case and punctuation. If a label is not in cell_type_col, the function looks for one other column that contains all of your labels and tells you which one it used. If none does, it stops and prints the labels that are available.
The object is already loaded, or you subset or recoloured it earlier in the session. Pass it as obj instead of rds_path.
seu <- readRDS("D:/second/npj_glioma/infercnv/GBM_scRNA_annotated_v4_CNV.rds")
table(seu$CellState) # look at the labels first
results <- run_reprogramming_pipeline(
obj = seu,
meta_parquet_path = "D:/Cell/data/l1000_cns_meta.parquet",
cell_type_col = "CellState",
source_types = c("MES-like", "AC-like"),
target_type = "Oligodendrocyte",
output_dir = "./Output"
)You want every figure to match the colours of your earlier plots. Give a named vector; names are your cell labels. Any label you do not list gets a colour from the default palette.
results <- run_reprogramming_pipeline(
rds_path = "D:/second/npj_glioma/infercnv/GBM_scRNA_annotated_v4_CNV.rds",
meta_parquet_path = "D:/Cell/data/l1000_cns_meta.parquet",
cell_type_col = "CellState",
source_types = c("MES-like", "AC-like", "NPC-like", "OPC-like"),
target_type = "Oligodendrocyte",
cell_colors = c(
"MES-like" = "#FF595E",
"Macrophage (MDM-TAM)" = "#F15BB5",
"Microglia" = "#FFCA3A",
"T cell" = "#FEE440",
"AC-like" = "#1982C4",
"OPC-like" = "#00BBF9",
"NPC-like" = "#FF99C8",
"Endothelial" = "#C77DFF",
"Mural / stromal" = "#F94144",
"Oligodendrocyte" = "#8AC926"
),
output_dir = "./Output"
)Set the colours once for the session with set_cell_colors(c("MES-like" = "#FF595E", ...)), or pass an unnamed vector to colour the types in their listed order.
You would rather type colours into a dialog than write a vector. A dialog (or the console, in plain R) lists your cell types. Type MES-like=#FF595E, AC-like=#1982C4, an ordered list of hex codes, or R code such as c("MES-like" = "#FF595E"). Leave it empty to keep the default palette.
results <- run_reprogramming_pipeline(
rds_path = "D:/second/npj_glioma/infercnv/GBM_scRNA_annotated_v4_CNV.rds",
meta_parquet_path = "D:/Cell/data/l1000_cns_meta.parquet",
cell_type_col = "CellState",
source_types = c("MES-like", "AC-like"),
target_type = "Oligodendrocyte",
color_input = "popup",
output_dir = "./Output"
)| Argument | What it does | Default |
|---|---|---|
| rds_path / obj | Path to a Seurat .rds file, or a Seurat object already loaded. Leave both empty to run the demo. | NULL |
| meta_parquet_path | L1000 signature metadata (.parquet). The matrix file is found automatically or downloaded. | NULL |
| cell_type_col | Metadata column that holds your cell labels. | "CellType" |
| source_types | Start states. Leave empty to use every non-target type. | NULL |
| target_type | End state you want to reach. | NULL |
| cell_colors | Named colour vector for your cell labels. | NULL |
| color_input | "code" uses cell_colors; "popup" opens a typing dialog. | "code" |
| cell_lines / pert_types | Filter L1000 signatures, for example by cell line or perturbation class. | NULL |
| drug1 / drug2 | Two perturbations to combine. Empty means the two best distinct ones. | NULL |
| top_n | How many candidates appear in the ranked plots. | 10 |
| n_perm | Permutations for the significance test. | 1000 |
| flow_method | Arrow field on the UMAP: "auto", "target" or "manifold". | "auto" |
| make_figure | Build one assembled multi-panel figure. | TRUE |
| figure_page | "auto" lets the page grow; "A4" or "A3" fixes the page. | "auto" |
| gradient_style | "dopamine" gives each bar plot a different random gradient; "reds" uses white to red. | "dopamine" |
| gradient_seed | Reproduce a particular random gradient draw. | NULL |
| seed | Random seed for the permutation tests. | 2026 |
| run_survival | Optional TCGA / CGGA survival check using virtual marker genes. | FALSE |
| run_pk | Optional benchmark against reference perturbagens and global rank. | TRUE |
| output_dir | Folder for every figure and table. | "./Output" |
Each output is produced on its own. If one fails, it is reported and the next one still runs.
Nine numbered steps scroll past. A green check means done, a yellow exclamation mark is a warning that was handled, a red cross is an error. Steps 1 to 4 are required; later steps are skipped on error and listed in results$run_log.
Look at the first console step. If it says running on the built-in demo data, no input file was read. If the run stopped with a red message, the figure in your folder is an old one from a previous run. Use a new output_dir such as "./Output_new" to be sure.
That happens when source_types is empty. Name the start states and the column: cell_type_col = "CellState", source_types = c("MES-like", ...).
Print the candidates and pick the one that contains your start and end states.
seu <- readRDS("path/to/object.rds")
for (cc in colnames(seu@meta.data)) {
v <- seu@meta.data[[cc]]
if ((is.character(v) || is.factor(v)) && nlevels(factor(v)) < 40) {
cat("\n==", cc, "==\n"); print(table(v))
}
}Use seed = 2026 (the default) for the permutation tests and gradient_seed = 1 (any integer) to reproduce the same random bar colours.
Scores are model-based predictions of how well a signature aligns with the path from your start to your end state. They are a ranking for hypothesis generation and need experimental validation.