[Biopython-dev] Switches in the Bio.Application interface
Peter
biopython at maubp.freeserve.co.uk
Mon May 4 11:03:17 EDT 2009
On Mon, May 4, 2009 at 3:48 PM, Peter <biopython at maubp.freeserve.co.uk> wrote:
> On Thu, Apr 30, 2009 at 1:05 PM, Brad Chapman <chapmanb at 50mail.com> wrote:
>> I love what you are doing here. The keywords and properties make
>> it much more Pythonic; the old way reeks of Java-style get/sets. My
>> vote is to put them both in.
>
> Cool - I was hoping people would agree it is more pythonic.
>
> I have some follow up thoughts, or points for discussion ...
>
> Peter
>
It seems sensible to me to allow "deleting" a property to clear it.
There is an example in the proposed Bio/Application/__init__.py
docstring of how this would work:
>>> from Bio.Emboss.Applications import WaterCommandline
>>> cline = WaterCommandline(gapopen=10, gapextend=0.5)
>>> cline
WaterCommandline(cmd='water', gapopen=10, gapextend=0.5)
You can also manipulate the parameters via their properties, e.g.
>>> cline.gapopen
10
>>> cline.gapopen = 20
>>> cline
WaterCommandline(cmd='water', gapopen=20, gapextend=0.5)
You can clear a parameter you have already added by 'deleting' the
corresponding property:
>>> del cline.gapopen
>>> cline.gapopen
>>> cline
WaterCommandline(cmd='water', gapextend=0.5)
That does seem to work and covers most situation, however there is a
special case of command line "switches" (arguments which don't take an
argument, like -kimura in ClustalW, or -l in ls). There are a lot of
these cases in Cymon's new alignment wrappers. These worked OK when
used with set_parameter("kimura"), the value is omitted and defaults
to None. Using the current patch, to set this via the keyword
argument or property, it must explicitly be set to None, which is
ugly:
>>> from Bio.Align.Applications import ClustalwCommandline
>>> print ClustalwCommandline(gapopen=2, gapext=0.5, infile="demo.fasta")
clustalw -infile=demo.fasta -gapopen=2 -gapext=0.5
>>> print ClustalwCommandline(gapopen=2, gapext=0.5, kimura=None, infile="demo.fasta")
clustalw -infile=demo.fasta -gapopen=2 -gapext=0.5 -kimura
For these "switch" arguments, perhaps the value should be interpreted
as a boolean (should the switch be added or not?). This would be a
change to the current API, but I don't think any of the existing
wrappers actually have this kind of parameter, so there shouldn't be a
backwards compatibility issue here. Instead I want to do this:
>>> from Bio.Align.Applications import ClustalwCommandline
>>> print ClustalwCommandline(gapopen=2, gapext=0.5, infile="demo.fasta")
clustalw -infile=demo.fasta -gapopen=2 -gapext=0.5
>>> print ClustalwCommandline(gapopen=2, gapext=0.5, kimura=True, infile="demo.fasta")
clustalw -infile=demo.fasta -gapopen=2 -gapext=0.5 -kimura
>>> print ClustalwCommandline(gapopen=2, gapext=0.5, kimura=False, infile="demo.fasta")
clustalw -infile=demo.fasta -gapopen=2 -gapext=0.5
An example use case is to allow parameter searches e.g.
from Bio.Align.Applications import ClustalwCommandline
for gap_open in [0, 1, 2, 10] :
for gap_extend in [0, 0.25, 0.5] :
for use_kimura in [True, False] :
#Won't work yet!:
cline = ClustalwCommandline(gapopen=gap_open,
gapext=gap_extend, kimura=use_kimura, infile="demo.fasta")
print cline
Or, modifying and reusing a single command line wrapper object:
from Bio.Align.Applications import ClustalwCommandline
#Set standard options:
cline = ClustalwCommandline(infile="demo.fasta")
#Do parameter sweep:
for gap_open in [0, 1, 2, 10] :
cline.gapopen = gap_open
for gap_extend in [0, 0.25, 0.5] :
cline.gapext = gap_extend
for use_kimura in [True, False] :
cline.kimura = use_kimura #Won't work yet!
print cline
Peter
More information about the Biopython-dev
mailing list