11/* Part of SMITHLAB_CPP software
22 *
3- * Copyright (C) 2013-2019 University of Southern California and
3+ * Copyright (C) 2013-2023 University of Southern California and
44 * Andrew D. Smith
55 *
66 * Authors: Meng Zhou, Qiang Song, Andrew Smith
1616 * General Public License for more details.
1717 */
1818
19- #include < string >
20- # include < vector >
19+ #include " htslib_wrapper.hpp "
20+
2121#include < fstream>
2222#include < iostream>
23+ #include < string>
24+ #include < vector>
2325
24- #include " htslib_wrapper.hpp"
25- #include " smithlab_utils.hpp"
2626#include " MappedRead.hpp"
27+ #include " smithlab_utils.hpp"
2728
28- // extern "C" {
29- // #include <htslib/thread_pool.h>
30- // }
31-
32- using std::string;
33- using std::vector;
3429using std::cerr;
3530using std::endl;
3631using std::runtime_error;
32+ using std::string;
33+ using std::vector;
3734
38- char check_htslib_wrapper () {return 1 ;}
39-
40- /*
41- void
42- SAMReader::add_threads(const size_t n_threads) {
43- // ADS: should probably check that `hts_tpool` succeeded
44- tp = new htsThreadPool{hts_tpool_init(n_threads), 0};
45- // tp->pool = hts_tpool_init(n_threads);
46- // tp->qsize = 0;
47- const int err_code = hts_set_thread_pool(hts, tp);
48- if (err_code < 0) throw runtime_error("error setting threads");
35+ char
36+ check_htslib_wrapper () {
37+ return 1 ;
4938}
50- */
51-
52- SAMReader::SAMReader (const string &fn) :
53- filename(fn), good(true ), hts(nullptr ),
54- hdr(nullptr ), b(nullptr ) { // , tp(nullptr) {
5539
40+ SAMReader::SAMReader (const string &fn)
41+ : filename(fn), good(true ), hts(nullptr ), hdr(nullptr ), b(nullptr ) {
5642 if (!(hts = hts_open (filename.c_str (), " r" )))
5743 throw runtime_error (" cannot open file: " + filename);
5844
@@ -79,17 +65,10 @@ SAMReader::~SAMReader() {
7965 assert (hts_close (hts) >= 0 );
8066 hts = nullptr ;
8167 }
82- // if (tp) {
83- // assert(tp->pool);
84- // hts_tpool_destroy(tp->pool);
85- // tp->pool = nullptr;
86- // tp = nullptr;
87- // }
8868 good = false ;
8969}
9070
91-
92- SAMReader&
71+ SAMReader &
9372operator >>(SAMReader &reader, sam_rec &aln) {
9473 reader.get_sam_record (aln);
9574 return reader;
@@ -111,7 +90,7 @@ SAMReader::get_sam_record(sam_rec &sr) {
11190 if ((fmt_ret = sam_format1 (hdr, b, &hts->line )) <= 0 )
11291 throw runtime_error (" failed reading record from: " + filename);
11392 sr = sam_rec (hts->line .s );
114- good = true ; // reader.get_sam_record(reader.hts->line.s, sr);
93+ good = true ; // reader.get_sam_record(reader.hts->line.s, sr);
11594 // ADS: line below seems to be needed when the file format is SAM
11695 // because the hts_getline for parsing SAM format files within
11796 // sam_read1 only get called when "(fp->line.l == 0)". For BAM
@@ -122,12 +101,12 @@ SAMReader::get_sam_record(sam_rec &sr) {
122101 }
123102 else if (rd_ret == -1 )
124103 good = false ;
125- else // rd_ret < -1
104+ else // rd_ret < -1
126105 throw runtime_error (" failed to read record from file: " + filename);
127106 return good;
128107}
129108
130109string
131110SAMReader::get_header () const {
132- return hdr->text ; // includes newline
111+ return hdr->text ; // includes newline
133112}
0 commit comments