Skip to content

Commit

Permalink
Merge pull request #9 from daviesrob/ref_fix
Browse files Browse the repository at this point in the history
Use HTSlib API to set the CRAM reference
  • Loading branch information
niemasd authored Sep 29, 2023
2 parents fd17c50 + 64ae7e8 commit 72c2382
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# use g++ compiler
CXX=g++
CXXFLAGS?=-std=c++11 -fpermissive
CXXFLAGS?=-Wall -pedantic -std=c++11

# flag specifications for release and debug
RELEASEFLAGS?=$(CXXFLAGS) -O3
Expand Down
10 changes: 5 additions & 5 deletions count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ counts_t compute_counts(const char* const in_reads_fn, std::string const & ref,
std::cerr << "Not a CRAM/BAM/SAM file: " << in_reads_fn << std::endl; exit(1);
}

// if CRAM file, load reference in htslib
if(reads->format.format == cram) {
hts_set_opt(reads, CRAM_OPT_REFERENCE, user_args.in_ref_fn);
}

// set up htsFile for parsing
bam_hdr_t* header = sam_hdr_read(reads);
if(!header) {
Expand All @@ -75,11 +80,6 @@ counts_t compute_counts(const char* const in_reads_fn, std::string const & ref,
std::cerr << "CRAM/BAM/SAM has " << header->n_targets << " references, but it should have exactly 1: " << in_reads_fn << std::endl; exit(1);
}

// if CRAM file, load reference in htslib
if(reads->format.format == cram) {
cram_load_reference((reads->fp).cram, user_args.in_ref_fn);
}

// prepare helper variables for computing counts
counts_t counts; // counts_t object to store the counts themselves
bam1_t* src = bam_init1(); // holds the current alignment record, which is read by sam_read1()
Expand Down
1 change: 0 additions & 1 deletion count.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#ifndef COUNT_H
#define COUNT_H
#include "htslib/cram/cram.h"
#include "common.h"
#include "argparse.h"

Expand Down

0 comments on commit 72c2382

Please sign in to comment.