ReduceColumns

Script: reducecolumns.sh Package: ml Class: ReduceColumns.java

Extracts specific columns from a tab-delimited vector file, producing a new file with only the selected columns. Useful for removing input dimensions from ML training data (e.g., dropping codon one-hots to test whether they contribute signal). Writes a new #dims header automatically. Processes files line-by-line with low memory overhead.

Basic Usage

reducecolumns.sh <in> <out> <col0> <col1> <col2> ...

This tool extracts specified columns from a tab-delimited input file and writes them to an output file. Column numbers are zero-indexed.

Parameters

This tool uses positional arguments rather than named parameters:

Parameters

in=<file>
Input tab-delimited vector file (with #dims header).
out=<file>
Output file with only the selected columns.
col0,col1,...
Zero-based column indices to keep, in order. The LAST column listed should be the target/output column. All other columns are treated as inputs. Supports three formats:
  • 5 – Single column (0-indexed).
  • 0-8 – Range: columns 0 through 8 inclusive.
  • 17+ – Open range: column 17 through the last column.
Example: 0-8 11 15 17+ keeps columns 0-8, 11, 15, and 17 onward. The last column in the expanded list becomes the target.

Memory Parameters

-Xmx
Maximum heap memory (default: 2g). Automatically calculated based on available system memory
-Xms
Initial heap memory (default: 2g). Set to match -Xmx for consistent performance

Examples

Extract First Three Columns

reducecolumns.sh input.txt output.txt 0 1 2

Extracts columns 0, 1, and 2 from input.txt and writes them to output.txt

Extract Non-Sequential Columns

reducecolumns.sh data.tsv subset.tsv 0 3 7 12

Extracts columns 0, 3, 7, and 12 from data.tsv, maintaining their order in the output

Single Column Extraction

reducecolumns.sh matrix.txt column5.txt 5

Extracts only column 5 from matrix.txt and saves it to column5.txt

Algorithm Details

ReduceColumns implements column extraction using ByteFile and ByteStreamWriter classes for file I/O with LineParser1 for tab-delimited parsing:

Processing Strategy

File Format Handling

Performance Characteristics

Use Cases

Input/Output Format

Input Requirements

Output Format

Technical Notes

Column Indexing

Columns are zero-indexed, meaning the first column is 0, second column is 1, etc. This follows standard programming conventions.

Error Handling

Memory Management

Default memory allocation is 2GB, automatically adjusted based on system availability. For very large files, memory usage remains constant due to streaming processing.

Support

For questions and support: