Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Read biological sequence files (FASTA, FASTQ, GenBank, EMBL, ABI, SFF) using Biopython Bio.SeqIO. Use when parsing sequence files, iterating multi-sequence files, random access to large files, or high-performance parsing.
.claude/skills/bio-read-sequences/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-22 | ✗→✓ | ▲ Improved | — | — |
| case-09 | ✗→✓ | ▲ Improved | — | — |
| case-13 | ✗→✓ | ▲ Improved | — | — |
| case-08 | ✗→✓ | ▲ Improved | — | — |
| case-02 | ✗→✓ | ▲ Improved | — | — |
Reference examples tested with: BioPython 1.83+
Before using code patterns, verify installed versions match. If versions differ:
pip show biopython then help(module.function) to check signaturesIf code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Read biological sequence data from files using Biopython's Bio.SeqIO module.
"Read sequences from a file" → Parse file into a collection of SeqRecord objects with IDs, sequences, and annotations accessible.
SeqIO.parse() or SeqIO.read() (BioPython)readDNAStringSet() or readAAStringSet() (Biostrings)pythonfrom Bio import SeqIO
Use for files with one or more sequences. Returns an iterator of SeqRecord objects.
pythonfor record in SeqIO.parse('sequences.fasta', 'fasta'): print(record.id, len(record.seq))
Important: Always specify the format explicitly as the second argument.
Use when file contains exactly one sequence. Raises error if zero or multiple records.
pythonrecord = SeqIO.read('single.fasta', 'fasta')
Use for random access by record ID. Loads entire file into memory.
pythonrecords = SeqIO.to_dict(SeqIO.parse('sequences.fasta', 'fasta')) seq = records['sequence_id'].seq
Use for large files when random access is needed without loading everything into memory.
pythonrecords = SeqIO.index('large.fasta', 'fasta') seq = records['sequence_id'].seq records.close()
Use for very large files or multiple files. Creates persistent SQLite index.
python# Create index (first time - parses file) records = SeqIO.index_db('index.sqlite', 'large.fasta', 'fasta') seq = records['sequence_id'].seq records.close() # Reuse existing index (instant load) records = SeqIO.index_db('index.sqlite') # Index multiple files together records = SeqIO.index_db('combined.sqlite', ['file1.fasta', 'file2.fasta'], 'fasta')
Advantages over index():
For maximum throughput on large files, use low-level parsers (3-6x faster than SeqIO.parse):
Goal: Parse large FASTA files at maximum speed without SeqRecord overhead.
Approach: Use low-level tuple-based parser returning (title, sequence) strings.
Reference (BioPython 1.83+):
pythonfrom Bio.SeqIO.FastaIO import SimpleFastaParser with open('large.fasta') as handle: for title, sequence in SimpleFastaParser(handle): if len(sequence) > 1000: print(title.split()[0]) # First word is usually ID
Returns (title, sequence) tuples as strings (no SeqRecord overhead).
Goal: Parse large FASTQ files at maximum speed.
Approach: Use low-level tuple-based parser returning (title, sequence, quality_string) strings.
Reference (BioPython 1.83+):
pythonfrom Bio.SeqIO.QualityIO import FastqGeneralIterator with open('reads.fastq') as handle: for title, sequence, quality in FastqGeneralIterator(handle): avg_qual = sum(ord(c) - 33 for c in quality) / len(quality)
Returns (title, sequence, quality_string) tuples.
| Format | String | Typical Extension | Notes | |--------|--------|-------------------|-------| | FASTA | 'fasta' | .fasta, .fa, .fna, .faa | Most common | | FASTA 2-line | 'fasta-2line' | .fasta | One line per sequence (no wrapping) | | FASTQ | 'fastq' | .fastq, .fq | With quality scores | | FASTQ Solexa | 'fastq-solexa' | .fastq | Old Solexa/Illumina (pre-1.3) | | FASTQ Illumina | 'fastq-illumina' | .fastq | Illumina 1.3-1.7 | | GenBank | 'genbank' or 'gb' | .gb, .gbk | With features/annotations | | EMBL | 'embl' | .embl | European format with features | | Swiss-Prot | 'swiss' | .dat | UniProt format |
| Format | String | Use Case | |--------|--------|----------| | ABI | 'abi' | Sanger sequencing trace files (.ab1) | | ABI Trimmed | 'abi-trim' | ABI with low-quality ends trimmed | | SFF | 'sff' | 454/Ion Torrent flowgram data | | SFF Trimmed | 'sff-trim' | SFF with adapter/quality trimming | | QUAL | 'qual' | Quality scores file (pairs with FASTA) | | PHD | 'phd' | Phred/Phrap/Consed output | | ACE | 'ace' | Assembly format (Consed) | | PDB SEQRES | 'pdb-seqres' | Protein sequences from PDB files | | PDB ATOM | 'pdb-atom' | Sequences from ATOM records in PDB | | SnapGene | 'snapgene' | SnapGene .dna files | | GCK | 'gck' | Gene Construction Kit files | | XDNA | 'xdna' | DNA Strider / SerialCloner files |
python# Read Sanger sequencing trace with quality record = SeqIO.read('sample.ab1', 'abi') print(f'Sequence: {record.seq}') qualities = record.letter_annotations['phred_quality'] # Auto-trim low quality ends record_trimmed = SeqIO.read('sample.ab1', 'abi-trim')
pythonfor record in SeqIO.parse('reads.sff', 'sff'): print(record.id, len(record.seq)) # With trimming applied for record in SeqIO.parse('reads.sff', 'sff-trim'): print(record.id, len(record.seq))
python# Get sequences from SEQRES records for record in SeqIO.parse('structure.pdb', 'pdb-seqres'): print(f'Chain {record.id}: {record.seq}') # Get sequences from ATOM coordinates for record in SeqIO.parse('structure.pdb', 'pdb-atom'): print(f'Chain {record.id}: {record.seq}')
| Format | String | Notes | |--------|--------|-------| | PHYLIP | 'phylip' | Interleaved phylip | | PHYLIP Sequential | 'phylip-sequential' | Sequential phylip | | PHYLIP Relaxed | 'phylip-relaxed' | Longer names allowed | | Clustal | 'clustal' | ClustalW output | | Stockholm | 'stockholm' | Rfam/Pfam alignments | | NEXUS | 'nexus' | PAUP/MrBayes format | | MAF | 'maf' | Multiple Alignment Format |
After parsing, each record has these key attributes:
pythonrecord.id # Sequence identifier (string) record.name # Sequence name (string) record.description # Full description line (string) record.seq # Sequence data (Seq object) record.features # List of SeqFeature objects (GenBank/EMBL) record.annotations # Dictionary of annotations record.letter_annotations # Per-letter annotations (quality scores) record.dbxrefs # Database cross-references
pythonrecords = list(SeqIO.parse('sequences.fasta', 'fasta'))
pythoncount = sum(1 for _ in SeqIO.parse('sequences.fasta', 'fasta'))
pythonfrom Bio.SeqIO.FastaIO import SimpleFastaParser with open('sequences.fasta') as f: count = sum(1 for _ in SimpleFastaParser(f))
pythonids = [record.id for record in SeqIO.parse('sequences.fasta', 'fasta')]
pythonfor record in SeqIO.parse('sequence.gb', 'genbank'): for feature in record.features: if feature.type == 'CDS': print(feature.qualifiers.get('product', ['Unknown'])[0]) cds_seq = feature.extract(record.seq) # Get feature sequence
pythonfor record in SeqIO.parse('reads.fastq', 'fastq'): qualities = record.letter_annotations['phred_quality'] avg_quality = sum(qualities) / len(qualities)
pythonwith open('sequences.fasta', 'r') as handle: for record in SeqIO.parse(handle, 'fasta'): print(record.id)
pythondef get_accession(identifier): return identifier.split('.')[0] # Remove version records = SeqIO.index('sequences.fasta', 'fasta', key_function=get_accession)
| Error | Cause | Solution | |-------|-------|----------| | ValueError: More than one record | Used read() on multi-record file | Use parse() instead | | ValueError: No records found | Used read() on empty file | Check file exists and has content | | ValueError: unknown format | Typo in format string | Check format string spelling | | UnicodeDecodeError | Binary file or wrong encoding | Open with encoding='latin-1' or check file | | sqlite3.OperationalError | index_db file locked | Close other connections first |
Need to read sequences?
├── Single record in file?
│ └── Use SeqIO.read()
├── Multiple records?
│ ├── Need all in memory at once?
│ │ └── Use list(SeqIO.parse()) or SeqIO.to_dict()
│ ├── Process one at a time (memory efficient)?
│ │ └── Use SeqIO.parse() iterator
│ ├── Large file, need random access by ID?
│ │ ├── Single session? → Use SeqIO.index()
│ │ └── Persistent/multi-file? → Use SeqIO.index_db()
│ └── Maximum throughput needed?
│ └── Use SimpleFastaParser or FastqGeneralIterator
├── Sanger sequencing trace?
│ └── Use 'abi' or 'abi-trim' format
├── 454/Ion Torrent data?
│ └── Use 'sff' or 'sff-trim' format
└── Protein from structure?
└── Use 'pdb-seqres' or 'pdb-atom' format| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-22 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
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. The headline lift of +41 percentage points is the difference between those two pass rates over the 22 comparable cases.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.