-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataStructures.h
298 lines (263 loc) · 9.12 KB
/
DataStructures.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/**
* @file DataStructures.h
* @author Amirhosein Afshinfard <afshinfard(at)ce(.)sharif(.)edu>
* <afshinfard(at)gmail(.)com>
* Bioinformatics Research Lab - Sharif Uiversity of Technology
*
* @cite
*
* @copyright (c) 2017
*
* Amirhosein Afshinfard <afshinfard(at)ce (.)sharif(.)edu>
* <afshinfard(at)gmail(.)com>
* Damoon Nashta-ali <damoun_dna(at)yahoo(.)com>
* Seyed Abolfazl Motahari <motahari(at)sharif(.)edu>
*
**/
#ifndef DATASTRUCTURES_H
#define DATASTRUCTURES_H
#include <cstdint>
#include <iostream>
#include <vector>
#include <map>
#include <string>
struct informativeChunk{
string readName = "";
uint32_t loci = 0;
bool bpIsRight = 0;
bool isRelated = 0;
uint32_t related_loci = 0;
bool related_bpIsRight = 0;
informativeChunk(){}
informativeChunk( const informativeChunk &a ):
readName(a.readName), loci(a.loci), bpIsRight(a.bpIsRight), isRelated(a.isRelated), related_loci(a.related_loci), related_bpIsRight(a.related_bpIsRight){}
informativeChunk( string readNamee, uint32_t locii, bool bpIsRightt, bool isRelatedd, uint32_t related_locii, bool related_bpIsRightt):
readName(readNamee), loci(locii), bpIsRight(bpIsRightt), isRelated(isRelatedd), related_loci(related_locii), related_bpIsRight(related_bpIsRightt){}
// bool operator<(const informativeChunk &a, const informativeChunk &b)
// {
// return a.loci < b.loci;
// }
};
//std::ostream& dump(std::ostream &o, const informativeChunk& p)
//{
// return o << p.readName << endl << p.loci << endl << p.bpIsRight << endl << p.isRelated << endl << p.related_loci << endl << p.related_bpIsRight << endl;
//}
//std::ostream& operator << (std::ostream &o,const informativeChunk &a){
// return dump(o,a);
//}
std::ostream& operator<<(std::ostream& os, const informativeChunk& pr)
{
return os << pr.readName << " " << pr.loci << " " << pr.bpIsRight << " " << pr.isRelated << " " << pr.related_loci << " " << pr.related_bpIsRight << endl;
}
std::istream& operator>>(std::istream& is, informativeChunk& pr)
{
string newName;
informativeChunk new_pr;
if( is >> std::ws
&& is >> newName /*std::getline(is, newName, 'q')*/
&& is >> new_pr.loci >> new_pr.bpIsRight >> new_pr.isRelated >> new_pr.related_loci >> new_pr.related_bpIsRight )
{
new_pr.readName = newName;
pr = new_pr; // could do more validation here
}else cout<<"Reading format problem!";
return is;
}
bool operator<(const informativeChunk &a, const informativeChunk &b)
{
return a.loci < b.loci;
}
bool compLoci(const informativeChunk &a, const informativeChunk &b){
return a.loci < b.loci;
}
bool compConnected(const informativeChunk &a, const informativeChunk &b){
return a.related_loci < b.related_loci;
}
struct connectedEvent{
long long index = 0;
bool isRightBP = false;
int weight = 0;
connectedEvent(){}
connectedEvent( long long indexx, bool isRightBPp, int weightt ):
index(indexx), isRightBP(isRightBPp), weight(weightt){}
};
bool operator<(const connectedEvent &a, const connectedEvent &b)
{
return a.weight < b.weight;
}
struct feasibleEvents{
vector<informativeChunk> informatives;
int maxDepth = 0;
uint32_t start = 0;
uint32_t end = 0;
vector<connectedEvent> connectedEvents;
};
struct mapResult{
long long position = 0; // 0:not searched yet - -1: can't find uniqely - -2: can't fnd with least size
bool isReverse = false;
//int flag;
//string cigar;
mapResult(){}
mapResult(long long p, bool isReverse):position(p),isReverse(isReverse){}
};
struct solvedFragInfo{
long startChunk = 0;
long long startPos = 0;
long endChunk = 0;
long long endPos = 0;
bool isReverse = false;
int shift = -1;
//int flag;
//string cigar;
solvedFragInfo(){}
solvedFragInfo(long start_c, long long start_p, long end_c, long long end_p, bool rev, int shiftt):
startChunk(start_c),startPos(start_p),endChunk(end_c),endPos(end_p),isReverse(rev),shift(shiftt){}
// bool operator<(const solvedFragInfo &a, const solvedFragInfo &b)
// {
// return a.startChunk < b.startChunk;
// }
};
bool operator<(const solvedFragInfo &a, const solvedFragInfo &b)
{
return a.startChunk < b.startChunk;
}
struct unMappedReads{
string name = "";
string read = "";
string quality = "";
unMappedReads(){}
unMappedReads(string namee, string readd, string qualityy ):
name(namee),read(readd),quality(qualityy){}
};
//
//
//
//
//
struct informativeReadsData{
long long index = 0;
string readName = "EMP";
string readSeq = "EMP";
vector<solvedFragInfo> clusters;
informativeReadsData(){}
informativeReadsData( long long indexx, string readname, string readseq, vector<solvedFragInfo> clusterss):
index(indexx),readName(readname),readSeq(readseq){
clusters = clusterss;
}
};
//std::istream& operator>>(std::istream& is, informativeReadsData& pr)
//{
// informativeReadsData new_pr;
// if( is >> std::ws
// && std::getline(is, new_pr.Name, '~')
// && is >> new_pr.StartSalary >> new_pr.Age )
// {
// pr = new_pr; // could do more validation here
// }
// return is;
//}
//std::ostream& operator<<(std::ostream& os, const informativeReadsData& pr)
//{
// return os << pr.index << " " << pr.readName << " " << pr.readSeq << " " << pr.clusters << '\n';
//}
struct interval{
long start = 0;
long end = 0;
interval(){}
interval(long p, long q):start(p),end(q){}
};
struct singleBowtied{
long long readIndex = 0;
int fragNum = 0;
long long snap = 0;
int flag = 0;
singleBowtied(){}
singleBowtied(long long rI, int fN, long long s, int f):readIndex(rI),fragNum(fN),snap(s),flag(f){}
};
// usage : singleUniqes[ stoll(tokens[0])-1 ].push_back( singleBowtied(stoll(tokens[0]) , stoi(tokens[1]) , stoll(tokens[2]) , stoi(tokens[3]) ) );
// ////////////////////////////
// ////////////////// Graph
struct vertex {
typedef pair<int, vertex*> ve;
vector<ve> adj; //cost of edge, destination vertex
string name;
long long start;
long long end;
int depth;
bool isRight;
vertex(string n, long long s, long long e, int dep, bool isR) : name(n),start(s), end(e), depth(dep), isRight(isR) {}
};
class graph
{
public:
typedef map<string, vertex *> vmap;
vmap work;
void addVertex(const string&, long long s, long long e, int dep, bool isR);
void addEdge(const string& from, const string& to, double cost);
void buildFromMatrices(int** adjacencyMatrix, int nodeCount, int *nodeWeight, int *nodeLocation[2], bool *node_BPIsRight );
void addPrimeEdge(const string& from, const string& to);
void overlappedConnector();
string *dfsNodes(const string nodeName);
};
string *graph::dfsNodes(const string nodeName){
vector<string> dfs_Nodes;
vertex *node = work.find(nodeName)->second;
typedef pair<int, vertex*> ve;
//vector<ve> adj;
for(vector<ve>::iterator itr = node->adj.begin() ; itr != node->adj.end() ; ++itr){
// error
if(dfs_Nodes.find( itr->first ) == dfs_Nodes.end() ){
// error
dfs_Nodes.push_back( itr->first );
// error
dfsNodes( itr->first );
}
}
}
void graph::addVertex(const string &name, long long s, long long e, int dep, bool isR)
{
vmap::iterator itr = work.find(name);
if (itr == work.end())
{
vertex *v;
v = new vertex(name,s,e,dep,isR);
work[name] = v;
return;
}
cout << "\nVertex already exists!";
}
void graph::addEdge(const string& from, const string& to, double cost)
{
vertex *f = (work.find(from)->second);
vertex *t = (work.find(to)->second);
pair<int, vertex *> edge = make_pair(cost, t);
f->adj.push_back(edge);
}
void graph::buildFromMatrices(int** adjacencyMatrix, int nodeCount, int *nodeWeight, int *nodeLocation[2], bool *node_BPIsRight ){
for(int i = 0 ; i < nodeCount ; i++)
addVertex( std::to_string(i), nodeLocation[0][i],nodeLocation[1][i], nodeWeight[i], node_BPIsRight[i]);
for(int i = 0; i < nodeCount; ++i)
for(int j = 0; j < nodeCount; ++j)
if(adjacencyMatrix[i][j] != 0)
addEdge(std::to_string(i),std::to_string(j),adjacencyMatrix[i][j]);
else
;
}
void graph::addPrimeEdge(const string& from, const string& to)
{
vertex *f = (work.find(from)->second);
vertex *t = (work.find(to)->second);
pair<int, vertex *> edge = make_pair(-1, t);
f->adj.push_back(edge);
}
void graph::overlappedConnector(){
for(vmap::iterator itr = work.begin() ; itr != work.end() ; itr++)
for(vmap::iterator itr2 = work.begin() ; itr2 != work.end() ; itr2++)
if(itr != itr2){
vertex *f = (work.find(from)->second);
vertex *t = (work.find(to)->second);
if( (f->start > t->start && f->start < t->end ) ||
(f->end > t->start && f->end < t->end ))
addPrimeEdge(f->name,t->name);
}
}
#endif // DATASTRUCTURES_H