Skip to content

'Bio.trie.trie' is not picklable #912

Closed

Description

@twrightsman

Originally filed as https://redmine.open-bio.org/issues/3337 in 2012

@superbobry said:

Is there any reason for this, or nobody just had the need (or time) to implement pickle interface?

Activity

  1. twrightsman commented on Aug 8, 2016

    @twrightsman
    Author

    @etal replied:

    @superbobry wrote:

    Is there any reason for this, or nobody just had the need (or time) to implement pickle interface?

    The latter, I believe. That module is also missing Python 3 compatibility; it might be easier to try writing a pure-Python replacement -- which can import the sped-up C functions at the end of the module, maybe. Either would be nice.

  2. twrightsman commented on Aug 8, 2016

    @twrightsman
    Author

    @superbobry replied:

    A pure-Python replacement would probably be much less efficient in terms of memory consumption.

  3. twrightsman commented on Aug 8, 2016

    @twrightsman
    Author

    Can confirm trie object is still not pickleable:

    $ python3
    Python 3.5.2 (default, Jul 28 2016, 21:28:00) 
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from Bio import trie
    >>> import pickle
    >>> myTrie = trie.trie()
    >>> myTrie['test'] = 123
    >>> pickle.dump(myTrie, open('trie.pkl', 'wb'))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: can't pickle trie objects
    
  4. peterjc commented on Aug 8, 2016

    @peterjc
    Member

    (On the bright side, Bio.Trie has been updated to support Python 3)

  5. mdehoon commented on Mar 23, 2018

    @mdehoon
    Contributor

    You can pickle the trie as a dictionary:

    >>> from Bio import trie
    >>> import pickle
    >>> myTrie = trie.trie()
    >>> myTrie['test'] = 123
    >>> pickle.dump(dict(myTrie), open('trie.pkl', 'wb'))

    To get the same trie back, you would do

    >>> from Bio import trie
    >>> import pickle
    >>> myTrie = trie.trie()
    >>> d = pickle.load(open('trie.pkl', 'rb'))
    >>> for key in d:
    ...     myTrie[key] = d[key]
  6. mdehoon commented on Mar 23, 2018

    @mdehoon
    Contributor

    Adding pickle support to the trie object directly is also possible, and actually quite easy in Python. It is also possible in C, but will be quite painful and ugly code. To add pickle support in Python, we'd have to create a Bio/trie.py module or Bio/trie/init.py module (or some other place where the Python code can live).

  7. mdehoon commented on Apr 2, 2018

    @mdehoon
    Contributor

    @twrightsman Would you be able to use the pygtrie package instead of the Trie code in Biopython?

  8. twrightsman commented on Apr 3, 2018

    @twrightsman
    Author

    I don't need Trie objects in Biopython at the moment but would it be a good idea to outsource the Trie objects to pygtrie in Biopython or is that overkill (and just adds another dependency)?

  9. peterjc commented on Apr 3, 2018

    @peterjc
    Member

    We could just deprecate Bio.trie and recommend people use pygtrie instead.

  10. mdehoon commented on Apr 7, 2018

    @mdehoon
    Contributor

    @twrightsman I am not sure if I understand. As far as I can tell, the trie modules on Biopython do not depend on anything else in Biopython, and vice versa, so they are completely independent.

  11. twrightsman commented on Apr 10, 2018

    @twrightsman
    Author

    @mdehoon I was suggesting that Biopython drop the Trie module (but agree with @peterjc that it should be depreciated first) and instead suggest to user to use pygtrie instead. Since you mention that nothing else in Biopython is dependent on Trie, it seems to be safe to depreciate?

  12. peterjc commented on Apr 10, 2018

    @peterjc
    Member

    It had crossed my mind to move Bio.trie to a separate repository and entry on PyPI, but ideally someone would step up to maintain it - otherwise there is little point.

  13. mdehoon commented on Apr 11, 2018

    @mdehoon
    Contributor

    @twrightsman OK. I think it is safe to deprecate and then remove the Trie module.

    @peterjc I had also thought about moving Bio.trie to a separate repository, but since pygtrie already exists and looks like it is actively maintained, I guess there is no point to have a separate Bio.trie as well.

  14. peterjc commented on Apr 11, 2018

    @peterjc
    Member

    I have asked on #636 if they'd like to take over maintenance of Bio.trie as a standalone package.

  15. gmjonker commented on May 16, 2019

    @gmjonker

    I compared several trie implementations, and found that Bio.trie is by far the best in terms of speed and memory usage.

  16. peterjc commented on Jul 24, 2020

    @peterjc
    Member

    Closing - We removed Bio.trie in #2501

    Thank you @chebizarro for issue triage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions