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