Skip to content

Can only do stranded operations when both PyRanges contain strand info #388

Description

@fairliereese

Hi @endrebak and @marco-mariotti. This issue is a follow-up for the discussion in #374. As usual, apologies for the delays.

I have a minimal example including a small bed file that produces the error with version 0.1.2. As per my previous comment, the key difference here is converting between Pandas DataFrames and PyRanges objects:

import pyranges as pr
pr.__version__

0.1.2

# no conversion between data types; runs fine
df = pr.read_bed('test.bed')
df = df.merge(strand=True,
              count=True,
              count_col='n_genes',
              slack=0)
# converting from PyRanges to Pandas DataFrame and back; error
df = pr.read_bed('test.bed')
df = df.df
df = pr.PyRanges(df)
df = df.merge(strand=True,
              count=True,
              count_col='n_genes',
              slack=0) 
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[18], line 4
      2 df = df.df
      3 df = pr.PyRanges(df)
----> 4 df = df.merge(strand=True,
      5               count=True,
      6               count_col='n_genes',
      7               slack=0)

File [~/miniconda3/envs/cerberus_3/lib/python3.9/site-packages/pyranges/pyranges_main.py:3139](http://localhost:8890/lab/tree/data/pseudomasked_genomic_isoquant_guided/raw/~/miniconda3/envs/cerberus_3/lib/python3.9/site-packages/pyranges/pyranges_main.py#line=3138), in PyRanges.merge(self, strand, count, count_col, by, slack)
   3136     kwargs["sparse"] = {"self": True}
   3137     from pyranges.methods.merge import _merge
-> 3139     df = pyrange_apply_single(_merge, self, **kwargs)
   3140 else:
   3141     kwargs["sparse"] = {"self": False}

File [~/miniconda3/envs/cerberus_3/lib/python3.9/site-packages/pyranges/multithreaded.py:320](http://localhost:8890/lab/tree/data/pseudomasked_genomic_isoquant_guided/raw/~/miniconda3/envs/cerberus_3/lib/python3.9/site-packages/pyranges/multithreaded.py#line=319), in pyrange_apply_single(function, self, **kwargs)
    317 function, get, _merge_dfs = get_multithreaded_funcs(function, nb_cpu=nb_cpu)
    319 if strand:
--> 320     assert self.stranded, "Can only do stranded operation when PyRange contains strand info"
    322 results = []
    324 if strand:

AssertionError: Can only do stranded operation when PyRange contains strand info

As I mentioned in this comment, I was able to circumvent this behavior in my branch by commenting out a check for different categories in the strand column (see this commit in my branch). I would be happy to help put a more permanent solution into place for this library but wanted to check with you all first before committing to something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions