[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75KAATFMSW44DDXZ8E8STYK":3,"skill-same:01M75KAATFMSW44DDXZ8E8STYK":46},{"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":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M75KAATFMSW44DDXZ8E8STYK","sequence-slicing",null,"Slice, subset, and extract regions from sequences and SeqRecords — including feature extraction, fuzzy ends, and the location algebra behind GenBank features.","pradyumnasagar\u002Fopen-research-skills","pradyumnasagar","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F10559871?v=4","01M75K78MYCCVKRTYGT8KKC380","Pradyumna Jayaram","01M75K78NTNE41F2PE1XBVFHAS",8,"MIT","https:\u002F\u002Fgithub.com\u002Fpradyumnasagar\u002Fopen-research-skills\u002Fblob\u002Fmain\u002Fskills\u002Fbioinformatics-sequence\u002Fsequence-slicing\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\n\nname: sequence-slicing\ndescription: \"Slice, subset, and extract regions from sequences and SeqRecords — including feature extraction, fuzzy ends, and the location algebra behind GenBank features.\"\nlicense: MIT\n---\n\u003C!-- metadata:\n  category: bioinformatics-sequence\n  oversight: low\n  version: 1.0.0\n  author: Pradyumna Jayaram\n  tags: [bioinformatics-sequence, research]\n  difficulty: intermediate\n-->\n\n# Sequence Slicing and Subsetting\n\n## Hard rules\n\n1. **No fabricated citations.** Every cited work must resolve to a verifiable\n2. **No claim without provenance.** Every quantitative or factual claim\n3. **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.\n\n## When to use\n\n- Extracting a gene\u002FCDS\u002Fexon from a chromosome sequence.\n- Slicing reads or contigs by position.\n- Computing intersection of two locations (e.g., variant overlaps a gene).\n- Fuzzy-end handling (next-generation sequencing produces `5'..\u003C200`).\n\n## When NOT to use\n\n- Production genomic region queries → use `pyranges` or `pysam` with a BED file.\n- Whole-genome windowed stats → use `bedtools` or `deeptools`.\n\n## Prerequisites\n\n- `biopython>=1.83`\n- For 1-based \u002F 0-based conversion discipline, see below.\n\n## Core workflow\n\n1. **Decide the coordinate system.** Biopython `FeatureLocation` is **0-based, end-exclusive**, matching BED and Python. GenBank flat files are 1-based, end-inclusive.\n2. **For a GenBank feature**, use `feature.extract(record.seq)` — Biopython handles strand for you.\n3. **For a manual region**, slice with Python: `record.seq[start:end]`.\n4. **For compound locations** (e.g., joins across exons), `extract` walks the parts.\n\n## Coordinate systems\n\n| Tool \u002F format | 0\u002F1-based | Start | End |\n|---------------|----------|-------|-----|\n| Biopython `FeatureLocation` | 0-based | inclusive | exclusive |\n| Python `seq[a:b]` | 0-based | inclusive | exclusive |\n| GenBank flat file | 1-based | inclusive | inclusive |\n| BED | 0-based | inclusive | exclusive |\n| GFF3 | 1-based | inclusive | inclusive |\n| VCF | 1-based | inclusive | (length-1) |\n\n**The single most common bug** in bioinformatics code is a 1-based \u002F 0-based\noff-by-one. Pick a convention and stick to it.\n\n## Code patterns\n\n### Slice a record\n\n```python\nfrom Bio import SeqIO\n\nrec = next(SeqIO.parse(\"chr1.fasta\", \"fasta\"))\nseq = rec.seq[1000:2000]   # 1000 bp window, 0-based\n```\n\n### Extract a feature (Biopython handles strand)\n\n```python\nfor feat in rec.features:\n    if feat.type == \"CDS\":\n        nt = feat.extract(rec.seq)  # always in 5'→3' of the feature's strand\n        protein = nt.translate()\n        print(feat.qualifiers.get(\"gene\", [\"?\"])[0], protein)\n```\n\n### Manual CDS extraction (start, end, strand)\n\n```python\nfrom Bio.Seq import Seq\n\ndef extract_region(seq, start, end, strand):\n    sub = seq[start:end]\n    return sub.reverse_complement() if strand == -1 else sub\n\nextract_region(rec.seq, 1000, 1500, strand=-1)\n```\n\n### Compound location (multi-exon)\n\n```python\nfrom Bio.SeqFeature import CompoundLocation\n\n# join(100..200, 300..400)\nloc = CompoundLocation([\n    FeatureLocation(100, 200, strand=1),\n    FeatureLocation(300, 400, strand=1),\n])\nnt = loc.extract(rec.seq)  # concatenates both parts\n```\n\n### Fuzzy-end locations (next-gen sequencing)\n\nGenBank uses `>` and `\u003C` for unknown bounds. Biopython supports them with `BeforePosition` \u002F `AfterPosition`:\n\n```python\nfrom Bio.SeqFeature import FeatureLocation, BeforePosition\n\n# >100..200  (start unknown, somewhere before 100)\nloc = FeatureLocation(BeforePosition(100), 200)\n```\n\n### Find which features overlap a window\n\n```python\ndef overlapping(feat, start, end):\n    return not (feat.location.end \u003C= start or feat.location.start >= end)\n\nhits = [f for f in rec.features if overlapping(f, 1000, 2000)]\n```\n\n### Construct a SimpleLocation and check strand\n\n```python\nfrom Bio.SeqFeature import SimpleLocation\n\nloc = SimpleLocation(100, 200, strand=1)\nprint(loc.start, loc.end, loc.strand)   # 100 200 1\n```\n\n### Convert 1-based GenBank coords to 0-based Python\n\n```python\ndef gb_to_python(start_gb, end_gb):\n    # GenBank: 1-based inclusive; Python: 0-based exclusive\n    return start_gb - 1, end_gb\n```\n\n### Slice a FASTQ read\n\n```python\nfrom Bio import SeqIO\n\nrec = next(SeqIO.parse(\"reads.fastq\", \"fastq\"))\nsubseq = rec.seq[10:50]   # a 40 bp window\n```\n\n### Take a sub-record (preserves ID and metadata)\n\n```python\nsub = rec[1000:2000]\nprint(sub.id, sub.description)\n```\n\n## Common pitfalls\n\n- **1-based GenBank vs 0-based Python.** Always convert explicitly.\n- **End-exclusive Python vs end-inclusive GenBank.** `seq[99:199]` is 100 bp, but GenBank would write it as `100..199`.\n- **Forgetting strand on manual extraction.** `seq[start:end]` always returns the + strand. To get the - strand, `.reverse_complement()`.\n- **Fuzzy bounds silently coerced.** `BeforePosition` and `AfterPosition` are real; don't pretend they're integers.\n- **Slicing a `Seq` vs slicing a `SeqRecord`.** Slicing a record returns a new `SeqRecord` (preserves ID\u002Fdescription). Slicing a `Seq` returns a `Seq`.\n\n## Validation\n\n- `len(rec.seq[1000:2000]) == 1000`.\n- For a CDS feature, the extracted length should be a multiple of 3.\n- Round-trip: `loc.extract(rec.seq)` length equals the sum of the location parts.\n\n## Open alternatives\n\n| Need | Tool |\n|------|------|\n| Production genomic windows | `pyranges`, `polars-bio` |\n| BED-style intersections | `bedtools intersect` |\n| Tabix region queries | `pysam.TabixFile.fetch(...)` |\n| Variant overlap with genes | `pyensembl`, `gffutils` |\n\n## References\n\n- Biopython `SeqFeature`: \u003Chttps:\u002F\u002Fbiopython.org\u002Fdocs\u002Flatest\u002Fapi\u002FBio.SeqFeature.html>\n- Location algebra: \u003Chttps:\u002F\u002Fbiopython.org\u002Fdocs\u002Flatest\u002FTutorial.html#sec:locations>\n- Companion: `ors-bioinformatics-sequence-seq-objects`, `ors-bioinformatics-omics-genome-intervals-*` skills.\n\n## Changelog\n\n- 1.0.0 (2026-06-10): Initial adaptation by Pradyumna Jayaram from `bio-sequence-slicing` (bioSkills-main\u002Fsequence-manipulation\u002Fsequence-slicing).\n\n## Cross-references\n\nOther skills in this category:\n\n- batch-processing\n- bowtie2-alignment\n- bwa-alignment\n- bwa-mem2-alignment\n- codon-usage\n- compressed-sequence-files\n- fastq-quality-scores\n- filter-sequences\n- format-conversion\n- hisat2-alignment\n- motif-search\n- paired-end-fastq\n- pysam-genomics\n- read-write-sequences\n- reverse-complement\n- sam-bam-basics\n- samtools-bam-processing\n- seq-objects\n- sequence-properties\n- sequence-statistics\n- star-alignment\n- transcription-translation\n","\u003C!-- metadata:\n  category: bioinformatics-sequence\n  oversight: low\n  version: 1.0.0\n  author: Pradyumna Jayaram\n  tags: [bioinformatics-sequence, research]\n  difficulty: intermediate\n-->\n\n# Sequence Slicing and Subsetting\n\n## Hard rules\n\n1. **No fabricated citations.** Every cited work must resolve to a verifiable\n2. **No claim without provenance.** Every quantitative or factual claim\n3. **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.\n\n## When to use\n\n- Extracting a gene\u002FCDS\u002Fexon from a chromosome sequence.\n- Slicing reads or contigs by position.\n- Computing intersection of two locations (e.g., variant overlaps a gene).\n- Fuzzy-end handling (next-generation sequencing produces `5'..\u003C200`).\n\n## When NOT to use\n\n- Production genomic region queries → use `pyranges` or `pysam` with a BED file.\n- Whole-genome windowed stats → use `bedtools` or `deeptools`.\n\n## Prerequisites\n\n- `biopython>=1.83`\n- For 1-based \u002F 0-based conversion discipline, see below.\n\n## Core workflow\n\n1. **Decide the coordinate system.** Biopython `FeatureLocation` is **0-based, end-exclusive**, matching BED and Python. GenBank flat files are 1-based, end-inclusive.\n2. **For a GenBank feature**, use `feature.extract(record.seq)` — Biopython handles strand for you.\n3. **For a manual region**, slice with Python: `record.seq[start:end]`.\n4. **For compound locations** (e.g., joins across exons), `extract` walks the parts.\n\n## Coordinate systems\n\n| Tool \u002F format | 0\u002F1-based | Start | End |\n|---------------|----------|-------|-----|\n| Biopython `FeatureLocation` | 0-based | inclusive | exclusive |\n| Python `seq[a:b]` | 0-based | inclusive | exclusive |\n| GenBank flat file | 1-based | inclusive | inclusive |\n| BED | 0-based | inclusive | exclusive |\n| GFF3 | 1-based | inclusive | inclusive |\n| VCF | 1-based | inclusive | (length-1) |\n\n**The single most common bug** in bioinformatics code is a 1-based \u002F 0-based\noff-by-one. Pick a convention and stick to it.\n\n## Code patterns\n\n### Slice a record\n\n```python\nfrom Bio import SeqIO\n\nrec = next(SeqIO.parse(\"chr1.fasta\", \"fasta\"))\nseq = rec.seq[1000:2000]   # 1000 bp window, 0-based\n```\n\n### Extract a feature (Biopython handles strand)\n\n```python\nfor feat in rec.features:\n    if feat.type == \"CDS\":\n        nt = feat.extract(rec.seq)  # always in 5'→3' of the feature's strand\n        protein = nt.translate()\n        print(feat.qualifiers.get(\"gene\", [\"?\"])[0], protein)\n```\n\n### Manual CDS extraction (start, end, strand)\n\n```python\nfrom Bio.Seq import Seq\n\ndef extract_region(seq, start, end, strand):\n    sub = seq[start:end]\n    return sub.reverse_complement() if strand == -1 else sub\n\nextract_region(rec.seq, 1000, 1500, strand=-1)\n```\n\n### Compound location (multi-exon)\n\n```python\nfrom Bio.SeqFeature import CompoundLocation\n\n# join(100..200, 300..400)\nloc = CompoundLocation([\n    FeatureLocation(100, 200, strand=1),\n    FeatureLocation(300, 400, strand=1),\n])\nnt = loc.extract(rec.seq)  # concatenates both parts\n```\n\n### Fuzzy-end locations (next-gen sequencing)\n\nGenBank uses `>` and `\u003C` for unknown bounds. Biopython supports them with `BeforePosition` \u002F `AfterPosition`:\n\n```python\nfrom Bio.SeqFeature import FeatureLocation, BeforePosition\n\n# >100..200  (start unknown, somewhere before 100)\nloc = FeatureLocation(BeforePosition(100), 200)\n```\n\n### Find which features overlap a window\n\n```python\ndef overlapping(feat, start, end):\n    return not (feat.location.end \u003C= start or feat.location.start >= end)\n\nhits = [f for f in rec.features if overlapping(f, 1000, 2000)]\n```\n\n### Construct a SimpleLocation and check strand\n\n```python\nfrom Bio.SeqFeature import SimpleLocation\n\nloc = SimpleLocation(100, 200, strand=1)\nprint(loc.start, loc.end, loc.strand)   # 100 200 1\n```\n\n### Convert 1-based GenBank coords to 0-based Python\n\n```python\ndef gb_to_python(start_gb, end_gb):\n    # GenBank: 1-based inclusive; Python: 0-based exclusive\n    return start_gb - 1, end_gb\n```\n\n### Slice a FASTQ read\n\n```python\nfrom Bio import SeqIO\n\nrec = next(SeqIO.parse(\"reads.fastq\", \"fastq\"))\nsubseq = rec.seq[10:50]   # a 40 bp window\n```\n\n### Take a sub-record (preserves ID and metadata)\n\n```python\nsub = rec[1000:2000]\nprint(sub.id, sub.description)\n```\n\n## Common pitfalls\n\n- **1-based GenBank vs 0-based Python.** Always convert explicitly.\n- **End-exclusive Python vs end-inclusive GenBank.** `seq[99:199]` is 100 bp, but GenBank would write it as `100..199`.\n- **Forgetting strand on manual extraction.** `seq[start:end]` always returns the + strand. To get the - strand, `.reverse_complement()`.\n- **Fuzzy bounds silently coerced.** `BeforePosition` and `AfterPosition` are real; don't pretend they're integers.\n- **Slicing a `Seq` vs slicing a `SeqRecord`.** Slicing a record returns a new `SeqRecord` (preserves ID\u002Fdescription). Slicing a `Seq` returns a `Seq`.\n\n## Validation\n\n- `len(rec.seq[1000:2000]) == 1000`.\n- For a CDS feature, the extracted length should be a multiple of 3.\n- Round-trip: `loc.extract(rec.seq)` length equals the sum of the location parts.\n\n## Open alternatives\n\n| Need | Tool |\n|------|------|\n| Production genomic windows | `pyranges`, `polars-bio` |\n| BED-style intersections | `bedtools intersect` |\n| Tabix region queries | `pysam.TabixFile.fetch(...)` |\n| Variant overlap with genes | `pyensembl`, `gffutils` |\n\n## References\n\n- Biopython `SeqFeature`: \u003Chttps:\u002F\u002Fbiopython.org\u002Fdocs\u002Flatest\u002Fapi\u002FBio.SeqFeature.html>\n- Location algebra: \u003Chttps:\u002F\u002Fbiopython.org\u002Fdocs\u002Flatest\u002FTutorial.html#sec:locations>\n- Companion: `ors-bioinformatics-sequence-seq-objects`, `ors-bioinformatics-omics-genome-intervals-*` skills.\n\n## Changelog\n\n- 1.0.0 (2026-06-10): Initial adaptation by Pradyumna Jayaram from `bio-sequence-slicing` (bioSkills-main\u002Fsequence-manipulation\u002Fsequence-slicing).\n\n## Cross-references\n\nOther skills in this category:\n\n- batch-processing\n- bowtie2-alignment\n- bwa-alignment\n- bwa-mem2-alignment\n- codon-usage\n- compressed-sequence-files\n- fastq-quality-scores\n- filter-sequences\n- format-conversion\n- hisat2-alignment\n- motif-search\n- paired-end-fastq\n- pysam-genomics\n- read-write-sequences\n- reverse-complement\n- sam-bam-basics\n- samtools-bam-processing\n- seq-objects\n- sequence-properties\n- sequence-statistics\n- star-alignment\n- transcription-translation\n",{"name":5,"license":15,"description":7},"main","9c0b41e2036cc5588c699f06e658ea6dc3b9685d","skills\u002Fbioinformatics-sequence\u002Fsequence-slicing",2,"https:\u002F\u002Fgithub.com\u002Fpradyumnasagar\u002Fopen-research-skills","https:\u002F\u002Fgithub.com\u002Fpradyumnasagar","PhD Scholar,\r\nManipal School Of Life Sciences, Manipal\r\n #OpenSourceDeveloper #LifeSciences #ComputationalBiology","2026-10-30 01:30:52",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add pradyumnasagar\u002Fopen-research-skills --skill sequence-slicing",{"tool":38,"command":39},"bunx","bunx skills add pradyumnasagar\u002Fopen-research-skills --skill sequence-slicing",{"tool":41,"command":42},"pnpm","pnpm dlx skills add pradyumnasagar\u002Fopen-research-skills --skill sequence-slicing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fpradyumnasagar\u002Fopen-research-skills\u002Fblob\u002Fmain\u002Fskills\u002Fbioinformatics-sequence\u002Fsequence-slicing\u002FSKILL.md",true,[],[47,54,60,67,74,81],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":19},"01M75KTS5K9QNX8FQBTJW2GQSH","good-skill","A well-formed test fixture for the validation script.","https:\u002F\u002Fgithub.com\u002Fpradyumnasagar\u002Fopen-research-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fgood-skill\u002FSKILL.md",[],[],{"skillNo":55,"name":56,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M75KTR7FAT0MMMED2EGC9WZZ","BadSkill","https:\u002F\u002Fgithub.com\u002Fpradyumnasagar\u002Fopen-research-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fbad-skill\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":19},"01M75KTN949EDF77GJDS8H6VR8","my-new-skill","One sentence (max 200 chars) — what the skill does and when to use it.","https:\u002F\u002Fgithub.com\u002Fpradyumnasagar\u002Fopen-research-skills\u002Fblob\u002Fmain\u002Ftemplate\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":19},"01M75KTHTFS121SSF1Q5X2FXDA","thesis-structure","Use when planning or checking the architecture of a PhD \u002F MPhil thesis in the life sciences or bioinformatics — monograph vs article-based, chapter sequence, IMRaD-based chapters, abstract-to-conclusion flow, and the examiner expectations that the structure must meet.","https:\u002F\u002Fgithub.com\u002Fpradyumnasagar\u002Fopen-research-skills\u002Fblob\u002Fmain\u002Fskills\u002Fthesis-writing\u002Fthesis-structure\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M75KTE3WKW46FXFHQ579H8YP","thesis-methods-reproducibility","Use when writing or checking the Methods, figures, data, and code of a bioinformatics \u002F microbiology \u002F life-science PhD thesis — the FAIR data, versioned code, report-generation, figure-and-table discipline, and the reproducibility expectations that examiners probe at viva.","https:\u002F\u002Fgithub.com\u002Fpradyumnasagar\u002Fopen-research-skills\u002Fblob\u002Fmain\u002Fskills\u002Fthesis-writing\u002Fthesis-methods-reproducibility\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":19},"01M75KTA033ZQCJY3DC8P5VQET","thesis-defense-viva","Use when preparing for the viva voce \u002F oral thesis defense — building the examiner's question set, rehearsing the presentation, and the pre-defense polish (slides, summary, the 'what if I'm stuck' responses) for a life-science or bioinformatics PhD.","https:\u002F\u002Fgithub.com\u002Fpradyumnasagar\u002Fopen-research-skills\u002Fblob\u002Fmain\u002Fskills\u002Fthesis-writing\u002Fthesis-defense-viva\u002FSKILL.md",[],[]]