lib/chainToAxt.c

Go to the documentation of this file.
00001 /* chainToAxt - convert from chain to axt format. */
00002 
00003 #include "common.h"
00004 #include "chain.h"
00005 #include "dnautil.h"
00006 #include "dnaseq.h"
00007 #include "axt.h"
00008 #include "chainToAxt.h"
00009 
00010 static char const rcsid[] = "$Id: chainToAxt.c,v 1.4 2005/04/10 14:41:21 markd Exp $";
00011 
00012 static struct axt *axtFromBlocks(
00013         struct chain *chain,
00014         struct cBlock *startB, struct cBlock *endB,
00015         struct dnaSeq *qSeq, int qOffset,
00016         struct dnaSeq *tSeq, int tOffset)
00017 /* Convert a list of blocks (guaranteed not to have inserts in both
00018  * strands between them) to an axt. */
00019 {
00020 int symCount = 0;
00021 int dq, dt, blockSize = 0, symIx = 0;
00022 struct cBlock *b, *a = NULL;
00023 struct axt *axt;
00024 char *qSym, *tSym;
00025 
00026 /* Make a pass through figuring out how big output will be. */
00027 for (b = startB; b != endB; b = b->next)
00028     {
00029     if (a != NULL)
00030         {
00031         dq = b->qStart - a->qEnd;
00032         dt = b->tStart - a->tEnd;
00033         symCount += dq + dt;
00034         }
00035     blockSize = b->qEnd - b->qStart;
00036     symCount += blockSize;
00037     a = b;
00038     }
00039 
00040 /* Allocate axt and fill in most fields. */
00041 AllocVar(axt);
00042 axt->qName = cloneString(chain->qName);
00043 axt->qStart = startB->qStart;
00044 axt->qEnd = a->qEnd;
00045 axt->qStrand = chain->qStrand;
00046 axt->tName = cloneString(chain->tName);
00047 axt->tStart = startB->tStart;
00048 axt->tEnd = a->tEnd;
00049 axt->tStrand = '+';
00050 axt->symCount = symCount;
00051 axt->qSym = qSym = needLargeMem(symCount+1);
00052 qSym[symCount] = 0;
00053 axt->tSym = tSym = needLargeMem(symCount+1);
00054 tSym[symCount] = 0;
00055 
00056 /* Fill in symbols. */
00057 a = NULL;
00058 for (b = startB; b != endB; b = b->next)
00059     {
00060     if (a != NULL)
00061         {
00062         dq = b->qStart - a->qEnd;
00063         dt = b->tStart - a->tEnd;
00064         if (dq == 0)
00065             {
00066             memset(qSym+symIx, '-', dt);
00067             memcpy(tSym+symIx, tSeq->dna + a->tEnd - tOffset, dt);
00068             symIx += dt;
00069             }
00070         else
00071             {
00072             assert(dt == 0);
00073             memset(tSym+symIx, '-', dq);
00074             memcpy(qSym+symIx, qSeq->dna + a->qEnd - qOffset, dq);
00075             symIx += dq;
00076             }
00077         }
00078     blockSize = b->qEnd - b->qStart;
00079     memcpy(qSym+symIx, qSeq->dna + b->qStart - qOffset, blockSize);
00080     memcpy(tSym+symIx, tSeq->dna + b->tStart - tOffset, blockSize);
00081     symIx += blockSize;
00082     a = b;
00083     }
00084 assert(symIx == symCount);
00085 
00086 /* Fill in score and return. */
00087 axt->score = axtScoreDnaDefault(axt);
00088 return axt;
00089 }
00090 
00091 struct axt *chainToAxt(struct chain *chain, 
00092         struct dnaSeq *qSeq, int qOffset,
00093         struct dnaSeq *tSeq, int tOffset, int maxGap, int maxChain)
00094 /* Convert a chain to a list of axt's.  This will break
00095  * where there is a double-sided gap in chain, or 
00096  * where there is a single-sided gap greater than maxGap, or 
00097  * where there is a chain longer than maxChain.
00098  */
00099 {
00100 struct cBlock *startB = chain->blockList, *a = NULL, *b;
00101 struct axt *axtList = NULL, *axt;
00102 
00103 for (b = chain->blockList; b != NULL; b = b->next)
00104     {
00105     if (a != NULL)
00106         {
00107         int dq = b->qStart - a->qEnd;
00108         int dt = b->tStart - a->tEnd;
00109         if ((dq > 0 && dt > 0) || dt > maxGap || dq > maxGap || (b->tEnd - startB->tStart) > maxChain)
00110             {
00111             axt = axtFromBlocks(chain, startB, b, qSeq, qOffset, tSeq, tOffset);
00112             slAddHead(&axtList, axt);
00113             startB = b;
00114             }
00115         }
00116     a = b;
00117     }
00118 axt = axtFromBlocks(chain, startB, NULL, qSeq, qOffset, tSeq, tOffset);
00119 slAddHead(&axtList, axt);
00120 slReverse(&axtList);
00121 return axtList;
00122 }

Generated on Tue Dec 25 18:39:30 2007 for blat by  doxygen 1.5.2