Exemple #1
0
int main(int argc, char *argv[])
/* Process command line. */
{
optionInit(&argc, argv, options);
if (argc != 5)
    usage();
acceptString = optionVal("A", NULL);
if (acceptString)
    {
    acceptExtensionsCount = chopByChar(acceptString, ',', NULL, 0);
    AllocArray(acceptExtensions, acceptExtensionsCount);
    chopByChar(acceptString, ',', acceptExtensions, acceptExtensionsCount);
    verbose(1, "accept-option count: %d\n", acceptExtensionsCount);
    int i = 0;
    for(i=0; i<acceptExtensionsCount; ++i) 
	{
	verbose(2, "accept-option: %s\n", acceptExtensions[i]);
	}
    }
struct dyString *url = dyStringNew(4096);
struct dyString *outPath = dyStringNew(4096);
dyStringAppend(url, argv[3]);
dyStringAppend(outPath, argv[4]);
if (!paraSync(atoi(argv[1]), atoi(argv[2]), url, outPath, optionExists("newer"), optionExists("progress")))
    exit(1);
return 0;
}
Exemple #2
0
void joinTwoInfo(char *spec1, char *spec2)
/* joinTwoInfo - Look at two columns in two tables in mySQL and see how joinable they look.. */
{
char *s1[4], *s2[4];
struct lm *lm = lmInit(0);
int partCount = chopByChar(lmCloneString(lm, spec1), '.', s1, ArraySize(s1));
if (partCount != 3)
    usage();
partCount = chopByChar(lmCloneString(lm, spec2), '.', s2, ArraySize(s2));
if (partCount != 3)
    usage();

struct slName *list1 = getColumn(s1[0], s1[1], s1[2], lm);
struct hash *uniq1 = uniqHash(list1);
struct slName *list2 = getColumn(s2[0], s2[1], s2[2], lm);
struct hash *uniq2 = uniqHash(list2);
int countOneInTwo = countInHash(list1, uniq2);
int countTwoInOne = countInHash(list2, uniq1);
int countUniqOneInTwo = countUniqInHash(list1, uniq2);
int countUniqTwoInOne = countUniqInHash(list2, uniq1);
printf("%s: %d items, %d unique items, %d items (%d unique) in %s\n",
	spec1, slCount(list1), uniq1->elCount, countOneInTwo, countUniqOneInTwo, spec2);
printf("%s: %d items, %d unique items, %d items (%d unique) in %s\n",
	spec2, slCount(list2), uniq2->elCount, countTwoInOne, countUniqTwoInOne, spec1);

lmCleanup(&lm);
}
Exemple #3
0
static boolean rowReaderNextFile(struct rowReader *rr)
/* read the next row into the rowReader from a file. */
{
char *line;
if (!lineFileNextReal(rr->lf, &line))
    return FALSE;
rr->numCols = chopByChar(line, '\t', NULL, 0);
if (rr->numCols > rr->colSpace)
    growRow(rr, rr->numCols);
chopByChar(line, '\t', rr->row, rr->numCols);
return TRUE;
}
char *llBlastPName(struct track *tg, void *item)
{
struct bed *bed = item;
char *itemName = cloneString(bed->name);
static char buf[256];
char *nameParts[2];
chopByChar(itemName,'|',nameParts,ArraySize(nameParts));
sprintf(buf, "%s", nameParts[0]);
chopByChar(buf,'$',nameParts,ArraySize(nameParts));
sprintf(buf,"%s",nameParts[1]);
freeMem(itemName);
return buf;
}
Exemple #5
0
static void printTabularHeaderRow(const struct vcfInfoDef *def)
/* Parse the column header parts out of def->description and print as table header row;
 * call this only when looksTabular returns TRUE. */
{
regmatch_t substrArr[PATH_LEN];
if (regexMatchSubstr(def->description, COL_DESC_REGEX, substrArr, ArraySize(substrArr)))
    {
    puts("<TR>");
    // Make a copy of the part of def->description that matches the regex,
    // then chop by '|' and print out header column tags:
    int matchSize = substrArr[0].rm_eo - substrArr[0].rm_so;
    char copy[matchSize+1];
    safencpy(copy, sizeof(copy), def->description + substrArr[0].rm_so, matchSize);
    // Turn '_' into ' ' so description words can wrap inside headers, saving some space
    subChar(copy, '_', ' ');
    char *words[PATH_LEN];
    int descColCount = chopByChar(copy, '|', words, ArraySize(words));
    int i;
    for (i = 0;  i < descColCount; i++)
        printf("<TH class='withThinBorder'>%s</TH>", words[i]);
    puts("</TR>");
    }
else
    errAbort("printTabularHeaderRow: code bug, if looksTabular returns true then "
             "regex should work here");
}
Exemple #6
0
void readEpcr(struct lineFile *ef)
/* Read in and record epcr records */
{
int wordCount;
char *words[8];
char *pos[4];
struct epcr *epcr;
struct sts *sts;

while (lineFileChopNext(ef, words, 4))
    {
    if (words[3])
      {
	AllocVar(epcr);
	epcr->next = NULL;
	epcr->contig = cloneString(words[0]);
	epcr->bases = cloneString(words[1]);
	epcr->dbstsId = cloneString(words[2]);
	epcr->ucscId = cloneString(words[3]);
	wordCount = chopByChar(words[1], '.', pos, ArraySize(pos));
	if (wordCount != 3) 
	  errAbort("Not parsing epcr as expeceted\n");
	epcr->start = sqlUnsigned(pos[0]);
	epcr->end = sqlUnsigned(pos[2]);
	sts = hashMustFindVal(stsHash, epcr->dbstsId);
	if (!epcrInList(sts->epcr, epcr))
	  {
	    slAddHead(&sts->epcr, epcr);
	    sts->epcrCount++;
	  } 	  
      }
    }
}
void readUniStsIds(struct lineFile *usf)
/* Read names and UniSTS IDs */
{
char *words[52], *sanger[NUMSANGER], *uniStsId = NULL;
struct alias *al = NULL;
int i = 0, sangerCount, j;
boolean found = FALSE;

/* Read in all rows */
while (lineFileChopTab(usf, words))
    {
    /* the Sanger ID may be a list separted by a semicolon */
    sangerCount = chopByChar(words[0], ';', sanger, ArraySize(sanger));
    uniStsId = cloneString(words[1]);
    for (j = 0; j < sangerCount; j++)
        {
        if ((al = hashFindVal(aliasHash, sanger[j])) != NULL)
            {
           /* add this UniSTS ID to the alias structure if this value is NULL */
            found = FALSE;
            for (i = 0; i < NUMSANGER && (!found); i++)
                {
                if (al->uniStsId[i] == NULL)
                    {
                    found = TRUE;
                    al->uniStsId[i] = cloneString(uniStsId);
                    }
                }
            /* if the UniStsId read here is not the same as that stored from markers file, then report */
            } 
        else
            fprintf(stderr, "This Sanger name, %s, is not found in the alias hash\n", sanger[j]);
        }
    }
}
void splitNcbiFa(char *ncbiIn, char *outDir)
/* splitNcbiFa - Split up NCBI format fa file into UCSC formatted ones.. */
{
struct lineFile *lf = lineFileOpen(ncbiIn, TRUE);
static struct dnaSeq seq;
ZeroVar(&seq);

makeDir(outDir);
while (faSpeedReadNext(lf, &seq.dna, &seq.size, &seq.name))
    {
    FILE *f;
    char fileName[512];
    char *row[5];
    int wordCount;
    char ourName[129];
    char cloneName[128];

    wordCount = chopByChar(seq.name, '|', row, ArraySize(row));
    if (wordCount != 5)
        errAbort("Expecting 5 | separated fields line %d of %s", lf->lineIx, lf->fileName);
    strcpy(cloneName, row[3]);
    chopSuffix(cloneName);
    sprintf(fileName, "%s/%s.fa", outDir, cloneName);
    sprintf(ourName, "%s_1", row[3]);
    faWrite(fileName, ourName, seq.dna, seq.size);
    }
}
Exemple #9
0
static void parseIntRangeSetting(struct trackDb *tdb, char *settingName,
				    int *retMin, int *retMax)
/* If setting is an integer range, store the values into retMin and retMax */
// This is highly similar to lib/wiggleCart.c's static void parseColonRange,
// though that expects doubles.  For quality scores we do want unsigned.
{
char *range = trackDbSetting(tdb, settingName);
if (range != NULL)
    {
    char rangeCopy[16]; // if it's longer than this, there's a problem.
    safecpy(rangeCopy, sizeof(rangeCopy), range);
    char *words[3];
    int wordCount = chopByChar(rangeCopy, ':', words, ArraySize(words));
    if (wordCount == 2)
	{
	if (retMin != NULL)
	    *retMin = sqlUnsigned(words[0]);
	if (retMax != NULL)
	    *retMax = sqlUnsigned(words[1]);
	return;
	}
    else
	warn("track %s table %s: setting %s should be integer range min:max but is %s",
	     tdb->track, tdb->table, settingName, range);
    }
}
Exemple #10
0
char *reverseComplementSlashSeparated(char *alleleStr)
/* Given a slash-separated series of sequences (a common representation of variant alleles),
 * returns a slash-sep series with the reverse complement of each sequence (if it is a
 * nucleotide sequence).
 * Special behavior to support dbSNP's variant allele conventions:
 * 1. Reverse the order of sequences (to maintain alphabetical ordering).
 * 2. If alleleStr begins with "-/", then after reversing, move "-/" back to the beginning. */
{
int len = strlen(alleleStr);
char choppyCopy[len+1];
safecpy(choppyCopy, sizeof(choppyCopy), alleleStr);
char *alleles[len];
int alCount = chopByChar(choppyCopy, '/', alleles, ArraySize(alleles));
char *outStr = needMem(len+1);
int i;
for (i = alCount-1;  i >= 0;  i--)
    {
    char *allele = alleles[i];
    int alLen = strlen(allele);
    if (isAllNt(allele, alLen))
        reverseComplement(allele, alLen);
    if (i != alCount-1)
        safecat(outStr, len+1, "/");
    safecat(outStr, len+1, allele);
    }
if (startsWith("-/", alleleStr))
    {
    // Keep "-/" at the beginning:
    memmove(outStr+2, outStr, len-2);
    outStr[0] = '-';
    outStr[1] = '/';
    }
return outStr;
}
Exemple #11
0
struct tabRow *tabRowByChar(struct slName *lineList, char c, char *fileName,
	boolean varCol)
/* Convert lines to rows based on character separation.  If varCol is TRUE then not
 * all rows need to have same number of columns. */
{
struct slName *line;
struct tabRow *rowList = NULL, *row;

if (varCol)
    {
    for (line = lineList; line != NULL; line = line->next)
        {
	char *s = line->name;
	int rowSize = countChars(s, c) + 1;
	row = tabRowNew(rowSize);
	chopByChar(s, c, row->columns, rowSize);
	slAddHead(&rowList, row);
	}
    }
else
    {
    if (lineList)
        {
	int rowSize = countChars(lineList->name, c) + 1;
	int extraSize = rowSize+1;
	int ix = 1;
	for (line = lineList; line != NULL; line = line->next, ++ix)
	    {
	    int oneSize;
	    row = tabRowNew(rowSize);
	    oneSize = chopByChar(line->name, c, row->columns, extraSize);
	    if (oneSize != rowSize)
	        {
		if (oneSize > rowSize)
		    errAbort("Got more than the expected %d columns line %d of %s",
			    rowSize, ix, fileName);
		else
		    errAbort("Expecting %d columns got %d, line %d of %s",
		    	rowSize, oneSize, ix, fileName);

		}
	    slAddHead(&rowList, row);
	    }
	}
    }
return rowList;
}
void readMarkers(struct lineFile *mkf)
/* Read in Sanger sts name, UniSTS ID and aliases */
/* All Sanger names in this file are found in the Clone marker file */
{
struct bac *b = NULL;
struct alias *a = NULL;
char *words[6], *sanger[NUMSANGER], *stsIdandAliases[NUMALIASES], *extName = NULL;
char *firstAlias = NULL, **aliases = NULL, *pr1 = NULL, *pr2 = NULL;
int sangerCount = 0, nameCount = 0, i, j, k;
char sep = '|';
boolean isId = TRUE;

/* Read in all rows */
while (lineFileChopCharNext(mkf, sep, words, 6))
    {
    sangerCount = chopByChar(words[1], ';', sanger, ArraySize(sanger));
    nameCount = chopByChar(words[2], ';', stsIdandAliases, ArraySize(stsIdandAliases));
    pr1 = cloneString(words[3]);
    pr2 = cloneString(words[4]);

    /* process each sanger name found */
    for (i = 0; i < sangerCount; i++)
        {
        /* use sanger name to find alias struct in hash */
        if ((a = hashFindVal(aliasHash, sanger[i])) != NULL)
            {
            /* if string is numeric, then it is an integer ID so do not add to array */
            k = 0;
            for (j = 0; j < nameCount; j++)
                {
                isId = stringIsAnInteger(stsIdandAliases[j]);
                if (!isId)
                    {
                    a->aliases[k] = cloneString(stsIdandAliases[j]);
                    k++;
                    }
                }
                
            /* store primer sequences */
            a->primer1 = cloneString(pr1);
            a->primer2 = cloneString(pr2);
            }
        else
            fprintf(stderr, "Can not find sanger name, %s, in aliasHash\n", sanger[i]);
        }
    }
}
void readUnistsAliases(struct lineFile *uaf)
/* Read in UniSTS alias names */
{
char *words[4], *name = NULL, *id = NULL;
int nameCount, i = 0, j, k, l = 0;
struct alias *aliases = NULL, *testAlias = NULL;
struct aliasId *aliasId = NULL;
boolean idAdded = FALSE;

/* store marker names keyed by ID and marker UniSTS IDs indexed by name. */
/* there can be many names per ID and many IDs per name */

aliasHash = newHash(16);
aliasByNameHash = newHash(18);

while (lineFileChopNext(uaf, words, 2) )
    {
    id = cloneString(words[0]);
    /* allocate memory for alias structure */
    AllocVar(aliases);
    nameCount = chopByChar(words[1], ';', aliases->names, ArraySize(aliases->names));
    for (i = 0; i < nameCount; i++)
        {
        /* add alias to hash keyed by alias, value is UniSTS ID. */
        /* alias can have multiple IDs */
        idAdded = FALSE;
        name = cloneString(aliases->names[i]);
        /* get existing aliasId struct from hash for this name if exists */
        /* else allocate memory for an aliasId struct */
        /* and initialize array of ids */
        if ((aliasId = hashFindVal(aliasByNameHash, name)) == NULL)
           {
           AllocVar(aliasId);
           for (j = 0; j < MAXIDS; j++)
               {
               aliasId->ids[j] = NULL;
               }
          }
        for (k = 0; (k < MAXIDS) && !idAdded; k++)
            {  
            /* find next empty slot in array to add UniSTS ID */
            if ((aliasId->ids[k] == NULL) && (!idAdded))
               {
               aliasId->ids[k] = id;  
               idAdded = TRUE; 
               }
            }     
        addHashElUnique(aliasByNameHash, name, aliasId);
        }
    /* add entry of "0" to signify the end of the array */
    aliases->names[i] = "0";  
    /* Add this entry to a hash keyed by UniSTS id, hash key must be a string */
    addHashElUnique(aliasHash, id, aliases);
    }
}
Exemple #14
0
boolean read_fastq_auto(struct fastq_auto *fq, struct lineFile *lf, boolean just_seq_qual)
/* fill in fastq struct from open lineFile.  return FALSE if at EOF */
/* set just_seq_qual=TRUE to skip loading everything except the sequence */
/* and quality information. */
{
    char *line;
    int len = 0;
    boolean neof = lineFileNext(lf, &line, &len);
    if (neof)
    {
	int i;
	int qual_size;
        /* should be header */
	if ((len <= 0) || (line[0] != '@'))
	    errAbort("Expecting header. Problem on line %d\n", lf->lineIx);
	if (!just_seq_qual)
	{
	    char *words[7];
	    int numWords;
	    numWords = chopByChar(line, ':', words, 6);
	    strcpy(fq->machine, words[0] + 1);
	    fq->flow_cell = sqlSigned(words[1]);
	    fq->tile = sqlSigned(words[2]);
	    fq->tile_x = sqlSigned(words[3]);
	    words[5] = chopPrefixAt(words[4], '#');
	    words[6] = chopPrefixAt(words[5], '/');
	    fq->tile_y = sqlSigned(words[4]);
	    fq->multiplex_index = sqlSigned(words[5]);
	    fq->pair_num = sqlSigned(words[6]);
	}
	/* read the sequence */
	fq->seq[0] = '\0';
	while ((neof = lineFileNext(lf, &line, &len)) && (len > 0) && (line[0] != '+'))
	    strcat(fq->seq, line);
	if (!neof)
	    errAbort("incomplete fastq file.  early EOF");
	fq->seq_size = strlen(fq->seq);
        /* at the point of the quality header.  who cares, read the quality */
	fq->qual[0] = '\0';
	while ((neof = lineFileNext(lf, &line, &len)) && (len > 0) && (line[0] != '@'))
	    strcat(fq->qual, line);
	if ((len > 0) && (line[0] == '@'))
	    lineFileReuse(lf);
	qual_size = strlen(fq->qual);
	if (qual_size != fq->seq_size)
	    errAbort("something wrong line %d.  sequence size (%d) should match quality size (%d)\n", 
		     lf->lineIx, fq->seq_size, qual_size);
	/* convert Illumina 1.3+ quals to Sanger */
	for (i = 0; i < qual_size; i++)
	    fq->qual[i] -= 64;
    }
    else 
	return FALSE;
    return TRUE;
}
Exemple #15
0
void processPrimers(struct lineFile *pf, FILE *of)
/* Read and process isPCR file and sts locations */
{
int lineSize, wordCount;
char *line;
char *words[21];
char *dbsts_name, *dbsts[4], *currDbsts;
struct sts *sts=NULL;
struct psl *psl;
struct place *place;

 currDbsts = "\0";
while (lineFileNext(pf, &line, &lineSize))
    {
    wordCount = chopTabs(line, words);
    if (wordCount != 21)
	errAbort("Bad line %d of %s\n", pf->lineIx, pf->fileName);
    psl = pslLoad(words);
    dbsts_name = cloneString(psl->qName);
    wordCount = chopByChar(dbsts_name, '_', dbsts, ArraySize(dbsts));
    if (differentString(dbsts[1], currDbsts))
      {
	if (sts != NULL)
	  {
	    filterPrimersAndWrite(of, sts);
	    /* stsFree(&sts); */
	    freez(&currDbsts);
	  }
	currDbsts = cloneString(dbsts[1]);
	sts = NULL;
	if (hashLookup(stsHash, dbsts[1]))
	  sts = hashMustFindVal(stsHash, dbsts[1]);
      }
    if (sts)
      {
	AllocVar(place);
	/* Check if this psl record is already present */
	if (!pslInList(place->psl, psl))
	  {
	    slAddHead(&place->psl, psl);
	    place->unali = calcUnali(sts, psl);
	    place->sizeDiff = calcSizeDiff(sts, psl);
	    place->badBits = calcBadBits(place);
	    if (place->sizeDiff < (200 - (place->badBits * 50)))
	      slAddHead(&sts->place, place);
	    else
	      placeFree(&place);
	  }
      }
    }
 if (sts != NULL)
   filterPrimersAndWrite(of, sts);
}
Exemple #16
0
char *unburyAcc(struct lineFile *lf, char *longNcbiName)
/* Return accession given a long style NCBI name.  
 * Cannibalizes the longNcbiName. */
{
char *parts[5];
int partCount;

partCount = chopByChar(longNcbiName, '|', parts, ArraySize(parts));
if (partCount < 4) 
    errAbort("Badly formed longNcbiName line %d of %s\n", lf->lineIx, lf->fileName);
chopSuffix(parts[3]);
return parts[3];
}
struct psl  *pslFromBigPsl( char *chrom, struct bigBedInterval *bb, unsigned chromSize, char **seq, char **cds)
/* build a psl from a bigPsl */
{
char *extra = cloneString(bb->rest);
int numCols = 12 + 12 - 3;
char *row[numCols];
int wordCount = chopByChar(extra, '\t', row, numCols);
assert(wordCount == numCols);

struct psl *psl;
int ii;
int sizeOne;
AllocVar(psl);

psl->qName = cloneString(row[0]); 
psl->strand[0] = *row[2];
if ((cds != NULL) && row[15] != NULL)
    *cds = cloneString(row[15]);

if ((seq != NULL) && row[14] != NULL)
    *seq = cloneString(row[14]);
psl->match = sqlUnsigned(row[17]);
psl->misMatch = sqlUnsigned(row[18]);
psl->repMatch = sqlUnsigned(row[19]);
psl->nCount = sqlUnsigned(row[20]);
psl->tName = chrom;
psl->tStart = bb->start;
psl->tEnd = bb->end;
psl->tSize = chromSize;
psl->blockCount = sqlSigned(row[6]);
sqlUnsignedDynamicArray(row[7], &psl->blockSizes, &sizeOne);
assert(sizeOne == psl->blockCount);
sqlUnsignedDynamicArray(row[8], &psl->tStarts, &sizeOne);
assert(sizeOne == psl->blockCount);
psl->qStart = sqlSigned(row[9]); 
psl->qEnd = sqlSigned(row[10]); 
psl->strand[1] = *row[11];
psl->strand[1] = 0;
psl->qSize = sqlSigned(row[12]); 
sqlUnsignedDynamicArray(row[13], &psl->qStarts, &sizeOne);
assert(sizeOne == psl->blockCount);
for(ii=0; ii < psl->blockCount; ii++)
    {
    psl->tStarts[ii] += psl->tStart;
//    psl->qStarts[ii] += psl->qStart;
    }

return psl;
}
Exemple #18
0
static void setStepSize(char *spec)
/*	given *spec: "step=<position>", parse and set stepSize and dataSpan */
{
char *wordPairs[2];
int wc;
char *clone;

clone = cloneString(spec);
wc = chopByChar(spec, '=', wordPairs, 2);
if (wc != 2)
    errAbort("Expecting step=<size>, no <size> found in %s at line %lu",
	clone, lineCount);
stepSize=sqlLongLong(wordPairs[1]);
freeMem(clone);
}
Exemple #19
0
static struct variant *variantFromVcfRow(struct annoGratorGpVar *self, struct annoRow *row,
					 char *refAllele)
/* Translate vcf array of words into variant. */
{
char **words = row->data;
// VCF may use abbreviated refAllele, so use VCF's refAllele to detect allele->isReference
// instead of the actual refAllele that's passed in.  But skip the initial extra base if
// necessary, i.e. if 1-based vcfStart is the same as row->start.
uint vcfStart = atoll(words[1]);
int offset = (vcfStart == row->start) ? 1 : 0;
char *vcfRefAllele = words[3] + offset;
char *alStr = vcfGetSlashSepAllelesFromWords(words, self->dyScratch);
unsigned alCount = chopByChar(alStr, '/', NULL, 0);
return variantNew(row->chrom, row->start, row->end, alCount, alStr, vcfRefAllele, self->lm);
}
Exemple #20
0
static void setDataSpan(char *spec)
/*	given *spec: "dataSpan=N",  set parse and dataSpan to N	*/
{
char *wordPairs[2];
int wc;
char *clone;

clone = cloneString(spec);
wc = chopByChar(spec, '=', wordPairs, 2);
if (wc != 2)
    errAbort("Expecting span=N, no N found in %s at line %lu",
	clone, lineCount);
dataSpan = sqlLongLong(wordPairs[1]);
freeMem(clone);
}
Exemple #21
0
struct slPair *trackDbParseCompositeSettingsByView(char *input)
/* Parse something that looks like:
 * wigView:windowingFunction=mean+whiskers,viewLimits=0:1000 bedView:minScore=200  
 * Into
 *    slPair "wigView", 
 * 	 { slPair "windowingFunction", "mean+whiskers" }
 *	 { slPair "viewLimits", "0:1000" }
 *    slPair "bedView",
 * 	 { slPair "minScore", "200" } */
{
char *inBuf = cloneString(input);
struct slPair *viewList = NULL, *view;
char *words[32];
int cnt,ix;
cnt = chopLine(inBuf, words);
for(ix=0;ix<cnt;ix++)
    {
    char *viewName = words[ix];
    char *settings = strchr(viewName, ':');
    struct slPair *el, *list = NULL;
    if (settings == NULL)
        errAbort("Missing colon in settingsByView on %s", viewName);
    *settings++ = 0;
    char *words[32];
    int cnt,ix;
    cnt = chopByChar(settings,',',words,ArraySize(words));
    for (ix=0; ix<cnt; ix++)
        {
	char *name = words[ix];
	char *val = strchr(name, '=');
	if (val == NULL)
	    errAbort("Missing equals in settingsByView on %s", name);
	*val++ = 0;
	AllocVar(el);
	el->name = cloneString(name);
	el->val = cloneString(val);
	slAddHead(&list,el);
	}
    slReverse(&list);
    AllocVar(view);
    view->name = cloneString(viewName);
    view->val = list;
    slAddHead(&viewList, view);
    }
slReverse(&viewList);
freeMem(inBuf);
return viewList;
}
Exemple #22
0
static void parseInfoColumn(struct vcfFile *vcff, struct vcfRecord *record, char *string)
/* Translate string into array of vcfInfoElement. */
{
if (sameString(string, "."))
    {
    record->infoCount = 0;
    return;
    }
char *elWords[VCF_MAX_INFO];
record->infoCount = chopByChar(string, ';', elWords, ArraySize(elWords));
if (record->infoCount >= VCF_MAX_INFO)
    vcfFileErr(vcff, "INFO column contains at least %d elements; "
	       "VCF_MAX_INFO may need to be increased in vcf.c!", VCF_MAX_INFO);
record->infoElements = vcfFileAlloc(vcff, record->infoCount * sizeof(struct vcfInfoElement));
char *emptyString = vcfFilePooledStr(vcff, "");
int i;
for (i = 0;  i < record->infoCount;  i++)
    {
    char *elStr = elWords[i];
    char *eq = strchr(elStr, '=');
    struct vcfInfoElement *el = &(record->infoElements[i]);
    if (eq == NULL)
	{
	el->key = vcfFilePooledStr(vcff, elStr);
	enum vcfInfoType type = typeForInfoKey(vcff, el->key);
	if (type != vcfInfoFlag)
	    {
	    vcfFileErr(vcff, "Missing = after key in INFO element: \"%s\" (type=%d)",
		       elStr, type);
	    if (type == vcfInfoString)
		{
		el->values = vcfFileAlloc(vcff, sizeof(union vcfDatum));
		el->values[0].datString = emptyString;
		}
	    }
	continue;
	}
    *eq = '\0';
    el->key = vcfFilePooledStr(vcff, elStr);
    enum vcfInfoType type = typeForInfoKey(vcff, el->key);
    char *valStr = eq+1;
    el->count = parseInfoValue(record, el->key, type, valStr, &(el->values), &(el->missingData));
    if (el->count >= VCF_MAX_INFO)
	vcfFileErr(vcff, "A single element of the INFO column has at least %d values; "
	       "VCF_MAX_INFO may need to be increased in vcf.c!", VCF_MAX_INFO);
    }
}
Exemple #23
0
int lineFileChopCharNext(struct lineFile *lf, char sep, char *words[], int maxWords)
/* Return next non-blank line that doesn't start with '#' chopped into
   words delimited by sep. */
{
int lineSize, wordCount;
char *line;

while (lineFileNext(lf, &line, &lineSize))
    {
    if (line[0] == '#')
        continue;
    wordCount = chopByChar(line, sep, words, maxWords);
    if (wordCount != 0)
        return wordCount;
    }
return 0;
}
Exemple #24
0
int lineFileChopNextTab(struct lineFile *lf, char *words[], int maxWords)
/* Return next non-blank line that doesn't start with '#' chopped into words
 * on tabs */
{
int lineSize, wordCount;
char *line;

while (lineFileNext(lf, &line, &lineSize))
    {
    if (line[0] == '#')
        continue;
    wordCount = chopByChar(line, '\t', words, maxWords);
    if (wordCount != 0)
        return wordCount;
    }
return 0;
}
Exemple #25
0
static void parseFilterColumn(struct vcfFile *vcff, struct vcfRecord *record, char *filterStr)
/* Transform ;-separated filter codes into count + string array. */
{
// We don't want to modify something allocated with vcfFilePooledStr because that uses
// hash element names for storage!  So don't make a vcfFilePooledStr copy of filterStr and
// chop that; instead, chop a temp string and pool the words separately.
static struct dyString *tmp = NULL;
if (tmp == NULL)
    tmp = dyStringNew(0);
dyStringClear(tmp);
dyStringAppend(tmp, filterStr);
record->filterCount = countChars(filterStr, ';') + 1;
record->filters = vcfFileAlloc(vcff, record->filterCount * sizeof(char **));
(void)chopByChar(tmp->string, ';', record->filters, record->filterCount);
int i;
for (i = 0;  i < record->filterCount;  i++)
    record->filters[i] = vcfFilePooledStr(vcff, record->filters[i]);
}
Exemple #26
0
static void setChromName(char *spec)
/*	given *spec: "chrom=<name>", parse and set chromName, featureName */
{
char *wordPairs[2];
int wc;
char *clone;

clone = cloneString(spec);
wc = chopByChar(spec, '=', wordPairs, 2);
if (wc != 2)
    errAbort("Expecting chrom=<name>, no <name> found in %s at line %lu",
	clone, lineCount);
freez(&chromName);
chromName=cloneString(wordPairs[1]);
freez(&featureName);
featureName=cloneString(wordPairs[1]);
freeMem(clone);
}
void readPrimerInfo(struct lineFile *sf)
/* Read in primer info from all.primers file */
{
int wordCount;
char *words[5];
char *dist1, *dist[2];
struct sts *sts;

stsHash = newHash(16);

while (lineFileChopCharNext(sf, '\t', words, 5))
    {
      verbose(2, "# line %d words1-4: '%s' '%s' '%s' '%s'\n", sf->lineIx, words[1], words[2], words[3], words[4]);
      if (words[1] && words[2] && words[3] && words[4])
	{
	  AllocVar(sts);
	  sts->dbstsId = cloneString(words[0]);
	  sts->leftPrimer = cloneString(words[1]);
	  sts->rightPrimer = cloneString(words[2]);
	  sts->size = cloneString(words[3]);
	  sts->ucscId = cloneString(words[4]);
	  sts->found = FALSE;
	  dist1 = cloneString(words[3]);
	  if (sts->leftPrimer && dist1 && differentWord("-", dist1))
	    {
	      wordCount = chopByChar(dist1, '-', dist, ArraySize(dist));
	      sts->minSize = sqlUnsigned(dist[0]);
	      if (wordCount == 1) 
		sts->maxSize = sqlUnsigned(dist[0]);
	      else
		sts->maxSize = sqlUnsigned(dist[1]);
	      if (sts->maxSize == 0) 
		sts->maxSize = 1000;
	      sts->next = NULL;
	      sts->place = NULL;
	      sts->epcr = NULL;
	      hashAdd(stsHash, sts->dbstsId, sts);
	    }
	  slAddHead(&stsList, sts);
	}
    }
}
Exemple #28
0
static void setFixedStart(char *spec)
/*	given *spec: "start=<position>", parse and set fixedStart */
{
char *wordPairs[2];
int wc;
char *clone;

clone = cloneString(spec);
wc = chopByChar(spec, '=', wordPairs, 2);
if (wc != 2)
    errAbort("Expecting start=<position>, no <position> found in %s at line %lu",
	clone, lineCount);
fixedStart=sqlLongLong(wordPairs[1]);
if (fixedStart == 0)
    errAbort("Found start=0 at line %lu, the first chrom position is 1, not 0",
	lineCount);
else
    fixedStart = BASE_0(fixedStart);	/* zero relative half-open */
freeMem(clone);
}
Exemple #29
0
int bigBedIntervalToRow(struct bigBedInterval *interval, char *chrom, char *startBuf, char *endBuf,
	char **row, int rowSize)
/* Convert bigBedInterval into an array of chars equivalent to what you'd get by
 * parsing the bed file. The startBuf and endBuf are used to hold the ascii representation of
 * start and end.  Note that the interval->rest string will have zeroes inserted as a side effect.
 */
{
int fieldCount = 3;
sprintf(startBuf, "%u", interval->start);
sprintf(endBuf, "%u", interval->end);
row[0] = chrom;
row[1] = startBuf;
row[2] = endBuf;
if (!isEmpty(interval->rest))
    {
    int wordCount = chopByChar(interval->rest, '\t', row+3, rowSize-3);
    fieldCount += wordCount;
    }
return fieldCount;
}
Exemple #30
0
void hubCommandAndPrint(char *command)
/* Send command to hub, and print response until blank line. */
{
char *line = NULL;
struct slRef *list = NULL, *ref;
struct paraMessage pm;
struct paraMultiMessage pmm;
int count = 0;
char *row[256];

/* Issue command and suck down response quickly into memory. */
if (!commandHubExt(command, &pm, &pmm))
    errAbort("Couldn't send '%s' command to paraHub", command);

/* ensure the multi-message response comes from the correct ip and has no duplicate msgs*/

for (;;)
    {
    if (!pmmReceive(&pmm, hubRudp))
	break;
    if (pm.size == 0)
        break;

    count = chopByChar(pm.data, '\n', row, sizeof(row));

    if (count > 1) --count;  /* for multiline, count is inflated by one */

    int i;
    for(i=0; i<count; ++i)
        refAdd(&list, cloneString(row[i]));

    }
slReverse(&list);

/* Print results. */
for (ref = list; ref != NULL; ref = ref->next)
    {
    line = ref->val;
    puts(line);
    }
}