Skip to content

ReadName tokenization and post tokenization compression / decompression pipeline for ReadNames - #29

Open
chris7716 wants to merge 3 commits into
NickRoz1:masterfrom
chris7716:rn-tokenization
Open

chris7716 wants to merge 3 commits into
NickRoz1:masterfrom
chris7716:rn-tokenization

Conversation

@chris7716

@chris7716 chris7716 commented Aug 29, 2025

Copy link
Copy Markdown
Contributor

Conversion example:

String: "HWUSI-EAS566_0007:2:30:18804:9636#0|AGC" (39 bytes, variable)
   ↓
Token: {
    instrument_id: 0,      // Points to dictionary[0] = "HWUSI-EAS566_0007"
    run_id: 3234567890,    // Hash of instrument (legacy format)
    flowcell_id: 0,        // Legacy format
    lane: 2,               // Parsed from string
    tile: 30,              // Parsed from string  
    x_coord: 18804,        // Parsed from string
    y_coord: 9636,         // Parsed from string
    umi_id: Some(0),       // Points to dictionary[0] = "AGC"
    read_num: 1,           // Default
    flags: 0,              // Default
    index_id: Some(0),     // Points to dictionary[0] = "0"
} (22 bytes, fixed)

Complete ReadName compression pipeline:

Original Read Names (strings)
    ↓ Tokenization
Fixed Binary Records + Dictionary
    ↓ Post-Tokenization Compression
    ├─ Delta encoding on coordinates  
    ├─ RLE on repeated metadata
    ├─ Huffman on value distributions
    └─ Deflate on optimized streams
    ↓
Highly Compressed Binary Data
hasitha@Hasithas-MacBook-Air gbam % ./target/release/gbam_binary -c test_data/little.bam -o test_data/little-with-tokenized-rn.gbam                   
hasitha@Hasithas-MacBook-Air gbam % ./target/release/gbam_binary --convert-to-bam test_data/little-with-tokenized-rn.gbam -o test_data/reconverted.bam
hasitha@Hasithas-MacBook-Air gbam % samtools view test_data/little.bam > test_data/original.txt                                   
hasitha@Hasithas-MacBook-Air gbam % samtools view test_data/reconverted.bam > test_data/reconverted.txt                           
hasitha@Hasithas-MacBook-Air gbam % diff test_data/original.txt test_data/reconverted.txt                                          
hasitha@Hasithas-MacBook-Air gbam % ls -lh test_data 
total 1911448
-rw-r--r--  1 hasitha  staff    38M Aug 29 11:08 little-with-tokenized-rn.gbam
-rw-r--r--  1 hasitha  staff    41M Aug 29 11:00 little-without-tokenized-rn.gbam
-rw-r--r--@ 1 hasitha  staff    49M Oct  4  2024 little.bam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant