Debian Codegraph @

SeqLib/BamWalker.h

raw symbols SCIP
1 #ifndef SEQLIB_BAM_WALKER_H__
2 #define SEQLIB_BAM_WALKER_H__
3
4 #include <cassert>
5
6 #include <stdint.h>
7 #include "SeqLib/BamRecord.h"
8
9 // not sure what going on here...
10 #ifndef INT32_MAX
11 #define INT32_MAX 0x7fffffffL
12 #endif
13
14 struct idx_delete {
15 void operator()(hts_idx_t* x) { if (x) hts_idx_destroy(x); }
16 };
17
18 struct hts_itr_delete {
19 void operator()(hts_itr_t* x) { if (x) hts_itr_destroy(x); }
20 };
21
22 struct bgzf_delete {
23 void operator()(BGZF* x) { if(x) bgzf_close(x); }
24 };
25
26 struct bam_hdr_delete {
27 void operator()(bam_hdr_t* x) { if (x) bam_hdr_destroy(x); }
28 };
29
30 struct htsFile_delete { // shoudl also close cram index
31 void operator()(htsFile* x) { if (x) sam_close(x); }
32 };
33
34 // Phred score transformations
35 inline int char2phred(char b) {
36 uint8_t v = b;
37 assert(v >= 33);
38 return v - 33;
39 }
40
41 // from samtools
42 inline char *samfaipath(const char *fn_ref)
43 {
44 char *fn_list = 0;
45 if (fn_ref == 0) return 0;
46 fn_list = (char*)calloc(strlen(fn_ref) + 5, 1);
47 strcat(strcpy(fn_list, fn_ref), ".fai");
48 if (access(fn_list, R_OK) == -1) { // fn_list is unreadable
49 std::cerr << "ERROR: Cannot read the index file for CRAM read/write" << std::endl;
50 }
51 return fn_list;
52 }
53
54 namespace SeqLib {
55
56 /** Small class to store a counter to measure BamReader progress.
57 * Currently only stores number of reads seen / kept.
58 */
59 struct ReadCount {
60
61 uint32_t keep; ///< Store total number of reads kept
62 uint32_t total; ///< Store total number of reads seen
63
64 ReadCount() : keep(0), total(0) {}
65
66 /** Return the percent of total reads kept
67 */
68 int percent () const {
69 int perc = SeqLib::percentCalc<uint64_t>(keep, total);
70 return perc;
71 }
72
73 /** Return the total reads visited as a comma-formatted string */
74 std::string totalString() const {
75 return SeqLib::AddCommas<uint64_t>(total);
76 }
77
78 /** Return the kept reads as a comma-formatted string */
79 std::string keepString() const {
80 return SeqLib::AddCommas<uint64_t>(keep);
81 }
82
83 };
84
85 }
86 #endif