-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllms.txt
More file actions
137 lines (101 loc) · 4.53 KB
/
Copy pathllms.txt
File metadata and controls
137 lines (101 loc) · 4.53 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Cytovanni
Cytovanni is a Python library for computational standardization of flow cytometry data.
- GitHub repository: https://github.com/anders-biostat/Cytovanni
- Documentation: https://cytovanni.readthedocs.io
## Container Setup
The recommended runtime is an Apptainer container with all dependencies. Jupyter and Apptainer must already be installed on the host. Ask the user where they want to store the container files (`.sif` and `init_kernel.sh`) — these paths are hardcoded, so the location matters.
### 1. Download and build the container
```bash
curl -L https://raw.githubusercontent.com/anders-biostat/Cytovanni/main/container/container.def -o /your/path/container.def
apptainer build -F /your/path/cytovanni-container.sif /your/path/container.def
```
Building takes several minutes and requires internet access.
### 2. Create the kernel launch script
Create `/your/path/init_kernel.sh`:
```bash
#!/bin/bash
apptainer exec --nv /your/path/cytovanni-container.sif python -m ipykernel "$@"
```
Then make it executable: `chmod +x /your/path/init_kernel.sh`
`--nv` enables GPU access. Use `--bind /extra/path` to mount additional directories (the user home directory is mounted automatically).
### 3. Register the Jupyter kernel
```bash
mkdir -p ~/.local/share/jupyter/kernels/cytovanni-container
```
Create `~/.local/share/jupyter/kernels/cytovanni-container/kernel.json`:
```json
{
"argv": [
"/your/path/init_kernel.sh",
"-f",
"{connection_file}"
],
"display_name": "Python (Cytovanni)",
"language": "python"
}
```
Download the kernel logo:
```bash
curl -L https://raw.githubusercontent.com/anders-biostat/Cytovanni/main/container/logo-64x64.png -o ~/.local/share/jupyter/kernels/cytovanni-container/logo-64x64.png
```
The kernel will appear as **Python (Cytovanni)** in the Jupyter launcher.
### Adding extra packages
To add packages, modify `container.def` before building:
```bash
sed '/ # custom packages/a\ uv pip install --system package1 package2' -i container.def
```
## R Container (CytoNorm)
```bash
curl -L https://raw.githubusercontent.com/anders-biostat/Cytovanni/main/container/Rcontainer.def -o /your/path/Rcontainer.def
apptainer build -F /your/path/cytovanni-R-container.sif /your/path/Rcontainer.def
```
Create `/your/path/init_R_kernel.sh`:
```bash
#!/bin/bash
for i in "$@"; do
if [[ "$prev" == "-f" ]]; then
CONN_FILE="$i"
fi
prev="$i"
done
apptainer exec /your/path/cytovanni-R-container.sif R --slave -e "IRkernel::main('${CONN_FILE}')"
```
Register with `kernel.json` using `"display_name": "R (Cytovanni)"` and `"language": "R"`.
## CytometerConfiguration Setup
Every Cytovanni workflow requires a `CytometerConfiguration` object. The TL;DR: only `channels_fluorescence`, `max_linear_range`, and `cytometer` usually need to be set.
### Step 1: Find available channels
```python
cytovanni.io.readfcs_available_channels("/path/to/file.fcs")
```
This returns the channel names as they appear in the .fcs file, e.g. `['FSC-A', 'FSC-H', 'FSC-W', 'SSC-A', 'SSC-H', 'SSC-W', 'BV421-A', ...]`.
### Step 2: Create the configuration
```python
cytoconfig = cytovanni.utils.CytometerConfiguration(
channels_fluorescence=['BB515-A', 'BV421-A', ...], # always required, varies per instrument
max_linear_range=2e5, # approximate detector linearity limit
cytometer="MyInstrument", # name string, used for bookkeeping
)
```
All other parameters have sensible defaults:
- `channels_scatter` — defaults to `["FSC-A","FSC-H","FSC-W","SSC-A","SSC-H","SSC-W"]`, usually the same across instruments
- `channels_meta` — defaults to `["Time"]`
- `default_scatter_gate` — defaults to `["FSC-A", "SSC-A"]`, used by bead gating functions
- `try_adding_HW` — if `True`, automatically loads `-H` and `-W` variants of fluorescence channels where available (default `False`)
- `fct_hash_settings` — hash function to detect cytometer setting changes between batches; rarely needs changing
### Reuse: subclass or save to JSON
For repeated use, either subclass:
```python
class MyCytometerConfig(cytovanni.utils.CytometerConfiguration):
def __init__(self):
super().__init__(
channels_fluorescence=[...],
cytometer="MyInstrument",
max_linear_range=2e5,
)
```
Or save/load as JSON:
```python
cytoconfig.write_json("cytoconfig.json")
cytoconfig = cytovanni.utils.CytometerConfiguration.load_json("cytoconfig.json")
```
Note: `fct_hash_settings` is never saved to JSON and always reverts to the default when loading.