Skip to content

Commit

Permalink
Merge pull request #18 from bw2/master
Browse files Browse the repository at this point in the history
added 'size' subcommand to get the number of lines in the file
  • Loading branch information
arq5x committed May 7, 2015
2 parents 08acb6c + cce50be commit d13743a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions grabix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ int usage()
cout << endl;
cout << " # Is the file bgzipped?" << endl;
cout << " grabix check big.vcf.gz" << endl;
cout << endl;
cout << " # get total number of lines in the file (minus the header)." << endl;
cout << " grabix size big.vcf.gz" << endl;
cout << "version: " << VERSION << "\n";
cout << endl;
return EXIT_SUCCESS;
Expand Down Expand Up @@ -305,3 +308,14 @@ int random(string bgzf_file, uint64_t K)
}
return EXIT_SUCCESS;
}

/*
Return the total number of records in the index.
*/
int size(string bgzf_file)
{
index_info index;
load_index(bgzf_file, index);

return index.num_lines;
}
5 changes: 5 additions & 0 deletions grabix.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ int grab(string bgzf_file, int64_t from_line, int64_t to_line);
Extract K random lines from file using reservoir sampling
*/
int random(string bgzf_file, uint64_t K);

/*
Return the total number of records in the index.
*/
int size(string bgzf_file);
4 changes: 4 additions & 0 deletions grabix_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ int main (int argc, char **argv)
{
cout << ((bgzf_is_bgzf(bgzf_file.c_str()) == 1) ? "yes" : "no") << "\n";
}
else if (sub_command == "size")
{
cout << size(bgzf_file) << "\n";
}
}

return EXIT_SUCCESS;
Expand Down

0 comments on commit d13743a

Please sign in to comment.