Skip to content

Commit 6c5860e

Browse files
committed
Added version and test files
1 parent f151500 commit 6c5860e

File tree

7 files changed

+19
-7
lines changed

7 files changed

+19
-7
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ tabix++: $(OBJS) main.cpp $(HTS_LIB)
6565
$(CXX) $(CXXFLAGS) -o $@ main.cpp $(OBJS) $(INCLUDES) $(LIBPATH) \
6666
-lhts -lpthread -lm -lz -lcurl -llzma -lbz2
6767

68+
test: all
69+
./tabix++ test/vcf_file.vcf.gz
70+
6871
install: all
6972
$(MKDIR) $(DESTDIR)$(PREFIX)/bin
7073
$(MKDIR) $(DESTDIR)$(PREFIX)/include

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This is a C++ wrapper around [tabix project](http://samtools.sourceforge.net/tab
55
```sh
66
git submodule update --init --recursive
77
make CC=gcc -j 16
8+
make test
89
```
910

1011
See also [guix.scm](./guix.scm) for the build environment we test with.

main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33

44
using namespace std;
55

6+
const string VERSION = "1.1.1";
7+
68
int main(int argc, char** argv) {
79

810
if (argc < 2) {
9-
cerr << argv[0] << " [file] [ [region] ... ]" << endl
11+
cout << argv[0] << " [file] [ [region] ... ]" << endl
1012
<< "Writes out regions from bgzf-compressed, tabix-indexed file." << endl
1113
<< "Supply 'header' to print out the header, and no regions to" << endl
12-
<< "print the contents of the entire file." << endl;
14+
<< "print the contents of the entire file." << endl << endl
15+
<< "Version " << VERSION << endl;
1316
return 1;
1417
}
1518

@@ -22,7 +25,7 @@ int main(int argc, char** argv) {
2225
Tabix file(filename);
2326

2427
if (!regions.empty()) {
25-
for (vector<string>::iterator r = regions.begin(); r != regions.end(); ++r) {
28+
for (vector<string>::iterator r = regions.begin(); r != regions.end(); ++r) {
2629
string& region = *r;
2730
if (region == "header") {
2831
string header;

tabix.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,31 @@ Tabix::Tabix(string& file) {
1313
char *fnidx = (char*) calloc(strlen(cfilename) + 5, 1);
1414
strcat(strcpy(fnidx, cfilename), ".tbi");
1515

16-
hFILE *fp = hopen(cfilename, "r");
17-
if (fp == NULL) {
16+
hFILE *fp;
17+
if (!(fp = hopen(cfilename, "r"))) {
1818
cerr << "can't open " << cfilename;
1919
return;
2020
}
2121

2222
htsFormat fmt;
23-
if ( hts_detect_format(fp,&fmt)!=1 )
23+
if ( hts_detect_format(fp,&fmt) < 0 )
2424
{
2525
cerr << "[tabix++] was bgzip used to compress this file? " << file << endl;
2626
free(fnidx);
2727
exit(1);
2828
}
29-
hclose(fp);
29+
if (hclose(fp) != 0) {
30+
cerr << "can't close " << cfilename;
31+
return;
32+
}
33+
3034
// Common source of errors: new VCF is used with an old index
3135
stat(fnidx, &stat_tbi);
3236
stat(cfilename, &stat_vcf);
3337
if ( stat_vcf.st_mtime > stat_tbi.st_mtime )
3438
{
3539
cerr << "[tabix++] the index file is older than the vcf file. Please use '-f' to overwrite or reindex." << endl;
40+
3641
free(fnidx);
3742
exit(1);
3843
}

test/vcf_file.vcf.gz

1019 Bytes
Binary file not shown.

test/vcf_file.vcf.gz.gzi

8 Bytes
Binary file not shown.

test/vcf_file.vcf.gz.tbi

257 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)