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

DEM: error when foreground and background regions have the same number of samples #6

Open
SeppeDeWinter opened this issue Jun 16, 2022 · 0 comments

Comments

@SeppeDeWinter
Copy link
Collaborator

When a contrast is given where fore and background have the same number of regions the following error occurs:

File /opt/venv/lib/python3.8/site-packages/pycistarget/motif_enrichment_dem.py:706, in DEM_internal(***failed resolving arguments***)
    704 keep_motifs = motif_df.index.tolist()
    705 keep_motifs_index = get_position_index(keep_motifs, motifs)
--> 706 scores_mat = sparse.vstack([fg_mat[keep_motifs_index,].T, bg_mat[keep_motifs_index,].T], format='csr').T
    707 regions = region_group[0] + ['Bg']*bg_mat.shape[1]
    708 labels = [1]*fg_mat.shape[1] + [0]*bg_mat.shape[1]

File /opt/venv/lib/python3.8/site-packages/scipy/sparse/_construct.py:553, in vstack(blocks, format, dtype)
    522 def vstack(blocks, format=None, dtype=None):
    523     """
    524     Stack sparse matrices vertically (row wise)
    525
   (...)
    551
    552     """
--> 553     return bmat([[b] for b in blocks], format=format, dtype=dtype)

File /opt/venv/lib/python3.8/site-packages/scipy/sparse/_construct.py:602, in bmat(blocks, format, dtype)
    599 blocks = np.asarray(blocks, dtype='object')
    601 if blocks.ndim != 2:
--> 602     raise ValueError('blocks must be 2-D')
    604 M,N = blocks.shape
    606 # check for fast path cases

ValueError: blocks must be 2-D

this occurs because internally in the sparse.vstack function the following is run.

np.array([fg_mat[keep_motifs_index,].T, bg_mat[keep_motifs_index,].T], object)

if both fg_mat and bg_mat have the same number of regions this will result in a np.array with dimension (2, n_regions, n_motfs) (this causes the error).

Ff they have different number of regions this will result in a np.array of two np.arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant