sequence-slicing
Skill8 starsChanged 5 months agoMITView on GitHub
Slice, subset, and extract regions from sequences and SeqRecords — including feature extraction, fuzzy ends, and the location algebra behind GenBank features.
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
- read-write-sequencesSkill
- reverse-complementSkill
- sam-bam-basicsSkill
- samtools-bam-processingSkill
- seq-objectsSkill
- sequence-propertiesSkill
- 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, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
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.
- Distinctive: line 163
1-based GenBank vs 0-based Python: Always convert explicitly.
≈ “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
-->Sequence Slicing and Subsetting
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
- Extracting a gene/CDS/exon from a chromosome sequence.
- Slicing reads or contigs by position.
- Computing intersection of two locations (e.g., variant overlaps a gene).
- Fuzzy-end handling (next-generation sequencing produces
5'..<200).
When NOT to use
- Production genomic region queries → use
pyrangesorpysamwith a BED file. - Whole-genome windowed stats → use
bedtoolsordeeptools.
Prerequisites
biopython>=1.83- For 1-based / 0-based conversion discipline, see below.
Core workflow
- Decide the coordinate system. Biopython
FeatureLocationis 0-based, end-exclusive, matching BED and Python. GenBank flat files are 1-based, end-inclusive. - For a GenBank feature, use
feature.extract(record.seq)— Biopython handles strand for you. - For a manual region, slice with Python:
record.seq[start:end]. - For compound locations (e.g., joins across exons),
extractwalks the parts.
Coordinate systems
| Tool / format | 0/1-based | Start | End |
Biopython FeatureLocation | 0-based | inclusive | exclusive |
Python seq[a:b] | 0-based | inclusive | exclusive |
| GenBank flat file | 1-based | inclusive | inclusive |
| BED | 0-based | inclusive | exclusive |
| GFF3 | 1-based | inclusive | inclusive |
| VCF | 1-based | inclusive | (length-1) |
The single most common bug in bioinformatics code is a 1-based / 0-based off-by-one. Pick a convention and stick to it.
Code patterns
Slice a record
from Bio import SeqIO
rec = next(SeqIO.parse("chr1.fasta", "fasta"))
seq = rec.seq[1000:2000] # 1000 bp window, 0-basedExtract a feature (Biopython handles strand)
for feat in rec.features:
if feat.type == "CDS":
nt = feat.extract(rec.seq) # always in 5'→3' of the feature's strand
protein = nt.translate()
print(feat.qualifiers.get("gene", ["?"])[0], protein)Manual CDS extraction (start, end, strand)
from Bio.Seq import Seq
def extract_region(seq, start, end, strand):
sub = seq[start:end]
return sub.reverse_complement() if strand == -1 else sub
extract_region(rec.seq, 1000, 1500, strand=-1)Compound location (multi-exon)
from Bio.SeqFeature import CompoundLocation
# join(100..200, 300..400)
loc = CompoundLocation([
FeatureLocation(100, 200, strand=1),
FeatureLocation(300, 400, strand=1),
])
nt = loc.extract(rec.seq) # concatenates both partsFuzzy-end locations (next-gen sequencing)
GenBank uses > and < for unknown bounds. Biopython supports them with BeforePosition / AfterPosition:
from Bio.SeqFeature import FeatureLocation, BeforePosition
# >100..200 (start unknown, somewhere before 100)
loc = FeatureLocation(BeforePosition(100), 200)Find which features overlap a window
def overlapping(feat, start, end):
return not (feat.location.end <= start or feat.location.start >= end)
hits = [f for f in rec.features if overlapping(f, 1000, 2000)]Construct a SimpleLocation and check strand
from Bio.SeqFeature import SimpleLocation
loc = SimpleLocation(100, 200, strand=1)
print(loc.start, loc.end, loc.strand) # 100 200 1Convert 1-based GenBank coords to 0-based Python
def gb_to_python(start_gb, end_gb):
# GenBank: 1-based inclusive; Python: 0-based exclusive
return start_gb - 1, end_gbSlice a FASTQ read
from Bio import SeqIO
rec = next(SeqIO.parse("reads.fastq", "fastq"))
subseq = rec.seq[10:50] # a 40 bp windowTake a sub-record (preserves ID and metadata)
sub = rec[1000:2000]
print(sub.id, sub.description)Common pitfalls
- 1-based GenBank vs 0-based Python. Always convert explicitly.
- End-exclusive Python vs end-inclusive GenBank.
seq[99:199]is 100 bp, but GenBank would write it as100..199. - Forgetting strand on manual extraction.
seq[start:end]always returns the + strand. To get the - strand,.reverse_complement(). - Fuzzy bounds silently coerced.
BeforePositionandAfterPositionare real; don't pretend they're integers. - Slicing a
Seqvs slicing aSeqRecord. Slicing a record returns a newSeqRecord(preserves ID/description). Slicing aSeqreturns aSeq.
Validation
len(rec.seq[1000:2000]) == 1000.- For a CDS feature, the extracted length should be a multiple of 3.
- Round-trip:
loc.extract(rec.seq)length equals the sum of the location parts.
Open alternatives
| Need | Tool |
| Production genomic windows | pyranges, polars-bio |
| BED-style intersections | bedtools intersect |
| Tabix region queries | pysam.TabixFile.fetch(...) |
| Variant overlap with genes | pyensembl, gffutils |
References
- Biopython
SeqFeature: https://biopython.org/docs/latest/api/Bio.SeqFeature.html - Location algebra: https://biopython.org/docs/latest/Tutorial.html#sec:locations
- Companion:
ors-bioinformatics-sequence-seq-objects,ors-bioinformatics-omics-genome-intervals-*skills.
Changelog
- 1.0.0 (2026-06-10): Initial adaptation by Pradyumna Jayaram from
bio-sequence-slicing(bioSkills-main/sequence-manipulation/sequence-slicing).
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
- read-write-sequences
- reverse-complement
- sam-bam-basics
- samtools-bam-processing
- seq-objects
- sequence-properties
- 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.

