[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 13 08:24:02 UTC 2012
Issue #3326 has been updated by Fabio Zanini.
Sure, here the examples, one using a plain iter object, one using itertools.
# to get a subalignment with only rows at indices 1,7 and 8, you could write:
<pre>
iterator = iter([1,7,8])
alignment[iterator]
</pre>
# you want a subalignment with only the indices from a list index_list that are True ater a certain filter index_filter, i.e. for which index_filter(index_list[i]) == True:
<pre>
from itertools import ifilter
iterator = ifilter(index_filter, index_list)
alignment[iterator]
</pre>
The trivial example from the itertools website on this is the following:
<pre>
ifilter(lambda x: x%2, range(10)) --> 1 3 5 7 9
</pre>
----------------------------------------
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