← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / OpenAI4S / skills / bioskills / bio-genome-intervals-proximity-operations / references / usage-guide.md

Proximity Operations - Usage Guide

Overview

Proximity operations compute the geometric relationships between genomic intervals: the nearest feature and its signed, strand-aware distance (bedtools closest), all features within a search radius (window), strand-aware interval extension (slop), and the regions beside a feature (flank). The defining judgment in this skill is interpretive, not mechanical: closest answers "what is the nearest annotated TSS?" (a coordinate fact), which is routinely misread as "which gene does this element regulate?" (a biology claim). For distal enhancers those disagree the majority of the time, so the agent does the bedtools arithmetic honestly and routes real enhancer-to-gene linking to activity/contact/QTL methods - while recognising that for GWAS locus-to-gene the nearest protein-coding gene is a defensible prior, the opposite advice from the same command.

Prerequisites

# bedtools (required for all operations)
conda install -c bioconda bedtools

# pybedtools (optional Python wrapper; needs the bedtools binary on PATH)
pip install pybedtools

# samtools, only to build a genome (chrom-sizes) file from a FASTA index
conda install -c bioconda samtools

A chrom-sizes file (genome.txt, two columns chromlength) is REQUIRED for slop and flank. Build it with cut -f1,2 reference.fa.fai > genome.txt or download UCSC *.chrom.sizes. closest requires both inputs coordinate-sorted.

Quick Start

Tell your AI agent what you want to do: - "Find the nearest gene to each ChIP-seq peak, signed by the gene's strand" - "Build strand-aware promoters at TSS minus 2 kb / plus 200 bp from my gene model" - "List all genes within 50 kb of each ATAC peak as candidates" - "Which gene does this distal enhancer regulate?" (the agent will flag this as a linking question, not a proximity one) - "Get 1 kb flanking regions on each side of every exon"

Example Prompts

Nearest Feature

"Sort my peaks and the gene model, then run bedtools closest with signed distance by the gene's strand, ignoring overlaps and resolving ties to the first feature, and drop the no-feature -1 rows before reporting." "Report the distance from each variant to the nearest exon and give me the distribution, not just a promoter/distal flag."

Enhancer-to-Gene (the interpretive case)

"I have distal H3K27ac peaks - assign each to its target gene." (Expect the agent to explain that nearest-gene is wrong the majority of the time for distal elements, produce a candidate set with closest/window, and route the real linking to atac-seq/enhancer-gene-linking via ABC/PCHi-C/eQTL.) "For this fine-mapped GWAS credible-set SNP, what gene does the locus implicate?" (Here nearest protein-coding gene is a fair ~50-65% prior; the agent should say so and point to causal-genomics for the rigorous version.)

Promoters and Windows

"Collapse my BED6 genes to TSS, then build strand-aware promoter windows of 2 kb upstream and 200 bp downstream, and warn me about any windows clipped at chromosome ends." "Count how many genes fall within a 50 kb window of each peak."

Flanking Regions

"Give me the 1 kb regions on each side of every exon for splice context, strand-aware."

What the Agent Will Do

  1. Identify the regime - promoter-proximal mark, distal enhancer, or GWAS locus - because it changes whether nearest-gene is an answer or only a candidate.
  2. Prepare inputs: build/verify the chrom-sizes file for slop/flank; coordinate-sort both inputs for closest; harmonize chromosome naming across all files.
  3. For promoters, collapse genes to TSS first (strand-aware), then slop strand-aware - never slop a gene body.
  4. Run the operation with the correct strand and sign flags (-D b for upstream/downstream biology, -s for slop/flank), resolving ties explicitly.
  5. Filter the -1 no-feature sentinel and verify slop/flank widths near chromosome ends.
  6. For distal-enhancer linking, return candidates plus a clear hand-off to ABC/PCHi-C/eQTL methods rather than a single "nearest gene" call.

Tips

Resources