File size: 2,339 Bytes
70070cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Quick Start

!!! note "Availability"
    Model weights and inference code are coming soon. The examples below reflect the planned API interface.

## Load a Pretrained Model

```python
from xcell import XCell

model = XCell.from_pretrained("Xaira-Therapeutics/X-Cell", variant="mini")
```

`variant="mini"` loads X-Cell Mini (55M parameters).

---

## Predict from an AnnData Object

```python
import anndata as ad
from xcell import XCell

model = XCell.from_pretrained("Xaira-Therapeutics/X-Cell", variant="mini")

# Load your control cells
adata = ad.read_h5ad("control_cells.h5ad")

# Predict transcriptional response to a single-gene CRISPRi knockdown
predictions = model.predict(adata, perturbation="BRCA1")

# predictions is an AnnData with predicted perturbed expression in .X
print(predictions)
```

!!! note "Input expectations"
    `adata` should contain log-normalized (log1p CP10k) expression values.
    X-Cell covers all ~19,000 protein-coding genes; genes not in the vocabulary are zero-imputed.

---

## Predict from `.h5ad` File Paths

```python
# Single file path
predictions = model.predict("control_cells.h5ad", perturbation="BRCA1")

# Multiple files — cells are pooled across datasets
predictions = model.predict(
    ["screen1.h5ad", "screen2.h5ad"],
    perturbation="BRCA1",
)
```

---

## Batch Predict Across Perturbations

```python
import pandas as pd

perturbations = ["BRCA1", "TP53", "MYC", "EGFR"]

results = {}
for pert in perturbations:
    results[pert] = model.predict(adata, perturbation=pert)

# Concatenate into a single AnnData
import anndata as ad
all_predictions = ad.concat(results, label="perturbation")
```

---

## Interpreting Outputs

The returned `AnnData` contains:

| Field | Description |
|-------|-------------|
| `.X` | Predicted perturbed expression (log1p CP10k, same shape as input) |
| `.obs["perturbation"]` | Perturbation name |
| `.var` | Gene metadata (same as input `adata.var`) |

To compute predicted fold-change relative to control:

```python
import numpy as np

# Pseudobulk fold-change
ctrl_mean = adata.X.mean(axis=0)
pred_mean = predictions.X.mean(axis=0)
fold_change = pred_mean - ctrl_mean  # in log space, this is log fold-change

# Top differentially expressed genes
top_genes = np.argsort(np.abs(fold_change))[::-1][:20]
print(adata.var_names[top_genes])
```