Permalink
Browse files

Start to clean up the parsers

  • Loading branch information...
1 parent ac4e438 commit d0bb15394fb28ac67a447b1fe140db852a2090ed @mdehoon mdehoon committed Dec 27, 2012
Showing with 13 additions and 21 deletions.
  1. +13 −21 Bio/Motif/__init__.py
View
@@ -15,10 +15,6 @@
from Bio.Motif import Jaspar
from Bio.Motif.Thresholds import ScoreDistribution
-_parsers={"AlignAce" : _AlignAce_read,
- "MEME" : _MEME_read,
- }
-
def _from_pfm(handle):
return Motif()._from_jaspar_pfm(handle)
@@ -27,10 +23,6 @@ def _from_pfm(handle):
def _from_sites(handle):
return Motif()._from_jaspar_sites(handle)
-_readers={"jaspar-pfm": _from_pfm,
- "jaspar-sites": _from_sites,
- }
-
def parse(handle,format):
"""Parses an output file of motif finding programs.
@@ -68,20 +60,20 @@ def parse(handle,format):
"""
if format in ('pfm', 'sites'):
yield Jaspar.read(handle, format)
+ elif format=="AlignAce":
+ record = _AlignAce_read(handle)
+ for m in record.motifs:
+ yield m
+ elif format=="MEME":
+ record = _MEME_read(handle)
+ for m in record.motifs:
+ yield m
+ elif format=="jaspar-pfm":
+ yield _from_pfm(handle)
+ elif format=="jaspar-sites":
+ yield _from_sites(handle)
else:
- try:
- parser=_parsers[format]
-
- except KeyError:
- try: # not a true parser, try reader formats
- reader=_readers[format]
- except:
- raise ValueError("Wrong parser format")
- else: # we have a proper reader
- yield reader(handle)
- else: # we have a proper reader
- for m in parser(handle).motifs:
- yield m
+ raise ValueError("Unknown format %s" % format)
def read(handle,format):

0 comments on commit d0bb153

Please sign in to comment.