Procedure for compiling HTSLIB under emscripten
- Get emscripten, e.g. brew install emscripten
- Get zlib source distribution from zlib.org
- zlib - “emconfigure ./configure” in zlib
- zlib - comment out AR and ARFLAGS in Makefile (default libtool breaks things, at least on Mac)
- zlib - Run “emmake make”
- Get htslib source distribution from htslib.org
- htslib - Don’t run emconfigure ./configure as it gets confused by lack of zlib (not sure how to point to it?)
- htslib - Delete the AR = ar line from Makefile
- htslib - Add
$(AR) $ (ARFLAGS) in place of the existing $(AR) rc line from Makefile - htslib - Run this command to compile a program with htslib:
- emcc -pthread -L. -I ../zlib -I. ../zlib/libz.dylib libhts.dylib cram/cram_io.c hts.c hfile.c htsfile.c vcf.c sam.c bgzf.c cram/sam_header.c kstring.c md5.c cram/cram_encode.c cram/string_alloc.c cram/cram_stats.c cram/cram_codecs.c cram/thread_pool.c cram/pooled_alloc.c cram/cram_decode.c cram/rANS_static.c tbx.c cram/cram_samtools.c cram/mFILE.c cram/files.c cram/cram_index.c hfile_net.c knetfile.c faidx.c cram/open_trace_file.c -o /var/www/html/htslib_tester.html
- This should compile but give some reference errors for pthread (I think as long as pthread isn’t used, we should be ok?)
- Open http://localhost/htslib_tester.html
Now you will see it start running but the problem is that it is automatically converting socket calls to websockets and also needs you to make the client asynchronous (i.e. select instead of a blocking recv style call), so it just requires a some custom stuff in this respect. Alternatively, could download the chunks via ajax and then run through the htslib API Also note: I know that emcc command is ugly. should be able to access all those C files from the dylib but it doesn't for some reason (?)