Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Bio::DB::Sam perl module

I am trying to install a perl module Bio::DB::Sam on my home directory on a remote server.

I downloaded the module, extracted the files, and ran:

perl Build.pl prefix=~/local

this is what happens next:

This module requires samtools 0.1.10 or higher (samtools.sourceforge.net).
Please enter the location of the bam.h and compiled libbam.a files: **/some_places/samtools-0.1.19**

Found /some_places/samtools-0.1.19/bam.h and /some_places/samtools-0.1.19/libbam.a.
Created MYMETA.yml and MYMETA.json
Creating new 'Build' script for 'Bio-SamTools' version '1.39'

Next when I try to run:

./Build

this is what I get:

  Building Bio-SamTools
gcc -shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -o blib/arch/auto/Bio/DB/Sam/Sam.so lib/Bio/DB/Sam.o c_bin/bam2bedgraph.o -L/some_places/samtools-0.1.19 -lbam -lpthread -lz
/usr/bin/ld: /some_places/samtools-0.1.19/libbam.a(bgzf.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/some_places/samtools-0.1.19/libbam.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
error building blib/arch/auto/Bio/DB/Sam/Sam.so from lib/Bio/DB/Sam.o c_bin/bam2bedgraph.o at ~/perl5/lib/perl5/ExtUtils/CBuilder/Base.pm line 323.

I did google the possible solutions and tried a couple, but they didn't work, e.g. --enable-shared OR export CXXFLAGS="$CXXFLAGS -fPIC".

I have already have Bioperl installed on my home directory.

Any help would be appreciated.

Cheers

like image 922
Nikleotide Avatar asked Aug 28 '14 19:08

Nikleotide


3 Answers

Here is a script that will fetch the SAMtools source and compile it, then fetch and compile the Perl bindings.

wget http://sourceforge.net/projects/samtools/files/samtools/0.1.18/samtools-0.1.18.tar.bz2
tar xjf samtools-0.1.18.tar.bz2 && cd samtools-0.1.18
make CFLAGS=-fPIC
export SAMTOOLS=`pwd`
cpanm Bio::DB::Sam

Part of the problem you were likely seeing is that the SAMtools project has recently undergone some major code reorganization (and this has naturally made it difficult to work with external language bindings).

like image 111
SES Avatar answered Sep 18 '22 01:09

SES


I fixed this issue by remaking samtools with the -fPIC parameter

make clean
make CXXFLAGS=-fPIC CFLAGS=-fPIC CPPFLAGS=-fPIC

then installed using cpan.

cpan[2]> install Bio::DB::Sam 
like image 45
user4208795 Avatar answered Sep 18 '22 01:09

user4208795


[Solved]

wget http://sourceforge.net/projects/samtools/files/samtools/0.1.18/samtools-0.1.18.tar.bz2

tar xjf samtools-0.1.18.tar.bz2 && cd samtools-0.1.18

make CFLAGS=-fPIC

enter cpan in terminal and enter

install Bio::DB::Sam

Be carefully:

You can not use the following command:

perl -MCPAN -Mlocal::lib -e 'CPAN::install(Bio::DB::Sam)'

You can only use cpan and then use

install Bio::DB::Sam
like image 43
Shicheng Guo Avatar answered Sep 19 '22 01:09

Shicheng Guo