[Biopython-dev] [BioPython] about the SeqRecord slicing
Eric Talevich
eric.talevich at gmail.com
Fri Mar 27 15:16:19 UTC 2009
On Fri, Mar 27, 2009 at 10:24 AM, Peter <biopython at maubp.freeserve.co.uk>wrote:
> On Fri, Mar 27, 2009 at 2:17 PM, Sebastian Bassi
> <sbassi at clubdelarazon.org> wrote:
> > On Fri, Mar 27, 2009 at 10:57 AM, Peter <biopython at maubp.freeserve.co.uk>
> wrote:
> >> How would you make it optional? As an extra non-standard argument
> >> to __getitem__? e.g.something like my_record[10:50, annotation=False]?
> >> That seems nasty.
> >
> > Yes it is nasty this way, I never meant to do it in __getitem__.
> > Anyway I can't think a nice and intuitive way to do it.
>
> Me neither right now.
>
> >> If we did drop the annotations and dbxrefs when slicing, the user can
> >> manually choose to explicitly copy them from the parent object if the
> >> do want them.
> >
> > Yes, that is OK.
>
>
One way to allow non-default options for adding and slicing is to provide a
couple of functions at the class or module level (classmethod, staticmethod,
plain ol' function) that have the necessary keyword arguments. These
functions would do the same thing by default as the corresponding syntax,
and the syntax-friendly magic methods would just pass their arguments
straight to these functions. This makes the syntax pretty for the common
cases, and makes the nonstandard stuff visually obvious.
Examples:
my_record.slice(10, 50) == my_record[10:50]
my_record.slice(10, 50, annotation=True) == my_record[10:50] plus updated
annotations
my_record.add(other_record) == my_record + other_record
my_record.add(other_record, annotation=True) == my_record + other_record,
keeping annotations
my_record.slice(10, 50, annotation=True).add(
my_record.slice(100, 200, annotation=True),
annotation=True) == my_record[10:50] + my_record[100:200], keeping all
annotations (a pain otherwise)
More information about the Biopython-dev
mailing list