src/hg/qacAddGapIdx/qacAddGapIdx.c 1.3
1.3 2009/11/02 21:40:02 hiram
Fixup crash in mafAddQRows and off-by-one error in qacAddGapIdx
Index: src/hg/qacAddGapIdx/qacAddGapIdx.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/qacAddGapIdx/qacAddGapIdx.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -B -U 1000000 -r1.2 -r1.3
--- src/hg/qacAddGapIdx/qacAddGapIdx.c 15 Nov 2007 15:09:18 -0000 1.2
+++ src/hg/qacAddGapIdx/qacAddGapIdx.c 2 Nov 2009 21:40:02 -0000 1.3
@@ -1,91 +1,91 @@
/* qacAddGapIdx - add gap data and index qac. */
#include "common.h"
#include "linefile.h"
#include "hash.h"
#include "options.h"
#include "qaSeq.h"
#include "agp.h"
#include "agpGap.h"
#define FAKE_GAP_QUAL 100
void usage()
/* Explain usage and exit. */
{
errAbort(
"qacAddGapIdx - Add gap data and index qac.\n"
"usage:\n"
" qacAddGapIdx in.agp in.qac out.qac out.qdx\n"
);
}
void qacAddGapIdx(char *inAgp, char *inQac, char *outQac, char *outQdx)
/* qacAddGapIdx - add gap data and index qac. */
{
struct hash *agpLists = agpLoadAll(inAgp);
boolean isSwapped;
FILE *in_qac_f = qacOpenVerify(inQac, &isSwapped);
struct qaSeq *qa, *qaList = NULL;
int total_seqs = 0;
struct hashEl *hel;
struct agp *agp;
struct agpGap *gap;
FILE *qacf = mustOpen(outQac, "wb");
FILE *qdxf = mustOpen(outQdx, "wb");
off_t offset;
/* Add gap data to the qac */
while ((qa = qacReadNext(in_qac_f, isSwapped)) != NULL)
{
total_seqs++;
if ((hel = hashLookup(agpLists, qa->name)) != NULL)
{
for (agp = (struct agp *) hel->val; agp != NULL; agp = agp->next)
{
if (! agp->isFrag)
{
gap = (struct agpGap *) (agp->entry);
- if (qa->size - gap->chromStart + 1 > gap->size)
+ if (qa->size - gap->chromStart + 1 >= gap->size)
{
memset(qa->qa + gap->chromStart - 1, FAKE_GAP_QUAL, gap->size);
}
else
{
- errAbort("gap too big: chromStart = %d size = %d\n", gap->chromStart, gap->size);
+ errAbort("%s gap too big: qa.size %d - chromStart = %d size = %d\n", gap->chrom, qa->size, gap->chromStart, gap->size);
}
}
}
}
slAddHead(&qaList, qa);
}
/* Write out new qac and index */
qacWriteHead(qacf);
fprintf(qdxf, "%d\n", total_seqs);
for (qa = qaList; qa != NULL; qa = qa->next)
{
if ((offset = ftello(qacf)) == (off_t) -1)
{
errAbort("ftello() failed\n");
}
fprintf(qdxf, "%s\t%ld\n", qa->name, offset);
qacWriteNext(qacf, qa);
}
/* Clean up after ourselves */
carefulClose(&qacf);
carefulClose(&qdxf);
agpHashFree(&agpLists);
qaSeqFreeList(&qaList);
}
int main(int argc, char *argv[])
/* Process command line. */
{
if (argc != 5)
usage();
qacAddGapIdx(argv[1], argv[2], argv[3], argv[4]);
return EXIT_SUCCESS;
}