FuseByTaxa

Script: fusebytaxa.sh Package: synth Class: FuseByTaxa.java

Fuses contigs sharing a taxonomy ID (from 'tid|TAXID|...' headers) into N-padded genome-scale sequences, emitting only fused sequences at least 'floor' bp long. This tool transforms combined RefSeq clade files (which contain mostly short rRNA markers plus some assemblies) into assembly-attempt sequences for contig-classification benchmarking, dropping marker-only taxa. Designed for taxonomically-grouped input where contigs of the same taxid are adjacent.

Basic Usage

fusebytaxa.sh in=<input> out=<output> floor=1m pad=10 maxlen=50m

FuseByTaxa processes taxonomically-sorted input sequences (FASTA or FASTQ, gzip supported) and outputs fused sequences for each taxonomy ID. The tool streams data without loading the entire file into memory, making it suitable for large genome databases.

Input Requirements

Input sequences must be sorted by taxonomy ID, with contigs of the same taxid adjacent to each other. If your input is not sorted, pre-process it with sortbyname.sh taxa=t. The tool extracts the taxonomy ID from sequence headers in the conventional format tid|TAXID|... — specifically, the text between the first and second pipe characters. Headers containing no pipe character are recorded under the ID "NA".

Important: Taxonomic Sorting Requirement

  • Input MUST be sorted by taxonomy ID (same taxid contigs adjacent)
  • Use sortbyname.sh taxa=t input.fa output.fa to sort if needed
  • Tool streams input and cannot buffer, so it processes by looking at adjacent sequences

Output Format

Output sequences are FASTA format with headers: >tid|TAXID|fusedCHUNK len=LENGTH. Each taxonomy ID may generate multiple sequences if the fused length exceeds maxlen, creating numbered chunks (fused0, fused1, etc.).

Common Use Cases

Processing RefSeq Clade Files

Create assembly-attempt sequences from a combined RefSeq clade file containing rRNA markers and partial assemblies:

sortbyname.sh taxa=t refseq_clade.fna.gz sorted.fna.gz
fusebytaxa.sh in=sorted.fna.gz out=genomes.fna.gz floor=1m pad=10 maxlen=50m

This produces genome-scale sequences suitable for contig-classification benchmarking, with marker-only taxa automatically dropped.

Processing Viral Sequences

Viruses are typically small, so set floor=0 to emit all fused sequences:

fusebytaxa.sh in=sorted_viruses.fna.gz out=viral_genomes.fna.gz floor=0 pad=10 maxlen=50m

This preserves viral sequences even if they don't meet a minimum size threshold.

Adjusting Padding and Maximum Chunk Size

When fusing contigs with minimal spacing and limiting genome size:

fusebytaxa.sh in=sorted.fna.gz out=genomes.fna.gz floor=1m pad=5 maxlen=100m

This uses 5 Ns between contigs (instead of 10) and allows fused sequences up to 100 Mb before splitting into chunks.

Parameters

FuseByTaxa parameters control input/output, sequence filtering, and chunking behavior. The tool uses a streaming architecture with minimal memory footprint regardless of input size.

Input/Output Parameters

in=<file>
Input sequences (FASTA or FASTQ, may be gzip-compressed). Required. Must be sorted by taxonomy ID with adjacent contigs sharing the same taxid.
out=<file>
Output fused sequences in FASTA format. Required. Output sequences have headers: >tid|TAXID|fusedCHUNK len=LENGTH
overwrite=false
Overwrite output files if they already exist. Default: false (do not overwrite).

Sequence Filtering Parameters

floor=1m (alias: minlen)
Minimum fused sequence length to emit (bases). Fused sequences shorter than this threshold are dropped, along with their taxonomy ID. Accepts integer values and K/M/G suffixes (e.g., 1m = 1,000,000 bp). Set to 0 to emit all sequences (e.g., for viral datasets where small sequences are meaningful). Default: 1m (1,000,000 bp).

Padding and Chunking Parameters

pad=10 (alias: npad)
Number of 'N' characters inserted between consecutive contigs when fusing sequences from the same taxonomy ID. This padding helps distinguish original contig boundaries in the fused sequence. Default: 10 Ns.
maxlen=50m
Maximum length (bases) for a fused sequence before splitting into chunks. If a taxon's fused sequence exceeds this length, it is split into multiple output sequences with numbered suffixes (fused0, fused1, etc.). Accepts integer values and K/M/G suffixes (e.g., 50m = 50,000,000 bp). Must be >= floor. Default: 50m (50,000,000 bp).

Other Parameters

verbose=false
Enable verbose output for debugging. Default: false (quiet operation).
-Xmx<mem>
Set maximum Java heap memory (e.g., -Xmx2g for 2 GB). Default: 2g. FuseByTaxa is streaming and requires minimal memory regardless of input size.

Output Statistics

FuseByTaxa prints statistics to standard error after processing:

Algorithm Details

Streaming Architecture

FuseByTaxa processes sequences in a single streaming pass, reading from input and writing to output sequentially. It maintains only the current fused chunk in memory via a ByteBuilder, making it suitable for processing gigabyte-scale datasets with minimal heap usage. Input must remain taxonomically sorted for this streaming approach to work correctly.

Taxonomy ID Extraction

Taxonomy IDs are extracted from sequence headers by finding the first pipe character (|) and taking the content up to the next pipe or the end of the string. This matches the conventional tid|TAXID|... header format, but note the tid prefix itself is not validated — any pipe-delimited header yields the field after its first pipe. Headers with no pipe character at all are recorded under the ID "NA".

Fusing and Chunking Logic

When the current fused sequence length plus padding plus the next contig length would exceed maxlen, the current chunk is flushed (if >= floor) and a new chunk begins. Taxa exceeding maxlen thus produce multiple output sequences with numbered suffixes. When a new taxonomy ID is encountered, any accumulated sequences for the previous taxid are flushed, and the sequence counter resets to 0 for the new taxid.

Filtering

Sequences are emitted only if their length (in bases, after padding) is >= floor. Taxa producing no output sequences are counted as "dropped". The tool automatically distinguishes between taxa that produced output and those below the threshold.

Examples

Example 1: Basic Genome Fusion from RefSeq

Processing a RefSeq file with ~5000 species and mixed rRNA/assembly data:

sortbyname.sh taxa=t refseq_archaea.fna.gz sorted_archaea.fna.gz
fusebytaxa.sh in=sorted_archaea.fna.gz out=archaea_genomes.fna.gz floor=2m pad=10 maxlen=50m

This sorts archaea sequences by taxonomy ID, then fuses contigs for each species into genome-scale sequences. Only species with >= 2 Mb of sequence data are retained.

Example 2: Strict Filtering for High-Quality Genomes

Creating a high-quality dataset with only well-assembled taxa:

fusebytaxa.sh in=sorted_bacteria.fna.gz out=quality_genomes.fna.gz floor=5m pad=20 maxlen=100m

Uses a 5 Mb floor to retain only taxa with substantial sequence content, 20 Ns spacing for clear contig distinction, and allows genomes up to 100 Mb.

Example 3: Viral Dataset Processing

Processing sorted viral sequences where size filtering is inappropriate:

fusebytaxa.sh in=sorted_viruses.fna floor=0 pad=5 maxlen=20m out=viral_genomes.fna

Emits all viral fused sequences regardless of size (floor=0), uses minimal padding (5 Ns), and limits chunk size to 20 Mb for manageability.

Example 4: Custom Memory Settings

For systems with limited memory or large datasets:

fusebytaxa.sh -Xmx500m in=large_dataset.fna.gz out=fused.fna.gz floor=1m

Explicitly sets Java heap to 500 MB. Because FuseByTaxa is streaming, even large input files process with minimal memory.

Workflow Integration

Part of Contig-Classification Benchmarking

FuseByTaxa is designed as a preprocessing step for contig-classification benchmarks. The typical workflow is:

  1. Download RefSeq clade data (mixed rRNA markers and full assemblies)
  2. Sort by taxonomy ID: sortbyname.sh taxa=t
  3. Fuse into genome-scale sequences: fusebytaxa.sh
  4. Generate synthetic reads or use for alignment benchmarking

Complementary Tools

FuseByTaxa works with other BBTools:

Support

For questions and support: