BED (Browser Extensible Data) is the standard format for genomic intervals and the coordinate substrate the whole interval category rests on. This skill covers reading, creating, validating, sorting, and converting BED files (BED3 through BED12, narrowPeak/broadPeak) with bedtools (CLI) and pybedtools/pyranges/pandas (Python). Its central concern is the coordinate convention: BED is 0-based half-open while GTF/GFF, SAM, VCF, and wiggle are 1-based closed, and a botched conversion shifts every answer by one base with no error. It also covers the silent traps that make an analysis "run fine but wrong" -- chromosome-name mismatch, CRLF corruption, and the lexicographic-vs-version sort mismatch under bedtools -sorted.
conda install -c bioconda bedtools samtools ucsc-bedtobigbed ucsc-liftover crossmap
pip install pybedtools pyranges pandas
pybedtools requires a bedtools binary on PATH. pyranges is pure-Python (no binary). Generate a genome/chrom.sizes file from the same reference FASTA the rest of the pipeline used: samtools faidx ref.fa && cut -f1,2 ref.fa.fai > genome.txt.
Tell your AI agent what you want to do: - "Create a BED file from my list of peak coordinates" - "Convert my VCF variants to BED, handling the coordinate systems" - "Why does my intersect return zero overlaps?" - "Sort my BED file the way bedtools expects" - "Lift my hg19 BED coordinates over to hg38 and tell me what failed to map" - "Validate this BED file and check the BED12 blocks"
"Create a BED6 file from this DataFrame with columns chrom, start, end, name, score, strand, then read it back and report the interval lengths." "Build a minimal BED3 from these peak coordinates and save it sorted."
"Convert my VCF variant positions to a BED file, subtracting 1 from the start so the coordinates line up, and verify on a known single-base variant." "I have a 1-based GTF feature -- give me the equivalent BED interval and confirm the length is unchanged."
"My peaks.bed intersects zero genes -- check whether it is a chromosome-naming mismatch (chr1 vs 1) before assuming there is no biological overlap." "This BED works in one tool and errors in another on the last column -- check for CRLF line endings." "I ran bedtools intersect -sorted and the output only has low-numbered chromosomes -- diagnose the sort-order mismatch."
"Lift this hg19 peak BED over to hg38 with liftOver and report how many regions failed to map and why I should not ignore them." "Use CrossMap to convert my GRCh37 intervals to GRCh38 and record the chain-file provenance with the output."
"Validate this BED file: field-count consistency, negative/inverted intervals, chromosome naming, and whether it is sorted." "Reconstruct the absolute exon coordinates from this BED12 and confirm the block invariants hold." "Make 10 kb sliding windows with a 5 kb step across hg38 and number them."
-sorted operation.start - 1, end unchanged at any 1-based boundary and a genome.txt derived from the aligned FASTA where lengths are needed.bedtools sort or sort -k1,1 -k2,2n (lexicographic) before tabix/bigBed; for -sorted ops, sort both files identically or pass -g genome.txt.pybedtools.cleanup() at the end of a pybedtools script to remove temp files.