Skip to content

Commit d062157

Browse files
committed
fix bug in perfect integration subsetting
1 parent 379b3dd commit d062157

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

  • src/control_methods/perfect_integration

src/control_methods/perfect_integration/script.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,36 @@
1414
print("Reading input files", flush=True)
1515
adata = ad.read_h5ad(par["input_unintegrated"])
1616

17+
# make sure batch is string so we don't run into issues later on when subsetting
18+
# also make sure is_control is numeric
19+
adata.obs["batch"] = adata.obs["batch"].astype("str")
20+
adata.obs["is_control"] = adata.obs["is_control"].astype(int)
21+
1722
print("Extracting and splitting unintegrated data", flush=True)
1823

1924
# split 1
20-
adata_split1 = adata[(adata.obs.is_control > 0) | (adata.obs.batch == 1)]
25+
# reminder: is_control > 0 will include control samples.
26+
adata_split1 = adata[(adata.obs.is_control > 0) | (adata.obs.batch == "1")]
2127
integrated_split1 = adata_split1.layers["preprocessed"]
2228

2329
# split 2 == split 1 in this case
2430

31+
print(
32+
"Sanity check: verifying perfect integration have both control and non-control samples",
33+
flush=True,
34+
)
35+
# Check that we have both control and non-control cells
36+
n_control = (adata_split1.obs.is_control > 0).sum()
37+
n_non_control = (adata_split1.obs.is_control == 0).sum()
38+
39+
assert n_non_control > 0, (
40+
f"Split 1 should contain cells from non-control samples, but found {n_non_control} cells!"
41+
)
42+
assert n_control > 0, (
43+
f"Split 1 should contain cells from control samples, but found {n_control} cells!"
44+
)
45+
46+
2547
print("Write output AnnData to file", flush=True)
2648
# split 1
2749
output_split1 = ad.AnnData(

0 commit comments

Comments
 (0)