| 1 | #include "mltaln.h" |
|---|
| 2 | |
|---|
| 3 | #define DEBUG 0 |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | static char *comment; |
|---|
| 7 | static char *orderfile; |
|---|
| 8 | static int format; |
|---|
| 9 | static int namelen; |
|---|
| 10 | |
|---|
| 11 | static void fillspace( char *seq, int lenmax ) |
|---|
| 12 | { |
|---|
| 13 | int len = strlen( seq ); |
|---|
| 14 | seq += len; |
|---|
| 15 | lenmax -= len; |
|---|
| 16 | while( lenmax-- ) *seq++ = ' '; |
|---|
| 17 | *seq = 0; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | void setmark_clustal( int nlen, int nseq, char **seq, char *mark ) |
|---|
| 21 | { |
|---|
| 22 | int i, j, k, nalpha; |
|---|
| 23 | char firstletter; |
|---|
| 24 | char *strong[9]; |
|---|
| 25 | char *weaker[11]; |
|---|
| 26 | int nstrong, nweaker; |
|---|
| 27 | char s; |
|---|
| 28 | |
|---|
| 29 | if( dorp == 'd' ) |
|---|
| 30 | { |
|---|
| 31 | strong[0] = "TU"; |
|---|
| 32 | nstrong = 1; |
|---|
| 33 | weaker[0] = "AG"; |
|---|
| 34 | weaker[1] = "CT"; |
|---|
| 35 | nweaker = 2; |
|---|
| 36 | nalpha = 10; |
|---|
| 37 | } |
|---|
| 38 | else |
|---|
| 39 | { |
|---|
| 40 | strong[0] = "STA"; |
|---|
| 41 | strong[1] = "NEQK"; |
|---|
| 42 | strong[2] = "NHQK"; |
|---|
| 43 | strong[3] = "NDEQ"; |
|---|
| 44 | strong[4] = "QHRK"; |
|---|
| 45 | strong[5] = "MILV"; |
|---|
| 46 | strong[6] = "MILF"; |
|---|
| 47 | strong[7] = "HY"; |
|---|
| 48 | strong[8] = "FYW"; |
|---|
| 49 | nstrong = 9; |
|---|
| 50 | weaker[0] = "CSA"; |
|---|
| 51 | weaker[1] = "ATV"; |
|---|
| 52 | weaker[2] = "SAG"; |
|---|
| 53 | weaker[3] = "STNK"; |
|---|
| 54 | weaker[4] = "STPA"; |
|---|
| 55 | weaker[5] = "SGND"; |
|---|
| 56 | weaker[6] = "SNDEQK"; |
|---|
| 57 | weaker[7] = "NDEQHK"; |
|---|
| 58 | weaker[8] = "NEQHRK"; |
|---|
| 59 | weaker[9] = "FVLIM"; |
|---|
| 60 | weaker[10] = "HFY"; |
|---|
| 61 | nweaker = 11; |
|---|
| 62 | nalpha = 20; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | for( i=0; i<nlen; i++ ) |
|---|
| 66 | { |
|---|
| 67 | mark[i] = ' '; |
|---|
| 68 | for( j=0; j<nseq; j++ ) |
|---|
| 69 | { |
|---|
| 70 | s = seq[j][i]; |
|---|
| 71 | if( '-' == s || ' ' == s ) break; |
|---|
| 72 | } |
|---|
| 73 | if( j != nseq ) |
|---|
| 74 | { |
|---|
| 75 | continue; |
|---|
| 76 | } |
|---|
| 77 | firstletter = toupper( seq[0][i] ); |
|---|
| 78 | if( amino_n[(int)firstletter] >= nalpha || amino_n[(int)firstletter] < 0 ) continue; |
|---|
| 79 | |
|---|
| 80 | for( j=0; j<nseq; j++ ) |
|---|
| 81 | if( toupper( seq[j][i] ) != firstletter ) break; |
|---|
| 82 | if( j == nseq ) |
|---|
| 83 | { |
|---|
| 84 | mark[i] = '*'; |
|---|
| 85 | continue; |
|---|
| 86 | } |
|---|
| 87 | for( k=0; k<nstrong; k++ ) |
|---|
| 88 | { |
|---|
| 89 | for( j=0; j<nseq; j++ ) |
|---|
| 90 | { |
|---|
| 91 | if( !strchr( strong[k], toupper( seq[j][i] ) ) ) break; |
|---|
| 92 | } |
|---|
| 93 | if( j == nseq ) break; |
|---|
| 94 | } |
|---|
| 95 | if( k < nstrong ) |
|---|
| 96 | { |
|---|
| 97 | mark[i] = ':'; |
|---|
| 98 | continue; |
|---|
| 99 | } |
|---|
| 100 | for( k=0; k<nweaker; k++ ) |
|---|
| 101 | { |
|---|
| 102 | for( j=0; j<nseq; j++ ) |
|---|
| 103 | { |
|---|
| 104 | if( !strchr( weaker[k], toupper( seq[j][i] ) ) ) break; |
|---|
| 105 | } |
|---|
| 106 | if( j == nseq ) break; |
|---|
| 107 | } |
|---|
| 108 | if( k < nweaker ) |
|---|
| 109 | { |
|---|
| 110 | mark[i] = '.'; |
|---|
| 111 | continue; |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | mark[nlen] = 0; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | void setmark( int nlen, int nseq, char **seq, char *mark ) |
|---|
| 118 | { |
|---|
| 119 | int i, j; |
|---|
| 120 | |
|---|
| 121 | for( i=0; i<nlen; i++ ) |
|---|
| 122 | { |
|---|
| 123 | mark[i] = ' '; |
|---|
| 124 | for( j=0; j<nseq; j++ ) |
|---|
| 125 | if( '-' == seq[j][i] ) break; |
|---|
| 126 | if( j != nseq ) |
|---|
| 127 | { |
|---|
| 128 | continue; |
|---|
| 129 | } |
|---|
| 130 | for( j=0; j<nseq; j++ ) |
|---|
| 131 | if( seq[0][i] != seq[j][i] ) break; |
|---|
| 132 | if( j == nseq ) |
|---|
| 133 | { |
|---|
| 134 | mark[i] = '*'; |
|---|
| 135 | continue; |
|---|
| 136 | } |
|---|
| 137 | for( j=0; j<nseq; j++ ) |
|---|
| 138 | if( amino_grp[(int)seq[0][i]] != amino_grp[(int)seq[j][i]] ) break; |
|---|
| 139 | if( j == nseq ) |
|---|
| 140 | { |
|---|
| 141 | mark[i] = '.'; |
|---|
| 142 | continue; |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | mark[nlen] = 0; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | void arguments( int argc, char *argv[] ) |
|---|
| 149 | { |
|---|
| 150 | int c; |
|---|
| 151 | namelen = -1; |
|---|
| 152 | scoremtx = 1; |
|---|
| 153 | nblosum = 62; |
|---|
| 154 | dorp = NOTSPECIFIED; |
|---|
| 155 | kimuraR = NOTSPECIFIED; |
|---|
| 156 | pamN = NOTSPECIFIED; |
|---|
| 157 | inputfile = NULL; |
|---|
| 158 | comment = NULL; |
|---|
| 159 | orderfile = NULL; |
|---|
| 160 | format = 'c'; |
|---|
| 161 | |
|---|
| 162 | while( --argc > 0 && (*++argv)[0] == '-' ) |
|---|
| 163 | { |
|---|
| 164 | while ( (c = *++argv[0]) ) |
|---|
| 165 | { |
|---|
| 166 | switch( c ) |
|---|
| 167 | { |
|---|
| 168 | case 'i': |
|---|
| 169 | inputfile = *++argv; |
|---|
| 170 | fprintf( stderr, "inputfile = %s\n", inputfile ); |
|---|
| 171 | --argc; |
|---|
| 172 | goto nextoption; |
|---|
| 173 | case 'c': |
|---|
| 174 | comment = *++argv; |
|---|
| 175 | fprintf( stderr, "comment = %s\n", comment ); |
|---|
| 176 | --argc; |
|---|
| 177 | goto nextoption; |
|---|
| 178 | case 'r': |
|---|
| 179 | orderfile = *++argv; |
|---|
| 180 | fprintf( stderr, "orderfile = %s\n", orderfile ); |
|---|
| 181 | --argc; |
|---|
| 182 | goto nextoption; |
|---|
| 183 | case 'n': |
|---|
| 184 | namelen = atoi( *++argv ); |
|---|
| 185 | fprintf( stderr, "namelen = %d\n", namelen ); |
|---|
| 186 | --argc; |
|---|
| 187 | goto nextoption; |
|---|
| 188 | case 'f': |
|---|
| 189 | format = 'f'; |
|---|
| 190 | break; |
|---|
| 191 | case 'y': |
|---|
| 192 | format = 'y'; |
|---|
| 193 | break; |
|---|
| 194 | default: |
|---|
| 195 | fprintf( stderr, "illegal option %c\n", c ); |
|---|
| 196 | argc = 0; |
|---|
| 197 | break; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | nextoption: |
|---|
| 201 | ; |
|---|
| 202 | } |
|---|
| 203 | if( argc != 0 ) |
|---|
| 204 | { |
|---|
| 205 | fprintf( stderr, "options: Check source file !\n" ); |
|---|
| 206 | exit( 1 ); |
|---|
| 207 | } |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | int main( int argc, char *argv[] ) |
|---|
| 212 | { |
|---|
| 213 | static int *nlen; |
|---|
| 214 | static char **name, **seq, *mark; |
|---|
| 215 | static int *order; |
|---|
| 216 | int i; |
|---|
| 217 | FILE *infp; |
|---|
| 218 | FILE *orderfp; |
|---|
| 219 | char gett[B]; |
|---|
| 220 | int nlenmin; |
|---|
| 221 | |
|---|
| 222 | arguments( argc, argv ); |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | if( inputfile ) |
|---|
| 226 | { |
|---|
| 227 | infp = fopen( inputfile, "r" ); |
|---|
| 228 | if( !infp ) |
|---|
| 229 | { |
|---|
| 230 | fprintf( stderr, "Cannot open %s\n", inputfile ); |
|---|
| 231 | exit( 1 ); |
|---|
| 232 | } |
|---|
| 233 | } |
|---|
| 234 | else |
|---|
| 235 | infp = stdin; |
|---|
| 236 | |
|---|
| 237 | getnumlen_casepreserve( infp, &nlenmin ); |
|---|
| 238 | rewind( infp ); |
|---|
| 239 | |
|---|
| 240 | seq = AllocateCharMtx( njob, nlenmax*2+1 ); |
|---|
| 241 | mark = AllocateCharVec( nlenmax*2+1 ); |
|---|
| 242 | order = AllocateIntVec( njob ); |
|---|
| 243 | name = AllocateCharMtx( njob, B+1 ); |
|---|
| 244 | nlen = AllocateIntVec( njob ); |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | if( orderfile ) |
|---|
| 248 | { |
|---|
| 249 | orderfp = fopen( orderfile, "r" ); |
|---|
| 250 | if( !orderfp ) |
|---|
| 251 | { |
|---|
| 252 | fprintf( stderr, "Cannot open %s\n", orderfile ); |
|---|
| 253 | exit( 1 ); |
|---|
| 254 | } |
|---|
| 255 | for( i=0; i<njob; i++ ) |
|---|
| 256 | { |
|---|
| 257 | fgets( gett, B-1, orderfp ); |
|---|
| 258 | order[i] = atoi( gett ); |
|---|
| 259 | } |
|---|
| 260 | fclose( orderfp ); |
|---|
| 261 | } |
|---|
| 262 | else |
|---|
| 263 | { |
|---|
| 264 | for( i=0; i<njob; i++ ) order[i] = i; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | readData_pointer_casepreserve( infp, name, nlen, seq ); |
|---|
| 268 | fclose( infp ); |
|---|
| 269 | |
|---|
| 270 | if( format == 'c' || format == 'y' ) for( i=0; i<njob; i++ ) fillspace( seq[i], nlenmax ); |
|---|
| 271 | constants( njob, seq ); |
|---|
| 272 | |
|---|
| 273 | // initSignalSM(); |
|---|
| 274 | |
|---|
| 275 | // initFiles(); |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | // setmark( nlenmax, njob, seq, mark ); |
|---|
| 280 | setmark_clustal( nlenmax, njob, seq, mark ); |
|---|
| 281 | |
|---|
| 282 | if( format == 'f' ) |
|---|
| 283 | writeData_reorder_pointer( stdout, njob, name, nlen, seq, order ); |
|---|
| 284 | else if( format == 'c' ) |
|---|
| 285 | clustalout_pointer( stdout, njob, nlenmax, seq, name, mark, comment, order, namelen ); |
|---|
| 286 | else if( format == 'y' ) |
|---|
| 287 | phylipout_pointer( stdout, njob, nlenmax, seq, name, order, namelen ); |
|---|
| 288 | else |
|---|
| 289 | fprintf( stderr, "Unknown format\n" ); |
|---|
| 290 | |
|---|
| 291 | // SHOWVERSION; |
|---|
| 292 | return( 0 ); |
|---|
| 293 | } |
|---|