User:ElNando888/Emscripten

From Eterna Wiki

 

Porting ViennaRNA to javascript

 

Requirements

You will need :

  • Linux (for other OSes, well... good luck :P)
  • LLVM 3.2 or better
  • Clang 3.2 or better
  • the latest Emscripten, pulled from the Git

 

If you don't have them yet, get

  • Python
  • node.js
  • Git
  • JRE (apparently needed for optimizations in Emscripten generated code)

 

And there may be some other dependencies I forgot... YMMV.

 

Build LLVM + Clang

 

~$ wget http://llvm.org/releases/3.2/llvm-3.2.src.tar.gz
~$ tar xvfz llvm-3.2.src.tar.gz
~$ wget http://llvm.org/releases/3.2/clang-3.2.src.tar.gz
~$ tar xvfz clang-3.2.src.tar.gz

 

Clang must be built as part of LLVM, so first

~$ mv clang-3.2.src llvm-3.2.src/tools/clang

 

and then build

~$ cd llvm-3.2.src
~/llvm-3.2.src$ ./configure
~/llvm-3.2.src$ make

 

It takes a looooong time to build, be prepared. And don't bother to make install, Emscripten needs absolute paths anyway.

 

Setting up Emscripten

Just do

~$ git clone git://github.com/kripken/emscripten.git

 

and follow the instructions on https://github.com/kripken/emscripten/wiki/Tutorial, specially in the section "Setting up Emscripten"

 

Compiling Vienna

Copy your Vienna source package in a subdirectory of emscripten

~/emscripten$ tar xvfz ViennaRNA-2.1.1.tar.gz
~/emscripten$ cd ViennaRNA-2.1.1

 

I'm not sure what is causing problem with it, but since I don't need Perl extensions, I did

~/emscripten/ViennaRNA-2.1.1$ rm -rf Perl

 

And now, let's compile

~/emscripten/ViennaRNA-2.1.1$ ../emconfigure ./configure
~/emscripten/ViennaRNA-2.1.1$ ../emmake make

 

At this point, there are a lot of .o files, but they are not your usual .o files

 

Using the generated code

So far, I haven't been able to do much, but I could validate that the generated javascript code does indeed work, like this :

First, create a HTML page which includes the necessary APIs

~/emscripten/ViennaRNA-2.1.1$ ../emcc lib/*.o -o test.html -s EXPORTED_FUNCTIONS="['_fold','_space','_free','_pf_fold','_export_bppm','_energy_of_structure']"

 

Load that HTML page in Firefox, ignore the content, and then open the javascript Scratch Pad and input this :

var vrna_fold = Module.cwrap( 'fold', 'number', ['string','number'] );
var seq = "GGAAAGCCGCUAUCUAGAUCAACGGAAACGGUCGAAAGACGCGAAAGCAAAGAUCUAGAUAGAAAGGCGCAUGAGUUCGCUCAUGCAAAAGAAACAACAACAACAAC";
var struct = Module._space( seq.length );
fe = vrna_fold( seq, struct );
alert( Pointer_stringify( struct ) );
alert( fe );
Module._free( struct );

 

and run it. Well, it worked for me. Slow, but understandable since no optimizations at all.

 

Implementing

I've started working with the Git repository, and well, it's looking good so far :)

The code snippet, in a usable form

 

Vrna211-js.png