Commit 4b17a10f authored by Michael R. Crusoe's avatar Michael R. Crusoe 🏳️‍🌈
Browse files

New upstream version 1.1.0

parent f9c33b4e
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -8,15 +8,19 @@ INCLUDES?= -Ihtslib
HTS_HEADERS?=	htslib/htslib/bgzf.h htslib/htslib/tbx.h
HTS_LIB?=	htslib/libhts.a
LIBPATH?=	-L. -Lhtslib

LIBS?=	-lhts -lpthread -lm -lbz2 -llzma -lz
DFLAGS=		-D_FILE_OFFSET_BITS=64 -D_USE_KNETFILE
PROG=		tabix++
SUBDIRS=.

ifeq ($(OS),Windows_NT)
	LIBS += -lws2_32
endif

.SUFFIXES:.c .o

.c.o:
	$(CC) -c $(CXXFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@
	$(CC) $(CPPFLAGS) -c $(CXXFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@

all-recur lib-recur clean-recur cleanlocal-recur install-recur:
	@target=`echo $@ | sed s/-recur//`; \
@@ -32,14 +36,13 @@ all-recur lib-recur clean-recur cleanlocal-recur install-recur:
all:	$(PROG)

tabix.o: $(HTS_HEADERS) tabix.cpp tabix.hpp
	$(CXX) $(CXXFLAGS) -c tabix.cpp $(INCLUDES)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c tabix.cpp $(INCLUDES)

htslib/libhts.a:
	cd htslib && $(MAKE) lib-static

tabix++: tabix.o main.cpp $(HTS_LIB)
	$(CXX) $(CXXFLAGS) -o $@ main.cpp tabix.o $(INCLUDES) $(LIBPATH) \
		-lhts -lpthread -lm -lz
	$(CXX) $(LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) -o $@ main.cpp tabix.o $(INCLUDES) $(LIBPATH) $(LIBS)

cleanlocal:
	rm -fr gmon.out *.o a.out *.dSYM $(PROG) *~ *.a tabix.aux tabix.log \
+42 −6
Original line number Diff line number Diff line
@@ -5,6 +5,9 @@ Tabix::Tabix(void) { }
Tabix::Tabix(string& file) {
    has_jumped = false;
    filename = file;
    str.l = 0;
    str.m = 0;
    str.s = NULL;
    const char* cfilename = file.c_str();
    struct stat stat_tbi,stat_vcf;
    char *fnidx = (char*) calloc(strlen(cfilename) + 5, 1);
@@ -47,18 +50,22 @@ Tabix::Tabix(string& file) {

    // set up the iterator, defaults to the beginning
    current_chrom = chroms.begin();
    iter = tbx_itr_querys(tbx, current_chrom->c_str());
    iter = tbx_itr_querys(tbx, (current_chrom != chroms.end() ? current_chrom->c_str() : ""));

}

Tabix::~Tabix(void) {
    tbx_itr_destroy(iter);
    tbx_destroy(tbx);
    free(str.s);
}

const kstring_t * Tabix::getKstringPtr(){
    return &str;
}

void Tabix::getHeader(string& header) {
    header.clear();
    kstring_t str = {0,0,0};
    while ( hts_getline(fn, KS_SEP_LINE, &str) >= 0 ) {
        if ( !str.l || str.s[0]!=tbx->conf.meta_char ) {
            break;
@@ -70,7 +77,7 @@ void Tabix::getHeader(string& header) {
    // set back to start
    current_chrom = chroms.begin();
    if (iter) tbx_itr_destroy(iter);
    iter = tbx_itr_querys(tbx, current_chrom->c_str());
    iter = tbx_itr_querys(tbx, (current_chrom != chroms.end() ? current_chrom->c_str() : ""));
}

bool Tabix::setRegion(string& region) {
@@ -81,7 +88,6 @@ bool Tabix::setRegion(string& region) {
}

bool Tabix::getNextLine(string& line) {
    kstring_t str = {0,0,0};
    if (has_jumped) {
        if (iter && tbx_itr_next(fn, tbx, iter, &str) >= 0) {
            line = string(str.s);
@@ -93,8 +99,8 @@ bool Tabix::getNextLine(string& line) {
            line = string(str.s);
            return true;
        } else {
            ++current_chrom;
            while (current_chrom != chroms.end()) {
            // While we aren't at the end, advance. While we're still not at the end...
            while (current_chrom != chroms.end() && ++current_chrom != chroms.end()) {
                tbx_itr_destroy(iter);
                iter = tbx_itr_querys(tbx, current_chrom->c_str());
                if (iter && tbx_itr_next(fn, tbx, iter, &str) >= 0) {
@@ -108,3 +114,33 @@ bool Tabix::getNextLine(string& line) {
        }
    }
}

bool Tabix::getNextLineKS() {
    if (has_jumped) {
        if (iter && 
	    tbx_itr_next(fn, tbx, iter, &str) >= 0) {
            //line = &str;
            return true;
        } else 
	    return false;
    } else { // step through all sequences in the file
        // we've never jumped, so read everything
        if (iter && tbx_itr_next(fn, tbx, iter, &str) >= 0) {
            //line = &str;
            return true;
        } else {
            // While we aren't at the end, advance. While we're still not at the end...
            while (current_chrom != chroms.end() && ++current_chrom != chroms.end()) {
                tbx_itr_destroy(iter);
                iter = tbx_itr_querys(tbx, current_chrom->c_str());
                if (iter && tbx_itr_next(fn, tbx, iter, &str) >= 0) {
                    //line = &str;
                    return true;
                } else {
                    ++current_chrom;
                }
            }
            return false;
        }
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ class Tabix {

    htsFile* fn;
    tbx_t* tbx;
    kstring_t str;
    hts_itr_t* iter;
    const tbx_conf_t *idxconf;
    int tid, beg, end;
@@ -23,7 +24,6 @@ class Tabix {
    vector<string>::iterator current_chrom;

public:

    string filename;
    vector<string> chroms;

@@ -31,8 +31,10 @@ public:
    Tabix(string& file);
    ~Tabix(void);

    const kstring_t * getKstringPtr();
    void getHeader(string& header);
    bool setRegion(string& region);
    bool getNextLine(string& line);
    bool getNextLineKS();

};