Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Find patterns, motifs, and subsequences in biological sequences using Biopython. Use when searching for transcription factor binding sites, regulatory elements, or any sequence pattern. For restriction enzyme analysis, use the restriction-analysis skill.
.claude/skills/bio-motif-search/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-15 | ✗→✓ | ▲ Improved | 23% | 0% |
| case-01 | ✗→✓ | ▲ Improved | 139% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 49% | 0% |
| case-12 | ✗→✓ | ▲ Improved | -11% | 0% |
| case-04 | ✓→✗ | ▼ Worse | 161% | 0% |
<!--
#
#
-->
Find patterns and motifs in biological sequences using Biopython and regex.
pythonfrom Bio.Seq import Seq from Bio import motifs import re
pythonseq = Seq('ATGCGAATTCGATCGAATTCGATC') pos = seq.find('GAATTC') # Returns 4 (first position)
Returns -1 if not found.
pythonseq = Seq('ATGCGAATTCGATCGAATTCGATC') n = seq.count('GAATTC') # Returns 2
pythonseq = Seq('ATGCGAATTCGATCGAATTCGATC') first = seq.find('GAATTC') # 4 second = seq.find('GAATTC', 5) # 14 (search from position 5)
pythondef find_all(seq, pattern): pattern = str(pattern) seq_str = str(seq) positions = [] pos = seq_str.find(pattern) while pos != -1: positions.append(pos) pos = seq_str.find(pattern, pos + 1) return positions seq = Seq('ATGCGAATTCGATCGAATTCGATC') positions = find_all(seq, 'GAATTC') # [4, 14]
pythondef find_both_strands(seq, pattern): results = [] for pos in find_all(seq, pattern): results.append(('+', pos)) rc = seq.reverse_complement() for pos in find_all(rc, pattern): results.append(('-', len(seq) - pos - len(pattern))) return results
For ambiguous or flexible patterns:
pythondef regex_search(seq, pattern): seq_str = str(seq) return [(m.start(), m.group()) for m in re.finditer(pattern, seq_str)] # Find all ATG start codons matches = regex_search(seq, 'ATG') # Find TATA box variants (TATAAA with possible variations) matches = regex_search(seq, 'TATA[AT]A[AT]')
pythonIUPAC_DNA = { 'R': '[AG]', 'Y': '[CT]', 'S': '[GC]', 'W': '[AT]', 'K': '[GT]', 'M': '[AC]', 'B': '[CGT]', 'D': '[AGT]', 'H': '[ACT]', 'V': '[ACG]', 'N': '[ACGT]' } def iupac_to_regex(pattern): regex = '' for char in pattern: regex += IUPAC_DNA.get(char, char) return regex # Search for pattern with ambiguous bases pattern = 'GATNNTC' # N = any base regex = iupac_to_regex(pattern) # 'GAT[ACGT][ACGT]TC' matches = regex_search(seq, regex)
pythondef find_orfs(seq, start='ATG', stops=['TAA', 'TAG', 'TGA'], min_length=30): seq_str = str(seq) orfs = [] start_positions = find_all(seq, start) for start_pos in start_positions: for frame_offset in range(3): if (start_pos - frame_offset) % 3 == 0: for stop in stops: stop_pos = start_pos + 3 while stop_pos <= len(seq) - 3: codon = seq_str[stop_pos:stop_pos + 3] if codon == stop: if stop_pos - start_pos >= min_length: orfs.append((start_pos, stop_pos + 3, seq[start_pos:stop_pos + 3])) break stop_pos += 3 break return orfs
pythondef find_tandem_repeats(seq, unit_length, min_copies=2): seq_str = str(seq) repeats = [] for i in range(len(seq) - unit_length * min_copies + 1): unit = seq_str[i:i + unit_length] copies = 1 pos = i + unit_length while pos <= len(seq) - unit_length and seq_str[pos:pos + unit_length] == unit: copies += 1 pos += unit_length if copies >= min_copies: repeats.append((i, unit, copies)) return repeats seq = Seq('ATGCAGCAGCAGCAGTTT') repeats = find_tandem_repeats(seq, 3, 2) # Find CAG repeats
pythonfrom Bio import motifs from Bio.Seq import Seq instances = [Seq('TACAA'), Seq('TACGA'), Seq('TACTA'), Seq('TGCAA')] m = motifs.create(instances)
python# Consensus sequences m.consensus # Most common base at each position m.degenerate_consensus # IUPAC degenerate consensus m.anticonsensus # Least likely sequence # Counts and matrices m.counts # Position frequency matrix (counts) pwm = m.counts.normalize(pseudocounts=0.5) # Position weight matrix pssm = pwm.log_odds() # Position-specific scoring matrix
python# Per-position information content pwm = m.counts.normalize(pseudocounts=0.5) pssm = pwm.log_odds() # Mean information content (bits) mean_ic = pssm.mean() # Score range max_score = pssm.max min_score = pssm.min # Relative entropy print(f'Mean IC: {mean_ic:.3f} bits') print(f'Max score: {max_score:.3f}') print(f'Min score: {min_score:.3f}')
pythonseq = Seq('ATGCTACAAGCTACGATACTA') # Search with threshold for position, score in pssm.search(seq, threshold=3.0): match = seq[position:position + len(m.consensus)] print(f'Position {position}: {match} (score: {score:.2f})') # Search both strands for position, score in pssm.search(seq, threshold=3.0, both=True): print(f'Position {position}: score {score:.2f}')
python# Calculate score distribution from PSSM sd = pssm.distribution() # Get threshold for specific false positive rate threshold = sd.threshold_fpr(0.01) # 1% FPR # Get threshold for specific false negative rate threshold = sd.threshold_fnr(0.1) # 10% FNR # Balanced threshold threshold = sd.threshold_balanced(1000) # For sequence of length 1000
pythonfrom Bio import motifs with open('motif.jaspar') as f: m = motifs.read(f, 'jaspar') print(f'Name: {m.name}') print(f'Matrix ID: {m.matrix_id}') print(m.counts)
pythonwith open('meme.txt') as f: record = motifs.parse(f, 'meme') for m in record: print(f'{m.name}: {m.consensus}')
pythonwith open('motif.transfac') as f: record = motifs.parse(f, 'transfac') for m in record: print(f'{m.name}: {m.consensus}')
python# Write to JASPAR format with open('output.jaspar', 'w') as f: f.write(m.format('jaspar')) # Write to TRANSFAC format with open('output.transfac', 'w') as f: f.write(m.format('transfac'))
| Motif | Pattern | Description | |-------|---------|-------------| | Start codon | ATG | Translation initiation | | Stop codons | TAA\|TAG\|TGA | Translation termination | | Kozak | [AG]CCATGG | Eukaryotic translation initiation | | TATA box | TATA[AT]A[AT] | Promoter element | | GC box | GGGCGG | Promoter element (Sp1) | | CAAT box | CCAAT | Promoter element | | Poly-A signal | AATAAA | mRNA polyadenylation | | E-box | CA[ACGT]{2}TG | bHLH TF binding | | CpG island | High CG density | Promoter regions |
| Error | Cause | Solution | |-------|-------|----------| | No matches found | Case mismatch | Use .upper() on both | | Missing matches | Pattern on opposite strand | Search reverse complement too | | TypeError | Mixing Seq and string | Use str() conversion | | ValueError parsing motif | Wrong format specified | Check file format |
Need to find patterns in sequence?
├── Exact match?
│ ├── Just need position of first? → seq.find()
│ ├── Need count? → seq.count()
│ └── Need all positions? → loop with find()
├── Fuzzy/ambiguous pattern?
│ └── Use regex with re.finditer()
├── IUPAC pattern?
│ └── Convert to regex, then search
├── Both strands?
│ └── Search original and reverse_complement
├── Probabilistic (PWM/PSSM)?
│ └── Use Bio.motifs
│ ├── Create from instances → motifs.create()
│ ├── Read from file → motifs.read() / parse()
│ ├── Get consensus → m.consensus, m.degenerate_consensus
│ ├── Search sequence → pssm.search()
│ └── Calculate threshold → distribution.threshold_fpr()
└── Restriction sites?
└── Use restriction-analysis skill (Bio.Restriction)<!-- AUTHOR_SIGNATURE: 9a7f3c2e-MD-BABU-MIA-2026-MSSM-SECURE -->
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-09 | pass→pass | 5,642 | 3,570 | -37% | 1 | 1 | 0% | 1,067 | 3,469 | +225% | 0 | 0 | — |
case-14 | pass→pass | 3,010 | 1,795 | -40% | 1 | 1 | 0% | 488 | 3,023 | +519% | 0 | 0 | — |
case-15 | fail→pass | 17,871 | 1,461 | -92% | 1 | 1 | 0% | 2,404 | 2,962 | +23% | 0 | 0 | — |
case-01 | fail→pass | 9,165 | 6,784 | -26% | 1 | 1 | 0% | 1,717 | 4,102 | +139% | 0 | 0 | — |
case-02 | pass→pass | 11,050 | 7,585 | -31% | 1 | 1 | 0% | 2,233 | 4,352 | +95% | 0 | 0 | — |
case-03 | pass→pass | 14,151 | 7,438 | -47% | 1 | 1 | 0% | 2,957 | 4,242 | +43% | 0 | 0 | — |
case-04 | pass→fail | 8,240 | 6,662 | -19% | 1 | 1 | 0% | 1,513 | 3,954 | +161% | 0 | 0 | — |
case-05 | fail→pass | 17,060 | 5,254 | -69% | 1 | 1 | 0% | 2,454 | 3,658 | +49% | 0 | 0 | — |
case-06 | pass→pass | 11,042 | 4,389 | -60% | 1 | 1 | 0% | 1,973 | 3,472 | +76% | 0 | 0 | — |
case-07 | fail→fail | 11,725 | 10,538 | -10% | 1 | 1 | 0% | 2,305 | 5,099 | +121% | 0 | 0 | — |
case-08 | pass→pass | 13,649 | 7,568 | -45% | 1 | 1 | 0% | 2,854 | 4,233 | +48% | 0 | 0 | — |
case-10 | pass→pass | 8,932 | 3,637 | -59% | 1 | 1 | 0% | 1,790 | 3,389 | +89% | 0 | 0 | — |
case-11 | pass→pass | 9,780 | 3,828 | -61% | 1 | 1 | 0% | 1,984 | 3,505 | +77% | 0 | 0 | — |
case-12 | fail→pass | 17,051 | 2,568 | -85% | 1 | 1 | 0% | 3,600 | 3,209 | -11% | 0 | 0 | — |
case-13 | pass→pass | 10,531 | 4,299 | -59% | 1 | 1 | 0% | 1,975 | 3,592 | +82% | 0 | 0 | — |
case-16 | pass→pass | 4,834 | 2,439 | -50% | 1 | 1 | 0% | 866 | 3,187 | +268% | 0 | 0 | — |
case-17 | pass→pass | 9,591 | 5,997 | -37% | 1 | 1 | 0% | 1,927 | 3,271 | +70% | 0 | 0 | — |
case-18 | pass→pass | 7,826 | 3,136 | -60% | 1 | 1 | 0% | 1,541 | 3,303 | +114% | 0 | 0 | — |
case-19 | pass→pass | 7,010 | 3,736 | -47% | 1 | 1 | 0% | 1,361 | 3,256 | +139% | 0 | 0 | — |
case-20 | pass→pass | 13,975 | 10,107 | -28% | 1 | 1 | 0% | 2,900 | 4,721 | +63% | 0 | 0 | — |
case-21 | pass→pass | 8,201 | 13,215 | +61% | 1 | 1 | 0% | 1,701 | 3,604 | +112% | 0 | 0 | — |
case-22 | pass→pass | 10,741 | 6,738 | -37% | 1 | 1 | 0% | 2,318 | 4,227 | +82% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 21 counted toward the lift figure. The other 1 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +14 percentage points is the difference between those two pass rates over the 21 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
| Model | Method | Date | Lift |
|---|---|---|---|
| gemini-3.6-flash | verified | 7/24/2026 | +23% |
Other measured skills in the registry, with their headline benchmark lift.