CovMaker

Script: covmaker.sh Package: bin Class: CovMaker.java

Coverage file generator and optimizer for QuickBin genomic binning workflows. Converts SAM, BAM, and COV format files into optimized coverage matrices with optional sample condensing, entropy-based sample reordering, and cosine-similarity-based merging. Designed to handle large contig sets and many samples with memory-efficient processing and SIMD-accelerated similarity calculations.

Basic Usage

covmaker.sh *.sam out=cov.txt
covmaker.sh in=sample1.bam,sample2.bam out=cov.txt
covmaker.sh cov.txt out=cov7.txt condense=7

CovMaker accepts three types of input files: SAM (Sequence Alignment Map), BAM (Binary Alignment Map), or existing COV (coverage) files. Input format is auto-detected by file extension and content. Output is always a COV file containing depth matrices suitable for genomic binning analysis.

Memory Management

CovMaker can use significant memory when processing many contigs and samples. Memory usage is primarily driven by: (1) number of samples, (2) number of unique contigs, and (3) proxy set size for similarity calculations. SAM files use substantially less memory than BAM files, and COV files use the least memory since data is already structured. Default memory detection allocates ~4GB; this can be overridden with Java parameters.

Memory Recommendations

  • Small datasets (few samples, hundreds of contigs): Default settings sufficient
  • Large datasets (many samples, millions of contigs): Increase -Xmx to 16-32GB
  • SAM vs BAM: Use SAM files when possible; BAM format increases memory footprint significantly
  • Condensing: When condense parameter is set, memory used is proportional to (number of samples)^2 for similarity matrix

Threading and Concurrency

CovMaker loads SAM/BAM files with multiple concurrent readers (default 4 threads). This parallel loading reduces total processing time but increases peak memory usage. Reduce readthreads if memory becomes a limiting factor. The condensing operation itself is single-threaded but highly optimized with SIMD calculations.

Common Use Cases

Converting Alignment Files to Coverage Matrix

The basic workflow: align reads to contigs using BBMap or similar tool, then convert the resulting SAM or BAM file to a coverage matrix for binning analysis.

# Convert SAM file to coverage format
covmaker.sh alignments.sam out=coverage.cov

# Convert multiple BAM files (higher memory usage)
covmaker.sh in=sample1.bam,sample2.bam,sample3.bam out=coverage.cov

# Process with minimum contig filtering
covmaker.sh in=alignments.sam out=coverage.cov mincontig=500

Condensing Many Samples into Fewer Logical Samples

When you have too many samples for efficient binning (typically >10-20), merge similar samples to reduce dimensionality while preserving binning quality. CovMaker uses cosine similarity on depth vectors to intelligently group similar samples.

# Condense 50 samples down to 10 using similarity merging
covmaker.sh in=all_samples.cov out=condensed.cov condense=10

# Aggressive condensing with entropy weighting
covmaker.sh in=alignments.bam out=merged.cov condense=7 entropy=t magnitude=t

Sample Reordering for Improved Indexing

Reorder samples by depth entropy to place high-information samples at indices 0, 1, 2. This improves QuickBin's internal indexing and can significantly improve binning accuracy for the primary samples of interest.

# Reorder samples by decreasing entropy (default behavior)
covmaker.sh in=coverage.cov out=reordered.cov reorder=t

# Combine condensing and reordering
covmaker.sh in=many_samples.cov out=optimized.cov condense=15 reorder=t

Complete QuickBin Workflow

Integration with downstream QuickBin analysis shows the typical usage context.

# 1. Align reads to assembled contigs
bbmap.sh ref=contigs.fa in=reads_R1.fastq in2=reads_R2.fastq out=alignment.sam

# 2. Convert to optimized coverage matrix
covmaker.sh alignment.sam out=coverage.cov mincontig=1000 reorder=t

# 3. Run QuickBin binning (separate tool)
quickbin.sh contigs=contigs.fa cov=coverage.cov out=bins.txt

Subset Extraction from Existing Coverage File

Extract coverage information for a specific set of contigs using a reference FASTA file, creating a condensed coverage matrix.

# Extract coverage only for contigs in subset.fa
covmaker.sh ref=subset.fa in=full_coverage.cov out=subset_coverage.cov mincontig=500

Parameters

CovMaker parameters are organized by function. Input can be SAM/BAM/COV files or comma-separated lists. Parameters control input format detection, output file handling, sample merging strategy, and memory/threading behavior.

Input/Output parameters

in=<file>
Input file. Accepts SAM, BAM, or COV format; auto-detected by extension and magic bytes. Properly-formatted files matching patterns (*.sam, *.bam, *.cov) do not require the 'in=' prefix - can be passed as positional arguments.
out=<file>
(outcov, covout) Output coverage file in COV format. Required parameter. Output is always COV format regardless of input format.
ref=<file>
Optional reference FASTA file. When specified, CovMaker extracts coverage only for contigs present in the reference file, creating a filtered coverage matrix. Useful for subset extraction or coordinate mapping.
mincontig=100
Ignore contigs shorter than this length. Saves memory by excluding short contigs from processing. Set to 0 to include all contigs (not recommended for large datasets).

Sample condensing parameters

condense=<int>
(samples) When the number of input samples exceeds this value, merge similar samples to reduce to this target count. Uses cosine similarity on depth vectors with optional entropy and magnitude weighting. Setting to -1 disables condensing. No condensing occurs if input samples <= target.
compare=100k
Number of largest contigs to use when calculating pairwise depth similarity between samples. Using a proxy set reduces memory usage and computation time for similarity calculations. Larger values (up to contig count) improve accuracy but use more memory.
cosine=t
Use cosine similarity in merge decisions. Prioritizes merging of samples with similar depth profiles. When true, samples with similar abundance patterns across contigs are preferred for merging.
negcos=f
Invert the cosine similarity metric to prioritize dissimilar samples instead of similar ones. Rarely used; invert merging preference order.
magnitude=t
Use total sample volume (sum of depths across all contigs) in merge decisions. Prioritizes merging low-volume samples. Helps preserve high-depth samples separate.
magpower=1.0
Raise sample volume to this power to alter its influence in merge decisions. Values < 1.0 reduce magnitude's influence; values > 1.0 increase it. Default 1.0 uses magnitude linearly.
entropy=f
Use depth entropy in merge decisions to prioritize merging low-entropy samples. When true, samples with low information content (uniform depth) are preferred for merging.
entpower=1.0
Raise entropy to this power to alter its influence in merge decisions. Default 0.25 (not 1.0) actually; allows fine-tuned entropy weighting. Values < 1.0 reduce entropy's influence.
lognorm=f
Use logs of normalized depth instead of raw depth for pairwise similarity calculations. When true, applies logarithmic transformation to depth values before calculating cosine similarity, giving equal weight to low and high abundance differences.
maxsamples=10000
Override the maximum number of samples that can be processed. Default limit is 10,000 samples to prevent excessive memory usage. Increasing this requires more memory.
readthreads=4
(maxconcurrentfiles, concurrentfiles) Load up to this many SAM/BAM files concurrently. Higher values increase speed but also peak memory usage. Lower values reduce memory footprint when processing many files sequentially.

Sample reordering parameters

reorder=t
(permute, sort) Reorder samples by decreasing depth entropy. Places high-information samples (high variance in depth across contigs) at indices 0, 1, 2 where QuickBin's indexing is most efficient. Improves binning performance for primary samples of interest.
minseed=2.5k
Minimum contig size used for entropy calculation during reordering. Entropy is calculated only from contigs >= this size, ignoring small contigs that add noise. Reduces impact of small, high-variance contigs on sample ordering.

Java Parameters

-Xmx
Set Java's maximum memory usage, overriding automatic detection. -Xmx20g specifies 20 GB of RAM; -Xmx4g specifies 4 GB. Default autodetection uses ~4GB; typical max is 85% of physical memory.
-Xms
Set Java's initial memory allocation. Less commonly used; setting equal to -Xmx prevents heap resizing during execution.
-eoom
Cause the process to exit cleanly if an out-of-memory exception occurs. Requires Java 8u92 or later. Without this flag, the JVM may hang on memory exhaustion.
-da
Disable Java assertions. Slightly improves performance; used in production deployments where assertions are not needed.

Algorithm Details

Coverage Matrix Format

CovMaker generates COV files containing a matrix where rows are contigs and columns are samples. Each cell contains the average depth (coverage) of that contig in that sample. The format is designed for efficient access by genomic binning algorithms.

Sample Condensing Strategy

Condensing uses a greedy merging algorithm optimized with pre-calculated proxy matrices:

Sample Reordering

Entropy-based reordering improves QuickBin's internal indexing by placing most informative samples at the beginning:

Memory Characteristics

Peak memory usage depends on operation:

SIMD Acceleration

Vector operations for cosine similarity calculations use SIMD (Single Instruction, Multiple Data) instructions when available, accelerating the similarity matrix computation phase.

Workflow Integration

Alignment to Binning Pipeline

CovMaker serves as the bridge between alignment and genomic binning:

Multi-Sample Metagenomics Workflows

For metagenomic assembly with read samples from multiple sources or conditions:

Integration with QuickBin

CovMaker output is specifically designed for QuickBin genomic binning:

Performance Characteristics

Speed

Performance depends primarily on input size and format:

Disk I/O

For large datasets with many samples:

Examples

Basic Coverage Matrix Generation

# Simple SAM to coverage conversion
covmaker.sh reads_aligned.sam out=coverage.cov

# From multiple BAM files
covmaker.sh in=sample1.bam,sample2.bam,sample3.bam out=combined.cov

Use case: Standard metagenomic workflow where read samples have been aligned to a reference assembly.

Filtering Small Contigs

# Only include contigs >= 1 kb
covmaker.sh alignments.sam out=coverage.cov mincontig=1000

# Very stringent filtering (only > 5 kb contigs)
covmaker.sh alignments.bam out=coverage.cov mincontig=5000

Purpose: Removing small contigs reduces memory usage and improves signal-to-noise ratio in binning. Small contigs often have unstable coverage estimates.

Sample Condensing with Default Settings

# Condense 20 samples to 10 using cosine similarity
covmaker.sh alignments.bam out=condensed.cov condense=10

# Aggressive condensing with multiple weighting metrics
covmaker.sh alignments.bam out=condensed.cov condense=5 cosine=t magnitude=t entropy=t

Effect: Similar samples (correlated depth patterns) are merged, reducing dimensionality. Cosine similarity identifies samples with similar abundance patterns. Magnitude weighting preserves low-depth samples.

Sample Reordering for Binning Quality

# Reorder samples by entropy (default)
covmaker.sh coverage.cov out=reordered.cov reorder=t

# Reorder with custom entropy threshold
covmaker.sh coverage.cov out=reordered.cov reorder=t minseed=5000

Benefit: Places most informative samples first, where QuickBin's indexing is most efficient. Improves binning accuracy for high-variance samples.

Combined Optimization: Condense and Reorder

# Merge samples AND reorder for maximum optimization
covmaker.sh many_samples.bam out=optimized.cov condense=12 reorder=t magnitude=t cosine=t

# With memory constraints
covmaker.sh -Xmx16g alignments.bam out=result.cov condense=8 readthreads=2 compare=50000

Workflow: Typical optimization for large metagenomics projects with many samples and limited computational resources.

Subset Extraction

# Extract coverage only for contigs in bin_genomes.fa
covmaker.sh ref=bin_genomes.fa in=full_coverage.cov out=bin_coverage.cov

# With contig filtering
covmaker.sh ref=target_contigs.fa in=alignments.sam out=subset.cov mincontig=2000

Use case: Create focused coverage matrices for specific contig subsets (e.g., a single putative genome or contig cluster).

Memory-Constrained Processing

# Read from COV (uses minimal memory), then reorder
covmaker.sh large_coverage.cov out=reordered.cov reorder=t

# Read from SAM with reduced threading to lower peak memory
covmaker.sh -Xmx8g alignments.sam out=coverage.cov readthreads=1 mincontig=1000

# Condense from COV input (very efficient)
covmaker.sh -Xmx4g full.cov out=condensed.cov condense=7

Efficiency: COV files as input are much more memory-efficient than SAM/BAM. Use when performing multiple operations on same data.

Complete Metagenomics Analysis Example

# Step 1: Align all reads to assembly
bbmap.sh ref=assembly.fa in=reads_R1.fastq in2=reads_R2.fastq out=alignment.sam

# Step 2: Optimize coverage matrix
covmaker.sh alignment.sam out=coverage.cov mincontig=1000 condense=15 reorder=t

# Step 3: Run genomic binning
quickbin.sh contigs=assembly.fa cov=coverage.cov out=bins.txt

# Step 4: Prepare genome-specific coverage (optional subset analysis)
covmaker.sh ref=bin1_contigs.fa in=coverage.cov out=bin1_cov.cov

Integration: Shows CovMaker's role in full metagenomic assembly and binning pipeline.

Troubleshooting

Out of Memory Errors

If you encounter "OutOfMemoryException":

Slow Condensing with Many Samples

If condensing takes very long:

Small or Empty Coverage Values

If contigs have very low coverage:

Support

For questions and support: