Registry / data / bx-python

bx-python

JSON →
library0.14.0pypypi✓ verified 35d ago

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.

dataai-ml
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from bx.seq.twobit import TwoBitFile
from bx.align.maf import MAFWriter
from bx.intervals.io import Interval
from bx.align.fasta import Header

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`.

from bx.seq.twobit import TwoBitFile import os # This is a placeholder for a real .2bit file # In a real scenario, you'd open an existing file. # For demonstration, we'll simulate a file path. twobit_file_path = os.environ.get('BX_TWOBIT_FILE', 'example.2bit') # Create a dummy .2bit file for demonstration if it doesn't exist # This part would typically not be in a quickstart but is here for runnability. if not os.path.exists(twobit_file_path): try: # TwoBitFile constructor expects a file-like object or a path to an existing file # For a runnable example, we would need to *create* a valid .2bit file or skip this section. # Given the complexity, let's illustrate reading an assumed existing file. # This part of the quickstart is illustrative rather than fully runnable without a .2bit file. print(f"Please provide a valid .2bit file at {twobit_file_path} to run this example.") print("Example: Download one from UCSC genome browser, e.g., 'hg38.2bit'") # Example of how you would *use* it if the file exists: # with open(twobit_file_path, 'rb') as f: # tb = TwoBitFile(f) # print(f"Sequence 'chr1' length: {tb['chr1'].length}") # print(f"Sequence 'chr1' first 10 bases: {tb['chr1'].get(0, 10)}") except Exception as e: print(f"Could not create or open dummy .2bit file for quickstart: {e}") print("Skipping TwoBitFile quickstart example.") # Example of using MAF (Multiple Alignment Format) writer from bx.align.maf import MAFWriter, MAFAlignment, MAFBlock, MAFComponent import sys print("\nDemonstrating MAFWriter:") writer = MAFWriter(sys.stdout) alignment = MAFAlignment() block = MAFBlock() # Create components for a block comp1 = MAFComponent() comp1.src = 'hg38.chr1' comp1.start = 100 comp1.size = 10 comp1.strand = '+' comp1.srcSize = 248956422 comp1.text = 'ATGCATGCAT' comp2 = MAFComponent() comp2.src = 'mm10.chrX' comp2.start = 50 comp2.size = 10 comp2.strand = '-' comp2.srcSize = 171031299 comp2.text = 'ATGCATGCAT' block.components.append(comp1) block.components.append(comp2) alignment.append(block) writer.write(alignment) print("MAF example written to stdout.")
Debug
Known footguns
breakingPython 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.
breakingThe `psyco` module and `bx.cookbook.progress_bar` module were removed in `bx-python` v0.13.0. Any code depending on these modules will break.
breakingIndexing `TwoBitFile` sequences changed from expecting `bytes` to `str` in `bx-python` v0.9.0. Using `bytes` for sequence names will result in errors.
gotchaOlder 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.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources