A package for splitting reads in BAM/FASTQ files into smaller fragments.
Project description
Bamurai
A Python toolkit for manipulating BAM and FASTQ files, designed to split reads into smaller fragments, extract statistics, validate files, and manage multi-sample data.
Description
Bamurai is a command-line tool for splitting reads in BAM/FASTQ files into smaller fragments. It is designed to be fast and efficient, and can be used to split reads into a target length or a target number of pieces per read.
These are the current features of Bamurai:
- Splitting reads in a file to a target length
- Splitting reads in a file to a target number of pieces per read
- Getting statistics from a BAM or FASTQ(.gz) file
- Basic validation of BAM and FASTQ(.gz) files
The split command splits reads into a target length, each read will be split into fragments as close to the target length as possible. Reads shorter than the target length will not be split.
The divide command splits reads into a target number of pieces, each read will be split into the number of pieces specified. A further minimum length can be specified to ensure that reads are not split if the resultant fragments are less than the minimum length.
The stats command will output the following information by default:
Statistics for input.bam:
Total reads: 8160
Average read length: 30638
Throughput: 250006998
N50: 82547
It can be used with the --tsv argument to output the statistics in a tab-separated format for computational analysis.
file_name total_reads avg_read_len throughput n50
input.bam 8160 30638 250006998 82547
The validate command will check the integrity of a BAM or FASTQ(.gz) file and output the following information if the file is valid.:
input.bam is a valid BAM file with 8160 records.
Installation
To install the released version of Bamurai from PyPI
pip install bamurai
To install the latest version of Bamurai from GitHub
pip install git+https://github.com/Shians/Bamurai.git
Usage
To get help on the command-line interface and list available commands
bamurai --help
To get help on a specific command
bamurai <command> --help
Splitting reads to target size
To split a file into 10,000 bp reads
bamurai split input.bam --target-length 10000 --output output.fastq
To create a gzipped output file
bamurai split input.bam --target-length 10000 | gzip > output.fastq.gz
Dividing reads into a target number of pieces
To divide reads into 2 pieces
bamurai divide input.bam --num_fragments 2 --output output.fastq
To divide reads into 2 pieces unless resultant fragments are less than 1000 bp
bamurai divide input.bam --num_fragments 2 --min_length 1000 --output output.fastq
Getting statistics from a BAM or FASTQ file
To get stats from a BAM file
bamurai stats input.bam
To get stats from a FASTQ file or Gzipped FASTQ file
bamurai stats input.fastq
bamurai stats input.fastq.gz
Validating BAM or FASTQ files
To validate a BAM file
bamurai validate input.bam
Working with multi-sample BAM files
Bamurai provides commands for processing BAM files with multiple samples based on barcode information.
Splitting BAM or FASTQ files by donor ID
To split a BAM or FASTQ file into multiple files, one for each donor ID:
bamurai split_samples --input input.bam --tsv barcode_to_donor.tsv --output-dir donor_bams
bamurai split_samples --input input.fastq.gz --tsv barcode_to_donor.tsv --output-dir donor_fastqs
The TSV file should contain at least two columns with headers 'barcode' and 'donor_id'. Each row maps a barcode to a donor ID.
You can process multiple BAM or FASTQ files at once:
bamurai split_samples --input input1.bam input2.bam --tsv barcode_to_donor.tsv --output-dir donor_bams
bamurai split_samples --input input1.fastq.gz input2.fastq.gz --tsv barcode_to_donor.tsv --output-dir donor_fastqs
Extracting reads for a specific donor
To extract all reads belonging to a specific donor from a BAM file:
bamurai extract_sample --bam input.bam --tsv barcode_to_donor.tsv --donor-id donor1 --output donor1.bam
You can also process multiple BAM files at once, combining all donor-specific reads into a single output file:
bamurai extract_sample --bam input1.bam input2.bam input3.bam --tsv barcode_to_donor.tsv --donor-id donor1 --output donor1.bam
This command will extract all reads with barcodes belonging to the specified donor ID and write them to a new BAM file.
Assigning samples to barcodes
The assign_samples command assigns donor IDs to barcodes based on a provided TSV mapping file. This is useful for annotating barcodes in single-cell data.
To assign donor IDs to barcodes in a TSV file:
bamurai assign_samples --barcodes barcodes.tsv --tsv barcode_to_donor.tsv --output assigned_barcodes.tsv
barcodes.tsvshould contain a list of barcodes (one per line or as a column in a table).barcode_to_donor.tsvshould have at least two columns: 'barcode' and 'donor_id'.- The output file
assigned_barcodes.tsvwill contain the barcodes with their assigned donor IDs.
You can also specify a custom column name for barcodes in the input file:
bamurai assign_samples --barcodes barcodes.tsv --tsv barcode_to_donor.tsv --barcode-column cell_barcode --output assigned_barcodes.tsv
This will use the column 'cell_barcode' in barcodes.tsv as the barcode column.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bamurai-0.7.0.tar.gz.
File metadata
- Download URL: bamurai-0.7.0.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae3b56ef2f752cb4f8ba0700717998335fbe89542b831c2db392e027b1f3cc23
|
|
| MD5 |
eb526cf3c2fa8904c9a63d179d239f49
|
|
| BLAKE2b-256 |
dcde925f5702fd22d30ff7a8bdd0d115d4fced08b5b9c1df7190e3794a9d7302
|
Provenance
The following attestation bundles were made for bamurai-0.7.0.tar.gz:
Publisher:
publish-to-pypi.yml on Shians/Bamurai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bamurai-0.7.0.tar.gz -
Subject digest:
ae3b56ef2f752cb4f8ba0700717998335fbe89542b831c2db392e027b1f3cc23 - Sigstore transparency entry: 257324979
- Sigstore integration time:
-
Permalink:
Shians/Bamurai@990e246b44a07a41cd45e4e3383909802e7a7104 -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/Shians
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@990e246b44a07a41cd45e4e3383909802e7a7104 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bamurai-0.7.0-py3-none-any.whl.
File metadata
- Download URL: bamurai-0.7.0-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0474b9fdc88be92163289b66bba9f818eda7ab9053aee9e8cddc514a48bb90ab
|
|
| MD5 |
5485de2e6967da8e9ff410df4840daa0
|
|
| BLAKE2b-256 |
593fe5cba06982c555f77c629643056cb55d24024e5aa1b194b0ebaffdb52de4
|
Provenance
The following attestation bundles were made for bamurai-0.7.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on Shians/Bamurai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bamurai-0.7.0-py3-none-any.whl -
Subject digest:
0474b9fdc88be92163289b66bba9f818eda7ab9053aee9e8cddc514a48bb90ab - Sigstore transparency entry: 257324980
- Sigstore integration time:
-
Permalink:
Shians/Bamurai@990e246b44a07a41cd45e4e3383909802e7a7104 -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/Shians
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@990e246b44a07a41cd45e4e3383909802e7a7104 -
Trigger Event:
push
-
Statement type: