1616#include " FalcoConfig.hpp"
1717#include " FastqStats.hpp"
1818
19- #include < fstream>
20- #include < sstream>
2119#include < sys/stat.h>
2220#include < unistd.h>
21+
22+ #include < fstream>
23+ #include < sstream>
2324#include < algorithm>
2425#include < sstream>
2526
26- using std::ostringstream;
27- using std::transform;
28- using std::string;
29- using std::vector;
30- using std::unordered_map;
31- using std::pair;
32- using std::make_pair;
33- using std::ifstream;
34- using std::runtime_error;
35- using std::istringstream;
36- using std::cerr;
37-
38- const string FalcoConfig::FalcoVersion = " 1.2.5" ;
27+ const std::string FalcoConfig::FalcoVersion = " 1.2.5" ;
3928
4029/* ********************************************************/
4130/* ************* DEFAULT VALUES FOR FILES *****************/
@@ -44,7 +33,7 @@ const string FalcoConfig::FalcoVersion = "1.2.5";
4433namespace FileConstants {
4534 // These will become const bools in the stream reader
4635 static const std::unordered_map<std::string,
47- std::unordered_map<std::string, double > >
36+ std::unordered_map<std::string, double >>
4837 limits = {
4938 {" quality_base" ,{{" ignore" ,0 }}},
5039 {" duplication" ,{{" ignore" ,0 }, {" warn" ,70 }, {" error" ,50 }}},
@@ -62,7 +51,7 @@ namespace FileConstants {
6251 };
6352
6453 /* ************** CONTAMINANTS *****************/
65- static const std::vector<std::pair<std::string, std::string> >
54+ static const std::vector<std::pair<std::string, std::string>>
6655 contaminants = {
6756 {" Illumina Single End Adapter 1" ," GATCGGAAGAGCTCGTATGCCGTCTTCTGCTTG" },
6857 {" Illumina Single End Adapter 2" ," CAAGCAGAAGACGGCATACGAGCTCTTCCGATCT" },
@@ -254,7 +243,7 @@ namespace FileConstants {
254243
255244// Check if line is not a comment or newline
256245inline bool
257- is_content_line (const string &line) {
246+ is_content_line (const std:: string &line) {
258247 // comment
259248 if (line[0 ] == ' #' )
260249 return false ;
@@ -269,7 +258,7 @@ is_content_line (const string &line) {
269258// Check existance of config files
270259inline bool
271260file_exists (const std::string& name) {
272- return ( access (name. c_str ( ), F_OK) == 0 ) ;
261+ return access (std::data (name ), F_OK) == 0 ;
273262}
274263
275264
@@ -279,7 +268,7 @@ file_exists(const std::string& name) {
279268// variable, and files are not read properly
280269// if these bytes are not removed
281270void
282- clean_zero_bytes (string &filename) {
271+ clean_zero_bytes (std:: string &filename) {
283272 filename.erase (std::remove (begin (filename), end (filename), ' \0 ' ), end (filename));
284273}
285274
@@ -294,10 +283,10 @@ endswith(std::string const &value, std::string const &ending) {
294283}
295284
296285// Removes absolute path from a file
297- static string
298- strip_path (string full_path) {
286+ static std:: string
287+ strip_path (std:: string full_path) {
299288 size_t start = full_path.find_last_of (' /' );
300- if (start == string::npos)
289+ if (start == std:: string::npos)
301290 start = 0 ;
302291 else
303292 ++start;
@@ -319,9 +308,9 @@ FalcoConfig::FalcoConfig(const int argc, char *argv[]) {
319308 read_step = 1 ;
320309 format = " " ;
321310 threads = 1 ;
322- contaminants_file = string (PROGRAM_PATH) + " /Configuration/contaminant_list.txt" ;
323- adapters_file = string (PROGRAM_PATH) + " /Configuration/adapter_list.txt" ;
324- limits_file = string (PROGRAM_PATH) + " /Configuration/limits.txt" ;
311+ contaminants_file = std:: string (PROGRAM_PATH) + " /Configuration/contaminant_list.txt" ;
312+ adapters_file = std:: string (PROGRAM_PATH) + " /Configuration/adapter_list.txt" ;
313+ limits_file = std:: string (PROGRAM_PATH) + " /Configuration/limits.txt" ;
325314
326315 clean_zero_bytes (contaminants_file);
327316 clean_zero_bytes (adapters_file);
@@ -337,16 +326,16 @@ FalcoConfig::FalcoConfig(const int argc, char *argv[]) {
337326 is_fastq = false ;
338327 is_fastq_gz = false ;
339328
340- ostringstream ost;
329+ std:: ostringstream ost;
341330 for (int i = 0 ; i < argc; ++i) {
342331 if (i != 0 )
343332 ost << " " ;
344- ost << string (argv[i]);
333+ ost << std:: string (argv[i]);
345334 }
346335 call = ost.str ();
347336}
348337
349- const vector<string> FalcoConfig::values_to_check ({
338+ const std:: vector<std:: string> FalcoConfig::values_to_check ({
350339 " duplication" ,
351340 " kmer" ,
352341 " n_content" ,
@@ -375,13 +364,13 @@ const vector<string> FalcoConfig::values_to_check({
375364template <class T >
376365bool
377366check_if_not_ignored (const T& limits_map,
378- const string &limit) {
367+ const std:: string &limit) {
379368 if (limits_map.find (limit) == end (limits_map))
380- throw runtime_error (" no instructions for limit " + limit);
369+ throw std:: runtime_error (" no instructions for limit " + limit);
381370
382371 const auto the_limit = limits_map.find (limit)->second ;
383372 if (the_limit.find (" ignore" ) == end (the_limit))
384- throw runtime_error (" 'ignore' option not set for limit " + limit);
373+ throw std:: runtime_error (" 'ignore' option not set for limit " + limit);
385374
386375 const bool ret = (the_limit.find (" ignore" )->second == 0.0 );
387376
@@ -406,9 +395,9 @@ FalcoConfig::setup() {
406395
407396void
408397FalcoConfig::define_file_format () {
409- transform (begin (format), end (format), begin (format), tolower);
410- string tmp_filename = filename;
411- transform (begin (tmp_filename), end (tmp_filename), begin (tmp_filename), tolower);
398+ std:: transform (begin (format), end (format), begin (format), tolower);
399+ std:: string tmp_filename = filename;
400+ std:: transform (begin (tmp_filename), end (tmp_filename), begin (tmp_filename), tolower);
412401
413402 // reset, important bececause the same FalcoConfig object is used
414403 // across possibly multiple input files
@@ -444,7 +433,7 @@ FalcoConfig::define_file_format() {
444433#endif
445434 else if (format == " fq.gz" || format == " fastq.gz" ) is_fastq_gz = true ;
446435 else if (format == " fq" || format == " fastq" ) is_fastq = true ;
447- else throw runtime_error (" unrecognized file format: " + format);
436+ else throw std:: runtime_error (" unrecognized file format: " + format);
448437 }
449438}
450439
@@ -454,38 +443,38 @@ FalcoConfig::read_limits() {
454443 limits = FileConstants::limits;
455444 if (!file_exists (limits_file)) {
456445 if (!quiet)
457- cerr << " [limits]\t WARNING: using default limits because "
446+ std:: cerr << " [limits]\t WARNING: using default limits because "
458447 << " limits file does not exist: " << limits_file << " \n " ;
459448 }
460449 else {
461- ifstream in (limits_file);
450+ std:: ifstream in (limits_file);
462451 if (!in)
463- throw runtime_error (" problem opening limits file: " + limits_file);
452+ throw std:: runtime_error (" problem opening limits file: " + limits_file);
464453
465454 if (!quiet)
466- cerr << " [limits]\t using file " << limits_file << " \n " ;
455+ std:: cerr << " [limits]\t using file " << limits_file << " \n " ;
467456
468457 // Variables to parse lines
469- string line, instruction;
458+ std:: string line, instruction;
470459 double value;
471460 while (getline (in, line)) {
472461 // Checks if the line has something to be parsed
473462 if (is_content_line (line)) {
474- istringstream iss (line);
463+ std:: istringstream iss (line);
475464
476465 // Every line is a limit, warn/error/ignore and the value
477- string limit;
466+ std:: string limit;
478467 if (!(iss >> limit >> instruction >> value))
479- throw runtime_error (" malformed limits line: \" " + line + " \" " );
468+ throw std:: runtime_error (" malformed limits line: \" " + line + " \" " );
480469
481470 if (find (begin (values_to_check), end (values_to_check), limit)
482471 == end (values_to_check))
483- throw runtime_error (" unknown limit option: " + limit);
472+ throw std:: runtime_error (" unknown limit option: " + limit);
484473
485474 if (instruction != " warn" &&
486475 instruction != " error" &&
487476 instruction != " ignore" )
488- throw runtime_error (" unknown instruction for limit " +
477+ throw std:: runtime_error (" unknown instruction for limit " +
489478 limit + " : " + instruction);
490479
491480 limits[limit][instruction] = value;
@@ -511,11 +500,11 @@ FalcoConfig::read_limits() {
511500}
512501
513502size_t
514- hash_adapter (const string &s) {
503+ hash_adapter (const std:: string &s) {
515504 size_t ans = 0 ;
516505 for (size_t i = 0 ; i < s.size (); ++i) {
517506 if (s[i] != ' A' && s[i] != ' C' && s[i] != ' T' && s[i] != ' G' )
518- throw runtime_error (" Bad adapter (non-ATGC characters): " + s);
507+ throw std:: runtime_error (" Bad adapter (non-ATGC characters): " + s);
519508
520509 ans = (ans << 2 ) | actg_to_2bit (s[i]);
521510 }
527516FalcoConfig::read_adapters () {
528517 if (!file_exists (adapters_file)) {
529518 if (!quiet)
530- cerr << " [adapters]\t WARNING: using default adapters because "
519+ std:: cerr << " [adapters]\t WARNING: using default adapters because "
531520 << " adapters file does not exist: " << adapters_file << " \n " ;
532521
533522 adapter_names = FileConstants::adapter_names;
@@ -541,16 +530,16 @@ FalcoConfig::read_adapters() {
541530 return ;
542531 }
543532
544- ifstream in (adapters_file);
533+ std:: ifstream in (adapters_file);
545534 if (!in)
546- throw runtime_error (" problem opening adapters file: " + adapters_file);
535+ throw std:: runtime_error (" problem opening adapters file: " + adapters_file);
547536
548537 if (!quiet)
549- cerr << " [adapters]\t using file " << adapters_file << " \n " ;
538+ std:: cerr << " [adapters]\t using file " << adapters_file << " \n " ;
550539
551- string line, _tmp;
552- vector<string> line_by_space;
553- string adapter_name, adapter_seq;
540+ std:: string line, _tmp;
541+ std:: vector<std:: string> line_by_space;
542+ std:: string adapter_name, adapter_seq;
554543
555544 // The adapters file has a space separated name, and the last instance is
556545 // the biological sequence
@@ -565,14 +554,14 @@ FalcoConfig::read_adapters() {
565554 if (is_content_line (line)) {
566555 if (adapter_names.size () > Constants::max_adapters) {
567556 in.close ();
568- throw runtime_error (" You are testing too many adapters. The maximum "
557+ throw std:: runtime_error (" You are testing too many adapters. The maximum "
569558 " number is 128!" );
570559 }
571560 adapter_name = " " ;
572561 adapter_seq = " " ;
573562
574563 line_by_space.clear ();
575- istringstream iss (line);
564+ std:: istringstream iss (line);
576565 while (iss >> _tmp) {
577566 line_by_space.push_back (_tmp);
578567 }
@@ -585,7 +574,7 @@ FalcoConfig::read_adapters() {
585574 adapter_seq = line_by_space.back ();
586575
587576 if (adapter_seq.size () > 32 ) {
588- cerr << " [adapters]\t adapter size is more then 32. Use slow adapters search" << " \n " ;
577+ std:: cerr << " [adapters]\t adapter size is more then 32. Use slow adapters search\n " ;
589578 do_adapter_optimized = false ;
590579 }
591580 }
@@ -600,7 +589,7 @@ FalcoConfig::read_adapters() {
600589 shortest_adapter_size = adapter_size;
601590 }
602591 else if (adapter_seq.size () != adapter_size) {
603- cerr << " [adapters]\t adapters have different size. Use slow adapters search" << " \n " ;
592+ std:: cerr << " [adapters]\t adapters have different size. Use slow adapters search\n " ;
604593 do_adapter_optimized = false ;
605594 if (adapter_seq.size () < shortest_adapter_size){
606595 shortest_adapter_size = adapter_seq.size ();
@@ -615,43 +604,43 @@ void
615604FalcoConfig::read_contaminants_file () {
616605 if (!file_exists (contaminants_file)) {
617606 if (!quiet)
618- cerr << " [contaminants]\t WARNING: using default contaminants because "
607+ std:: cerr << " [contaminants]\t WARNING: using default contaminants because "
619608 << " contaminants file does not exist: " << contaminants_file << " \n " ;
620609 contaminants = FileConstants::contaminants;
621610 return ;
622611 }
623- ifstream in (contaminants_file);
612+ std:: ifstream in (contaminants_file);
624613 if (!in)
625- throw runtime_error (" problem opening contaminants file: " + contaminants_file);
614+ throw std:: runtime_error (" problem opening contaminants file: " + contaminants_file);
626615
627616 if (!quiet)
628- cerr << " [contaminants]\t using file " << contaminants_file << " \n " ;
629- vector<string> line_by_space;
617+ std:: cerr << " [contaminants]\t using file " << contaminants_file << " \n " ;
618+ std:: vector<std:: string> line_by_space;
630619
631620 // The contaminants file has a space separated name, and the last
632621 // instance is the biological sequence
633- string line;
622+ std:: string line;
634623 contaminants.clear ();
635624 while (getline (in, line)) {
636625 if (is_content_line (line)) {
637- istringstream iss (line);
638- string token;
626+ std:: istringstream iss (line);
627+ std:: string token;
639628 while (iss >> token)
640629 line_by_space.push_back (token);
641630
642631 if (line_by_space.size () > 1 ) {
643- string contaminant_name = line_by_space[0 ];
632+ std:: string contaminant_name = line_by_space[0 ];
644633 for (size_t i = 1 ; i < line_by_space.size () - 1 ; ++i)
645634 contaminant_name += " " + line_by_space[i];
646- contaminants.push_back (make_pair (contaminant_name, line_by_space.back ()));
635+ contaminants.push_back (std:: make_pair (contaminant_name, line_by_space.back ()));
647636 }
648637 line_by_space.clear ();
649638 }
650639 }
651640 in.close ();
652641}
653642
654- const string FalcoConfig::html_template =
643+ const std:: string FalcoConfig::html_template =
655644" <html>"
656645" <head>"
657646" <meta charset=\" utf-8\" >"
0 commit comments