1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <malloc.h> |
---|
4 | #include <arbdb.h> |
---|
5 | #include "adtools.hxx" |
---|
6 | |
---|
7 | ADT_ALI::ADT_ALI() { |
---|
8 | gapsequence = 0; |
---|
9 | gapshowoffset = 0; |
---|
10 | gaprealoffset = 0; |
---|
11 | inited = 0; |
---|
12 | } |
---|
13 | |
---|
14 | ADT_ALI::~ADT_ALI() { |
---|
15 | } |
---|
16 | |
---|
17 | void ADT_ALI::init(AD_MAIN *ad_maini) |
---|
18 | { |
---|
19 | int len; |
---|
20 | AD_ALI::init(ad_maini); |
---|
21 | len = (int)(AD_ALI::len()); |
---|
22 | if (len<0) len = 0; |
---|
23 | gapsequence = (char *) malloc(len+1); // gap_init |
---|
24 | gapshowoffset = (int *) calloc(len,sizeof(int)); |
---|
25 | gaprealoffset = (int *) calloc(len,sizeof(int)); |
---|
26 | // testversion leerer gap |
---|
27 | for (int i = 0; i < len; i++) { |
---|
28 | gapsequence[i] = NOGAP_SYMBOL; |
---|
29 | gapshowoffset[i] = 0; |
---|
30 | gaprealoffset[i] = 0; |
---|
31 | } |
---|
32 | gapshowoffset_len = len; |
---|
33 | inited = 1; |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | |
---|
39 | // Funktionen auf gapsequence |
---|
40 | AD_ERR * ADT_ALI::gap_make(int position,int length) { |
---|
41 | int offset_sum = 1; |
---|
42 | int i,counter = 0; |
---|
43 | if (!((position+length > AD_ALI::len()) || gap_inside(position,position + length))) { |
---|
44 | for (i = position;i<position +length;i++) { // gapsequence |
---|
45 | gapsequence[i] = GAP_SYMBOL; |
---|
46 | } |
---|
47 | if (position == 0) { // luecke am anfang |
---|
48 | offset_sum = -length-1; |
---|
49 | } |
---|
50 | for (i = 0; i<AD_ALI::len(); i++) { // gaprealoffset |
---|
51 | if (gapsequence[i] == GAP_SYMBOL) { |
---|
52 | offset_sum ++; } |
---|
53 | gaprealoffset[i] = offset_sum; |
---|
54 | } |
---|
55 | |
---|
56 | offset_sum = 0; // gapshowoffset |
---|
57 | for (i = 0;i<AD_ALI::len() ; i++) { |
---|
58 | if (gapsequence[i] != GAP_SYMBOL) { |
---|
59 | gapshowoffset[counter] = offset_sum; |
---|
60 | counter ++; |
---|
61 | } else { |
---|
62 | offset_sum ++; |
---|
63 | } |
---|
64 | } |
---|
65 | gapshowoffset_len = counter-1; |
---|
66 | printf("gap maked % d of len %d\n",position,length); |
---|
67 | return 0; |
---|
68 | } else { |
---|
69 | return new AD_ERR("ADT_ALI::gap_make(int position,int length) ungueltige parameter"); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | AD_ERR * ADT_ALI::gap_delete(int showposition) { |
---|
75 | // showposition zeigt auf die position vor dem gap |
---|
76 | int i,counter=0,offset_sum = 0; |
---|
77 | int realpos = gap_realpos(showposition); |
---|
78 | int startpos = realpos + 1; |
---|
79 | int endpos = gap_realpos(showposition+1); |
---|
80 | for (i=startpos;i<endpos;i++) { |
---|
81 | gapsequence[i] = NOGAP_SYMBOL; |
---|
82 | } |
---|
83 | for (i = 0; i<AD_ALI::len(); i++) { // gaprealoffset |
---|
84 | if (gapsequence[i] == GAP_SYMBOL) { |
---|
85 | offset_sum ++; } |
---|
86 | gaprealoffset[i] = offset_sum; |
---|
87 | } |
---|
88 | |
---|
89 | offset_sum = 0; // gapshowoffset |
---|
90 | for (i = 0;i<AD_ALI::len() ; i++) { |
---|
91 | if (gapsequence[i] != GAP_SYMBOL) { |
---|
92 | gapshowoffset[counter] = offset_sum; |
---|
93 | counter ++; |
---|
94 | } else { |
---|
95 | offset_sum ++; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | gapshowoffset_len = gapshowoffset_len + endpos-startpos; |
---|
100 | return 0; |
---|
101 | } |
---|
102 | |
---|
103 | AD_ERR * ADT_ALI::gap_update(char *oldseq,char *newseq) { |
---|
104 | oldseq=oldseq;newseq=newseq; |
---|
105 | // realsequenz wurde in DAtenbank geaendert -> gap sequenz muss erneuert werden |
---|
106 | return 0; |
---|
107 | } |
---|
108 | |
---|
109 | char * ADT_ALI::gap_make_real_sequence(char *realseq,const char *showseq) { |
---|
110 | realseq=realseq;showseq=showseq; |
---|
111 | return 0; |
---|
112 | } |
---|
113 | |
---|
114 | char * ADT_ALI::gap_make_show_sequence(const char *realseq,char *showseq) { |
---|
115 | realseq=realseq;showseq=showseq; |
---|
116 | return 0; |
---|
117 | } |
---|
118 | |
---|
119 | int ADT_ALI::gap_inside(int realposition) { |
---|
120 | GBUSE(realposition); |
---|
121 | return 0; |
---|
122 | // if (gapsequence[realposition] != GAP_SYMBOL) |
---|
123 | // return 0; |
---|
124 | // return 1; |
---|
125 | } |
---|
126 | |
---|
127 | int ADT_ALI::gap_inside(int showposition1,int showposition2) { |
---|
128 | // if (gapshowoffset[showposition1] != gapshowoffset[showposition2]) |
---|
129 | // return 1; |
---|
130 | GBUSE(showposition1);GBUSE(showposition2); |
---|
131 | return 0; |
---|
132 | } |
---|
133 | |
---|
134 | int ADT_ALI::gap_behind(int showposition) { /* returns 1 if |
---|
135 | any excluded data is after |
---|
136 | showposition */ |
---|
137 | // if (gapshowoffset[showposition] != gapshowoffset[gapshowoffset_len-1]) { |
---|
138 | // return 1; } |
---|
139 | GBUSE(showposition); |
---|
140 | return 0; |
---|
141 | } |
---|
142 | |
---|
143 | int ADT_ALI::gap_realpos(int showposition) { |
---|
144 | return showposition; |
---|
145 | // return (showposition + gapshowoffset[showposition]); |
---|
146 | } |
---|
147 | |
---|
148 | int ADT_ALI::gap_showpos(int realposition) { |
---|
149 | return realposition; |
---|
150 | // return (realposition - gaprealoffset[realposition]); |
---|
151 | } |
---|
152 | |
---|
153 | #if 0 |
---|
154 | void ADT_ALI::operator = (ADT_ALI &adtali) |
---|
155 | { |
---|
156 | // hier gibt es probleme, wenn speicherplatz noch nicht reserviert wurde |
---|
157 | gapsequence = adtali.gapsequence; |
---|
158 | gaprealoffset = adtali.gaprealoffset; |
---|
159 | gapshowoffset = adtali.gapshowoffset; |
---|
160 | (AD_ALI)*this = (AD_ALI &)adtali; |
---|
161 | |
---|
162 | } |
---|
163 | #endif |
---|