Exemple #1
0
void bedIntersect(char *aFile, char *bFile, char *outFile)
/* bedIntersect - Intersect two bed files. */
{
struct lineFile *lf = lineFileOpen(aFile, TRUE);
struct hash *bHash = readBed(bFile);
FILE *f = mustOpen(outFile, "w");
char *row[40];
int wordCount;

while ((wordCount = (strictTab ? lineFileChopTab(lf, row) : lineFileChop(lf, row))) != 0)
    {
    char *chrom = row[0];
    int start = lineFileNeedNum(lf, row, 1);
    int end = lineFileNeedNum(lf, row, 2);
    if (start > end)
        errAbort("start after end line %d of %s", lf->lineIx, lf->fileName);
    if (start == end && !allowStartEqualEnd)
	lineFileAbort(lf, "start==end (if this is legit, use -allowStartEqualEnd)");
    struct binKeeper *bk = hashFindVal(bHash, chrom);
    if (bk != NULL)
	{
	struct binElement *hitList = NULL, *hit;
	if (allowStartEqualEnd && start == end)
	    hitList = binKeeperFind(bk, start-1, end+1);
	else
	    hitList = binKeeperFind(bk, start, end);
	if (aHitAny)
	    {
	    for (hit = hitList; hit != NULL; hit = hit->next)
		{
		float cov = getCov(start, end, hit->val);
		if (cov >= minCoverage)
		    {
		    outputBed(f, row, wordCount, start, end, hit->val);
		    break;
		    }
		else
		    {
		    struct bed5 *b = hit->val;
		    verbose(1, "filter out %s %d %d %d %d overlap %d %d %d %.3f\n",
			    chrom, start, end, b->start, b->end,
			    positiveRangeIntersection(start, end, b->start, b->end),
			    end-start, b->end-b->start, cov);
		    }
		}
	    }
	else
	    {
	    for (hit = hitList; hit != NULL; hit = hit->next)
	        {
		if (getCov(start, end, hit->val) >= minCoverage)
		    outputBed(f, row, wordCount, start, end, hit->val);
		}
	    }
	slFreeList(&hitList);
	}
    }
}
void callPrimer3(struct cassetteSeq *cseq, FILE *primerFa, FILE *primerBed)
/* Write out a boulder IO format file and call primer3 on it. */
{
char *primer3 = optionVal("primer3","/projects/compbio/usr/sugnet/local/src/primer3_0_9_test/src/primer3_core");
FILE *tmpFile = NULL;
char command[2048];
char inFile[512];
char outFile[512];
int retVal = 0;
snprintf(inFile, sizeof(inFile), "%s.tmp", cseq->name);
snprintf(outFile, sizeof(outFile), "%s.primer", cseq->name);
tmpFile = mustOpen(inFile, "w");
writeBoulderIoFormat(tmpFile, cseq);
carefulClose(&tmpFile);
snprintf(command, sizeof(command), "%s < %s > %s", primer3, inFile, outFile);
retVal = system(command);
if(retVal != 0)
    warn("pickCassettePcrPrimers::callPrimer3() - Primer3 call failed for bed %s", cseq->name);
else
    parseBoulderIo(outFile, cseq);
outputFasta(cseq, primerFa);
outputBed(cseq, primerBed);
}