Course Content
Biopython Fundamentals
About Lesson

Introduction to Sequence Motifs:

  • Sequence motifs are short, conserved patterns or motifs within DNA or protein sequences.
  • Motifs play a crucial role in understanding biological function, regulatory elements, and evolutionary relationships.

Using Regular Expressions for Motif Search:

  • Regular expressions (regex) provide a powerful and flexible way to search for specific patterns within sequences.
  • Biopython’s re module enables motif search using regular expressions.

Motif Search with Regular Expressions

import re

sequence = "ATGTCAGCTAAGCGAATAGTACGT"

motif = "T[A|G]"

matches = re.finditer(motif, sequence)

for match in matches:
    start = match.start()
    end = match.end()
    print("Motif found at position", start, "-", end)
  • Define a sequence and a motif using regular expression syntax.
  • Use re.finditer() to find all matches of the motif in the sequence.
  • Iterate over the matches and print their start and end positions.

Regular Expression Syntax

  • Regular expressions use special characters and symbols to define patterns.
  • Examples of common symbols used in regular expressions:
    • .: Matches any single character.
    • []: Matches any character within the brackets.
    • |: Acts as an OR operator, matching either side of the symbol.

Motif Search with Position-Specific Notation:

  • Position-specific notation allows specifying variations at specific positions within the motif.
  • Use square brackets with specific characters or groups at desired positions.

Motif Search with Position-Specific Notation

import re

sequence = "ATGTCAGCTAAGCGAATAGTACGT"

motif = "T[A|G]..[AT]"

matches = re.finditer(motif, sequence)

for match in matches:
    start = match.start()
    end = match.end()
    print("Motif found at position", start, "-", end)
  • Define a motif using position-specific notation.
  • Use re.finditer() to find all matches of the motif in the sequence.
  • Iterate over the matches and print their start and end positions.

Summary

  • Motif search using regular expressions is a powerful approach to identify conserved patterns in sequences.
  • Biopython’s re module enables motif search and analysis using regular expressions.
  • Understanding regular expression syntax and position-specific notation is crucial for effective motif search