-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetITX.cpp
111 lines (91 loc) · 2.68 KB
/
getITX.cpp
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
/*
* getITX.c
*
* Created on: Feb 2, 2017
* Author: goel
*/
#include "getITX.h"
void parseITX(std::vector<BLOCK> &chromo, char chr[], int num) {
int i;
for (i = 1; i < num-1; i++) {
if (chromo[i].bchr.compare(chr) == 0 && chromo[i].state != CTX && chromo[i].state != SYN) { //&& blocks[i].state != SYN_IN_INV && blocks[i].state != INV) {
if(chromo[i].dir == 1){
chromo[i].state = ITX;
}
else if (chromo[i].dir == -1){
chromo[i].state = INV_ITX;
}
}
}
}
void groupITX(std::vector<BLOCK> &chromo, char chr[], int num){
int i, in = -1;
int state;
for (i = 1; i < num-1; i++) {
if (chromo[i].bchr.compare(chr) == 0 && (chromo[i].state == ITX || chromo[i].state == INV_ITX || chromo[i].state == ITX_IN_INV)) {
if (in == -1) {
in = i;
state = chromo[i].state;
}
else {
// There is a itx already, do they belong together?
// If yes, do nothing
// If no, print old set
int together = 1;
if (chromo[i].bchr.compare(chromo[i-1].bchr) != 0 || chromo[i].dir != chromo[i-1].dir) {
// not on same chromosome or different direction?
together = 0;
}
else { // on same chr and same direction, but next to each other also on B genome?
if ((chromo[i].dir == 1 && chromo[i].leftBNeighbor != i-1) ||
(chromo[i].dir == -1 && chromo[i].rightBNeighbor != i-1)) {
together = 0;
}
else{
if(chromo[i].state != state){
together = 0;
}
}
}
if (together == 0) {
writeITX(chromo, in, i-1);
in = i;
}
}
}
else {
// Write if a ITX was just passed
if (in != -1) {
writeITX(chromo, in, i-1);
}
in = -1;
}
}
if (in != -1) {
writeITX(chromo,in, i-1);
}
}
void writeITX(std::vector<BLOCK> &chromo, int a, int b) {
//Header
switch(chromo[a].state){
case 5://ITX
fprintf(itxOutFile,"#ITX\t");
//printf("chr : %s \t chr: %d\n", chromo[a].achr, chromo[a].achr);
fprintf(itxOutFile, "%s %d %d - ", chromo[a].achr.c_str(), chromo[a].astart, chromo[b].aend);
fprintf(itxOutFile, "%s %d %d\n", chromo[a].bchr.c_str(), chromo[b].bstart, chromo[b].bend);
break;
case 6: //Inverted ITX
fprintf(itxOutFile,"#INV_ITX\t");
fprintf(itxOutFile, "%s %d %d - ", chromo[a].achr.c_str(), chromo[a].astart, chromo[b].aend);
fprintf(itxOutFile, "%s %d %d\n", chromo[a].bchr.c_str(), chromo[b].bstart, chromo[a].bend);
break;
case 7: //Inverted ITX
fprintf(itxOutFile,"#ITX_IN_INV\t");
fprintf(itxOutFile, "%s %d %d - ", chromo[a].achr.c_str(), chromo[a].astart, chromo[b].aend);
fprintf(itxOutFile, "%s %d %d\n", chromo[a].bchr.c_str(), chromo[b].bstart, chromo[a].bend);
break;
}
for (int i = a; i <= b; i++) {
writeBlock(itxOutFile, chromo[i]);
}
}