bf1d058d73bdb153279eb4e530d1257d2ccc5675 angie Mon Jun 23 10:43:04 2014 -0700 Added ENCODE Regulatory summary tracks for clustered DNase and TFBS,with support for filtering based on BED5 score and factor/cellType/treatment. refs #11461 diff --git src/hg/lib/variant.c src/hg/lib/variant.c index 2055cde..d3aa3f5 100644 --- src/hg/lib/variant.c +++ src/hg/lib/variant.c @@ -1,22 +1,23 @@ /* variant.c -- routines to convert other variant formats to a generic * variant structure */ /* Copyright (C) 2014 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" +#include "annoRow.h" #include "variant.h" 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 delFront = 0; int delRear = 0; if (start < sx) { delFront = min(sx - start, allele->length); start = sx; @@ -103,22 +104,45 @@ // we have a new allele! struct allele *allele; AllocVar(allele); slAddHead(&variant->alleles, allele); allele->variant = variant; allele->length = alleleStringLength; allele->sequence = lmCloneString(lm, thisAlleleString); allele->isReference = isRefAllele; } slReverse(&variant->alleles); return variant; } -struct variant *variantFromPgSnp(struct pgSnp *pgSnp, char *refAllele, struct lm *lm) -/* convert pgSnp record to variant record */ +struct variant *variantFromPgSnpAnnoRow(struct annoRow *row, char *refAllele, struct lm *lm) +/* Translate pgSnp annoRow into variant (allocated by lm). */ { -return variantNew(pgSnp->chrom, pgSnp->chromStart, pgSnp->chromEnd, pgSnp->alleleCount, - pgSnp->name, refAllele, lm); +struct pgSnp pgSnp; +pgSnpStaticLoad(row->data, &pgSnp); +return variantNew(pgSnp.chrom, pgSnp.chromStart, pgSnp.chromEnd, pgSnp.alleleCount, + pgSnp.name, refAllele, lm); +} + +struct variant *variantFromVcfAnnoRow(struct annoRow *row, char *refAllele, struct lm *lm, + struct dyString *dyScratch) +/* Translate vcf array of words into variant (allocated by lm, overwriting dyScratch + * as temporary scratch string). */ +{ +char **words = row->data; +char *alStr = vcfGetSlashSepAllelesFromWords(words, dyScratch); +// The reference allele is the first allele in alStr -- and it may be trimmed on both ends with +// respect to the raw VCF ref allele in words[3], so copy vcfRefAllele back out of alStr. +// That ensures that variantNew will get the reference allele that matches the slash-separated +// allele string. +int refLen = strlen(alStr); +char *p = strchr(alStr, '/'); +if (p) + refLen = p - alStr; +char vcfRefAllele[refLen + 1]; +safencpy(vcfRefAllele, sizeof(vcfRefAllele), alStr, refLen); +unsigned alCount = countChars(alStr, '/') + 1; +return variantNew(row->chrom, row->start, row->end, alCount, alStr, vcfRefAllele, lm); }