[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7ECQVDGJ4VGPEG82JMS72CC":3,"skill-same:01M7ECQVDGJ4VGPEG82JMS72CC":107},{"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":29,"commitSha":30,"skillDirectory":31,"forksCount":32,"repositoryHtmlUrl":33,"repositoryHomepageUrl":6,"ownerHtmlUrl":34,"ownerBlogUrl":6,"ownerDescription":35,"updatedAt":36,"install":37,"resources":50},"01M7ECQVDGJ4VGPEG82JMS72CC","pysam",null,"Python\u002FHTSlib workflows for genomic files. Use when reading, querying, filtering, or writing SAM\u002FBAM\u002FCRAM, VCF\u002FBCF, FASTA\u002FFASTQ, or tabix data with pysam, including pileup, coverage, indexing, and CRAM references.","sanjeevafk\u002Fagent-skills","sanjeevafk","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F230678117?v=4","01M7C540EFY46ETG1NNWKS5X3Q","Sanjeev","01M7C540F366J5C1D587BMKH9Q",0,"MIT","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: pysam\ndescription: Python\u002FHTSlib workflows for genomic files. Use when reading, querying, filtering, or writing SAM\u002FBAM\u002FCRAM, VCF\u002FBCF, FASTA\u002FFASTQ, or tabix data with pysam, including pileup, coverage, indexing, and CRAM references.\nlicense: MIT\nallowed-tools: Read Write Edit Bash\ncompatibility: Requires Python 3.8–3.14 and pysam 0.24.0. Bundled scripts use local files. CRAM decoding may require the matching reference FASTA or an explicitly configured REF_PATH\u002FREF_CACHE.\nmetadata:\n  version: \"2.0\"\n  skill-author: K-Dense Inc.\n---\n\n# pysam\n\n## Overview\n\nUse pysam for low-level, streaming access to HTSlib-supported genomic formats:\n\n- `AlignmentFile` and `AlignedSegment` for SAM\u002FBAM\u002FCRAM\n- `VariantFile`, `VariantHeader`, and `VariantRecord` for VCF\u002FBCF\n- `FastaFile` for indexed FASTA and `FastxFile` for sequential FASTA\u002FFASTQ\n- `TabixFile` for BGZF-compressed, tabix-indexed BED\u002FGFF\u002FGTF\u002Fcustom tables\n- `pysam.samtools` and `pysam.bcftools` for wrapped command dispatchers\n\nCurrent upstream baseline: **pysam 0.24.0** (27 April 2026), wrapping\nHTSlib\u002Fsamtools\u002Fbcftools 1.23.1. Read `references\u002Fsources.md` before updating\nversion-specific guidance.\n\n## Installation\n\nUse the pinned release for reproducible work:\n\n```bash\nuv pip install \"pysam==0.24.0\"\n```\n\nConfirm the runtime:\n\n```python\nimport pysam\n\nprint(pysam.__version__)           # 0.24.0\nprint(pysam.__samtools_version__)  # 1.23.1\n```\n\nPrebuilt wheels are available for supported macOS and Linux platforms. A\nsource build needs a C compiler and HTSlib build dependencies; read the\nofficial installation guide linked from `references\u002Fsources.md`.\n\n## First Decide\n\nBefore writing code:\n\n1. Identify the real format, compression, sort order, and available index.\n2. Decide whether coordinates are numeric Python coordinates or a region\n   string. Do not mix them.\n3. For CRAM, identify the exact reference assembly and FASTA.\n4. Prefer indexed region access; use sequential iteration only when intended.\n5. Preserve headers when writing and write to a new path by default.\n6. State filtering semantics: mapping\u002Fbase quality, flags, overlap handling,\n   duplicate handling, and pileup depth cap.\n\nFor unfamiliar files, start with the bundled read-only inspector:\n\n```bash\npython scripts\u002Finspect_hts.py sample.bam\npython scripts\u002Finspect_hts.py cohort.vcf.gz\npython scripts\u002Finspect_hts.py reference.fa\n```\n\n## Bundled Scripts\n\n| Script | Purpose | Typical call |\n|---|---|---|\n| `scripts\u002Finspect_hts.py` | Metadata-only inspection for alignment, variant, FASTA, FASTQ, and tabix files | `python scripts\u002Finspect_hts.py sample.cram --reference ref.fa` |\n| `scripts\u002Falignment_qc.py` | Streaming aggregate read\u002FQC counts as JSON | `python scripts\u002Falignment_qc.py sample.bam --max-records 100000` |\n| `scripts\u002Fvariant_summary.py` | Streaming variant, FILTER, and genotype summary as JSON | `python scripts\u002Fvariant_summary.py cohort.vcf.gz --region chr1:1-1000000` |\n| `scripts\u002Ffilter_alignments.py` | Filter SAM\u002FBAM\u002FCRAM without changing record order | `python scripts\u002Ffilter_alignments.py input.bam output.bam --exclude-secondary` |\n\nAll scripts refuse to overwrite existing outputs. Run each with `--help` for\ncoordinate, index, and privacy notes.\n\n## Coordinate Contract\n\n**Numeric coordinates accepted by pysam APIs are 0-based, half-open.** This\nincludes numeric `AlignmentFile.fetch()`, `VariantFile.fetch()`,\n`FastaFile.fetch()`, `TabixFile.fetch()`, and `pileup()` arguments.\n\n**Region strings are samtools-style: 1-based and inclusive.**\n\n```python\n# The same 100 bases:\nbam.fetch(\"chr1\", 99, 199)          # [99, 199)\nbam.fetch(region=\"chr1:100-199\")    # 1-based inclusive\n```\n\nVCF text uses 1-based `POS`, while record properties expose both systems:\n\n```python\nrecord.pos    # 1-based\nrecord.start  # 0-based inclusive\nrecord.stop   # 0-based exclusive\n```\n\nRead `references\u002Fcoordinates_and_indexing.md` for format conversions, overlap\nsemantics, index choices, and contig-name checks.\n\n## Alignment Files\n\nUse context managers and explicit modes:\n\n```python\nimport pysam\n\nwith pysam.AlignmentFile(\"sample.bam\", \"rb\", threads=4) as bam:\n    for read in bam.fetch(\"chr1\", 1_000, 2_000):\n        if (\n            not read.is_unmapped\n            and not read.is_secondary\n            and not read.is_supplementary\n            and read.mapping_quality >= 30\n        ):\n            print(read.query_name, read.reference_start, read.cigarstring)\n```\n\nUse `fetch(until_eof=True)` to stream every record in file order, including\nunplaced unmapped reads, without requiring an index:\n\n```python\nwith pysam.AlignmentFile(\"sample.bam\", \"rb\") as bam:\n    for read in bam.fetch(until_eof=True):\n        ...\n```\n\nImportant distinctions:\n\n- `fetch()` returns alignment records overlapping a region.\n- `count()` counts records and defaults to `read_callback=\"nofilter\"`.\n- `count_coverage()` returns A\u002FC\u002FG\u002FT base counts and defaults to base quality\n  15 plus `read_callback=\"all\"`.\n- `pileup()` exposes per-column reads and has its own filtering, base-quality,\n  overlap, orphan, and `max_depth=8000` defaults.\n\nFor exact-region pileups, set `truncate=True` and explicit filters:\n\n```python\nwith pysam.FastaFile(\"reference.fa\") as fasta, pysam.AlignmentFile(\n    \"sample.bam\", \"rb\"\n) as bam:\n    for column in bam.pileup(\n        \"chr1\",\n        1_000,\n        2_000,\n        truncate=True,\n        stepper=\"samtools\",\n        fastafile=fasta,\n        min_mapping_quality=20,\n        min_base_quality=20,\n        max_depth=100_000,\n    ):\n        print(column.reference_pos, column.get_num_aligned())\n```\n\nRead `references\u002Falignment_files.md` for flags, CIGAR operations, tags,\nmodified bases, writing records, pileup details, and iterator lifetime.\n\n## Variant Files\n\nInput format is auto-detected. Numeric fetch coordinates remain 0-based:\n\n```python\nimport pysam\n\nwith pysam.VariantFile(\"cohort.vcf.gz\", threads=4) as variants:\n    for record in variants.fetch(\"chr1\", 999_999, 2_000_000):\n        print(record.contig, record.pos, record.ref, record.alts)\n        for sample_name, call in record.samples.items():\n            print(sample_name, call.get(\"GT\"))\n```\n\nSubset samples **before retrieving records**:\n\n```python\nwith pysam.VariantFile(\"cohort.bcf\") as variants:\n    variants.subset_samples([\"sample_A\", \"sample_B\"])\n    for record in variants:\n        ...\n```\n\nWhen changing a header, copy each record and translate it to the destination\nheader before assigning newly declared INFO\u002FFORMAT\u002FFILTER fields. Do not\nmanually clear and rebuild `header.samples`.\n\nRead `references\u002Fvariant_files.md` for safe headers, writing, sample\nsubsetting, missing genotypes, symbolic alleles, filtering, translation, and\nindexing.\n\n## FASTA, FASTQ, and Tabix\n\nIndexed FASTA uses numeric 0-based coordinates:\n\n```python\nwith pysam.FastaFile(\"reference.fa\") as fasta:\n    sequence = fasta.fetch(\"chr1\", 999, 1_099)\n```\n\n`FastxFile` is sequential. `persist=False` is faster but yielded records become\ninvalid after iteration advances:\n\n```python\nwith pysam.FastxFile(\"reads.fastq.gz\", persist=False) as reads:\n    for read in reads:\n        qualities = read.get_quality_array()\n        ...\n```\n\nTabix input must be coordinate-sorted and BGZF-compressed, not ordinary gzip.\nUse a non-destructive two-step workflow:\n\n```python\npysam.tabix_compress(\"regions.bed\", \"regions.bed.gz\")\npysam.tabix_index(\"regions.bed.gz\", preset=\"bed\")\n\nwith pysam.TabixFile(\"regions.bed.gz\", parser=pysam.asBed()) as tbx:\n    for interval in tbx.fetch(\"chr1\", 1_000, 2_000):\n        print(interval.contig, interval.start, interval.end)\n```\n\nRead `references\u002Fsequence_files.md` for FASTA\u002FFASTQ records and safe tabix\ncreation.\n\n## CRAM, Remote I\u002FO, and Threads\n\npysam 0.24 changed inherited HTSlib behavior:\n\n- Newly written CRAM defaults to CRAM 3.1, not 3.0.\n- HTSlib no longer contacts the EBI reference server by default.\n- Prefer `reference_filename=\"reference.fa\"` for deterministic local reads and\n  writes.\n\n```python\nwith pysam.AlignmentFile(\n    \"sample.cram\",\n    \"rc\",\n    reference_filename=\"reference.fa\",\n    threads=4,\n) as cram:\n    for read in cram.fetch(\"chr1\", 1_000, 2_000):\n        ...\n```\n\nOnly configure `REF_PATH`\u002F`REF_CACHE` when reference-by-MD5 lookup is\nintentional. Do not assume a CRAM is self-contained. `threads=` accelerates\ncompression\u002Fdecompression; it does not parallelize Python analysis.\n\nRead `references\u002Fcram_and_performance.md` before CRAM conversion, remote access,\nor concurrent iteration.\n\n## Wrapped samtools and bcftools\n\nImport command modules explicitly. Pass each command-line token as a separate\nstring:\n\n```python\nimport pysam.samtools\nimport pysam.bcftools\n\npysam.samtools.sort(\n    \"-@\", \"4\", \"-o\", \"sorted.bam\", \"input.bam\", catch_stdout=False\n)\npysam.samtools.index(\"-@\", \"4\", \"sorted.bam\", catch_stdout=False)\n\npysam.bcftools.index(\"--csi\", \"variants.vcf.gz\", catch_stdout=False)\n```\n\nDispatchers capture stdout by default. For large or binary output, use the\ntool's `-o` option with `catch_stdout=False`, or `save_stdout=...`, rather than\nreturning the complete output in memory.\n\n```python\ntry:\n    pysam.samtools.quickcheck(\"-v\", \"sample.bam\")\nexcept pysam.SamtoolsError as error:\n    messages = pysam.samtools.quickcheck.get_messages()\n    raise RuntimeError(messages or str(error)) from error\n```\n\nUse the Python API for record-level logic and dispatchers for mature bulk\noperations such as sort, index, merge, view, and normalization. Never compose\ndispatcher arguments by splitting an untrusted shell command.\n\n## Writing Rules\n\n- Copy or construct a valid header before opening output.\n- Write to a new path; do not use `force=True` unless replacement is explicit.\n- Preserve sort order if the output will be indexed.\n- Set `query_sequence` before `query_qualities`.\n- Prefer `pysam.CIGAR_OPS` enum members; top-level constants such as\n  `pysam.CMATCH` are compatibility aliases slated for future removal.\n- Validate outputs with `pysam.samtools.quickcheck()` for alignments and reopen\n  variant\u002Fsequence outputs before downstream use.\n- Use CSI rather than BAI\u002FTBI when references or coordinates exceed legacy\n  index limits.\n\n## Reference Map\n\n| Need | Read |\n|---|---|\n| Alignment API, flags, CIGAR, pileup, modified bases | `references\u002Falignment_files.md` |\n| VCF\u002FBCF headers, records, samples, writing | `references\u002Fvariant_files.md` |\n| FASTA\u002FFASTQ and tabix-indexed tables | `references\u002Fsequence_files.md` |\n| Coordinate conversion and index selection | `references\u002Fcoordinates_and_indexing.md` |\n| CRAM references, remote I\u002FO, threads, performance | `references\u002Fcram_and_performance.md` |\n| Correct integrated analysis patterns | `references\u002Fcommon_workflows.md` |\n| Compact current API signatures and defaults | `references\u002Fapi_reference.md` |\n| Upgrade notes for existing environments | `references\u002Fmigration_to_0_24.md` |\n| Official docs, specifications, and release sources | `references\u002Fsources.md` |\n\n## Common Failure Modes\n\n- Treating numeric `VariantFile.fetch()` coordinates as 1-based\n- Using ordinary gzip where BGZF plus tabix\u002FCSI is required\n- Calling region fetch without an index\n- Assuming `fetch()` includes unplaced unmapped alignments\n- Forgetting `truncate=True` for an exact pileup interval\n- Ignoring pileup defaults such as base quality 13 and depth cap 8000\n- Sharing one file handle across active iterators or threads\n- Decoding CRAM without its exact reference\n- Assigning a new VCF field before declaring it in the output header\n- Capturing large samtools\u002Fbcftools output in memory\n- Using a SNP base-counting method for indels or symbolic alleles\n","# pysam\n\n## Overview\n\nUse pysam for low-level, streaming access to HTSlib-supported genomic formats:\n\n- `AlignmentFile` and `AlignedSegment` for SAM\u002FBAM\u002FCRAM\n- `VariantFile`, `VariantHeader`, and `VariantRecord` for VCF\u002FBCF\n- `FastaFile` for indexed FASTA and `FastxFile` for sequential FASTA\u002FFASTQ\n- `TabixFile` for BGZF-compressed, tabix-indexed BED\u002FGFF\u002FGTF\u002Fcustom tables\n- `pysam.samtools` and `pysam.bcftools` for wrapped command dispatchers\n\nCurrent upstream baseline: **pysam 0.24.0** (27 April 2026), wrapping\nHTSlib\u002Fsamtools\u002Fbcftools 1.23.1. Read `references\u002Fsources.md` before updating\nversion-specific guidance.\n\n## Installation\n\nUse the pinned release for reproducible work:\n\n```bash\nuv pip install \"pysam==0.24.0\"\n```\n\nConfirm the runtime:\n\n```python\nimport pysam\n\nprint(pysam.__version__)           # 0.24.0\nprint(pysam.__samtools_version__)  # 1.23.1\n```\n\nPrebuilt wheels are available for supported macOS and Linux platforms. A\nsource build needs a C compiler and HTSlib build dependencies; read the\nofficial installation guide linked from `references\u002Fsources.md`.\n\n## First Decide\n\nBefore writing code:\n\n1. Identify the real format, compression, sort order, and available index.\n2. Decide whether coordinates are numeric Python coordinates or a region\n   string. Do not mix them.\n3. For CRAM, identify the exact reference assembly and FASTA.\n4. Prefer indexed region access; use sequential iteration only when intended.\n5. Preserve headers when writing and write to a new path by default.\n6. State filtering semantics: mapping\u002Fbase quality, flags, overlap handling,\n   duplicate handling, and pileup depth cap.\n\nFor unfamiliar files, start with the bundled read-only inspector:\n\n```bash\npython scripts\u002Finspect_hts.py sample.bam\npython scripts\u002Finspect_hts.py cohort.vcf.gz\npython scripts\u002Finspect_hts.py reference.fa\n```\n\n## Bundled Scripts\n\n| Script | Purpose | Typical call |\n|---|---|---|\n| `scripts\u002Finspect_hts.py` | Metadata-only inspection for alignment, variant, FASTA, FASTQ, and tabix files | `python scripts\u002Finspect_hts.py sample.cram --reference ref.fa` |\n| `scripts\u002Falignment_qc.py` | Streaming aggregate read\u002FQC counts as JSON | `python scripts\u002Falignment_qc.py sample.bam --max-records 100000` |\n| `scripts\u002Fvariant_summary.py` | Streaming variant, FILTER, and genotype summary as JSON | `python scripts\u002Fvariant_summary.py cohort.vcf.gz --region chr1:1-1000000` |\n| `scripts\u002Ffilter_alignments.py` | Filter SAM\u002FBAM\u002FCRAM without changing record order | `python scripts\u002Ffilter_alignments.py input.bam output.bam --exclude-secondary` |\n\nAll scripts refuse to overwrite existing outputs. Run each with `--help` for\ncoordinate, index, and privacy notes.\n\n## Coordinate Contract\n\n**Numeric coordinates accepted by pysam APIs are 0-based, half-open.** This\nincludes numeric `AlignmentFile.fetch()`, `VariantFile.fetch()`,\n`FastaFile.fetch()`, `TabixFile.fetch()`, and `pileup()` arguments.\n\n**Region strings are samtools-style: 1-based and inclusive.**\n\n```python\n# The same 100 bases:\nbam.fetch(\"chr1\", 99, 199)          # [99, 199)\nbam.fetch(region=\"chr1:100-199\")    # 1-based inclusive\n```\n\nVCF text uses 1-based `POS`, while record properties expose both systems:\n\n```python\nrecord.pos    # 1-based\nrecord.start  # 0-based inclusive\nrecord.stop   # 0-based exclusive\n```\n\nRead `references\u002Fcoordinates_and_indexing.md` for format conversions, overlap\nsemantics, index choices, and contig-name checks.\n\n## Alignment Files\n\nUse context managers and explicit modes:\n\n```python\nimport pysam\n\nwith pysam.AlignmentFile(\"sample.bam\", \"rb\", threads=4) as bam:\n    for read in bam.fetch(\"chr1\", 1_000, 2_000):\n        if (\n            not read.is_unmapped\n            and not read.is_secondary\n            and not read.is_supplementary\n            and read.mapping_quality >= 30\n        ):\n            print(read.query_name, read.reference_start, read.cigarstring)\n```\n\nUse `fetch(until_eof=True)` to stream every record in file order, including\nunplaced unmapped reads, without requiring an index:\n\n```python\nwith pysam.AlignmentFile(\"sample.bam\", \"rb\") as bam:\n    for read in bam.fetch(until_eof=True):\n        ...\n```\n\nImportant distinctions:\n\n- `fetch()` returns alignment records overlapping a region.\n- `count()` counts records and defaults to `read_callback=\"nofilter\"`.\n- `count_coverage()` returns A\u002FC\u002FG\u002FT base counts and defaults to base quality\n  15 plus `read_callback=\"all\"`.\n- `pileup()` exposes per-column reads and has its own filtering, base-quality,\n  overlap, orphan, and `max_depth=8000` defaults.\n\nFor exact-region pileups, set `truncate=True` and explicit filters:\n\n```python\nwith pysam.FastaFile(\"reference.fa\") as fasta, pysam.AlignmentFile(\n    \"sample.bam\", \"rb\"\n) as bam:\n    for column in bam.pileup(\n        \"chr1\",\n        1_000,\n        2_000,\n        truncate=True,\n        stepper=\"samtools\",\n        fastafile=fasta,\n        min_mapping_quality=20,\n        min_base_quality=20,\n        max_depth=100_000,\n    ):\n        print(column.reference_pos, column.get_num_aligned())\n```\n\nRead `references\u002Falignment_files.md` for flags, CIGAR operations, tags,\nmodified bases, writing records, pileup details, and iterator lifetime.\n\n## Variant Files\n\nInput format is auto-detected. Numeric fetch coordinates remain 0-based:\n\n```python\nimport pysam\n\nwith pysam.VariantFile(\"cohort.vcf.gz\", threads=4) as variants:\n    for record in variants.fetch(\"chr1\", 999_999, 2_000_000):\n        print(record.contig, record.pos, record.ref, record.alts)\n        for sample_name, call in record.samples.items():\n            print(sample_name, call.get(\"GT\"))\n```\n\nSubset samples **before retrieving records**:\n\n```python\nwith pysam.VariantFile(\"cohort.bcf\") as variants:\n    variants.subset_samples([\"sample_A\", \"sample_B\"])\n    for record in variants:\n        ...\n```\n\nWhen changing a header, copy each record and translate it to the destination\nheader before assigning newly declared INFO\u002FFORMAT\u002FFILTER fields. Do not\nmanually clear and rebuild `header.samples`.\n\nRead `references\u002Fvariant_files.md` for safe headers, writing, sample\nsubsetting, missing genotypes, symbolic alleles, filtering, translation, and\nindexing.\n\n## FASTA, FASTQ, and Tabix\n\nIndexed FASTA uses numeric 0-based coordinates:\n\n```python\nwith pysam.FastaFile(\"reference.fa\") as fasta:\n    sequence = fasta.fetch(\"chr1\", 999, 1_099)\n```\n\n`FastxFile` is sequential. `persist=False` is faster but yielded records become\ninvalid after iteration advances:\n\n```python\nwith pysam.FastxFile(\"reads.fastq.gz\", persist=False) as reads:\n    for read in reads:\n        qualities = read.get_quality_array()\n        ...\n```\n\nTabix input must be coordinate-sorted and BGZF-compressed, not ordinary gzip.\nUse a non-destructive two-step workflow:\n\n```python\npysam.tabix_compress(\"regions.bed\", \"regions.bed.gz\")\npysam.tabix_index(\"regions.bed.gz\", preset=\"bed\")\n\nwith pysam.TabixFile(\"regions.bed.gz\", parser=pysam.asBed()) as tbx:\n    for interval in tbx.fetch(\"chr1\", 1_000, 2_000):\n        print(interval.contig, interval.start, interval.end)\n```\n\nRead `references\u002Fsequence_files.md` for FASTA\u002FFASTQ records and safe tabix\ncreation.\n\n## CRAM, Remote I\u002FO, and Threads\n\npysam 0.24 changed inherited HTSlib behavior:\n\n- Newly written CRAM defaults to CRAM 3.1, not 3.0.\n- HTSlib no longer contacts the EBI reference server by default.\n- Prefer `reference_filename=\"reference.fa\"` for deterministic local reads and\n  writes.\n\n```python\nwith pysam.AlignmentFile(\n    \"sample.cram\",\n    \"rc\",\n    reference_filename=\"reference.fa\",\n    threads=4,\n) as cram:\n    for read in cram.fetch(\"chr1\", 1_000, 2_000):\n        ...\n```\n\nOnly configure `REF_PATH`\u002F`REF_CACHE` when reference-by-MD5 lookup is\nintentional. Do not assume a CRAM is self-contained. `threads=` accelerates\ncompression\u002Fdecompression; it does not parallelize Python analysis.\n\nRead `references\u002Fcram_and_performance.md` before CRAM conversion, remote access,\nor concurrent iteration.\n\n## Wrapped samtools and bcftools\n\nImport command modules explicitly. Pass each command-line token as a separate\nstring:\n\n```python\nimport pysam.samtools\nimport pysam.bcftools\n\npysam.samtools.sort(\n    \"-@\", \"4\", \"-o\", \"sorted.bam\", \"input.bam\", catch_stdout=False\n)\npysam.samtools.index(\"-@\", \"4\", \"sorted.bam\", catch_stdout=False)\n\npysam.bcftools.index(\"--csi\", \"variants.vcf.gz\", catch_stdout=False)\n```\n\nDispatchers capture stdout by default. For large or binary output, use the\ntool's `-o` option with `catch_stdout=False`, or `save_stdout=...`, rather than\nreturning the complete output in memory.\n\n```python\ntry:\n    pysam.samtools.quickcheck(\"-v\", \"sample.bam\")\nexcept pysam.SamtoolsError as error:\n    messages = pysam.samtools.quickcheck.get_messages()\n    raise RuntimeError(messages or str(error)) from error\n```\n\nUse the Python API for record-level logic and dispatchers for mature bulk\noperations such as sort, index, merge, view, and normalization. Never compose\ndispatcher arguments by splitting an untrusted shell command.\n\n## Writing Rules\n\n- Copy or construct a valid header before opening output.\n- Write to a new path; do not use `force=True` unless replacement is explicit.\n- Preserve sort order if the output will be indexed.\n- Set `query_sequence` before `query_qualities`.\n- Prefer `pysam.CIGAR_OPS` enum members; top-level constants such as\n  `pysam.CMATCH` are compatibility aliases slated for future removal.\n- Validate outputs with `pysam.samtools.quickcheck()` for alignments and reopen\n  variant\u002Fsequence outputs before downstream use.\n- Use CSI rather than BAI\u002FTBI when references or coordinates exceed legacy\n  index limits.\n\n## Reference Map\n\n| Need | Read |\n|---|---|\n| Alignment API, flags, CIGAR, pileup, modified bases | `references\u002Falignment_files.md` |\n| VCF\u002FBCF headers, records, samples, writing | `references\u002Fvariant_files.md` |\n| FASTA\u002FFASTQ and tabix-indexed tables | `references\u002Fsequence_files.md` |\n| Coordinate conversion and index selection | `references\u002Fcoordinates_and_indexing.md` |\n| CRAM references, remote I\u002FO, threads, performance | `references\u002Fcram_and_performance.md` |\n| Correct integrated analysis patterns | `references\u002Fcommon_workflows.md` |\n| Compact current API signatures and defaults | `references\u002Fapi_reference.md` |\n| Upgrade notes for existing environments | `references\u002Fmigration_to_0_24.md` |\n| Official docs, specifications, and release sources | `references\u002Fsources.md` |\n\n## Common Failure Modes\n\n- Treating numeric `VariantFile.fetch()` coordinates as 1-based\n- Using ordinary gzip where BGZF plus tabix\u002FCSI is required\n- Calling region fetch without an index\n- Assuming `fetch()` includes unplaced unmapped alignments\n- Forgetting `truncate=True` for an exact pileup interval\n- Ignoring pileup defaults such as base quality 13 and depth cap 8000\n- Sharing one file handle across active iterators or threads\n- Decoding CRAM without its exact reference\n- Assigning a new VCF field before declaring it in the output header\n- Capturing large samtools\u002Fbcftools output in memory\n- Using a SNP base-counting method for indels or symbolic alleles\n",{"name":5,"license":15,"metadata":24,"description":7,"allowed-tools":27,"compatibility":28},{"version":25,"skill-author":26},"2.0","K-Dense Inc.","Read Write Edit Bash","Requires Python 3.8–3.14 and pysam 0.24.0. Bundled scripts use local files. CRAM decoding may require the matching reference FASTA or an explicitly configured REF_PATH\u002FREF_CACHE.","main","4e084e84eb42fc53e144c89c0f7f48b39c8a4b0f","collections\u002Fscientific-skills\u002Fpysam",1,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills","https:\u002F\u002Fgithub.com\u002Fsanjeevafk","First make it work. Then make it right. Then make it fast.","2026-11-14 13:36:16",{"source":8,"skillName":5,"commands":38,"prompt":48,"zipAvailable":49},[39,42,45],{"tool":40,"command":41},"npx","npx skills add sanjeevafk\u002Fagent-skills --skill pysam",{"tool":43,"command":44},"bunx","bunx skills add sanjeevafk\u002Fagent-skills --skill pysam",{"tool":46,"command":47},"pnpm","pnpm dlx skills add sanjeevafk\u002Fagent-skills --skill pysam","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002FSKILL.md",true,[51,57,61,65,69,73,77,81,85,89,95,99,103],{"path":52,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":55,"sourceHtmlUrl":56},"references\u002Falignment_files.md","REFERENCE","参考文档",11183,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Freferences\u002Falignment_files.md",{"path":58,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":59,"sourceHtmlUrl":60},"references\u002Fapi_reference.md",9085,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Freferences\u002Fapi_reference.md",{"path":62,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":63,"sourceHtmlUrl":64},"references\u002Fcommon_workflows.md",11969,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Freferences\u002Fcommon_workflows.md",{"path":66,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":67,"sourceHtmlUrl":68},"references\u002Fcoordinates_and_indexing.md",8215,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Freferences\u002Fcoordinates_and_indexing.md",{"path":70,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":71,"sourceHtmlUrl":72},"references\u002Fcram_and_performance.md",8970,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Freferences\u002Fcram_and_performance.md",{"path":74,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":75,"sourceHtmlUrl":76},"references\u002Fmigration_to_0_24.md",4735,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Freferences\u002Fmigration_to_0_24.md",{"path":78,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":79,"sourceHtmlUrl":80},"references\u002Fsequence_files.md",8853,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Freferences\u002Fsequence_files.md",{"path":82,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":83,"sourceHtmlUrl":84},"references\u002Fsources.md",6045,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Freferences\u002Fsources.md",{"path":86,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":87,"sourceHtmlUrl":88},"references\u002Fvariant_files.md",10748,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Freferences\u002Fvariant_files.md",{"path":90,"resourceType":91,"resourceTypeDesc":92,"sizeBytes":93,"sourceHtmlUrl":94},"scripts\u002Falignment_qc.py","SCRIPT","脚本",10204,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Fscripts\u002Falignment_qc.py",{"path":96,"resourceType":91,"resourceTypeDesc":92,"sizeBytes":97,"sourceHtmlUrl":98},"scripts\u002Ffilter_alignments.py",11223,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Fscripts\u002Ffilter_alignments.py",{"path":100,"resourceType":91,"resourceTypeDesc":92,"sizeBytes":101,"sourceHtmlUrl":102},"scripts\u002Finspect_hts.py",13784,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Fscripts\u002Finspect_hts.py",{"path":104,"resourceType":91,"resourceTypeDesc":92,"sizeBytes":105,"sourceHtmlUrl":106},"scripts\u002Fvariant_summary.py",11119,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fscientific-skills\u002Fpysam\u002Fscripts\u002Fvariant_summary.py",[108,115,123,132,140,147],{"skillNo":109,"name":110,"nameZh":6,"description":111,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":19},"01M7EFHX67M3KKXT1BXVPA5ADT","zarr-python","Chunked N-D arrays for cloud storage (Zarr-Python 3). Compressed arrays, parallel I\u002FO, S3\u002FGCS via fsspec, NumPy\u002FDask\u002FXarray compatible, for large-scale scientific computing pipelines.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":116,"name":117,"nameZh":6,"description":118,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":119,"sourceHtmlUrl":120,"categories":121,"keywords":122,"publishedAt":19},"01M7EFFQGM51TZBGRENXY50ZYM","whiteboard-diagrams","Create accurate, simple, hand-drawn whiteboard diagrams from a user's process, system, architecture, learning workflow, comparison, or causal explanation. Use when the user asks for a scribbly whiteboard visual, educational workflow graphic, hand-drawn explainer, or diagram like the bundled reference; ask one focused clarification question when the subject or relationships are missing, then generate and visually verify the final image.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwhiteboard-diagrams\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwhiteboard-diagrams\u002FSKILL.md",[],[],{"skillNo":124,"name":125,"nameZh":6,"description":126,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":127,"licenseFileUrl":128,"sourceHtmlUrl":129,"categories":130,"keywords":131,"publishedAt":19},"01M7EFF1CSQNTDMHFK4ZGY6NYK","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":133,"name":134,"nameZh":6,"description":135,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":127,"licenseFileUrl":136,"sourceHtmlUrl":137,"categories":138,"keywords":139,"publishedAt":19},"01M7EFE8106X6C28FT8PA74427","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fweb-artifacts-builder\u002FSKILL.md",[],[],{"skillNo":141,"name":142,"nameZh":6,"description":143,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":144,"categories":145,"keywords":146,"publishedAt":19},"01M7EFCSNZM9G7ZHS6F127Q71X","verification-loop","A comprehensive verification system for Claude Code sessions.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fverification-loop\u002FSKILL.md",[],[],{"skillNo":148,"name":149,"nameZh":6,"description":150,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":151,"sourceHtmlUrl":152,"categories":153,"keywords":154,"publishedAt":19},"01M7EFCE7EZMKPRYDDNKBQ9EEH","vercel-deploy","Deploy applications and websites to Vercel. Use when the user requests deployment actions like \"deploy my app\", \"deploy and give me the link\", \"push this live\", or \"create a preview deployment\".","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fvercel-deploy\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fvercel-deploy\u002FSKILL.md",[],[]]