read-write-sequences
Skill8 starsChanged 5 months agoMITView on GitHub
Read and write FASTA, FASTQ, GenBank, EMBL using Biopython SeqIO — including indexed random access, conversion, and 2026 best practices.
In this repository125 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/AGENTS.mdAGENTS.md
- batch-processingSkill
- bowtie2-alignmentSkill
- bwa-alignmentSkill
- bwa-mem2-alignmentSkill
- codon-usageSkill
- compressed-sequence-filesSkill
- fastq-quality-scoresSkill
- filter-sequencesSkill
- format-conversionSkill
- hisat2-alignmentSkill
- motif-searchSkill
- paired-end-fastqSkill
- pysam-genomicsSkill
- reverse-complementSkill
- sam-bam-basicsSkill
- samtools-bam-processingSkill
- seq-objectsSkill
- sequence-propertiesSkill
- sequence-slicingSkill
- sequence-statisticsSkill
- star-alignmentSkill
- transcription-translationSkill
- academic-cvSkill
- faculty-interviewSkill
- fellowship-applicationSkill
- industry-transitionSkill
- negotiationSkill
- tenure-dossierSkill
- admet-predictionSkill
- conformer-generationSkill
- covalent-designSkill
- docking-rescoringSkill
- free-energy-calculationsSkill
- generative-designSkill
- molecular-descriptorsSkill
- molecular-ioSkill
- molecular-standardizationSkill
- pharmacophore-modelingSkill
- pose-validationSkill
- protac-degradersSkill
- qsar-modelingSkill
- retrosynthesisSkill
- scaffold-analysisSkill
- shape-similaritySkill
- similarity-searchingSkill
- substructure-searchSkill
- virtual-screeningSkill
- snakemake-workflow-engineSkill
- ai-disclosureSkill
- data-privacySkill
- image-integritySkill
- irb-protocolSkill
- ai-detection-awarenessSkill
- ai-disclosure-statementSkill
- scientific-voice-styleSkill
- text-humanizing-editorialSkill
- cellprofiler-pipelinesSkill
- image-analysis-best-practicesSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 20
No fabricated citations: Every cited work must resolve to a verifiable
- Distinctive: line 21
No claim without provenance: Every quantitative or factual claim
- Distinctive: line 22
No silent failure: Every script invocation, API call, or tool use must declare its exit status and what to do on non-zero.
- Very specific: line 184
Write format mismatch: If you parsed with "fastq-illumina" and wrote with "fastq", Biopython re-encodes qualities.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- metadata:
category: bioinformatics-sequence
oversight: low
version: 1.0.0
author: Pradyumna Jayaram
tags: [bioinformatics-sequence, research]
difficulty: intermediate
-->Read and Write Sequence Files
Hard rules
- No fabricated citations. Every cited work must resolve to a verifiable
- No claim without provenance. Every quantitative or factual claim
- No silent failure. Every script invocation, API call, or tool use must declare its exit status and what to do on non-zero. A skill that silently swallows errors is a violation.
When to use
- Streaming reads from FASTA/FASTQ/GenBank/EMBL.
- Random access to a record by ID (huge files).
- Writing records back out, optionally after modification.
- Format conversion without touching record content.
When NOT to use
- BAM/SAM/CRAM/VCF → use
pysam(seeors-bioinformatics-sequence-pysam-genomics). - gzipped BAM/CRAM with random access →
pysam.AlignmentFile. - For >10 GB files, consider
pyfastx(faster than Biopython for FASTA).
Prerequisites
biopython>=1.83- For indexed random access on BGZF FASTA, Biopython 1.83+ supports
index()on.bgz.
Format strings (cheat sheet)
| Format | String | Notes |
|--------|--------|-------|"
| FASTA | "fasta" | Sequence only, single-line or wrapped |
| FASTQ (Sanger / Illumina 1.8+) | "fastq" | Phred+33 |
| FASTQ (Illumina 1.3-1.7) | "fastq-illumina" | Phred+64 |
| FASTQ (Solexa) | "fastq-solexa" | Solexa+64 |
| GenBank | "genbank" | Annotation + sequence |
| EMBL | "embl" | EBI submission format |
| SwissProt | "swiss" | UniProt curated |
| UniProt XML | "uniprot-xml" | EBI download |
| GFF3 | "gff3" | Genome features, not sequence records |
| GTF | "gtf" | Gene transfer format |
| ABI | "abi" | Sanger trace |
| Phylip | "phylip" | Alignment |
| Clustal | "clustal" | Alignment |
| Stockholm | "stockholm" | Pfam/Rfam |
| Tab-delimited | "tab" | ID, seq, optional qualifiers |
Code patterns
Stream parse
from Bio import SeqIO
for rec in SeqIO.parse("input.fasta", "fasta"):
# rec.id, rec.description, rec.seq
...List parse (small files only)
records = list(SeqIO.parse("small.fasta", "fasta"))Indexed random access (huge FASTA)
from Bio import SeqIO
db = SeqIO.index("large.fasta", "fasta")
seq = db["target_id"].seq
db.close()For persistent index (no rebuild on next open):
db = SeqIO.index_db("large.idx", "large.fasta", "fasta")Indexed BGZF random access
db = SeqIO.index("indexable.fasta.bgz", "fasta")Write records (single file, multiple records)
from Bio import SeqIO
SeqIO.write(records, "out.fasta", "fasta")The return value is the number of records written.
Write one record at a time
from Bio import SeqIO
from Bio.SeqRecord import SeqRecord
from Bio.Seq import Seq
with open("out.fasta", "w") as fh:
rec = SeqRecord(Seq("ACGT"), id="seq1", description="example")
SeqIO.write(rec, fh, "fasta")Append records across formats (streaming)
from Bio import SeqIO
def stream_to_fasta(in_path, in_fmt, out_path):
with open(out_path, "w") as out:
for rec in SeqIO.parse(in_path, in_fmt):
# modify rec if needed
SeqIO.write(rec, out, "fasta")Convert without touching records
from Bio import SeqIO
n = SeqIO.convert("in.gb", "genbank", "out.fasta", "fasta")
print(f"Converted {n} records")Handle FASTA with wrapped multi-line sequences
Biopython auto-handles wrapped FASTA in parse(); record.seq is always the full sequence.
Parse GenBank with features
from Bio import SeqIO
for rec in SeqIO.parse("annotation.gb", "genbank"):
for feat in rec.features:
if feat.type == "CDS":
gene = feat.qualifiers.get("gene", ["?"])[0]
print(gene, feat.location)Parse BLAST tab output
from Bio import SeqIO
for qresult in SeqIO.parse("blast.tab", "blast-tab"):
for hsp in qresult:
...blast-tab parses the tabular -outfmt 6.
Truncate IDs to first whitespace
def short_id(rec):
rec.id = rec.id.split()[0]
rec.description = ""
return recCommon pitfalls
- Mixing parse() with index() and forgetting to close the index. Index files hold file handles; use a context manager or explicit
close(). - Indexed access on a
.fasta.gz(plain gzip) fails. Convert to BGZF first. - Write format mismatch. If you parsed with
"fastq-illumina"and wrote with"fastq", Biopython re-encodes qualities. Usually fine, but worth being explicit. - Mismatched record count from
SeqIO.convert. Returns 0 silently if source format is wrong.assert n > 0. - Header pollution. FASTA identifiers stop at first whitespace; multi-word descriptions go into
description. If you write a record with bothid="seq1 chr1"and a description, downstream tools will seeseq1as the ID.
Validation
n_records_in == n_records_outfor round-trips.- For indexed access:
db["known_id"].seq == expected_seq. - For GenBank round-trips:
len(features_in) == len(features_out), modulo per-format feature filtering.
Open alternatives
| Need | Tool |
| Faster FASTA parsing | pyfastx |
| Format conversion at scale | seqkit convert, bioawk |
| Random access to huge FASTA | samtools faidx + bgzip |
| GFF/GTF parsing | gffutils, pyranges |
References
- Biopython SeqIO: https://biopython.org/docs/latest/api/Bio.SeqIO.html
- Format list: https://biopython.org/wiki/SeqIO#File_Formats
- Companion:
ors-bioinformatics-sequence-format-conversion,ors-bioinformatics-sequence-compressed-sequence-files.
Changelog
- 1.0.0 (2026-06-10): Initial adaptation by Pradyumna Jayaram from
bio-read-sequencesandbio-write-sequences(bioSkills-main/sequence-io/).
Cross-references
Other skills in this category:
- batch-processing
- bowtie2-alignment
- bwa-alignment
- bwa-mem2-alignment
- codon-usage
- compressed-sequence-files
- fastq-quality-scores
- filter-sequences
- format-conversion
- hisat2-alignment
- motif-search
- paired-end-fastq
- pysam-genomics
- reverse-complement
- sam-bam-basics
- samtools-bam-processing
- seq-objects
- sequence-properties
- sequence-slicing
- sequence-statistics
- star-alignment
- transcription-translation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

