2 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
5 /* $Name: fa_34_26_5 $ - $Id: workacc.c,v 1.19 2006/02/07 17:58:19 wrp Exp $ */
7 /* Concurrent read version */
22 /* Initialization - set up defaults - assume protein sequence */
29 /* allocate memory for pam matrix - identical to version in initfa/sw.c */
30 alloc_pam (int d1, int d2, struct pstruct *ppst)
35 if ((ppst->pam2[0] = (int **) malloc (d1 * sizeof (int *))) == NULL) {
36 sprintf(err_str,"Cannot allocate 2D pam matrix: %d",d1);
40 if ((ppst->pam2[1] = (int **) malloc (d1 * sizeof (int *))) == NULL) {
41 sprintf(err_str,"Cannot allocate 2D pam matrix: %d",d1);
45 if ((d2p = pam12 = (int *) malloc (d1 * d2 * sizeof (int))) == NULL) {
46 sprintf(err_str,"Cannot allocate 2D pam matrix: %d",d1);
49 for (i = 0; i < d1; i++, d2p += d2) ppst->pam2[0][i] = d2p;
51 if ((d2p=pam12x= (int *) malloc (d1 * d2 * sizeof (int))) == NULL) {
52 sprintf(err_str,"Cannot allocate 2d pam matrix: %d",d2);
55 for (i = 0; i < d1; i++, d2p += d2) ppst->pam2[1][i] = d2p;
61 alloc_pam2p(int len, int nsq) {
65 if ((pam2p = (int **)calloc(len,sizeof(int *)))==NULL) {
66 fprintf(stderr," Cannot allocate pam2p: %d\n",len);
70 if((pam2p[0] = (int *)calloc((nsq+1)*len,sizeof(int)))==NULL) {
71 fprintf(stderr, "Cannot allocate pam2p[0]: %d\n", (nsq+1)*len);
76 for (i=1; i<len; i++) {
77 pam2p[i] = pam2p[0] + (i*(nsq+1));
83 void free_pam2p(int **pam2p) {
91 aancpy(char *to, char *from, int count, struct pstruct pst)
107 while (count-- && *from) {
108 if (*from <= nsq) *tp++ = sq[*(from++)];
109 else *tp++ = *from++;
115 /* copies from from to to shuffling */
118 shuffle(unsigned char *from, unsigned char *to, int n)
120 int i,j; unsigned char tmp;
122 if (from != to) memcpy((void *)to,(void *)from,(size_t)n);
124 for (i=n; i>0; i--) {
133 /* this shuffle is for FASTS */
134 /* convert ',' -> '\0', shuffle each of the substrings */
135 qshuffle(unsigned char *aa0, int n0, int nm0)
137 unsigned char **aa0start, *aap, tmp;
140 if ((aa0start=(unsigned char **)calloc(nm0+1,
141 sizeof(unsigned char *)))==NULL) {
142 fprintf(stderr,"cannot calloc for qshuffle %d\n",nm0);
146 for (k=1,i=0; i<n0; i++) {
147 if (aa0[i]==EOSEQ || aa0[i]==ESS) {
149 aa0start[k++] = &aa0[i+1];
153 /* aa0start has the beginning of each substring */
154 for (k=0; k<nm0; k++) {
156 ns = strlen((char *)aap);
157 for (i=ns; i>1; i--) {
166 for (k=1; k<nm0; k++) {
167 /* aap = aa0start[k];
168 while (*aap) fputc(pst.sq[*aap++],stderr);
177 /* copies from from to from shuffling */
179 wshuffle(unsigned char *from, unsigned char *to, int n, int wsiz, int *ieven)
182 unsigned char tmp, *top;
184 memcpy((void *)to,(void *)from,n);
189 for (k=0; k<(n-wsiz); k += wsiz) {
191 for (i=wsiz; i>0; i--) {
199 for (i=mm; i>0; i--) {
208 for (k=n; k>=wsiz; k -= wsiz) {
210 for (i=wsiz; i>0; i--) {
218 for (i=mm; i>0; i--) {
229 void initseq(char **seqc0, char **seqc0a, char **seqc1, char **seqca, int seqsiz) /* initialize arrays */
231 *seqc0=(char *)calloc((size_t)(seqsiz+1)*4,sizeof(char));
232 *seqc0a= *seqc0+seqsiz+1;
233 *seqc1= *seqc0a+seqsiz+1;
234 *seqca= *seqc1+seqsiz+1;
236 {fprintf(stderr,"cannot allocate consensus arrays %d\n",seqsiz);
240 void freeseq(char **seqc0, char **seqc1, char **seqca)
248 revcomp(unsigned char *seq, int n, int *c_nt)
253 for (i=0, ni = n-1; i< n/2; i++,ni--) {
255 seq[i] = c_nt[seq[ni]];
260 seq[i] = c_nt[seq[i]];