{"library":"pybigwig","title":"pyBigWig: Accessing BigWig Files","description":"pyBigWig is a Python package providing efficient access to bigWig files, leveraging the underlying C library libBigWig. It enables reading genomic data stored in bigWig format and also supports creating and writing new bigWig files. The current version is 0.3.25, with frequent updates addressing bug fixes and build improvements.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pyBigWig"],"cli":null},"imports":["import pyBigWig"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pyBigWig\nimport os\n\n# Define a temporary bigWig file name\ntemp_bw_file = \"temp_quickstart.bigWig\"\n\n# --- Writing a new bigWig file for demonstration ---\n# Chromosome sizes are required for writing\nchrom_sizes = {\"chr1\": 100000, \"chr2\": 50000}\nbw_write = pyBigWig.open(temp_bw_file, \"w\")\nbw_write.addHeader([(name, size) for name, size in chrom_sizes.items()])\n\n# Add some dummy entries\nbw_write.addEntries(\n    [\"chr1\"] * 5,\n    [0, 100, 200, 300, 400],\n    [99, 199, 299, 399, 499],\n    [0.1, 0.2, 0.3, 0.4, 0.5]\n)\nbw_write.addEntries(\"chr1\", 5000, 5010, [1.0]*10, step=1, span=1)\nbw_write.addEntries(\"chr2\", 1000, 1005, [2.0]*5, step=1, span=1)\nbw_write.close()\nprint(f\"Created dummy bigWig file: {temp_bw_file}\\n\")\n\n# --- Reading from the bigWig file ---\nbw = pyBigWig.open(temp_bw_file)\n\nprint(f\"Chromosomes found: {bw.chroms()}\\n\")\n\n# Get values from a specific region on chr1\nvalues_chr1 = bw.values(\"chr1\", 0, 500)\nprint(f\"Values on chr1 (0-500, first 10): {values_chr1[:10]}...\\n\")\n\n# Get summary statistics for a region\nsummary_chr1 = bw.stats(\"chr1\", 0, 1000, type=\"mean\")\nprint(f\"Mean value on chr1 (0-1000): {summary_chr1[0]}\\n\")\n\n# Get intervals (start, end, value) for a region\nintervals_chr1 = bw.intervals(\"chr1\", 0, 1000)\nprint(f\"Intervals on chr1 (0-1000, first 3): {intervals_chr1[:3]}...\\n\")\n\n# Close the bigWig file to release resources\nbw.close()\n\n# Clean up the temporary file\nif os.path.exists(temp_bw_file):\n    os.remove(temp_bw_file)\n    print(f\"Cleaned up temporary file: {temp_bw_file}\")","lang":"python","description":"This quickstart demonstrates how to create a simple bigWig file with dummy data, then open it in read mode to extract values, summary statistics, and intervals from specific genomic regions. It also shows the importance of closing the file handles.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}