Can I read chrom, strand, pos, len from bam files without htslib?
3
0
Entering edit mode
5.5 years ago

I am having trouble compiling my program when I use htslib. Since this is software many other people are likely to use, I imagine my pain * 10000. Is there a way to read bam files without htslib? I just need the chrom, start, end and strand.

Otherwise, is there a way to include all of htslib in my software?

I am using the bioconda htslib and the flag -Ihtslib when compiling, but I get the error:

fatal error: htslib/sam.h: No such file or directory
 #include "htslib/sam.h"
          ^~~~~~~~~~~~~~
htslib • 1.7k views
ADD COMMENT
2
Entering edit mode
5.5 years ago

-Ihtslib means there is a directory named htslib in your current directory and this directory a bunch of *.h files.

if this directory is not in the current working directory , search for it (someting like)

find / -type -f -name "sam.h" 2> /dev/null

(wait if you have a large server). Then use

-I/path/to/the/directory/htsdlib

I am using the bioconda htslib

does it contains the sources of htslib ? try to install htslib from github without conda

ADD COMMENT
1
Entering edit mode

HTSlib's headers are set up so that they are in an htslib/ subdirectory of an includedir and used with #include "htslib/sam.h" etc. This avoids collisions with other libraries that might provide unrelated headers coincidentally named sam.h.

So if your find command shows /path/to/the/directory/htslib/sam.h, the -I option you should use will be -I/path/to/the/directory.

ADD REPLY
0
Entering edit mode

So I can include the whole htslib-project in my project if I want other users to compile easily?

ADD REPLY
0
Entering edit mode

So I can include the whole htslib-project in my project

what does 'include the whole htslib-project in my project ' means ? are you talking about git submodules ? https://git-scm.com/book/en/v2/Git-Tools-Submodules

ADD REPLY
0
Entering edit mode

I want people to not need to have htslib installed when they compile my software. So I can have a folder with htslib in my codebase and point to it.

ADD REPLY
0
Entering edit mode
ADD REPLY
0
Entering edit mode
5.5 years ago
endrebak852 ▴ 110

My solution. Works, but probably not the cleverest. Hinges on users having conda w/appropriate libs installed:

# In setup.py
from subprocess import check_output

conda_path = check_output("which conda", shell=True).decode().strip()

conda_include = []
conda_lib = []
if conda_path:
    conda_base = conda_path.replace("bin/conda", "")
    conda_include.append(conda_base + "include/")
    conda_lib.append(conda_base + "lib/")

extensions = [Extension("bla.src.reads_to_bins",
                        ["bla/src/reads_to_bins.pyx", "bla/src/gzstream.cpp"], language="c++",
                        include_dirs=conda_include,
                        library_dirs=conda_lib,
                        extra_compile_args=compile_options,
                        libraries=["z"]),

Chapter 7 of Computer Systems: A Programmer's Perspective was of great help. The book is highly recommended for people who want to understand computers from a C programmers perspective.

ADD COMMENT

Login before adding your answer.

Traffic: 2539 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6