본문으로 건너뛰기
cccskills
무료GitHub에 공개

bio-genome-intervals-bigwig-tracks

Create and read bigWig browser tracks for visualizing continuous genomic data. Convert bedGraph to bigWig, extract signal values, and generate coverage tracks using UCSC tools and pyBigWig. Use when preparing coverage tracks for genome browsers or extracting signal at specific regions.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

실행 점수 미검증

설치 방법 보기

포함된 파일(4)

  • SKILL.md8.7 KB
  • examples/bedgraph_to_bigwig.sh2.0 KB
  • examples/pybigwig_demo.py2.5 KB
  • usage-guide.md2.7 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Version Compatibility

Reference examples tested with: bedtools 2.31+, numpy 1.26+, pandas 2.2+, samtools 1.19+

Before using code patterns, verify installed versions match. If versions differ:

  • Python: pip show <package> then help(module.function) to check signatures
  • CLI: <tool> --version then <tool> --help to confirm flags

If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.

BigWig Tracks

"Read and create BigWig files" → Access indexed binary signal tracks for efficient region queries and genome browser display.

  • Python: pyBigWig.open('file.bw') (pyBigWig)
  • CLI: bigWigToBedGraph, bedGraphToBigWig (UCSC tools)

BigWig is an indexed binary format for continuous genomic data. Efficient for genome browsers and programmatic access.

Why BigWig?

FormatSizeRandom AccessBrowser Support
bedGraphLargeNoLimited
bigWig~10x smallerYes (indexed)Excellent

Convert bedGraph to bigWig (CLI)

Installation

# UCSC tools
conda install -c bioconda ucsc-bedgraphtobigwig ucsc-bigwigtobedgraph

# Or download directly
wget http://hgdownload.soe.ucsc.edu/admin/exe/linux.x86_64/bedGraphToBigWig
chmod +x bedGraphToBigWig

Basic Conversion

# Sort bedGraph first (required)
sort -k1,1 -k2,2n coverage.bedGraph > coverage.sorted.bedGraph

# Convert to bigWig
bedGraphToBigWig coverage.sorted.bedGraph chrom.sizes output.bw

# chrom.sizes format: chr<TAB>size
# chr1	248956422
# chr2	242193529

Get Chromosome Sizes

# From FASTA index
cut -f1,2 reference.fa.fai > chrom.sizes

# Download from UCSC
wget https://hgdownload.soe.ucsc.edu/goldenPath/hg38/bigZips/hg38.chrom.sizes

# From BAM header
samtools view -H alignments.bam | grep @SQ | sed 's/@SQ\tSN:\|LN://g' > chrom.sizes

Full Workflow

# Generate bedGraph from BAM
bedtools genomecov -ibam alignments.bam -bg > coverage.bedGraph

# Sort bedGraph
sort -k1,1 -k2,2n coverage.bedGraph > coverage.sorted.bedGraph

# Convert to bigWig
bedGraphToBigWig coverage.sorted.bedGraph hg38.chrom.sizes coverage.bw

# Clean up intermediate files
rm coverage.bedGraph coverage.sorted.bedGraph

Read BigWig with pyBigWig (Python)

Installation

pip install pyBigWig

Open and Inspect

import pyBigWig

# Open file
bw = pyBigWig.open('coverage.bw')

# File info
print(f'Chromosomes: {bw.chroms()}')
print(f'Header: {bw.header()}')

# Check if file is bigWig (not bigBed)
print(f'Is bigWig: {bw.isBigWig()}')

# Close when done
bw.close()

Extract Values

import pyBigWig

bw = pyBigWig.open('coverage.bw')

# Get values for a region (returns numpy array)
values = bw.values('chr1', 1000000, 1001000)
print(f'Mean: {values.mean():.2f}')
print(f'Max: {values.max():.2f}')

# Get specific intervals with values
intervals = bw.intervals('chr1', 1000000, 1001000)
# Returns: [(start, end, value), ...]
for start, end, val in intervals:
    print(f'{start}-{end}: {val}')

# Statistics for region
stats = bw.stats('chr1', 1000000, 1001000, type='mean')
print(f'Mean coverage: {stats[0]:.2f}')

# Available stat types: mean, min, max, coverage, std, sum
max_val = bw.stats('chr1', 1000000, 1001000, type='max')
coverage = bw.stats('chr1', 1000000, 1001000, type='coverage')

bw.close()

Binned Statistics

import pyBigWig

bw = pyBigWig.open('coverage.bw')

# Get mean values in 100bp bins across region
region_start, region_end = 1000000, 2000000
n_bins = 1000  # 100bp bins

binned = bw.stats('chr1', region_start, region_end, type='mean', nBins=n_bins)
# Returns list of n_bins values

bw.close()

Extract for BED Regions

Goal: Extract mean bigWig signal values for a set of genomic regions defined in a BED file.

Approach: Open the bigWig file with pyBigWig, iterate through BED intervals, query the mean signal per region, and collect results into a pandas DataFrame.

import pyBigWig
import pybedtools

bw = pyBigWig.open('coverage.bw')
bed = pybedtools.BedTool('regions.bed')

# Get mean signal per region
results = []
for interval in bed:
    chrom, start, end = interval.chrom, interval.start, interval.end
    mean_signal = bw.stats(chrom, start, end, type='mean')[0]
    results.append({
        'chrom': chrom,
        'start': start,
        'end': end,
        'name': interval.name,
        'signal': mean_signal if mean_signal else 0
    })

bw.close()

# Convert to DataFrame
import pandas as pd
df = pd.DataFrame(results)
print(df)

Create BigWig with pyBigWig

import pyBigWig

# Create new bigWig
bw = pyBigWig.open('output.bw', 'w')

# Add header (chromosome sizes)
bw.addHeader([('chr1', 248956422), ('chr2', 242193529)])

# Add entries (must be sorted by position)
# Method 1: Individual entries
bw.addEntries(['chr1', 'chr1'], [0, 100], ends=[100, 200], values=[1.5, 2.3])

# Method 2: Chromosome at a time (more efficient)
bw.addEntries('chr1', [0, 100, 200], ends=[100, 200, 300], values=[1.5, 2.3, 3.1])

# Method 3: Fixed-width spans (most efficient for dense data)
bw.addEntries('chr2', 0, values=[1.0, 2.0, 3.0, 4.0], span=100, step=100)
# Creates: chr2:0-100=1.0, chr2:100-200=2.0, chr2:200-300=3.0, chr2:300-400=4.0

bw.close()

deepTools for BigWig Operations

Installation

conda install -c bioconda deeptools

Generate Normalized BigWig from BAM

# RPKM normalization
bamCoverage -b alignments.bam -o coverage.bw --normalizeUsing RPKM

# CPM normalization
bamCoverage -b alignments.bam -o coverage.bw --normalizeUsing CPM

# BPM (bins per million) - like TPM for ChIP-seq
bamCoverage -b alignments.bam -o coverage.bw --normalizeUsing BPM

# With bin size and smoothing
bamCoverage -b alignments.bam -o coverage.bw \
    --binSize 10 \
    --normalizeUsing CPM \
    --smoothLength 30

# Extend reads to fragment length
bamCoverage -b alignments.bam -o coverage.bw \
    --extendReads 200 \
    --normalizeUsing CPM

Compare BigWig Files

# Log2 ratio of two bigWig files
bigwigCompare -b1 treatment.bw -b2 control.bw -o log2ratio.bw --ratio log2

# Subtract
bigwigCompare -b1 treatment.bw -b2 control.bw -o diff.bw --ratio subtract

# Mean of multiple files
bigwigAverage -b file1.bw file2.bw file3.bw -o average.bw

Summarize BigWig Over Regions

# Matrix for heatmap (signal around regions)
computeMatrix reference-point -S signal.bw -R regions.bed \
    -b 2000 -a 2000 -o matrix.gz

# Plot heatmap
plotHeatmap -m matrix.gz -o heatmap.png

# Summary statistics per region
multiBigwigSummary BED-file -b sample1.bw sample2.bw -o results.npz --BED regions.bed

Convert BigWig to bedGraph

# Using UCSC tool
bigWigToBedGraph input.bw output.bedGraph

# Extract specific region
bigWigToBedGraph input.bw output.bedGraph -chrom=chr1 -start=1000000 -end=2000000

Common Patterns

ChIP-seq Signal Track

# Generate normalized track
bamCoverage -b chip.bam -o chip.bw \
    --normalizeUsing CPM \
    --extendReads 200 \
    --binSize 10

# Generate input-subtracted track
bigwigCompare -b1 chip.bw -b2 input.bw -o chip_minus_input.bw --ratio subtract

RNA-seq Coverage

# Strand-specific coverage
bamCoverage -b rnaseq.bam -o forward.bw --filterRNAstrand forward
bamCoverage -b rnaseq.bam -o reverse.bw --filterRNAstrand reverse

Extract Signal for Analysis

import pyBigWig
import pandas as pd

def extract_signal(bw_path, bed_path, stat='mean'):
    '''Extract bigWig signal for BED regions.'''
    import pybedtools
    bw = pyBigWig.open(bw_path)
    bed = pybedtools.BedTool(bed_path)

    results = []
    for interval in bed:
        val = bw.stats(interval.chrom, interval.start, interval.end, type=stat)[0]
        results.append({
            'chrom': interval.chrom,
            'start': interval.start,
            'end': interval.end,
            'name': interval.name if interval.name else '.',
            'signal': val if val is not None else 0
        })

    bw.close()
    return pd.DataFrame(results)

# Usage
df = extract_signal('coverage.bw', 'peaks.bed', stat='mean')
print(df)

Related Skills

  • coverage-analysis - Generate bedGraph input
  • chip-seq/chipseq-visualization - ChIP-seq signal tracks
  • alignment-files/bam-statistics - BAM to coverage
  • interval-arithmetic - Region operations

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Workflow for read alignment, sorting, indexing, mapping statistics, and downstream-ready alignment artifacts.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

BioTender-max/awesome-bio-agent-skills2042026년 7월 2일 업데이트

alphafold

무료

Validate protein designs using AlphaFold2 structure prediction. Use this skill when: (1) Validating designed sequences fold correctly, (2) Predicting binder-target complex structures, (3) Calculating confidence metrics (pLDDT, pTM, ipTM), (4) Self-consistency validation of designs, (5) Multi-chain complex prediction with AlphaFold-Multimer. For faster single-chain prediction, use esm. For QC thresholds, use protein-qc.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

BioTender-max/awesome-bio-agent-skills2042026년 7월 2일 업데이트

AlphaFold2 / AlphaFold-Multimer structure prediction for validation and confidence scoring. Use this skill when: (1) Validating designed sequences fold correctly, (2) Predicting binder-target complex structures, (3) Calculating confidence metrics (pLDDT, pTM, ipTM), (4) Self-consistency validation of designs, (5) Multi-chain complex prediction with AlphaFold-Multimer. For faster single-chain prediction, use esm2-sequence-scoring. For QC thresholds, use protein-design-qc.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

BioTender-max/awesome-bio-agent-skills2042026년 7월 2일 업데이트

Workflow for event-level and isoform-level splicing analysis with sashimi-ready outputs and splice QC.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

BioTender-max/awesome-bio-agent-skills2042026년 7월 2일 업데이트

atac-seq

무료

ATAC-seq processing with assay QC, MACS3 peak calling, consensus peak matrices, differential accessibility, and motif or footprint follow-up.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

BioTender-max/awesome-bio-agent-skills2042026년 7월 2일 업데이트

bindcraft

무료

End-to-end binder design using BindCraft hallucination. Use this skill when: (1) Designing protein binders with built-in AF2 validation, (2) Running production-quality binder campaigns, (3) Using different design protocols (fast, default, slow), (4) Need joint backbone and sequence optimization, (5) Want high experimental success rate. For backbone-only generation, use rfdiffusion. For QC thresholds, use protein-qc. For tool selection guidance, use binder-design.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

BioTender-max/awesome-bio-agent-skills2042026년 7월 2일 업데이트

BioTender-max의 스킬 모두 보기

이 스킬의 문제 신고