forked from grenaud/libgab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReconsReferenceBAM.h
96 lines (75 loc) · 1.9 KB
/
ReconsReferenceBAM.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* ReconsReferenceBAM
* Date: Oct-03-2012
* Author : Gabriel Renaud gabriel.reno [at sign here] gmail.com
*
*/
#ifndef ReconsReferenceBAM_h
#define ReconsReferenceBAM_h
#include <vector>
#include <stdlib.h> //for exit()
#include "api/BamMultiReader.h"
#include "api/BamReader.h"
#include "api/BamWriter.h"
#include "api/BamAux.h"
using namespace BamTools;
using namespace std;
typedef struct{
char bp;
int offset;
} mdField;
static int asciiOffsetZero=48;
static char DUMMYCHAR='#';
//! To convert the MD first into a vector of mdField structs
/*!
*
* This function converts the MD field into a vector of mdField structs
* we skip deletions in the read (ins in reference)
*
\return vector<mdField> a vector of mdField structures
*/
inline vector<mdField> mdString2Vector(const string & mdFieldToParse){
vector<mdField> toReturn;
int i=0;
// int addToOffset=0;
mdField toadd;
toadd.offset=0;
toadd.bp='N';
while(int(mdFieldToParse.length()) != i){
if(isdigit(mdFieldToParse[i])){
toadd.offset=toadd.offset*10+(int(mdFieldToParse[i])-asciiOffsetZero);
}else{
//deletions in read (insertion in reference)
if(mdFieldToParse[i] == '^'){
if(toadd.offset != 0){
toadd.bp=DUMMYCHAR;
toReturn.push_back(toadd);
toadd.offset=0;
toadd.bp='N';
}
i++;
mdField toadd2;
toadd2.offset=0;
toadd2.bp='^';
while(isalpha(mdFieldToParse[i])){
i++;
toadd2.offset++;
}
toReturn.push_back(toadd2);
i--;
}else{
toadd.bp=mdFieldToParse[i];
toReturn.push_back(toadd);
toadd.offset=0;
toadd.bp='N';
}
}
i++;
}
return toReturn;
}
string reconstructRef(const BamAlignment * al);
pair< string, vector<int> > reconstructRefWithPos(const BamAlignment * al);
pair< string, vector<int> > reconstructRefWithPosOnRead(const BamAlignment * al);
int numberOfDeletions(const BamAlignment * al);
#endif