示例#1
0
struct raRecord *raNext(struct lineFile *lf, struct hash *stringHash)
/* Return next ra record.  Returns NULL at end of file.  */
{
char *line, *key, *val;
struct raRecord *ra = NULL;
struct nameVal *nv;

for (;;)
   {
   if (!lineFileNext(lf, &line, NULL))
       break;
   line = skipLeadingSpaces(line);
   if (line[0] == '#')
       continue;
   if (line[0] == 0)
       break;
   if (ra == NULL)
       AllocVar(ra);
   key = nextWord(&line);
   AllocVar(nv);
   nv->name = hashStoreName(stringHash, key);
   val = skipLeadingSpaces(line);
   if (val == NULL)
       errAbort("Expecting line/value pair line %d of %s"
       	, lf->lineIx, lf->fileName);
   nv->val = hashStoreName(stringHash, val);
   slAddHead(&ra->fieldList, nv);
   }
if (ra != NULL)
    slReverse(&ra->fieldList);
return ra;
}
void liftFillsQ(struct cnFill *fillList, struct hash *nameHash,
        struct hash *liftHash, struct lineFile *lf)
/* Lift query coords in each element of fillList and recursively descend to 
 * children of each element if necessary.  lf is only for err reporting. */
{
    struct cnFill *fill;
    for (fill=fillList;  fill != NULL;  fill=fill->next)
        {
        struct liftSpec *spec = findLift(liftHash, fill->qName, lf);
        if (spec == NULL)
            {
            if (how != carryMissing)
                {
                errAbort("Can't lift fill->qName %s and don't support dropping lifts",
                        fill->qName);
                }
            }
        else
            {
	    cantHandleSpecRevStrand(spec);
            fill->qName = spec->newName;
            fill->qStart += spec->offset;
            }
        // nameHash needs to be completely rebuilt with all strings it contained 
        // before (see chainNet.c::cnFillFromLine), regardless of whether we're 
        // changing their values:
        fill->qName = hashStoreName(nameHash, fill->qName);
        fill->type  = hashStoreName(nameHash, fill->type);

        if (fill->children != NULL)
            liftFillsQ(fill->children, nameHash, liftHash, lf);
        }
}
示例#3
0
struct cloneLoc *cloneLocNew(char *clone, char *contig, char *chrom)
/* Make a new clone loc. */
{
struct cloneLoc *cl;
AllocVar(cl);
cl->clone = cloneString(clone);
cl->contig = hashStoreName(contigHash, contig);
cl->chrom = hashStoreName(chromHash, chrom);
return cl;
}
struct seqPair *readPairList(char *pairFileName, struct hash *cloneHash, struct hash *pairHash)
/* Read in an overlapping pair file. */
{
char *pairName;
char *a, *b;
struct lineFile *lf = lineFileOpen(pairFileName, TRUE);
char *line, *words[4];
int lineSize, wordCount;
struct hashEl *hel;
int overlap;
struct seqPair *pair, *pairList = NULL;
boolean firstA;

while (lineFileNext(lf, &line, &lineSize))
    {
    wordCount = chopLine(line, words);
    if (wordCount != 3)
	errAbort("Expecting three words line %d of %s", lf->lineIx, lf->fileName);
    if (!isdigit(words[1][0]))
	errAbort("Expecting number in second field line %d of %s", lf->lineIx, lf->fileName);
    a = hashStoreName(cloneHash, words[0]);
    overlap = atoi(words[1]);
    b = hashStoreName(cloneHash, words[2]);
    pairName = makePairName(a, b, &firstA);
    if ((hel = hashLookup(pairHash, pairName)) == NULL)
	{
	AllocVar(pair);
	hel = hashAdd(pairHash, pairName, pair);
	pair->pairName = pairName;
	if (firstA)
	    {
	    pair->a.name = a;
	    pair->b.name = b;
	    }
	else
	    {
	    pair->a.name = b;
	    pair->b.name = a;
	    }
	slAddHead(&pairList, pair);
	}
    else
	pair = hel->val;
    if (firstA)
	pair->a.overlap = overlap;
    else
	pair->b.overlap = overlap;
    }
slReverse(&pairList);
lineFileClose(&lf);
return pairList;
}
示例#5
0
文件: ppAnalyse.c 项目: bowhan/kent
int readAlignments(char *pairsPsl, struct hash *readHash, struct hash *fragHash)
/* Read in alignments and process them into the read->aliList. 
 * Returns number of alignments altogether. */
{
struct lineFile *lf = pslFileOpen(pairsPsl);
struct shortAli *ali;
struct psl *psl;
struct readInfo *rd;
int aliCount = 0;
int dotEvery = 20*1024;
int dotty = dotEvery;
int aliSize;

printf("Reading and processing %s\n", pairsPsl);
for (;;)
    {
    AllocVar(ali);     /* Allocate this first to reduce memory fragmentation. */
    if ((psl = pslNext(lf)) == NULL)
        {
	freeMem(ali);
	break;
	}
    if (filter(psl))
	{
	rd = hashMustFindVal(readHash, psl->qName);
	aliSize = psl->match + psl->repMatch;
	aliSize /= 100;
	if (aliSize < 0) aliSize = 0;
	if (aliSize >= ArraySize(aliSizes)) aliSize = ArraySize(aliSizes)-1;
	aliSizes[aliSize] += 1;
	ali->tName = hashStoreName(fragHash, psl->tName);
	ali->tStart = psl->tStart;
	ali->tEnd = psl->tEnd;
	ali->tSize = psl->tSize;
	ali->strand = psl->strand[0];
	slAddHead(&rd->aliList, ali);
	pslFree(&psl);
	++aliCount;
	}
    else
        {
	pslFree(&psl);
	freeMem(ali);
	}
    if (--dotty <= 0)
	{
	dotty = dotEvery;
        printf(".");
	fflush(stdout);
	}
    }
printf("\n");
return aliCount;
}
示例#6
0
void addNib(char *file, struct hash *fileHash, struct hash *seqHash)
/* Add a nib file to hashes. */
{
struct seqFilePos *sfp;
char root[128];
splitPath(file, NULL, root, NULL);
AllocVar(sfp);
hashAddSaveName(seqHash, root, sfp, &sfp->name);
sfp->file = hashStoreName(fileHash, file);
sfp->isNib = TRUE;
sfp->pos = 0;
}
static struct hash *hashFromCommaString(char *commaString)
/* Return a hash that stores words in comma-separated string, or NULL if string is NULL or empty. */
{
struct hash *hash = NULL;
if (isNotEmpty(commaString))
    {
    hash = hashNew(0);
    char *words[1024];
    int i, wordCount = chopCommas(commaString, words);
    for (i = 0;  i < wordCount;  i++)
        hashStoreName(hash, words[i]);
    }
return hash;
}
void assocGroupAdd(struct assocGroup *ag, char *key, char *val)
/* Add key/val pair to assocGroup. */
{
struct assocList *al = hashFindVal(ag->listHash, key);
struct slRef *ref;
if (al == NULL)
    {
    lmAllocVar(ag->lm, al);
    hashAdd(ag->listHash, key, al);
    }
val = hashStoreName(ag->valStringHash, val);
lmAllocVar(ag->lm, ref);
ref->val = val;
slAddHead(&al->list, ref);
}
示例#9
0
void addTwoBit(char *file, struct hash *fileHash, struct hash *seqHash)
/* Add a nib file to hashes. */
{
struct seqFilePos *sfp;
struct twoBitFile *tbf = twoBitOpen(file);
struct twoBitIndex *index;
for (index = tbf->indexList; index != NULL; index = index->next)
    {
    AllocVar(sfp);
    hashAddSaveName(seqHash, index->name, sfp, &sfp->name);
    sfp->file = hashStoreName(fileHash, file);
    sfp->isTwoBit = TRUE;
    sfp->tbf = tbf;
    }
}
示例#10
0
void addNib(char *file, struct hash *fileHash, struct hash *seqHash)
/* Add a nib file to hashes. */
{
struct seqFilePos *sfp;
char root[128];
int size;
FILE *f = NULL;
splitPath(file, NULL, root, NULL);
AllocVar(sfp);
hashAddSaveName(seqHash, root, sfp, &sfp->name);
sfp->file = hashStoreName(fileHash, file);
sfp->isNib = TRUE;
nibOpenVerify(file, &f, &size);
sfp->pos = size;
}
示例#11
0
void addTwoBit(char *file, struct hash *fileHash, struct hash *seqHash)
/* Add a 2bit file to hashes. */
{
struct twoBitFile *lf = twoBitOpen(file);
char *rFile = hashStoreName(fileHash, file);
struct slName *names = twoBitSeqNames(file);
struct slName *name;

for(name = names;name;name = name->next)
    {
    struct seqFilePos *sfp;
    AllocVar(sfp);
    hashAddSaveName(seqHash, name->name, sfp, &sfp->name);
    sfp->file = rFile;
    sfp->isTwoBit = TRUE;
    sfp->pos = 0;
    }
slFreeList(&names);
twoBitClose(&lf);
}
示例#12
0
void addSizes(char *database, struct hash *eiHash, struct hash *dateHash)
/* Add and date info to ests in eiHash. Date strings are stored in dateHash */
{
struct sqlConnection *conn = sqlConnect(database);
struct sqlResult *sr = NULL;
char **row;

sr = sqlGetResult(conn, "NOSQLINJ select acc,size,gb_date from seq");
while ((row = sqlNextRow(sr)) != NULL)
    {
    char *acc = row[0];
    struct estInfo *ei = hashFindVal(eiHash, acc);
    if (ei != NULL)
        {
	ei->size = sqlUnsigned(row[1]);
	ei->date = hashStoreName(dateHash, row[2]);
	}
    }
sqlFreeResult(&sr);
sqlDisconnect(&conn);
}
示例#13
0
struct crTreeItem *scanAll(char *fileName, struct hash *chromNameHash, 
	bits64 *retFileSize) 
/* Load all crTreeItem from a whitespace-separated file.
 * Dispose of this with chromRangeFreeList(). */
{
struct crTreeItem *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[3];

while (lineFileRow(lf, row))
    {
    AllocVar(el);
    el->chrom = hashStoreName(chromNameHash, row[0]);
    el->start = sqlUnsigned(row[1]);
    el->end = sqlUnsigned(row[2]);
    el->fileOffset = lineFileTell(lf);
    slAddHead(&list, el);
    }
*retFileSize = lineFileTell(lf);
lineFileClose(&lf);
slReverse(&list);
return list;
}
示例#14
0
void addFa(char *file, struct hash *fileHash, struct hash *seqHash)
/* Add a fa file to hashes. */
{
struct lineFile *lf = lineFileOpen(file, TRUE);
char *line, *name;
char *rFile = hashStoreName(fileHash, file);

while (lineFileNext(lf, &line, NULL))
    {
    if (line[0] == '>')
        {
	struct seqFilePos *sfp;
	line += 1;
	name = nextWord(&line);
	if (name == NULL)
	   errAbort("bad line %d of %s", lf->lineIx, lf->fileName);
	AllocVar(sfp);
	hashAddSaveName(seqHash, name, sfp, &sfp->name);
	sfp->file = rFile;
	sfp->pos = lineFileTell(lf);
	}
    }
lineFileClose(&lf);
}
示例#15
0
文件: vcf.c 项目: vatlab/VariantTools
char *vcfFilePooledStr(struct vcfFile *vcff, char *str)
/* Allocate memory for a string from vcff's shared string pool. */
{
return hashStoreName(vcff->pool, str);  // Always stored in main pool, not reuse pool
}
示例#16
0
文件: chainNet.c 项目: bowhan/kent
struct cnFill *cnFillFromLine(struct hash *nameHash, 
	struct lineFile *lf, char *line)
/* Create cnFill structure from line.  This will chop up
 * line as a side effect. */
{
static char *words[64];
int i, wordCount;
enum {basicFields = 7};
struct cnFill *fill;

wordCount = chopLine(line, words);
lineFileExpectAtLeast(lf, basicFields, wordCount);
fill = cnFillNew();
fill->tStart = lineFileNeedNum(lf, words, 1);
fill->tSize = lineFileNeedNum(lf, words, 2);
fill->qName = hashStoreName(nameHash, words[3]);
fill->qStrand = words[4][0];
fill->qStart = lineFileNeedNum(lf, words, 5);
fill->qSize = lineFileNeedNum(lf, words, 6);
for (i=basicFields; i<wordCount; i += 2)
    {
    char *name = words[i];

    if (sameString(name, "score"))
	fill->score = atof(words[i+1]);
    else if (sameString(name, "type"))
	fill->type = hashStoreName(nameHash, words[i+1]);
    else
	{
	/* Cope with integer values. */
	int iVal = lineFileNeedNum(lf, words, i+1);
	if (sameString(name, "id"))
	    fill->chainId = iVal;
	else if (sameString(name, "ali"))
	    fill->ali = iVal;
	else if (sameString(name, "tN"))
	    fill->tN = iVal;
	else if (sameString(name, "qN"))
	    fill->qN = iVal;
	else if (sameString(name, "tR"))
	    fill->tR = iVal;
	else if (sameString(name, "qR"))
	    fill->qR = iVal;
	else if (sameString(name, "tNewR"))
	    fill->tNewR = iVal;
	else if (sameString(name, "qNewR"))
	    fill->qNewR = iVal;
	else if (sameString(name, "tOldR"))
	    fill->tOldR = iVal;
	else if (sameString(name, "qOldR"))
	    fill->qOldR = iVal;
	else if (sameString(name, "tTrf"))
	    fill->tTrf = iVal;
	else if (sameString(name, "qTrf"))
	    fill->qTrf = iVal;
	else if (sameString(name, "qOver"))
	    fill->qOver = iVal;
	else if (sameString(name, "qFar"))
	    fill->qFar = iVal;
	else if (sameString(name, "qDup"))
	    fill->qDup = iVal;
	}
    }
return fill;
}
示例#17
0
void nibbParseImageDir(char *sourceDir, char *goodTab, char *badTab)
/* nibbParseImageDir - Look through nibb image directory and allowing for 
 * typos and the like create a table that maps a file name to clone name, 
 * developmental stage, and view of body part. */
{
struct fileInfo *l1List, *l1, *l2List, *l2, *l3List, *l3;
struct hash *stageHash = hashNew(0);
struct hash *viewHash = hashNew(0);
struct hash *otherHash = hashNew(0);
struct hash *probeHash = hashNew(0);
struct hash *fixHash = hashFixers();
struct imageInfo *imageList = NULL, *image;
FILE *good = mustOpen(goodTab, "w");
FILE *bad = mustOpen(badTab, "w");
int goodCount = 0, badCount = 0;
int jpgCount = 0, jpgDir = 0;


l1List = listDirX(sourceDir, "XL*", FALSE);
for (l1 = l1List; l1 != NULL; l1 = l1->next)
    {
    char l1Path[PATH_LEN];
    safef(l1Path, sizeof(l1Path), "%s/%s", sourceDir, l1->name);
    l2List = listDirX(l1Path, "XL*", FALSE);
    for (l2 = l2List; l2 != NULL; l2 = l2->next)
        {
	char l2Path[PATH_LEN];
	char cloneName[64], *permanentCloneName;
	char *cloneDir = l2->name;
	char *cloneEnd;
	int cloneNameSize = 0;

	if (stringIx(cloneDir, skipDir) >= 0)
	    continue;

	/* Figure out clone name, whish is directory component up to
	 * first underbar. */
	cloneEnd = strchr(cloneDir, '_');
	if (cloneEnd != NULL)
	    cloneNameSize = cloneEnd - cloneDir;
	else
	    errAbort("Strangely formatted image dir %s, no underbar", cloneDir);
	if (cloneNameSize >= sizeof(cloneName))
	    errAbort("Clone name too long in dir %s", cloneDir);
	if (cloneNameSize < 8 || cloneNameSize > 12)
	    errAbort("Clone name wrong size %s", cloneDir);
	memcpy(cloneName, cloneDir, cloneNameSize);
	cloneName[cloneNameSize] = 0;
	/* Check format is XL###L##.  We already checked the XL. */
	if (!isdigit(cloneName[2]) || !isdigit(cloneName[3]) 
		 || !isdigit(cloneName[4]) || isdigit(cloneName[5]) 
		 || !isdigit(cloneName[6]) || !isdigit(cloneName[7]))
	    errAbort("Strangely formatted clone name %s", cloneDir);

	permanentCloneName = hashStoreName(probeHash, cloneName);


	/* Get all files in dir. */
	safef(l2Path, sizeof(l2Path), 
		"%s/%s/%s", sourceDir, l1->name, l2->name);
	l3List = listDirX(l2Path, "*.jpg", FALSE);
	for (l3 = l3List; l3 != NULL; l3 = l3->next)
	    {
	    char *fileName = l3->name;

	    if (stringIx(l3->name, skipFile) >= 0)
		continue;
	    image = getImageInfo(fixHash, permanentCloneName, 
	    	l1->name, cloneDir, fileName,
	    	stageHash, viewHash, otherHash, probeHash);
	    slAddHead(&imageList, image);
	    ++jpgCount;
	    }
	++jpgDir;
	}
    }
slReverse(&imageList);

verbose(1, "%d jpg images in %d directories\n", jpgCount, jpgDir);

#ifdef OLD
verbose(1, "%d probes, %d stages, %d views, %d other\n", 
	probeHash->elCount, stageHash->elCount, 
	viewHash->elCount, otherHash->elCount);
printHash("stages", stageHash);
printHash("views", viewHash);
printHash("other", otherHash);
#endif /* OLD */

for (image = imageList; image != NULL; image = image->next)
    {
    if (image->clone != NULL && image->stage != NULL && image->view != NULL)
        {
	imageInfoOut(image, good);
	++goodCount;
	}
    else
	{
	imageInfoOut(image, bad);
	++badCount;
	}
    }
verbose(1, "%d (%4.1f%%) parsed ok, %d (%4.2f%%) didn't\n", 
	goodCount, 100.0 * goodCount/(goodCount + badCount), 
	badCount, 100.0 * badCount/(goodCount + badCount));
carefulClose(&good);
carefulClose(&bad);
}
示例#18
0
struct hash *makeMotifBed(char *gffDir, char *outBed)
/* Make bed file from GFFs.  Return hash of transcription factors. */
{
static char *consLevelPath[3] = {"3", "2", "0"};
static char *consLevelBed[3] = {"2", "1", "0"};
static char *pLevelPath[3] = {"p001b", "p005b", "nobind"};
static char *pLevelBed[3] = {"good", "weak", "none"};
int cIx, pIx;
FILE *f = mustOpen(outBed, "w");
struct hash *tfHash = newHash(0);
struct hash *yrcHash = newHash(18);
struct yrc *yrcList = NULL, *yrc;

for (cIx=0; cIx<3; ++cIx)
   {
   for (pIx=0; pIx<3; ++pIx)
       {
       struct lineFile *lf;
       char *row[10];
       char fileName[PATH_LEN];
       char hashKey[256];

       safef(fileName, sizeof(fileName), "%s/IGR_v24.%s.%s.GFF",
       	   gffDir, consLevelPath[cIx], pLevelPath[pIx]);
       lf = lineFileOpen(fileName, TRUE);
       while (lineFileRow(lf, row))
            {
	    char *name = row[9];
	    char *e;
	    int chromIx, chromStart, chromEnd;
	    if (!sameWord(row[8], "Site"))
	        errAbort("Expecting 'Site' line %d of %s", lf->lineIx, lf->fileName);
	    e = strchr(name, ';');
	    if (e == NULL)
	        errAbort("Expecting semicolon line %d of %s", lf->lineIx, lf->fileName);
	    *e = 0;
	    chromIx = romanToArabicChrom(row[0], lf);
	    chromStart = lineFileNeedNum(lf, row, 3);
	    chromEnd = lineFileNeedNum(lf, row, 4);
	    safef(hashKey, sizeof(hashKey), "%s.%d.%d", name, chromIx, chromStart);
	    if ((yrc = hashFindVal(yrcHash, hashKey)) == NULL)
	        {
		AllocVar(yrc);
		yrc->chromIx= chromIx;
		yrc->chromStart = chromStart;
		yrc->chromEnd = chromEnd;
		yrc->name = hashStoreName(tfHash, name);
		yrc->pLevel = pIx;
		yrc->consLevel = cIx;
		hashAdd(yrcHash, hashKey, yrc);
		slAddHead(&yrcList, yrc);
		}
	    else
	        {
		if (pIx < yrc->pLevel)
		    yrc->pLevel = pIx;
		if (cIx < yrc->consLevel)
		    yrc->consLevel = cIx;
		}
	    }
       lineFileClose(&lf);
       }
   }
for (yrc = yrcList; yrc != NULL; yrc = yrc->next)
    {
    fprintf(f, "chr%d\t", yrc->chromIx+1);
    fprintf(f, "%d\t", yrc->chromStart);
    fprintf(f, "%d\t", yrc->chromEnd);
    fprintf(f, "%s\t", yrc->name);
    fprintf(f, "%d\t", (int)(1000/(yrc->pLevel + yrc->consLevel + 1)));
    fprintf(f, "%s\t", pLevelBed[yrc->pLevel]);
    fprintf(f, "%s\n", consLevelBed[yrc->consLevel]);
    }
carefulClose(&f);
hashFree(&yrcHash);
return tfHash;
}
示例#19
0
文件: vcf.c 项目: bh0085/kent
static char *vcfFilePooledStr(struct vcfFile *vcff, char *str)
/* allocate memory for a string from the shared string pool */
{
return hashStoreName(vcff->pool, str);
}
void allWriteReadsToDir(char *regionFile, char *dir) {
	FILE *fp, *rd;
	char buf[500], readName[500], fileName[500], chr[50], fub[500];
	char str[2][500];
	char *readStr, *ch;
	int i, b, e, j, k;
	struct slName *ali;
	struct hashEl *el;
	struct rbTree *tr;
	struct range *rg;
	struct hash *localHash = NULL;

	fp = mustOpen(regionFile, "r");
	j = 0;
	while (fgets(buf, 500, fp)) {
		if (sscanf(buf, "%[^\t]\t%[^\t]\t%*s", str[0], str[1]) != 2)
			errAbort("error: %s", buf);
		++j;
		sprintf(fileName, "%s/R%d/reads.fq", dir, j);
		rd = mustOpen(fileName, "w");
		localHash = hashNew(8);
		for (i = 0; i < 2; i++) {
			if (sscanf(str[i], "%[^:]:%d-%d", chr, &b, &e) != 3)
				errAbort("error: %s", str[i]);
			el = hashLookup(aliHash, chr);
			tr = (struct rbTree *)(el->val);
			for (rg = rangeTreeAllOverlapping(tr, b, e); rg; rg = rg->next) {
				for (ali = (struct slName *)(rg->val); ali; ali = ali->next) {
					if (hashLookup(localHash, ali->name))
						continue;
					hashStoreName(localHash, ali->name);
					readStr = (char *)hashFindVal(readsHash, ali->name);
					if(readStr == NULL)
						continue;
					//assert(readStr);
					strcpy(fub, readStr);
					ch = strchr(fub, ' ');
					*ch = '\0';
					fprintf(rd, "@%s\n", ali->name);
					fprintf(rd, "%s\n", fub);
					++ch;
					fprintf(rd, "+%s\n", ali->name);
					fprintf(rd, "%s\n", ch);
         				strcpy(readName, ali->name);
					k = strlen(readName);
					/*
					if (readName[k-1] == '1')
						readName[k-1] = '2';
					else if (readName[k-1] == '2')
						readName[k-1] = '1';
					else
						errAbort("read identifier error: %s", readName);
						
					if (hashLookup(localHash, readName))
						continue;
					hashStoreName(localHash, readName);
					readStr = (char *)hashFindVal(readsHash, readName);

					assert(readStr);
					strcpy(fub, readStr);
					ch = strchr(fub, ' ');
					*ch = '\0';
					fprintf(rd, "@%s\n", readName);
					fprintf(rd, "%s\n", fub);
					++ch;
					fprintf(rd, "+%s\n", readName);
					fprintf(rd, "%s\n", ch); 
					*/
				}
			}
		}
		hashFree(&localHash);
		fclose(rd);
	}
	fclose(fp);
	hashFreeWithVals(&readsHash, freez);
	hashFreeWithVals(&aliHash, rbTreeFree);
}
示例#21
0
文件: rudp.c 项目: ma-compbio/RACA
int rudpReceiveTimeOut(struct rudp *ru, void *messageBuf, int bufSize, 
	struct sockaddr_in *retFrom, int timeOut)
/* Read message into buffer of given size.  Returns actual size read on
 * success. On failure prints a warning, sets errno, and returns -1. 
 * Also returns ip address of message source. If timeOut is nonzero,
 * it represents the timeout in milliseconds.  It will set errno to
 * ETIMEDOUT in this case.*/
{
char inBuf[udpEthMaxSize];
struct rudpHeader *head = (struct rudpHeader *)inBuf;
struct rudpHeader ackHead;
struct sockaddr_in sai;
socklen_t saiSize = sizeof(sai);
int readSize, err;
assert(bufSize <= rudpMaxSize);
ru->receiveCount += 1;
for (;;)
    {
    if (timeOut != 0)
	{
	if (!readReadyWait(ru->socket, timeOut))
	    {
	    warn("rudpReceive timed out\n");
	    errno = ETIMEDOUT;
	    return -1;
	    }
	}
    readSize = recvfrom(ru->socket, inBuf, sizeof(inBuf), 0, 
	(struct sockaddr*)&sai, &saiSize);
    if (retFrom != NULL)
	*retFrom = sai;
    if (readSize < 0)
	{
	if (errno == EINTR)
	    continue;
	warn("recvfrom error: %s", strerror(errno));
	ru->failCount += 1;
	return readSize;
	}
    if (readSize < sizeof(*head))
	{
	warn("rudpRecieve truncated message");
	continue;
	}
    if (head->type != rudpData)
	{
	if (head->type != rudpAck)
	    warn("skipping non-data message %d in rudpReceive", head->type);
	continue;
	}
    ackHead = *head;
    ackHead.type = rudpAck;
    err = sendto(ru->socket, &ackHead, sizeof(ackHead), 0, 
	(struct sockaddr *)&sai, sizeof(sai));
    if (err < 0)
	{
	warn("problem sending ack in rudpRecieve: %s", strerror(errno));
	}
    readSize -= sizeof(*head);
    if (readSize > bufSize)
	{
	warn("read more bytes than have room for in rudpReceive");
	readSize = bufSize;
	}
    memcpy(messageBuf, head+1, readSize);

    /* check for duplicate packet */
    if (!ru->recvHash)
	{ /* take advantage of new auto-expanding hashes */
	ru->recvHash = newHashExt(4, FALSE);  /* do not use local mem in hash */
	ru->recvList = newDlList();
	ru->recvCount = 0;
	}
    char hashKey[64];
    char saiDottedQuad[17];
    internetIpToDottedQuad(ntohl(sai.sin_addr.s_addr), saiDottedQuad);
    safef(hashKey, sizeof(hashKey), "%s-%d-%d-%d" 
    	, saiDottedQuad 
        , head->pid              
        , head->connId
        , head->id
      );		    
    if (hashLookup(ru->recvHash, hashKey))
	{
	warn("duplicate packet filtered out: %s", hashKey);
	continue;
	}
    long now = time(NULL);
    struct packetSeen *p;
    AllocVar(p);
    AllocVar(p->node);
    p->node->val = p;
    p->recvHashKey = hashStoreName(ru->recvHash, hashKey);
    p->lastChecked = now;
    dlAddTail(ru->recvList, p->node);
    ++ru->recvCount;
   
    sweepOutOldPacketsSeen(ru, now);

    ru->lastIdReceived = head->id;
    break;
    }
return readSize;
}
示例#22
0
static void mafOrAxtClick2(struct sqlConnection *conn, struct sqlConnection *conn2, struct trackDb *tdb, char *axtOtherDb, char *fileName)
/* Display details for MAF or AXT tracks. */
{
hgBotDelay();
if (winEnd - winStart > 30000)
    {
    printf("Zoom so that window is 30,000 bases or less to see alignments and conservation statistics\n");
    }
else
    {
    struct mafAli *mafList = NULL, *maf, *subList = NULL;
    int aliIx = 0, realCount = 0;
    char dbChrom[64];
    char option[128];
    char *capTrack;
    struct consWiggle *consWig, *consWiggles;
    struct hash *speciesOffHash = NULL;
    char *speciesOrder = NULL;
    char *speciesTarget = trackDbSetting(tdb, SPECIES_TARGET_VAR);
    char buffer[1024];
    int useTarg = FALSE;
    int useIrowChains = FALSE;

    safef(option, sizeof(option), "%s.%s", tdb->track, MAF_CHAIN_VAR);
    if (cartCgiUsualBoolean(cart, option, FALSE) &&
	trackDbSetting(tdb, "irows") != NULL)
	    useIrowChains = TRUE;

    safef(buffer, sizeof(buffer), "%s.vis",tdb->track);
    if (useIrowChains)
	{
	if (!cartVarExists(cart, buffer) && (speciesTarget != NULL))
	    useTarg = TRUE;
	else
	    {
	    char *val;

	    val = cartUsualString(cart, buffer, "useCheck");
            useTarg = sameString("useTarg",val);
            }
        }

    if (sameString(tdb->type, "bigMaf"))
        {
        char *fileName = trackDbSetting(tdb, "bigDataUrl");
        struct bbiFile *bbi = bigBedFileOpen(fileName);
        mafList = bigMafLoadInRegion(bbi, seqName, winStart, winEnd);
        }
    else
        mafList = mafOrAxtLoadInRegion2(conn,conn2, tdb, seqName, winStart, winEnd,
                                        axtOtherDb, fileName);
    safef(dbChrom, sizeof(dbChrom), "%s.%s", hubConnectSkipHubPrefix(database), seqName);

    safef(option, sizeof(option), "%s.speciesOrder", tdb->track);
    speciesOrder = cartUsualString(cart, option, NULL);
    if (speciesOrder == NULL)
	speciesOrder = trackDbSetting(tdb, "speciesOrder");

    for (maf = mafList; maf != NULL; maf = maf->next)
        {
        int mcCount = 0;
        struct mafComp *mc;
        struct mafAli *subset;
        struct mafComp *nextMc;

        /* remove empty components and configured off components
         * from MAF, and ignore
         * the entire MAF if all components are empty
         * (solely for gap annotation) */

        if (!useTarg)
            {
            for (mc = maf->components->next; mc != NULL; mc = nextMc)
		{
		char buf[64];
                char *organism;
		mafSrcDb(mc->src, buf, sizeof buf);
                organism = hOrganism(buf);
                if (!organism)
                    organism = buf;
		nextMc = mc->next;
		safef(option, sizeof(option), "%s.%s", tdb->track, buf);
		if (!cartUsualBoolean(cart, option, TRUE))
		    {
		    if (speciesOffHash == NULL)
			speciesOffHash = newHash(4);
		    hashStoreName(speciesOffHash, organism);
		    }
		if (!cartUsualBoolean(cart, option, TRUE))
		    slRemoveEl(&maf->components, mc);
		else
		    mcCount++;
		}
	    }
        if (mcCount == 0)
            continue;

	if (speciesOrder)
	    {
	    int speciesCt;
	    char *species[2048];
	    struct mafComp **newOrder, *mcThis;
	    int i;

	    mcCount = 0;
	    speciesCt = chopLine(cloneString(speciesOrder), species);
	    newOrder = needMem((speciesCt + 1) * sizeof (struct mafComp *));
	    newOrder[mcCount++] = maf->components;

	    for (i = 0; i < speciesCt; i++)
		{
		if ((mcThis = mafMayFindCompSpecies(maf, species[i], '.')) == NULL)
		    continue;
		newOrder[mcCount++] = mcThis;
		}

	    maf->components = NULL;
	    for (i = 0; i < mcCount; i++)
		{
		newOrder[i]->next = 0;
		slAddHead(&maf->components, newOrder[i]);
		}

	    slReverse(&maf->components);
	    }
	subset = mafSubsetE(maf, dbChrom, winStart, winEnd, TRUE);
	if (subset != NULL)
	    {
	    /* Reformat MAF if needed so that sequence from current
	     * database is the first component and on the
	     * plus strand. */
	    mafMoveComponentToTop(subset, dbChrom);
	    if (subset->components->strand == '-')
		mafFlipStrand(subset);
	    subset->score = mafScoreMultiz(subset);
	    slAddHead(&subList, subset);
	    ++realCount;
	    }
	}
    slReverse(&subList);
    mafAliFreeList(&mafList);
    if (subList != NULL)
	{
	char *showVarName = "hgc.showMultiBase";
	char *showVarVal = cartUsualString(cart, showVarName, "all");
	boolean onlyDiff = sameWord(showVarVal, "diff");
#ifdef ADDEXONCAPITAL
	char *codeVarName = "hgc.multiCapCoding";
	char *codeVarVal = cartUsualString(cart, codeVarName, "coding");
	boolean onlyCds = sameWord(codeVarVal, "coding");
#endif
        /* add links for conservation score statistics */
        consWiggles = wigMafWiggles(database, tdb);
        int wigCount = slCount(consWiggles);
        if (wigCount == 1)
            {
            conservationStatsLink(tdb, "Conservation score statistics", consWiggles->table);
            }
        else if (wigCount > 1)
            {
            /* multiple wiggles. List all that have been turned on with
             * checkboxes */

            /* Scan for cart variables -- do any exist, are any turned on ? */
            boolean wigSet = FALSE;
            boolean wigOn = FALSE;
            for (consWig = consWiggles; consWig != NULL;
                        consWig = consWig->next)
                {
                char *wigVarSuffix = NULL;
                (void)wigMafWiggleVar(tdb->track, consWig, &wigVarSuffix);
                if (cartVarExistsAnyLevel(cart, tdb, FALSE, wigVarSuffix))
                    {
                    wigSet = TRUE;
                    if (cartBooleanClosestToHome(cart, tdb, FALSE, wigVarSuffix))
                        wigOn = TRUE;
                    }
                }
            /* If there are no cart vars, turn on the first (default) wig */
            if (!wigSet)
                {
                char *prefix = tdb->track; // use when setting things to the cart
                if (tdbIsContainerChild(tdb))
                    prefix = tdbGetContainer(tdb)->track;

                cartSetBoolean(cart, wigMafWiggleVar(prefix, consWiggles, NULL), TRUE);
                wigOn = TRUE;
                }
            if (wigOn)
                {
                boolean first = TRUE;
                for (consWig = consWiggles; consWig != NULL;
                            consWig = consWig->next)
                    {
                    if (first)
                        {
                        printf("Conservation score statistics:");
                        first = FALSE;
                        }
                    char *wigVarSuffix = NULL;
                    (void)wigMafWiggleVar(tdb->track, consWig, &wigVarSuffix);
                    if (cartUsualBooleanClosestToHome(cart, tdb, FALSE, wigVarSuffix,FALSE))
                        {
                        printf("&nbsp;&nbsp;");
                        subChar(consWig->uiLabel, '_', ' ');
                        conservationStatsLink(tdb,
                            consWig->uiLabel, consWig->table);
                        }
                    }
                }
            }
        puts("</P>\n");

        /* no alignment to display when in visibilities where only wiggle is shown */
        char *vis = cartOptionalString(cart, tdb->track);
        if (vis)
            {
            enum trackVisibility tv = hTvFromStringNoAbort(vis);
            if (tv == tvSquish || tv == tvDense)
                return;
            }

#ifdef ADDEXONCAPITAL
	puts("<FORM ACTION=\"../cgi-bin/hgc\" NAME=\"gpForm\" METHOD=\"GET\">");
	cartSaveSession(cart);
	cgiContinueHiddenVar("g");
	cgiContinueHiddenVar("c");
	cgiContinueHiddenVar("i");
	printf("Capitalize ");
        cgiMakeDropListFull(codeVarName, codeAll, codeAll,
	    ArraySize(codeAll), codeVarVal, autoSubmit);
	printf("exons based on ");
        capTrack = genePredDropDown(cart, trackHash,
                                       "gpForm", "hgc.multiCapTrack");
#endif
	printf("show ");
        cgiMakeDropListFull(showVarName, showAll, showAll,
	    ArraySize(showAll), showVarVal, autoSubmit);
	printf("bases");
	printf("<BR>\n");
	printf("</FORM>\n");

#ifdef REVERSESTRAND
        /* notify if bases are complemented (hgTracks is on reverse strand) */
        if (cartCgiUsualBoolean(cart, COMPLEMENT_BASES_VAR, FALSE))
            puts("<EM>Alignment displayed on reverse strand</EM><BR>");
#endif
	puts("Place cursor over species for alignment detail. Click on 'B' to link to browser ");
	puts("for aligned species, click on 'D' to get DNA for aligned species.<BR>");

	printf("<TT><PRE>");

        /* notify if species removed from alignment */
        if (speciesOffHash) 
            {
            char *species;
            struct hashCookie hc = hashFirst(speciesOffHash);
            puts("<B>Components not displayed:</B> ");
            while ((species = hashNextName(&hc)) != NULL)
                printf("%s ", species);
            puts("<BR>");
            }


	for (maf = subList; maf != NULL; maf = maf->next)
	    {
	    mafLowerCase(maf);
#ifdef ADDEXONCAPITAL
	    if (capTrack != NULL)
                capMafOnTrack(maf, capTrack, onlyCds);
#endif
            printf("<B>Alignment block %d of %d in window, %d - %d, %d bps </B>\n",
                   ++aliIx,realCount,maf->components->start + 1,
                   maf->components->start + maf->components->size, maf->components->size);
            mafPrettyOut(stdout, maf, 70,onlyDiff, aliIx);
            }
	mafAliFreeList(&subList);
	}
    else
	{
        printf("No multiple alignment in browser window");
	}
    printf("</PRE></TT>");
    }
}