Cigar.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #if !defined(_CIGAR_H)
00019 #define _CIGAR_H
00020
00021 #include <string.h>
00022 #include <limits.h>
00023 #include <stdint.h>
00024
00025
00026 #include <assert.h>
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <string>
00030 #include <iostream>
00031 #include <iomanip>
00032 #include <utility>
00033 #include <vector>
00034
00035 #include "Generic.h"
00036 #include "StringBasics.h"
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00072
00073
00074
00075
00076
00077
00078
00079
00080 class Cigar
00081 {
00082 public:
00083 enum Operation {none, match, mismatch, insert, del, skip, softClip, hardClip, pad};
00084
00085
00086
00087 static bool foundInQuery(Operation op)
00088 {
00089 switch(op)
00090 {
00091 case match:
00092 case mismatch:
00093 case insert:
00094 case softClip:
00095 return true;
00096 default:
00097 return false;
00098 }
00099 return false;
00100 }
00101
00102
00103
00104 static bool isClip(Operation op)
00105 {
00106 switch(op)
00107 {
00108 case softClip:
00109 case hardClip:
00110 return true;
00111 default:
00112 return false;
00113 }
00114 return false;
00115 }
00116
00118
00119
00120
00121 struct CigarOperator
00122 {
00123
00124 CigarOperator()
00125 {
00126 operation = none;
00127 count = 0;
00128 }
00129
00130 CigarOperator(Operation operation, uint32_t count): operation(operation), count(count) {};
00131
00132 Operation operation;
00133
00134 uint32_t count;
00135
00136
00137 char getChar() const
00138 {
00139 switch (operation)
00140 {
00141 case none:
00142 return '?';
00143 case match:
00144 case mismatch:
00145 return'M';
00146 case insert:
00147 return 'I';
00148 case del:
00149 return'D';
00150 case skip:
00151 return 'N';
00152 case softClip:
00153 return 'S';
00154 case hardClip:
00155 return 'H';
00156 case pad:
00157 return 'P';
00158 }
00159 return '?';
00160 }
00161
00162
00163
00164
00165
00166
00167 bool operator == (const CigarOperator &rhs) const
00168 {
00169 if (operation==rhs.operation)
00170 return true;
00171 if ((operation == mismatch || operation == match) && (rhs.operation == mismatch || rhs.operation == match))
00172 return true;
00173 return false;
00174 }
00175
00176 bool operator != (const CigarOperator &rhs) const
00177 {
00178 return !((*this) == rhs) ;
00179 }
00180
00181 };
00182
00184
00185
00186
00187 friend std::ostream &operator << (std::ostream &stream, const Cigar& cigar);
00188
00189 Cigar()
00190 {
00191 clearQueryAndReferenceIndexes();
00192 }
00193
00194
00195
00196
00197
00198 void getCigarString(String& cigarString) const;
00199 void getCigarString(std::string& cigarString) const;
00200
00209 void getExpandedString(std::string &s) const;
00210
00211 const CigarOperator & operator [](int i) const
00212 {
00213 return cigarOperations[i];
00214 }
00215
00216 const CigarOperator & getOperator(int i) const
00217 {
00218 return cigarOperations[i];
00219 }
00220
00221 bool operator == (Cigar &rhs) const;
00222
00223
00224
00225
00226 int size() const
00227 {
00228 return cigarOperations.size();
00229 }
00230
00231 void Dump() const
00232 {
00233 String cigarString;
00234 getCigarString(cigarString);
00235 std::cout << cigarString ;
00236 }
00237
00255 int getExpectedQueryBaseCount() const;
00256
00273 int getExpectedReferenceBaseCount() const;
00274
00276 int getNumBeginClips() const;
00277
00279 int getNumEndClips() const;
00280
00281
00282
00283 int32_t getRefOffset(int32_t queryIndex);
00284
00285
00286
00287 int32_t getQueryIndex(int32_t refOffset);
00288
00289
00290
00291
00292
00293 int32_t getRefPosition(int32_t queryIndex, int32_t queryStartPos);
00294
00295
00296
00297
00298 int32_t getQueryIndex(int32_t refPosition, int32_t queryStartPos);
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 uint32_t getNumOverlaps(int32_t start, int32_t end, int32_t queryStartPos);
00311
00312 static const int32_t INDEX_NA;
00313
00314 protected:
00315
00316 void clearQueryAndReferenceIndexes();
00317
00318
00319 void setQueryAndReferenceIndexes();
00320
00321
00322 std::vector<CigarOperator> cigarOperations;
00323
00324 private:
00325
00326
00327
00328
00329 std::vector<int32_t> queryToRef;
00330
00331
00332
00333
00334
00335 std::vector<int32_t> refToQuery;
00336 };
00337
00338 inline std::ostream &operator << (std::ostream &stream, const Cigar::CigarOperator& o)
00339 {
00340 stream << o.count << o.getChar();
00341 return stream;
00342 }
00343
00344 inline std::ostream &operator << (std::ostream &stream, const Cigar& cigar)
00345 {
00346 stream << cigar.cigarOperations;
00347 return stream;
00348 }
00349
00350 #endif