Back to index

python-biopython  1.60
Classes | Functions
Bio.Motif.Parsers.MEME Namespace Reference

Classes

class  MEMEMotif
class  MEMEInstance
class  MEMERecord

Functions

def read
def __read_version
def __read_datafile
def __read_alphabet
def __read_sequence_names
def __read_command
def __create_motif
def __read_motif_name
def __read_motif_sequences
def __skip_unused_lines

Function Documentation

def Bio.Motif.Parsers.MEME.__create_motif (   line) [private]

Definition at line 258 of file MEME.py.

00258 
00259 def __create_motif(line):
00260     line = line[5:].strip()
00261     ls = line.split()
00262     motif = MEMEMotif()
00263     motif.length = int(ls[3])
00264     motif._numoccurrences(ls[6])
00265     motif._evalue(ls[12])
00266     return motif
00267 

Here is the caller graph for this function:

def Bio.Motif.Parsers.MEME.__read_alphabet (   record,
  handle 
) [private]

Definition at line 206 of file MEME.py.

00206 
00207 def __read_alphabet(record, handle):
00208     try:
00209         line = handle.next()
00210     except StopIteration:
00211         raise ValueError("Unexpected end of stream: Expected to find line starting with 'ALPHABET'")
00212     if not line.startswith('ALPHABET'):
00213         raise ValueError("Line does not start with 'ALPHABET':\n%s" % line)
00214     line = line.strip()
00215     line = line.replace('ALPHABET= ','')
00216     if line == 'ACGT':
00217         al = IUPAC.unambiguous_dna
00218     else:
00219         al = IUPAC.protein
00220     record.alphabet = al
00221 

Here is the caller graph for this function:

def Bio.Motif.Parsers.MEME.__read_command (   record,
  handle 
) [private]

Definition at line 247 of file MEME.py.

00247 
00248 def __read_command(record, handle):
00249     for line in handle:
00250         if line.startswith('command:'):
00251             break
00252     else:
00253         raise ValueError("Unexpected end of stream: Expected to find line starting with 'command'")
00254     line = line.strip()
00255     line = line.replace('command: ','')
00256     record.command = line
00257 

Here is the caller graph for this function:

def Bio.Motif.Parsers.MEME.__read_datafile (   record,
  handle 
) [private]

Definition at line 183 of file MEME.py.

00183 
00184 def __read_datafile(record, handle):
00185     for line in handle:
00186         if line.startswith('TRAINING SET'):
00187             break
00188     else:
00189         raise ValueError("Unexpected end of stream: 'TRAINING SET' not found.")
00190     try:
00191         line = handle.next()
00192     except StopIteration:
00193         raise ValueError("Unexpected end of stream: Expected to find line starting with '****'")
00194     if not line.startswith('****'):
00195         raise ValueError("Line does not start with '****':\n%s" % line)
00196     try:
00197         line = handle.next()
00198     except StopIteration:
00199         raise ValueError("Unexpected end of stream: Expected to find line starting with 'DATAFILE'")
00200     if not line.startswith('DATAFILE'):
00201         raise ValueError("Line does not start with 'DATAFILE':\n%s" % line)
00202     line = line.strip()
00203     line = line.replace('DATAFILE= ','')
00204     record.datafile = line
00205 

Here is the caller graph for this function:

def Bio.Motif.Parsers.MEME.__read_motif_name (   motif,
  handle 
) [private]

Definition at line 268 of file MEME.py.

00268 
00269 def __read_motif_name(motif, handle):
00270     for line in handle:
00271         if 'sorted by position p-value' in line:
00272             break
00273     else:
00274         raise ValueError('Unexpected end of stream: Failed to find motif name')
00275     line = line.strip()
00276     ls = line.split()
00277     name = " ".join(ls[0:2])
00278     motif.name=name
00279 

Here is the caller graph for this function:

def Bio.Motif.Parsers.MEME.__read_motif_sequences (   motif,
  handle,
  rv 
) [private]

Definition at line 280 of file MEME.py.

00280 
00281 def __read_motif_sequences(motif, handle, rv):
00282     try:
00283         line = handle.next()
00284     except StopIteration:
00285         raise ValueError('Unexpected end of stream: Failed to find motif sequences')
00286     if not line.startswith('---'):
00287         raise ValueError("Line does not start with '---':\n%s" % line)
00288     try:
00289         line = handle.next()
00290     except StopIteration:
00291         raise ValueError("Unexpected end of stream: Expected to find line starting with 'Sequence name'")
00292     if not line.startswith('Sequence name'):
00293         raise ValueError("Line does not start with 'Sequence name':\n%s" % line)
00294     try:
00295         line = handle.next()
00296     except StopIteration:
00297         raise ValueError('Unexpected end of stream: Failed to find motif sequences')
00298     if not line.startswith('---'):
00299         raise ValueError("Line does not start with '---':\n%s" % line)
00300     for line in handle:
00301         if line.startswith('---'):
00302             break
00303         line = line.strip()
00304         ls = line.split()
00305         if rv:
00306             #seq = Seq.Seq(ls[5], record.alphabet)
00307             motif.add_instance_from_values(name = ls[0], sequence = ls[5], start = ls[2], pvalue = ls[3], strand = ls[1])
00308         else:
00309             #seq = Seq.Seq(ls[4], record.alphabet)
00310             motif.add_instance_from_values(name = ls[0], sequence = ls[4], start = ls[1], pvalue = ls[2])
00311     else:
00312         raise ValueError('Unexpected end of stream')
00313 

Here is the caller graph for this function:

def Bio.Motif.Parsers.MEME.__read_sequence_names (   record,
  handle 
) [private]

Definition at line 222 of file MEME.py.

00222 
00223 def __read_sequence_names(record, handle):
00224     try:
00225         line = handle.next()
00226     except StopIteration:
00227         raise ValueError("Unexpected end of stream: Expected to find line starting with 'Sequence name'")
00228     if not line.startswith('Sequence name'):
00229         raise ValueError("Line does not start with 'Sequence name':\n%s" % line)
00230     try:
00231         line = handle.next()
00232     except StopIteration:
00233         raise ValueError("Unexpected end of stream: Expected to find line starting with '----'")
00234     if not line.startswith('----'):
00235         raise ValueError("Line does not start with '----':\n%s" % line)
00236     for line in handle:
00237         if line.startswith('***'):
00238             break
00239         line = line.strip()
00240         ls = line.split()
00241         record.sequence_names.append(ls[0])
00242         if len(ls) == 6:
00243             record.sequence_names.append(ls[3])
00244     else:
00245         raise ValueError("Unexpected end of stream: Expected to find line starting with '***'")
00246 

Here is the caller graph for this function:

def Bio.Motif.Parsers.MEME.__read_version (   record,
  handle 
) [private]

Definition at line 172 of file MEME.py.

00172 
00173 def __read_version(record, handle):
00174     for line in handle:
00175         if line.startswith('MEME version'):
00176             break
00177     else:
00178         raise ValueError("Improper input file. File should contain a line starting MEME version.")
00179     line = line.strip()
00180     ls = line.split()
00181     record.version = ls[2]
00182 

Here is the caller graph for this function:

def Bio.Motif.Parsers.MEME.__skip_unused_lines (   handle) [private]

Definition at line 314 of file MEME.py.

00314 
00315 def __skip_unused_lines(handle):
00316     for line in handle:
00317         if line.startswith('log-odds matrix'):
00318             break
00319     else:
00320         raise ValueError("Unexpected end of stream: Expected to find line starting with 'log-odds matrix'")
00321     for line in handle:
00322         if line.startswith('---'):
00323             break
00324     else:
00325         raise ValueError("Unexpected end of stream: Expected to find line starting with '---'")
00326     for line in handle:
00327         if line.startswith('letter-probability matrix'):
00328             break
00329     else:
00330         raise ValueError("Unexpected end of stream: Expected to find line starting with 'letter-probability matrix'")
00331     for line in handle:
00332         if line.startswith('---'):
00333             break
00334     else:
00335         raise ValueError("Unexpected end of stream: Expected to find line starting with '---'")
00336     for line in handle:
00337         if line.startswith('Time'):
00338             break
00339     else:
00340         raise ValueError("Unexpected end of stream: Expected to find line starting with 'Time'")
00341     try:
00342         line = handle.next()
00343     except StopIteration:
00344         raise ValueError('Unexpected end of stream: Expected to find blank line')
00345     if line.strip():
00346         raise ValueError("Expected blank line, but got:\n%s" % line)
00347     try:
00348         line = handle.next()
00349     except StopIteration:
00350         raise ValueError("Unexpected end of stream: Expected to find line starting with '***'")
00351     if not line.startswith('***'):
00352         raise ValueError("Line does not start with '***':\n%s" % line)
00353     for line in handle:
00354         if line.strip():
00355             break
00356     else:
00357         raise ValueError("Unexpected end of stream: Expected to find line starting with '***'")
00358     if not line.startswith('***'):
00359         raise ValueError("Line does not start with '***':\n%s" % line)
00360 

Here is the caller graph for this function:

def Bio.Motif.Parsers.MEME.read (   handle)
Parses the text output of the MEME program into MEME.Record object.

Example:

>>> f = open("meme.output.txt")
>>> from Bio.Motif.Parsers import MEME
>>> record = MEME.read(f)
>>> for motif in record.motifs:
...     for instance in motif.instances:
...         print instance.motif_name, instance.sequence_name, instance.strand, instance.pvalue

Definition at line 16 of file MEME.py.

00016 
00017 def read(handle):
00018     """Parses the text output of the MEME program into MEME.Record object.
00019     
00020     Example:
00021     
00022     >>> f = open("meme.output.txt")
00023     >>> from Bio.Motif.Parsers import MEME
00024     >>> record = MEME.read(f)
00025     >>> for motif in record.motifs:
00026     ...     for instance in motif.instances:
00027     ...         print instance.motif_name, instance.sequence_name, instance.strand, instance.pvalue
00028     
00029     """
00030     record = MEMERecord()
00031     __read_version(record, handle)
00032     __read_datafile(record, handle)
00033     __read_alphabet(record, handle)
00034     __read_sequence_names(record, handle)
00035     __read_command(record, handle)
00036     for line in handle:
00037         if line.startswith('MOTIF  1'):
00038             break
00039     else:
00040         raise ValueError('Unexpected end of stream')
00041     while True:
00042         motif = __create_motif(line)
00043         motif.alphabet = record.alphabet
00044         record.motifs.append(motif)
00045         __read_motif_name(motif, handle)
00046         __read_motif_sequences(motif, handle, 'revcomp' in record.command)
00047         __skip_unused_lines(handle)
00048         try:
00049             line = handle.next()
00050         except StopIteration:
00051             raise ValueError('Unexpected end of stream: Expected to find new motif, or the summary of motifs')
00052         if line.startswith("SUMMARY OF MOTIFS"):
00053             break
00054         if not line.startswith('MOTIF'):
00055             raise ValueError("Line does not start with 'MOTIF':\n%s" % line)
00056     return record
00057 

Here is the call graph for this function: