// -*- mode: c++; indent-tabs-mode: nil; -*- // // Copyright 2009 Illumina, Inc. // // This software is covered by the "Illumina Genome Analyzer Software // License Agreement" and the "Illumina Source Code License Agreement", // and certain third party copyright/licenses, and any user of this // source file is bound by the terms therein (see accompanying files // Illumina_Genome_Analyzer_Software_License_Agreement.pdf and // Illumina_Source_Code_License_Agreement.pdf and third party // copyright/license notices). // // /// \file /// \author Chris Saunders /// #include "blt_util/log.hh" #include "blt_util/seq_util.hh" #include #include #include #include void base_error(const char* func, const char a){ log_os << "ERROR:: Invalid base in " << func << ".\n" << "\t\tinvalid base (char): '" << a << "'\n" << "\t\tinvalid base (int): " << static_cast(a) << "\n"; exit(EXIT_FAILURE); } void id_to_base_error(const uint8_t i){ log_os << "ERROR:: Invalid id in id_to_base. id: " << i << "\n"; exit(EXIT_FAILURE); } bool is_valid_seq(const char* seq){ assert(NULL != seq); while(*seq != '\0'){ if(not is_valid_base(*seq)) return false; seq++; } return true; } void get_ref_seq(const char* ref_seq_file, std::string& ref_seq) { static const unsigned buff_size(50000); char buff[buff_size]; std::ifstream ref_is(ref_seq_file); if( ! ref_is ) { log_os << "ERROR:: Can't open reference sequence file: " << ref_seq_file << "\n"; exit(EXIT_FAILURE); } #ifdef SEQ_UTIL_VERBOSE log_os << "Reading from reference sequence file " << ref_seq_file << "\n"; #endif ref_is.getline(buff,buff_size); #ifdef SEQ_UTIL_VERBOSE log_os << "First line: " << buff << "\n"; #endif ref_seq.clear(); while(true){ ref_is.getline(buff,buff_size); if(! ref_is) { if (ref_is.eof()) break; else if(ref_is.fail()) { if(ref_is.bad()){ log_os << "ERROR:: unexpected failure while attempting to read sequence file: " << ref_seq_file << "\n"; exit(EXIT_FAILURE); } ref_is.clear(); } } ref_seq += buff; } #ifdef SEQ_UTIL_VERBOSE log_os << "Finished reading from reference sequence file " << ref_seq_file << "\n"; log_os << "Reference sequence size: " << ref_seq.size() << "\n"; #endif } void standardize_ref_seq(const char* ref_seq_file, std::string& ref_seq) { const std::string::size_type ref_size(ref_seq.size()); for(std::string::size_type i(0);i