1c9a4cb6897ec2924b5d7f46e4c6b9162d94d6ba
angie
  Mon Apr 22 16:43:15 2013 -0700
Converted variant and gpFx to use localmem.  Also got rid of a coupleunnecessary conversions from genePred to bed and psl in annoGratorGpVar
and gpFx. refs #6152

diff --git src/hg/lib/variant.c src/hg/lib/variant.c
index 1ba9f52..33b8251 100644
--- src/hg/lib/variant.c
+++ src/hg/lib/variant.c
@@ -1,71 +1,70 @@
 /* variant.c -- routines to convert other variant formats to a generic
  *              variant structure */
 
 #include "common.h"
 #include "variant.h"
 
-struct allele  *alleleClip(struct allele *allele, int sx, int ex)
-/* clip allele to be inside region defined by sx..ex.  Returns 
- * pointer to new allele which should be freed by alleleFree, or variantFree
- */
+struct allele  *alleleClip(struct allele *allele, int sx, int ex, struct lm *lm)
+/* Return new allele pointing to new variant, both clipped to region defined by [sx,ex). */
 {
 struct variant *oldVariant = allele->variant;
 int start = oldVariant->chromStart;
 int end = oldVariant->chromEnd;
 int oldVariantWidth = end - start;
 int delFront = 0;
 int delRear = 0;
 
 if (start < sx)
     {
     if (oldVariantWidth != allele->length)	 /* FIXME */
 	errAbort("cannot clip alleles that are a different length than variant region");
     delFront = sx - start;
     start = sx;
     }
 
 if (end > ex)
     {
     if (oldVariantWidth != allele->length)	 /* FIXME */
 	errAbort("cannot clip alleles that are a different length than variant region");
     delRear = end - ex;
     end = ex;
     }
 
 struct variant *newVariant;
-AllocVar(newVariant);
-newVariant->chrom = cloneString(oldVariant->chrom);
+lmAllocVar(lm, newVariant);
+newVariant->chrom = lmCloneString(lm, oldVariant->chrom);
 newVariant->chromStart = start;
 newVariant->chromEnd = end;
 newVariant->numAlleles = 1;
+
 struct allele *newAllele;
-AllocVar(newAllele);
+lmAllocVar(lm, newAllele);
 newVariant->alleles = newAllele;
 newAllele->variant = newVariant;
 newAllele->length = allele->length - delRear - delFront;
 assert(newAllele->length >= 0);
-newAllele->sequence = cloneString(&allele->sequence[delFront]);
+newAllele->sequence = lmCloneString(lm, &allele->sequence[delFront]);
 newAllele->sequence[newAllele->length] = 0;   // cut off delRear part
 
 return newAllele;
 }
 
-static char *addDashes(char *input, int count)
+static char *addDashes(char *input, int count, struct lm *lm)
 /* add dashes at the end of a sequence to pad it out so it's length is count */
 {
-char *ret = needMem(count + 1);
+char *ret = lmAlloc(lm, count + 1);
 int inLen = strlen(input);
 
 safecpy(ret, count + 1, input);
 count -= inLen;
 
 char *ptr = &ret[inLen];
 while(count--)
     *ptr++ = '-';
 
 return ret;
 }
 
 struct variant *variantNew(char *chrom, unsigned start, unsigned end, unsigned numAlleles,
 			   char *slashSepAlleles, struct lm *lm)
 /* Create a variant from basic information that is easy to extract from most other variant
@@ -102,31 +101,31 @@
 	*nextAlleleString = 0;
 	nextAlleleString++;
 	}
 
     // this check probably not right, could be different per allele
     int alleleStringLength = strlen(thisAlleleString);
     if (sameString(thisAlleleString, "-") && alleleLength == 0)
 	{
 	alleleStringLength = 0;
 	thisAlleleString[0] = '\0';
 	}
     else if (alleleStringLength != alleleLength)
 	{
 	if ( alleleStringLength < alleleLength)
 	    {
-	    thisAlleleString = addDashes(thisAlleleString, alleleLength);
+	    thisAlleleString = addDashes(thisAlleleString, alleleLength, lm);
 	    alleleStringLength = alleleLength;
 	    }
 	}
 
     // we have a new allele!
     struct allele *allele;
     AllocVar(allele);
     slAddHead(&variant->alleles, allele);
     allele->variant = variant;
     allele->length = alleleStringLength; 
     toLowerN(thisAlleleString, alleleStringLength);
     allele->sequence = lmCloneString(lm, thisAlleleString);
     }
 
 slReverse(&variant->alleles);