| 1 |
/** |
| 2 |
* logarithmic k-mer count based on a Bloom filter |
| 3 |
* Copyright 2014 BCGSC |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "config.h" |
| 7 |
#include "plc.h" |
| 8 |
#include "CountingBloomFilter.h" |
| 9 |
|
| 10 |
#include "Common/IOUtil.h" |
| 11 |
#include "Common/Options.h" |
| 12 |
#include "Common/StringUtil.h" |
| 13 |
#include "DataLayer/Options.h" |
| 14 |
|
| 15 |
#include <cassert> |
| 16 |
#include <getopt.h> |
| 17 |
#include <iostream> |
| 18 |
#include <cstring> |
| 19 |
#if _OPENMP |
| 20 |
# include <omp.h> |
| 21 |
#endif |
| 22 |
|
| 23 |
using namespace std; |
| 24 |
|
| 25 |
#define PROGRAM "logcounter" |
| 26 |
|
| 27 |
static const char VERSION_MESSAGE[] = |
| 28 |
PROGRAM " (" PACKAGE_NAME ") " VERSION "\n" |
| 29 |
"Written by ?.\n" |
| 30 |
"\n" |
| 31 |
"Copyright 2014 Canada's Michael Smith Genome Science Centre\n"; |
| 32 |
|
| 33 |
static const char USAGE_MESSAGE[] = |
| 34 |
"Usage: " PROGRAM " [OPTION]... [READS]...\n" |
| 35 |
" -j, --threads=N use N parallel threads [1]\n" |
| 36 |
" -k, --kmer=N the size of a k-mer\n" |
| 37 |
" -s, --seed=N the seed value used\n" |
| 38 |
" -b, --bloom-size=N size of bloom filter [500M]\n" |
| 39 |
" --chastity discard unchaste reads [default]\n" |
| 40 |
" --no-chastity do not discard unchaste reads\n" |
| 41 |
" --trim-masked trim masked bases from the ends of reads\n" |
| 42 |
" --no-trim-masked do not trim masked bases from the ends\n" |
| 43 |
" of reads [default]\n" |
| 44 |
" -q, --trim-quality=N trim bases from the ends of reads whose\n" |
| 45 |
" quality is less than the threshold\n" |
| 46 |
" --standard-quality zero quality is `!' (33)\n" |
| 47 |
" default for FASTQ and SAM files\n" |
| 48 |
" --illumina-quality zero quality is `@' (64)\n" |
| 49 |
" default for qseq and export files\n" |
| 50 |
" -v, --verbose display verbose output\n" |
| 51 |
" --help display this help and exit\n" |
| 52 |
" --version output version information and exit\n" |
| 53 |
"\n" |
| 54 |
"Report bugs to <" PACKAGE_BUGREPORT ">.\n"; |
| 55 |
|
| 56 |
namespace opt { |
| 57 |
/** The number of parallel threads. */ |
| 58 |
static unsigned threads = 1; |
| 59 |
|
| 60 |
/** The size of the bloom filter in bytes. */ |
| 61 |
size_t bloomSize = 500 * 1024 * 1024; |
| 62 |
|
| 63 |
/** The size of a k-mer. */ |
| 64 |
unsigned k; |
| 65 |
|
| 66 |
/** The seed value to use for random number gen **/ |
| 67 |
unsigned s; |
| 68 |
|
| 69 |
// /** Prefix for output files */ |
| 70 |
// static string outputPrefix; |
| 71 |
} |
| 72 |
|
| 73 |
///** Counters */ |
| 74 |
//static struct { |
| 75 |
//} g_count; |
| 76 |
|
| 77 |
static const char shortopts[] = "j:k:s:q:v"; |
| 78 |
|
| 79 |
enum { OPT_HELP = 1, OPT_VERSION }; |
| 80 |
|
| 81 |
static const struct option longopts[] = { |
| 82 |
{ "bloom-size", required_argument, NULL, 'b' }, |
| 83 |
{ "threads", required_argument, NULL, 'j' }, |
| 84 |
{ "kmer", required_argument, NULL, 'k' }, |
| 85 |
{ "seed", required_argument, NULL, 's' }, |
| 86 |
{ "chastity", no_argument, &opt::chastityFilter, 1 }, |
| 87 |
{ "no-chastity", no_argument, &opt::chastityFilter, 0 }, |
| 88 |
{ "trim-masked", no_argument, &opt::trimMasked, 1 }, |
| 89 |
{ "no-trim-masked", no_argument, &opt::trimMasked, 0 }, |
| 90 |
{ "trim-quality", required_argument, NULL, 'q' }, |
| 91 |
{ "standard-quality", no_argument, &opt::qualityOffset, 33 }, |
| 92 |
{ "illumina-quality", no_argument, &opt::qualityOffset, 64 }, |
| 93 |
{ "verbose", no_argument, NULL, 'v' }, |
| 94 |
{ "help", no_argument, NULL, OPT_HELP }, |
| 95 |
{ "version", no_argument, NULL, OPT_VERSION }, |
| 96 |
{ NULL, 0, NULL, 0 } |
| 97 |
}; |
| 98 |
|
| 99 |
int main(int argc, char** argv) |
| 100 |
{ |
| 101 |
bool die = false; |
| 102 |
|
| 103 |
for (int c; (c = getopt_long(argc, argv, |
| 104 |
shortopts, longopts, NULL)) != -1;) { |
| 105 |
istringstream arg(optarg != NULL ? optarg : ""); |
| 106 |
switch (c) { |
| 107 |
case '?': |
| 108 |
die = true; break; |
| 109 |
case 'b': |
| 110 |
opt::bloomSize = SIToBytes(arg); break; |
| 111 |
case 'j': |
| 112 |
arg >> opt::threads; break; |
| 113 |
case 'k': |
| 114 |
arg >> opt::k; break; |
| 115 |
case 's': |
| 116 |
arg >> opt::s; break; |
| 117 |
case 'q': |
| 118 |
arg >> opt::qualityThreshold; break; |
| 119 |
case 'v': |
| 120 |
opt::verbose++; break; |
| 121 |
case OPT_HELP: |
| 122 |
cout << USAGE_MESSAGE; |
| 123 |
exit(EXIT_SUCCESS); |
| 124 |
case OPT_VERSION: |
| 125 |
cout << VERSION_MESSAGE; |
| 126 |
exit(EXIT_SUCCESS); |
| 127 |
} |
| 128 |
if (optarg != NULL && (!arg.eof() || arg.fail())) { |
| 129 |
cerr << PROGRAM ": invalid option: `-" |
| 130 |
<< (char)c << optarg << "'\n"; |
| 131 |
exit(EXIT_FAILURE); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
if (opt::k == 0) { |
| 136 |
cerr << PROGRAM ": missing mandatory option `-k'\n"; |
| 137 |
die = true; |
| 138 |
} |
| 139 |
|
| 140 |
if (die) { |
| 141 |
cerr << "Try `" << PROGRAM |
| 142 |
<< " --help' for more information.\n"; |
| 143 |
exit(EXIT_FAILURE); |
| 144 |
} |
| 145 |
|
| 146 |
#if _OPENMP |
| 147 |
if (opt::threads > 0) |
| 148 |
omp_set_num_threads(opt::threads); |
| 149 |
#endif |
| 150 |
|
| 151 |
//set seed |
| 152 |
srand (opt::s); |
| 153 |
|
| 154 |
Kmer::setLength(opt::k); |
| 155 |
|
| 156 |
assert(opt::bloomSize > 0); |
| 157 |
|
| 158 |
//size determined by |
| 159 |
CountingBloomFilter<plc> bloom(opt::bloomSize, 1); |
| 160 |
for (int i = optind; i < argc; i++) |
| 161 |
Bloom::loadFile(bloom, opt::k, string(argv[i]), opt::verbose); |
| 162 |
|
| 163 |
return 0; |
| 164 |
} |