# Copyright 2008 by Bartek Wilczynski. # Adapted from Bio.MEME.Parser by Jason A. Hackney. All rights reserved. # This code is part of the Biopython distribution and governed by its # license. Please see the LICENSE file that should have been included # as part of this package. """Module for the support of Motif Alignment and Search Tool (MAST).""" from __future__ import print_function import xml.etree.ElementTree as ET from Bio.motifs import meme class Record(list): """The class for holding the results from a MAST run. A mast.Record holds data about matches between motifs and sequences. The motifs held by the Record are objects of the class meme.Motif. The mast.Record class inherits from list, so you can access individual motifs in the record by their index. Alternatively, you can find a motif by its name: >>> from Bio import motifs >>> with open("motifs/mast.crp0.de.oops.txt.xml") as f: ... record = motifs.parse(f, 'MAST') >>> motif = record[0] >>> print(motif.name) 1 >>> motif = record['1'] >>> print(motif.name) 1 """ def __init__(self): """Initialize the class.""" self.sequences = [] self.version = "" self.database = "" self.diagrams = {} self.alphabet = None self.strand_handling = "" def __getitem__(self, key): """Return the motif of index key.""" if isinstance(key, str): for motif in self: if motif.name == key: return motif else: return list.__getitem__(self, key) def read(handle): """Parse a MAST XML format handle as a Record object.""" record = Record() try: xml_tree = ET.parse(handle) except ET.ParseError: raise ValueError("Improper MAST XML input file. XML root tag should start with