This is a test version of Biostars. For the public version, visit https://www.biostars.org.
bio::db::sam installation error

I installed bioperl in ubuntu 14 by

sudo apt-get install bioperl

Then installed samtools by sudo apt-get install samtools . Then I tried installing bio::db::sam perl module but I couldn't trace bam.h or libbam.a. So I installed samtools from source in home/ramesh8v/samtools-1.3.1, then I added this directory to environmental variable and I confirmed this by echo $PATH.
Now, I'm trying to install bio::db::sam by typing sudo cpan bio::db::sam but I'm running into this error,

Reading '/home/ramesh8v/.cpan/Metadata'
  Database was generated on Thu, 22 Sep 2016 04:17:02 GMT
Running install for module 'Bio::DB::Sam'
Running make for L/LD/LDS/Bio-SamTools-1.43.tar.gz
Checksum for /home/ramesh8v/.cpan/sources/authors/id/L/LD/LDS/Bio-SamTools-1.43.tar.gz ok

  CPAN.pm: Building L/LD/LDS/Bio-SamTools-1.43.tar.gz

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: /home/ramesh8v/samtools-1.3.1

Found /home/ramesh8v/samtools-1.3.1/bam.h and /home/ramesh8v/samtools-1.3.1/libbam.a.
Created MYMETA.yml and MYMETA.json
Creating new 'Build' script for 'Bio-SamTools' version '1.43'
Building Bio-SamTools
cc -I/home/ramesh8v/samtools-1.3.1 -Ic_bin -I/usr/lib/perl/5.18/CORE -fPIC -D_IOLIB=2 -D_FILE_OFFSET_BITS=64 -Wformat=0 -c -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fstack-protector -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -o c_bin/bam2bedgraph.o c_bin/bam2bedgraph.c
cc -I/home/ramesh8v/samtools-1.3.1 -Ic_bin -I/usr/lib/perl/5.18/CORE -DXS_VERSION="1.43" -DVERSION="1.43" -fPIC -D_IOLIB=2 -D_FILE_OFFSET_BITS=64 -Wformat=0 -c -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fstack-protector -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -o lib/Bio/DB/Sam.o lib/Bio/DB/Sam.c
lib/Bio/DB/Sam.xs: In function ‘XS_Bio__DB__Bam__Alignment_l_aux’:
lib/Bio/DB/Sam.xs:575:8: error: ‘bam1_t’ has no member named ‘l_aux’
       b->l_aux = SvIV(ST(1));
        ^
lib/Bio/DB/Sam.xs:576:13: error: ‘bam1_t’ has no member named ‘l_aux’
     RETVAL=b->l_aux;
             ^
lib/Bio/DB/Sam.c: In function ‘XS_Bio__DB__Bam__Index_coverage’:
lib/Bio/DB/Sam.xs:1008:20: warning: ignoring return value of ‘bgzf_seek’, declared with attribute warn_unused_result [-Wunused-result]
           bgzf_seek(bfp,0,0);
                    ^
In file included from lib/Bio/DB/Sam.xs:28:0:
lib/Bio/DB/Sam.c: In function ‘XS_Bio__DB__Bam_seek’:
/home/ramesh8v/samtools-1.3.1/bam.h:57:41: warning: ignoring return value of ‘bgzf_seek’, declared with attribute warn_unused_result [-Wunused-result]
 #define bam_seek(fp, pos, dir) bgzf_seek(fp, pos, dir)
                                         ^
lib/Bio/DB/Sam.xs:380:5: note: in expansion of macro ‘bam_seek’
     bam_seek(bam,pos,dir);
     ^
lib/Bio/DB/Sam.c: In function ‘XS_Bio__DB__Bam_header_write’:
lib/Bio/DB/Sam.xs:356:16: warning: ignoring return value of ‘bgzf_seek’, declared with attribute warn_unused_result [-Wunused-result]
       bgzf_seek(bam,0,0);
                ^
error building lib/Bio/DB/Sam.o from 'lib/Bio/DB/Sam.c' at /usr/share/perl/5.18/ExtUtils/CBuilder/Base.pm line 177.
  LDS/Bio-SamTools-1.43.tar.gz
  ./Build -- NOT OK
Running Build test
  Can't test without successful make
Running Build install
  Make had returned bad status, install seems impossible
bioperl samtools

Can you check what version of samtools was installed by apt-get (samtools --version)? I assume that is in your $PATH.

samtools --version gives me

samtools 1.3.1
Using htslib 1.3.1
Copyright (C) 2016 Genome Research Ltd.

Yes. it's in my path. I could able to use samtools without any problem.

README file for bio::db:sam says following.

This is a Perl interface to the SAMtools sequence alignment interface. It ONLY works on versions of Samtools up to 0.1.17. It does not work on version 1.0 or higher due to major changes in the library structure.

Many thanks for pointing that out

Aside from the version issue, you probably only installed the samtools binary and the Perl module needs the library files to compile against. So, I'm certain this won't work because there is possibly no library available and it would be the wrong version if it could be found.

2 answers

To save some space, I'll just point you to StackOverflow where I've answered this a couple of times. It is important that you compile samtools correctly, make sure it can be found by the Perl module, and use a version that the Perl module was designed to work with.

That will solve the question, but the problem you may be creating for yourself is that neither of these packages are being developed now. I recommend you use Bio::DB::HTS instead, which is based on Bio::DB::Sam. Bio::DB::HTS provides bindings to HTSlib and is a safer bet to support formats and operations currently in use.

Thanks! I try that and let you know

If you want to try Bio::DB::HTS, fetch the latest release, then do the normal configure and make followed by export HTSLIB_DIR=path where "path" is the source distribution. Then you can do cpanm Bio::DB::HTS with no problem.

If you are using code that already exists then stick to Bio::DB::Sam because it is stable and there's no reason to rewrite it.

Thanks a ton... Finally, I installed :)

Hey, your other useful comment got deleted. Sorry about that.

How about sudo apt install libbio-samtools ?

Log in to answer this question.