[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7ECBFVF4DNNVXVMTBD53WJE":3,"skill-same:01M7ECBFVF4DNNVXVMTBD53WJE":62},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":30,"commitSha":31,"skillDirectory":32,"forksCount":14,"repositoryHtmlUrl":33,"repositoryHomepageUrl":33,"ownerHtmlUrl":34,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":35,"install":36,"resources":49},"01M7ECBFVF4DNNVXVMTBD53WJE","bio-compressed-files",null,"Read, write, and index compressed sequence files (gzip, bzip2, xz, BGZF) with Biopython and bgzip\u002Fsamtools. Use when working with .gz, .bz2, or .bgz sequence files, when random access into a compressed FASTA\u002FFASTQ is needed, or when SeqIO.index\u002Ffaidx\u002Ftabix rejects a plain .gz. Covers the BGZF-vs-gzip seekability asymmetry, the 'rt'-not-'rb' handle trap, virtual offsets, and gzip-to-BGZF conversion.","Mr-Nobody-Anonymous\u002FAll-skills","Mr-Nobody-Anonymous","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184253119?v=4","01M7AEXFJHKTYQW5R0ZCQQTWFV","anonymous","01M7C00M3GQR4QKP9GZA42GFAK",0,"MIT","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-compressed-files\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: bio-compressed-files\ndescription: Read, write, and index compressed sequence files (gzip, bzip2, xz, BGZF) with Biopython and bgzip\u002Fsamtools. Use when working with .gz, .bz2, or .bgz sequence files, when random access into a compressed FASTA\u002FFASTQ is needed, or when SeqIO.index\u002Ffaidx\u002Ftabix rejects a plain .gz. Covers the BGZF-vs-gzip seekability asymmetry, the 'rt'-not-'rb' handle trap, virtual offsets, and gzip-to-BGZF conversion.\ntool_type: mixed\nprimary_tool: Bio.bgzf\nsource: \"https:\u002F\u002Fgithub.com\u002FGPTomics\u002FbioSkills\"\nsource_repository: \"GPTomics\u002FbioSkills\"\nsource_path: \"sequence-io\u002Fcompressed-files\u002FSKILL.md\"\nlicense: \"MIT\"\nimported_at: \"2026-09-20\"\n---\n\n## Version Compatibility\n\nReference examples tested with: BioPython 1.83+, htslib\u002Fbgzip 1.19+, samtools 1.19+\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- Python: `pip show \u003Cpackage>` then `help(module.function)` to check signatures\n- CLI: `\u003Ctool> --version` then `\u003Ctool> --help` to confirm flags\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed\npackage and adapt the example to match the actual API rather than retrying.\n\n# Compressed Files\n\nRead, write, and randomly access gzip, bzip2, xz, and BGZF compressed sequence files.\n\n**\"Read a compressed sequence file\"** -> Open a decompression handle in TEXT mode, then parse with the standard SeqIO interface.\n- gzip: `gzip.open(path, 'rt')` (Python stdlib)\n- bzip2: `bz2.open(path, 'rt')` (Python stdlib)\n- xz\u002FLZMA: `lzma.open(path, 'rt')` (Python stdlib)\n- BGZF: `bgzf.open(path, 'rt')` (BioPython) - BGZF input ONLY\n\n**\"Make a compressed file randomly accessible\"** -> Re-compress as BGZF, then index. Only BGZF supports `SeqIO.index()`, `samtools faidx`, and `tabix` on compressed data.\n\n## The Governing Principle: BGZF vs plain gzip is asymmetric\n\nA BGZF (Blocked GNU Zip) file IS a valid gzip file - `gunzip` and `zcat` read it transparently. The reverse is FALSE: a plain `.gz` is NOT BGZF, so `faidx`\u002F`tabix`\u002F`SeqIO.index` reject it, and `bgzf.open` refuses to read it.\n\nThe reason is structural. BGZF is a series of concatenated gzip blocks, each \u003C=64 KiB and independently decodable, so any record can be reached by seeking to its block. Plain gzip is one continuous DEFLATE stream with no block boundaries: reaching byte N means decompressing every byte before it (O(n)). Random access therefore REQUIRES BGZF; on a plain `.gz`, `SeqIO.index()` would re-decompress huge prefixes on every lookup, which is why Biopython forbids it outright (it raises rather than running slowly).\n\nConsequences the agent must respect:\n- Reading sequentially: gzip, bzip2, xz, and BGZF all work via the matching `*.open(path, 'rt')` handle.\n- Random access \u002F indexing: BGZF only. Convert plain gzip to BGZF first.\n- `bgzf.open()` reads BGZF input only. Pointing it at a plain `.gz` raises `ValueError: A BGZF block should start with b'\\x1f\\x8b\\x08\\x04'...`. To read plain gzip use `gzip.open()`.\n- BAM and tabix-indexed files use BGZF natively; bzip2\u002Fxz are archive-only (no seekable index).\n\n## Required Imports\n\n```python\nimport gzip\nimport bz2\nimport lzma\nfrom Bio import SeqIO\nfrom Bio import bgzf\n```\n\n## Reading Compressed Files\n\n**Goal:** Parse sequence records from a compressed file without decompressing to disk.\n\n**Approach:** Open a decompression handle in TEXT mode (`'rt'`), then pass the handle to `SeqIO.parse()`. The parser is format-agnostic about the underlying compression.\n\n```python\nwith gzip.open('reads.fastq.gz', 'rt') as handle:\n    for record in SeqIO.parse(handle, 'fastq'):\n        print(record.id, len(record.seq))\n```\n\nSwap `gzip.open` for `bz2.open` (`.bz2`), `lzma.open` (`.xz`), or `bgzf.open` (`.bgz`) - the parse loop is identical.\n\n### The 'rt' vs 'rb' trap\n\n`SeqIO.parse()` in Python 3 needs a TEXT handle that yields `str`. A binary `'rb'` handle yields `bytes` and raises `TypeError: a bytes-like object is required` (or a decode error). Always use `'rt'` for reading and `'wt'` for writing through `SeqIO`. The low-level `SimpleFastaParser`\u002F`FastqGeneralIterator` also require text handles.\n\n## Writing Compressed Files\n\n**Goal:** Save records straight to a compressed file with no intermediate plain copy.\n\n**Approach:** Open a compression handle in TEXT mode (`'wt'`), then pass it to `SeqIO.write()`.\n\n```python\nwith gzip.open('output.fasta.gz', 'wt') as handle:\n    SeqIO.write(records, handle, 'fasta')\n```\n\nFor an indexable result write BGZF instead:\n\n```python\nwith bgzf.open('output.fasta.bgz', 'wt') as handle:\n    SeqIO.write(records, handle, 'fasta')\n```\n\n`BgzfWriter.close()` (and the `with` block exit) automatically appends the 28-byte empty-block EOF marker that htslib tools check for; let the context manager close the handle.\n\n## Random Access: index a BGZF file\n\n**Goal:** Pull individual records by id from a large compressed file without a linear scan.\n\n**Approach:** Compress as BGZF, then build a Biopython offset index. `SeqIO.index()` keeps virtual offsets in RAM; `SeqIO.index_db()` stores them in an on-disk SQLite index that persists across sessions and spans multiple files.\n\n```python\nrecords = SeqIO.index('sequences.fasta.bgz', 'fasta')\ntarget = records['gene_042'].seq\nrecords.close()\n\n# Persistent, multi-file, scales beyond RAM:\ndb = SeqIO.index_db('idx.sqlite', ['a.fasta.bgz', 'b.fasta.bgz'], 'fasta')\n```\n\n`SeqIO.index()` on a plain `.gz` raises `ValueError: Gzipped files are not suitable for indexing, please use BGZF (blocked gzip format) instead.` Convert first (below).\n\n## Convert plain gzip to BGZF\n\n**\"Convert gzip to an indexable format\"** -> Decompress the gzip stream and re-compress it as BGZF.\n\nCLI (fastest, htslib-native):\n\n```bash\n# Either decompress then bgzip in place...\ngzip -d sequences.fasta.gz && bgzip sequences.fasta      # -> sequences.fasta.gz (now BGZF)\n# ...or stream without touching disk:\nzcat sequences.fasta.gz | bgzip -@ 4 > sequences.fasta.bgz\n\n# Index a BGZF FASTA for region extraction:\nsamtools faidx sequences.fasta.bgz                        # writes BOTH .fai and .gzi\nsamtools faidx sequences.fasta.bgz gene_042:1-200\n```\n\n`samtools faidx` on a BGZF FASTA writes TWO index files: `.fai` (record offsets in uncompressed coordinates) AND `.gzi` (the compressed-to-uncompressed block map). Deleting `.gzi` breaks region extraction even though `.fai` survives. Note that bgzip keeps the `.gz` extension, so a `.gz` may be EITHER plain gzip or BGZF - check with `bgzip -t file.gz` (tests for a valid BGZF stream) rather than trusting the suffix.\n\nPure-Python equivalent (no external tools):\n\n```python\nimport gzip\nfrom Bio import SeqIO, bgzf\n\nwith gzip.open('input.fasta.gz', 'rt') as in_handle:\n    with bgzf.open('output.fasta.bgz', 'wt') as out_handle:\n        SeqIO.write(SeqIO.parse(in_handle, 'fasta'), out_handle, 'fasta')\n```\n\n## Bio.bgzf API and virtual offsets\n\n`Bio.bgzf` exports `open`, `BgzfReader`, `BgzfWriter`, `make_virtual_offset`, `split_virtual_offset`.\n\nA virtual offset packs two coordinates into one 64-bit integer: `voffset = coffset \u003C\u003C 16 | uoffset`, where `coffset` is the byte position of the block start in the compressed file (top 48 bits) and `uoffset` is the offset within that block's decompressed data (low 16 bits - 16 bits suffices because a block holds at most 64 KiB).\n\n```python\nvo = bgzf.make_virtual_offset(100, 7)        # 6553607\ncoffset, uoffset = bgzf.split_virtual_offset(vo)   # (100, 7)\n\nwith bgzf.open('sequences.fasta.bgz', 'rt') as handle:\n    handle.readline()\n    saved = handle.tell()        # a VIRTUAL offset, not a byte position\n    handle.seek(saved)           # jumps back to the same record\n```\n\nCritical caveat: virtual offsets may be COMPARED for ordering but NEVER SUBTRACTED to get a byte length - they live in two coordinate spaces (compressed position and within-block position), so `vo2 - vo1` is meaningless. `BgzfReader.tell()` returns a virtual offset; `seek()` consumes one. Text mode forces `latin1` and does no newline translation.\n\n## Compression Format Comparison\n\n| Format | Extension | Random access | Speed | Ratio | Stdlib handle |\n|--------|-----------|---------------|-------|-------|---------------|\n| gzip | `.gz` | No (O(n) seek) | Fast | Good | `gzip.open` |\n| BGZF | `.bgz` \u002F `.gz` | **Yes (block-seekable)** | Fast, threadable | Good | `bgzf.open` (BioPython) |\n| bzip2 | `.bz2` | No | Slow | Better | `bz2.open` |\n| xz \u002F LZMA | `.xz` | No | Slowest | Best | `lzma.open` |\n\n## When to Use Each Format\n\n| Use case | Format | Why |\n|----------|--------|-----|\n| Sequential read\u002Fwrite, sharing | gzip | Universal, fast, every tool reads it |\n| Need `faidx`\u002F`tabix`\u002F`SeqIO.index` | **BGZF** | Only seekable compressed format |\n| BAM, tabix-indexed VCF\u002FGFF\u002FBED | BGZF | Required natively |\n| Cold archive, max shrink, no random access | xz then bzip2 | Highest ratios, slowest |\n| Random access into an existing plain `.gz` without re-bgzipping | pyfastx | Adds a seek-point index over the gzip stream |\n\n`pyfastx` is the exception that gives random access into a PLAIN gzip FASTA\u002FFASTQ: it builds a seek-point index (via `zran` from indexed_gzip) plus a SQLite `.fxi`\u002F`.fqi` index alongside the file, a different strategy from faidx (which requires the stream itself to be BGZF). Use it when re-compressing a large gzipped genome to BGZF is not an option.\n\n## Common Errors\n\n| Symptom | Cause | Fix |\n|---------|-------|-----|\n| `TypeError: a bytes-like object is required` | Handle opened `'rb'` instead of `'rt'` | Open compressed handles with `'rt'`\u002F`'wt'` for SeqIO |\n| `ValueError: Gzipped files are not suitable for indexing, please use BGZF...` | `SeqIO.index()` on a plain `.gz` | Re-compress as BGZF (`zcat ... | bgzip`), then index |\n| `ValueError: A BGZF block should start with b'\\x1f\\x8b\\x08\\x04'...` | `bgzf.open()` pointed at a plain gzip file | Read plain gzip with `gzip.open()`; reserve `bgzf.open` for BGZF |\n| `[bgzf] file ... not BGZF` \u002F `not compressed with bgzip` (htslib) | faidx\u002Ftabix given a plain `.gz` | Convert to BGZF first |\n| `[faidx] Failed to read ... \u002F could not load .gzi` | `.gzi` deleted next to a BGZF FASTA | Re-run `samtools faidx` to regenerate `.fai` + `.gzi` |\n| `gzip.BadGzipFile` \u002F `OSError: Not a gzipped file` | File is not gzip (wrong suffix \u002F corrupt) | Verify with `bgzip -t` or `file`; match handle to real format |\n| `UnicodeDecodeError` | Non-UTF8 bytes in a text handle | `gzip.open(path, 'rt', encoding='latin-1')` |\n\n## Related Skills\n\n- read-sequences - parse vs index vs index_db trade-offs for compressed handles\n- write-sequences - write records through a compression handle\n- batch-processing - stream many compressed files without loading them into RAM\n- filter-sequences - keep R1\u002FR2 in sync when filtering gzipped paired reads\n- alignment-files\u002Fsam-bam-basics - BAM is BGZF natively; samtools manages the compression\n\n## References\n\n- Li H, Handsaker B, Wysoker A, et al. The Sequence Alignment\u002FMap format and SAMtools. Bioinformatics. 2009;25(16):2078-2079. (Defines BGZF in the SAM\u002FBAM specification.)\n- Bonfield JK. CRAM 3.1: advances in the CRAM file format. Bioinformatics. 2022;38(6):1497. (Per-column block compression beyond BGZF.)\n- Du L, Liu Q, Fan Z, et al. Pyfastx: a robust Python package for fast random access to sequences from plain and gzipped FASTA\u002FQ files. Briefings in Bioinformatics. 2021;22(4):bbaa368.\n","## Version Compatibility\n\nReference examples tested with: BioPython 1.83+, htslib\u002Fbgzip 1.19+, samtools 1.19+\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- Python: `pip show \u003Cpackage>` then `help(module.function)` to check signatures\n- CLI: `\u003Ctool> --version` then `\u003Ctool> --help` to confirm flags\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed\npackage and adapt the example to match the actual API rather than retrying.\n\n# Compressed Files\n\nRead, write, and randomly access gzip, bzip2, xz, and BGZF compressed sequence files.\n\n**\"Read a compressed sequence file\"** -> Open a decompression handle in TEXT mode, then parse with the standard SeqIO interface.\n- gzip: `gzip.open(path, 'rt')` (Python stdlib)\n- bzip2: `bz2.open(path, 'rt')` (Python stdlib)\n- xz\u002FLZMA: `lzma.open(path, 'rt')` (Python stdlib)\n- BGZF: `bgzf.open(path, 'rt')` (BioPython) - BGZF input ONLY\n\n**\"Make a compressed file randomly accessible\"** -> Re-compress as BGZF, then index. Only BGZF supports `SeqIO.index()`, `samtools faidx`, and `tabix` on compressed data.\n\n## The Governing Principle: BGZF vs plain gzip is asymmetric\n\nA BGZF (Blocked GNU Zip) file IS a valid gzip file - `gunzip` and `zcat` read it transparently. The reverse is FALSE: a plain `.gz` is NOT BGZF, so `faidx`\u002F`tabix`\u002F`SeqIO.index` reject it, and `bgzf.open` refuses to read it.\n\nThe reason is structural. BGZF is a series of concatenated gzip blocks, each \u003C=64 KiB and independently decodable, so any record can be reached by seeking to its block. Plain gzip is one continuous DEFLATE stream with no block boundaries: reaching byte N means decompressing every byte before it (O(n)). Random access therefore REQUIRES BGZF; on a plain `.gz`, `SeqIO.index()` would re-decompress huge prefixes on every lookup, which is why Biopython forbids it outright (it raises rather than running slowly).\n\nConsequences the agent must respect:\n- Reading sequentially: gzip, bzip2, xz, and BGZF all work via the matching `*.open(path, 'rt')` handle.\n- Random access \u002F indexing: BGZF only. Convert plain gzip to BGZF first.\n- `bgzf.open()` reads BGZF input only. Pointing it at a plain `.gz` raises `ValueError: A BGZF block should start with b'\\x1f\\x8b\\x08\\x04'...`. To read plain gzip use `gzip.open()`.\n- BAM and tabix-indexed files use BGZF natively; bzip2\u002Fxz are archive-only (no seekable index).\n\n## Required Imports\n\n```python\nimport gzip\nimport bz2\nimport lzma\nfrom Bio import SeqIO\nfrom Bio import bgzf\n```\n\n## Reading Compressed Files\n\n**Goal:** Parse sequence records from a compressed file without decompressing to disk.\n\n**Approach:** Open a decompression handle in TEXT mode (`'rt'`), then pass the handle to `SeqIO.parse()`. The parser is format-agnostic about the underlying compression.\n\n```python\nwith gzip.open('reads.fastq.gz', 'rt') as handle:\n    for record in SeqIO.parse(handle, 'fastq'):\n        print(record.id, len(record.seq))\n```\n\nSwap `gzip.open` for `bz2.open` (`.bz2`), `lzma.open` (`.xz`), or `bgzf.open` (`.bgz`) - the parse loop is identical.\n\n### The 'rt' vs 'rb' trap\n\n`SeqIO.parse()` in Python 3 needs a TEXT handle that yields `str`. A binary `'rb'` handle yields `bytes` and raises `TypeError: a bytes-like object is required` (or a decode error). Always use `'rt'` for reading and `'wt'` for writing through `SeqIO`. The low-level `SimpleFastaParser`\u002F`FastqGeneralIterator` also require text handles.\n\n## Writing Compressed Files\n\n**Goal:** Save records straight to a compressed file with no intermediate plain copy.\n\n**Approach:** Open a compression handle in TEXT mode (`'wt'`), then pass it to `SeqIO.write()`.\n\n```python\nwith gzip.open('output.fasta.gz', 'wt') as handle:\n    SeqIO.write(records, handle, 'fasta')\n```\n\nFor an indexable result write BGZF instead:\n\n```python\nwith bgzf.open('output.fasta.bgz', 'wt') as handle:\n    SeqIO.write(records, handle, 'fasta')\n```\n\n`BgzfWriter.close()` (and the `with` block exit) automatically appends the 28-byte empty-block EOF marker that htslib tools check for; let the context manager close the handle.\n\n## Random Access: index a BGZF file\n\n**Goal:** Pull individual records by id from a large compressed file without a linear scan.\n\n**Approach:** Compress as BGZF, then build a Biopython offset index. `SeqIO.index()` keeps virtual offsets in RAM; `SeqIO.index_db()` stores them in an on-disk SQLite index that persists across sessions and spans multiple files.\n\n```python\nrecords = SeqIO.index('sequences.fasta.bgz', 'fasta')\ntarget = records['gene_042'].seq\nrecords.close()\n\n# Persistent, multi-file, scales beyond RAM:\ndb = SeqIO.index_db('idx.sqlite', ['a.fasta.bgz', 'b.fasta.bgz'], 'fasta')\n```\n\n`SeqIO.index()` on a plain `.gz` raises `ValueError: Gzipped files are not suitable for indexing, please use BGZF (blocked gzip format) instead.` Convert first (below).\n\n## Convert plain gzip to BGZF\n\n**\"Convert gzip to an indexable format\"** -> Decompress the gzip stream and re-compress it as BGZF.\n\nCLI (fastest, htslib-native):\n\n```bash\n# Either decompress then bgzip in place...\ngzip -d sequences.fasta.gz && bgzip sequences.fasta      # -> sequences.fasta.gz (now BGZF)\n# ...or stream without touching disk:\nzcat sequences.fasta.gz | bgzip -@ 4 > sequences.fasta.bgz\n\n# Index a BGZF FASTA for region extraction:\nsamtools faidx sequences.fasta.bgz                        # writes BOTH .fai and .gzi\nsamtools faidx sequences.fasta.bgz gene_042:1-200\n```\n\n`samtools faidx` on a BGZF FASTA writes TWO index files: `.fai` (record offsets in uncompressed coordinates) AND `.gzi` (the compressed-to-uncompressed block map). Deleting `.gzi` breaks region extraction even though `.fai` survives. Note that bgzip keeps the `.gz` extension, so a `.gz` may be EITHER plain gzip or BGZF - check with `bgzip -t file.gz` (tests for a valid BGZF stream) rather than trusting the suffix.\n\nPure-Python equivalent (no external tools):\n\n```python\nimport gzip\nfrom Bio import SeqIO, bgzf\n\nwith gzip.open('input.fasta.gz', 'rt') as in_handle:\n    with bgzf.open('output.fasta.bgz', 'wt') as out_handle:\n        SeqIO.write(SeqIO.parse(in_handle, 'fasta'), out_handle, 'fasta')\n```\n\n## Bio.bgzf API and virtual offsets\n\n`Bio.bgzf` exports `open`, `BgzfReader`, `BgzfWriter`, `make_virtual_offset`, `split_virtual_offset`.\n\nA virtual offset packs two coordinates into one 64-bit integer: `voffset = coffset \u003C\u003C 16 | uoffset`, where `coffset` is the byte position of the block start in the compressed file (top 48 bits) and `uoffset` is the offset within that block's decompressed data (low 16 bits - 16 bits suffices because a block holds at most 64 KiB).\n\n```python\nvo = bgzf.make_virtual_offset(100, 7)        # 6553607\ncoffset, uoffset = bgzf.split_virtual_offset(vo)   # (100, 7)\n\nwith bgzf.open('sequences.fasta.bgz', 'rt') as handle:\n    handle.readline()\n    saved = handle.tell()        # a VIRTUAL offset, not a byte position\n    handle.seek(saved)           # jumps back to the same record\n```\n\nCritical caveat: virtual offsets may be COMPARED for ordering but NEVER SUBTRACTED to get a byte length - they live in two coordinate spaces (compressed position and within-block position), so `vo2 - vo1` is meaningless. `BgzfReader.tell()` returns a virtual offset; `seek()` consumes one. Text mode forces `latin1` and does no newline translation.\n\n## Compression Format Comparison\n\n| Format | Extension | Random access | Speed | Ratio | Stdlib handle |\n|--------|-----------|---------------|-------|-------|---------------|\n| gzip | `.gz` | No (O(n) seek) | Fast | Good | `gzip.open` |\n| BGZF | `.bgz` \u002F `.gz` | **Yes (block-seekable)** | Fast, threadable | Good | `bgzf.open` (BioPython) |\n| bzip2 | `.bz2` | No | Slow | Better | `bz2.open` |\n| xz \u002F LZMA | `.xz` | No | Slowest | Best | `lzma.open` |\n\n## When to Use Each Format\n\n| Use case | Format | Why |\n|----------|--------|-----|\n| Sequential read\u002Fwrite, sharing | gzip | Universal, fast, every tool reads it |\n| Need `faidx`\u002F`tabix`\u002F`SeqIO.index` | **BGZF** | Only seekable compressed format |\n| BAM, tabix-indexed VCF\u002FGFF\u002FBED | BGZF | Required natively |\n| Cold archive, max shrink, no random access | xz then bzip2 | Highest ratios, slowest |\n| Random access into an existing plain `.gz` without re-bgzipping | pyfastx | Adds a seek-point index over the gzip stream |\n\n`pyfastx` is the exception that gives random access into a PLAIN gzip FASTA\u002FFASTQ: it builds a seek-point index (via `zran` from indexed_gzip) plus a SQLite `.fxi`\u002F`.fqi` index alongside the file, a different strategy from faidx (which requires the stream itself to be BGZF). Use it when re-compressing a large gzipped genome to BGZF is not an option.\n\n## Common Errors\n\n| Symptom | Cause | Fix |\n|---------|-------|-----|\n| `TypeError: a bytes-like object is required` | Handle opened `'rb'` instead of `'rt'` | Open compressed handles with `'rt'`\u002F`'wt'` for SeqIO |\n| `ValueError: Gzipped files are not suitable for indexing, please use BGZF...` | `SeqIO.index()` on a plain `.gz` | Re-compress as BGZF (`zcat ... | bgzip`), then index |\n| `ValueError: A BGZF block should start with b'\\x1f\\x8b\\x08\\x04'...` | `bgzf.open()` pointed at a plain gzip file | Read plain gzip with `gzip.open()`; reserve `bgzf.open` for BGZF |\n| `[bgzf] file ... not BGZF` \u002F `not compressed with bgzip` (htslib) | faidx\u002Ftabix given a plain `.gz` | Convert to BGZF first |\n| `[faidx] Failed to read ... \u002F could not load .gzi` | `.gzi` deleted next to a BGZF FASTA | Re-run `samtools faidx` to regenerate `.fai` + `.gzi` |\n| `gzip.BadGzipFile` \u002F `OSError: Not a gzipped file` | File is not gzip (wrong suffix \u002F corrupt) | Verify with `bgzip -t` or `file`; match handle to real format |\n| `UnicodeDecodeError` | Non-UTF8 bytes in a text handle | `gzip.open(path, 'rt', encoding='latin-1')` |\n\n## Related Skills\n\n- read-sequences - parse vs index vs index_db trade-offs for compressed handles\n- write-sequences - write records through a compression handle\n- batch-processing - stream many compressed files without loading them into RAM\n- filter-sequences - keep R1\u002FR2 in sync when filtering gzipped paired reads\n- alignment-files\u002Fsam-bam-basics - BAM is BGZF natively; samtools manages the compression\n\n## References\n\n- Li H, Handsaker B, Wysoker A, et al. The Sequence Alignment\u002FMap format and SAMtools. Bioinformatics. 2009;25(16):2078-2079. (Defines BGZF in the SAM\u002FBAM specification.)\n- Bonfield JK. CRAM 3.1: advances in the CRAM file format. Bioinformatics. 2022;38(6):1497. (Per-column block compression beyond BGZF.)\n- Du L, Liu Q, Fan Z, et al. Pyfastx: a robust Python package for fast random access to sequences from plain and gzipped FASTA\u002FQ files. Briefings in Bioinformatics. 2021;22(4):bbaa368.\n",{"name":5,"source":24,"license":15,"tool_type":25,"description":7,"imported_at":26,"source_path":27,"primary_tool":28,"source_repository":29},"https:\u002F\u002Fgithub.com\u002FGPTomics\u002FbioSkills","mixed","2026-09-20","sequence-io\u002Fcompressed-files\u002FSKILL.md","Bio.bgzf","GPTomics\u002FbioSkills","main","2d1750717747097b602acf30bd09a7cbd4b4c6ea","awesome_skills\u002Fbiology\u002Fbio-compressed-files","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous","2026-11-09 11:45:36",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-compressed-files",{"tool":42,"command":43},"bunx","bunx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-compressed-files",{"tool":45,"command":46},"pnpm","pnpm dlx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-compressed-files","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-compressed-files\u002FSKILL.md",true,[50,56],{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"examples\u002Fcompressed_io.py","SCRIPT","脚本",2839,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-compressed-files\u002Fexamples\u002Fcompressed_io.py",{"path":57,"resourceType":58,"resourceTypeDesc":59,"sizeBytes":60,"sourceHtmlUrl":61},"usage-guide.md","REFERENCE","参考文档",3578,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-compressed-files\u002Fusage-guide.md",[63,71,78,85,92,99],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":70},"01M7FFFZPC2025JQQHPHDX154J","dei-assessment","Assess diversity, equity, and inclusion with metrics. TRIGGERS - Use when user needs help with dei-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-assessment\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":70},"01M7FFFWN8H4WA7A6Y398QKB6J","dei-action-plan","Create DEI action plans with goals and initiatives. TRIGGERS - Use when user needs help with dei-action-plan related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-action-plan\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":70},"01M7FFFSHTM0QZRVZ2NRJTJ0PY","culture-fit-assessment","Design culture add assessment processes. TRIGGERS - Use when user needs help with culture-fit-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fculture-fit-assessment\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":70},"01M7FFFMA12RKEQA38KHJSXXPS","cowork-to-code-bridge","Use an already-installed, independently verified cowork-to-code bridge to run narrowly approved actions on the user's own macOS, Linux, or WSL2 machine through a local file queue.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcowork-to-code-bridge\u002FSKILL.md",[],[],{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":70},"01M7FFFH1F6M8YRGW5V487GH1K","counter-offer-response","Draft counter-offer responses for retention. TRIGGERS - Use when user needs help with counter-offer-response related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcounter-offer-response\u002FSKILL.md",[],[],{"skillNo":100,"name":101,"nameZh":6,"description":102,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":70},"01M7FFFDGEHV8Y7J9N40HZXW52","continuous-feedback-system","Design continuous feedback systems. TRIGGERS - Use when user needs help with continuous-feedback-system related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcontinuous-feedback-system\u002FSKILL.md",[],[]]