Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/cell_load/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def get_fewshot_celltypes(self, dataset: str) -> dict[str, dict[str, list[str]]]
if key.startswith(f"{dataset}."):
celltype = key.split(".", 1)[1]
result[celltype] = pert_config
print(dataset, celltype, {k: len(v) for k, v in pert_config.items()})
return result

def validate(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/cell_load/data_modules/perturbation_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
num_workers: Num workers for PyTorch DataLoader
few_shot_percent: Fraction of data to use for few-shot tasks
random_seed: For reproducible splits & sampling
embed_key: Embedding key or matrix in the H5 file to use for feauturizing cells
embed_key: Embedding key or matrix in the H5 file to use for featurizing cells
output_space: The output space for model predictions (gene or latent, which uses embed_key)
basal_mapping_strategy: One of {"batch","random","nearest","ot"}
n_basal_samples: Number of control cells to sample per perturbed cell
Expand Down
4 changes: 2 additions & 2 deletions src/cell_load/dataset/_perturbation.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ def collate_fn(batch, int_counts=False):
if has_ctrl_cell_counts:
ctrl_cell_counts = torch.stack(ctrl_cell_counts_list)

is_discrete = suspected_discrete_torch(pert_cell_counts)
is_log = suspected_log_torch(pert_cell_counts)
is_discrete = suspected_discrete_torch(ctrl_cell_counts)
is_log = suspected_log_torch(ctrl_cell_counts)
already_logged = (not is_discrete) and is_log

if already_logged: # counts are already log transformed
Expand Down
10 changes: 7 additions & 3 deletions src/cell_load/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ def is_on_target_knockdown(
return False

if target_gene not in adata.var_names:
print(f"Gene {target_gene!r} not found in `adata.var_names`.")
return 1
raise KeyError(f"Gene {target_gene!r} not found in `adata.var_names`.")

gene_idx = adata.var_names.get_loc(target_gene)
X = adata.layers[layer] if layer is not None else adata.X
Expand Down Expand Up @@ -396,7 +395,9 @@ def filter_on_target_knockdown(
return adata_[keep_mask]


def set_var_index_to_col(adata: anndata.AnnData, col: str = "col", copy=True) -> None:
def set_var_index_to_col(
adata: anndata.AnnData, col: str = "col", copy: bool = True
) -> anndata.AnnData:
"""
Set `adata.var` index to the values in the specified column, allowing non-unique indices.

Expand All @@ -412,6 +413,9 @@ def set_var_index_to_col(adata: anndata.AnnData, col: str = "col", copy=True) ->
KeyError
If the specified column does not exist in `adata.var`.
"""
if copy:
adata = adata.copy()

if col not in adata.var.columns:
raise KeyError(f"Column {col!r} not found in adata.var.")

Expand Down