Spaces:
Running
Running
annotacell space sync commited on
Commit ·
dc56cd2
1
Parent(s): 4ef3a39
Sync space: fix label==group
Browse files
README.md
CHANGED
|
@@ -18,6 +18,7 @@ and `manifest.json`. Built for a 2 vCPU / 16 GB Docker Space.
|
|
| 18 |
| GET | `/` | cgroup limits and endpoints |
|
| 19 |
| GET | `/probe?mb=50` | RTT + range throughput to CELLxGENE and Census S3 |
|
| 20 |
| GET | `/datasets` | recommended batches and the skip list |
|
|
|
|
| 21 |
| POST | `/build?dataset_id=...` | start a background build, returns `job_id` |
|
| 22 |
| GET | `/jobs/{job_id}` | status and result |
|
| 23 |
|
|
|
|
| 18 |
| GET | `/` | cgroup limits and endpoints |
|
| 19 |
| GET | `/probe?mb=50` | RTT + range throughput to CELLxGENE and Census S3 |
|
| 20 |
| GET | `/datasets` | recommended batches and the skip list |
|
| 21 |
+
| GET | `/inspect?dataset_id=...` | download and report obs/var/raw/X format before building |
|
| 22 |
| POST | `/build?dataset_id=...` | start a background build, returns `job_id` |
|
| 23 |
| GET | `/jobs/{job_id}` | status and result |
|
| 24 |
|
app.py
CHANGED
|
@@ -270,9 +270,9 @@ def pick_group_col(obs: pd.DataFrame, preferred: str | None = None) -> str:
|
|
| 270 |
)
|
| 271 |
|
| 272 |
|
| 273 |
-
def pick_label_col(obs: pd.DataFrame) -> str | None:
|
| 274 |
for column in ("cell_type_ontology_term_id", "cell_type"):
|
| 275 |
-
if column in obs.columns:
|
| 276 |
return column
|
| 277 |
return None
|
| 278 |
|
|
@@ -280,9 +280,15 @@ def pick_label_col(obs: pd.DataFrame) -> str | None:
|
|
| 280 |
def majority_labels(
|
| 281 |
obs: pd.DataFrame, group: str, label: str | None, min_cells: int, min_purity: float
|
| 282 |
) -> pd.DataFrame:
|
|
|
|
|
|
|
| 283 |
if label is None:
|
| 284 |
frame = obs.groupby(group, observed=True).size().rename("n_total").reset_index()
|
| 285 |
-
frame["label"] =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
frame["n_majority"] = frame["n_total"]
|
| 287 |
frame["purity"] = 1.0
|
| 288 |
else:
|
|
@@ -450,7 +456,7 @@ def run_build(
|
|
| 450 |
n_genes_total = int(adata.n_vars)
|
| 451 |
obs = adata.obs
|
| 452 |
group = pick_group_col(obs, group_col)
|
| 453 |
-
label = pick_label_col(obs)
|
| 454 |
src = adata.raw.to_adata() if adata.raw is not None else adata.copy()
|
| 455 |
del adata
|
| 456 |
gc.collect()
|
|
|
|
| 270 |
)
|
| 271 |
|
| 272 |
|
| 273 |
+
def pick_label_col(obs: pd.DataFrame, group: str | None = None) -> str | None:
|
| 274 |
for column in ("cell_type_ontology_term_id", "cell_type"):
|
| 275 |
+
if column in obs.columns and column != group:
|
| 276 |
return column
|
| 277 |
return None
|
| 278 |
|
|
|
|
| 280 |
def majority_labels(
|
| 281 |
obs: pd.DataFrame, group: str, label: str | None, min_cells: int, min_purity: float
|
| 282 |
) -> pd.DataFrame:
|
| 283 |
+
if label == group:
|
| 284 |
+
label = None
|
| 285 |
if label is None:
|
| 286 |
frame = obs.groupby(group, observed=True).size().rename("n_total").reset_index()
|
| 287 |
+
frame["label"] = (
|
| 288 |
+
frame[group].astype(str)
|
| 289 |
+
if group in ("cell_type_ontology_term_id", "cell_type")
|
| 290 |
+
else None
|
| 291 |
+
)
|
| 292 |
frame["n_majority"] = frame["n_total"]
|
| 293 |
frame["purity"] = 1.0
|
| 294 |
else:
|
|
|
|
| 456 |
n_genes_total = int(adata.n_vars)
|
| 457 |
obs = adata.obs
|
| 458 |
group = pick_group_col(obs, group_col)
|
| 459 |
+
label = pick_label_col(obs, group)
|
| 460 |
src = adata.raw.to_adata() if adata.raw is not None else adata.copy()
|
| 461 |
del adata
|
| 462 |
gc.collect()
|