Skip to content

Commit

Permalink
Merge pull request #10 from aertslab/remove_region_from_matrix_when_o…
Browse files Browse the repository at this point in the history
…ut_of_bounds

Remove regions out of bounds from matrix
  • Loading branch information
LukasMahieu authored Jul 25, 2024
2 parents 7e26dc4 + 4204826 commit 3d7bc43
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/crested/pp/_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ def _check_input_params(chromsizes_file):

# Check if regions are within the chromosome boundaries
if chromsizes_file is not None:
regions_to_keep = list(adata.var_names.copy())
for idx, row in adata.var.iterrows():
chr_name = row["chr"]
start, end = row["start"], row["end"]
if start < 0 or end > chromsizes.get(chr_name, float("inf")):
logger.warning(
f"Region {idx} with coordinates {chr_name}:{start}-{end} is out of bounds for chromosome {chr_name}. Removing region."
)
adata.var.drop(idx, inplace=True)
regions_to_keep.remove(idx)
if len(regions_to_keep) < len(adata.var_names):
adata._inplace_subset_var(regions_to_keep)


adata.var_names.name = "region"

0 comments on commit 3d7bc43

Please sign in to comment.