Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix counts_fragments_features #143

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions muon/_atac/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ def count_fragments_features(
raise ValueError("No column with strand for features could be found")
strand_col = features.columns.values[np.where(f_cols == chrom_col)[0][0]]

fragments = pysam.TabixFile(adata.uns["files"]["fragments"], parser=pysam.asBed())
fragments = pysam.TabixFile(adata.uns["files"]["fragments"])
try:
# List of lists matrix is quick and convenient to fill by row
mx = lil_matrix((n_features, n), dtype=int)
Expand All @@ -867,7 +867,7 @@ def count_fragments_features(
f_from = f[start_col] - extend_upstream
f_to = f[end_col] + extend_downstream

for fr in fragments.fetch(f[chr_col], f_from, f_to):
for fr in fragments.fetch(f[chr_col], f_from, f_to, parser=pysam.asBed()):
try:
ind = adata.obs.index.get_loc(fr.name) # cell barcode (e.g. GTCAGTCAGTCAGTCA-1)
mx.rows[i].append(ind)
Expand All @@ -878,7 +878,8 @@ def count_fragments_features(
mx.data[i].append(1)
except:
pass

# The connection has to be closed
fragments.close()
# Faster to convert to csr first and then transpose
mx = mx.tocsr().transpose()

Expand Down
Loading