Skillversitas

Motif Objects

Motifs are short patterns recurring in sequences: transcription factor binding sites, protein domains, RNA elements. Bio.motifs models a motif as a position-specific scoring matrix (PSSM) or position frequency matrix, and provides tools to build, write, and scan for motifs.

Building a Motif from Sequences

from Bio import motifs

seqs = ["ACGT", "ACGT", "ACGG", "ACGT", "ACCC"]
m = motifs.create(seqs)
print(m.alphabet)
print(m.count)        # position frequency matrix
print(m.log_odds)     # position-specific scoring (log-odds)
print(m.pseudocounts)  # 1.0 by default

Parsing Motif Files

Bio.motifs.io supports several motif file formats (MAST, MEME, TRANSFAC):

from Bio import motifs

for motif in motifs.parse("motifs.mast", "mast"):
    print(motif.id)
    print(motif.pfm)  # position frequency matrix

Scanning Sequences for Motifs

from Bio import motifs
from Bio.Seq import Seq

m = motifs.create(["ACGT", "ACGG", "ACGT"])
target = Seq("GGGACGTAACGTCCCC")

# log-odds score at each position
scores = m.score(target, "log-odds")
best = max(range(len(scores)), key=lambda i: scores[i])
print("best position:", best, "score:", round(scores[best], 2))

Writing Motifs

with open("out.mast", "w") as out:
    motifs.write([m], out, "mast")

with open("out.meme", "w") as out:
    motifs.write([m], out, "meme")

Typical Uses

  • Profile a set of known binding sites, then scan a genome region for similar sites.
  • Compare two motif sets (log-odds difference) to find condition-specific factors.
  • Generate IUPAC consensus strings from a frequency matrix for annotation.

Summary

Bio.motifs represents motifs as frequency and log-odds matrices: build one with motifs.create(seqs), parse MAST/MEME/TRANSFAC files with motifs.parse, score positions in a target with motif.score, and export with motifs.write. It is the standard way to handle binding-site profiles in Python pipelines.