Exemple #1
0
int pslCmpTargetScore(const void *va, const void *vb)
/* Compare to sort based on target then score. */
{
const struct psl *a = *((struct psl **)va);
const struct psl *b = *((struct psl **)vb);
int diff = cmpChrom(a->tName, b->tName);
if (diff == 0)
    diff = pslScore(b) - pslScore(a);
return diff;
}
Exemple #2
0
boolean findAndMapPsl(struct bed *bed, char *protAcc, struct hash *refPslHash, 
	int chromSize, FILE *f)
/* Find appropriate protein/mrna alignment in hash, and transmogrify it into fake alignment
 * between CDS of RNA and genome.  If this gets too hairy maybe we just have pslMap
 * do it instead. */
{
struct hashEl *el;
struct psl *matchPsl = NULL, *psl;
int bestScore = 0;
for (el = hashLookup(refPslHash, bed->name); el != NULL; el = hashLookupNext(el))
    {
    psl = el->val;
    if (sameString(protAcc, psl->qName))
        {
	int score = pslScore(psl);
	if (score > bestScore)
	    {
	    bestScore = score;
	    matchPsl = psl;
	    }
	}
    }
if (matchPsl == NULL)
    {
    verbose(2, "Could not find %s vs %s alignment\n", bed->name, protAcc);
    return FALSE;
    }
else
    {
    protPslToCdsPsl(matchPsl, bed->name, bed->name, f);
    return TRUE;
    }
}
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);
    }
}
Exemple #4
0
void pslToChain(char *pslIn, char *chainOut)
/* pslToChain - Extract multiple psl records. */
{
struct lineFile *lf = pslFileOpen(pslIn);
int chainId = 1;
int ii;
FILE *f = mustOpen(chainOut, "w");
struct psl *psl;
struct chain chain;

while ((psl = pslNext(lf) ) != NULL)
    {
    if (psl->strand[1] == '-') 
        {
        if (ignoreError)
            continue;
        errAbort("PSL record on line %d has '-' for target strand which is not allowed.", lf->lineIx);
        }

    chain.score = pslScore(psl);
    chain.id = chainId++;
    chain.tName = psl->tName;
    chain.tSize = psl->tSize;
    chain.tStart = psl->tStart;
    chain.tEnd = psl->tEnd;
    chain.qName = psl->qName;
    chain.qSize = psl->qSize;
    chain.qStrand = psl->strand[0];

    if (psl->strand[0] == '-')
        {
        chain.qEnd = psl->qSize - psl->qStart;
        chain.qStart = psl->qSize - psl->qEnd;
        }
    else
        {
        chain.qStart = psl->qStart;
        chain.qEnd = psl->qEnd;
        }
    chainWriteHead(&chain,f);

    for(ii=0; ii < psl->blockCount; ii++)
	{
	fprintf(f, "%d", psl->blockSizes[ii]);
	if (ii < psl->blockCount - 1)
	    fprintf(f, "\t%d\t%d", psl->tStarts[ii+1]-(psl->tStarts[ii] + psl->blockSizes[ii]),
		psl->qStarts[ii+1]-(psl->qStarts[ii] + psl->blockSizes[ii]));
	fprintf(f,"\n");
	}


    pslFree(&psl);
    }
}
void dropNotBest(struct psl **pslList)
/* Sorts list and drops any score less than the best score */
{
struct psl *tail = NULL;
int bestScore =0;
slSort(pslList, pslCmpScoreDesc);
if(pslList == NULL) 
    return;
bestScore = pslScore(*pslList);
for(tail=*pslList; tail != NULL; tail=tail->next)
    {
    if(tail->next == NULL)
	break;
    if(pslScore(tail->next) < bestScore)
	{
	struct psl *tmp = tail->next;
	tail->next = NULL;
	pslFreeList(&tmp);
	break;
	}
    }
}
Exemple #6
0
struct pslAli *createPslAli(struct psl *psl)
/* Create a pslAli element from a psl record */
{
  struct pslAli *pa;
  
  AllocVar(pa);
  pa->next = NULL;
  pa->psl = psl;
  pa->score = pslScore(psl);
  pa->id = (float)(psl->match + psl->repMatch + psl->nCount)/(psl->match + psl->misMatch + psl->repMatch + psl->nCount);
  pa->cov = (float)(psl->match + psl->misMatch + psl->repMatch + psl->nCount)/psl->qSize;
  return(pa);
}
Exemple #7
0
void processBestSingle(char *acc, struct psl *pslList, FILE *bestFile, FILE *repFile)
/* Find single best psl in list. */
{
struct psl *bestPsl = NULL, *psl;
int bestScore = 0, score, threshold;

for (psl = pslList; psl != NULL; psl = psl->next)
    {
    score = pslScore(psl);
    if (score > bestScore)
        {
	bestScore = score;
	bestPsl = psl;
	}
    }
threshold = round((1.0 - nearTop)*bestScore);
for (psl = pslList; psl != NULL; psl = psl->next)
    {
    if (pslScore(psl) >= threshold && passFilters(psl, NULL))
        pslTabOut(psl, bestFile);
    }
}
Exemple #8
0
void showAliPlaces(char *pslName, char *faName, char *database, 
		   enum gfType qType, enum gfType tType, 
		   char *organism, boolean feelingLucky)
/* Show all the places that align. */
{
struct lineFile *lf = pslFileOpen(pslName);
struct psl *pslList = NULL, *psl;
char *browserUrl = hgTracksName();
char *hgcUrl = hgcName();
char uiState[64];
char *vis;
char unhideTrack[64];
char *sort = cartUsualString(cart, "sort", sortList[0]);
char *output = cartUsualString(cart, "output", outputList[0]);
boolean pslOut = startsWith("psl", output);
boolean isStraightNuc = (qType == gftRna || qType == gftDna);
int  minThreshold = (isStraightNuc ? minMatchShown : 0);

sprintf(uiState, "%s=%s", cartSessionVarName(), cartSessionId(cart));

/* If user has hidden BLAT track, add a setting that will unhide the 
   track if user clicks on a browser link. */
vis = cartOptionalString(cart, "hgUserPsl");
if (vis != NULL && sameString(vis, "hide"))
    snprintf(unhideTrack, sizeof(unhideTrack), "&hgUserPsl=dense");
else
    unhideTrack[0] = 0;

while ((psl = pslNext(lf)) != NULL)
    {
    if (psl->match >= minThreshold)
	slAddHead(&pslList, psl);
    }
lineFileClose(&lf);
if (pslList == NULL)
    {
    puts("<table><tr><td><hr>Sorry, no matches found<hr><td></tr></table>");
    return;
    }

if (sameString(sort, "query,start"))
    {
    slSort(&pslList, pslCmpQuery);
    }
else if (sameString(sort, "query,score"))
    {
    slSort(&pslList, pslCmpQueryScore);
    }
else if (sameString(sort, "score"))
    {
    slSort(&pslList, pslCmpScore);
    }
else if (sameString(sort, "chrom,start"))
    {
    slSort(&pslList, pslCmpTargetStart);
    }
else if (sameString(sort, "chrom,score"))
    {
    slSort(&pslList, pslCmpTargetScore);
    }
else
    {
    slSort(&pslList, pslCmpQueryScore);
    }
if(feelingLucky)
    {
    /* If we found something jump browser to there. */
    if(slCount(pslList) > 0)
	printLuckyRedirect(browserUrl, pslList, database, pslName, faName, uiState, unhideTrack);
    /* Otherwise call ourselves again not feeling lucky to print empty 
       results. */
    else 
	{
	cartWebStart(cart, database, "%s BLAT Results", trackHubSkipHubName(organism));
	showAliPlaces(pslName, faName, database, qType, tType, organism, FALSE);
	cartWebEnd();
	}
    }
else if (pslOut)
    {
    printf("<TT><PRE>");
    if (!sameString(output, "psl no header"))
	pslxWriteHead(stdout, qType, tType);
    for (psl = pslList; psl != NULL; psl = psl->next)
	pslTabOut(psl, stdout);
    printf("</PRE></TT>");
    }
else
    {
    printf("<H2>BLAT Search Results</H2>");
    printf("<TT><PRE>");
    printf("   ACTIONS      QUERY           SCORE START  END QSIZE IDENTITY CHRO STRAND  START    END      SPAN\n");
    printf("---------------------------------------------------------------------------------------------------\n");
    for (psl = pslList; psl != NULL; psl = psl->next)
	{
	printf("<A HREF=\"%s?position=%s:%d-%d&db=%s&ss=%s+%s&%s%s\">",
	    browserUrl, psl->tName, psl->tStart + 1, psl->tEnd, database, 
	    pslName, faName, uiState, unhideTrack);
	printf("browser</A> ");
	printf("<A HREF=\"%s?o=%d&g=htcUserAli&i=%s+%s+%s&c=%s&l=%d&r=%d&db=%s&%s\">", 
	    hgcUrl, psl->tStart, pslName, cgiEncode(faName), psl->qName,  psl->tName,
	    psl->tStart, psl->tEnd, database, uiState);
	printf("details</A> ");
	printf("%-14s %5d %5d %5d %5d %5.1f%%  %4s  %2s  %9d %9d %6d\n",
	    psl->qName, pslScore(psl), psl->qStart+1, psl->qEnd, psl->qSize,
	    100.0 - pslCalcMilliBad(psl, TRUE) * 0.1,
	    skipChr(psl->tName), psl->strand, psl->tStart+1, psl->tEnd,
	    psl->tEnd - psl->tStart);
	}
    printf("</PRE></TT>");
    }
pslFreeList(&pslList);

}