Skip to main content

hifi-trimmer

hifi-trimmer is a command-line tool for filtering and trimming extraneous adapter hits from a HiFi read set using a BLAST search against a fasta file of adapter sequences. It is designed to be highly configurable, with per-adapter settings to determine actions if the adapter is found at the ends of a read or in the middle. To improve reproducibility, the primary output of the tool is a BED file that describes the region of each read to be excluded. The tool also includes a command to filter the reads to disk using the produced BED file.

The polars backend for BLAST file processing should respect the number of cores set by your scheduler; however, if this is not the case the number of threads used can be adjusted by setting the environment variable POLARS_MAX_THREADS=int before running the software. The number of threads used by the bgzip backend for writing compressed BED files and the filtered FASTA files can be adjusted using the command-line option --threads.

Installation

pip install hifi_trimmer

Usage

Usage: hifi-trimmer [OPTIONS] COMMAND [ARGS]...

  Main entry point for the tool.

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  process-blast  Processes the input blastout file according to the...
  trim           Filter the reads stored in a BAM file using the...

To process a blast output TSV to a BED file:

Usage: hifi-trimmer process-blast [OPTIONS] BLASTOUT ADAPTER_YAML

  Processes the input blastout file according to the adapter yaml key.

  BLASTOUT: tabular file resulting from a BLAST query of a readset against a
  BLAST database of adapter sequences, run with -outfmt "6 std qlen".

  ADAPTER_YAML: yaml file containing a list with the following fields per
  adapter:

  - name: (name of adapter. can be a regular expression)
    discard_middle: True/False (discard read if adapter found in middle)
    discard_end: True/False (discard read if adapter found in end)
    trim_end: True/False (trim read if adapter found in end)
    middle_pident: int (minimum pident requred to identify adapter in middle of read)
    middle_length: int (minimum match length required to identify adapter in middle of read)
    end_pident: int (minimum pident requred to identify adapter in end window)
    end_length: int (minimum match length requred to identify adapter in end window)

  Output: By default, writes bgzipped BED to [prefix].bed.gz, and a JSON
  summary file with raw counts of adapter hits detected, counts identified
  after processing, and the total length of removed sequences per adapter to
  [prefix].summary.json.

Options:
  -p, --prefix TEXT               Output prefix for results. Defaults to the
                                  basename of the blastout if not provided.
  -ml, --min-length-after-trimming INTEGER
                                  Minumum length of a read after trimming the
                                  ends in order not to be discarded  [default:
                                  300]
  -el, --end-length INTEGER       Window size at either end of the read to be
                                  considered as 'ends' for searching
                                  [default: 150]
  --hits / --no-hits              Write the hits identified using the given
                                  adapter specifications to TSV. The format is
                                  standard BLAST outfmt 6 with the following
                                  extra columns: read_length (int), discard
                                  (bool), trim_l (bool), trim_r (bool)
  --no-summary                    Skip writing a summary JSON with the number
                                  of hits for each adapter
  -t, --threads INTEGER           Number of threads to use for compression
                                  [default: 1]
  --help                          Show this message and exit.

To filter a BAM file using the BED file:

Usage: hifi-trimmer trim [OPTIONS] INPUT BED

  Filter the reads stored in an input file (FASTX or *AM) using the
  appropriate BED file produced by blastout_to_bed. Can write the trimmed
  reads as FASTX or as SAM/BAM/CRAM as required.

  INPUT: Input FASTX/SAM/BAM/CRAM file in which to trim reads
  BED: BED file describing regions of the read set to exclude.

Options:
  -o, --outfile FILENAME          The output file to write to. Defaults to
                                  stdout if not specified. If writing FASTX
                                  and the outfile name ends in .gz, the output
                                  will be bgzip compressed.
  -t, --threads INTEGER           Number of threads to use for compression
                                  [default: 1]
  -f, --out-format [sam|bam|cram|fasta|fastq]
                                  Output file format.  [default: fasta]
  -h, --format-opts TEXT          Comma-separated list of format options to
                                  pass to htslib for writing the output (see h
                                  ttps://www.htslib.org/doc/samtools.html#GLOB
                                  AL_COMMAND_OPTIONS) when writing BAM or CRAM
                                  outputs.
  --help                          Show this message and exit.

Example

First, BLAST your reads against an adapter database:

blastn -query <(samtools fasta /path/to/bam) \
  -db /path/to/adapter/blast/db \
  -reward 1 -penalty -5 -gapopen 3 -gapextend 3 \
  -dust no -soft_masking true -evalue 700 \
  -searchsp 1750000000000 \
  -outfmt "6 std qlen" |\
  bgzip > blastout.gz

To create a BED file, you then need to create a YAML file describing the actions to take for each adapter. The adapter name can be a regular expression, but note that each adapter name in the BLAST file must match only one entry in the YAML.

- adapter: "^NGB00972"  // regular expression matching adapter names
  discard_middle: True  // discard read if adapter is found in the middle
  discard_end: False    // discard read if adapter found at end
  trim_end: True        // trim read if adapter is found at end (overridden by discard choice)
  middle_pident: 95     // minimum percent identity for a match in the middle of the read
  middle_length: 44     // minimum match length for a match in the middle of the read
  end_pident: 90        // minimum percent identity for a match at the end of the read
  end_length: 18        // minimum match length for a match at the end of the read

Then run process-blast to generate a BED file:

hifi-trimmer process-blast /path/to/blastout.gz /path/to/yaml

Then filter the BAM file using the BED file:

hifi-trimmer trim /path/to/bam /path/to/bed /path/to/final/file.bam

Release files for hifi-trimmer 5.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hifi-trimmer 5.0.1
File Size Uploaded
hifi_trimmer-5.0.1.tar.gz 421.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hifi-trimmer 5.0.1
File Interpreter ABI Platform
hifi_trimmer-5.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 437.8 kB

Release files / hifi_trimmer-5.0.1.tar.gz

Download URL hifi_trimmer-5.0.1.tar.gz
Size 421.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5a5e545ce8fe02dee508517259de6b2b68e5bed7772ccc3942b5a85301ecdae6
BLAKE2b-256 checksum
How to use checksums
c226fc997ea0f3a17ee437658939030dac605122ea55f9b4bb5a5075d50cbe39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

Release files / hifi_trimmer-5.0.1-py3-none-any.whl

Download URL hifi_trimmer-5.0.1-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
609ff665919d1bcc8feb1566f6674d2d5d991f30a4a665336ed7dcbb28414db3
BLAKE2b-256 checksum
How to use checksums
5a87b12bb0b9f344ca6529ceefe173da8c95509c67813bd1a71e4266b51cf895
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

5.0.1 This release

2 release files

5.0.0

2 release files

4.0.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page