[Biopython-dev] [Biopython - Feature #3326] MultipleSeqAlignment should support iterators, not only slice objects

redmine at redmine.open-bio.org redmine at redmine.open-bio.org
Mon Feb 20 17:58:38 EST 2012


Issue #3326 has been updated by Peter Cock.


It strikes me that while Python sequences don't support this at all, numpy arrays do allow indexing with a list - but surprisingly perhaps not an iterator. I imaging the problem with iterators is when you have more than one dimension (here we have slicing in one or two dimensions), and the fact you'd be forced to cache the iterator values in a list.

On balance, I would recommend doing this instead:

new_align = MultipleSeqAlignment(old_align[i] for i in row_iter)

Please bring this up on the mailing list if you want - we might spark some discussion and brainstorming.

----------------------------------------
Feature #3326: MultipleSeqAlignment should support iterators, not only slice objects
https://redmine.open-bio.org/issues/3326

Author: Fabio Zanini
Status: New
Priority: Normal
Assignee: Biopython Dev Mailing List
Category: Main Distribution
Target version: 
URL: 


Currently, the MultipleSeqAlignment object supports slicing via various syntaxes, e.g.:

- alignment[4,6]
- alignment[2:4,3:6]
- alignment[3:4:5]

In the latter case, the indices build a so-called slice, a pure Python object, and MultipleSeqAlignment has an explicit if clause for dealing with this case.

However, the user might want to iterate over the MSA using the more general *iterators*, e.g. from itertools, rather than simple slice objects. An extension that includes iterators looks easy:

# Check whether the index is an iterator
if (hasattr(index, 'next')) and (hasattr(index:, '__iter__')):
    return MultipleSeqAlignment([self._records[i] for i in index], self._alphabet)

Would you think this is useful?




-- 
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here and login: http://redmine.open-bio.org



More information about the Biopython-dev mailing list