fix: add include
This commit is contained in:
parent
525c9eb122
commit
b2951105ae
2 changed files with 2449 additions and 2789 deletions
330
HGL_SRC/Alloc.c
330
HGL_SRC/Alloc.c
|
@ -1,114 +1,104 @@
|
||||||
#include <stdio.h>
|
#include <ctype.h>
|
||||||
#include "global_defs.h"
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "global_defs.h"
|
||||||
/*
|
/*
|
||||||
* Alloc.c
|
* Alloc.c
|
||||||
* Memory functions for Harvard Genome Laboratory.
|
* Memory functions for Harvard Genome Laboratory.
|
||||||
* Last revised 6/3/91
|
* Last revised 6/3/91
|
||||||
*
|
*
|
||||||
* Print error message, and die
|
* Print error message, and die
|
||||||
*/
|
*/
|
||||||
void ErrorOut(code,string)
|
void ErrorOut(code, string) int code;
|
||||||
int code;
|
|
||||||
char *string;
|
char *string;
|
||||||
{
|
{
|
||||||
if (code == 0)
|
if (code == 0) {
|
||||||
{
|
fprintf(stderr, "Error:%s\n", string);
|
||||||
fprintf(stderr,"Error:%s\n",string);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calloc count*size bytes with memory aligned to size.
|
* Calloc count*size bytes with memory aligned to size.
|
||||||
* Return pointer to new block.
|
* Return pointer to new block.
|
||||||
*/
|
*/
|
||||||
char *Calloc(count,size)
|
char *Calloc(count, size)
|
||||||
int count,size;
|
int count, size;
|
||||||
/*unsigned count,size;*/
|
/*unsigned count,size;*/
|
||||||
{
|
{
|
||||||
char *temp;
|
char *temp;
|
||||||
temp = calloc(count,(unsigned)size);
|
temp = calloc(count, (unsigned)size);
|
||||||
|
|
||||||
if(count*size == 0)
|
if (count * size == 0) fprintf(stderr, "Allocate ZERO blocks?\n");
|
||||||
fprintf(stderr,"Allocate ZERO blocks?\n");
|
ErrorOut(temp, "Cannot allocate memory");
|
||||||
ErrorOut(temp,"Cannot allocate memory");
|
return (temp);
|
||||||
return(temp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reallocate memory at block, expand to size.
|
* Reallocate memory at block, expand to size.
|
||||||
* Return pointer to (possibly) new block.
|
* Return pointer to (possibly) new block.
|
||||||
*/
|
*/
|
||||||
char *Realloc(block,size)
|
char *Realloc(block, size)
|
||||||
char *block;
|
char *block;
|
||||||
unsigned size;
|
unsigned size;
|
||||||
{
|
{
|
||||||
char *temp;
|
char *temp;
|
||||||
temp=realloc(block,size);
|
temp = realloc(block, size);
|
||||||
ErrorOut(temp,"Cannot change memory size");
|
ErrorOut(temp, "Cannot change memory size");
|
||||||
return(temp);
|
return (temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free block Allocated by Calloc.
|
* Free block Allocated by Calloc.
|
||||||
* Return error code from free().
|
* Return error code from free().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Cfree(block)
|
void Cfree(block) char *block;
|
||||||
char* block;
|
|
||||||
{
|
{
|
||||||
extern void Warning();
|
extern void Warning();
|
||||||
if(block != NULL)
|
if (block != NULL) {
|
||||||
{
|
|
||||||
#ifdef SUN4
|
#ifdef SUN4
|
||||||
if(free(block) == 0)
|
if (free(block) == 0) Warning("Error in Cfree...");
|
||||||
Warning("Error in Cfree...");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/* else
|
/* else
|
||||||
Warning("Error in Cfree, NULL block");
|
Warning("Error in Cfree, NULL block");
|
||||||
*/
|
*/
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print Warning message to stderr.
|
* Print Warning message to stderr.
|
||||||
*/
|
*/
|
||||||
void Warning(s)
|
void Warning(s) char *s;
|
||||||
char *s;
|
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Warning:%s\n",s);
|
fprintf(stderr, "Warning:%s\n", s);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get array element from a sequence structure. The index
|
* Get array element from a sequence structure. The index
|
||||||
* is relative to the alignment.
|
* is relative to the alignment.
|
||||||
*/
|
*/
|
||||||
char GetElem(seq,indx)
|
char GetElem(seq, indx)
|
||||||
Sequence *seq; /*Sequence to search*/
|
Sequence *seq; /*Sequence to search*/
|
||||||
int indx; /*Index relative to the global offset*/
|
int indx; /*Index relative to the global offset*/
|
||||||
{
|
{
|
||||||
if((indx<seq->offset) || (indx >= seq->offset + seq->seqlen))
|
if ((indx < seq->offset) || (indx >= seq->offset + seq->seqlen))
|
||||||
return('-');
|
return ('-');
|
||||||
else
|
else
|
||||||
return((char)(seq->c_elem[indx-seq->offset]));
|
return ((char)(seq->c_elem[indx - seq->offset]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Replace the array element at seq[indx] with elem. The index
|
* Replace the array element at seq[indx] with elem. The index
|
||||||
* is relative to the alignment.
|
* is relative to the alignment.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ReplaceElem(seq,indx,elem)
|
void ReplaceElem(seq, indx, elem) Sequence *seq; /*Sequence */
|
||||||
Sequence *seq; /*Sequence */
|
|
||||||
int indx; /*Position to overwrite (replace) */
|
int indx; /*Position to overwrite (replace) */
|
||||||
unsigned char elem; /*Character to replace with */
|
unsigned char elem; /*Character to replace with */
|
||||||
{
|
{
|
||||||
|
@ -116,18 +106,17 @@ unsigned char elem; /*Character to replace with */
|
||||||
extern char *Calloc();
|
extern char *Calloc();
|
||||||
int width;
|
int width;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If no c_elem has been allocated yet...
|
* If no c_elem has been allocated yet...
|
||||||
*/
|
*/
|
||||||
/* if(index("abcdefghijklmnopqrstuvwxyz-0123456789",elem)==0)
|
/* if(index("abcdefghijklmnopqrstuvwxyz-0123456789",elem)==0)
|
||||||
fprintf(stderr,"Warning (ReplaceElem) elem = %c\n",elem);
|
fprintf(stderr,"Warning (ReplaceElem) elem =
|
||||||
*/
|
%c\n",elem);
|
||||||
width = seq->offset-indx;
|
*/
|
||||||
if(seq->seqlen == 0 && elem != '-')
|
width = seq->offset - indx;
|
||||||
{
|
if (seq->seqlen == 0 && elem != '-') {
|
||||||
if(seq->seqmaxlen == 0 || seq->c_elem == NULL)
|
if (seq->seqmaxlen == 0 || seq->c_elem == NULL) {
|
||||||
{
|
seq->c_elem = Calloc(4, sizeof(char));
|
||||||
seq->c_elem = Calloc(4,sizeof(char));
|
|
||||||
seq->offset = indx;
|
seq->offset = indx;
|
||||||
seq->seqmaxlen = 4;
|
seq->seqmaxlen = 4;
|
||||||
}
|
}
|
||||||
|
@ -135,118 +124,109 @@ unsigned char elem; /*Character to replace with */
|
||||||
seq->c_elem[0] = elem;
|
seq->c_elem[0] = elem;
|
||||||
seq->offset = indx;
|
seq->offset = indx;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* If inserting before the c_elem (< offset)
|
* If inserting before the c_elem (< offset)
|
||||||
*/
|
*/
|
||||||
else if((indx<seq->offset) && (elem!='-'))
|
else if ((indx < seq->offset) && (elem != '-')) {
|
||||||
{
|
|
||||||
seq->seqmaxlen += width;
|
seq->seqmaxlen += width;
|
||||||
seq->c_elem = Realloc(seq->c_elem,seq->seqmaxlen*sizeof(char));
|
seq->c_elem =
|
||||||
for(j=seq->seqmaxlen-1;j>=width;j--)
|
Realloc(seq->c_elem, seq->seqmaxlen * sizeof(char));
|
||||||
seq->c_elem[j] = seq->c_elem[j-width];
|
for (j = seq->seqmaxlen - 1; j >= width; j--)
|
||||||
for(j=0;j<width;j++)
|
seq->c_elem[j] = seq->c_elem[j - width];
|
||||||
seq->c_elem[j] = '-';
|
for (j = 0; j < width; j++) seq->c_elem[j] = '-';
|
||||||
seq->c_elem[0] = elem;
|
seq->c_elem[0] = elem;
|
||||||
seq->seqlen += width;
|
seq->seqlen += width;
|
||||||
seq->offset = indx;
|
seq->offset = indx;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* if inserting after c_elem (indx > offset + seqlen)
|
* if inserting after c_elem (indx > offset + seqlen)
|
||||||
*/
|
*/
|
||||||
else if((indx>=seq->offset+seq->seqlen) && (elem!='-'))
|
else if ((indx >= seq->offset + seq->seqlen) && (elem != '-')) {
|
||||||
{
|
if (indx - seq->offset >= seq->seqmaxlen) {
|
||||||
if(indx-seq->offset >= seq->seqmaxlen)
|
seq->seqmaxlen = indx - seq->offset + 256;
|
||||||
{
|
seq->c_elem =
|
||||||
seq->seqmaxlen = indx-seq->offset+256;
|
Realloc(seq->c_elem, seq->seqmaxlen * sizeof(char));
|
||||||
seq->c_elem = Realloc(seq->c_elem,seq->seqmaxlen*
|
|
||||||
sizeof(char));
|
|
||||||
}
|
}
|
||||||
for(j=seq->seqlen;j<seq->seqmaxlen;j++)
|
for (j = seq->seqlen; j < seq->seqmaxlen; j++)
|
||||||
seq->c_elem[j] = '-';
|
seq->c_elem[j] = '-';
|
||||||
seq->c_elem[indx-seq->offset] = elem;
|
seq->c_elem[indx - seq->offset] = elem;
|
||||||
seq->seqlen = indx-seq->offset+1;
|
seq->seqlen = indx - seq->offset + 1;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
if (indx - (seq->offset) >= 0 &&
|
||||||
if(indx-(seq->offset)>=0 && indx-(seq->offset)<seq->seqlen)
|
indx - (seq->offset) < seq->seqlen)
|
||||||
seq->c_elem[indx-(seq->offset)] = elem;
|
seq->c_elem[indx - (seq->offset)] = elem;
|
||||||
else if(elem!='-')
|
else if (elem != '-')
|
||||||
fprintf(stderr,"%c better be a -\n",elem);
|
fprintf(stderr, "%c better be a -\n", elem);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* InsertElem is a modification of InsertElems, and should be
|
* InsertElem is a modification of InsertElems, and should be
|
||||||
* optimized. s.s.5/6/91
|
* optimized. s.s.5/6/91
|
||||||
*/
|
*/
|
||||||
int InsertElem(a,b,ch)
|
int InsertElem(a, b, ch)
|
||||||
Sequence *a; /* Sequence */
|
Sequence *a; /* Sequence */
|
||||||
int b; /*Position to insert BEFORE*/
|
int b; /*Position to insert BEFORE*/
|
||||||
char ch; /*element to insert */
|
char ch; /*element to insert */
|
||||||
{
|
{
|
||||||
char c[2];
|
char c[2];
|
||||||
c[0]=ch;
|
c[0] = ch;
|
||||||
c[1] = '\0';
|
c[1] = '\0';
|
||||||
|
|
||||||
return (InsertElems(a,b,c));
|
return (InsertElems(a, b, c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make a copy of Sequence one, place in Sequence two
|
* Make a copy of Sequence one, place in Sequence two
|
||||||
*/
|
*/
|
||||||
void SeqCopy(one,two)
|
void SeqCopy(one, two) Sequence *one, *two;
|
||||||
Sequence *one,*two;
|
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
*two = *one;
|
*two = *one;
|
||||||
if(two->seqmaxlen)
|
if (two->seqmaxlen) two->c_elem = Calloc(one->seqmaxlen, sizeof(char));
|
||||||
two->c_elem = Calloc(one->seqmaxlen,sizeof(char));
|
if (two->commentsmaxlen)
|
||||||
if(two->commentsmaxlen)
|
two->comments = Calloc(one->commentsmaxlen, sizeof(char));
|
||||||
two->comments = Calloc(one->commentsmaxlen,sizeof(char));
|
for (j = 0; j < one->seqlen; j++) two->c_elem[j] = one->c_elem[j];
|
||||||
for(j=0;j<one->seqlen;j++)
|
for (j = 0; j < one->commentslen; j++)
|
||||||
two->c_elem[j] = one->c_elem[j];
|
|
||||||
for(j=0;j<one->commentslen;j++)
|
|
||||||
two->comments[j] = one->comments[j];
|
two->comments[j] = one->comments[j];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Normalize seq (remove leading indels in the c_elem;
|
* Normalize seq (remove leading indels in the c_elem;
|
||||||
*/
|
*/
|
||||||
void SeqNormal(seq)
|
void SeqNormal(seq) Sequence *seq;
|
||||||
Sequence *seq;
|
|
||||||
{
|
{
|
||||||
int len,j,shift_width,trailer;
|
int len, j, shift_width, trailer;
|
||||||
char *c_elem;
|
char *c_elem;
|
||||||
len = seq->seqlen;
|
len = seq->seqlen;
|
||||||
|
|
||||||
c_elem = seq->c_elem;
|
c_elem = seq->c_elem;
|
||||||
|
|
||||||
if(len == 0) return;
|
if (len == 0) return;
|
||||||
|
|
||||||
for(shift_width=0; (shift_width<len) && (c_elem[shift_width] == '-');
|
for (shift_width = 0;
|
||||||
shift_width++);
|
(shift_width < len) && (c_elem[shift_width] == '-'); shift_width++)
|
||||||
|
;
|
||||||
|
|
||||||
for(j=0;j<len-shift_width;j++)
|
for (j = 0; j < len - shift_width; j++)
|
||||||
c_elem[j] = c_elem[j+shift_width];
|
c_elem[j] = c_elem[j + shift_width];
|
||||||
|
|
||||||
seq->seqlen -= shift_width;
|
seq->seqlen -= shift_width;
|
||||||
seq->offset += shift_width;
|
seq->offset += shift_width;
|
||||||
for(trailer=seq->seqlen-1;(c_elem[trailer] =='-' ||
|
for (trailer = seq->seqlen - 1;
|
||||||
c_elem[trailer] == '\0') && trailer>=0;
|
(c_elem[trailer] == '-' || c_elem[trailer] == '\0') &&
|
||||||
|
trailer >= 0;
|
||||||
trailer--)
|
trailer--)
|
||||||
c_elem[trailer] = '\0';
|
c_elem[trailer] = '\0';
|
||||||
seq->seqlen = trailer+1;
|
seq->seqlen = trailer + 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeqRev(seq,min,max)
|
void SeqRev(seq, min, max) Sequence *seq;
|
||||||
Sequence *seq;
|
int min, max;
|
||||||
int min,max;
|
|
||||||
/*
|
/*
|
||||||
SeqRev will reverse a given sequence within a window from
|
SeqRev will reverse a given sequence within a window from
|
||||||
min to max (inclusive). The idea is to allow several sequences
|
min to max (inclusive). The idea is to allow several sequences
|
||||||
|
@ -260,16 +240,15 @@ int min,max;
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
char temp1,temp2;
|
char temp1, temp2;
|
||||||
extern char GetElem();
|
extern char GetElem();
|
||||||
extern void ReplaceElem();
|
extern void ReplaceElem();
|
||||||
|
|
||||||
for(j=0;j<= (max-min)/2;j++)
|
for (j = 0; j <= (max - min) / 2; j++) {
|
||||||
{
|
temp1 = GetElem(seq, min + j);
|
||||||
temp1 = GetElem(seq,min+j);
|
temp2 = GetElem(seq, max - j);
|
||||||
temp2 = GetElem(seq,max-j);
|
ReplaceElem(seq, min + j, (unsigned char)temp2);
|
||||||
ReplaceElem(seq,min+j,(unsigned char)temp2);
|
ReplaceElem(seq, max - j, (unsigned char)temp1);
|
||||||
ReplaceElem(seq,max-j,(unsigned char)temp1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
seq->direction *= -1;
|
seq->direction *= -1;
|
||||||
|
@ -278,54 +257,51 @@ int min,max;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* sequence complementing. */
|
/* sequence complementing. */
|
||||||
void SeqComp(seq)
|
void SeqComp(seq) Sequence *seq;
|
||||||
Sequence *seq;
|
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
unsigned char in,out,case_bit;
|
unsigned char in, out, case_bit;
|
||||||
char *c;
|
char *c;
|
||||||
static int tmatr[16] = {'-','a','c','m','g','r','s','v',
|
static int tmatr[16] = {'-', 'a', 'c', 'm', 'g', 'r', 's', 'v',
|
||||||
't','w','y','h','k','d','b','n'};
|
't', 'w', 'y', 'h', 'k', 'd', 'b', 'n'};
|
||||||
|
|
||||||
static int matr[128] = {
|
static int matr[128] = {
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0x01,0x0e,0x02,0x0d,0,0,0x04,0x0b,0,0,0x0c,0,0x03,0x0f,0,0x05,0,0x05,0x06,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0,
|
||||||
0x08,0x08,0x07,0x09,0x00,0x0a,0,0,0,0,0,0,0,0x01,0x0e,0x02,0x0d,0,0,0x04,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0x0b,0,0,0x0c,0,0x03,0x0f,0,0x05,0,0x05,0x06,0x08,0x08,0x07,0x09,0x00,0x0a,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0,0,0,0,0x00,0
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01,
|
||||||
};
|
0x0e, 0x02, 0x0d, 0, 0, 0x04, 0x0b, 0, 0, 0x0c, 0,
|
||||||
|
0x03, 0x0f, 0, 0x05, 0, 0x05, 0x06, 0x08, 0x08, 0x07, 0x09,
|
||||||
|
0x00, 0x0a, 0, 0, 0, 0, 0, 0, 0, 0x01, 0x0e,
|
||||||
|
0x02, 0x0d, 0, 0, 0x04, 0x0b, 0, 0, 0x0c, 0, 0x03,
|
||||||
|
0x0f, 0, 0x05, 0, 0x05, 0x06, 0x08, 0x08, 0x07, 0x09, 0x00,
|
||||||
|
0x0a, 0, 0, 0, 0, 0x00, 0};
|
||||||
|
|
||||||
c = seq->c_elem;
|
c = seq->c_elem;
|
||||||
for(j=0;j<seq->seqlen;j++)
|
for (j = 0; j < seq->seqlen; j++) {
|
||||||
{
|
/*
|
||||||
/*
|
* Save Case bit...
|
||||||
* Save Case bit...
|
*/
|
||||||
*/
|
|
||||||
case_bit = c[j] & 32;
|
case_bit = c[j] & 32;
|
||||||
out = 0;
|
out = 0;
|
||||||
in = matr[c[j]];
|
in = matr[c[j]];
|
||||||
if(in&1)
|
if (in & 1) out |= 8;
|
||||||
out|=8;
|
if (in & 2) out |= 4;
|
||||||
if(in&2)
|
if (in & 4) out |= 2;
|
||||||
out|=4;
|
if (in & 8) out |= 1;
|
||||||
if(in&4)
|
|
||||||
out|=2;
|
|
||||||
if(in&8)
|
|
||||||
out|=1;
|
|
||||||
|
|
||||||
if(case_bit == 0)
|
if (case_bit == 0)
|
||||||
c[j] = toupper(tmatr[out]);
|
c[j] = toupper(tmatr[out]);
|
||||||
else
|
else
|
||||||
c[j] = tmatr[out];
|
c[j] = tmatr[out];
|
||||||
}
|
}
|
||||||
|
|
||||||
seq->direction *= -1;
|
seq->direction *= -1;
|
||||||
seq->strandedness = ( seq->strandedness == 2)?1:
|
seq->strandedness = (seq->strandedness == 2) ? 1
|
||||||
( seq->strandedness == 1)?2:
|
: (seq->strandedness == 1) ? 2
|
||||||
0;
|
: 0;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
2178
HGL_SRC/HGLfuncs.c
2178
HGL_SRC/HGLfuncs.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue