static void convertToPsl(struct mafComp *qc, struct mafComp *tc, FILE *pslFh)
/* convert two components to a psl */
{
struct psl* psl;
int qStart = qc->start;
int qEnd = qc->start+qc->size;
int tStart = tc->start;
int tEnd = tc->start+tc->size;
char strand[3];
strand[0] = qc->strand;
strand[1] = tc->strand;
strand[2] = '\0';

    
if (qc->strand == '-')
    reverseIntRange(&qStart, &qEnd, qc->srcSize);
if (tc->strand == '-')
    reverseIntRange(&tStart, &tEnd, tc->srcSize);

psl = pslFromAlign(skipDot(qc->src), qc->srcSize, qStart, qEnd, qc->text,
                   skipDot(tc->src), tc->srcSize, tStart, tEnd, tc->text,
                   strand, 0);
if (psl != NULL)
    {
    /* drop target strand */
    if (psl->strand[1] == '-')
        pslRc(psl);
    psl->strand[1] = '\0';
    pslTabOut(psl, pslFh);
    }
}
Ejemplo n.º 2
0
void bigPslToPsl(char *bigPslName, char *outputName)
/* bigPslToPsl - convert bigPsl file to psle. */
{
struct bbiFile *bbi = bigBedFileOpen(bigPslName);
struct lm *lm = lmInit(0);
FILE *f = mustOpen(outputName, "w");
struct bbiChromInfo *chrom, *chromList = bbiChromList(bbi);
for (chrom = chromList; chrom != NULL; chrom = chrom->next)
    {
    int start = 0, end = chrom->size;
    int itemsLeft = 0;
    char *chromName = chrom->name;

    struct bigBedInterval  *bbList = bigBedIntervalQuery(bbi, chromName,
            start, end, itemsLeft, lm);
    
    for(; bbList; bbList = bbList->next)
        {
        struct psl *psl, *pslList = pslFromBigPsl(chromName, bbList, NULL, NULL);

        for(psl=pslList; psl; psl = psl->next)
            {
            if (collapseStrand && (psl->strand[1] == '+'))
                psl->strand[1] = 0;
            pslTabOut(psl, f);
            }
        }
    }
}
void outputChunk(struct psl **pPslList, char *tempDir, int midIx, boolean noHead)
/* Sort and write out pslList and free it. */
{
char fileName[512];
FILE *f;
struct psl *psl;

if (*pPslList == NULL)
    return; 	/* Empty. */
psl = *pPslList;
//slSort(pPslList, pslCmpTarget);
makeMidName(tempDir, midIx, fileName);
if (stripVer)
    {
    char *s = stringIn(".",psl->qName);
    if (s != NULL)
        *s = 0;
    }
if (chunkSize ==1)
    safef(fileName, sizeof(fileName), "%s/%s.psl",tempDir,psl->qName);
f = mustOpen(fileName, "w");
if (!noHead)
    pslWriteHead(f);
for (psl = *pPslList; psl != NULL; psl = psl->next)
    pslTabOut(psl, f);
fclose(f);
pslFreeList(pPslList);
}
Ejemplo n.º 4
0
void copyPslToTab(char *pslFile, char *tabFile)
/* copy a single PSL to the tab file */
{
struct psl *psl;
struct lineFile *lf = pslFileOpen(pslFile);
struct pipeline *pl = NULL;
FILE *tabFh = NULL;
if (noSort)
    tabFh = mustOpen(tabFile, "w");
else
    {
    if (pslCreateOpts & PSL_WITH_BIN)
	pl = pipelineOpen(outPipeBin, pipelineWrite, tabFile, NULL);
    else
	pl = pipelineOpen(outPipeNoBin, pipelineWrite, tabFile, NULL);
    tabFh = pipelineFile(pl);
    }
while ((psl = pslNext(lf)) != NULL)
    {
    if (pslCreateOpts & PSL_WITH_BIN)
        fprintf(tabFh, "%u\t", hFindBin(psl->tStart, psl->tEnd));
    pslTabOut(psl, tabFh);
    pslFree(&psl);
    }
lineFileClose(&lf);
if (noSort)
    carefulClose(&tabFh);
else
    {
    pipelineWait(pl);
    pipelineFree(&pl);
    }
}
Ejemplo n.º 5
0
void migratePsl(struct migrateAligns* migrate, unsigned pslFileType,
                struct gbEntryCnts* counts, struct psl* psl,
                char* inPsl, FILE* outPslFh)
/* Migrate PSL, if it's accession and version are flagged */
{
struct gbAligned* aligned = getMigrateAligned(migrate, psl->qName, inPsl);
if (aligned != NULL)
    {
    pslTabOut(psl, outPslFh);

    if (pslFileType == MAIN_PSL_FILE)
        {
        /* count main psls in index. */
        gbAlignedCount(aligned, 1);
        /* increment accession count if this is the first one */
        gbCountNeedAligned(counts, aligned->entry,
                           ((aligned->numAligns == 1) ? 1 : 0), 1);
        }
    else
        {
        /* for rawPsl and intronPsl only count PSLs */
        gbCountNeedAligned(counts, aligned->entry, 0, 1);
        }
    if (gbVerbose >= 3)
        gbVerbPr(3, "migrating %s %s %s",
                 gbOrgCatName(aligned->entry->orgCat), 
                 gPslFileExt[pslFileType], psl->qName);
    }
}
Ejemplo n.º 6
0
void copyPsl(struct gbSelect* select, unsigned pslFileType,
             struct psl* psl, char* inPsl,
             FILE* outPslFh, struct gbEntryCnts* counts)
/* Copy a PSL. */
{
char acc[GB_ACC_BUFSZ];
int version = gbSplitAccVer(psl->qName, acc);
struct gbAligned* aligned;
struct gbEntry* entry = getEntry(select, acc, inPsl);
if (entry == NULL)
    errAbort("no entry for %s %s in %s", gPslFileExt[pslFileType],
             psl->qName, inPsl);
aligned = gbEntryGetAligned(entry, select->update, version, NULL);
pslTabOut(psl, outPslFh);
if (pslFileType == MAIN_PSL_FILE)
    {
    /* count main psls in index. */
    gbAlignedCount(aligned, 1);
    /* increment accession count if this is * the first one */
    gbCountNeedAligned(counts, entry,
                           ((aligned->numAligns == 1) ? 1 : 0), 1);
    }
else
    {
    /* for rawPsl and intronPsl only count PSLs */
    gbCountNeedAligned(counts, entry, 0, 1);
    }
if (gbVerbose >= 3)
    gbVerbPr(3, "installing %s %s %s.%d", gbOrgCatName(entry->orgCat),
             gPslFileExt[pslFileType], acc, version);
}
Ejemplo n.º 7
0
void pslRecalcMatch(char *inName, char *targetName, char *queryName, 
	char *outName)
/* pslRecalcMatch - Recalculate match,mismatch,repMatch columns in psl file.  
 * This can be useful if the psl went through pslMap, or if you've added 
 * lower-case repeat masking after the fact. */
{
struct nibTwoCache *tCache = nibTwoCacheNew(targetName);
struct dnaSeq *qSeqList = dnaLoadAll(queryName);
struct hash *qHash = dnaSeqHash(qSeqList);
struct psl *psl;
struct lineFile *lf = pslFileOpen(inName);
FILE *f = mustOpen(outName, "w");

while ((psl = pslNext(lf)) != NULL)
    {
    int tSize;
    struct dnaSeq *tSeqPart = nibTwoCacheSeqPart(tCache,
    	psl->tName, psl->tStart, psl->tEnd - psl->tStart, &tSize);
    struct dnaSeq *qSeq = hashMustFindVal(qHash, getQName(psl->qName));
    recalcMatches(psl, tSeqPart, psl->tStart, qSeq);
    pslTabOut(psl, f);
    dnaSeqFree(&tSeqPart);
    }
carefulClose(&f);
lineFileClose(&lf);
}
void pslIntronsOnly(char *inPslName, char *genoFile, char *outPslName)
/* pslIntronsOnly - Filter psl files to only include those with introns. */
{
struct lineFile *lf = NULL;
FILE *outFile = NULL;
struct hash *genoHash = loadGeno(genoFile);
struct psl *psl;
int count = 0, intronCount = 0;

lf = pslFileOpen(inPslName);
outFile = mustOpen(outPslName, "w");
while ((psl = pslNext(lf)) != NULL)
    {
    struct dnaSeq *geno = hashMustFindVal(genoHash, psl->tName);
    if (pslHasIntron(psl, geno, 0))
        {
	++intronCount;
	pslTabOut(psl, outFile);
	}
    pslFree(&psl);
    ++count;
    }
carefulClose(&outFile);
lineFileClose(&lf);
printf("%d of %d in %s have introns\n", intronCount, count, inPslName);
}
Ejemplo n.º 9
0
void pslCut(char *cutList, char *inPsl, char *outPsl)
/* pslCut - Remove a list of clones from psl file.. */
{
struct hash *cutHash = newHash(0);
struct lineFile *lf = pslFileOpen(inPsl);
FILE *f = mustOpen(outPsl, "w");
struct psl *psl;
char cloneName[128];
int total = 0, cut = 0;

buildCutHash(cutList, cutHash);
pslWriteHead(f);
while ((psl = pslNext(lf)) != NULL)
    {
    fragToCloneName(psl->tName, cloneName);
    if (!hashLookup(cutHash, cloneName))
	{
        pslTabOut(psl, f);
	}
    else
        ++cut;
    ++total;
    pslFree(&psl);
    }
printf("Cut %d of %d\n", cut, total);
}
Ejemplo n.º 10
0
void axtToPsl(char *inName, char *tSizeFile, char *qSizeFile, char *outName)
/* axtToPsl - Convert axt to psl format. */
{
struct hash *tSizeHash = readSizes(tSizeFile);
struct hash *qSizeHash = readSizes(qSizeFile);
struct lineFile *lf = lineFileOpen(inName, TRUE);
char strand[2];
FILE *f = mustOpen(outName, "w");
struct psl* psl;
struct axt *axt;
strand[1] = '\0';

while ((axt = axtRead(lf)) != NULL)
    {
    int qSize = findSize(qSizeHash, axt->qName);
    int qStart =  axt->qStart;
    int qEnd = axt->qEnd;
    if (axt->qStrand == '-')
        reverseIntRange(&qStart, &qEnd, qSize);
    strand[0] = axt->qStrand;
    psl = pslFromAlign(axt->qName, qSize, qStart, qEnd, axt->qSym, 
                       axt->tName, findSize(tSizeHash, axt->tName),
                       axt->tStart, axt->tEnd, axt->tSym, strand,
                       PSL_IS_SOFTMASK);
    if (psl != NULL)
	{
	pslTabOut(psl, f);
	pslFree(&psl);
	}
    axtFree(&axt);
    }
lineFileClose(&lf);
carefulClose(&f);
}
void pslCopyInClones(char *listFile, char *partDir, char *outName)
/* Copy in the .psl files corresponding to the clones named in listFile. */
{
struct slName *inList, *inEl;
FILE *out = mustOpen(outName, "w");
struct psl *psl;
int pslCount = 0;
int fileCount = 0;

pslWriteHead(out);
inList = getFileList(listFile, partDir);
for (inEl = inList; inEl != NULL; inEl = inEl->next)
    {
    char *inName = inEl->name;
    struct lineFile *lf = pslFileOpen(inName);
    ++fileCount;
    while ((psl = pslNext(lf)) != NULL)
	{
	pslTabOut(psl, out);
	pslFree(&psl);
	++pslCount;
	}
    lineFileClose(&lf);
    }
printf("%d psls in %d files written to %s\n", pslCount, fileCount, outName);
fclose(out);
}
Ejemplo n.º 12
0
static void cnvGenePred(struct hash *chromHash, struct genePred *gp, FILE *pslFh, FILE *cdsFh)
/* convert a genePred to a psl and CDS */
{
int chromSize = hashIntValDefault(chromHash, gp->chrom, 0);
if (chromSize == 0)
    errAbort("Couldn't find chromosome/scaffold '%s' in chromInfo", gp->chrom);
int e = 0, qSize=0;

for (e = 0; e < gp->exonCount; ++e)
    qSize+=(gp->exonEnds[e] - gp->exonStarts[e]);
struct psl *psl = pslNew(gp->name, qSize, 0, qSize,
                         gp->chrom, chromSize, gp->txStart, gp->txEnd,
                         gp->strand, gp->exonCount, 0);
psl->blockCount = gp->exonCount;		    
for (e = 0; e < gp->exonCount; ++e)
    {
    psl->blockSizes[e] = (gp->exonEnds[e] - gp->exonStarts[e]);
    psl->qStarts[e] = e==0 ? 0 : psl->qStarts[e-1] + psl->blockSizes[e-1];
    psl->tStarts[e] = gp->exonStarts[e];
    }
psl->match = qSize;	
psl->tNumInsert = psl->blockCount-1; 
psl->tBaseInsert = (gp->txEnd - gp->txStart) - qSize;
pslTabOut(psl, pslFh);
pslFree(&psl);
if (gp->cdsStart < gp->cdsEnd)
    cnvGenePredCds(gp, qSize, cdsFh);
}
void readTableTask(char *db, char *table)
/* Implements the readTable task */
{
FILE *outFh = NULL;
struct sqlConnection *conn = sqlConnect(db);
struct pslReader* pr = pslReaderQuery(conn, table, gWhere);
struct psl* psl;
int numRows = 0;

if (gOutput != NULL)
    outFh = mustOpen(gOutput, "w");

while ((numRows < gMaxRows) && ((psl = pslReaderNext(pr)) != NULL))
    {
    if (outFh != NULL)
        pslTabOut(psl, outFh);
    pslFree(&psl);
    numRows++;
    }

carefulClose(&outFh);
pslReaderFree(&pr);

sqlDisconnect(&conn);
checkNumRows(table, numRows);
}
Ejemplo n.º 14
0
static void chainToLongest(struct psl** queryPsls,
                           FILE* outPslFh)
/* pull off one or more psls from the list and chain them */
{
struct psl* chainedPsl = slPopHead(queryPsls);
struct psl* unchainedPsls = NULL;  // ones not included
struct psl* nextPsl;
while ((nextPsl = slPopHead(queryPsls)) != NULL)
    {
    int insertIdx = findChainPoint(chainedPsl, nextPsl);
    if (insertIdx >= 0)
        {
        addPslToChained(chainedPsl, nextPsl, insertIdx);
        pslFree(&nextPsl);
        }
    else
        {
        slAddHead(&unchainedPsls, nextPsl);
        }
    }
pslComputeInsertCounts(chainedPsl);
pslTabOut(chainedPsl, outPslFh);
pslFree(&chainedPsl);
slReverse(&unchainedPsls); // preserve longest to shortest order
*queryPsls = unchainedPsls;
}
Ejemplo n.º 15
0
void pslUnpile(char *inName, char *outName)
/* pslUnpile - Removes huge piles of alignments from sorted 
 * psl files (due to unmasked repeats presumably).. */
{
FILE *f = mustOpen(outName, "w");
enum gfType qType, tType;
struct lineFile *lf;
struct psl *list = NULL, *psl, *el;

pslxFileOpen(inName, &qType, &tType, &lf);
if (!noHead)
    pslxWriteHead(f, qType, tType);
for (;;)
    {
    psl = pslNext(lf);
    if (list != NULL && (psl == NULL || !pslOverlap(psl, list)))
        {
	if (list != NULL)
	    {
	    slReverse(&list);
	    if (checkPile(list))
	        {
		for (el = list; el != NULL; el = el->next)
		    {
		    pslTabOut(el, f);
		    }
		}
	    else
	        {
		for (el = list; el != NULL; el = el->next)
		    {
		    if (psl == NULL)
			pslTabOut(el, f);
		    else if (psl->tEnd - psl->tStart > 4000)
			pslTabOut(el, f);
		    }
		}
	    pslFreeList(&list);
	    }
	}
    if (psl == NULL)
        break;
    slAddHead(&list, psl);
    }
lineFileClose(&lf);
carefulClose(&f);
}
Ejemplo n.º 16
0
static void outputPsl(struct blastBlock *bb, unsigned flags, struct psl *psl,
                      FILE* pslFh, FILE* scoreFh)
/* output a psl and optional score */
{
pslTabOut(psl, pslFh);
if (scoreFh != NULL)
    pslBuildScoresWrite(scoreFh, psl, bb->bitScore, bb->eVal);
pslCheck("blastToPsl", stderr, psl);
}
Ejemplo n.º 17
0
void fastaToPsl(char *inName, char *outName)
/* fastaToPsl - Convert axt to psl format. */
{
struct lineFile *inLF;
FILE *outFh;
boolean read;
struct psl* pslAlign;

DNA *qSeq;
int qSize;
int qSeqLen;
char *qHeader;

DNA *tSeq;
int tSize;
int tSeqLen;
char *tHeader;

int queryCounter;

inLF  = lineFileOpen(inName, TRUE);
outFh = mustOpen(outName, "w");

/* read the target sequence */
read = faMixedSpeedReadNext(inLF, &qSeq, &qSize, &qHeader);
if (!read)
    errAbort("Could not read target FASTA entry.");
qSeq    = cloneString(qSeq);
qSeqLen = countNonDash(qSeq, qSize);
qHeader = cloneString(qHeader);
verbose(2, "Query sequence header: %s\n", qHeader);
verbose(3, "Query sequence alignment length: %d\n", qSize);
verbose(3, "Query sequence length: %d\n", qSeqLen);
verbose(4, "Query sequence: %s\n", qSeq);

/* read the rest of the sequences */
queryCounter = 1;
pslWriteHead(outFh);
while (faMixedSpeedReadNext(inLF, &tSeq, &tSize, &tHeader))
    {
    tSeqLen = countNonDash(tSeq, tSize);

    verbose(2, "Target sequence (%d) header: %s\n", queryCounter, tHeader);
    verbose(3, "Target sequence (%d) length: %d\n", queryCounter, tSeqLen);
    verbose(4, "Target sequence (%d): %s\n", queryCounter, tSeq);

    pslAlign = pslFromAlign(qHeader, qSeqLen, 0, qSeqLen, qSeq,
                            tHeader, tSeqLen, 0, tSeqLen, tSeq,
                            "+", 0);
    pslTabOut(pslAlign, outFh);

    ++queryCounter;
    }

lineFileClose(&inLF);
}
Ejemplo n.º 18
0
/* convert one line read from a bed file to a PSL */
void cnvBedRec(char *line, struct hash *chromSizes, FILE *pslFh)
{
char *row[12];
int numCols = chopByWhite(line, row, ArraySize(row));
if (numCols < 4)
    errAbort("bed must have at least 4 columns");
struct bed *bed = bedLoadN(row, numCols);
struct psl* psl = bedToPsl(bed, chromSizes);
pslTabOut(psl, pslFh);
pslFree(&psl);
bedFree(&bed);
}
Ejemplo n.º 19
0
static void processPsl(FILE *fh, struct hash *refSeqVerInfoTbl, struct psl *psl)
/* check if a psl has been select, if so, write including version in qName */
{
struct refSeqVerInfo *rsvi = hashFindVal(refSeqVerInfoTbl, psl->qName);
if (rsvi != NULL)
    {
    char buf[GENBANK_ACC_BUFSZ], *hold = psl->qName;
    psl->qName = addVer(psl->qName, rsvi->ver, buf, sizeof(buf));
    pslTabOut(psl, fh);
    psl->qName = hold;
    }
}
Ejemplo n.º 20
0
static void mapToRefWithMapping(struct hapRegions *hr, struct cDnaAlign *hapAln, struct psl *mapping, struct psl **mappedHaps)
/* map an alignment on a haplotype chromosome using one mapping */
{
    struct psl *m;
    struct psl *mapped = pslTransMap(pslTransMapNoOpts, hapAln->psl, mapping);
    while ((m = slPopHead(&mapped)) != NULL)
    {
        slAddHead(&mappedHaps, m);
        if (hr->hapRefMappedFh != NULL)
            pslTabOut(m, hr->hapRefMappedFh);
    }
}
Ejemplo n.º 21
0
void pslListFromGenePred(char *chromSizesFile, struct genePred *gpList, FILE *out) 
{
struct hash *chromSizes = getChromSizes(chromSizesFile);
struct genePred *gp = NULL;
struct psl *psl=NULL;
for(gp=gpList; gp != NULL; gp=gp->next)
    {
    int size = hashIntVal(chromSizes, gp->chrom);
    psl = pslFromGenePred(gp, size);
    pslTabOut(psl, out);
    }
hashFree(&chromSizes);
}
Ejemplo n.º 22
0
static void cnvGenePred(struct hash *chromHash, struct genePred *gp, FILE *pslFh, FILE *cdsFh)
/* convert a genePred to a psl and CDS */
{
int chromSize = hashIntValDefault(chromHash, gp->chrom, 0);
if (chromSize == 0)
    errAbort("Couldn't find chromosome/scaffold '%s' in chromInfo", gp->chrom);
int qSize = 0;
if (qSizes != NULL)
    qSize = hashIntValDefault(qSizeHash, gp->name, 0);
struct psl *psl = genePredToPsl(gp, chromSize, qSize);
pslTabOut(psl, pslFh);
pslFree(&psl);
if (gp->cdsStart < gp->cdsEnd)
    cnvGenePredCds(gp, qSize, cdsFh);
}
static void mapPslPair(struct psl *inPsl, struct mapAln *mapAln,
                       FILE* outPslFh, FILE *mapInfoFh, FILE *mappingPslFh)
/* map one pair of query and target PSL */
{
struct psl* mappedPsl;
if (inPsl->tSize != mapAln->psl->qSize)
    errAbort("Error: inPsl %s tSize (%d) != mapping alignment %s qSize (%d) (perhaps you need to specify -swapMap?)\n",
             inPsl->tName, inPsl->tSize, mapAln->psl->qName, mapAln->psl->qSize);

mappedPsl = pslTransMap(mapOpts, inPsl, mapAln->psl);

/* only output if blocks were actually mapped */
if (mappedPsl != NULL)
    {
    if (suffix != NULL)
        addQNameSuffix(mappedPsl);
    pslTabOut(mappedPsl, outPslFh);
    if (mapInfoFh != NULL)
        writeMapInfo(mapInfoFh, inPsl, mapAln, mappedPsl);
    if (mappingPslFh != NULL)
        pslTabOut(mapAln->psl, mappingPslFh);
    }
pslFree(&mappedPsl);
}
static void pslLiftSubrangeBlat(char *inPsl, char *outPsl, char *qSizesFile, char *tSizesFile)
/* pslLiftSubrangeBlat - lift PSLs from blat subrange alignments. */
{
struct hash *qSizes = (qSizesFile != NULL) ? loadSizes(qSizesFile) : NULL;
struct hash *tSizes = (tSizesFile != NULL) ? loadSizes(tSizesFile) : NULL;
struct pslReader *inRd = pslReaderFile(inPsl, NULL);
FILE *outFh = mustOpen(outPsl, "w");
struct psl *psl;
while ((psl = pslReaderNext(inRd)) != NULL)
    {
    liftIt(psl, qSizes, tSizes);
    pslTabOut(psl, outFh);
    pslFree(&psl);
    }
carefulClose(&outFh);
pslReaderFree(&inRd);
}
Ejemplo n.º 25
0
void outputAlignmentForStan(struct sqlConnection *conn, struct stanMad *sm, struct hash *iHash, FILE *out)
{
struct psl *pslList, *bestPsl = NULL;
char buff[1024];
int i;
struct imageClone *ic = NULL;
sprintf(buff, "%d", sm->clid);
printf("Looking for %s\n", buff);
ic = hashFindVal(iHash, buff);
if(ic != NULL) 
    {
    /* first try looking for the image clones themselves... */
    for(i=0; i<ic->numGenbank; i++) 
	{
	char query[1024];
	sqlSafef(query, sizeof query, "select * from all_est where qName='%s'", ic->genbankIds[i]);
	pslList = pslLoadByQuery(conn, buff);
	if(pslList != NULL) 
	    {
	    slSort(&pslList, pslCmpScore);	
	    if(bestPsl == NULL || (pslScore(pslList) > pslScore(bestPsl)))
		pslFree(&bestPsl);
		bestPsl = copyPsl(pslList);
	    }
	
	pslFreeList(&pslList);
	}

    if(bestPsl != NULL)
	{    
	freez(&bestPsl->qName);
	sprintf(buff, "%d", sm->clid);
	bestPsl->qName = cloneString(buff);
	pslTabOut(bestPsl,out);
	}
    else 
	{
	fprintf(out, "%d\talignment unknown\n", sm->clid);
	}
    
    }
else 
    {
    fprintf(out, "%d\tunknown\n", sm->clid);
    }
}
Ejemplo n.º 26
0
void pslRcFile(char *inPslFile, char *outPslFile)
/* reverse target and query in a psl file */
{
struct lineFile *inLf = pslFileOpen(inPslFile);
FILE *outFh = mustOpen(outPslFile, "w");
struct psl *psl;

while ((psl = pslNext(inLf)) != NULL)
    {
    pslRc(psl);
    pslTabOut(psl, outFh);
    pslFree(&psl);
    }

carefulClose(&outFh);
lineFileClose(&inLf);
}
Ejemplo n.º 27
0
void protDat(char *protName, char *blatName, char *aliasFile, char *outName)
{
FILE *outFile = mustOpen(outName, "w");
struct hash *protHash = newHash(10);
struct hash *blatHash = newHash(10);
struct hash *aliasHash = newHash(10);
struct psl *psls, *pslPtr, *protPsls, *blatPsl;
struct lineFile *lf = lineFileOpen(aliasFile, TRUE);
struct alias *alPtr;
char buffer[1024];
char *words[3];
int numWords = optionExists("fb") ? 2 : 3;

while (lineFileNextRow(lf, words, numWords))
    {
    AllocVar(alPtr);
    alPtr->kgName = cloneString(words[1]);
    if (numWords == 3)
	alPtr->spName = cloneString(words[2]);
    hashAdd(aliasHash, cloneString(words[0]), alPtr);
    }

protPsls = pslLoadAll(protName);

pslPtr = psls = pslLoadAll(blatName);
for(; pslPtr; pslPtr = pslPtr->next)
    hashAdd(blatHash, pslPtr->qName, pslPtr);

for(pslPtr = protPsls; pslPtr; pslPtr = pslPtr->next)
    {
    if ((blatPsl = hashFindVal(blatHash, pslPtr->qName)) != NULL)
	{
	if ((alPtr = hashFindVal(aliasHash, pslPtr->qName)) != NULL)
	    {
	    if (numWords == 3)
		sprintf(buffer,"%s.%s:%d-%d.%s.%s",pslPtr->qName,blatPsl->tName, 
		    blatPsl->tStart, blatPsl->tEnd,alPtr->kgName, alPtr->spName); 
	    else
		sprintf(buffer,"%s.%s:%d-%d.%s",pslPtr->qName,blatPsl->tName, 
		    blatPsl->tStart, blatPsl->tEnd,alPtr->kgName); 
	    pslPtr->qName = buffer;
	    pslTabOut(pslPtr, outFile);
	    }
	}
    }
}
Ejemplo n.º 28
0
void filterPrimersAndWrite(FILE *of, struct sts *sts)
/* Filter placements and write out to file */
{
  int bestScore = 1000;
  struct place *p = NULL;

  for (p = sts->place; p != NULL; p=p->next)
    if (p->badBits < bestScore)
	bestScore = p->badBits;

  for (p = sts->place; p != NULL; p=p->next)
    if ((p->badBits - bestScore) < 2)
      {
	pslTabOut(p->psl, of);
	sts->found = TRUE;
      }
}
Ejemplo n.º 29
0
void writePslFrags(struct psl *psl, FILE *f)
/* Look into psl and figure out if we want to write out
 * all or part of it. */
{
int i;
int totalSize = 0;
int size = pslBlockTotalSize(psl);

for (i=0; i<psl->blockCount; ++i)
    {
    if ((size = psl->blockSizes[i]) >= 30)
        {
	static struct psl p;
	unsigned blockSizes, qStarts, tStarts;
	p.match = roundingScale(psl->match, size, totalSize);
	p.misMatch = roundingScale(psl->misMatch, size, totalSize);
	p.repMatch = roundingScale(psl->repMatch, size, totalSize);
	p.nCount = roundingScale(psl->nCount, size, totalSize);
	p.strand[0] = psl->strand[0];
	p.strand[1] = psl->strand[1];
	p.qName = psl->qName;
	p.qSize = psl->qSize;
	p.tName =psl->tName;
	p.tSize = psl->tSize;
	p.blockCount = 1;
	p.blockSizes = &blockSizes;
	blockSizes = size;
	p.qStarts = &qStarts;
	qStarts = psl->qStarts[i];
	p.tStarts = &tStarts;
	tStarts = psl->tStarts[i];
	if (p.strand[0] == '-')
	    p.qStart = psl->qSize - (qStarts + size);
	else
	    p.qStart = qStarts;
	if (p.strand[1] == '-')
	    p.tStart = psl->tSize - (tStarts + size);
	else
	    p.tStart = tStarts;
	p.qEnd = p.qStart + size;
	p.tEnd = p.tStart + size;
	pslTabOut(&p, f);
	}
    }
}
Ejemplo n.º 30
0
void protPslToCdsPsl(struct psl *psl, char *qName, char *tName, FILE *f)
/* Given a protein/rna alignment, transform it to a cds/rna alignment.
 * This comes down to multiplying by three here and there.  This
 * routine will mess with the psl.  Don't reuse or free the PSL when done. */
{
psl->qSize *= 3;
psl->qStart *= 3;
psl->qEnd *= 3;
int i;
for (i=0; i<psl->blockCount; ++i)
    {
    psl->blockSizes[i] *= 3;
    psl->qStarts[i] *= 3;
    }
psl->qName = qName;
psl->tName = tName;
pslTabOut(psl, f);
}