Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.Align.Applications._Prank.PrankCommandline Class Reference
Inheritance diagram for Bio.Align.Applications._Prank.PrankCommandline:
Inheritance graph
[legend]
Collaboration diagram for Bio.Align.Applications._Prank.PrankCommandline:
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 PRANK.

http://www.ebi.ac.uk/goldman-srv/prank/prank/

Example:

To align a FASTA file (unaligned.fasta) with the output in aligned
FASTA format with the output filename starting with "aligned" (you
can't pick the filename explicitly), no tree ouput and no XML output,
use:

>>> from Bio.Align.Applications import PrankCommandline
>>> prank_cline = PrankCommandline(d="unaligned.fasta",
...                                o="aligned", #prefix only!
...                                f=8, #FASTA output
...                                notree=True, noxml=True)
>>> print prank_cline
prank -d=unaligned.fasta -o=aligned -f=8 -noxml -notree

You would typically run the command line with prank_cline() or via
the Python subprocess module, as described in the Biopython tutorial.

Citations:

Loytynoja, A. and Goldman, N. 2005. An algorithm for progressive
multiple alignment of sequences with insertions. Proceedings of
the National Academy of Sciences, 102: 10557--10562.

Loytynoja, A. and Goldman, N. 2008. Phylogeny-aware gap placement
prevents errors in sequence alignment and evolutionary analysis.
Science, 320: 1632.

Last checked agains version: 081202

Definition at line 12 of file _Prank.py.


Constructor & Destructor Documentation

def Bio.Align.Applications._Prank.PrankCommandline.__init__ (   self,
  cmd = "prank",
  kwargs 
)
Create a new instance of a command line wrapper object.

Reimplemented from Bio.Application.AbstractCommandline.

Definition at line 47 of file _Prank.py.

00047 
00048     def __init__(self, cmd="prank", **kwargs):
00049         OUTPUT_FORMAT_VALUES = list(range(1,18))
00050         self.parameters = [
00051             ################## input/output parameters: ##################
00052             #-d=sequence_file
00053             _Option(["-d", "d"],
00054                     "Input filename",
00055                     filename=True,
00056                     is_required=True),
00057             #-t=tree_file [default: no tree, generate approximate NJ tree]
00058             _Option(["-t", "t"],"Input guide tree filename",
00059                     filename=True),
00060             #-tree="tree_string" [tree in newick format; in double quotes]
00061             _Option(["-tree", "tree"],
00062                     "Input guide tree as Newick string"),
00063             #-m=model_file [default: HKY2/WAG]
00064             _Option(["-m", "m"],
00065                     "User-defined alignment model filename. Default: "
00066                     "HKY2/WAG"),
00067             #-o=output_file [default: 'output']
00068             _Option(["-o", "o"],
00069                     "Output filenames prefix. Default: 'output'\n "
00070                     "Will write: output.?.fas (depending on requested "
00071                     "format), output.?.xml and output.?.dnd",
00072                     filename=True),
00073             #-f=output_format [default: 8]
00074             _Option(["-f", "f"],
00075                     "Output alignment format. Default: 8 FASTA\n"
00076                     "Option are:\n"
00077                     "1. IG/Stanford       8. Pearson/Fasta\n"
00078                     "2. GenBank/GB        11. Phylip3.2\n"
00079                     "3. NBRF              12. Phylip\n"
00080                     "4. EMBL              14. PIR/CODATA\n"
00081                     "6. DNAStrider        15. MSF\n"
00082                     "7. Fitch             17. PAUP/NEXUS",
00083                     checker_function=lambda x: x in OUTPUT_FORMAT_VALUES),
00084             _Switch(["-noxml", "noxml"],
00085                     "Do not output XML files"),
00086             _Switch(["-notree", "notree"],
00087                     "Do not output dnd tree files"),
00088             _Switch(["-shortnames", "shortnames"],
00089                     "Truncate names at first space"),
00090             _Switch(["-quiet", "quiet"],
00091                     "Reduce verbosity"),
00092             ####################### model parameters: ######################
00093             #+F [force insertions to be always skipped]
00094             #-F [equivalent]
00095             _Switch(["-F", "+F", "F"],
00096                     "Force insertions to be always skipped: same as +F"),
00097             #-dots [show insertion gaps as dots]
00098             _Switch(["-dots", "dots"],
00099                     "Show insertion gaps as dots"),
00100             #-gaprate=# [gap opening rate; default: dna 0.025 / prot 0.0025]
00101             _Option(["-gaprate", "gaprate"],
00102                     "Gap opening rate. Default: dna 0.025 prot 0.0025",
00103                     checker_function=lambda x: isinstance(x, float)), 
00104             #-gapext=# [gap extension probability; default: dna 0.5 / prot 0.5]
00105             _Option(["-gapext", "gapext"],
00106                     "Gap extension probability. Default: dna 0.5 "
00107                     "/ prot 0.5",
00108                     checker_function=lambda x: isinstance(x, float)),
00109             #-dnafreqs=#,#,#,# [ACGT; default: empirical]
00110             _Option(["-dnafreqs", "dnafreqs"],
00111                     "DNA frequencies - 'A,C,G,T'. eg '25,25,25,25' as a quote "
00112                     "surrounded string value. Default: empirical",
00113                     checker_function=lambda x: isinstance(x, bytes)), 
00114             #-kappa=# [ts/tv rate ratio; default:2]
00115             _Option(["-kappa", "kappa"],
00116                     "Transition/transversion ratio. Default: 2",
00117                     checker_function=lambda x: isinstance(x, int)), 
00118             #-rho=# [pur/pyr rate ratio; default:1]
00119             _Option(["-rho", "rho"],
00120                     "Purine/pyrimidine ratio. Default: 1",
00121                     checker_function=lambda x: isinstance(x, int)), 
00122             #-codon [for DNA: use empirical codon model]
00123             #Assuming this is an input file as in -m
00124             _Option(["-codon", "codon"],
00125                     "Codon model filename. Default: empirical codon model"),
00126             #-termgap [penalise terminal gaps normally]
00127             _Switch(["-termgap", "termgap"],
00128                     "Penalise terminal gaps normally"),
00129             ################ other parameters: ################################
00130             #-nopost [do not compute posterior support; default: compute]
00131             _Switch(["-nopost", "nopost"],
00132                     "Do not compute posterior support. Default: compute"),
00133             #-pwdist=# [expected pairwise distance for computing guidetree;
00134             #default: dna 0.25 / prot 0.5]
00135             _Option(["-pwdist", "pwdist"],
00136                     "Expected pairwise distance for computing guidetree. "
00137                     "Default: dna 0.25 / prot 0.5",
00138                     checker_function=lambda x: isinstance(x, float)),
00139             _Switch(["-once", "once"], 
00140                     "Run only once. Default: twice if no guidetree given"),
00141             _Switch(["-twice", "twice"],
00142                     "Always run twice"),
00143             _Switch(["-skipins", "skipins"],
00144                     "Skip insertions in posterior support"),
00145             _Switch(["-uselogs", "uselogs"],
00146                     "Slower but should work for a greater number of sequences"),
00147             _Switch(["-writeanc", "writeanc"],
00148                     "Output ancestral sequences"),
00149             _Switch(["-printnodes", "printnodes"],
00150                     "Output each node; mostly for debugging"),
00151             #-matresize=# [matrix resizing multiplier]
00152             # Doesnt specify type but Float and Int work
00153             _Option(["-matresize", "matresize"],
00154                     "Matrix resizing multiplier",
00155                     checker_function=lambda x: isinstance(x, float) or \
00156                                                isinstance(x, int)),
00157             #-matinitsize=# [matrix initial size multiplier]
00158             # Doesnt specify type but Float and Int work
00159             _Option(["-matinitsize", "matinitsize"],
00160                     "Matrix initial size multiplier",
00161                     checker_function=lambda x: isinstance(x, float) or \
00162                                                isinstance(x, int)),
00163             _Switch(["-longseq", "longseq"],
00164                     "Save space in pairwise alignments"),
00165             _Switch(["-pwgenomic", "pwgenomic"],
00166                     "Do pairwise alignment, no guidetree"),
00167             #-pwgenomicdist=# [distance for pairwise alignment; default: 0.3]
00168             _Option(["-pwgenomicdist", "pwgenomicdist"],
00169                     "Distance for pairwise alignment. Default: 0.3",
00170                     checker_function=lambda x: isinstance(x, float)),
00171             #-scalebranches=# [scale branch lengths; default: dna 1 / prot 2]
00172             _Option(["-scalebranches", "scalebranches"],
00173                     "Scale branch lengths. Default: dna 1 / prot 2",
00174                     checker_function=lambda x: isinstance(x, int)),
00175             #-fixedbranches=# [use fixed branch lengths]
00176             #Assume looking for a float
00177             _Option(["-fixedbranches", "fixedbranches"],
00178                     "Use fixed branch lengths of input value",
00179                     checker_function=lambda x: isinstance(x, float)),
00180             #-maxbranches=# [set maximum branch length]
00181             #Assume looking for a float
00182             _Option(["-maxbranches", "maxbranches"],
00183                     "Use maximum branch lengths of input value",
00184                     checker_function=lambda x: isinstance(x, float)),
00185             #-realbranches [disable branch length truncation]
00186             _Switch(["-realbranches", "realbranches"],
00187                     "Disable branch length truncation"),
00188             _Switch(["-translate", "translate"],
00189                     "Translate to protein"),
00190             _Switch(["-mttranslate", "mttranslate"],
00191                     "Translate to protein using mt table"),
00192             ###################### other: ####################
00193             _Switch(["-convert", "convert"],
00194                     "Convert input alignment to new format. Do "
00195                     "not perform alignment")
00196             ]
00197         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 49 of file _Prank.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: