61 using namespace nvbio;
69 for (
uint32 l = 0; *str !=
'\0' && l < len; ++l)
71 const char c = *str; ++str;
72 if (c ==
'.')
continue;
73 if (c >=
'0' && c <=
'9')
continue;
86 for (
uint32 i = 0; i < mapped.size(); ++i)
88 if (
float(mapped[i])/float(stats.
n_mapped) > 1.0e-3f)
93 for (
uint32 i = 0; i < mapped.size(); ++i)
95 if (
float(mapped[i])/float(stats.
n_mapped) > 1.0e-3f)
106 for (
uint32 i = 0; i < 8; ++i)
110 for (
uint32 i = 0; i < 8; ++i)
115 int main(
int argc,
char* argv[])
122 (argc == 2 && strcmp( argv[1],
"--help" ) == 0) ||
123 (argc == 2 && strcmp( argv[1],
"-h" ) == 0))
125 log_info(stderr,
"nvBowtie [options]\n");
128 log_info(stderr,
" -U file-name unpaired reads\n");
129 log_info(stderr,
" -1 file-name first mate reads\n");
130 log_info(stderr,
" -2 file-name second mate reads\n");
131 log_info(stderr,
" -S file-name output file (.sam|.bam)\n");
132 log_info(stderr,
" -x file-name reference index\n");
133 log_info(stderr,
" --verbosity int [5] verbosity level\n");
134 log_info(stderr,
" --upto | -u int [-1] maximum number of reads to process\n");
135 log_info(stderr,
" --trim3 | -3 int [0] trim the first N bases of 3'\n");
136 log_info(stderr,
" --trim5 | -5 int [0] trim the first N bases of 5'\n");
137 log_info(stderr,
" --nofw do not align the forward strand\n");
138 log_info(stderr,
" --norc do not align the reverse-complemented strand\n");
139 log_info(stderr,
" --device int [0] select the given cuda device(s) (e.g. --device 0 --device 1 ...)\n");
140 log_info(stderr,
" --file-ref load reference from file\n");
141 log_info(stderr,
" --server-ref load reference from server\n");
142 log_info(stderr,
" --phred33 qualities are ASCII characters equal to Phred quality + 33\n");
143 log_info(stderr,
" --phred64 qualities are ASCII characters equal to Phred quality + 64\n");
144 log_info(stderr,
" --solexa-quals qualities are in the Solexa format\n");
145 log_info(stderr,
" --rg-id string add the RG-ID field of the SAM output header\n");
146 log_info(stderr,
" --rg string,val add an RG-TAG field of the SAM output header\n");
148 log_info(stderr,
" --ff paired mates are forward-forward\n");
149 log_info(stderr,
" --fr paired mates are forward-reverse\n");
150 log_info(stderr,
" --rf paired mates are reverse-forward\n");
151 log_info(stderr,
" --rr paired mates are reverse-reverse\n");
152 log_info(stderr,
" --minins int [0] minimum insert length\n");
153 log_info(stderr,
" --minins int [500] maximum insert length\n");
154 log_info(stderr,
" --overlap allow overlapping mates\n");
155 log_info(stderr,
" --dovetail allow dovetailing mates\n");
156 log_info(stderr,
" --no-mixed only report paired alignments\n");
157 log_info(stderr,
" --ungapped-mates | -ug perform ungapped mate alignment\n");
159 log_info(stderr,
" --seed-len | -L int [22] seed lengths\n");
160 log_info(stderr,
" --seed-freq | -i {G|L|S},x,y seed interval, as x + y*func(read-len) (G=log,L=linear,S=sqrt)\n");
161 log_info(stderr,
" --max-hits int [100] maximum amount of seed hits\n");
162 log_info(stderr,
" --max-reseed | -R int [2] number of reseeding rounds\n");
164 log_info(stderr,
" --all | -a perform all-mapping (i.e. find and report all alignments)\n");
165 log_info(stderr,
" --local perform local alignment\n");
166 log_info(stderr,
" --rand randomized seed selection\n");
167 log_info(stderr,
" --no-rand do not randomize seed hit selection\n");
168 log_info(stderr,
" --max-dist int [15] maximum edit distance\n");
169 log_info(stderr,
" --max-effort-init int [15] initial maximum number of consecutive extension failures\n");
170 log_info(stderr,
" --max-effort | -D int [15] maximum number of consecutive extension failures\n");
171 log_info(stderr,
" --min-ext int [30] minimum number of extensions per read\n");
172 log_info(stderr,
" --max-ext int [400] maximum number of extensions per read\n");
173 log_info(stderr,
" --fast apply the fast presets\n");
174 log_info(stderr,
" --very-fast apply the very-fast presets\n");
175 log_info(stderr,
" --sensitive apply the sensitive presets\n");
176 log_info(stderr,
" --very-sensitive apply the very-sensitive presets\n");
177 log_info(stderr,
" --fast-local apply the fast presets\n");
178 log_info(stderr,
" --very-fast-local apply the very-fast presets\n");
179 log_info(stderr,
" --sensitive-local apply the sensitive presets\n");
180 log_info(stderr,
" --very-sensitive-local apply the very-sensitive presets\n");
182 log_info(stderr,
" --scoring {sw|ed} Smith-Waterman / Edit-Distance scoring\n");
183 log_info(stderr,
" --score-min {G|L|S},x,y minimum score function, as x + y*func(read-len)\n");
184 log_info(stderr,
" --ma int match bonus\n");
185 log_info(stderr,
" --mp int,int mismatch min/max penalties\n");
186 log_info(stderr,
" --np int N penalty\n");
187 log_info(stderr,
" --rdg int,int read open/extension gap penalties\n");
188 log_info(stderr,
" --rfg int,int reference open/extension gap penalties\n");
190 log_info(stderr,
" --mapQ-filter | -Q int [0] minimum mapQ threshold\n");
193 else if (argc == 2 && strcmp( argv[1],
"-test" ) == 0)
195 log_visible(stderr,
"nvBowtie tests... started\n");
201 else if (argc == 2 && strcmp( argv[1],
"--version" ) == 0)
215 bool from_file =
false;
216 bool paired_end =
false;
219 std::vector<int> cuda_devices;
221 std::map<std::string,std::string> string_options;
224 for (
int32 i = 1; i < argc; ++i)
231 std::string rg_string;
233 bool legacy_cmdline =
true;
235 const char* read_name1 =
"";
236 const char* read_name2 =
"";
237 const char* reference_name =
"";
238 const char* output_name =
"";
240 for (
int32 i = 1; i < argc; ++i)
242 if (strcmp( argv[i],
"--pe" ) == 0 ||
243 strcmp( argv[i],
"-paired-ends" ) == 0 ||
244 strcmp( argv[i],
"--paired-ends" ) == 0)
246 else if (strcmp( argv[i],
"--ff" ) == 0)
248 else if (strcmp( argv[i],
"--fr" ) == 0)
250 else if (strcmp( argv[i],
"--rf" ) == 0)
252 else if (strcmp( argv[i],
"--rr" ) == 0)
254 else if (strcmp( argv[i],
"-max-reads" ) == 0 ||
255 strcmp( argv[i],
"--max-reads" ) == 0 ||
256 strcmp( argv[i],
"-u" ) == 0 ||
257 strcmp( argv[i],
"--upto" ) == 0)
258 max_reads = (
uint32)atoi( argv[++i] );
259 else if (strcmp( argv[i],
"-max-read-len" ) == 0 ||
260 strcmp( argv[i],
"--max-read-len" ) == 0)
261 max_read_len = (
uint32)atoi( argv[++i] );
262 else if (strcmp( argv[i],
"-3") == 0 ||
263 strcmp( argv[i],
"--trim3") == 0)
264 trim3 = (
uint32)atoi( argv[++i] );
265 else if (strcmp( argv[i],
"-5") == 0 ||
266 strcmp( argv[i],
"--trim5") == 0)
267 trim5 = (
uint32)atoi( argv[++i] );
268 else if (strcmp( argv[i],
"-file-ref" ) == 0 ||
269 strcmp( argv[i],
"--file-ref" ) == 0)
271 else if (strcmp( argv[i],
"-server-ref" ) == 0 ||
272 strcmp( argv[i],
"--server-ref" ) == 0)
274 else if (strcmp( argv[i],
"-input" ) == 0 ||
275 strcmp( argv[i],
"--input" ) == 0)
277 if (strcmp( argv[i+1],
"file" ) == 0)
279 else if (strcmp( argv[i+1],
"server" ) == 0)
282 log_warning(stderr,
"unknown \"%s\" input, skipping\n", argv[i+1]);
286 else if (strcmp( argv[i],
"-phred33" ) == 0 ||
287 strcmp( argv[i],
"--phred33" ) == 0)
289 else if (strcmp( argv[i],
"-phred64" ) == 0 ||
290 strcmp( argv[i],
"--phred64" ) == 0)
292 else if (strcmp( argv[i],
"-solexa-quals" ) == 0 ||
293 strcmp( argv[i],
"--solexa-quals" ) == 0)
295 else if (strcmp( argv[i],
"-device" ) == 0 ||
296 strcmp( argv[i],
"--device" ) == 0)
297 cuda_devices.push_back( atoi( argv[++i] ) );
298 else if (strcmp( argv[i],
"-verbosity" ) == 0 ||
299 strcmp( argv[i],
"--verbosity" ) == 0)
301 else if (strcmp( argv[i],
"-rg-id" ) == 0 ||
302 strcmp( argv[i],
"--rg-id" ) == 0)
304 else if (strcmp( argv[i],
"-rg" ) == 0 ||
305 strcmp( argv[i],
"--rg" ) == 0)
308 rg_string += argv[++i];
310 else if (strcmp( argv[i],
"-1") == 0)
312 legacy_cmdline =
false;
314 read_name1 = argv[++i];
316 else if (strcmp( argv[i],
"-2") == 0)
318 legacy_cmdline =
false;
320 read_name2 = argv[++i];
322 else if (strcmp( argv[i],
"-U") == 0)
324 legacy_cmdline =
false;
326 read_name1 = argv[++i];
328 else if (strcmp( argv[i],
"-S") == 0)
330 legacy_cmdline =
false;
331 output_name = argv[++i];
333 else if (strcmp( argv[i],
"-x") == 0)
335 legacy_cmdline =
false;
336 reference_name = argv[++i];
338 else if (argv[i][0] ==
'-')
341 const std::string key = std::string( argv[i][1] ==
'-' ? argv[i] + 2 : argv[i] + 1 );
342 const char*
next = argv[i+1];
346 const std::string val = std::string( next ); ++i;
347 string_options.insert( std::make_pair( key, val ) );
350 string_options.insert( std::make_pair( key,
"1" ) );
354 log_info(stderr,
"nvBowtie... started\n");
355 log_debug(stderr,
" %-16s : %d\n",
"max-reads", max_reads);
356 log_debug(stderr,
" %-16s : %d\n",
"max-length", max_read_len);
362 log_debug(stderr,
" %-16s : %s\n",
"pe-policy",
368 if (string_options.empty() ==
false)
370 for (std::map<std::string,std::string>::const_iterator it = string_options.begin(); it != string_options.end(); ++it)
371 log_debug(stderr,
" %-16s : %s\n", it->first.c_str(), it->second.c_str());
376 cudaGetDeviceCount(&device_count);
377 log_verbose(stderr,
" cuda devices : %d\n", device_count);
380 if (device_count > 0)
382 if (cuda_devices.empty())
385 cudaDeviceProp best_device_prop;
386 cudaGetDeviceProperties( &best_device_prop, best_device );
388 for (
int device = 0; device < device_count; ++device)
390 cudaDeviceProp device_prop;
391 cudaGetDeviceProperties( &device_prop, device );
392 log_verbose(stderr,
" device %d has compute capability %d.%d\n", device, device_prop.major, device_prop.minor);
393 log_verbose(stderr,
" SM count : %u\n", device_prop.multiProcessorCount);
394 log_verbose(stderr,
" SM clock rate : %u Mhz\n", device_prop.clockRate / 1000);
395 log_verbose(stderr,
" memory clock rate : %.1f Ghz\n",
float(device_prop.memoryClockRate) * 1.0e-6f);
397 if (device_prop.major >= best_device_prop.major &&
398 device_prop.minor >= best_device_prop.minor)
400 best_device_prop = device_prop;
401 best_device = device;
404 cuda_devices.push_back( best_device );
407 for (
size_t i = 0; i < cuda_devices.size(); ++i)
409 cudaDeviceProp device_prop;
410 cudaGetDeviceProperties( &device_prop, cuda_devices[i] );
411 log_verbose(stderr,
" chosen device %d\n", cuda_devices[i]);
412 log_verbose(stderr,
" device name : %s\n", device_prop.name);
413 log_verbose(stderr,
" compute capability : %d.%d\n", device_prop.major, device_prop.minor);
418 log_error(stderr,
"no available CUDA devices\n");
424 const uint32 arg_offset = paired_end ? argc-4 : argc-3;
425 reference_name = argv[arg_offset];
428 read_name1 = argv[arg_offset+1];
429 read_name2 = argv[arg_offset+2];
432 read_name1 = argv[arg_offset+1];
434 output_name = argv[argc-1];
456 log_warning(stderr,
"edit-distance scoring is incompatible with local alignment, switching to Smith-Waterman\n");
468 log_visible(stderr,
"loading reference index... started\n");
469 log_info(stderr,
" file: \"%s\"\n", reference_name);
473 if (reference_data == NULL)
475 log_error(stderr,
"unable to load reference index \"%s\"\n", reference_name);
479 log_visible(stderr,
"loading reference index... done\n");
482 if (!loader->
load( reference_name ))
484 log_error(stderr,
"unable to load reference index \"%s\"\n", reference_name);
488 driver_data = loader;
492 log_visible(stderr,
"mapping reference index... started\n");
493 log_info(stderr,
" file: \"%s\"\n", reference_name);
497 if (reference_data == NULL)
499 log_visible(stderr,
"mapping reference index... failed\n");
500 log_visible(stderr,
"loading reference index... started\n");
501 log_info(stderr,
" file: \"%s\"\n", reference_name);
505 if (reference_data == NULL)
507 log_error(stderr,
"unable to load reference index \"%s\"\n", reference_name);
511 log_visible(stderr,
"loading reference index... done\n");
514 if (!loader->
load( reference_name ))
516 log_error(stderr,
"unable to load reference index \"%s\"\n", reference_name);
520 driver_data = loader;
524 log_visible(stderr,
"mapping reference index... done\n");
527 if (!loader->
load( reference_name ))
529 log_error(stderr,
"unable to load reference index \"%s\"\n", reference_name);
533 driver_data = loader;
546 output_file->
set_rg( rg_id.c_str(), rg_string.c_str() );
562 log_visible(stderr,
"opening read file [1] \"%s\"\n", read_name1);
574 if (read_data_file1 == NULL || read_data_file1->
is_ok() ==
false)
576 log_error(stderr,
"unable to open read file \"%s\"\n", read_name1);
580 log_visible(stderr,
"opening read file [2] \"%s\"\n", read_name2);
592 if (read_data_file2 == NULL || read_data_file2->
is_ok() ==
false)
594 log_error(stderr,
"unable to open read file \"%s\"\n", read_name2);
633 std::vector< bowtie2::cuda::Stats > device_stats( cuda_devices.size() );
634 std::vector< SharedPointer<bowtie2::cuda::ComputeThreadPE> > compute_threads( cuda_devices.size() );
636 for (
uint32 i = 0; i < cuda_devices.size(); ++i)
650 batch_size =
nvbio::min( batch_size, compute_threads[i]->gauge_batch_size() );
665 for (
uint32 i = 0; i < cuda_devices.size(); ++i)
667 compute_threads[i]->set_input( &input_thread );
668 compute_threads[i]->set_output( output_file.
get() );
669 compute_threads[i]->create();
678 for (
uint32 i = 0; i < cuda_devices.size(); ++i)
680 compute_threads[i]->join();
682 n_reads += device_stats[i].n_reads;
683 concordant.
merge( device_stats[i].concordant );
684 discordant.
merge( device_stats[i].discordant );
685 mate1.
merge( device_stats[i].mate1 );
686 mate2.
merge( device_stats[i].mate2 );
693 log_verbose( stderr,
" compute threads joined\n" );
696 output_file->
close();
706 log_stats(stderr,
" total : %.2f sec (avg: %.3fK reads/s).\n", timer.
seconds(), 1.0e-3f * float(n_reads) / timer.
seconds());
716 log_stats(stderr,
" concordant reads : %.2f %% - of these:\n", 100.0f *
float(n_mapped)/
float(n_reads) );
717 log_stats(stderr,
" aligned uniquely : %4.1f%% (%4.1f%% of total)\n", 100.0f *
float(n_unique)/
float(n_mapped), 100.0f *
float(n_mapped - n_multiple)/
float(n_reads) );
718 log_stats(stderr,
" aligned unambiguously : %4.1f%% (%4.1f%% of total)\n", 100.0f *
float(n_nonambiguous)/
float(n_mapped), 100.0f *
float(n_nonambiguous)/
float(n_reads) );
719 log_stats(stderr,
" aligned ambiguously : %4.1f%% (%4.1f%% of total)\n", 100.0f *
float(n_ambiguous)/
float(n_mapped), 100.0f *
float(n_ambiguous)/
float(n_reads) );
720 log_stats(stderr,
" aligned multiply : %4.1f%% (%4.1f%% of total)\n", 100.0f *
float(n_multiple)/
float(n_mapped), 100.0f *
float(n_multiple)/
float(n_reads) );
724 log_stats(stderr,
" discordant reads : %.2f %%\n", 100.0f *
float(discordant.
n_mapped)/
float(n_reads) );
728 log_stats(stderr,
" mate1 : %.2f %% - of these:\n", 100.0f *
float(mate1.
n_mapped)/
float(n_reads) );
737 log_stats(stderr,
" mate2 : %.2f %% - of these:\n", 100.0f *
float(mate2.
n_mapped)/
float(n_reads) );
748 if (params.
report.length())
757 log_visible(stderr,
"opening read file \"%s\"\n", read_name1);
769 if (read_data_file == NULL || read_data_file->
is_ok() ==
false)
771 log_error(stderr,
"unable to open read file \"%s\"\n", read_name1);
804 std::vector< bowtie2::cuda::Stats > device_stats( cuda_devices.size() );
805 std::vector< SharedPointer<bowtie2::cuda::ComputeThreadSE> > compute_threads( cuda_devices.size() );
807 for (
uint32 i = 0; i < cuda_devices.size(); ++i)
821 batch_size =
nvbio::min( batch_size, compute_threads[i]->gauge_batch_size() );
836 for (
uint32 i = 0; i < cuda_devices.size(); ++i)
838 compute_threads[i]->set_input( &input_thread );
839 compute_threads[i]->set_output( output_file.
get() );
840 compute_threads[i]->create();
846 for (
uint32 i = 0; i < cuda_devices.size(); ++i)
848 compute_threads[i]->join();
850 n_reads += device_stats[i].n_reads;
851 mate1.
merge( device_stats[i].mate1 );
858 log_verbose( stderr,
" compute threads joined\n" );
861 output_file->
close();
871 log_stats(stderr,
" total : %.2f sec (avg: %.3fK reads/s).\n", timer.
seconds(), 1.0e-3f * float(n_reads) / timer.
seconds());
881 log_stats(stderr,
" mapped reads : %.2f %% - of these:\n", 100.0f *
float(n_mapped)/
float(n_reads) );
882 log_stats(stderr,
" aligned uniquely : %4.1f%% (%4.1f%% of total)\n", 100.0f *
float(n_unique)/
float(n_mapped), 100.0f *
float(n_mapped - n_multiple)/
float(n_reads) );
883 log_stats(stderr,
" aligned unambiguously : %4.1f%% (%4.1f%% of total)\n", 100.0f *
float(n_nonambiguous)/
float(n_mapped), 100.0f *
float(n_nonambiguous)/
float(n_reads) );
884 log_stats(stderr,
" aligned ambiguously : %4.1f%% (%4.1f%% of total)\n", 100.0f *
float(n_ambiguous)/
float(n_mapped), 100.0f *
float(n_ambiguous)/
float(n_reads) );
885 log_stats(stderr,
" aligned multiply : %4.1f%% (%4.1f%% of total)\n", 100.0f *
float(n_multiple)/
float(n_mapped), 100.0f *
float(n_multiple)/
float(n_reads) );
891 if (params.
report.length())
895 log_info( stderr,
"nvBowtie... done\n" );
899 log_error(stderr,
"caught a nvbio::cuda_error exception:\n");
904 log_error(stderr,
"caught a nvbio::bad_alloc exception:\n");
909 log_error(stderr,
"caught a nvbio::logic_error exception:\n");
914 log_error(stderr,
"caught a nvbio::runtime_error exception:\n");
917 catch (std::bad_alloc e)
919 log_error(stderr,
"caught a std::bad_alloc exception:\n");
922 catch (std::logic_error e)
924 log_error(stderr,
"caught a std::logic_error exception:\n");
927 catch (std::runtime_error e)
929 log_error(stderr,
"caught a std::runtime_error exception:\n");
934 log_error(stderr,
"caught an unknown exception!\n");