Back to index

python-biopython  1.60
AlignAce.py
Go to the documentation of this file.
00001 # Copyright 2003 by Bartek Wilczynski.  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 
00006 """Parsing AlignACE files: AlignAceParser
00007 """
00008 
00009 from Bio.Motif import Motif
00010 from Bio.Alphabet import IUPAC
00011 from Bio.Seq import Seq
00012 
00013 
00014 class Record(object):
00015     def __init__(self):
00016         self.motifs=[]
00017         self.current_motif=None
00018         self.param_dict = None
00019 
00020 
00021 def read(handle):
00022     """read(handle)"""
00023     record = Record()
00024     record.ver = handle.next()
00025     record.cmd_line = handle.next()
00026     for line in handle:
00027         if line.strip() == "":
00028             pass
00029         elif line[:4]=="Para":
00030             record.param_dict={}
00031         elif line[0]=="#":
00032             seq_name = line.split("\t")[1]
00033             record.seq_dict.append(seq_name)
00034         elif "=" in line:
00035             par_name = line.split("=")[0].strip()
00036             par_value = line.split("=")[1].strip()
00037             record.param_dict[par_name]=par_value
00038         elif line[:5]=="Input":
00039             record.seq_dict=[]
00040         elif line[:5]=="Motif":
00041             record.current_motif = Motif()
00042             record.motifs.append(record.current_motif)
00043             record.current_motif.alphabet=IUPAC.unambiguous_dna
00044         elif line[:3]=="MAP":
00045             record.current_motif.score = float(line.split()[-1])
00046         elif len(line.split("\t"))==4:
00047             seq = Seq(line.split("\t")[0],IUPAC.unambiguous_dna)
00048             record.current_motif.add_instance(seq)
00049         elif "*" in line:
00050             record.current_motif.set_mask(line.strip("\n\c"))
00051         else:
00052             raise ValueError(line)
00053     return record
00054 
00055