Back to index

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

 program_name
 parameters

Detailed Description

Command line wrapper for the multiple alignment program DIALIGN2-2.

http://bibiserv.techfak.uni-bielefeld.de/dialign/welcome.html

Example:

To align a FASTA file (unaligned.fasta) with the output files names
aligned.* including a FASTA output file (aligned.fa), use:

>>> from Bio.Align.Applications import DialignCommandline
>>> dialign_cline = DialignCommandline(input="unaligned.fasta",
...                                    fn="aligned", fa=True)
>>> print dialign_cline
dialign2-2 -fa -fn aligned unaligned.fasta

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

Citation:

B. Morgenstern (2004). DIALIGN: Multiple DNA and Protein Sequence
Alignment at BiBiServ. Nucleic Acids Research 32, W33-W36.

Last checked against version: 2.2

Definition at line 12 of file _Dialign.py.


Constructor & Destructor Documentation

def Bio.Align.Applications._Dialign.DialignCommandline.__init__ (   self,
  cmd = "dialign2-2",
  kwargs 
)
Create a new instance of a command line wrapper object.

Reimplemented from Bio.Application.AbstractCommandline.

Definition at line 38 of file _Dialign.py.

00038 
00039     def __init__(self, cmd="dialign2-2", **kwargs):
00040         self.program_name = cmd
00041         self.parameters = \
00042             [
00043             _Switch(["-afc", "afc"],
00044                     "Creates additional output file '*.afc' "
00045                     "containing data of all fragments considered "
00046                     "for alignment WARNING: this file can be HUGE !"),
00047             _Switch(["-afc_v", "afc_v"],
00048                     "Like '-afc' but verbose: fragments are explicitly "
00049                     "printed. WARNING: this file can be EVEN BIGGER !"),
00050             _Switch(["-anc", "anc"],
00051                     "Anchored alignment. Requires a file <seq_file>.anc "
00052                     "containing anchor points."),
00053             _Switch(["-cs", "cs"],
00054                     "If segments are translated, not only the `Watson "
00055                     "strand' but also the `Crick strand' is looked at."),
00056             _Switch(["-cw", "cw"],
00057                     "Additional output file in CLUSTAL W format."),
00058             _Switch(["-ds", "ds"],
00059                     "`dna alignment speed up' - non-translated nucleic acid "
00060                     "fragments are taken into account only if they start "
00061                     "with at least two matches. Speeds up DNA alignment at "
00062                     "the expense of sensitivity."),
00063             _Switch(["-fa", "fa"],
00064                     "Additional output file in FASTA format."),
00065             _Switch(["-ff", "ff"],
00066                     "Creates file *.frg containing information about all "
00067                     "fragments that are part of the respective optimal "
00068                     "pairwise alignmnets plus information about "
00069                     "consistency in the multiple alignment"),
00070             _Option(["-fn", "fn"],
00071                     "Output files are named <out_file>.<extension>.",
00072                     equate=False),
00073             _Switch(["-fop", "fop"],
00074                     "Creates file *.fop containing coordinates of all "
00075                     "fragments that are part of the respective pairwise alignments."),
00076             _Switch(["-fsm", "fsm"],
00077                     "Creates file *.fsm containing coordinates of all "
00078                     "fragments that are part of the final alignment"),
00079             _Switch(["-iw", "iw"],
00080                     "Overlap weights switched off (by default, overlap "
00081                     "weights are used if up to 35 sequences are aligned). "
00082                     "This option speeds up the alignment but may lead "
00083                     "to reduced alignment quality."),
00084             _Switch(["-lgs", "lgs"],
00085                     "`long genomic sequences' - combines the following "
00086                     "options: -ma, -thr 2, -lmax 30, -smin 8, -nta, -ff, "
00087                     "-fop, -ff, -cs, -ds, -pst "),
00088             _Switch(["-lgs_t", "lgs_t"],
00089                     "Like '-lgs' but with all segment pairs assessed "
00090                     "at the peptide level (rather than 'mixed alignments' "
00091                     "as with the '-lgs' option). Therefore faster than "
00092                     "-lgs but not very sensitive for non-coding regions."),
00093             _Option(["-lmax", "lmax"],
00094                     "Maximum fragment length = x  (default: x = 40 or "
00095                     "x = 120 for `translated' fragments). Shorter x "
00096                     "speeds up the program but may affect alignment quality.",
00097                     checker_function=lambda x: isinstance(x, int),
00098                     equate=False),
00099             _Switch(["-lo", "lo"],
00100                     "(Long Output) Additional file *.log with information "
00101                     "about fragments selected for pairwise alignment and "
00102                     "about consistency in multi-alignment proceedure."),
00103             _Switch(["-ma", "ma"],
00104                     "`mixed alignments' consisting of P-fragments and "
00105                     "N-fragments if nucleic acid sequences are aligned."),
00106             _Switch(["-mask", "mask"],
00107                     "Residues not belonging to selected fragments are "
00108                     "replaced by `*' characters in output alignment "
00109                     "(rather than being printed in lower-case characters)"),
00110             _Switch(["-mat", "mat"],
00111                     "Creates file *mat with substitution counts derived "
00112                     "from the fragments that have been selected for alignment."),
00113             _Switch(["-mat_thr", "mat_thr"],
00114                     "Like '-mat' but only fragments with weight score "
00115                     "> t are considered"),
00116             _Switch(["-max_link", "max_link"],
00117                     "'maximum linkage' clustering used to construct "
00118                     "sequence tree (instead of UPGMA)."),
00119             _Switch(["-min_link", "min_link"],
00120                     "'minimum linkage' clustering used."),
00121             _Option(["-mot", "mot"],
00122                     "'motif' option.",
00123                     equate=False),
00124             _Switch(["-msf", "msf"],
00125                     "Separate output file in MSF format."),
00126             _Switch(["-n", "n"],
00127                     "Input sequences are nucleic acid sequences. "
00128                     "No translation of fragments."),
00129             _Switch(["-nt", "nt"],
00130                     "Input sequences are nucleic acid sequences and "
00131                     "`nucleic acid segments' are translated to `peptide "
00132                     "segments'."),
00133             _Switch(["-nta", "nta"],
00134                     "`no textual alignment' - textual alignment suppressed. "
00135                     "This option makes sense if other output files are of "
00136                     "intrest -- e.g. the fragment files created with -ff, "
00137                     "-fop, -fsm or -lo."),
00138             _Switch(["-o", "o"],
00139                     "Fast version, resulting alignments may be slightly "
00140                     "different."),
00141             _Switch(["-ow", "ow"],
00142                     "Overlap weights enforced (By default, overlap weights "
00143                     "are used only if up to 35 sequences are aligned since "
00144                     "calculating overlap weights is time consuming)."),
00145             _Switch(["-pst", "pst"],
00146                     "'print status'. Creates and updates a file *.sta with "
00147                     "information about the current status of the program "
00148                     "run.  This option is recommended if large data sets "
00149                     "are aligned since it allows the user to estimate the "
00150                     "remaining running time."),
00151             _Switch(["-smin", "smin"],
00152                     "Minimum similarity value for first residue pair "
00153                     "(or codon pair) in fragments. Speeds up protein "
00154                     "alignment or alignment of translated DNA fragments "
00155                     "at the expense of sensitivity."),
00156             _Option(["-stars", "stars"],
00157                     "Maximum number of `*' characters indicating degree "
00158                     "of local similarity among sequences. By default, no "
00159                     "stars are used but numbers between 0 and 9, instead.",
00160                     checker_function = lambda x: x in range(0,10),
00161                     equate=False),
00162             _Switch(["-stdo", "stdo"],
00163                     "Results written to standard output."),
00164             _Switch(["-ta", "ta"],
00165                     "Standard textual alignment printed (overrides "
00166                     "suppression of textual alignments in special "
00167                     "options, e.g. -lgs)"),
00168             _Option(["-thr", "thr"],
00169                     "Threshold T = x.",
00170                     checker_function = lambda x: isinstance(x, int),
00171                     equate=False),
00172             _Switch(["-xfr", "xfr"],
00173                     "'exclude fragments' - list of fragments can be "
00174                     "specified that are NOT considered for pairwise alignment"),
00175             _Argument(["input"],
00176                       "Input file name. Must be FASTA format",
00177                       filename=True,
00178                       is_required=True),
00179             ]
00180         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 40 of file _Dialign.py.

Reimplemented from Bio.Application.AbstractCommandline.

Definition at line 39 of file _Dialign.py.


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