Пример #1
0
void sqlSignedDynamicArray(char *s, int **retArray, int *retSize)
/* Convert comma separated list of numbers to an dynamically allocated
 * array, which should be freeMem()'d when done. */
{
int *sArray, *dArray = NULL;
int size;

sqlSignedStaticArray(s, &sArray, &size);
if (size > 0)
    {
    AllocArray(dArray,size);
    CopyArray(sArray, dArray, size);
    }
*retArray = dArray;
*retSize = size;
}
Пример #2
0
static char *computeFrames(struct bed *bed, char *exonFrames, int *retStartIndx, int *retStopIndx)
/* Compute frames, in order dictated by strand.  bed must be BED12. 
 * Convert exonFrames to gtf frame if available. */
{
int *ef;
if (exonFrames)
    {
    int efSize = 0;
    sqlSignedStaticArray(exonFrames, &ef, &efSize); // not thread safe.
    if (efSize != bed->blockCount)
	errAbort("Unexpected error, name=%s blockCount=%d but exonFrames size = %d", bed->name, bed->blockCount, efSize);
    }
char *frames = needMem(bed->blockCount);
boolean gotFirstCds = FALSE;
int nextPhase = 0, startIndx = 0, stopIndx = 0;
// If lack of thick region has been represented this way, fix:
if (bed->thickStart == 0 && bed->thickEnd == 0)
    bed->thickStart = bed->thickEnd = bed->chromStart;
int i;
for (i=0;  i < bed->blockCount;  i++)
    {
    int j = (bed->strand[0] == '-') ? bed->blockCount-i-1 : i;
    int exonStart = bed->chromStart + bed->chromStarts[j];
    int exonEnd = exonStart + bed->blockSizes[j];
    if ((exonStart < bed->thickEnd) && (exonEnd > bed->thickStart))
	{
	int cdsS = max(exonStart, bed->thickStart);
	int cdsE = min(exonEnd, bed->thickEnd);
	int cdsSize = cdsE - cdsS;
	if (! gotFirstCds)
	    {
	    gotFirstCds = TRUE;
	    startIndx = j;
	    }
	if (exonFrames)
	    {
	    int n = ef[j];
	    char c = '.';     // -1 exonFrame becomes '.' in gtf 
	    if (n == 0)
		c = '0';
	    else if (n == 1)  // gtf frames are really "phases", so 1 and 2 swap.
		c = '2';
	    else if (n == 2)
		c = '1';
	    frames[j] = c;
	    }
	else
	    {
	    frames[j] = '0' + nextPhase;
	    nextPhase = (3 + ((nextPhase - cdsSize) % 3)) % 3;
	    }
	stopIndx = j;
	}
    else
	{
	frames[j] = '.';
	}
    }
if (retStartIndx)
    *retStartIndx = startIndx;
if (retStopIndx)
    *retStopIndx = stopIndx;
return frames;
}