{"library":"pybedtools","title":"pybedtools","description":"pybedtools wraps and extends BEDTools and offers feature-level manipulations from within Python. It allows for genomic interval manipulation, also known as 'genome algebra'. The current version is 0.12.0, and it generally follows the release cadence of BEDTools, with major updates happening periodically.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pybedtools"],"cli":null},"imports":["from pybedtools import BedTool","import pybedtools.scripts"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pybedtools\nimport os\n\n# Create dummy files for demonstration\n# In a real scenario, these would be your actual genomic files\nwith open('snps.bed', 'w') as f:\n    f.write('chr1\\t10\\t20\\tSNP1\\n')\n    f.write('chr1\\t30\\t40\\tSNP2\\n')\nwith open('exons.bed', 'w') as f:\n    f.write('chr1\\t15\\t25\\tEXON1\\n')\n    f.write('chr1\\t35\\t45\\tEXON2\\n')\n\n# Create BedTool objects from files\nsnps = pybedtools.BedTool('snps.bed')\nexons = pybedtools.BedTool('exons.bed')\n\n# Perform an intersection and save the results\n# This example saves a new BED file of intersections\n# between snps.bed and exons.bed\nintersected_bed = snps.intersect(exons)\noutput_filename = 'snps_in_exons.bed'\nintersected_bed.saveas(output_filename, trackline=\"track name='SNPs in exons' color=128,0,0\")\n\nprint(f\"Intersection results saved to {output_filename}:\")\nwith open(output_filename, 'r') as f:\n    print(f.read())\n\n# Clean up dummy files\nos.remove('snps.bed')\nos.remove('exons.bed')\nos.remove(output_filename)\n","lang":"python","description":"This quickstart demonstrates how to create `BedTool` objects from existing BED files, perform an intersection operation (like `intersectBed`), and save the results to a new file, including adding a track line.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}