static struct pfToken *fakeToken(struct pfToken *old, enum pfTokType type, union pfTokVal *val) /* Create a fake token. */ { struct pfToken *tok = CloneVar(old); tok->type = type; tok->val = *val; return tok; }
static struct hashEl *hashElCloneList(struct hashEl *hels) /* clone a list of hashEl objects */ { struct hashEl *hels2 = NULL, *hel; for (hel = hels; hel != NULL; hel = hel->next) { slSafeAddHead(&hels2, CloneVar(hel)); } slReverse(&hels2); return hels2; }
struct dnaSeq *cloneDnaSeq(struct dnaSeq *orig) /* Duplicate dna sequence in RAM. */ { struct dnaSeq *seq = CloneVar(orig); seq->name = cloneString(seq->name); seq->dna = needHugeMem(seq->size+1); memcpy(seq->dna, orig->dna, seq->size+1); seq->mask = NULL; if (orig->mask != NULL) { seq->mask = bitClone(orig->mask, seq->size); } return seq; }
struct annoFilter *annoFilterCloneList(struct annoFilter *list) /* Copy a list of annoFilters. */ { struct annoFilter *newList = NULL, *oldF; for (oldF = list; oldF != NULL; oldF = oldF->next) { struct annoFilter *newF = CloneVar(oldF); newF->label = cloneString(oldF->label); newF->values = cloneValues(oldF->values, oldF->type); slAddHead(&newList, newF); } slReverse(&newList); return newList; }
struct psl *clonePsl(struct psl *psl) /* Copy a psl to separate memory. */ { struct psl *c = CloneVar(psl); c->next = NULL; c->qName = cloneString(psl->qName); c->tName = cloneString(psl->tName); AllocArray(c->blockSizes, c->blockCount); CopyArray(psl->blockSizes, c->blockSizes, c->blockCount); AllocArray(c->qStarts, c->blockCount); CopyArray(psl->qStarts, c->qStarts, c->blockCount); AllocArray(c->tStarts, c->blockCount); CopyArray(psl->tStarts, c->tStarts, c->blockCount); return c; }
struct hashEl *hashElListHash(struct hash *hash) /* Return a list of all elements of hash. Free return with hashElFreeList. */ { int i; struct hashEl *hel, *dupe, *list = NULL; for (i=0; i<hash->size; ++i) { for (hel = hash->table[i]; hel != NULL; hel = hel->next) { dupe = CloneVar(hel); slAddHead(&list, dupe); } } return list; }
void annoGratorGpVarSetFuncFilter(struct annoGrator *gSelf, struct annoGratorGpVarFuncFilter *funcFilter) /* If funcFilter is non-NULL, it specifies which functional categories * to include in output; if NULL, by default intergenic variants are excluded and * all other categories are included. * NOTE: After calling this, call gpVar->setOverlapRule() because implementation * of that depends on filter settings. */ { struct annoGratorGpVar *self = (struct annoGratorGpVar *)gSelf; freez(&self->funcFilter); if (funcFilter != NULL) self->funcFilter = CloneVar(funcFilter); // Since our overlapRule behavior depends on filter settings, reevaluate: aggvSetOverlapRule(gSelf, self->gpVarOverlapRule); }
struct annoOption *annoOptionCloneList(struct annoOption *list) /* Return a newly allocated copy of list. */ { struct annoOption *newList = NULL, *afo; for (afo = list; afo != NULL; afo = afo->next) { struct annoOption *newAfo = CloneVar(afo); newAfo->spec.name = cloneString(afo->spec.name); newAfo->value = NULL; unsigned opFlags = opFlags; if (opFlags & OPTION_MULTI) { switch (opFlags & OPTION_TYPE_MASK) { case OPTION_STRING: newAfo->value = slNameCloneList((struct slName *)(afo->value)); break; default: errAbort("annoOptionCloneList: OPTION_MULTI implemented only for " "OPTION_STRING (not 0x%x)", opFlags); } } else { switch (opFlags & OPTION_TYPE_MASK) { // For numeric singleton values, we are overloading value. case OPTION_DOUBLE: case OPTION_FLOAT: case OPTION_LONG_LONG: case OPTION_INT: case OPTION_BOOLEAN: newAfo->value = afo->value; break; case OPTION_STRING: newAfo->value = cloneString((char *)afo->value); break; default: errAbort("annoOptionCloneList: unrecognized op type 0x%x", opFlags); } } slAddHead(&newList, newAfo); } slReverse(&newList); return newList; }
struct microData *lookupGenes(struct sqlConnection *conn, char *table, struct microData *oldList) /* Use gene list to lookup */ { struct microData *newList = NULL, *gene, *geneCopy, *next; struct hash *hash = newHash(0); struct sqlResult *sr; char **row; char query[256]; /* Load up hash from lookup table. We are doing inverse lookup on it * actually. */ sqlSafef(query, sizeof(query), "select name,value from %s", table); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { char *geneName = row[0]; char *expName = row[1]; hashAdd(hash, expName, cloneString(geneName)); } /* Move genes in oldList that hit hash to newList. * If more than one new gene hits then make a (shallow) * dupe of it and put it on newList too. This would * be a nightmare if we were actually going to free this * memory, but as a simple file filter there's no need. */ for (gene = oldList; gene != NULL; gene = next) { struct hashEl *hel; next = gene->next; hel = hashLookup(hash, gene->name); if (hel != NULL) { gene->name = hel->val; slAddHead(&newList, gene); while ((hel = hashLookupNext(hel)) != NULL) { geneCopy = CloneVar(gene); geneCopy->name = hel->val; slAddHead(&newList, geneCopy); } } } slReverse(&newList); return newList; }
int FASTCALL CompileVarBody(U16 flags, S16 *brackCnt, VAR *var, int *_elementsSize, int braceCnt, int cast) { int elementsSize, len; S32 num; VAR *childvar; S16 braceCntStart; int elementsStart; elementsSize = *_elementsSize; if(!PRECOMPILING) { elementsStart = elementsSize; } if(comProc_LabelDeclaration(flags, brackCnt)) { // catch the labels if(braceCnt) { if(GetNextWord()[0]=='}') braceCnt--; } } else { if(var->cast == VARCAST_STRUCT) { braceCntStart = braceCnt; if(szTemp[0]!='{') { error(ERR_STRUCTELEMENTBRACE,szTemp); } else { GetNextWord(); braceCnt++; } childvar = FindFirstVariable(var->childVars); while(childvar) { braceCnt = CompileVarBody(flags|CF_VARCHILD,brackCnt, childvar, &elementsSize, braceCnt, childvar->cast); childvar = childvar->next; if(childvar && !braceCnt) return 0; } if(braceCntStart != braceCnt) { error(ERR_CLOSEBRACEEXP,var->label); } if(!PRECOMPILING) var=var; } else if(szTemp[0]=='{' && var->arraySize) { int arsize = var->arraySize; braceCntStart = braceCnt; GetNextWord(); braceCnt++; childvar = CloneVar(var, curVar, 0); childvar->arraySize = 0; do { braceCnt = CompileVarBody(flags|CF_VARCHILD,brackCnt, childvar, &elementsSize, braceCnt, childvar->cast); arsize--; } while(braceCnt && braceCnt > braceCntStart); FreeVars(&childvar); if(braceCntStart != braceCnt) { error(ERR_CLOSEBRACEEXP,var->label); } if(!PRECOMPILING && arsize < 0) { error(ERR_ARRAYTOOLARGE,var->label); } } else if(szTemp[0]=='"') { if(varcasts[cast].size!=VARSIZE_BYTE) error(ERR_STRINGNOTBYTE,var->label); if(!DoString()) return 0; if(!PRECOMPILING) { len = lenSzStr;//(U16)strlen(szString); if(var->arraySize && len > var->arraySize) { len = var->arraySize; szString[len?len-1:0] = '\0'; error(ERR_STRINGTOOLONG,szString); } BankWrite(szString,len); if(var->arraySize) { BankFill(0,var->arraySize-len); elementsSize += var->arraySize; } else { elementsSize += len; } } } else { CompileImmediateInteger(0, &num, -4, 0); if(!PRECOMPILING) { if(strToInt_LabelObject) { // do the fixup AddFixOffs( strToInt_LabelType, (var->flags&VARFLAG_16BIT)?FIXOFFS_WORD:FIXOFFS_BYTE, curBank->ptr, 0, strToInt_LabelObject ); } if(var->flags&VARFLAG_16BIT) { WriteCodeW(num); elementsSize += 2; } else { WriteCodeB(num); elementsSize ++; } } } if(braceCnt) { if(GetNextWord()[0]=='}') { braceCnt--; } else if(szTemp[0]!=',') { error(ERR_ARRAYCOMMAEXP,var->label); } else { if(GetNextWord()[0]=='}') { braceCnt--; } } } } if(!PRECOMPILING && (flags&CF_VARCHILD)) { int amount = (elementsSize-elementsStart); if(var->arraySize && amount < var->arraySize) { BankFill(0,var->arraySize-amount); elementsSize += var->arraySize-amount; } } *_elementsSize = elementsSize; return braceCnt; }
double *cloneDouble(double x) /* Return clone of double in dynamic memory */ { return CloneVar(&x); }
void reportCassette(struct altGraphX *ag, bool **em, int vs, int ve1, int ve2, int altBpStart, int altBpEnd, int startV, int endV, FILE *out) /* Write out both an altGraphX and two bed files. For a cassette exon the edges are - Name Vertexes Class ------ ---------- ----- exon1: startV->vs constitutive (cons 0) junction1: vs->ve1 alternative1 (alt1 1) exon2: ve1->altBpEnd alternative1 (alt1 1) junction2: altBpEnd->ve2 alternative1 (alt1 1) exon3: ve2->endV constitutive (cons 0) junction3: vs->ve2 alternative2 (alt2 2) */ { struct altGraphX *agLoc = NULL; /* Local altGraphX. */ struct evidence *ev = NULL, *evLoc = NULL; int *vPos = ag->vPositions; unsigned char *vT = ag->vTypes; int *vPosLoc = NULL; /* Vertex Positions. */ int *eStartsLoc = NULL; /* Edge Starts. */ int *eEndsLoc = NULL; /* Edge ends. */ unsigned char *vTLoc = NULL; /* Vertex Types. */ int *eTLoc = NULL; /* Edge Types. */ int vCLoc = 0; int eCLoc = 0; int i =0; struct dyString *dy = NULL; if(out == NULL) return; AllocVar(agLoc); agLoc->tName = cloneString(ag->tName); agLoc->name = cloneString(ag->name); agLoc->tStart = vPos[startV]; agLoc->tEnd = vPos[endV]; agLoc->strand[0] = ag->strand[0]; agLoc->vertexCount = vCLoc = 6; agLoc->edgeCount = eCLoc = 6; agLoc->id = altCassette; /* Allocate some arrays. */ AllocArray(vPosLoc, vCLoc); AllocArray(eStartsLoc, vCLoc); AllocArray(eEndsLoc, vCLoc); AllocArray(vTLoc, vCLoc); AllocArray(eTLoc, vCLoc); /* Fill in the vertex positions. */ vPosLoc[0] = vPos[startV]; vPosLoc[1] = vPos[vs]; vPosLoc[2] = vPos[ve1]; vPosLoc[3] = vPos[altBpEnd]; vPosLoc[4] = vPos[ve2]; vPosLoc[5] = vPos[endV]; /* Fill in the vertex types. */ vTLoc[0] = vT[startV]; vTLoc[1] = vT[vs]; vTLoc[2] = vT[ve1]; vTLoc[3] = vT[altBpEnd]; vTLoc[4] = vT[ve2]; vTLoc[5] = vT[endV]; /* Fill in the edges. */ /* Constitutive first exon. */ eStartsLoc[0] = 0; eEndsLoc[0] = 1; eTLoc[0] = 0; ev = evidenceForEdge(ag, startV, vs); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); /* Exon inclusion junction. */ eStartsLoc[1] = 1; eEndsLoc[1] = 2; eTLoc[1] = 1; ev = evidenceForEdge(ag, vs, ve1); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); /* Exon exclusion junction. */ eStartsLoc[2] = 1; eEndsLoc[2] = 4; eTLoc[2] = 2; ev = evidenceForEdge(ag, vs, ve2); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); /* Cassette exon. */ eStartsLoc[3] = 2; eEndsLoc[3] = 3; eTLoc[3] = 1; ev = evidenceForEdge(ag, ve1, altBpEnd); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); /* Exon inclusion junction. */ eStartsLoc[4] = 3; eEndsLoc[4] = 4; eTLoc[4] = 1; ev = evidenceForEdge(ag, altBpEnd, ve2); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); /* Constitutive second exon. */ eStartsLoc[5] = 4; eEndsLoc[5] = 5; eTLoc[5] = 0; ev = evidenceForEdge(ag, ve2, endV); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); slReverse(&agLoc->evidence); dy = newDyString(ag->mrnaRefCount*36); agLoc->mrnaRefCount = ag->mrnaRefCount; for(i=0; i<ag->mrnaRefCount; i++) dyStringPrintf(dy, "%s,", ag->mrnaRefs[i]); sqlStringDynamicArray(dy->string, &agLoc->mrnaRefs, &i); dyStringFree(&dy); agLoc->mrnaTissues = CloneArray(ag->mrnaTissues, ag->mrnaRefCount); agLoc->mrnaLibs = CloneArray(ag->mrnaLibs, ag->mrnaRefCount); agLoc->vPositions = vPosLoc; agLoc->edgeStarts = eStartsLoc; agLoc->edgeEnds = eEndsLoc; agLoc->vTypes = vTLoc; agLoc->edgeTypes = eTLoc; altGraphXTabOut(agLoc, out); altGraphXFree(&agLoc); }
void reportAlt3Prime(struct altGraphX *ag, bool **em, int vs, int ve1, int ve2, int altBpStart, int altBpEnd, int startV, int endV, FILE *out) /* Write out an altGraphX record for an alt3Prime splicing event. Variable names are consistent with the rest of the program, but can be misleading. Specifically vs = start of alt splicing, ve1 = first end of alt splicing, etc. even though "vs" is really the end of an exon. For an alt5Prime splice the edges are: Name Vertexes Class ------ ---------- ----- exon1: startV->vs constituative (0) junction1: vs->ve1 alternative (1) junction2: vs->ve2 alternative (2) exon2: ve1->e2 alternative (1) exon3: ve2->endV constituative (0) */ { struct altGraphX *agLoc = NULL; /* Local altGraphX. */ struct evidence *ev = NULL, *evLoc = NULL; int *vPos = ag->vPositions; unsigned char *vT = ag->vTypes; int *vPosLoc = NULL; /* Vertex Positions. */ int *eStartsLoc = NULL; /* Edge Starts. */ int *eEndsLoc = NULL; /* Edge ends. */ unsigned char *vTLoc = NULL; /* Vertex Types. */ int *eTLoc = NULL; /* Edge Types. */ int vCLoc = 0; int eCLoc = 0; int edgeIx = 0, vertexIx = 0; int i =0; struct dyString *dy = NULL; if(out == NULL) return; AllocVar(agLoc); agLoc->tName = cloneString(ag->tName); agLoc->name = cloneString(ag->name); agLoc->tStart = vPos[startV]; agLoc->tEnd = vPos[endV]; agLoc->strand[0] = ag->strand[0]; agLoc->vertexCount = vCLoc = 6; agLoc->edgeCount = eCLoc = 5; agLoc->id = alt3Prime; /* Allocate some arrays. */ AllocArray(vPosLoc, vCLoc); AllocArray(eStartsLoc, eCLoc); AllocArray(eEndsLoc, eCLoc); AllocArray(vTLoc, vCLoc); AllocArray(eTLoc, eCLoc); /* Fill in the vertex positions. */ vertexIx = 0; vPosLoc[vertexIx++] = vPos[startV]; /* 0 */ vPosLoc[vertexIx++] = vPos[vs]; /* 1 */ vPosLoc[vertexIx++] = vPos[ve1]; /* 2 */ vPosLoc[vertexIx++] = vPos[ve2]; /* 3 */ vPosLoc[vertexIx++] = vPos[ve2]; /* 4 */ vPosLoc[vertexIx++] = vPos[endV]; /* 5 */ /* Fill in the vertex types. */ vertexIx = 0; vTLoc[vertexIx++] = vT[startV]; vTLoc[vertexIx++] = vT[vs]; vTLoc[vertexIx++] = vT[ve1]; vTLoc[vertexIx++] = vT[vs]; /* Faking a separate exon for the alt spliced portion. */ vTLoc[vertexIx++] = vT[ve2]; vTLoc[vertexIx++] = vT[endV]; edgeIx = 0; /* Constitutive first exon. */ eStartsLoc[edgeIx] = 0; eEndsLoc[edgeIx] = 1; eTLoc[edgeIx] = 0; ev = evidenceForEdge(ag, startV, vs); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); edgeIx++; /* Alternative1 junction (shorter). */ eStartsLoc[edgeIx] = 1; eEndsLoc[edgeIx] = 2; eTLoc[edgeIx] = 1; ev = evidenceForEdge(ag, vs, ve1); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); edgeIx++; /* Alt2 junction (longer). */ eStartsLoc[edgeIx] = 1; eEndsLoc[edgeIx] = 4; eTLoc[edgeIx] = 2; ev = evidenceForEdge(ag, vs, ve2); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); edgeIx++; /* Alt1 portion of second exon. */ eStartsLoc[edgeIx] = 2; eEndsLoc[edgeIx] = 3; eTLoc[edgeIx] = 1; ev = evidenceForEdge(ag, ve1, endV); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); edgeIx++; /* Exon 2 constitutive (shorter exon) */ eStartsLoc[edgeIx] = 4; eEndsLoc[edgeIx] = 5; eTLoc[edgeIx] = 0; ev = evidenceForEdge(ag, ve2, endV); evLoc = CloneVar(ev); evLoc->mrnaIds = CloneArray(ev->mrnaIds, ev->evCount); slAddHead(&agLoc->evidence, evLoc); edgeIx++; /* Package up the evidence, tissues, etc. */ slReverse(&agLoc->evidence); dy = newDyString(ag->mrnaRefCount*36); agLoc->mrnaRefCount = ag->mrnaRefCount; for(i=0; i<ag->mrnaRefCount; i++) dyStringPrintf(dy, "%s,", ag->mrnaRefs[i]); sqlStringDynamicArray(dy->string, &agLoc->mrnaRefs, &i); dyStringFree(&dy); agLoc->mrnaTissues = CloneArray(ag->mrnaTissues, ag->mrnaRefCount); agLoc->mrnaLibs = CloneArray(ag->mrnaLibs, ag->mrnaRefCount); agLoc->vPositions = vPosLoc; agLoc->edgeStarts = eStartsLoc; agLoc->edgeEnds = eEndsLoc; agLoc->vTypes = vTLoc; agLoc->edgeTypes = eTLoc; altGraphXTabOut(agLoc, out); altGraphXFree(&agLoc); }
static struct linkedFeatures *cgapSageToLinkedFeatures(struct cgapSage *tag, struct hash *libHash, struct hash *libTotHash, enum trackVisibility vis) /* Convert a single CGAP tag to a list of linkedFeatures. */ { struct linkedFeatures *libList = NULL; struct linkedFeatures *skel = skeletonLf(tag); int i; if (vis == tvDense) /* Just use the skeleton one. */ { int tagTotal = 0; int freqTotal = 0; int libsUsed = 0; for (i = 0; i < tag->numLibs; i++) { char libId[16]; char *libName; safef(libId, sizeof(libId), "%d", tag->libIds[i]); libName = hashMustFindVal(libHash, libId); if (keepThisLib(libName, libId)) { int libTotal = hashIntVal(libTotHash, libId); tagTotal += libTotal; freqTotal += tag->freqs[i]; libsUsed++; } } if (libsUsed > 0) { skel->name = cloneString("whatever"); skel->score = (float)((double)freqTotal * (1000000/tagTotal)); skel->grayIx = grayIxForCgap(skel->score); addSimpleFeature(skel); libList = skel; } } else if (vis == tvPack) { /* If it's pack mode, average tissues into one linkedFeature. */ struct hash *tpmHash = combineCgapSages(tag, libHash, libTotHash); struct hashEl *tpmList = hashElListHash(tpmHash); struct hashEl *tpmEl; slSort(&tpmList, slNameCmp); for (tpmEl = tpmList; tpmEl != NULL; tpmEl = tpmEl->next) { struct linkedFeatures *tiss = CloneVar(skel); struct cgapSageTpmHashEl *tpm = (struct cgapSageTpmHashEl *)tpmEl->val; char link[256]; char *encTissName = NULL; double score = 0; int len = strlen(tpmEl->name) + 32; tiss->name = needMem(len); safef(tiss->name, len, "%s (%d)", tpmEl->name, tpm->count); encTissName = cgiEncode(tpmEl->name); safef(link, sizeof(link), "i=%s&tiss=%s", tag->name, encTissName); score = (double)tpm->freqTotal*(1000000/(double)tpm->libTotals); tiss->score = (float)score; tiss->grayIx = grayIxForCgap(score); tiss->extra = cloneString(link); freeMem(encTissName); addSimpleFeature(tiss); slAddHead(&libList, tiss); } hashElFreeList(&tpmList); freeHashAndVals(&tpmHash); } else /* full mode */ { for (i = 0; i < tag->numLibs; i++) { char libId[16]; char *libName; char link[256]; struct linkedFeatures *lf; safef(libId, sizeof(libId), "%d", tag->libIds[i]); libName = hashMustFindVal(libHash, libId); if (keepThisLib(libName, libId)) { lf = CloneVar(skel); lf->name = cloneString(libName); safef(link, sizeof(link), "i=%s&lib=%s", tag->name, libId); lf->score = (float)tag->tagTpms[i]; lf->grayIx = grayIxForCgap(tag->tagTpms[i]); lf->extra = cloneString(link); addSimpleFeature(lf); slAddHead(&libList, lf); } } } slSort(&libList, cgapLinkedFeaturesCmp); slReverse(&libList); return libList; }
void chainSubsetOnQ(struct chain *chain, int subStart, int subEnd, struct chain **retSubChain, struct chain **retChainToFree) /* Get subchain of chain bounded by subStart-subEnd on * query side. Return result in *retSubChain. In some * cases this may be the original chain, in which case * *retChainToFree is NULL. When done call chainFree on * *retChainToFree. The score and id fields are not really * properly filled in. */ { struct chain *sub = NULL; struct cBlock *oldB, *b, *bList = NULL; int qStart = BIGNUM, qEnd = -BIGNUM; int tStart = BIGNUM, tEnd = -BIGNUM; /* Check for easy case. */ if (subStart <= chain->qStart && subEnd >= chain->qEnd) { *retSubChain = chain; *retChainToFree = NULL; return; } /* Build new block list and calculate bounds. */ for (oldB = chain->blockList; oldB != NULL; oldB = oldB->next) { if (oldB->qEnd <= subStart) continue; if (oldB->qStart >= subEnd) break; b = CloneVar(oldB); if (b->qStart < subStart) { b->tStart += subStart - b->qStart; b->qStart = subStart; } if (b->qEnd > subEnd) { b->tEnd -= b->qEnd - subEnd; b->qEnd = subEnd; } slAddHead(&bList, b); if (tStart > b->tStart) tStart = b->tStart; if (tEnd < b->tEnd) tEnd = b->tEnd; if (qStart > b->qStart) qStart = b->qStart; if (qEnd < b->qEnd) qEnd = b->qEnd; } slReverse(&bList); /* Make new chain based on old. */ if (bList != NULL) { AllocVar(sub); sub->blockList = bList; sub->qName = cloneString(chain->qName); sub->qSize = chain->qSize; sub->qStrand = chain->qStrand; sub->qStart = qStart; sub->qEnd = qEnd; sub->tName = cloneString(chain->tName); sub->tSize = chain->tSize; sub->tStart = tStart; sub->tEnd = tEnd; sub->id = chain->id; } *retSubChain = *retChainToFree = sub; }
void chainFastSubsetOnT(struct chain *chain, struct cBlock *firstBlock, int subStart, int subEnd, struct chain **retSubChain, struct chain **retChainToFree) /* Get subchain as in chainSubsetOnT. Pass in initial block that may * be known from some index to speed things up. */ { struct chain *sub = NULL; struct cBlock *oldB, *b, *bList = NULL; int qStart = BIGNUM, qEnd = -BIGNUM; int tStart = BIGNUM, tEnd = -BIGNUM; /* Check for easy case. */ if (subStart <= chain->tStart && subEnd >= chain->tEnd) { *retSubChain = chain; *retChainToFree = NULL; return; } /* Build new block list and calculate bounds. */ for (oldB = firstBlock; oldB != NULL; oldB = oldB->next) { if (oldB->tStart >= subEnd) break; b = CloneVar(oldB); if (b->tStart < subStart) { b->qStart += subStart - b->tStart; b->tStart = subStart; } if (b->tEnd > subEnd) { b->qEnd -= b->tEnd - subEnd; b->tEnd = subEnd; } slAddHead(&bList, b); if (qStart > b->qStart) qStart = b->qStart; if (qEnd < b->qEnd) qEnd = b->qEnd; if (tStart > b->tStart) tStart = b->tStart; if (tEnd < b->tEnd) tEnd = b->tEnd; } slReverse(&bList); /* Make new chain based on old. */ if (bList != NULL) { double sizeRatio; AllocVar(sub); sub->blockList = bList; sub->qName = cloneString(chain->qName); sub->qSize = chain->qSize; sub->qStrand = chain->qStrand; sub->qStart = qStart; sub->qEnd = qEnd; sub->tName = cloneString(chain->tName); sub->tSize = chain->tSize; sub->tStart = tStart; sub->tEnd = tEnd; sub->id = chain->id; /* Fake new score. */ sizeRatio = (sub->tEnd - sub->tStart); sizeRatio /= (chain->tEnd - chain->tStart); sub->score = sizeRatio * chain->score; } *retSubChain = *retChainToFree = sub; }