Skip to content

Instantly share code, notes, and snippets.

@brainstorm
Last active May 7, 2020 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brainstorm/83ab0fe91b3aaa1e73072e58319d15bb to your computer and use it in GitHub Desktop.
Save brainstorm/83ab0fe91b3aaa1e73072e58319d15bb to your computer and use it in GitHub Desktop.
htslib access (un)compressed offsets, now with newest htslib featuring hts_idx_load3 method.
#include <stdio.h>
#include <stdlib.h>
#include <htslib/hts.h>
#include <htslib/bgzf.h>
#include <hts_internal.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv)
{
hts_idx_t *baifile = NULL;
baifile = hts_idx_load3("htsnexus_test_NA12878.bam",
"htsnexus_test_NA12878.bam.bai",
HTS_FMT_BAI, 0);
}
all:
${CC} -g -Wall -I. -L. -I../rust-htslib/hts-sys/htslib -L../rust-htslib/hts-sys/htslib -I/usr/local/opt/bzip2/include -I/usr/local/Cellar/curl-openssl/7.68.0/include -I/usr/local/Cellar/xz/5.2.4/include -I/usr/local/opt/zlib/include s3_htslib.c -o s3_htslib -llzma -lz -lbz2 -lhts
clean:
rm s3_htslib
#include <stdio.h>
#include <stdlib.h>
#include <htslib/hfile.h>
#include <htslib/hts.h>
#include <htslib/sam.h>
#include <string.h>
#include <unistd.h>
//export DYLD_LIBRARY_PATH=/Users/romanvg/dev/umccr/htsget/rust-htslib/hts-sys/htslib
int main(int argc, char **argv)
{
samFile *fp_in = hts_open(argv[1],"r"); //open bam file
bam_hdr_t *bamHdr = sam_hdr_read(fp_in); //read header
printf("%s\n", bamHdr->target_name[1]);
}
@brainstorm
Copy link
Author

brainstorm commented Dec 9, 2019

On OSX Compile with:

$ make -j4 # for htslib itself
$ export DYLD_LIBRARY_PATH=./htslib
$ gcc -g -Wall -I. -I./htslib/ -L./htslib -I. -L. htsget_read_idx.c -o htsget -lhts && ./htsget

@brainstorm
Copy link
Author

Then, usage be like:

$ aws sso login
$ samtools view -H s3://umccr-research-dev/htsget/htsnexus_test_NA12878.bam
(...) (all header)
$ export DYLD_LIBRARY_PATH=/Users/romanvg/dev/umccr/htsget/rust-htslib/hts-sys/htslib
$ ./s3_htslib s3://umccr-research-dev/htsget/htsnexus_test_NA12878.bam
2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment