Back to index

python-biopython  1.60
_Probcons.py
Go to the documentation of this file.
00001 # Copyright 2009 by Cymon J. Cox.  All rights reserved.
00002 # This code is part of the Biopython distribution and governed by its
00003 # license.  Please see the LICENSE file that should have been included
00004 # as part of this package.
00005 """Command line wrapper for the multiple alignment program PROBCONS.
00006 """
00007 
00008 __docformat__ = "epytext en" #Don't just use plain text in epydoc API pages!
00009 
00010 from Bio.Application import _Option, _Switch, _Argument, AbstractCommandline
00011 
00012 class ProbconsCommandline(AbstractCommandline):
00013     """Command line wrapper for the multiple alignment program PROBCONS.
00014 
00015     http://probcons.stanford.edu/
00016 
00017     Example:
00018 
00019     To align a FASTA file (unaligned.fasta) with the output in ClustalW
00020     format, and otherwise default settings, use:
00021 
00022     >>> from Bio.Align.Applications import ProbconsCommandline
00023     >>> probcons_cline = ProbconsCommandline(input="unaligned.fasta",
00024     ...                                      clustalw=True)
00025     >>> print probcons_cline
00026     probcons -clustalw unaligned.fasta
00027 
00028     You would typically run the command line with probcons_cline() or via
00029     the Python subprocess module, as described in the Biopython tutorial.
00030     Note that PROBCONS will write the alignment to stdout, which you may
00031     want to save to a file and then parse, e.g.::
00032 
00033         stdout, stderr = probcons_cline()
00034         handle = open("aligned.aln", "w")
00035         handle.write(stdout)
00036         handle.close()
00037         from Bio import AlignIO
00038         align = AlignIO.read("aligned.fasta", "clustalw")
00039 
00040     Alternatively, to parse the output with AlignIO directly you can
00041     use StringIO to turn the string into a handle::
00042 
00043         stdout, stderr = probcons_cline()
00044         from StringIO import StringIO
00045         from Bio import AlignIO
00046         align = AlignIO.read(StringIO(stdout), "clustalw")
00047     
00048     Citations:
00049 
00050     Do, C.B., Mahabhashyam, M.S.P., Brudno, M., and Batzoglou, S. 2005.
00051     PROBCONS: Probabilistic Consistency-based Multiple Sequence Alignment.
00052     Genome Research 15: 330-340. 
00053 
00054     Last checked agains version: 1.12
00055     """
00056     def __init__(self, cmd="probcons", **kwargs):
00057         self.parameters = \
00058             [
00059             #Note that some options cannot be assigned via properties using the
00060             #original documented option (because hyphens are not valid for names in
00061             #python), e.g cmdline.pre-training = 3 will not work
00062             #In these cases the shortened option name should be used
00063             #cmdline.pre = 3
00064             _Switch(["-clustalw", "clustalw"],
00065                     "Use CLUSTALW output format instead of MFA"),
00066             _Option(["-c", "c", "--consistency", "consistency" ],
00067                     "Use 0 <= REPS <= 5 (default: 2) passes of consistency transformation",
00068                     checker_function=lambda x: x in range(0,6),
00069                     equate=False),
00070             _Option(["-ir", "--iterative-refinement", "iterative-refinement", "ir"],
00071                     "Use 0 <= REPS <= 1000 (default: 100) passes of "
00072                     "iterative-refinement",
00073                     checker_function=lambda x: x in range(0,1001),
00074                     equate=False),
00075             _Option(["-pre", "--pre-training", "pre-training", "pre"],
00076                     "Use 0 <= REPS <= 20 (default: 0) rounds of pretraining",
00077                     checker_function=lambda x: x in range(0,21),
00078                     equate=False),
00079             _Switch(["-pairs", "pairs"],
00080                     "Generate all-pairs pairwise alignments"),
00081             _Switch(["-viterbi", "viterbi"],
00082                     "Use Viterbi algorithm to generate all pairs "
00083                     "(automatically enables -pairs)"),
00084             _Switch(["-verbose", "verbose"],
00085                     "Report progress while aligning (default: off)"),
00086             _Option(["-annot", "annot"],
00087                     "Write annotation for multiple alignment to FILENAME",
00088                     equate=False),
00089             _Option(["-t", "t", "--train", "train"],
00090                     "Compute EM transition probabilities, store in FILENAME "
00091                     "(default: no training)",
00092                     equate=False),
00093             _Switch(["-e", "e", "--emissions", "emissions"],
00094                     "Also reestimate emission probabilities (default: off)"),
00095             _Option(["-p", "p", "--paramfile", "paramfile"],
00096                     "Read parameters from FILENAME",
00097                     equate=False),
00098             _Switch(["-a", "--alignment-order", "alignment-order", "a"],
00099                     "Print sequences in alignment order rather than input "
00100                     "order (default: off)"),
00101             #Input file name
00102             _Argument(["input"],
00103                       "Input file name. Must be multiple FASTA alignment "+ \
00104                       "(MFA) format",
00105                       filename=True,
00106                       is_required=True),
00107             ]
00108         AbstractCommandline.__init__(self, cmd, **kwargs)
00109 
00110 def _test():
00111     """Run the module's doctests (PRIVATE)."""
00112     print "Runing modules doctests..."
00113     import doctest
00114     doctest.testmod()
00115     print "Done"
00116 
00117 if __name__ == "__main__":
00118     _test()