• Welcome
  • Research
  • CV
  • Publications
  • Software
  • Blogs
  • Travel
  • Contact
  • Links

iAmphioxus

~ It's a long way from Amphioxus

iAmphioxus

Tag Archives: synteny

Wrapping R functions for use in Perl scripts

11 Tuesday Aug 2015

Posted by iAmphioxus in Bioinformatics, Blogs

≈ Leave a comment

Tags

rmath, synteny

It comes in handy when we can use R functions in our Perl scripts sometimes. So how could we do that?
Here is an exmaple:

Say we want to wrap the R function phyper(), dhyper(), ppois() and atan() as a Perl module named “rmath”,
first we need to create a file (here I named it as “rmath.in”) with the following content:

%module rmath
%{
       double phyper (double x, double NR, double NB, double n, int lower_tail, int log_p) ;
       double dhyper (double x, double NR, double NB, double n, int log_p) ;
       double ppois(double x, double lambda, int lower_tail, int log_p) ;
       double atan(double x) ;
%}
       double phyper (double x, double NR, double NB, double n, int lower_tail, int log_p) ;
       double dhyper (double x, double NR, double NB, double n, int log_p) ;
       double ppois(double x, double lambda, int lower_tail, int log_p) ;
       double atan(double x) ;

We will use swig (http://www.swig.org/) to wrap it. In Mac OSX, we can simply install it using homebrew (http://brew.sh/).


# install swig with homebrew
brew install swig

We need to download a temporary copy of R for compiling the standalone Rmath library.


# download R 
wget https://cran.r-project.org/src/base/R-3/R-3.2.1.tar.gz
tar xvzf R-3.2.1.tar.gz
ln -s R-3.2.1 R
cd R
./configure --prefix=/<Path to this temporary R>/R
cd ./src/nmath/standalone
make
make install

Now we use swig to wrap the R functions that we need into Perl modules.

swig -perl rmath.i 

rm *.o 
for f in *.c ; 
do 
gcc -I. -I../../../src/include -I../../../src/include -I./.. -I/usr/local/include -DHAVE_CONFIG_H -DMATHLIB_STANDALONE -arch x86_64 -g -O2 -std=gnu99 -c $f -o ${f/.c/.o} `perl -MExtUtils::Embed -e ccopts`;
ls -l ${f/.c/.o}; 
done rm sunif.o; 

gcc -bundle -flat_namespace -undefined dynamic_lookup -o rmath.bundle *.o
sudo cp rmath.bundle  /usr/local/ActivePerl-5.18/site/lib/ 
sudo cp rmath.pm  /usr/local/ActivePerl-5.18/site/lib/ 

Note: I am using ActivePerl-5.18 here since ActivePerl-5.22 doesn’t work for this for some reason.

References
https://cran.r-project.org/doc/manuals/r-release/R-admin.html#The-standalone-Rmath-library

43.704039 7.289707

Share this:

  • Email
  • Twitter
  • Facebook

Like this:

Like Loading...

Recent Posts

  • Using anaconda to manage local python environment
  • Local installation of ncbi-blast+ together with the nr and taxonomy database
  • Installing Augustus with manual bamtools installation
  • Custom installation of PacBio’s GenomicConsensus (Quiver)
  • Compiling 64-bit MUMmer

Archives

  • January 2018 (2)
  • May 2017 (2)
  • February 2016 (1)
  • January 2016 (1)
  • August 2015 (1)
  • July 2015 (1)
  • April 2015 (1)
  • June 2013 (1)
  • April 2013 (1)
  • October 2012 (1)
  • May 2012 (1)
  • April 2012 (1)
  • March 2012 (1)
  • February 2012 (2)
  • January 2012 (2)

Categories

  • Blogs (19)
    • Bioinformatics (14)
    • Journal club (3)

2012 annotation arabidopsis Augustus bamtools BioPerl blasr blast C. elegans Centennial CMake conda CPAN developmental biology embryonic genesis Ensembl evolution genewise Genome assembly GenomicConsensus Git GitHub Kent Utilities LiftOver Macports maker maternal effect multicellularity mummer MySQL ncbi new year nr PacBio parallel evolution Perl plant biology Python Quiver resolution Rice rmath SMRTanalysis snoscan Stampy synteny taxonomy tRNAscan-SE UCSC Genome Browser wise2 yeast

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 320 other followers

Blog Stats

  • 39,916 hits
Locations of visitors to this page
Map

Blog at WordPress.com.

  • Follow Following
    • iAmphioxus
    • Join 320 other followers
    • Already have a WordPress.com account? Log in now.
    • iAmphioxus
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
%d bloggers like this: