Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.Align.Applications._Mafft.MafftCommandline Class Reference
Inheritance diagram for Bio.Align.Applications._Mafft.MafftCommandline:
Inheritance graph
[legend]
Collaboration diagram for Bio.Align.Applications._Mafft.MafftCommandline:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __str__
def __repr__
def set_parameter
def __setattr__
def __call__

Public Attributes

 parameters
 program_name

Detailed Description

Command line wrapper for the multiple alignment program MAFFT.

http://align.bmr.kyushu-u.ac.jp/mafft/software/

Example:

>>> from Bio.Align.Applications import MafftCommandline
>>> mafft_exe = "/opt/local/mafft"
>>> in_file = "../Doc/examples/opuntia.fasta"
>>> mafft_cline = MafftCommandline(mafft_exe, input=in_file)
>>> print mafft_cline
/opt/local/mafft ../Doc/examples/opuntia.fasta

If the mafft binary is on the path (typically the case on a Unix style
operating system) then you don't need to supply the executable location:

>>> from Bio.Align.Applications import MafftCommandline
>>> in_file = "../Doc/examples/opuntia.fasta"
>>> mafft_cline = MafftCommandline(input=in_file)
>>> print mafft_cline
mafft ../Doc/examples/opuntia.fasta

You would typically run the command line with mafft_cline() or via
the Python subprocess module, as described in the Biopython tutorial.
Note that MAFFT will write the alignment to stdout, which you may
want to save to a file and then parse, e.g.

stdout, stderr = mafft_cline()
handle = open("aligned.fasta", "w")
handle.write(stdout)
handle.close()
from Bio import AlignIO
align = AlignIO.read("aligned.fasta", "fasta")

Alternatively, to parse the output with AlignIO directly you can
use StringIO to turn the string into a handle:

stdout, stderr = mafft_cline()
from StringIO import StringIO
from Bio import AlignIO
align = AlignIO.read(StringIO(stdout), "fasta")

Citations:

Katoh, Toh (BMC Bioinformatics 9:212, 2008) Improved accuracy of
multiple ncRNA alignment by incorporating structural information into
a MAFFT-based framework (describes RNA structural alignment methods)

Katoh, Toh (Briefings in Bioinformatics 9:286-298, 2008) Recent
developments in the MAFFT multiple sequence alignment program
(outlines version 6)

Katoh, Toh (Bioinformatics 23:372-374, 2007)  Errata PartTree: an
algorithm to build an approximate tree from a large number of
unaligned sequences (describes the PartTree algorithm)

Katoh, Kuma, Toh, Miyata (Nucleic Acids Res. 33:511-518, 2005) MAFFT
version 5: improvement in accuracy of multiple sequence alignment
(describes [ancestral versions of] the G-INS-i, L-INS-i and E-INS-i
strategies)

Katoh, Misawa, Kuma, Miyata (Nucleic Acids Res. 30:3059-3066, 2002)

Last checked against version: MAFFT v6.717b (2009/12/03)

Definition at line 16 of file _Mafft.py.


Constructor & Destructor Documentation

def Bio.Align.Applications._Mafft.MafftCommandline.__init__ (   self,
  cmd = "mafft",
  kwargs 
)
Create a new instance of a command line wrapper object.

Reimplemented from Bio.Application.AbstractCommandline.

Definition at line 82 of file _Mafft.py.

00082 
00083     def __init__(self, cmd="mafft", **kwargs):
00084         BLOSUM_MATRICES = ["30","45","62","80"]
00085         self.parameters = \
00086             [
00087             #**** Algorithm ****
00088             #Automatically selects an appropriate strategy from L-INS-i, FFT-NS-
00089             #i and FFT-NS-2, according to data size. Default: off (always FFT-NS-2)
00090             _Switch(["--auto", "auto"],
00091                     "Automatically select strategy. Default off."),
00092             #Distance is calculated based on the number of shared 6mers. Default: on
00093             _Switch(["--6merpair", "6merpair", "sixmerpair"],
00094                     "Distance is calculated based on the number of shared "
00095                     "6mers. Default: on"),
00096             #All pairwise alignments are computed with the Needleman-Wunsch
00097             #algorithm. More accurate but slower than --6merpair. Suitable for a
00098             #set of globally alignable sequences. Applicable to up to ~200
00099             #sequences. A combination with --maxiterate 1000 is recommended (G-
00100             #INS-i). Default: off (6mer distance is used)
00101             _Switch(["--globalpair", "globalpair"],
00102                     "All pairwise alignments are computed with the "
00103                     "Needleman-Wunsch algorithm. Default: off"),
00104             #All pairwise alignments are computed with the Smith-Waterman
00105             #algorithm. More accurate but slower than --6merpair. Suitable for a
00106             #set of locally alignable sequences. Applicable to up to ~200
00107             #sequences. A combination with --maxiterate 1000 is recommended (L-
00108             #INS-i). Default: off (6mer distance is used)
00109             _Switch(["--localpair", "localpair"],
00110                     "All pairwise alignments are computed with the "
00111                     "Smith-Waterman algorithm. Default: off"),
00112             #All pairwise alignments are computed with a local algorithm with
00113             #the generalized affine gap cost (Altschul 1998). More accurate but
00114             #slower than --6merpair. Suitable when large internal gaps are
00115             #expected. Applicable to up to ~200 sequences. A combination with --
00116             #maxiterate 1000 is recommended (E-INS-i). Default: off (6mer
00117             #distance is used)
00118             _Switch(["--genafpair", "genafpair"],
00119                     "All pairwise alignments are computed with a local "
00120                     "algorithm with the generalized affine gap cost "
00121                     "(Altschul 1998). Default: off"),
00122             #All pairwise alignments are computed with FASTA (Pearson and Lipman
00123             #1988). FASTA is required. Default: off (6mer distance is used)
00124             _Switch(["--fastapair", "fastapair"],
00125                     "All pairwise alignments are computed with FASTA "
00126                     "(Pearson and Lipman 1988). Default: off"),
00127             #Weighting factor for the consistency term calculated from pairwise
00128             #alignments. Valid when either of --blobalpair, --localpair, --
00129             #genafpair, --fastapair or --blastpair is selected. Default: 2.7
00130             _Option(["--weighti", "weighti"],
00131                     "Weighting factor for the consistency term calculated "
00132                     "from pairwise alignments. Default: 2.7",
00133                     checker_function=lambda x: isinstance(x, float),
00134                     equate=False),
00135             #Guide tree is built number times in the progressive stage. Valid
00136             #with 6mer distance. Default: 2
00137             _Option(["--retree", "retree"],
00138                     "Guide tree is built number times in the progressive "
00139                     "stage. Valid with 6mer distance. Default: 2",
00140                     checker_function=lambda x: isinstance(x, int),
00141                     equate=False),
00142             #Number cycles of iterative refinement are performed. Default: 0
00143             _Option(["--maxiterate", "maxiterate"],
00144                     "Number cycles of iterative refinement are performed. "
00145                     "Default: 0",
00146                     checker_function=lambda x: isinstance(x, int),
00147                     equate=False),
00148             #Use FFT approximation in group-to-group alignment. Default: on
00149             _Switch(["--fft", "fft"],
00150                     "Use FFT approximation in group-to-group alignment. "
00151                     "Default: on"),
00152             #Do not use FFT approximation in group-to-group alignment. Default:
00153             #off
00154             _Switch(["--nofft", "nofft"],
00155                     "Do not use FFT approximation in group-to-group "
00156                     "alignment. Default: off"),
00157             #Alignment score is not checked in the iterative refinement stage.
00158             #Default: off (score is checked)
00159             _Switch(["--noscore", "noscore"],
00160                     "Alignment score is not checked in the iterative "
00161                     "refinement stage. Default: off (score is checked)"),
00162             #Use the Myers-Miller (1988) algorithm. Default: automatically
00163             #turned on when the alignment length exceeds 10,000 (aa/nt).
00164             _Switch(["--memsave", "memsave"],
00165                     "Use the Myers-Miller (1988) algorithm. Default: "
00166                     "automatically turned on when the alignment length "
00167                     "exceeds 10,000 (aa/nt)."),
00168             #Use a fast tree-building method (PartTree, Katoh and Toh 2007) with
00169             #the 6mer distance. Recommended for a large number (> ~10,000) of
00170             #sequences are input. Default: off
00171             _Switch(["--parttree", "parttree"],
00172                     "Use a fast tree-building method with the 6mer "
00173                     "distance. Default: off"),
00174             #The PartTree algorithm is used with distances based on DP. Slightly
00175             #more accurate and slower than --parttree. Recommended for a large
00176             #number (> ~10,000) of sequences are input. Default: off
00177             _Switch(["--dpparttree", "dpparttree"],
00178                     "The PartTree algorithm is used with distances "
00179                     "based on DP. Default: off"),
00180             #The PartTree algorithm is used with distances based on FASTA.
00181             #Slightly more accurate and slower than --parttree. Recommended for
00182             #a large number (> ~10,000) of sequences are input. FASTA is
00183             #required. Default: off
00184             _Switch(["--fastaparttree", "fastaparttree"],
00185                     "The PartTree algorithm is used with distances based "
00186                     "on FASTA. Default: off"),
00187             #The number of partitions in the PartTree algorithm. Default: 50
00188             _Option(["--partsize", "partsize"],
00189                     "The number of partitions in the PartTree algorithm. "
00190                     "Default: 50",
00191                     checker_function=lambda x: isinstance(x, int),
00192                     equate=False),
00193             #Do not make alignment larger than number sequences. Valid only with
00194             #the --*parttree options. Default: the number of input sequences
00195             _Switch(["--groupsize", "groupsize"],
00196                     "Do not make alignment larger than number sequences. "
00197                     "Default: the number of input sequences"),
00198             #**** Parameter ****
00199             #Gap opening penalty at group-to-group alignment. Default: 1.53
00200             _Option(["--op", "op"],
00201                     "Gap opening penalty at group-to-group alignment. "
00202                     "Default: 1.53",
00203                     checker_function=lambda x: isinstance(x, float),
00204                     equate=False),
00205             #Offset value, which works like gap extension penalty, for group-to-
00206             #group alignment. Deafult: 0.123
00207             _Option(["--ep", "ep"],
00208                     "Offset value, which works like gap extension penalty, "
00209                     "for group-to- group alignment. Default: 0.123",
00210                     checker_function=lambda x: isinstance(x, float),
00211                     equate=False),
00212             #Gap opening penalty at local pairwise alignment. Valid when the --
00213             #localpair or --genafpair option is selected. Default: -2.00
00214             _Option(["--lop", "lop"],
00215                     "Gap opening penalty at local pairwise alignment. "
00216                     "Default: 0.123",
00217                     checker_function=lambda x: isinstance(x, float),
00218                     equate=False),
00219             #Offset value at local pairwise alignment. Valid when the --
00220             #localpair or --genafpair option is selected. Default: 0.1
00221             _Option(["--lep", "lep"],
00222                     "Offset value at local pairwise alignment. "
00223                     "Default: 0.1",
00224                     checker_function=lambda x: isinstance(x, float),
00225                     equate=False),
00226             #Gap extension penalty at local pairwise alignment. Valid when the -
00227             #-localpair or --genafpair option is selected. Default: -0.1
00228             _Option(["--lexp", "lexp"],
00229                     "Gap extension penalty at local pairwise alignment. "
00230                     "Default: -0.1",
00231                     checker_function=lambda x: isinstance(x, float),
00232                     equate=False),
00233             #Gap opening penalty to skip the alignment. Valid when the --
00234             #genafpair option is selected. Default: -6.00
00235             _Option(["--LOP", "LOP"],
00236                     "Gap opening penalty to skip the alignment. "
00237                     "Default: -6.00",
00238                     checker_function=lambda x: isinstance(x, float),
00239                     equate=False),
00240             #Gap extension penalty to skip the alignment. Valid when the --
00241             #genafpair option is selected. Default: 0.00
00242             _Option(["--LEXP", "LEXP"],
00243                     "Gap extension penalty to skip the alignment. "
00244                     "Default: 0.00",
00245                     checker_function=lambda x: isinstance(x, float),
00246                     equate=False),
00247 
00248             #BLOSUM number matrix (Henikoff and Henikoff 1992) is used.
00249             #number=30, 45, 62 or 80. Default: 62
00250             _Option(["--bl", "bl"],
00251                     "BLOSUM number matrix is used. Default: 62",
00252                     checker_function=lambda x: x in BLOSUM_MATRICES,
00253                     equate=False),
00254             #JTT PAM number (Jones et al. 1992) matrix is used. number>0.
00255             #Default: BLOSUM62
00256             _Option(["--jtt", "jtt"],
00257                     "JTT PAM number (Jones et al. 1992) matrix is used. "
00258                     "number>0. Default: BLOSUM62",
00259                     equate=False),
00260             #Transmembrane PAM number (Jones et al. 1994) matrix is used.
00261             #number>0. Default: BLOSUM62
00262             _Option(["--tm", "tm"],
00263                     "Transmembrane PAM number (Jones et al. 1994) "
00264                     "matrix is used. number>0. Default: BLOSUM62",
00265                     checker_function=os.path.exists,
00266                     filename=True,
00267                     equate=False),
00268             #Use a user-defined AA scoring matrix. The format of matrixfile is
00269             #the same to that of BLAST. Ignored when nucleotide sequences are
00270             #input. Default: BLOSUM62
00271             _Option(["--aamatrix", "aamatrix"],
00272                     "Use a user-defined AA scoring matrix. "
00273                     "Default: BLOSUM62",
00274                     checker_function=os.path.exists,
00275                     filename=True,
00276                     equate=False),
00277             #Incorporate the AA/nuc composition information into the scoring
00278             #matrix. Default: off
00279             _Switch(["--fmodel", "fmodel"],
00280                     "Incorporate the AA/nuc composition information into "
00281                     "the scoring matrix (True) or not (False, default)"),
00282             #**** Output ****
00283             #Output format: clustal format. Default: off (fasta format)
00284             _Switch(["--clustalout", "clustalout"],
00285                     "Output format: clustal (True) or fasta (False, default)"),
00286             #Output order: same as input. Default: on
00287             _Switch(["--inputorder", "inputorder"],
00288                     "Output order: same as input (True, default) or alignment "
00289                     "based (False)"),
00290             #Output order: aligned. Default: off (inputorder)
00291             _Switch(["--reorder", "reorder"],
00292                     "Output order: aligned (True) or in input order (False, "
00293                     "default)"),
00294             #Guide tree is output to the input.tree file. Default: off
00295             _Switch(["--treeout", "treeout"],
00296                     "Guide tree is output to the input.tree file (True) or "
00297                     "not (False, default)"),
00298             #Do not report progress. Default: off
00299             _Switch(["--quiet", "quiet"],
00300                     "Do not report progress (True) or not (False, default)."),
00301             #**** Input ****
00302             #Assume the sequences are nucleotide. Deafult: auto
00303             _Switch(["--nuc", "nuc"],
00304                     "Assume the sequences are nucleotide (True/False). "
00305                     "Default: auto"),
00306             #Assume the sequences are amino acid. Deafult: auto
00307             _Switch(["--amino", "amino"],
00308                     "Assume the sequences are amino acid (True/False). "
00309                     "Default: auto"),
00310             ###################### SEEDS #####################################
00311             # MAFFT has multiple --seed commands where the unaligned input is
00312             # aligned to the seed alignment. There can be multiple seeds in the
00313             # form: "mafft --seed align1 --seed align2 [etc] input"
00314             # Effectively for n number of seed alignments. Here we're going to
00315             # assume 6 extra are enough
00316             _Option(["--seed", "seed"],
00317                     "Seed alignments given in alignment_n (fasta format) "
00318                     "are aligned with sequences in input.",
00319                     checker_function=os.path.exists,
00320                     filename=True,
00321                     equate=False),
00322             #The old solution of also defining extra parameters with
00323             #["--seed", "seed1"] etc worked, but clashes with the recent
00324             #code in the base class to look for duplicate paramters and raise
00325             #an error.  Perhaps that check should be ignored here, or maybe
00326             #we can handle this more elegantly...
00327             #TODO - Create an _OptionList parameter which allows a list to be
00328             #assigned to the value?
00329             ####################### END SEEDS  ################################
00330             #The input (must be FASTA format)
00331             _Argument(["input"],
00332                       "Input file name",
00333                       checker_function=os.path.exists,
00334                       filename=True,
00335                       is_required=True),
00336             ###################################################################
00337             #mafft-profile takes a second alignment input as an argument:
00338             #mafft-profile align1 align2
00339             _Argument(["input1"],
00340                       "Second input file name for the mafft-profile command",
00341                       checker_function=os.path.exists,
00342                       filename=True),
00343             ]
00344         AbstractCommandline.__init__(self, cmd, **kwargs)

Here is the caller graph for this function:


Member Function Documentation

def Bio.Application.AbstractCommandline.__call__ (   self,
  stdin = None,
  stdout = True,
  stderr = True,
  cwd = None,
  env = None 
) [inherited]
Executes the command, waits for it to finish, and returns output.

Runs the command line tool and waits for it to finish. If it returns
a non-zero error level, an exception is raised. Otherwise two strings
are returned containing stdout and stderr.

The optional stdin argument should be a string of data which will be
passed to the tool as standard input.

The optional stdout and stderr argument are treated as a booleans, and
control if the output should be captured (True, default), or ignored
by sending it to /dev/null to avoid wasting memory (False). In the
later case empty string(s) are returned.

The optional cwd argument is a string giving the working directory to
to run the command from. See Python's subprocess module documentation
for more details.

The optional env argument is a dictionary setting the environment
variables to be used in the new process. By default the current
process' environment variables are used. See Python's subprocess
module documentation for more details.

Default example usage:

from Bio.Emboss.Applications import WaterCommandline
water_cmd = WaterCommandline(gapopen=10, gapextend=0.5,
                     stdout=True, auto=True,
                     asequence="a.fasta", bsequence="b.fasta")
print "About to run:\n%s" % water_cmd
std_output, err_output = water_cmd()

This functionality is similar to subprocess.check_output() added in
Python 2.7. In general if you require more control over running the
command, use subprocess directly.

As of Biopython 1.56, when the program called returns a non-zero error
level, a custom ApplicationError exception is raised. This includes
any stdout and stderr strings captured as attributes of the exception
object, since they may be useful for diagnosing what went wrong.

Definition at line 368 of file __init__.py.

00368 
00369                  cwd=None, env=None):
00370         """Executes the command, waits for it to finish, and returns output.
00371         
00372         Runs the command line tool and waits for it to finish. If it returns
00373         a non-zero error level, an exception is raised. Otherwise two strings
00374         are returned containing stdout and stderr.
00375         
00376         The optional stdin argument should be a string of data which will be
00377         passed to the tool as standard input.
00378 
00379         The optional stdout and stderr argument are treated as a booleans, and
00380         control if the output should be captured (True, default), or ignored
00381         by sending it to /dev/null to avoid wasting memory (False). In the
00382         later case empty string(s) are returned.
00383 
00384         The optional cwd argument is a string giving the working directory to
00385         to run the command from. See Python's subprocess module documentation
00386         for more details.
00387 
00388         The optional env argument is a dictionary setting the environment
00389         variables to be used in the new process. By default the current
00390         process' environment variables are used. See Python's subprocess
00391         module documentation for more details.
00392 
00393         Default example usage:
00394 
00395         from Bio.Emboss.Applications import WaterCommandline
00396         water_cmd = WaterCommandline(gapopen=10, gapextend=0.5,
00397                                      stdout=True, auto=True,
00398                                      asequence="a.fasta", bsequence="b.fasta")
00399         print "About to run:\n%s" % water_cmd
00400         std_output, err_output = water_cmd()
00401 
00402         This functionality is similar to subprocess.check_output() added in
00403         Python 2.7. In general if you require more control over running the
00404         command, use subprocess directly.
00405         
00406         As of Biopython 1.56, when the program called returns a non-zero error
00407         level, a custom ApplicationError exception is raised. This includes
00408         any stdout and stderr strings captured as attributes of the exception
00409         object, since they may be useful for diagnosing what went wrong.
00410         """
00411         if stdout:
00412             stdout_arg = subprocess.PIPE
00413         else:
00414             stdout_arg = open(os.devnull)
00415         if stderr:
00416             stderr_arg = subprocess.PIPE
00417         else:
00418             stderr_arg = open(os.devnull)
00419         #We may not need to supply any piped input, but we setup the
00420         #standard input pipe anyway as a work around for a python
00421         #bug if this is called from a Windows GUI program.  For
00422         #details, see http://bugs.python.org/issue1124861
00423         #
00424         #Using universal newlines is important on Python 3, this
00425         #gives unicode handles rather than bytes handles.
00426         child_process = subprocess.Popen(str(self), stdin=subprocess.PIPE,
00427                                          stdout=stdout_arg, stderr=stderr_arg,
00428                                          universal_newlines=True,
00429                                          cwd=cwd, env=env,
00430                                          shell=(sys.platform!="win32"))
00431         #Use .communicate as can get deadlocks with .wait(), see Bug 2804
00432         stdout_str, stderr_str = child_process.communicate(stdin)
00433         if not stdout: assert not stdout_str
00434         if not stderr: assert not stderr_str
00435         return_code = child_process.returncode
00436         if return_code:
00437             raise ApplicationError(return_code, str(self),
00438                                    stdout_str, stderr_str)
00439         return stdout_str, stderr_str
00440 

Here is the call graph for this function:

Here is the caller graph for this function:

Return a representation of the command line object for debugging.

e.g.
>>> from Bio.Emboss.Applications import WaterCommandline
>>> cline = WaterCommandline(gapopen=10, gapextend=0.5)
>>> cline.asequence = "asis:ACCCGGGCGCGGT"
>>> cline.bsequence = "asis:ACCCGAGCGCGGT"
>>> cline.outfile = "temp_water.txt"
>>> print cline
water -outfile=temp_water.txt -asequence=asis:ACCCGGGCGCGGT -bsequence=asis:ACCCGAGCGCGGT -gapopen=10 -gapextend=0.5
>>> cline
WaterCommandline(cmd='water', outfile='temp_water.txt', asequence='asis:ACCCGGGCGCGGT', bsequence='asis:ACCCGAGCGCGGT', gapopen=10, gapextend=0.5)

Definition at line 251 of file __init__.py.

00251 
00252     def __repr__(self):
00253         """Return a representation of the command line object for debugging.
00254 
00255         e.g.
00256         >>> from Bio.Emboss.Applications import WaterCommandline
00257         >>> cline = WaterCommandline(gapopen=10, gapextend=0.5)
00258         >>> cline.asequence = "asis:ACCCGGGCGCGGT"
00259         >>> cline.bsequence = "asis:ACCCGAGCGCGGT"
00260         >>> cline.outfile = "temp_water.txt"
00261         >>> print cline
00262         water -outfile=temp_water.txt -asequence=asis:ACCCGGGCGCGGT -bsequence=asis:ACCCGAGCGCGGT -gapopen=10 -gapextend=0.5
00263         >>> cline
00264         WaterCommandline(cmd='water', outfile='temp_water.txt', asequence='asis:ACCCGGGCGCGGT', bsequence='asis:ACCCGAGCGCGGT', gapopen=10, gapextend=0.5)
00265         """
00266         answer = "%s(cmd=%s" % (self.__class__.__name__, repr(self.program_name))
00267         for parameter in self.parameters:
00268             if parameter.is_set:
00269                 if isinstance(parameter, _Switch):
00270                     answer += ", %s=True" % parameter.names[-1]
00271                 else:
00272                     answer += ", %s=%s" \
00273                               % (parameter.names[-1], repr(parameter.value))
00274         answer += ")"
00275         return answer

def Bio.Application.AbstractCommandline.__setattr__ (   self,
  name,
  value 
) [inherited]
Set attribute name to value (PRIVATE).

This code implements a workaround for a user interface issue.
Without this __setattr__ attribute-based assignment of parameters
will silently accept invalid parameters, leading to known instances
of the user assuming that parameters for the application are set,
when they are not.

>>> from Bio.Emboss.Applications import WaterCommandline
>>> cline = WaterCommandline(gapopen=10, gapextend=0.5, stdout=True)
>>> cline.asequence = "a.fasta"
>>> cline.bsequence = "b.fasta"
>>> cline.csequence = "c.fasta"
Traceback (most recent call last):
...
ValueError: Option name csequence was not found.
>>> print cline
water -stdout -asequence=a.fasta -bsequence=b.fasta -gapopen=10 -gapextend=0.5

This workaround uses a whitelist of object attributes, and sets the
object attribute list as normal, for these.  Other attributes are
assumed to be parameters, and passed to the self.set_parameter method
for validation and assignment.

Definition at line 337 of file __init__.py.

00337 
00338     def __setattr__(self, name, value):
00339         """Set attribute name to value (PRIVATE).
00340 
00341         This code implements a workaround for a user interface issue.
00342         Without this __setattr__ attribute-based assignment of parameters
00343         will silently accept invalid parameters, leading to known instances
00344         of the user assuming that parameters for the application are set,
00345         when they are not.
00346         
00347         >>> from Bio.Emboss.Applications import WaterCommandline
00348         >>> cline = WaterCommandline(gapopen=10, gapextend=0.5, stdout=True)
00349         >>> cline.asequence = "a.fasta"
00350         >>> cline.bsequence = "b.fasta"
00351         >>> cline.csequence = "c.fasta"
00352         Traceback (most recent call last):
00353         ...
00354         ValueError: Option name csequence was not found.
00355         >>> print cline
00356         water -stdout -asequence=a.fasta -bsequence=b.fasta -gapopen=10 -gapextend=0.5
00357 
00358         This workaround uses a whitelist of object attributes, and sets the
00359         object attribute list as normal, for these.  Other attributes are
00360         assumed to be parameters, and passed to the self.set_parameter method
00361         for validation and assignment.
00362         """
00363         if name in ['parameters', 'program_name']: # Allowed attributes
00364             self.__dict__[name] = value
00365         else:
00366             self.set_parameter(name, value)  # treat as a parameter
    

Here is the call graph for this function:

def Bio.Application.AbstractCommandline.__str__ (   self) [inherited]
Make the commandline string with the currently set options.

e.g.
>>> from Bio.Emboss.Applications import WaterCommandline
>>> cline = WaterCommandline(gapopen=10, gapextend=0.5)
>>> cline.asequence = "asis:ACCCGGGCGCGGT"
>>> cline.bsequence = "asis:ACCCGAGCGCGGT"
>>> cline.outfile = "temp_water.txt"
>>> print cline
water -outfile=temp_water.txt -asequence=asis:ACCCGGGCGCGGT -bsequence=asis:ACCCGAGCGCGGT -gapopen=10 -gapextend=0.5
>>> str(cline)
'water -outfile=temp_water.txt -asequence=asis:ACCCGGGCGCGGT -bsequence=asis:ACCCGAGCGCGGT -gapopen=10 -gapextend=0.5'

Definition at line 229 of file __init__.py.

00229 
00230     def __str__(self):
00231         """Make the commandline string with the currently set options.
00232 
00233         e.g.
00234         >>> from Bio.Emboss.Applications import WaterCommandline
00235         >>> cline = WaterCommandline(gapopen=10, gapextend=0.5)
00236         >>> cline.asequence = "asis:ACCCGGGCGCGGT"
00237         >>> cline.bsequence = "asis:ACCCGAGCGCGGT"
00238         >>> cline.outfile = "temp_water.txt"
00239         >>> print cline
00240         water -outfile=temp_water.txt -asequence=asis:ACCCGGGCGCGGT -bsequence=asis:ACCCGAGCGCGGT -gapopen=10 -gapextend=0.5
00241         >>> str(cline)
00242         'water -outfile=temp_water.txt -asequence=asis:ACCCGGGCGCGGT -bsequence=asis:ACCCGAGCGCGGT -gapopen=10 -gapextend=0.5'
00243         """
00244         self._validate()
00245         commandline = "%s " % self.program_name
00246         for parameter in self.parameters:
00247             if parameter.is_set:
00248                 #This will include a trailing space:
00249                 commandline += str(parameter)
00250         return commandline.strip() # remove trailing space

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Application.AbstractCommandline.set_parameter (   self,
  name,
  value = None 
) [inherited]
Set a commandline option for a program.

Definition at line 297 of file __init__.py.

00297 
00298     def set_parameter(self, name, value = None):
00299         """Set a commandline option for a program.
00300         """
00301         set_option = False
00302         for parameter in self.parameters:
00303             if name in parameter.names:
00304                 if isinstance(parameter, _Switch):
00305                     if value is None:
00306                         import warnings
00307                         warnings.warn("For a switch type argument like %s, "
00308                                       "we expect a boolean.  None is treated "
00309                                       "as FALSE!" % parameter.names[-1])
00310                     parameter.is_set = bool(value)
00311                     set_option = True
00312                 else:
00313                     if value is not None:
00314                         self._check_value(value, name, parameter.checker_function)
00315                         parameter.value = value
00316                     parameter.is_set = True
00317                     set_option = True
00318         if not set_option:
00319             raise ValueError("Option name %s was not found." % name)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 84 of file _Mafft.py.

Reimplemented in Bio.Align.Applications._Dialign.DialignCommandline.

Definition at line 167 of file __init__.py.


The documentation for this class was generated from the following file: