SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble Downloading bamtools on macosx nickhill Bioinformatics 5 10-29-2015 07:59 PM
bamtools-2.3.0 will not work godzilla07 Bioinformatics 2 11-09-2013 04:53 PM
compiling bamtools issue: zlib.h not found orionzhou Bioinformatics 1 10-13-2011 06:01 PM

Reply
 
Thread Tools
Old 10-30-2015, 11:39 AM   #1
nickhill
Member
 
Location: Santa Cruz, CA

Join Date: Oct 2015
Posts: 11
Default Trouble Using BamTools

Hi everyone,

I have successfully downloaded BamTools but am still having trouble incorporating it into my code. When I compile with make, I get the errors like:

main.cpp:7:10: fatal error: 'api/BamMultiReader.h' file not found
#include "api/BamMultiReader.h"

It seems like the download is not working but I am quite sure it worked. If I ls into my bamtools folder I see:

CMakeLists.txt README build include src
LICENSE bin docs lib

The api folder with its contents is located in include. It seems like I have the necessary libraries. Is there something I need to include in my Makefile to be able use the bamtools libraries in my code?
nickhill is offline   Reply With Quote
Old 10-30-2015, 01:01 PM   #2
blancha
Senior Member
 
Location: Montreal

Join Date: May 2013
Posts: 367
Default

It's possible that you are not including the path to the header files when compiling.

First, you can check that you indeed have the header files.
Code:
[email protected] ~/Desktop$ ls /Applications/bamtools/include/api/
BamAlgorithms.h           BamIndex.h                IBamIODevice.h            SamProgramChain.h         SamSequenceDictionary.h
BamAlignment.h            BamMultiReader.h          SamConstants.h            SamReadGroup.h            algorithms/
BamAux.h                  BamReader.h               SamHeader.h               SamReadGroupDictionary.h  api_global.h
BamConstants.h            BamWriter.h               SamProgram.h              SamSequence.h
Then, you just need to include the path to the header file when compiling.
Code:
g++ test.cpp -I /Applications/bamtools/include/ -L /Applications/bamtools/lib/ -lbamtools
I know that you asked for a Makefile, so I'll try and write the equivalent command later using a Make file.
As you can see, I'm not a C++ programmer, so someone else on the forum will probably explain to you better than me that you need to include the path to the header files when compiling, but I'm answering the question since no one has tried yet.

If I put the wrong path to the header file or don't include the path at all, I get the same error message as you, leading me to believe this could be the bug.
blancha is offline   Reply With Quote
Old 10-30-2015, 01:23 PM   #3
blancha
Senior Member
 
Location: Montreal

Join Date: May 2013
Posts: 367
Default

Ok, here is my MakeFile to compile the program in the Bamtools API tutorial.

Code:
CC=g++
IDIR=/Applications/bamtools/include/
LDIR=/Applications/bamtools/lib/
CFLAGS=-I $(IDIR)
LFLAGS=-L $(LDIR) -lbamtools

test: test.cpp
        $(CC) $(CFLAGS) $(LFLAGS) test.cpp
It's my first time writing a Makefile, so I hope it's not a case of the blind leading the blind.

I do believe your bug is simply that you are not including the path to the header files when compiling, assuming that the header files are indeed in the include bamtools subfolder.
blancha is offline   Reply With Quote
Old 10-30-2015, 01:58 PM   #4
blancha
Senior Member
 
Location: Montreal

Join Date: May 2013
Posts: 367
Default

This site has a nice explanation for all the possible causes and solutions to your bug.

https://latedev.wordpress.com/2013/0...-or-directory/

What program are your trying to write?
blancha is offline   Reply With Quote
Old 10-30-2015, 02:03 PM   #5
nickhill
Member
 
Location: Santa Cruz, CA

Join Date: Oct 2015
Posts: 11
Default

I included the path and still receive errors about using BamTools

error: expected namespace name
using namespace BamTools;
^
Here is my Makefile:

CC = g++ -g -O0 -Wall -Wextra -std=gnu++11
IDIR = /Users/nicholashill/src/new/bamtools/include/
LDIR = /Users/nicholashill/src/new/bamtools/lib/
CFLAGS=-I $(IDIR)
LFLAGS=-L $(LDIR) -lbamtools
SOURCES = main.cpp new.cpp

CPPHEADER = new.h
OBJECTS = $(SOURCES:.cpp=.o)

EXECUTABLE = new

main: main.cpp
$(CC) $(CFLAGS) $(LFLAGS) main.cpp

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) -o [email protected]

.cpp.o:
$(CC) $(CXXFLAGS) $< -o [email protected]

clean:
- rm $(OBJECTS)

spotless:
- rm ${EXECUTABLE}
nickhill is offline   Reply With Quote
Old 10-30-2015, 02:12 PM   #6
nickhill
Member
 
Location: Santa Cruz, CA

Join Date: Oct 2015
Posts: 11
Default

I am trying to a write a program which requires taking BAM as an input file
nickhill is offline   Reply With Quote
Old 10-30-2015, 02:28 PM   #7
nickhill
Member
 
Location: Santa Cruz, CA

Join Date: Oct 2015
Posts: 11
Default

I cannot execute the bamtools executable in the bamtools/bin. Could this be the problem?
nickhill is offline   Reply With Quote
Old 10-30-2015, 02:38 PM   #8
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,800
Default

Add execute permissions to the file (you are on a Mac?)

Code:
$ sudo chmod a+x /path_to/bamtools
GenoMax is offline   Reply With Quote
Old 10-30-2015, 02:45 PM   #9
nickhill
Member
 
Location: Santa Cruz, CA

Join Date: Oct 2015
Posts: 11
Default

Thanks yes I got the executable working but I am still unable to include bam tools for developing code
nickhill is offline   Reply With Quote
Old 10-30-2015, 02:48 PM   #10
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,800
Default

What exactly are you trying to do? Use bamtools code in your own code/extend that code or are you just interested in calling the bamtools binary from your own program?
GenoMax is offline   Reply With Quote
Old 10-30-2015, 02:53 PM   #11
nickhill
Member
 
Location: Santa Cruz, CA

Join Date: Oct 2015
Posts: 11
Default

Just use bamtools in my own code. I've just been confused about whether I have bamtools since the compiler doesn't recognize when I incorporate it in my code
nickhill is offline   Reply With Quote
Old 10-30-2015, 03:04 PM   #12
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,800
Default

Have you looked at the wiki: https://github.com/pezmaster31/bamtools/wiki?
GenoMax is offline   Reply With Quote
Old 10-30-2015, 03:14 PM   #13
nickhill
Member
 
Location: Santa Cruz, CA

Join Date: Oct 2015
Posts: 11
Default

Yeah i've been looking at the API tutorial for help which is why i've been trying to edit my Makefile to include the library and include paths but have been unsuccessful. I apologize for my ignorance, this is the first time i've tried to use outside developers libraries in my own code.
nickhill is offline   Reply With Quote
Old 10-30-2015, 04:41 PM   #14
blancha
Senior Member
 
Location: Montreal

Join Date: May 2013
Posts: 367
Default

You'll get that error message if you don't include the BamTools header file before using the namespace.
If I delete the first two lines in my test file that include the BamTools header, I can reproduce your error message.
I can't troubleshoot more, without seeing the first few lines of your source code, but that is the bug.

These are really basic C++ programming questions, rather than questions specific to BamTools.
You might find better answers, and more expertise in a C++ programming forum.
That being said, I'm happy to try and answer the questions to the best of my ability, and there are some top-notch C++ programmers on this forum.

Also, as you must have realized, there is an h missing in the first line of the example given in the BamTools manual, and the quotes are also incorrect if you just copy-paste the code.
blancha is offline   Reply With Quote
Old 10-30-2015, 04:53 PM   #15
blancha
Senior Member
 
Location: Montreal

Join Date: May 2013
Posts: 367
Default

Here is an example illustrating how this error will appear if you don't include the BamTools header in the source code, before using the namespace.

I just compile the original code first, without any problems.
After I delete the first two lines, which include the BamTools header files, I get the same error message you reported.
I use head to show the first few lines of my source code, and sed to delete the first two lines.
Code:
MacBook-Pro:Downloads blancha$ head test.cpp
#include "api/BamMultiReader.h"
#include "api/BamWriter.h"
using namespace BamTools;
using namespace std;

int main() {
// at some point, start our merge operation
vector<string> inputFilenames;
string outputFilename;
// provide some input & output filenames
MacBook-Pro:Downloads blancha$ make
g++ -I ~/Downloads/bamtools/include/ -L ~/Downloads/bamtools/lib/ -lbamtools test.cpp
MacBook-Pro:Downloads blancha$ sed -i.bak '1,2d' test.cpp
MacBook-Pro:Downloads blancha$ head test.cpp
using namespace BamTools;
using namespace std;

int main() {
// at some point, start our merge operation
vector<string> inputFilenames;
string outputFilename;
// provide some input & output filenames
// attempt to open our BamMultiReader
BamMultiReader reader;
MacBook-Pro:Downloads blancha$ make
g++ -I ~/Downloads/bamtools/include/ -L ~/Downloads/bamtools/lib/ -lbamtools test.cpp
test.cpp:1:17: error: expected namespace name
using namespace BamTools;

Last edited by blancha; 10-30-2015 at 04:55 PM.
blancha is offline   Reply With Quote
Old 10-30-2015, 05:02 PM   #16
nickhill
Member
 
Location: Santa Cruz, CA

Join Date: Oct 2015
Posts: 11
Default

I've since managed to get BamTools working properly. Thank you for taking the time to help me
nickhill is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 02:31 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO