Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #2
    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:
    blancha@hai04 ~/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.

    Comment


    • #3
      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.

      Comment


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

        Introduction In this intermittent series, I’ll be looking at the most common error messages your C++ compiler (and linker) can produce, explaining exactly what they mean, and showing how they…


        What program are your trying to write?

        Comment


        • #5
          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 $@

          .cpp.o:
          $(CC) $(CXXFLAGS) $< -o $@

          clean:
          - rm $(OBJECTS)

          spotless:
          - rm ${EXECUTABLE}

          Comment


          • #6
            I am trying to a write a program which requires taking BAM as an input file

            Comment


            • #7
              I cannot execute the bamtools executable in the bamtools/bin. Could this be the problem?

              Comment


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

                Code:
                $ sudo chmod a+x /path_to/bamtools

                Comment


                • #9
                  Thanks yes I got the executable working but I am still unable to include bam tools for developing code

                  Comment


                  • #10
                    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?

                    Comment


                    • #11
                      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

                      Comment


                      • #12
                        Have you looked at the wiki: https://github.com/pezmaster31/bamtools/wiki?

                        Comment


                        • #13
                          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.

                          Comment


                          • #14
                            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.

                            Comment


                            • #15
                              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, 03:55 PM.

                              Comment

                              Latest Articles

                              Collapse

                              • seqadmin
                                Strategies for Sequencing Challenging Samples
                                by seqadmin


                                Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
                                03-22-2024, 06:39 AM
                              • seqadmin
                                Techniques and Challenges in Conservation Genomics
                                by seqadmin



                                The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

                                Avian Conservation
                                Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
                                03-08-2024, 10:41 AM

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by seqadmin, Yesterday, 06:37 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, Yesterday, 06:07 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, 03-22-2024, 10:03 AM
                              0 responses
                              49 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, 03-21-2024, 07:32 AM
                              0 responses
                              67 views
                              0 likes
                              Last Post seqadmin  
                              Working...
                              X