一键导入
compressed-sequence-files
Read and write gzip, bzip2, and BGZF-compressed FASTA/FASTQ using Python stdlib and Biopython — including indexable BGZF.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Read and write gzip, bzip2, and BGZF-compressed FASTA/FASTQ using Python stdlib and Biopython — including indexable BGZF.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Pass work between ORS skills with a Material Passport — a structured JSON envelope that captures inputs, outputs, decisions, and provenance so a downstream skill can resume without re-deriving context. Use when one skill produces output that another skill must consume, especially across category boundaries (e.g. analysis → writing, sequencing → statistics).
Discover and maintain `## Cross-references` between ORS skills. Given a new or edited skill, suggest related skills (same category, shared tags, complementary workflows). Verify all xref slugs resolve to existing SKILL.md files. Use when adding a new skill, when sibling skills move, or when an audit reveals dangling xrefs.
7-mode AI failure-mode checklist applied before publishing any ORS artifact (skill, manuscript section, dataset card, agent output). Catches: fabricated citations, silent failures, scope creep, missing provenance, unsupervised writes, version drift, hallucinated APIs. Use as the final pass before any 'publish', 'release', 'merge', or 'finalize' action.
Version, changelog, and marketplace workflow for ORS skills. Semver discipline, breaking-change protocol, marketplace.json update, README refresh, and the v0.X.Y → v1.0.0 graduation criteria. Use when bumping a skill version, publishing a release, or upgrading the ORS package version.
Author a new ORS skill from scratch using the v0.4.0 schema. Produces a valid SKILL.md (frontmatter + metadata + sections) following spec/skill-format.md, guided by spec/author-guide.md, validated by scripts/validate-skills.py. Use when a user says 'add a new skill', 'create a skill for X', or 'I want to contribute a skill'.
Process many FASTA/FASTQ/GenBank files in batch — merge, split, convert, summarize, organize — using Biopython 1.83+.
| name | compressed-sequence-files |
| description | Read and write gzip, bzip2, and BGZF-compressed FASTA/FASTQ using Python stdlib and Biopython — including indexable BGZF. |
| license | MIT |
.fasta.gz, .fastq.gz, .fasta.bz2 in Python."
SeqIO.parse(path, "fasta") directly.pysam (see ors-bioinformatics-sequence-pysam-genomics).samtools faidx + bgzip, not Biopython.biopython>=1.83 (ships Bio.bgzf).htslib ≥ 1.19 (bgzip + tabix).bz2.'rt' / 'wt'). The parser expects text. 'rb' will trip on a bytes-vs-str TypeError..gz → archive only, not indexable..bz2 → smaller but slower; archive only..bgz → indexable via SeqIO.index(); native for BAM/VCF/tabix.htslib bgzip — its blocks are HTSlib-compatible; Biopython's BGZF works but is slower on huge files.import gzip
from Bio import SeqIO
with gzip.open("sequences.fasta.gz", "rt") as fh:
for rec in SeqIO.parse(fh, "fasta"):
print(rec.id, len(rec.seq))
import bz2
from Bio import SeqIO
with bz2.open("reads.fastq.bz2", "rt") as fh:
recs = list(SeqIO.parse(fh, "fastq"))
import gzip
from Bio import SeqIO
with gzip.open("clean.fasta.gz", "wt") as out:
SeqIO.write(records, out, "fasta")
bgzf.openfrom Bio import SeqIO, bgzf
# Either works
for rec in SeqIO.parse("seqs.fasta.bgz", "fasta"):
...
with bgzf.open("seqs.fasta.bgz", "rt") as fh:
for rec in SeqIO.parse(fh, "fasta"):
...
from Bio import SeqIO, bgzf
with bgzf.open("indexable.fasta.bgz", "wt") as out:
SeqIO.write(SeqIO.parse("raw.fasta", "fasta"), out, "fasta")
from Bio import SeqIO
db = SeqIO.index("seqs.fasta.bgz", "fasta")
print(db["target_id"].seq)
db.close()
# Or persistent on-disk index for huge files
db = SeqIO.index_db("seqs.idx", "seqs.fasta.bgz", "fasta")
from pathlib import Path
import gzip, bz2
from Bio import SeqIO, bgzf
def open_seq(path: str, fmt: str):
p = Path(path)
sfx = "".join(p.suffixes).lower()
if sfx.endswith(".bgz") or sfx.endswith(".bgzf"):
fh = bgzf.open(p, "rt")
elif sfx.endswith(".gz") or sfx.endswith(".bgzf"):
fh = gzip.open(p, "rt")
elif sfx.endswith(".bz2"):
fh = bz2.open(p, "rt")
else:
fh = open(p, "r")
return SeqIO.parse(fh, fmt)
import gzip
from Bio import SeqIO, bgzf
with gzip.open("input.fasta.gz", "rt") as src, \
bgzf.open("indexable.fasta.bgz", "wt") as dst:
SeqIO.write(SeqIO.parse(src, "fasta"), dst, "fasta")
import gzip
from Bio.SeqIO.FastaIO import SimpleFastaParser
with gzip.open("sequences.fasta.gz", "rt") as fh:
n = sum(1 for _ in SimpleFastaParser(fh))
print(f"{n} sequences")
'rb' instead of 'rt'. You'll get TypeError: a bytes-like object is required, not 'str'.SeqIO.index() to work on plain .gz. It does not — convert to BGZF first.htslib bgzip blocks. They are wire-compatible for FASTA, but for .vcf.gz/.bcf use htslib bgzip end-to-end to avoid rare edge cases..bz2 is slow. For long-term archives, yes; for active work, prefer BGZF.gzip → 1f 8b, bzip2 → 42 5a, BGZF → 1f 8b 08 04 (with extra fields).SeqIO.index("out.bgz", "fasta")["known_id"] returns the same record.bgzf open → gzip open byte counts differ only by BGZF block overhead.| Need | Open tool | Why |
|---|---|---|
| Indexable compressed FASTA | htslib bgzip (≥ 1.19) | BAM/VCF-compatible blocks |
Fast stats on .fasta.gz | seqkit stats -j 8 *.fasta.gz | Much faster than Python |
| Random access by region | samtools faidx regions.fa.gz + bgzip | Standard, battle-tested |
| BGZF block dump | bgzip -b 0 -d out.fa.gz | Inspect block boundaries |
ors-bioinformatics-sequence-pysam-genomics, ors-bioinformatics-sequence-samtools-bam-processing.bio-compressed-files (bioSkills-main/sequence-io/compressed-files).Other skills in this category: