void writeAliasTable(FILE *alias)
/* print out tabbed file for loading into the alias table, bacCloneAlias */
{
struct hashEl *aliasList = NULL, *aliasEl = NULL;
struct hashEl *bacList = NULL, *bacEl = NULL;
struct alias *al = NULL;
struct bac *bac = NULL;
char *name = NULL;
int i, j;

aliasList = hashElListHash(aliasHash);
bacList = hashElListHash(bacHash);
if (aliasList != NULL)
    {
    /* walk through list of hash elements */
    for (aliasEl = aliasList; aliasEl != NULL; aliasEl = aliasEl->next)
        {
        al = (struct alias *)aliasEl->val;
        name = cloneString(aliasEl->name);
        /* print out row for Sanger STS name and each alias */
        for (i = 0; i < NUMALIASES && (al->aliases[i] != NULL); i++) 
            {
            fprintf(alias, "%s\t%s\n", al->aliases[i], al->sangerName);
            }
        fflush(alias);
        }
    }
else
    errAbort("The hash of BAC clones aliases is empty or there was an error retrieving the list of entries in the hash\n");
/* those BAC clones without an entry in the alias hash have no sangerName */
/* so do not print to this table */
hashElFreeList(&aliasList);
hashElFreeList(&bacList);
}
Пример #2
0
void printCounts(struct hash *counts)
{
struct hashEl *el, *els = hashElListHash(counts);
slSort(&els, hashElCmp);
for (el = els; el != NULL; el = el->next)
    printf("	%s	%d\n", el->name, ptToInt(el->val));
}
Пример #3
0
struct bed* metaBig_chopGenome(struct metaBig* mb, int size)
/* return a bed of regularly-sized intervals (given) from the chromSizeHash */
{
    struct hashEl* list = hashElListHash(mb->chromSizeHash);
    struct hashEl* el;
    struct bed* bed_list = NULL;
    for (el = list; el != NULL; el = el->next) {
        char* chrom = el->name;
        int chromSize = ptToInt(el->val);
        int i;
        for (i = 0; i < chromSize; i += size) {
            struct bed* newbed;
            AllocVar(newbed);
            newbed->chrom = cloneString(chrom);
            newbed->chromStart = i;
            if ((i + size) > chromSize)
                newbed->chromEnd = chromSize;
            else
                newbed->chromEnd = i + size;
            newbed->name = cloneString(".");
            slAddHead(&bed_list, newbed);
        }
    }
    if (mb->sections)
        subset_with_sections(mb, &bed_list);
    slReverse(&bed_list);
    return bed_list;
}
Пример #4
0
struct hashEl *peakClusterMakerChromList(struct peakClusterMaker *maker)
/* Return list of chromosomes.  In hashEl format where the hashEl val is
 * a rangeTree filled with items. */
{
struct hashEl *chromList =  hashElListHash(maker->chromHash);
slSort(&chromList, cmpChromEls);
return chromList;
}
Пример #5
0
void edwBamToWig(char *input, char *output)
/* edwBamToWig - Convert a bam file to a wig file by measuring depth of coverage, optionally adjusting hit size to average for library.. */
{
FILE *f = mustOpen(output, "w");
/* Open file and get header for it. */
samfile_t *sf = samopen(input, "rb", NULL);
if (sf == NULL)
    errnoAbort("Couldn't open %s.\n", input);
bam_header_t *head = sf->header;
if (head == NULL)
    errAbort("Aborting ... Bad BAM header in file: %s", input);


/* Scan through input populating genome range trees */
struct genomeRangeTree *grt = genomeRangeTreeNew();
bam1_t one = {};
for (;;)
    {
    /* Read next record. */
    if (bam_read1(sf->x.bam, &one) < 0)
	break;
    if (one.core.tid >= 0 && one.core.n_cigar > 0)
	{
	char *chrom = head->target_name[one.core.tid];
	int start = one.core.pos;
	int end = start + one.core.l_qseq;
	if (one.core.flag & BAM_FREVERSE)
	    {
	    start -= clPad;
	    }
	else
	    {
	    end += clPad;
	    }
	struct rbTree *rt = genomeRangeTreeFindOrAddRangeTree(grt,chrom);
	rangeTreeAddToCoverageDepth(rt, start, end);
	}
    }


/* Convert genome range tree into output wig */

/* Get list of chromosomes. */
struct hashEl *hel, *helList = hashElListHash(grt->hash);
for (hel = helList; hel != NULL; hel = hel->next)
    {
    char *chrom = hel->name;
    struct rbTree *rt = hel->val;
    struct range *range, *rangeList = rangeTreeList(rt);
    for (range = rangeList; range != NULL; range = range->next)
         {
	 fprintf(f, "%s\t%d\t%d\t%d\n",  chrom, range->start, range->end, ptToInt(range->val));
	 }
    }

carefulClose(&f);
}
Пример #6
0
static struct hash* splitByPrefix(struct gbConf *conf)
/* split by prefix in to has of prefixElems  */
{
struct hash *prefixMap = hashNew(18);
struct hashEl *elems = hashElListHash(conf->hash);
struct hashEl *confEl;
while ((confEl = slPopHead(&elems)) != NULL)
    addByPrefix(prefixMap, confEl);
return prefixMap;
}
Пример #7
0
/*	one iteration of convolution
 *
 *	input is a probability histogram with N bins
 *		bins are numbered 0 through N-1
 *	output is a probability histogram with (N*2)-1 bins
 *
 *	The value to calculate in an output bin is a sum
 *	of the probabilities from the input bins that contribute to that
 *	output bin.  Specifically:
 *
 *	output[0] = input[0] * input[0]
 *	output[1] = (input[0] * input[1]) +
 *			(input[1] * input[0])
 *	output[2] = (input[0] * input[2]) +
 *			(input[1] * input[1]) +
 *			(input[2] * input[0])
 *	output[3] = (input[0] * input[3]) +
 *			(input[1] * input[2]) +
 *			(input[2] * input[1]) +
 *			(input[3] * input[0])
 *	output[4] = (input[0] * input[4]) +
 *			(input[1] * input[3]) +
 *			(input[2] * input[2]) +
 *			(input[3] * input[1]) +
 *			(input[4] * input[0])
 *	the pattern here is that the bin numbers from the input are
 *	summed together to get the bin number of the output.  The
 *	probabilities from those bins used from the input in each
 *	individual sum are multiplied together, and all those resulting
 *	multiplies are added together for the resulting output.
 *
 *	A double for() loop would do the above calculation:
 *	for (i = 0; i < N; ++i) {
 *		for (j = 0; j < N; ++j) {
 *			output[i+j] += input[i] * input[j];
 *		}
 *	}
 */
static int iteration(struct hash *input, struct hash *output)
{
struct hashEl *el, *elList;
int median = 0;
double maxLog = -1000000.0;

/*	This outside loop is like (i = 0; i < N; ++i)	*/
elList = hashElListHash(input);
for (el = elList; el != NULL; el = el->next)
    {
    struct histoGram *hg0;	/*	a hash element	*/
    struct hashEl *elInput;
    int bin0;

    /*	This inside loop is like (j = 0; j < N; ++j)	*/
    hg0 = el->val;
    bin0 = hg0->bin;
    for (elInput = elList; elInput != NULL; elInput = elInput->next)
	{
	struct histoGram *hg1;	/*	a hash element	*/
	int bin1;
	char binName[128];
	struct hashEl *el;
	struct histoGram *hgNew;

	hg1 = elInput->val;
	bin1 = hg1->bin;
	/*	output bin name is (i+j) == (bin0+bin1)	*/
	snprintf(binName, sizeof(binName), "%d", bin0+bin1);
	el = hashLookup(output, binName);
	/*	start new output bin if it does not yet exist	*/
	if (el == NULL) {
	    AllocVar(hgNew);
	    hgNew->bin = bin0+bin1;
	    hgNew->prob = hg0->prob * hg1->prob;
	    hgNew->log_2 = hg0->log_2 + hg1->log_2;
	    hashAdd(output, binName, hgNew);
	} else {	/*	Add to existing output bin the new inputs */
	    hgNew = el->val;
	    hgNew->log_2 =
		addLogProbabilities(hgNew->log_2, (hg0->log_2+hg1->log_2));
	    hgNew->prob = pow(2.0,hgNew->log_2);
	}
	/*	Keep track of the resulting output median	*/
	if (hgNew->log_2 > maxLog)
	    {
	    maxLog = hgNew->log_2;
	    median = hgNew->bin;
	    }
	}
    }
hashElFreeList(&elList);

return median;
}	/*	iteration()	*/
void writeHashToFile(struct hash *countHash, char *outputFile)
/* Make an slPair list out of a hashEl list, sort it, output it. */
{
FILE *f = mustOpen(outputFile, "w");
struct hashEl *el, *list = hashElListHash(countHash);
slNameSort((struct slName **)&list);
for (el = list; el != NULL; el = el->next)
    fprintf(f, "%s\t%d\n", el->name, ptToInt(el->val));
carefulClose(&f);
hashElFreeList(&list);
}
Пример #9
0
void printHash(char *label, struct hash *hash)
/* Print out keys in hash alphabetically. */
{
struct hashEl *list, *el;
list = hashElListHash(hash);
slSort(&list, hashElCmp);
printf("%s:\n", label);
for (el = list; el != NULL; el = el->next)
    printf("    %s\n", el->name);
hashElFreeList(&list);
}
Пример #10
0
void doEnrichmentsFromBed3Sample(struct bed3 *sampleList,
    struct sqlConnection *conn,
    struct cdwFile *ef, struct cdwValidFile *vf, 
    struct cdwAssembly *assembly, struct target *targetList)
/* Given a bed3 list,  calculate enrichments for targets */
{
struct genomeRangeTree *sampleGrt = cdwMakeGrtFromBed3List(sampleList);
struct hashEl *chrom, *chromList = hashElListHash(sampleGrt->hash);

/* Iterate through each target - and in lockstep each associated grt to calculate unique overlap */
struct target *target;
for (target = targetList; target != NULL; target = target->next)
    {
    if (target->skip)
        continue;
    struct genomeRangeTree *grt = target->grt;
    long long uniqOverlapBases = 0;
    for (chrom = chromList; chrom != NULL; chrom = chrom->next)
        {
	struct rbTree *sampleTree = chrom->val;
	struct rbTree *targetTree = genomeRangeTreeFindRangeTree(grt, chrom->name);
	if (targetTree != NULL)
	    {
	    struct range *range, *rangeList = rangeTreeList(sampleTree);
	    for (range = rangeList; range != NULL; range = range->next)
		{
		/* Do unique base overlap counts (since using range trees both sides) */
		int overlap = rangeTreeOverlapSize(targetTree, range->start, range->end);
		uniqOverlapBases += overlap;
		}
	    }
	}

    /* Figure out how much we overlap allowing same bases in genome
     * to part of more than one overlap. */ 
    long long overlapBases = 0;
    struct bed3 *sample;
    for (sample = sampleList; sample != NULL; sample = sample->next)
        {
	int overlap = genomeRangeTreeOverlapSize(grt, 
	    sample->chrom, sample->chromStart, sample->chromEnd);
	overlapBases += overlap;
	}

    /* Save to database. */
    struct cdwQaEnrich *enrich = enrichFromOverlaps(ef, vf, assembly,
	target, overlapBases, uniqOverlapBases);
    cdwQaEnrichSaveToDb(conn, enrich, "cdwQaEnrich", 128);
    cdwQaEnrichFree(&enrich);
    }
genomeRangeTreeFree(&sampleGrt);
hashElFreeList(&chromList);
}
Пример #11
0
static void printGbConf(FILE *fh, struct gbConf *conf)
/* Print contents of genbank.conf file for debugging purposes */
{
struct hashEl *confEls = hashElListHash(conf->hash);
struct hashEl *confEl;

slSort(&confEls, hashElCmp);
for (confEl = confEls; confEl != NULL; confEl = confEl->next)
    fprintf(fh, "%s = %s\n", confEl->name, (char*)confEl->val);

hashElFreeList(&confEls);
}
struct slName *hashToList(struct hash *wordHash)
/* convert the hash back to a list. */
{
struct hashEl *elList = hashElListHash(wordHash);
struct slName *list = NULL;
struct hashEl *cur;
for (cur = elList; cur != NULL; cur = cur->next)
    slNameAddHead(&list, cur->name);
slNameSort(&list);
hashElFreeList(&elList);
return list;
}
void weedLines(char *weedFile, char *file, char *output, 
	boolean invert, char *invertOutput)
/* weedLines - Selectively remove lines from file. */
{
struct hash *hash = hashWordsInFile(weedFile, 16);
struct hashEl *weedList = hashElListHash(hash);
verbose(2, "%d words in weed file %s\n", hash->elCount, weedFile);
struct lineFile *lf = lineFileOpen(file, TRUE);
char *line, *word;
FILE *f = mustOpen(output, "w");
FILE *fInvert = NULL;
boolean embedded = optionExists("embedded");
if (invertOutput != NULL)
    fInvert = mustOpen(invertOutput, "w");

while (lineFileNext(lf, &line, NULL))
    {
    boolean doWeed = FALSE;
    char *dupe = NULL;
    if (embedded)
	{
	struct hashEl *hel;
	for (hel = weedList; hel != NULL; hel = hel->next)
	    {
	    if (stringIn(hel->name, line))
	        doWeed = TRUE;
	    }
	}
    else
	{
	dupe = cloneString(line);
	while ((word = nextWord(&line)) != NULL)
	    {
	    if (hashLookup(hash, word))
		doWeed = TRUE;
	    }
	line = dupe;
	}
    if (invert)
	doWeed = !doWeed;
    if (!doWeed)
	fprintf(f, "%s\n", line);
    else
	{
	if (fInvert != NULL)
	    fprintf(fInvert, "%s\n", line);
	}
    freez(&dupe);
    }
}
Пример #14
0
void edwSamRepeatAnalysis(char *inSam, char *outRa)
/* edwSamRepeatAnalysis - Analyze result of alignment vs. RepeatMasker type libraries.. */
{
/* Go through sam file, filling in hiLevelHash with count of each hi level repeat class we see. */
struct hash *hiLevelHash = hashNew(0);
samfile_t *sf = samopen(inSam, "r", NULL);
bam_header_t *bamHeader = sf->header;
bam1_t one;
ZeroVar(&one);
int err;
long long hit = 0, miss = 0;
while ((err = samread(sf, &one)) >= 0)
    {
    int32_t tid = one.core.tid;
    if (tid < 0)
	{
	++miss;
        continue;
	}
    ++hit;

    /* Parse out hiLevel classification from target,  which is something like 7SLRNA#SINE/Alu 
     * from which we'd want to extract SINE.  The '/' is not present in all input. */
    char *target = bamHeader->target_name[tid];
    char *hashPos = strchr(target, '#');
    if (hashPos == NULL)
        errAbort("# not found in target %s", target);
    char *hiLevel = cloneString(hashPos + 1);
    char *slashPos = strchr(hiLevel, '/');
    if (slashPos != NULL)
        *slashPos = 0;

    hashIncInt(hiLevelHash, hiLevel);
    }
samclose(sf);

/* Output some basic stats as well as contents of hash */
FILE *f = mustOpen(outRa, "w");
double invTotal = 1.0 / (hit + miss);
double mapRatio = (double)hit * invTotal;
struct hashEl *hel, *helList = hashElListHash(hiLevelHash);
slSort(&helList, hashElCmp);
for (hel = helList; hel != NULL; hel = hel->next)
    {
    double hitRatio = ptToInt(hel->val) * invTotal;
    fprintf(f, "%s %g\n", hel->name, hitRatio);
    }
fprintf(f, "total %g\n", mapRatio);
carefulClose(&f);
}
Пример #15
0
struct hash *minChromSizeKeeperHash(struct hash *sizeHash)
/* Return a hash full of binKeepers that match the input sizeHash,
 * (which generally is the output of minChromSizeFromBeds). */
{
struct hashEl *el, *list = hashElListHash(sizeHash);
struct hash *keeperHash = hashNew(16);
for (el = list; el != NULL; el = el->next)
    {
    struct minChromSize *chrom = el->val;
    struct binKeeper *bk = binKeeperNew(0, chrom->minSize);
    hashAdd(keeperHash, chrom->chrom, bk);
    }
hashElFreeList(&list);
return keeperHash;
}
Пример #16
0
char *hashToRaString(struct hash *hash)
/* Convert hash to string in ra format. */
{
struct hashEl *el, *list = hashElListHash(hash);
struct dyString *dy = dyStringNew(0);
slSort(&list, hashElCmp);
for (el = list; el != NULL; el = el->next)
   {
   dyStringAppend(dy, el->name);
   dyStringAppendC(dy, ' ');
   dyStringAppend(dy, el->val);
   dyStringAppendC(dy, '\n');
   }
hashElFreeList(&list);
return dyStringCannibalize(&dy);
}
static struct hash *joinerAllFields(struct joiner *joiner)
/* Get hash of all fields in database.table.field format.
 * Similar to sqlAllFields(void) function in jksql.c, but different
 *	method of creating the list of databases to check.
 */
{
    struct hash *fullHash = hashNew(18);
    struct hashEl *db, *dbList = hashElListHash(joiner->databasesChecked);
    for (db = dbList; db != NULL; db = db->next)
    {
        verbose(3, "joinerAllFields: extracting fields from database: '%s'\n",
                db->name);
        sqlAddDatabaseFields(db->name, fullHash);
    }
    slFreeList(&dbList);
    return fullHash;
}
void userSettingsUseNamed(struct userSettings *us, char *setName)
/* Use named collection of settings. */
{
struct cart *cart = us->cart;
char *varName = settingsVarName(us->savePrefix, setName);
char *settings = cartOptionalString(cart, varName);
if (settings != NULL)
    {
    struct hash *hash = hashVarLine(settings, 1);
    struct hashEl *list = hashElListHash(hash);
    struct hashEl *el;
    for (el = list; el != NULL; el = el->next)
	cartSetString(cart, el->name, el->val);
    slFreeList(&list);
    hashFree(&hash);
    }
freez(&varName);
}
Пример #19
0
static struct bed* sectionsFromChromSizes(struct hash* chromSizes)
/* return a list of bed3s used as sections using the whole chromosome sizes */
{
    struct bed* bedList = NULL;
    struct hashEl* list = hashElListHash(chromSizes);
    struct hashEl* el;
    for (el = list; el != NULL; el = el->next) {
        struct bed* bed;
        AllocVar(bed);
        bed->chrom = cloneString(el->name);
        bed->chromStart = 0;
        bed->chromEnd = (unsigned)ptToInt(el->val);
        slAddHead(&bedList, bed);
    }
    slReverse(&bedList);
    hashElFreeList(&list);
    return bedList;
}
Пример #20
0
static char *settingsFromHash(struct hash *hash)
/* Create settings string from settings hash. */
{
if (hash == NULL)
    return cloneString("");
else
    {
    struct dyString *dy = dyStringNew(1024);
    char *ret;
    struct hashEl *el, *list = hashElListHash(hash);
    slSort(&list, hashElCmp);
    for (el = list; el != NULL; el = el->next)
	dyStringPrintf(dy, "%s %s\n", el->name, (char *)el->val);
    slFreeList(&list);
    ret = cloneString(dy->string);
    dyStringFree(&dy);
    return ret;
    }
}
Пример #21
0
void crTreeFileCreate(
	struct crTreeItem *itemList,  /* List of all items - sorted here and in underlying file. */
	struct hash *chromHash,	      /* Hash of all chromosome names. */
	bits32 blockSize,	/* R tree block size - # of children for each node. 1024 is good. */
	bits32 itemsPerSlot,	/* Number of items to put in each index slot at lowest level.
				 * Typically either blockSize/2 or 1. */
	bits64 endPosition,	/* File offset after have read all items in file. */
	char *fileName)        /* Name of output file. */
/* Create a cr tree index of file. The itemList contains the position of each item in the
 * chromosome and in the file being indexed.  Both the file and the itemList must be sorted
 * by chromosome (alphabetic), start (numerical), end (numerical). 
 *    We recommend you run crTreeFileCreateInputCheck on the input parameters right before
 * calling this if you have problems. */
{
/* We can't handle empty input... */
if (itemList == NULL)
    errAbort("crTreeFileCreate can't handle empty itemList.");

/* Make array of pointers out of linked list. */
struct crTreeItem **itemArray;
bits32 itemCount = slCount(itemList);
AllocArray(itemArray, itemCount);
struct crTreeItem *item;
int itemIx;
for (itemIx=0, item=itemList; itemIx<itemCount; ++itemIx, item=item->next)
    itemArray[itemIx] = item;

/* Make up chromosome array. */
int chromCount = chromHash->elCount;
char **chromArray;
AllocArray(chromArray, chromCount);
struct hashEl *el, *list = hashElListHash(chromHash);
bits32 chromIx;
for (el = list, chromIx=0; el != NULL; el = el->next, ++chromIx)
    chromArray[chromIx] = el->name;
slFreeList(&list);

/* Call function to make index file. */
crTreeFileCreateLow(chromArray, chromCount, itemArray, sizeof(itemArray[0]), itemCount,
	blockSize, itemsPerSlot, crTreeItemKey, crTreeItemOffset, itemList->fileOffset, 
	endPosition, fileName);
}
void joinerCheckTableCoverage(struct joiner *joiner, char *specificDb)
/* Check that all tables either are part of an identifier or
 * are in the tablesIgnored statements. */
{
    struct slName *miss, *missList = NULL;
    struct hashEl *dbList, *db;

    dbList = hashElListHash(joiner->databasesChecked);
    for (db = dbList; db != NULL; db = db->next)
    {
        if (specificDb == NULL || sameString(db->name, specificDb))
        {
            struct sqlConnection *conn = sqlMayConnect(db->name);
            if (conn == NULL)
                warn("Error: database %s doesn't exist", db->name);
            else
            {
                struct slName *table;
                struct slName *tableList = sqlListTables(conn);
                struct hash *hash = getCoveredTables(joiner, db->name, conn);
                for (table = tableList; table != NULL; table = table->next)
                {
                    if (!hashLookup(hash, table->name))
                    {
                        char fullName[256];
                        safef(fullName, sizeof(fullName), "%s.%s",
                              db->name, table->name);
                        miss = slNameNew(fullName);
                        slAddHead(&missList, miss);
                    }
                    else
                        verbose(2,"tableCovered: '%s'\n", table->name);
                }
                slFreeList(&tableList);
                freeHash(&hash);
                reportErrorList(&missList, "tables not in .joiner file");
            }
            sqlDisconnect(&conn);
        }
    }
    slFreeList(&dbList);
}
Пример #23
0
void bwtool_lift(struct hash *options, char *favorites, char *regions, unsigned decimals,
		 enum wigOutType wot, char *bigfile, char *chainfile, char *outputfile)
/* bwtool_lift - main for lifting program */
{
    struct hash *sizeHash = NULL;
    struct hash *chainHash = readLiftOverMapChainHash(chainfile);
    struct hash *gpbw = NULL;
    char *size_file = hashFindVal(options, "sizes");
    char *bad_file = hashFindVal(options, "unlifted");
    if (size_file)
	sizeHash = readCsizeHash(size_file);
    else
	sizeHash = qSizeHash(chainfile);
    gpbw = genomePbw(sizeHash);
    struct metaBig *mb = metaBigOpen_check(bigfile, regions);
    char wigfile[512];
    safef(wigfile, sizeof(wigfile), "%s.tmp.wig", outputfile);
    FILE *out = mustOpen(wigfile, "w");
    struct hashEl *elList = hashElListHash(gpbw);
    struct hashEl *el;
    verbose(2,"starting first pass\n");
    do_pass1(mb, chainHash, gpbw);
    verbose(2, "starting second pass\n");
    do_pass2(mb, chainHash, gpbw);
    verbose(2,"starting final pass\n");
    do_final_pass(mb, chainHash, gpbw, bad_file);
    slSort(&elList, pbwHashElCmp);
    for (el = elList; el != NULL; el = el->next)
    {
	struct perBaseWig *pbw = (struct perBaseWig *)el->val;
	perBaseWigOutputNASkip(pbw, out, wot, decimals, NULL, FALSE, FALSE);
    }
    hashElFreeList(&elList);
    carefulClose(&out);
    hashFreeWithVals(&chainHash, freeChainHashMap);
    hashFreeWithVals(&gpbw, perBaseWigFree);
    writeBw(wigfile, outputfile, sizeHash);
    hashFree(&sizeHash);
    remove(wigfile);
    metaBigClose(&mb);
}
void agpNotInf(char *agpFile, char *infFile)
/* agpNotInf - List clones in .agp file not in .inf file. */
{
struct hash *agpHash = readAgp(agpFile);
struct hash *infHash = readInf(infFile);
struct hashEl *list, *el;
struct clone *agpClone, *infClone;

list = hashElListHash(agpHash);
uglyf("%d clones in agpHash\n", slCount(list));
for (el = list; el != NULL; el = el->next)
    {
    agpClone = el->val;
    infClone = hashFindVal(infHash, agpClone->name);
    if (infClone == NULL)
        printf("%s missing\n", agpClone->version);
    else if (!sameString(agpClone->version, infClone->version))
        printf("%s updated from %s\n", agpClone->version, infClone->version);
    }
hashElFreeList(&list);
}
void joinerCheckDependencies(struct joiner *joiner, char *specificDb)
/* Check time stamps on dependent tables. */
{
    struct hashEl *db, *dbList = hashElListHash(joiner->databasesChecked);
    for (db = dbList; db != NULL; db = db->next)
    {
        if (specificDb == NULL || sameString(specificDb, db->name))
        {
            struct sqlConnection *conn = sqlMayConnect(db->name);
            if (conn != NULL)	/* We've already warned on this NULL */
            {
                struct joinerDependency *dep;
                for (dep = joiner->dependencyList; dep != NULL; dep = dep->next)
                {
                    checkOneDependency(joiner, dep, conn, db->name);
                }
                sqlDisconnect(&conn);
            }
        }
    }
    slFreeList(&dbList);
}
Пример #26
0
struct hash *genomePbw(struct hash *qSizes)
/* make a parallel hash of pbws given the size hash, also keyed on chrom name */
{
    struct hash *pbwHash = newHash(10);
    struct hashEl *list = hashElListHash(qSizes);
    struct hashEl *el;
    const double na = NANUM;
    int i;
    for (el = list; el != NULL; el = el->next)
    {
	int size = ptToInt(el->val);
	struct perBaseWig *pbw = alloc_perBaseWig(el->name, 0, size);
	for (i = 0; i < pbw->len; i++)
	    pbw->data[i] = na;
	pbw->name = cloneString(el->name);
	pbw->strand[0] = '+';
	pbw->strand[1] = '\0';
	hashAdd(pbwHash, el->name, pbw);
    }
    hashElFreeList(&list);
    return pbwHash;
}
Пример #27
0
static void checkIgnoreBalance(struct joiner *joiner)
/* Check that databases in fields are in the checked list.
 * Check that there is no overlap between checked and ignored
 * list. */
{
struct joinerSet *js;
struct joinerField *jf;
struct slName *db;
struct hashEl *ignoreList, *ignore;

/* Check that there is no overlap between databases ignored
 * and databases checked. */
ignoreList = hashElListHash(joiner->databasesIgnored);
for (ignore=ignoreList; ignore != NULL; ignore = ignore->next)
    {
    if (hashLookup(joiner->databasesChecked, ignore->name))
        errAbort("%s is in both databasesChecked and databasesIgnored",
		ignore->name);
    }
slFreeList(&ignoreList);

/* Check that all databases mentioned in fields are in 
 * databasesChecked. */
for (js = joiner->jsList; js != NULL; js = js->next)
    {
    for (jf = js->fieldList; jf != NULL; jf = jf->next)
        {
	for (db = jf->dbList; db != NULL; db = db->next)
	    {
	    if (!hashLookup(joiner->databasesChecked, db->name))
	        {
		errAbort("database %s line %d of %s is not in databasesChecked",
			db->name, jf->lineIx, joiner->fileName);
		}
	    }
	}
    }
}
Пример #28
0
double calcBaseCoverage(struct hash *refHash, struct hash *geneHash)
/* Figure proportion refBases covered by genes.  Both refHash and geneHash
 * are keyed by chromosome and filled with genes. */
{
struct hashEl *chrom, *chromList = hashElListHash(refHash);
long totalRef = 0, totalOverlap = 0;
for (chrom = chromList; chrom != NULL; chrom = chrom->next)
    {
    char *chromName = chrom->name;
    struct binKeeper *refBk = chrom->val;
    struct rbTree *refTree = bedBkToTree(refBk);
    totalRef += rangeTreeTotalSize(refTree);
    struct binKeeper *geneBk = hashFindVal(geneHash, chromName);
    if (geneBk != NULL)
	{
	struct rbTree *geneTree = bedBkToTree(geneBk);
        totalOverlap += rangeTreeRangeTreeOverlap(refTree, geneTree);
	rangeTreeFree(&geneTree);
	}
    rangeTreeFree(&refTree);
    }
return (double)totalOverlap / totalRef;
}
Пример #29
0
static void printDir(FILE *f, struct _pf_dir *dir, struct _pf_base *base,
	struct hash *idHash)
/* Print out each key/val pair in dir. */
{
if (dir == NULL)
    fprintf(f, "()");
else
    {
    if (idHash)
	{
	if (!reuseObject(f, idHash, dir))
	    {
	    struct hash *hash = dir->hash;
	    struct hashEl *hel, *helList = hashElListHash(hash);
	    struct _pf_base *base = dir->elType->base;
	    slSort(&helList, hashElCmp);
	    fprintf(f, "(");
	    for (hel = helList; hel != NULL; hel = hel->next)
		{
		fprintf(f, "'%s'@", hel->name);
		if (base->needsCleanup)
		    _pf_printField(f, &hel->val, base, idHash);
		else
		    _pf_printField(f, hel->val, base, idHash);
		if (hel->next != NULL)
		     fprintf(f, ",");
		}
	    hashElFreeList(&helList);
	    fprintf(f, ")");
	    }
	}
    else
        {
	fprintf(f, "<dir of %d>", dir->hash->elCount);
	}
    }
}
Пример #30
0
void nibTwoCacheFree(struct nibTwoCache **pNtc)
/* Free up resources associated with nibTwoCache. */
{
struct nibTwoCache *ntc = *pNtc;
if (ntc != NULL)
    {
    freez(&ntc->pathName);
    if (ntc->isTwoBit)
        twoBitClose(&ntc->tbf);
    else
        {
	struct hashEl *el, *list = hashElListHash(ntc->nibHash);
	struct nibInfo *nib;
	for (el = list; el != NULL; el = el->next)
	     {
	     nib = el->val;
	     nibInfoFree(&nib);
	     }
	hashElFreeList(&list);
	hashFree(&ntc->nibHash);
	}
    freez(pNtc);
    }
}