Back to index

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

Namespaces

namespace  _Motif
namespace  Applications
namespace  Parsers
namespace  Thresholds

Functions

def _from_pfm
def _from_sites
def parse
def read
def _test

Variables

dictionary _parsers

Function Documentation

def Bio.Motif._from_pfm (   handle) [private]

Definition at line 21 of file __init__.py.

00021 
00022 def _from_pfm(handle):
00023     return Motif()._from_jaspar_pfm(handle)

def Bio.Motif._from_sites (   handle) [private]

Definition at line 24 of file __init__.py.

00024 
00025 def _from_sites(handle):
00026     return Motif()._from_jaspar_sites(handle)
00027 
00028 _readers={"jaspar-pfm": _from_pfm,
00029           "jaspar-sites": _from_sites
00030           }
00031 
00032 
          
def Bio.Motif._test ( ) [private]
Run the Bio.Motif module's doctests.

This will try and locate the unit tests directory, and run the doctests
from there in order that the relative paths used in the examples work.

Definition at line 137 of file __init__.py.

00137 
00138 def _test():
00139     """Run the Bio.Motif module's doctests.
00140 
00141     This will try and locate the unit tests directory, and run the doctests
00142     from there in order that the relative paths used in the examples work.
00143     """
00144     import doctest
00145     import os
00146     if os.path.isdir(os.path.join("..","..","Tests")):
00147         print "Runing doctests..."
00148         cur_dir = os.path.abspath(os.curdir)
00149         os.chdir(os.path.join("..","..","Tests"))
00150         doctest.testmod()
00151         os.chdir(cur_dir)
00152         del cur_dir
00153         print "Done"

def Bio.Motif.parse (   handle,
  format 
)
Parses an output file of motif finding programs.

Currently supported formats:
 - AlignAce
 - MEME

You can also use single-motif formats, although the Bio.Motif.read()
function is simpler to use in this situation.
 - jaspar-pfm
 - jaspar-sites

For example:

>>> from Bio import Motif
>>> for motif in Motif.parse(open("Motif/alignace.out"),"AlignAce"):
...     print motif.consensus()
TCTACGATTGAG
CTGCACCTAGCTACGAGTGAG
GTGCCCTAAGCATACTAGGCG
GCCACTAGCAGAGCAGGGGGC
CGACTCAGAGGTT
CCACGCTAAGAGAAGTGCCGGAG
GCACGTCCCTGAGCA
GTCCATCGCAAAGCGTGGGGC
GAGATCAGAGGGCCG
TGGACGCGGGG
GACCAGAGCCTCGCATGGGGG
AGCGCGCGTG
GCCGGTTGCTGTTCATTAGG
ACCGACGGCAGCTAAAAGGG
GACGCCGGGGAT
CGACTCGCGCTTACAAGG

Definition at line 33 of file __init__.py.

00033 
00034 def parse(handle,format):
00035     """Parses an output file of motif finding programs.
00036 
00037     Currently supported formats:
00038      - AlignAce
00039      - MEME
00040 
00041     You can also use single-motif formats, although the Bio.Motif.read()
00042     function is simpler to use in this situation.
00043      - jaspar-pfm
00044      - jaspar-sites
00045 
00046     For example:
00047 
00048     >>> from Bio import Motif
00049     >>> for motif in Motif.parse(open("Motif/alignace.out"),"AlignAce"):
00050     ...     print motif.consensus()
00051     TCTACGATTGAG
00052     CTGCACCTAGCTACGAGTGAG
00053     GTGCCCTAAGCATACTAGGCG
00054     GCCACTAGCAGAGCAGGGGGC
00055     CGACTCAGAGGTT
00056     CCACGCTAAGAGAAGTGCCGGAG
00057     GCACGTCCCTGAGCA
00058     GTCCATCGCAAAGCGTGGGGC
00059     GAGATCAGAGGGCCG
00060     TGGACGCGGGG
00061     GACCAGAGCCTCGCATGGGGG
00062     AGCGCGCGTG
00063     GCCGGTTGCTGTTCATTAGG
00064     ACCGACGGCAGCTAAAAGGG
00065     GACGCCGGGGAT
00066     CGACTCGCGCTTACAAGG
00067     """
00068     try:
00069         parser=_parsers[format]
00070         
00071     except KeyError:
00072         try: #not a true parser, try reader formats
00073             reader=_readers[format]
00074         except:
00075             raise ValueError("Wrong parser format")
00076         else: #we have a proper reader 
00077             yield reader(handle)
00078     else: # we have a proper reader
00079         for m in parser(handle).motifs:
00080             yield m

Here is the caller graph for this function:

def Bio.Motif.read (   handle,
  format 
)
Reads a motif from a handle using a specified file-format.

This supports the same formats as Bio.Motif.parse(), but
only for files containing exactly one record.  For example,
reading a pfm file:

>>> from Bio import Motif
>>> motif = Motif.read(open("Motif/SRF.pfm"),"jaspar-pfm")
>>> motif.consensus()
Seq('GCCCATATATGG', IUPACUnambiguousDNA())

Or a single-motif MEME file,

>>> from Bio import Motif
>>> motif =  Motif.read(open("Motif/meme.out"),"MEME")
>>> motif.consensus()
Seq('CTCAATCGTA', IUPACUnambiguousDNA())

If the handle contains no records, or more than one record,
an exception is raised:

>>> from Bio import Motif
>>> motif = Motif.read(open("Motif/alignace.out"),"AlignAce")
Traceback (most recent call last):
    ...
ValueError: More than one motif found in handle

If however you want the first record from a file containing
multiple records this function would raise an exception (as
shown in the example above).  Instead use:

>>> from Bio import Motif
>>> motif = Motif.parse(open("Motif/alignace.out"),"AlignAce").next()
>>> motif.consensus()
Seq('TCTACGATTGAG', IUPACUnambiguousDNA())

Use the Bio.Motif.parse(handle, format) function if you want
to read multiple records from the handle.

Definition at line 81 of file __init__.py.

00081 
00082 def read(handle,format):
00083     """Reads a motif from a handle using a specified file-format.
00084 
00085     This supports the same formats as Bio.Motif.parse(), but
00086     only for files containing exactly one record.  For example,
00087     reading a pfm file:
00088 
00089     >>> from Bio import Motif
00090     >>> motif = Motif.read(open("Motif/SRF.pfm"),"jaspar-pfm")
00091     >>> motif.consensus()
00092     Seq('GCCCATATATGG', IUPACUnambiguousDNA())
00093 
00094     Or a single-motif MEME file,
00095 
00096     >>> from Bio import Motif
00097     >>> motif =  Motif.read(open("Motif/meme.out"),"MEME")
00098     >>> motif.consensus()
00099     Seq('CTCAATCGTA', IUPACUnambiguousDNA())
00100 
00101     If the handle contains no records, or more than one record,
00102     an exception is raised:
00103 
00104     >>> from Bio import Motif
00105     >>> motif = Motif.read(open("Motif/alignace.out"),"AlignAce")
00106     Traceback (most recent call last):
00107         ...
00108     ValueError: More than one motif found in handle
00109 
00110     If however you want the first record from a file containing
00111     multiple records this function would raise an exception (as
00112     shown in the example above).  Instead use:
00113 
00114     >>> from Bio import Motif
00115     >>> motif = Motif.parse(open("Motif/alignace.out"),"AlignAce").next()
00116     >>> motif.consensus()
00117     Seq('TCTACGATTGAG', IUPACUnambiguousDNA())
00118 
00119     Use the Bio.Motif.parse(handle, format) function if you want
00120     to read multiple records from the handle.
00121     """
00122     iterator = parse(handle, format)
00123     try:
00124         first = iterator.next()
00125     except StopIteration:
00126         first = None
00127     if first is None:
00128         raise ValueError("No motifs found in handle")
00129     try:
00130         second = iterator.next()
00131     except StopIteration:
00132         second = None
00133     if second is not None:
00134         raise ValueError("More than one motif found in handle")
00135     return first
00136 

Here is the call graph for this function:


Variable Documentation

dictionary Bio.Motif._parsers
Initial value:
00001 {"AlignAce" : _AlignAce_read,
00002           "MEME" : _MEME_read,
00003           }

Definition at line 17 of file __init__.py.