Loading LICENSE 0 → 100644 +21 −0 Original line number Diff line number Diff line The MIT License (MIT) Copyright (c) 2015 Brent Pedersen and Aaron Quinlan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. grabix.cpp +19 −11 Original line number Diff line number Diff line #include <cstdlib> #include <iostream> #include <stdio.h> #include <fstream> #include <vector> #include <unistd.h> Loading Loading @@ -56,6 +57,12 @@ random access via the BGZF seek utility */ int create_grabix_index(string bgzf_file) { if (!bgzf_is_bgzf(bgzf_file.c_str())) { cerr << "[grabix] " << bgzf_file << " doesn't exist or wasn't compressed with bgzip" << endl; exit (1); } BGZF *bgzf_fp = bgzf_open(bgzf_file.c_str(), "r"); if (bgzf_fp == NULL) { Loading @@ -64,7 +71,7 @@ int create_grabix_index(string bgzf_file) } // create an index for writing string index_file_name = bgzf_file + ".gbi"; string index_file_name = bgzf_file + ".gbi.tmp"; ofstream index_file(index_file_name.c_str(), ios::out); // add the offset for the end of the header to the index Loading Loading @@ -92,15 +99,15 @@ int create_grabix_index(string bgzf_file) int64_t total_lines = 1; vector<int64_t> chunk_positions; chunk_positions.push_back (prev_offset); bool eof = false; int eof = 1; while (true) { // grab the next line and store the offset eof = bgzf_getline_counting(bgzf_fp); eof = bgzf_getline(bgzf_fp, '\n', line); offset = bgzf_tell(bgzf_fp); chunk_count++; // stop if we have encountered an empty line if (eof) if (eof < 0 || offset == prev_offset) { if (bgzf_check_EOF(bgzf_fp) == 1) { if (offset > prev_offset) { Loading @@ -109,6 +116,7 @@ int create_grabix_index(string bgzf_file) } break; } break; } // store the offset of this chunk start else if (chunk_count == CHUNK_SIZE) Loading @@ -129,7 +137,7 @@ int create_grabix_index(string bgzf_file) } index_file.close(); return EXIT_SUCCESS; return std::rename((bgzf_file + ".gbi.tmp").c_str(), (bgzf_file + ".gbi").c_str()); } /* Loading Loading @@ -206,7 +214,7 @@ int grab(string bgzf_file, int64_t from_line, int64_t to_line) line->l = 0; line->m = 0; while ((status = bgzf_getline(bgzf_fp, '\n', line)) != 0) while ((status = bgzf_getline(bgzf_fp, '\n', line)) > 0) { if (line->s[0] == '#') printf("%s\n", line->s); Loading grabix.h +1 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ using namespace std; #include "bgzf.h" #define VERSION "0.1.6" #define VERSION "0.1.8" // we only want to store the offset for every 10000th // line. otherwise, were we to store the position of every // line in the file, the index could become very large for Loading test.sh +21 −3 Original line number Diff line number Diff line Loading @@ -3,17 +3,35 @@ make FQ=test.cnt.gz rm -f ${FQ}{,.gbi} lines=50000 lines=500000 python tests/make-test-fastq.py $lines | bgzip -c > $FQ ./grabix index $FQ echo "indexing" time ./grabix index $FQ echo "indexed" python tests/test-fastq.py $FQ a=$(grabix grab test.cnt.gz $(($lines * 4))) a=$(./grabix grab test.cnt.gz $(($lines * 4))) b=$(zless $FQ | tail -1) if [[ "$a" != "$b" ]]; then echo FAIL last record exit 1 else echo OK last record fi rm -f ${FQ}{,.gbi} rm -f tests/empty.fastq.gz.gbi ./grabix index tests/empty.fastq.gz a=$(cat tests/empty.fastq.gz.gbi | awk 'NR == 2') if [[ "$a" != "16" ]]; then echo FAIL index wrong size exit 1 else echo "OK index size" fi for V in \ test.PLs.vcf \ test.auto_dom.no_parents.2.vcf \ Loading tests/empty.fastq.gz 0 → 100644 +79 B File added.No diff preview for this file type. View file Loading
LICENSE 0 → 100644 +21 −0 Original line number Diff line number Diff line The MIT License (MIT) Copyright (c) 2015 Brent Pedersen and Aaron Quinlan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
grabix.cpp +19 −11 Original line number Diff line number Diff line #include <cstdlib> #include <iostream> #include <stdio.h> #include <fstream> #include <vector> #include <unistd.h> Loading Loading @@ -56,6 +57,12 @@ random access via the BGZF seek utility */ int create_grabix_index(string bgzf_file) { if (!bgzf_is_bgzf(bgzf_file.c_str())) { cerr << "[grabix] " << bgzf_file << " doesn't exist or wasn't compressed with bgzip" << endl; exit (1); } BGZF *bgzf_fp = bgzf_open(bgzf_file.c_str(), "r"); if (bgzf_fp == NULL) { Loading @@ -64,7 +71,7 @@ int create_grabix_index(string bgzf_file) } // create an index for writing string index_file_name = bgzf_file + ".gbi"; string index_file_name = bgzf_file + ".gbi.tmp"; ofstream index_file(index_file_name.c_str(), ios::out); // add the offset for the end of the header to the index Loading Loading @@ -92,15 +99,15 @@ int create_grabix_index(string bgzf_file) int64_t total_lines = 1; vector<int64_t> chunk_positions; chunk_positions.push_back (prev_offset); bool eof = false; int eof = 1; while (true) { // grab the next line and store the offset eof = bgzf_getline_counting(bgzf_fp); eof = bgzf_getline(bgzf_fp, '\n', line); offset = bgzf_tell(bgzf_fp); chunk_count++; // stop if we have encountered an empty line if (eof) if (eof < 0 || offset == prev_offset) { if (bgzf_check_EOF(bgzf_fp) == 1) { if (offset > prev_offset) { Loading @@ -109,6 +116,7 @@ int create_grabix_index(string bgzf_file) } break; } break; } // store the offset of this chunk start else if (chunk_count == CHUNK_SIZE) Loading @@ -129,7 +137,7 @@ int create_grabix_index(string bgzf_file) } index_file.close(); return EXIT_SUCCESS; return std::rename((bgzf_file + ".gbi.tmp").c_str(), (bgzf_file + ".gbi").c_str()); } /* Loading Loading @@ -206,7 +214,7 @@ int grab(string bgzf_file, int64_t from_line, int64_t to_line) line->l = 0; line->m = 0; while ((status = bgzf_getline(bgzf_fp, '\n', line)) != 0) while ((status = bgzf_getline(bgzf_fp, '\n', line)) > 0) { if (line->s[0] == '#') printf("%s\n", line->s); Loading
grabix.h +1 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ using namespace std; #include "bgzf.h" #define VERSION "0.1.6" #define VERSION "0.1.8" // we only want to store the offset for every 10000th // line. otherwise, were we to store the position of every // line in the file, the index could become very large for Loading
test.sh +21 −3 Original line number Diff line number Diff line Loading @@ -3,17 +3,35 @@ make FQ=test.cnt.gz rm -f ${FQ}{,.gbi} lines=50000 lines=500000 python tests/make-test-fastq.py $lines | bgzip -c > $FQ ./grabix index $FQ echo "indexing" time ./grabix index $FQ echo "indexed" python tests/test-fastq.py $FQ a=$(grabix grab test.cnt.gz $(($lines * 4))) a=$(./grabix grab test.cnt.gz $(($lines * 4))) b=$(zless $FQ | tail -1) if [[ "$a" != "$b" ]]; then echo FAIL last record exit 1 else echo OK last record fi rm -f ${FQ}{,.gbi} rm -f tests/empty.fastq.gz.gbi ./grabix index tests/empty.fastq.gz a=$(cat tests/empty.fastq.gz.gbi | awk 'NR == 2') if [[ "$a" != "16" ]]; then echo FAIL index wrong size exit 1 else echo "OK index size" fi for V in \ test.PLs.vcf \ test.auto_dom.no_parents.2.vcf \ Loading