Skip to content

Commit

Permalink
Adding static argument to Bio.Application, use for BWA
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjc committed May 21, 2013
1 parent 26314b0 commit ca93be7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
19 changes: 19 additions & 0 deletions Bio/Application/__init__.py
Expand Up @@ -173,6 +173,9 @@ def __init__(self, cmd, **kwargs):
#Create properties for each parameter at run time
aliases = set()
for p in parameters:
if not p.names:
assert isinstance(p, _StaticArgument), p
continue
for name in p.names:
if name in aliases:
raise ValueError("Parameter alias %s multiply defined"
Expand Down Expand Up @@ -610,6 +613,22 @@ def __str__(self):
return "%s " % self.value


class _StaticArgument(_AbstractParameter):
"""Represent a static (read only) argument on a commandline.
This is not intended to be exposed as a named argument or
property of a command line wrapper object.
"""
def __init__(self, value):
self.names = []
self.is_required = False
self.is_set = True
self.value = value

def __str__(self):
return "%s " % self.value


def _escape_filename(filename):
"""Escape filenames with spaces by adding quotes (PRIVATE).
Expand Down
18 changes: 11 additions & 7 deletions Bio/Sequencing/Applications/_bwa.py
Expand Up @@ -4,6 +4,7 @@
__docformat__ = "epytext en"

from Bio.Application import _Option, _Argument, _Switch, AbstractCommandline
from Bio.Application import _StaticArgument


class BwaIndexCommandline(AbstractCommandline):
Expand All @@ -27,10 +28,11 @@ class BwaIndexCommandline(AbstractCommandline):
Python subprocess module, as described in the Biopython tutorial.
"""
def __init__(self, cmd="bwa index", **kwargs):
def __init__(self, cmd="bwa", **kwargs):
self.program_name = cmd
self.parameters = \
[
_StaticArgument("index"),
_Option(["-a", "a", "algorithm"],
"""Algorithm for constructing BWT index.
Expand Down Expand Up @@ -79,10 +81,11 @@ class BwaAlignCommandline(AbstractCommandline):
You would typically run the command line using align_cmd(stdout=output_sai_file)
or via the Python subprocess module, as described in the Biopython tutorial.
"""
def __init__(self, cmd="bwa aln", **kwargs):
def __init__(self, cmd="bwa", **kwargs):
self.program_name = cmd
self.parameters = \
[
_StaticArgument("aln"),
_Argument(["reference"], "Reference file name",
filename=True, is_required=True),
_Argument(["read_file"], "Read file name",
Expand Down Expand Up @@ -190,12 +193,12 @@ class BwaSamseCommandline(AbstractCommandline):
You would typically run the command line using samse_cmd(stdout=output_sam_file)
or via the Python subprocess module, as described in the Biopython tutorial.
"""
def __init__(self, cmd="bwa samse", **kwargs):
def __init__(self, cmd="bwa", **kwargs):
self.program_name = cmd
self.parameters = \
[
_StaticArgument("samse"),
_Argument(["reference"], "Reference file name", filename=True, is_required=True),
_Argument(["sai_file"], "Sai file name", filename=True, is_required=True),
_Argument(["read_file"], "Read file name", filename=True, is_required=True),
Expand All @@ -209,7 +212,6 @@ def __init__(self, cmd="bwa samse", **kwargs):
"Specify the read group in a format like '@RG\tID:foo\tSM:bar'. [null]",
checker_function=lambda x: isinstance(x, int),
equate=False),

]
AbstractCommandline.__init__(self, cmd, **kwargs)

Expand Down Expand Up @@ -246,10 +248,11 @@ class BwaSampeCommandline(AbstractCommandline):
or via the Python subprocess module, as described in the Biopython tutorial.
"""
#TODO - Should the read group have a raw tab in it, or \t?
def __init__(self, cmd="bwa sampe", **kwargs):
def __init__(self, cmd="bwa", **kwargs):
self.program_name = cmd
self.parameters = \
[
_StaticArgument("sampe"),
_Argument(["reference"], "Reference file name", filename=True, is_required=True),
_Argument(["sai_file1"], "Sai file 1", filename=True, is_required=True),
_Argument(["sai_file2"], "Sai file 2", filename=True, is_required=True),
Expand Down Expand Up @@ -311,10 +314,11 @@ class BwaBwaswCommandline(AbstractCommandline):
You would typically run the command line using bwasw_cmd() or via the
Python subprocess module, as described in the Biopython tutorial.
"""
def __init__(self, cmd="bwa bwasw", **kwargs):
def __init__(self, cmd="bwa", **kwargs):
self.program_name = cmd
self.parameters = \
[
_StaticArgument("bwasw"),
_Argument(["reference"],"Reference file name", filename=True, is_required=True),
_Argument(["read_file"],"Read file", filename=True, is_required=True),
_Argument(["mate_file"],"Mate file", filename=True, is_required=False),
Expand Down

0 comments on commit ca93be7

Please sign in to comment.