Back to index

python-biopython  1.60
Namespaces | Functions | Variables
Bio.Wise Namespace Reference

Namespaces

namespace  dnal
namespace  psw

Functions

def _build_align_cmdline
def align
def all_pairs
def main
def _test

Variables

string __version__ = "$Revision: 1.17 $"

Function Documentation

def Bio.Wise._build_align_cmdline (   cmdline,
  pair,
  output_filename,
  kbyte = None,
  force_type = None,
  quiet = False 
) [private]
Helper function to build a command line string (PRIVATE).

>>> os.environ["WISE_KBYTE"]="300000"
>>> if os.isatty(sys.stderr.fileno()):
...    c = _build_align_cmdline(["dnal"], ("seq1.fna", "seq2.fna"),
...                             "/tmp/output", kbyte=100000)
...    assert c == 'dnal -kbyte 100000 seq1.fna seq2.fna > /tmp/output', c
...    c = _build_align_cmdline(["psw"], ("seq1.faa", "seq2.faa"),
...                             "/tmp/output_aa")
...    assert c == 'psw -kbyte 300000 seq1.faa seq2.faa > /tmp/output_aa', c
... else:
...    c = _build_align_cmdline(["dnal"], ("seq1.fna", "seq2.fna"),
...                             "/tmp/output", kbyte=100000)
...    assert c == 'dnal -kbyte 100000 -quiet seq1.fna seq2.fna > /tmp/output', c
...    c = _build_align_cmdline(["psw"], ("seq1.faa", "seq2.faa"),
...                             "/tmp/output_aa")
...    assert c == 'psw -kbyte 300000 -quiet seq1.faa seq2.faa > /tmp/output_aa', c

Definition at line 23 of file __init__.py.

00023 
00024 def _build_align_cmdline(cmdline, pair, output_filename, kbyte=None, force_type=None, quiet=False):
00025     """Helper function to build a command line string (PRIVATE).
00026 
00027     >>> os.environ["WISE_KBYTE"]="300000"
00028     >>> if os.isatty(sys.stderr.fileno()):
00029     ...    c = _build_align_cmdline(["dnal"], ("seq1.fna", "seq2.fna"),
00030     ...                             "/tmp/output", kbyte=100000)
00031     ...    assert c == 'dnal -kbyte 100000 seq1.fna seq2.fna > /tmp/output', c
00032     ...    c = _build_align_cmdline(["psw"], ("seq1.faa", "seq2.faa"),
00033     ...                             "/tmp/output_aa")
00034     ...    assert c == 'psw -kbyte 300000 seq1.faa seq2.faa > /tmp/output_aa', c
00035     ... else:
00036     ...    c = _build_align_cmdline(["dnal"], ("seq1.fna", "seq2.fna"),
00037     ...                             "/tmp/output", kbyte=100000)
00038     ...    assert c == 'dnal -kbyte 100000 -quiet seq1.fna seq2.fna > /tmp/output', c
00039     ...    c = _build_align_cmdline(["psw"], ("seq1.faa", "seq2.faa"),
00040     ...                             "/tmp/output_aa")
00041     ...    assert c == 'psw -kbyte 300000 -quiet seq1.faa seq2.faa > /tmp/output_aa', c
00042 
00043     """
00044     cmdline = cmdline[:]
00045 
00046     ### XXX: force_type ignored
00047 
00048     if kbyte is None:
00049         try:
00050             cmdline.extend(("-kbyte", os.environ["WISE_KBYTE"]))
00051         except KeyError:
00052             pass
00053     else:
00054         cmdline.extend(("-kbyte", str(kbyte)))
00055 
00056     if not os.isatty(sys.stderr.fileno()):
00057         cmdline.append("-quiet")
00058 
00059     cmdline.extend(pair)
00060     cmdline.extend((">", output_filename))
00061     if quiet:
00062         cmdline.extend(("2>", "/dev/null"))
00063     cmdline_str = ' '.join(cmdline)
00064 
00065     return cmdline_str

Here is the caller graph for this function:

def Bio.Wise._test (   args,
  keywds 
) [private]

Definition at line 134 of file __init__.py.

00134 
00135 def _test(*args, **keywds):
00136     import doctest, sys
00137     doctest.testmod(sys.modules[__name__], *args, **keywds)

def Bio.Wise.align (   cmdline,
  pair,
  kbyte = None,
  force_type = None,
  dry_run = False,
  quiet = False,
  debug = False 
)
Returns a filehandle

Definition at line 66 of file __init__.py.

00066 
00067 def align(cmdline, pair, kbyte=None, force_type=None, dry_run=False, quiet=False, debug=False):
00068     """
00069     Returns a filehandle
00070     """
00071     assert len(pair) == 2
00072     
00073     output_file = tempfile.NamedTemporaryFile(mode='r')
00074     input_files = tempfile.NamedTemporaryFile(mode="w"), tempfile.NamedTemporaryFile(mode="w")
00075 
00076     if dry_run:
00077         print _build_align_cmdline(cmdline,
00078                                    pair,
00079                                    output_file.name,
00080                                    kbyte,
00081                                    force_type,
00082                                    quiet)
00083         return
00084 
00085     for filename, input_file in zip(pair, input_files):
00086         # Pipe the file through Biopython's Fasta parser/writer
00087         # to make sure it conforms to the Fasta standard (in particular,
00088         # Wise2 may choke on long lines in the Fasta file)
00089         records = SeqIO.parse(open(filename), 'fasta')
00090         SeqIO.write(records, input_file, 'fasta')
00091         input_file.flush()
00092 
00093     input_file_names = [input_file.name for input_file in input_files]
00094 
00095     cmdline_str = _build_align_cmdline(cmdline,
00096                                        input_file_names,
00097                                        output_file.name,
00098                                        kbyte,
00099                                        force_type,
00100                                        quiet)
00101 
00102     if debug:
00103         print >>sys.stderr, cmdline_str
00104 
00105     status = os.system(cmdline_str) >> 8
00106 
00107     if status > 1:
00108         if kbyte != 0: # possible memory problem; could be None
00109             print >>sys.stderr, "INFO trying again with the linear model"
00110             return align(cmdline, pair, 0, force_type, dry_run, quiet, debug)
00111         else:
00112             raise OSError("%s returned %s" % (" ".join(cmdline), status))
00113     
00114     return output_file

Here is the call graph for this function:

def Bio.Wise.all_pairs (   singles)
Generate pairs list for all-against-all alignments

>>> all_pairs(range(4))
[(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]

Definition at line 115 of file __init__.py.

00115 
00116 def all_pairs(singles):
00117     """
00118     Generate pairs list for all-against-all alignments
00119 
00120     >>> all_pairs(range(4))
00121     [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
00122     """
00123     pairs = []
00124 
00125     singles = list(singles)
00126     while singles:
00127         suitor = singles.pop(0) # if sorted, stay sorted
00128         pairs.extend([(suitor, single) for single in singles])
00129 
00130     return pairs

def Bio.Wise.main ( )

Definition at line 131 of file __init__.py.

00131 
00132 def main():
00133     pass


Variable Documentation

string Bio.Wise.__version__ = "$Revision: 1.17 $"

Definition at line 14 of file __init__.py.