Commit patch to not break on spaces.
[bowtie.git] / refmap.h
1 /*
2  * refmap.h
3  *
4  *  Created on: Aug 3, 2009
5  *      Author: Ben Langmead
6  */
7
8 #ifndef REFMAP_H_
9 #define REFMAP_H_
10
11 #include <stdint.h>
12 #include <cassert>
13 #include <vector>
14 #include <iostream>
15 #include <fstream>
16
17 class ReferenceMap {
18         typedef std::pair<uint32_t, uint32_t> U32Pair;
19
20 public:
21         ReferenceMap(const char *fname, bool parseNames) {
22                 fname_ = fname;
23                 parseNames_ = parseNames;
24                 parse();
25         }
26
27         /**
28          * Give a reference coordinate in the index, translate it into a
29          * new reference coordinate via the reference map supplied by the
30          * user.
31          */
32         void map(U32Pair& h) const;
33
34         /**
35          * Return true iff we have a name for reference with id 'i'.
36          */
37         bool hasName(size_t i) const {
38                 if(!parseNames_) return false;
39                 return !names_[i].empty();
40         }
41
42         /**
43          * Get the name for reference with id 'i'.
44          */
45         const std::string& getName(size_t i) const {
46                 assert(parseNames_);
47                 assert(hasName(i));
48                 return names_[i];
49         }
50
51 protected:
52
53         /**
54          * Parse a reference-map file.
55          */
56         void parse();
57
58         const char *fname_;
59         std::vector<U32Pair> map_;
60         bool parseNames_;
61         std::vector<std::string> names_;
62 };
63
64 #endif /* REFMAP_H_ */