Example #1
0
    def format(self,format):
        """Returns a string representation of the Motif in a given format

        Currently supported fromats:
         - pfm : JASPAR Position Frequency Matrix
         - transfac : TRANSFAC like files
        """

        if format=="pfm":
            from Bio.Motif import Jaspar
            return Jaspar.write(self)
        elif format=="transfac":
            from Bio.Motif import TRANSFAC
            motifs = [self]
            return TRANSFAC.write(motifs)
        else:
            raise ValueError("Unknown format type %s" % format)
Example #2
0
def write(motifs, format):
    """Returns a string representation of motifs in a given format

    Currently supported fromats:
     - pfm : JASPAR Position Frequency Matrix
             [only if len(motifs)==1]
     - transfac : TRANSFAC like files
    """

    if format=="pfm":
        from Bio.Motif import Jaspar
        if len(motifs)!=1:
            raise Exception("Only a single motif can be written in the JASPAR Position Frequency Matrix (pfm) format")
        motif = motifs[0]
        return Jaspar.write(motif)
    elif format=="transfac":
        from Bio.Motif import TRANSFAC
        return TRANSFAC.write(motifs)
    else:
        raise ValueError("Unknown format type %s" % format)
Example #3
0
def parse(handle, format):
    """Parses an output file of motif finding programs.

    Currently supported formats:
     - AlignAce:      AlignAce output file format
     - MEME:          MEME output file motif
     - TRANSFAC:      TRANSFAC database file format
     - pfm:           JASPAR-style position-frequency matrix
     - sites:         JASPAR-style sites file
     - jaspar-pfm:    JASPAR-style position-frequency matrix [DEPRECATED]
     - jaspar-sites:  JASPAR-style sites file [DEPRECATED]
    As files in the pfm and sites formats contain only a single motif,
    it is easier to use Bio.Motif.read() instead of Bio.Motif.parse()
    for those.

    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
    >>> for motif in Motif.parse(open("Motif/alignace.out"),"alignace"):
    ...     print motif.consensus
    TCTACGATTGAG
    CTGCAGCTAGCTACGAGTGAG
    GTGCTCTAAGCATAGTAGGCG
    GCCACTAGCAGAGCAGGGGGC
    CGACTCAGAGGTT
    CCACGCTAAGAGAGGTGCCGGAG
    GCGCGTCGCTGAGCA
    GTCCATCGCAAAGCGTGGGGC
    GGGATCAGAGGGCCG
    TGGAGGCGGGG
    GACCAGAGCTTCGCATGGGGG
    GGCGTGCGTG
    GCTGGTTGCTGTTCATTAGG
    GCCGGCGGCAGCTAAAAGGG
    GAGGCCGGGGAT
    CGACTCGTGCTTAGAAGG
    """
    if format=="AlignAce":
        # Old Motif code
        from Bio.Motif.Parsers import AlignAce
        record = AlignAce.read(handle)
        return iter(record.motifs)
    elif format=="alignace":
        # Old Motif code
        from Bio.Motif import AlignAce
        record = AlignAce.read(handle)
        return record
    elif format=="MEME":
        from Bio.Motif.Parsers import MEME
        record = MEME.read(handle)
        return iter(record.motifs)
    elif format=="meme":
        from Bio.Motif import MEME
        record = MEME.read(handle)
        return record
    elif format=="TRANSFAC":
        from Bio.Motif import TRANSFAC
        record = TRANSFAC.read(handle)
        return record
    elif format in ('pfm', 'sites'):
        from Bio.Motif import Jaspar
        motif = Jaspar.read(handle, format)
    elif format=="jaspar-pfm":
        motif = OldMotif()._from_jaspar_pfm(handle)
        return iter([motif])
    elif format=="jaspar-sites":
        motif = OldMotif()._from_jaspar_sites(handle)
        return iter([motif])
    else:
        raise ValueError("Unknown format %s" % format)
    # Treat the single-motif formats
    motifs = [motif]
    return motifs