Example #1
0
void loadCr2g(char *fileName, struct cr2g **chromLists)
{
char buf[512];
struct cr2g *el;
FILE *f = mustOpen(fileName, "r");
char *words[8];
int wordCount;
char *parts[3];
int partCount;
int chromIx;

uglyf("Loading %s<BR>\n", fileName);
while (fgets(buf, sizeof(buf), f) != NULL)
    {
    wordCount = chopString(buf, whiteSpaceChopper, words, ArraySize(words));
    if (wordCount != 3)
        errAbort("Bad cr2g file\n");
    partCount = chopString(words[0], ":-", parts, ArraySize(parts));
    if (partCount != 3)
        errAbort("Bad cr2g file\n");
    AllocVar(el);
    chromIx = findChromIx(parts[0]);
    el->strand = words[1][0];
    el->start = atoi(parts[1]);
    el->end = atoi(parts[2]);
    strncpy(el->geneName, words[2], sizeof(el->geneName));

    el->next = chromLists[chromIx];
    chromLists[chromIx] = el;
    }
uglyf("Done loading %s<BR>\n", fileName);
fclose(f);
}
Example #2
0
void chainPair(struct seqPair *sp, FILE *f)
/* Make chains for all alignments in sp. */
{
long startTime, dt;
struct axt *axt;
struct cBlock *blockList, *block;
struct chain *chainList = NULL, *chain;

uglyf("%s %d nodes\n", sp->name, slCount(sp->blockList));

/* Make up tree and time it for debugging. */
startTime = clock1000();
chainList = chainBlocks(&sp->blockList, gapCost);
dt = clock1000() - startTime;
uglyf("Made %d chains in %5.3f seconds\n", slCount(chainList), dt*0.001);

/* Dump chains to file. */
for (chain = chainList; chain != NULL; chain = chain->next)
    {
    struct cBlock *first = chain->blockList;
    struct cBlock *last = slLastEl(first);
    struct cBlock *block;
    fprintf(f, "%s Chain %d, score %d, %d %d, %d %d:\n", 
	sp->name, slCount(chain->blockList), chain->score,
	first->qStart, last->qEnd, first->tStart, last->qEnd);
    for (block = chain->blockList; block != NULL; block = block->next)
        {
	fprintf(f, " %s q %d, t %d, score %d\n", sp->name,
		block->qStart, block->tStart, block->score);
	}
    fprintf(f, "\n");
    }
chainFreeList(&chainList);
uglyf("\n");
}
Example #3
0
void rt1dFindOld(char *tabFile, char *treeFile, bits32 chromIx, bits32 start, bits32 end)
/* rt1dCreate - find items in 1-D range tree. */
{
struct lineFile *lf = lineFileOpen(tabFile, TRUE);
struct cirTreeFile *crf = cirTreeFileOpen(treeFile);
struct fileOffsetSize *block, *blockList = cirTreeFindOverlappingBlocks(crf, chromIx, start, end);
uglyf("Got %d overlapping blocks\n", slCount(blockList));
for (block = blockList; block != NULL; block = block->next)
    {
    uglyf("block->offset %llu, block->size %llu\n", block->offset, block->size);
    lineFileSeek(lf, block->offset, SEEK_SET);
    bits64 sizeUsed = 0;
    while (sizeUsed < block->size)
        {
	char *line;
	int size;
	if (!lineFileNext(lf, &line, &size))
	    errAbort("Couldn't read %s\n", lf->fileName);
	char *parsedLine = cloneString(line);
	char *row[3];
	if (chopLine(parsedLine, row) != ArraySize(row))
	    errAbort("Badly formatted line of %s\n%s", lf->fileName, line);
	bits32 bedChromIx = sqlUnsigned(row[0]);
	bits32 bedStart = sqlUnsigned(row[1]);
	bits32 bedEnd = sqlUnsigned(row[2]);
	if (bedChromIx == chromIx && rangeIntersection(bedStart, bedEnd, start, end) > 0)
	    fprintf(stdout, "%s\n", line);
	freeMem(parsedLine);
	sizeUsed += size;
	}
    }
}
Example #4
0
void alignNt(char *nt)
/* Do alignments of draft bacs against one NT. */
{
char indexFileName[512];
char ntFaName[512];
struct lineFile *indexLf;
int lineSize;
char *line;
char *words[3];
int wordCount;
struct patSpace *ps;
struct dnaSeq *ntSeq;

printf("<H1>Check Layout of %s</H1>\n", nt);
printf("<PRE>");
sprintf(ntFaName, "%s/p%s.fa", faDir, nt);
ntSeq = faReadAllDna(ntFaName);
ps = makePatSpace(&ntSeq, 1, oocFile, 10, 500);
sprintf(indexFileName, "%s/%s.index", indexDir, nt);
uglyf("Checking out %s and %s\n", indexFileName, ntFaName);
indexLf = lineFileOpen(indexFileName, TRUE);
while (lineFileNext(indexLf, &line, &lineSize))
    {
    wordCount = chopLine(line, words);
    if (wordCount > 0)
	{
	char bacFaName[512];
	struct dnaSeq *contigList, *contig;
	char *bacAcc = words[0];
	char *s = strrchr(bacAcc, '.');
	if (s != NULL)
	    *s = 0;
	uglyf("%s\n", bacAcc);
	sprintf(bacFaName, "%s/%s.fa", faDir, bacAcc);
	contigList = faReadAllDna(bacFaName);
	for (contig = contigList; contig != NULL; contig = contig->next)
	    {
	    boolean isRc;
	    uglyf(" %s\n", contig->name);
	    for (isRc = FALSE; isRc <= TRUE; isRc += 1)
		{
		struct ssBundle *bunList, *bun;
		bunList = ssFindBundles(ps, contig, contig->name, ffTight);
		for (bun = bunList; bun != NULL; bun = bun->next)
		    {
		    showBundle(bun, isRc);
		    }
		ssBundleFreeList(&bunList);
		reverseComplement(contig->dna, contig->size);
		}
	    }
	freeDnaSeqList(&contigList);
	}
    }
lineFileClose(&indexLf);
freeDnaSeqList(&ntSeq);
}
void intersectOnChrom(char *db, struct sqlConnection *conn, char *chrom, 
	char *track1, char *track2)
/* Do intersection on one chromosome. */
{
int chromSize = hChromSize(chrom);
struct lm *lm = lmInit(0);
struct bed *bedList1, *bedList2, *andBed;
struct featureBits *fb1, *fb2;
Bits *bit1, *bit2;
int fieldCount1, fieldCount2;
struct binKeeper *bk2;

uglyTime(NULL);
scanChromTable(conn, chrom, track1);
scanChromTable(conn, chrom, track2);
uglyTime("Scan tracks");
bedList1 = getChromAsBed(conn, db, track1, chrom, lm, &fieldCount1);
bedList2 = getChromAsBed(conn, db, track2, chrom, lm, &fieldCount2);
uglyTime("Tracks as bed");
uglyf("%d items with %d fields in %s, ", slCount(bedList1), fieldCount1, track1);
uglyf("%d items with %d fields in %s\n", slCount(bedList2), fieldCount2, track2);
bit1 = bitAlloc(chromSize+8);
bit2 = bitAlloc(chromSize+8);
uglyTime("bitAlloc");

fb1 = fbList(db, chrom, track1,  bedList1, chromSize);
fb2 = fbList(db, chrom, track1,  bedList1, chromSize);
uglyTime("bed to featureBits list");

fbOrBits(bit1, chromSize, fb1, 0);
fbOrBits(bit2, chromSize, fb2, 0);
uglyTime("or into bits");

bitAnd(bit1, bit2, chromSize);
uglyTime("Anding bitfields");

andBed = bitsToBed4List(bit1, chromSize, chrom, 0, 0, chromSize, lm);
uglyTime("Converting bitfield to bed 4");

bitCountAllOverlaps(bedList1, bit2, fieldCount2);
uglyTime("Counting overlaps in track1 with bitfield of track2");

bk2 = fbToBinKeeper(fb2, chromSize);
uglyTime("Adding featureBits list from track 2 into binKeeper.");

bkCountAllOverlaps(bedList1, bk2, fieldCount2);
uglyTime("Count overlaps in track1 with binKeeper of track2");

featureBitsFreeList(&fb1);
featureBitsFreeList(&fb2);
uglyTime("free featureBits");


bitFree(&bit1);
bitFree(&bit2);
uglyTime("bitFree");
}
Example #6
0
void hgNibSeq(char *database, char *destDir, int faCount, char *faNames[])
/* hgNibSeq - convert DNA to nibble-a-base and store location in database. */
{
char dir[256], name[128], chromName[128], ext[64];
char nibName[512];
struct sqlConnection *conn = sqlConnect(database);
char query[512];
int i;
char *faName;
struct dnaSeq *seq = NULL;
unsigned long total = 0;
int size;

if (!strchr(destDir, '/'))
   errAbort("Use full path name for nib file dir\n");

makeDir(destDir);
if ((!appendTbl) || !sqlTableExists(conn, tableName))
    createTable(conn);
for (i=0; i<faCount; ++i)
    {
    faName = faNames[i];
    splitPath(faName, dir, name, ext);
    sprintf(nibName, "%s/%s.nib", destDir, name);
    printf("Processing %s to %s\n", faName, nibName);
    if (preMadeNib)
        {
	FILE *nibFile;
	nibOpenVerify(nibName, &nibFile, &size);
	carefulClose(&nibFile);
	}
    else
	{
	seq = faReadDna(faName);
	if (seq != NULL)
	    {
	    size = seq->size;
	    uglyf("Read DNA\n");
	    nibWrite(seq, nibName);
	    uglyf("Wrote nib\n");
	    freeDnaSeq(&seq);
	    }
	}
    strcpy(chromName, chromPrefix);
    strcat(chromName, name);
    sqlSafef(query, sizeof query, "INSERT into %s VALUES('%s', %d, '%s')",
        tableName, chromName, size, nibName);
    sqlUpdate(conn,query);
    total += size;
    }
sqlDisconnect(&conn);
printf("%lu total bases\n", total);
}
int main()
{
testPolyOut();
uglyf("Ok1\n");
testPolyIn();
uglyf("Ok2\n");
testPolyhOut();
uglyf("Ok3\n");
testPolyhIn();
uglyf("Ok4\n");
return 0;
}
Example #8
0
void makeCdnaToGene(struct cdnaInfo *cdnaList)
/* Make cdna to gene translation file. */
{
struct hash *hash = newHash(12);
struct cdnaInfo *ci;
struct fineAli *fa;
struct geneHit *gh;
struct geneHitList *geneHitList = NULL;
struct geneHitList *ghl;
struct hashEl *he;

uglyf("Making cdnaToGene file<BR>\n");

for (ci = cdnaList; ci != NULL; ci = ci->next)
    {
    if (ci->isDupe)
        continue;
    for (fa = ci->fineAli; fa != NULL; fa = fa->next)
        {
        if (fa->isDupe || !fa->isGood) 
            continue;
        if ((he = hashLookup(hash, fa->geneName)) == NULL)
            {
            AllocVar(ghl);
            ghl->geneName = fa->geneName;
            ghl->next = geneHitList;
            geneHitList = ghl;
            he = hashAdd(hash, fa->geneName, ghl);
            }
        ghl = (struct geneHitList *)(he->val);
        AllocVar(gh);
        gh->cdnaName = ci->name;
        gh->chromOffset = fa->hStart;
        gh->next = ghl->hits;
        ghl->hits = gh;
        }
    }
slSort(&geneHitList, cmpGhlName);

for (ghl=geneHitList; ghl!=NULL; ghl = ghl->next)
    {
    slReverse(&ghl->hits);
    slSort(&ghl->hits, cmpGhOffset);
    fprintf(cdnaToGeneFile, "%s ", ghl->geneName);
    for (gh = ghl->hits; gh != NULL; gh = gh->next)
        fprintf(cdnaToGeneFile, "%s ", gh->cdnaName);
    fprintf(cdnaToGeneFile, "\n");
    }

freeHash(&hash);
slFreeList(&geneHitList);
uglyf("Done making cdnaToGene file<BR>\n");
}
void smallTest()
/* Test out stuff. */
{
struct ggMrnaCluster *mc = makeTestInput();
struct geneGraph *gg;
static struct ggMrnaInput dummyCi;

uglyf("Initial input\n");
dumpMc(mc);
uglyf("\n");
gg = ggGraphCluster(mc, &dummyCi);
traverseGeneGraph(gg, mc->tStart, mc->tEnd, dumpGgAliInfo);
errAbort("Done testing");
}
int bwtSearch(UBYTE *bwt, bits32 size, char *string)
/* Reverse Burrows Wheeler transform of string. */
{
/* Empty case is easy here (and a pain if we have to deal with it later) */
if (size == 0)
    return 0;

/* Make array that will store the count of occurences of each character up to a given position. */
bits32 *occ;
AllocArray(occ, size+1);

/* Count up occurences of all characters into offset array.   */
bits32 i, counts[256], offsets[256];
for (i=0; i<256; ++i)
    counts[i] = 0;
for (i=0; i<size; ++i)
    {
    int c = bwt[i];
    occ[i] = counts[c];
    counts[c] += 1;
    }

/* Convert counts to offsets. */
bits32 total = 0;
for (i=0; i<ArraySize(offsets); ++i)
    {
    offsets[i] = total;
    total += counts[i];
    }

i = strlen(string)-1;
int start = 0, end = size-1;
while (start <= end)
    {
    UBYTE c = string[i];
    int startOcc = findOcc(bwt, c, start-1);
    int endOcc = findOcc(bwt, c, end) - 1;
    uglyf("%u  start=%u  end=%u  c=%c(%d) offsets[%c]=%d startOcc=%d endOcc=%d\n", i, start, end, c, c, c, offsets[c], startOcc, endOcc);
    start = offsets[c] + startOcc;
    end = offsets[c] + endOcc;
    if (i == 0)
        break;
    i = i - 1;
    }
uglyf("final i=%d start=%u end=%u\n", i, start, end);
if (i != 0)
    return 0;
return end - start + 1;
}
Example #11
0
void freen(char *chrom)
/* Test something */
{
uglyTime(NULL);
struct sqlConnection *conn = sqlConnect("hg19");
uglyTime("connect");
char query[512];
sqlSafef(query, sizeof(query), "select * from knownGene where chrom='%s'", chrom);
struct sqlResult *sr = sqlGetResult(conn, query);
uglyTime("get result");
char **row;
struct rbTree *rt = rangeTreeNew();
while ((row = sqlNextRow(sr)) != NULL)
    {
    struct genePred *gp = genePredLoad(row);
    int i;
    int exonCount = gp->exonCount;
    for (i=0; i<exonCount; ++i)
        rangeTreeAdd(rt, gp->exonStarts[i], gp->exonEnds[i]);
    }
uglyTime("Add rows");
struct range *list = rangeTreeList(rt);
uglyTime("Did list");
uglyf("%d items in chrom %s\n", slCount(list), chrom);
}
void loadFaSeq(struct hash *faHash, char *newName, char strand, 
	char **pName, struct dnaSeq **pSeq, char *pStrand)
/* retrieve sequence from hash.  Reverse complement
 * if necessary. */
{
struct dnaSeq *seq;
if (sameString(newName, *pName))
    {
    if (strand != *pStrand)
        {
	seq = *pSeq;
	reverseComplement(seq->dna, seq->size);
	*pStrand = strand;
	}
    }
else
    {
    char fileName[512];
    *pName = newName;
    *pSeq = seq = hashFindVal(faHash, newName);
    *pStrand = strand;
    if (strand == '-')
        reverseComplement(seq->dna, seq->size);
    uglyf("Loaded %d bases from %s fa\n", seq->size, newName);
    }
}
Example #13
0
void splitSim(char *XXX)
/* splitSim - Simulate gapless distribution size. */
{
int splitCount = simSize / aveSize;
bool *splitBuf = needMem(simSize+1);
int start = 0, size;
int i;
uglyf("split count %d\n", splitCount);
for (i=0; i<splitCount; ++i)
     {
     for (;;)
	 {
	 int rPos = random()%simSize;
	 if (splitBuf[rPos] == 0)
	     {
	     splitBuf[rPos] = 1;
	     break;
	     }
	 }
     }
splitBuf[simSize] = 1;
start = 0;
for (i=0; i<=simSize; ++i)
    {
    if (splitBuf[i])
        {
	size = i - start;
	if (size < countCount)
	     counts[size] += 1;
	start = i;
	}
    }
for (i=0; i<countCount; ++i)
    printf("%3d %6d\n", i, counts[i]);
}
int main(int argc, char *argv[])
{
char *rerunDir = "/projects/cc/hg/gs.2/g2g/g2g.fix";
FILE *f = mustOpen("/projects/cc/hg/gs.2/g2g/g2g.fix/makeFix.con", "w");
char *inName = "/projects/cc/hg/gs.2/g2g/miss.txt";
struct lineFile *lf = lineFileOpen(inName, TRUE);
int wordCount, lineSize, len;
char *line, *words[16];
char *a, *b;
char *s;
char both[32];

while (lineFileNext(lf, &line, &lineSize))
    {
    s = strchr(line, ':');
    if (s == NULL)
	continue;
    *s = 0;
    a = line;
    b = strchr(a, '_');
    if (b == NULL)
	errAbort("Expecting '_' in first word line %d of %s", lf->lineIx, lf->fileName);
    *b++ = 0;
    sprintf(both, "%s_%s", a, b);
    uglyf("Processing %s\n", both);
    fprintf(f, "log = %s/log/%s\n", rerunDir, both);
    fprintf(f, "error = %s/err/%s\n", rerunDir, both);
    fprintf(f, "output = %s/out/%s\n", rerunDir, both);
    fprintf(f, "arguments = in/%s in/%s g2g /var/tmp/hg/h/11.ooc %s/psl/%s.psl\n",
    	a, b, rerunDir, both);
    fprintf(f, "queue 1\n\n");
    }
}
void loadIfNewSeq(char *nibDir, char *newName, char strand, 
	char **pName, struct dnaSeq **pSeq, char *pStrand)
/* Load sequence unless it is already loaded.  Reverse complement
 * if necessary. */
{
struct dnaSeq *seq;
if (sameString(newName, *pName))
    {
    if (strand != *pStrand)
        {
	seq = *pSeq;
	reverseComplement(seq->dna, seq->size);
	*pStrand = strand;
	}
    }
else
    {
    char fileName[512];
    freeDnaSeq(pSeq);
    snprintf(fileName, sizeof(fileName), "%s/%s.nib", nibDir, newName);
    *pName = newName;
    *pSeq = seq = nibLoadAllMasked(NIB_MASK_MIXED, fileName);
    *pStrand = strand;
    if (strand == '-')
        reverseComplement(seq->dna, seq->size);
    uglyf("Loaded %d bases in %s\n", seq->size, fileName);
    }
}
Example #16
0
void fakeChromLinkage(char *database, char *chrom, FILE *f)
/* Generate fake linkage data for one chromosome */
{
int size = hdbChromSize(database, chrom);
int stepSize = 5000000;
int pos;
uglyf("faking %s %d\n", chrom, size);
struct sqlConnection *conn = hAllocConn();
for (pos=0; pos<size; pos += stepSize)
    {
    int rowOffset = 0;
    char query[512];
    sqlSafef(query, sizeof(query), "select name from stsMap where chrom='%s' and chromStart >= %d && chromStart < %d", chrom, pos, pos+stepSize);
    struct sqlResult *sr = sqlGetResult(conn, query);
    char **row = sqlNextRow(sr);
    if (row != NULL)
        {
	double x;
	if (rand()%250 == 0)
	    {
	    x = 3.5 + (double)rand()/RAND_MAX;
	    }
	else
	    {
	    x = (double)rand() / RAND_MAX + 0.001;
	    x = log(x) + 1;
	    if (x < -1)
	       x = -1;
	    }
        fprintf(f, "%s\t%f\n", row[0], x);
	}
    sqlFreeResult(&sr);
    }
hFreeConn(&conn);
}
Example #17
0
static void getCloneDna(struct clone *clone, struct hash *fragHash)
/* Read in clone DNA from file in format with one record per
 * clone contig.   Make clone->dna so that it is same as
 * non-fragmented clone file. */
{
struct dnaSeq *seqList = faReadAllDna(clone->faFile), *seq;
int fragSize;
clone->dna = needLargeMem(clone->size+1);
clone->dna[clone->size] = 0;
uglyf("GetCloneDna %s\n", clone->faFile);
for (seq = seqList; seq != NULL; seq = seq->next)
    {
    struct frag *frag = hashFindVal(fragHash, seq->name);
    if (frag == NULL)
        errAbort("Couldn't find %s from %s in trans files", seq->name, clone->faFile);
    assert(frag->end <= clone->size);
    fragSize = frag->end - frag->start;
    assert(fragSize >= 0);
    if (fragSize != seq->size)
        errAbort("Size mismatch (%d vs %d) between trans and .ffa files on %s", 
		fragSize, seq->size, frag->name);
    memcpy(clone->dna + frag->start,  seq->dna,  fragSize);
    }
freeDnaSeqList(&seqList);
}
Example #18
0
void doItPromoterBed(struct inInfo *in, struct bed *chiaList, double *out1, double *out2)
/* Process overlaps with promoters defined by a gene bed file. */
{
struct genomeRangeTree *grt = grtFromOpenBed(in->lf, 12, TRUE);
outputOverlappingGrt(chiaList, grt, out1, out2);
uglyf("done %s\n", in->fileName);
}
void testDbSorts(struct htmlPage *dbPage, char *org, char *db, 
	char *accColumn, struct slName *geneList)
/* Test on one database. */
{
struct htmlPage *emptyConfig;
struct htmlFormVar *sortVar = htmlFormVarGet(dbPage->forms, orderVarName);
struct slName *gene, *sort;

uglyf("testDbSorts %s %s\n", org, db);
if (sortVar == NULL)
    errAbort("Couldn't find var %s", orderVarName);

emptyConfig = emptyConfigPage(dbPage, org, db);
if (emptyConfig != NULL)
    {
    for (sort = sortVar->values; sort != NULL; sort= sort->next)
	{
	for (gene = geneList; gene != NULL; gene = gene->next)
	    {
	    testSort(emptyConfig, org, db, sort->name, gene->name, accColumn);
	    }
	}
    htmlPageFree(&emptyConfig);
    }
}
Example #20
0
char *cellAbbreviation(char *cell)
/* Return abbreviated version of cell-name */
{
if (cellLetterHash == NULL)
    return cellAbbrevDefault(cell, FALSE);

if (noLetterOk)
    {
    // strip qualifiers (follow the '+' char)
    char *plus = stringIn("+", cell);
    if (plus)
        *plus = 0;
    }
char *val = hashFindVal(cellLetterHash, cell);
if (val != NULL)
    return val;

if (noLetterOk)
    return cellAbbrevDefault(cell, TRUE);

if (noLetter)
    uglyf("cell %s isn't in %s\n", cell, cellLetter);
else
    errAbort("cell %s isn't in %s\n", cell, cellLetter);
return NULL;
}
Example #21
0
struct fullExperiment *getGoodExperiments(struct sqlConnection *conn, struct edwExperiment *eeList,
    char *assembly)
/* Get list of experiments that are good in the sense of being replicated and having
 * bam,broadPeak and so forth all from hotspot  in the same run */
{
uglyf("Got %d on eeList\n", slCount(eeList));
struct fullExperiment *fullList = getFullExperimentList(conn, eeList, assembly, NULL);
uglyf("Got %d on fullList\n", slCount(fullList));
int replicatedCount = 0, goodCount = 0, goodIndividualRepCount = 0, totalRepCount = 0;
struct fullExperiment *full, *next, *goodList = NULL, *badList = NULL;
for (full = fullList; full != NULL; full = next)
     {
     next = full->next;
     int repCount = slCount(full->repList);
     totalRepCount += repCount;
     if (repCount > 0)
         {
	 uglyf("%s %d\n", full->exp->accession, repCount);
	 if (repCount > 1)
	     ++replicatedCount;
	 int goodRepCount = 0;
	 struct replicate *r;
	 for (r = full->repList; r != NULL; r = r->next)
	     {
	     if (replicateIsComplete(conn, r))
	         {
		 ++goodRepCount;
		 ++goodIndividualRepCount;
		 }
	     }
	 if (goodRepCount >= 2)
	     {
	     ++goodCount;
	     slAddHead(&goodList, full);
	     }
         else
	     slAddHead(&badList, full);
	 }
     }
slReverse(&goodList);
uglyf("%d replicates %d are good\n", totalRepCount, goodIndividualRepCount);
uglyf("%d replicated experiments,  %d of which look good\n", replicatedCount, goodCount);

return goodList;
}
Example #22
0
void chopFaLines(char *inName, char *outName)
/* chopFaLines - Read in FA file with long lines and rewrite it with shorter lines. */
{
FILE *in = mustOpen(inName, "r");
FILE *out = mustOpen(outName, "w");
char *commentLine;
struct dnaSeq *seq;

while (faReadNext(in, NULL, TRUE, &commentLine, &seq))
    {
    commentLine = trimSpaces(commentLine+1);
    uglyf(">%s\n", commentLine);
    mustWrite(uglyOut, seq->dna, 100);
    uglyf("\n");
    uglyAbort("All for now");
    faWriteNext(out, commentLine, seq->dna, seq->size);
    }
}
Example #23
0
double paranoidSqrt(double x)
/* There seems to be a bug in MS's square-root that enclosing it in
 * a subroutine avoids. */
{
double y = sqrt(x);
if (fabs(y*y - x) > 0.001)
    uglyf("sqrt(%f) = %f !?? \n", x, y);
return y;
}
Example #24
0
void setupHugeGaps(char *insertFile)
/* Setup things to lookup gaps. */
{
struct lineFile *lf;
char *words[8];
int wordCount;
struct chromGaps *chromList = NULL, *cg;
struct hugeGap *gap;
char *chrom;
char query[512];
struct sqlResult *sr;
char **row;
struct ctgPos ctgPos;
int start, size;
struct hashEl *hel;
struct sqlConnection *conn = sqlConnect("hg4");

hugeHash = newHash(6);
lf = lineFileOpen(insertFile, TRUE);
while ((wordCount = lineFileChop(lf, words)) != 0)
     {
     chrom = words[0];
     if (sameString(words[2], "-"))
         continue;
     if ((cg = hashFindVal(hugeHash, chrom)) == NULL)
         {
	 AllocVar(cg);
	 slAddHead(&chromList, cg);
	 hel = hashAdd(hugeHash, chrom, cg);
	 cg->chrom = hel->name;
	 }
     size = atoi(words[3]);
     sqlSafef(query, sizeof query, "select * from ctgPos where contig = '%s'", words[2]);
     sr = sqlGetResult(conn, query);
     if ((row = sqlNextRow(sr)) == NULL)
        errAbort("Couldn't find %s from %s in database", words[2], lf->fileName);
     ctgPosStaticLoad(row, &ctgPos);
     if (!sameString(chrom, ctgPos.chrom))
         errAbort("%s is in %s in database and %s in %s", ctgPos.contig, ctgPos.chrom,
	 	chrom, lf->fileName);
     start = ctgPos.chromStart;
     uglyf("%s %s (%d size %d) %s \n", chrom, words[1], start, size, words[2]);
     sqlFreeResult(&sr);

     AllocVar(gap);
     slAddHead(&cg->gapList, gap);
     gap->offset = start;
     gap->size = size;
     }
lineFileClose(&lf);
sqlDisconnect(&conn);
for (cg = chromList; cg != NULL; cg = cg->next)
    {
    slSort(&cg->gapList, cmpHugeGap);
    }
}
Example #25
0
struct hash *hashPsls(char *fileName)
/* Return hash of all psls in file. */
{
struct psl *pslList = pslLoadAll(fileName), *psl;
struct hash *hash = newHash(20);
for (psl = pslList; psl != NULL; psl = psl->next)
    hashAdd(hash, psl->qName, psl);
uglyf("Loaded %d psls from %s\n", slCount(pslList), fileName);
return hash;
}
void constraintsForBac(char *bacAcc, char *outDir)
/* Generate a set of constraint files for bac. */
{
struct ggMrnaInput *ci = ggGetMrnaForBac(bacAcc);
struct ggMrnaCluster *mc, *mcList = ggClusterMrna(ci);
struct geneGraph *gg;

uglyf("Got %d clusters\n", slCount(mcList));
for (mc = mcList; mc != NULL; mc = mc->next)
    {
    uglyf("Initial input\n");
    dumpMc(mc);
    uglyf("\n");
    gg = ggGraphCluster(mc, ci);
    uglyf("Constraints\n");
    traverseGeneGraph(gg, mc->tStart, mc->tEnd, dumpGgAliInfo);
    uglyf("\n\n");
    }
}
Example #27
0
struct memGfx *getScaledMg(int bases, int height)
/* Allocate a memGfx big enough for bases. */
{
int width = baseToDot(bases);
struct memGfx *mg;
uglyf("Allocatting memory graphic of %d x %d (for %d bases)\n", width, height, bases);
mg = mgNew(width, height);
mgClearPixels(mg);
return mg;
}
Example #28
0
void gifTest()
{
static char *labels[] = {"cerebellum", "thymus", "breast", "heart",
			 "stomach", "cartilage", "kidney", "liver",
			 "lung", "testis", "black hole" };
int size = gifLabelMaxWidth(labels, ArraySize(labels));
int gifLabelMaxWidth(char **labels, int labelCount)
gifLabelVerticalText("../trash/foo.gif", labels, ArraySize(labels), size);
uglyf("<IMG SRC=\"../trash/foo.gif\">");
}
Example #29
0
void spanRaft(char *spanFile, char *raftFile, char *outFile)
/* spanRaft - combine James Gilbert's phrap derived
 * .span files with ooGreedy raft files ease comparison. */
{
struct span *spanList = NULL, *span;
struct spanFrag *sf;
struct raft *raftList = NULL, *raft;
struct raftFrag *rf;
struct hash *fragHash = newHash(0);

spanList = readSpanFile(spanFile);
printf("Got %d spans\n", slCount(spanList));
raftList = readRaftFile(raftFile);
printf("Got %d rafts\n", slCount(raftList));
printf("Got %d non-singleton rafts\n", multiRaftCount(raftList));
matchFrags(raftList, spanList, fragHash);
uglyf("Matched frags\n");
writeFrags(raftList, spanList, outFile);
uglyf("All done\n");
}
Example #30
0
void printListVals(struct sageCounts *scList, int index)
{
struct sageCounts *sc = NULL;
struct sortable *s=NULL, *sList = NULL, *next = NULL;
for(sc = scList; sc != NULL; sc = sc->next)
    {
    AllocVar(s);
    s->val = sc->expCounts[index];
    slAddHead(&sList,s);
    }
slSort(&sList,compSortable);
for(s = sList; s!= NULL; s=s->next)
    uglyf("%d,",s->val);
uglyf("\n");
for(s=sList; s != NULL; s = next)
    {
    next = s->next;
    freez(&s);
    }
}