Skip to content
Back to skills

Python Bio Strings

ASecurity

Python string operations for bioinformatics: reverse complement, GC content, motif finding, FASTA parsing. Bio-specific patterns and pitfalls only.

  • 4 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 27, 2026
data-aipythonapi

Works with

  • api

Security analysis

A100/100

Scanned May 27, 2026

npx -y skills add Pavel-Kravchenko/Bioinformatics --skill python-bio-strings --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python Bio Strings?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Python Bio Strings
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/pavel-kravchenko-python-bio-strings/badge)](https://www.skillsdirectory.com/skills/pavel-kravchenko-python-bio-strings)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: python-bio-strings
description: "Python string operations for bioinformatics: reverse complement, GC content, motif finding, FASTA parsing. Bio-specific patterns and pitfalls only."
tool_type: python
primary_tool: Python
---

# Python Strings for Bioinformatics

## Core Patterns

```python
# Reverse complement — use maketrans, NOT chained replace()
complement_table = str.maketrans('ATGC', 'TACG')
rev_comp = dna.translate(complement_table)[::-1]

# Transcription
rna = dna.replace('T', 'U')

# Extract all codons
codons = [mrna[i:i+3] for i in range(0, len(mrna), 3)]

# GC content
gc = (seq.count('G') + seq.count('C')) / len(seq)

# Validate DNA
is_valid = all(c in 'ATGC' for c in seq.upper())
```

## Motif Finding

```python
# All positions of a motif (overlapping)
def find_all(seq, motif):
    positions = []
    pos = seq.find(motif)
    while pos != -1:
        positions.append(pos)
        pos = seq.find(motif, pos + 1)
    return positions

# Non-overlapping count (built-in)
"ATATATAT".count("ATAT")  # returns 2

# Regex for IUPAC patterns
import re
hits = [(m.start(), m.group()) for m in re.finditer(r'TATA[AT]A[AT]', seq)]
```

## FASTA Header Parsing

```python
# UniProt: >sp|P04637|P53_HUMAN Cellular tumor antigen...
header = ">sp|P04637|P53_HUMAN Cellular tumor antigen p53 OS=Homo sapiens"
parts = header.split('|')
db, accession = parts[0][1:], parts[1]
description = parts[2].split()[0]  # P53_HUMAN
```

## Sequence Features

```python
seq = "ATGGCCGATTAGCCA"

seq.startswith('ATG')          # has start codon
seq[-3:] in ('TAA', 'TAG', 'TGA')  # ends with stop codon
'GATTAG' in seq                # motif membership
```

## Pitfalls

- **Chained `replace()` fails for complement**: `dna.replace('A','T').replace('T','A')` converts all A→T then all T→A, including the ones just created. Use `str.maketrans` + `translate()`.
- **`find()` returns -1, not None**: `if pos:` is truthy for -1. Always check `if pos != -1:`.
- **`count()` is non-overlapping**: `"ATAT".count("AT")` = 2 (correct), but `"AAAA".count("AA")` = 2, not 3. Use `find()` loop for overlapping.
- **Case sensitivity**: `.count('G')` misses lowercase 'g'. Always normalize with `.upper()` first.
- **Strings are immutable**: `seq[0] = 'C'` raises `TypeError`. Build new strings with concatenation or `''.join(...)`.
- **Bioinformatics coordinates are 1-based**: Python slices are 0-based half-open `[start, stop)`. GFF/VCF position 100 → Python index 99.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.