{"id":7995,"library":"bx-python","title":"bx-python","description":"bx-python is a collection of Python tools designed for manipulating biological data, with a particular focus on operations involving multiple sequence alignments and genomic intervals. The library is currently at version 0.14.0 and follows an active release cadence, frequently updating to support newer Python versions and improve compatibility with other scientific libraries like NumPy.","status":"active","version":"0.14.0","language":"en","source_language":"en","source_url":"https://github.com/bxlab/bx-python","tags":["bioinformatics","genomics","sequence-alignment","genomic-intervals","data-manipulation"],"install":[{"cmd":"pip install bx-python","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for numerical operations, especially in alignment and interval modules. Compatibility changes are common across bx-python versions.","package":"numpy","optional":false}],"imports":[{"symbol":"TwoBitFile","correct":"from bx.seq.twobit import TwoBitFile"},{"symbol":"MAFWriter","correct":"from bx.align.maf import MAFWriter"},{"symbol":"Interval","correct":"from bx.intervals.io import Interval"},{"symbol":"Header","correct":"from bx.align.fasta import Header"}],"quickstart":{"code":"from bx.seq.twobit import TwoBitFile\nimport os\n\n# This is a placeholder for a real .2bit file\n# In a real scenario, you'd open an existing file.\n# For demonstration, we'll simulate a file path.\ntwobit_file_path = os.environ.get('BX_TWOBIT_FILE', 'example.2bit')\n\n# Create a dummy .2bit file for demonstration if it doesn't exist\n# This part would typically not be in a quickstart but is here for runnability.\nif not os.path.exists(twobit_file_path):\n    try:\n        # TwoBitFile constructor expects a file-like object or a path to an existing file\n        # For a runnable example, we would need to *create* a valid .2bit file or skip this section.\n        # Given the complexity, let's illustrate reading an assumed existing file.\n        # This part of the quickstart is illustrative rather than fully runnable without a .2bit file.\n        print(f\"Please provide a valid .2bit file at {twobit_file_path} to run this example.\")\n        print(\"Example: Download one from UCSC genome browser, e.g., 'hg38.2bit'\")\n        # Example of how you would *use* it if the file exists:\n        # with open(twobit_file_path, 'rb') as f:\n        #     tb = TwoBitFile(f)\n        #     print(f\"Sequence 'chr1' length: {tb['chr1'].length}\")\n        #     print(f\"Sequence 'chr1' first 10 bases: {tb['chr1'].get(0, 10)}\")\n\n    except Exception as e:\n        print(f\"Could not create or open dummy .2bit file for quickstart: {e}\")\n        print(\"Skipping TwoBitFile quickstart example.\")\n\n# Example of using MAF (Multiple Alignment Format) writer\nfrom bx.align.maf import MAFWriter, MAFAlignment, MAFBlock, MAFComponent\nimport sys\n\nprint(\"\\nDemonstrating MAFWriter:\")\nwriter = MAFWriter(sys.stdout)\n\nalignment = MAFAlignment()\nblock = MAFBlock()\n\n# Create components for a block\ncomp1 = MAFComponent()\ncomp1.src = 'hg38.chr1'\ncomp1.start = 100\ncomp1.size = 10\ncomp1.strand = '+'\ncomp1.srcSize = 248956422\ncomp1.text = 'ATGCATGCAT'\n\ncomp2 = MAFComponent()\ncomp2.src = 'mm10.chrX'\ncomp2.start = 50\ncomp2.size = 10\ncomp2.strand = '-'\ncomp2.srcSize = 171031299\ncomp2.text = 'ATGCATGCAT'\n\nblock.components.append(comp1)\nblock.components.append(comp2)\nalignment.append(block)\n\nwriter.write(alignment)\nprint(\"MAF example written to stdout.\")","lang":"python","description":"This quickstart demonstrates how to interact with `bx-python` for common bioinformatics tasks. It shows how to use `TwoBitFile` to access genomic sequences (note: a valid .2bit file is required for this part to fully run) and how to construct and write a simple MAF (Multiple Alignment Format) block to standard output using `MAFWriter`."},"warnings":[{"fix":"Upgrade Python to 3.9 or higher (recommended), or install `bx-python<0.14.0`.","message":"Python 3.8 support was dropped in `bx-python` v0.14.0. If you are using an older Python version, you must upgrade Python or pin an older `bx-python` version.","severity":"breaking","affected_versions":">=0.14.0"},{"fix":"Remove all references to `psyco` (which only supported Python <= 2.6) and `bx.cookbook.progress_bar`. For progress bars, consider alternatives like `tqdm`.","message":"The `psyco` module and `bx.cookbook.progress_bar` module were removed in `bx-python` v0.13.0. Any code depending on these modules will break.","severity":"breaking","affected_versions":">=0.13.0"},{"fix":"Ensure that sequence names used for indexing `TwoBitFile` objects are Python `str` objects, not `bytes`.","message":"Indexing `TwoBitFile` sequences changed from expecting `bytes` to `str` in `bx-python` v0.9.0. Using `bytes` for sequence names will result in errors.","severity":"breaking","affected_versions":">=0.9.0"},{"fix":"Ensure `bx-python` and `numpy` versions are compatible. `bx-python` >= 0.10.0 provides fixes for `np.float` deprecation. If experiencing issues, try upgrading both packages or ensuring your NumPy is not extremely old/new compared to your `bx-python`.","message":"Older versions of NumPy (pre-1.24) used `np.float`, which is deprecated in newer NumPy versions. `bx-python` has addressed compatibility, but issues might arise if using specific older `bx-python` versions with new NumPy or vice-versa.","severity":"gotcha","affected_versions":"All versions, depending on NumPy version interaction"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Remove any code that attempts to import or use `bx.cookbook.progress_bar`. If a progress bar is needed, use a third-party library like `tqdm`.","cause":"The `bx.cookbook.progress_bar` module was removed in `bx-python` version 0.13.0.","error":"ModuleNotFoundError: No module named 'bx.cookbook.progress_bar'"},{"fix":"Convert any `bytes` sequence names to `str` before indexing `TwoBitFile`. For example, `tb[b'chr1']` should become `tb['chr1']`.","cause":"Prior to `bx-python` v0.9.0, `TwoBitFile` sequences could be indexed by `bytes`. From v0.9.0 onwards, `str` is required.","error":"TypeError: sequence indices must be integers or slices, not bytes"},{"fix":"Verify the exact import path from the `bx-python` documentation for your specific version. Ensure you are importing from `bx.cookbook.tools` or `bx.align.maf` etc., rather than just `bx.cookbook` directly.","cause":"Incorrect import path used, or trying to import a module that was moved/removed. A fix was applied in v0.13.0 for `bx.cookbook`'s import.","error":"ImportError: cannot import name 'cookbook' from 'bx' (or similar for other submodules)"},{"fix":"Upgrade your Python environment to Python 3.9 or higher. Alternatively, if you must use Python 3.8, install an older compatible version of `bx-python`, e.g., `pip install 'bx-python<0.14.0'`.","cause":"`bx-python` v0.14.0 and newer versions dropped support for Python 3.8.","error":"RuntimeError: Python 3.8 is not supported"}]}