vanheeringen-lab/genomepy

Import of `as_seqdict`

simonvh opened this issue · 9 comments

@siebrenf Is it necessary to have as_seqdict import in __init__.py?

It gives an error when genomepy is imported in another module due to a circular import of pybedtools (I think). Removing it from __init__.py fixes the issue.

It is not necessary.

I simply thought it was nice to expose this function to the surface level API as
genomepy.as_seqdict() vs genomepy.genome.seqdict.as_seqdict()

Yes, that's what I thought. I would indeed be nicer to have a shorter import, but this somehow results in weird import issues.

Bad news. Without importing as_seqdict in anywhere in genomepy it will not be accessible. When importing it, it will always cause a circular import error.

bottom line is we can't import pybedtools inside genomepy, unless its an older version.

We could make the bybedtools option available if pybedools has already been imported with
if "pybedtools" in sys.modules:

I think #174 may fix it. It's not too pretty, but I think importing in any order should work now. I also tried putting the import back in genomepy/__init__.py but that doesn't work.

I think it doesnt work :(

>>>import genomepy
>>>genomepy.genome.seqdict
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: module 'genomepy.genome' has no attribute 'seqdict'

As far as I understand it, we have to import the as_seqdict function, or its module, somewhere in genomepy. Otherwise it isn't reachable.
That also means the code is read, thus pybedtools is imported, and the recursion happens again...

So I think the "solution" it to remove the try import.

This does work:

>>> from genomepy.genome.seqdict import as_seqdict
>>>

Guess it's an "advanced feature" then ;)

Should we still move the seqdict module to a higher level?
I mean change it from from genomepy.genome.seqdict import as_seqdict to from genomepy.seq import as_seqdict

Yes, I think that's a good idea.