Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

SIMD Smith-Waterman in the browser


Generate sample data

# Download sample files from bowtie2 repo
curl -o data/ref.fa ""
curl -o data/query.fastq ""

# Generate files with progressively more reads
nb_reads=(5 25 100 200 300 400 500)
for i in ${nb_reads[@]}; do
  head -n$((i * 4)) "data/query.fastq" > "data/reads_${i}.fastq"


var Module = typeof Module !== "undefined" ? Module : {};
Module.print = function(d) { };

Compile to WebAssembly

Using Emscripten 2.0.10

git clone
cd Complete-Striped-Smith-Waterman-Library/
git clone

# Shared flags
FLAGS="-O3 -pipe -s TOTAL_MEMORY=200MB -s EXTRA_EXPORTED_RUNTIME_METHODS=['callMain'] -s INVOKE_RUN=0 -s USE_ZLIB=1 --preload-file data/ --pre-js ./pre.js"

# With simd:
git stash && rm *.{wasm,html} && make clean
emmake make ssw_simd_on.html CC=emcc PROG=ssw_simd_on.html CFLAGS="$FLAGS -msse2 -msimd128"
/emsdk/upstream/bin/wasm-dis ssw_simd_on.wasm | grep v128 | wc -l  # 51

# Without simd:
git stash && rm *.{wasm,html} && make clean
sed -i -e 's|include <emmintrin.h>|include "simde/simde/x86/sse2.h"|g' *.c *.h
sed -i -e 's|__m|simde__m|g' *.c *.h
sed -i -e 's|_mm_|simde_mm_|g' *.c *.h
emmake make ssw_simd_off.html CC=emcc PROG=ssw_simd_off.html CFLAGS="$FLAGS"
/emsdk/upstream/bin/wasm-dis ssw_simd_off.wasm | grep v128 | wc -l  # 0

Compile to binary

make clean
make ssw_test_simd_on PROG=ssw_test_simd_on


Use default gap penalties: parameters = /data/ref.fa /data/read_${i}.fastq

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