Esempio n. 1
0
static void requireStartEndLines(char *fileName, char *startLine, char *endLine)
/* Make sure first real line in file is startLine, and last is endLine.  Tolerate
 * empty lines and white space. */
{
char *reportFileName = fileNameOnly(fileName);
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *line;

/* Get first real line and make sure it is not empty and matches start line. */
if (!lineFileNextReal(lf, &line))
    errAbort("%s is empty", reportFileName);
line = trimSpaces(line);
if (!sameString(line, startLine))
    errAbort("%s doesn't start with %s as expected", reportFileName, startLine);

boolean lastSame = FALSE;

for (;;)
    {
    if (!lineFileNextReal(lf, &line))
        break;
    line = trimSpaces(line);
    lastSame = sameString(line, endLine);
    }
if (!lastSame)
    errAbort("%s doesn't end with %s as expected", reportFileName, endLine);

lineFileClose(&lf);
}
struct wigSection *wigSectionRead(struct lineFile *lf)
/* Parse out next section of wig. */
{
    static double *vals = NULL;
    static int valAlloc = 0;

    /* Get "fixedStep" line and parse it. */
    char *line;
    if (!lineFileNextReal(lf, &line))
        return NULL;
    char *pattern = "fixedStep ";
    int patSize = 10;
    if (!startsWith(pattern, line))
        errAbort("Expecting fixedStep line %d of %s", lf->lineIx, lf->fileName);
    line += patSize;
    struct hash *varHash = hashVarLine(line, lf->lineIx);
    int step = sqlUnsigned(requiredVal(lf, varHash, "step"));
    int start = sqlUnsigned(requiredVal(lf, varHash, "start"));
    char *chrom = cloneString(requiredVal(lf, varHash, "chrom"));
    hashFree(&varHash);

    /* Parse out numbers until next fixedStep. */
    int valCount = 0;
    int i;
    for (;;)
    {
        if (!lineFileNextReal(lf, &line))
            break;
        if (startsWith(pattern, line))
        {
            lineFileReuse(lf);
            break;
        }
        for (i=0; i<step; ++i)
        {
            if (valCount >= valAlloc)
            {
                int newAlloc = valAlloc + 1024;
                ExpandArray(vals, valAlloc, newAlloc);
                valAlloc = newAlloc;
            }
            vals[valCount] = lineFileNeedDouble(lf, &line, 0);
            ++valCount;
        }
    }

    /* Create wigSection. */
    struct wigSection *section;
    AllocVar(section);
    section->chrom = chrom;
    section->chromStart = start;
    section->chromEnd = start + valCount;
    section->vals = CloneArray(vals, valCount);
    return section;
}
Esempio n. 3
0
void makeConditions(char *input, char *output)
/* Parse input in form:
 *    transcriptionFactor   list, of, conditions
 * into
 *    transcriptionFactor<tab>list
 *    transcriptionFactor<tab>of
 *    transcriptionFactor<tab>conditions
 */    
{
struct lineFile *lf = lineFileOpen(input, TRUE);
FILE *f = mustOpen(output, "w");
char *line;
while (lineFileNextReal(lf, &line))
    {
    char *tf, *cond;
    tf = nextWord(&line);
    while ((cond = nextWord(&line)) != NULL)
        {
	stripChar(cond, ',');
	fprintf(f, "%s\t%s\n", tf, cond);
	}
    }
carefulClose(&f);
lineFileClose(&lf);
}
Esempio n. 4
0
void wordStoreLoadMonomerOrder(struct wordStore *store, char *readsFile, char *fileName)
/* Read in a file with one line for each monomer type, containing a word for each
 * monomer variant.  Requires all variants already be in store.  The readsFile is passed
 * just for nicer error reporting. */
{
/* Stuff for processing file a line at a time. */
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *line, *word;

/* Set up variables we'll put results in in store. */
store->typeHash = hashNew(0);
store->typeList = NULL;

while (lineFileNextReal(lf, &line))
    {
    struct wordType *type;
    AllocVar(type);
    slAddHead(&store->typeList, type);
    while ((word = nextWord(&line)) != NULL)
        {
	struct wordInfo *info = hashFindVal(store->infoHash, word);
	if (info == NULL)
	    errAbort("%s is in %s but not %s", word, lf->fileName, readsFile);
	struct wordInfoRef *ref;
	AllocVar(ref);
	ref->val = info;
	slAddHead(&type->list, ref);
	hashAddUnique(store->typeHash, word, type);
	}
    }
slReverse(&store->typeList);
lineFileClose(&lf);
verbose(2, "Added %d types containing %d words from %s\n", 
    slCount(store->typeList), store->typeHash->elCount, fileName);
}
Esempio n. 5
0
long long currentVmPeak()
/* return value of peak Vm memory usage (if /proc/ business exists) */
{
long long vmPeak = 0;

pid_t pid = getpid();
char temp[256];
safef(temp, sizeof(temp), "/proc/%d/status", (int) pid);
struct lineFile *lf = lineFileMayOpen(temp, TRUE);
if (lf)
    {
    char *line;
    while (lineFileNextReal(lf, &line))
	{	// typical line: 'VmPeak:     62646196 kB'
		// seems to always be kB
	if (stringIn("VmPeak", line))
	    {
	    char *words[3];
	    chopByWhite(line, words, 3);
	    vmPeak = sqlLongLong(words[1]);	// assume always 2nd word
	    break;
	    }
	}
    lineFileClose(&lf);
    }

return vmPeak;
}
boolean mgcStatusTblCopyRow(struct lineFile *inLf, FILE *outFh)
/* read a copy one row of a status table tab file without
 * fully parsing.  Expand if optional fields are missing  */
{
char *line;
int numCols, i;
char *row[MGCSTATUS_NUM_COLS];
if (!lineFileNextReal(inLf, &line))
    return FALSE;
numCols = chopTabs(line, row);
numCols = min(numCols, MGCSTATUS_NUM_COLS);
lineFileExpectAtLeast(inLf, MGCSTATUS_MIN_NUM_COLS, numCols);
for (i = 0; i < numCols; i++)
    {
    if (i > 0)
        fputc('\t', outFh);
    fputs(row[i], outFh);
    }

/* pad */
for (; i < MGCSTATUS_NUM_COLS; i++)
    fputc('\t', outFh);
fputc('\n', outFh);

return TRUE;
}
void setupTable(struct sqlConnection *conn) 
/* Set up the autoTest table for testing. Call dropTable() later
 to remove table. */
{
struct lineFile *lf = lineFileOpen("output/newTest.sql", TRUE);
char *update = NULL;
char *line = NULL;
struct dyString *ds = newDyString(256);
if(sqlTableExists(conn, testTableName))
    errAbort("dbLinkTest.c::setupTable() - Table %s.%s already exists. Can't create another.",
             sqlGetDatabase(conn), testTableName);
while(lineFileNextReal(lf, &line)) 
    {
    char *tmp = strstr(line, "not null");
    if(tmp != NULL)
	{
	*tmp = ',';
	tmp++;
	*tmp = '\0';
	}
    subChar(line, '\t', ' ');
    dyStringPrintf(ds, "%s", line);
    }
update = replaceChars(ds->string, "PRIMARY KEY", "UNIQUE");
sqlUpdate(conn, update);
freez(&update);
dyStringFree(&ds);
lineFileClose(&lf);
}
Esempio n. 8
0
static void readTaggedNumLine(struct lineFile *lf, char *tag, 
	int count, int *intOut,  double *floatOut)
/* Read in a line that starts with tag and then has count numbers.
 * Complain and die if tag is unexpected or other problem occurs. 
 * Put output as integers and/or floating point into intOut and 
 * floatOut. */
{
char *line;
int i = 0;
char *word;
if (!lineFileNextReal(lf, &line))
   lineFileUnexpectedEnd(lf);
word = nextWord(&line);
if (!sameWord(tag, word))
    errAbort("Expecting %s got %s line %d of %s",
             tag, word, lf->lineIx, lf->fileName);
for (i = 0; i < count; ++i)
    {
    word = nextWord(&line);
    if (word == NULL)
        errAbort("Not enough numbers line %d of %s", lf->lineIx, lf->fileName);
    if (!isdigit(word[0]))
        errAbort("Expecting number got %s line %d of %s",
	         word, lf->lineIx, lf->fileName);
    if (intOut)
	intOut[i] = atoi(word);
    if (floatOut)
        floatOut[i] = atof(word);
    }
word = nextWord(&line);
if (word != NULL)
        errAbort("Too many numbers line %d of %s", lf->lineIx, lf->fileName);
}
int findBedSize(char *fileName, struct lineFile **retLf)
/* Read first line of file and figure out how many words in it. */
/* Input file could be stdin, in which case we really don't want to open,
 * read, and close it here.  So if retLf is non-NULL, return the open 
 * linefile (having told it to reuse the line we just read). */
{
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *words[64], *line;
int wordCount;

if (!lineFileNextReal(lf, &line))
    if (ignoreEmpty)
        return(0);
line = cloneString(line);
if (strictTab)
    wordCount = chopTabs(line, words);
else
    wordCount = chopLine(line, words);
if (wordCount == 0)
    errAbort("%s appears to be empty", fileName);
if (retLf != NULL)
    {
    lineFileReuse(lf);
    *retLf = lf;
    }
else
    lineFileClose(&lf);
freeMem(line);
return wordCount;
}
Esempio n. 10
0
struct cnFill *cnFillRead(struct chainNet *net, struct lineFile *lf)
/* Recursively read in list and children from file. */
{
char *line;
int d, depth = 0;
struct cnFill *fillList = NULL;
struct cnFill *fill = NULL;

for (;;)
    {
    if (!lineFileNextReal(lf, &line))
	break;
    d = countLeadingChars(line, ' ');
    if (fill == NULL)
        depth = d;
    if (d < depth)
	{
	lineFileReuse(lf);
	break;
	}
    if (d > depth)
        {
	lineFileReuse(lf);
	fill->children = cnFillRead(net, lf);
	}
    else
        {
	fill = cnFillFromLine(net->nameHash, lf, line);
	slAddHead(&fillList, fill);
	}
    }
slReverse(&fillList);
return fillList;
}
Esempio n. 11
0
struct hash *readDescriptionFile(char *fileName)
/* Return two column file keyed by first column with
 * values in second column.  Strip any tabs from values. */
{
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *line;
struct hash *hash = newHash(16);
while (lineFileNextReal(lf, &line))
    {
    char *key = nextWord(&line);
    char *val = skipLeadingSpaces(line);
    if (val != NULL && val[0] != 0)
        {
        char *desc = hashFindVal(hash, key);
	subChar(val, '\t', ' ');
	stripChar(val, '\r');
        /* if gene exists in hash */
	if (desc != NULL) 
            {
	    struct dyString *dy = dyStringNew(1024);
            dyStringPrintf(dy, "%s  ", desc);
            dyStringAppend(dy, val);
            val = cloneString(dy->string);
            dyStringFree(&dy); 
            }
        /* add to gene and description to hash */
        hashAdd(hash, key, cloneString(val));
	}
    }
lineFileClose(&lf);
return hash;
}
void fillInBioHash(char *fileName, struct hash *bioHash)
/* Fill in the bioHash with key/value pairs from file. */
{
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *line = NULL;
int regSize = 0;
while(lineFileNextReal(lf, &line)) 
    {
    char *key = NULL;
    char *val = NULL;
    char *mark = NULL;
    mark = strchr(line, '=');
    if(mark == NULL) // Error: not in boulder IO format.
	errAbort("pickCassettePcrPrimers::fillInBioHash() - ",
		 "Couldn't find '=' in line %s. File %s doesn't appear to be in boulderIO format.",
		 line, fileName);
    if(mark == line) // First character is '=' means end of record.
	break;
    key = line;
    val = mark+1;
    *mark = '\0';
    hashAddUnique(bioHash, key, cloneString(val));
    }
lineFileClose(&lf);
}
Esempio n. 13
0
static void addExtras(char *extraFile, struct trackHubCheckOptions *checkOptions)
/* Add settings from extra file (e.g. for specific hub display site) */
{
verbose(2, "Accepting extra settings in '%s'\n", extraFile);
checkOptions->extraFile = extraFile;
checkOptions->extra = hashNew(0);
struct lineFile *lf = NULL;
if (startsWith("http", extraFile))
    {
    struct dyString *ds = netSlurpUrl(extraFile);
    char *s = dyStringCannibalize(&ds);
    lf = lineFileOnString(extraFile, TRUE, s);
    }
else
    {
    lf = lineFileOpen(extraFile, TRUE);
    }
char *line;
while (lineFileNextReal(lf, &line))
    {
    hashAdd(checkOptions->extra, line, NULL);
    }
lineFileClose(&lf);
verbose(3, "Found %d extra settings\n", hashNumEntries(checkOptions->extra));
}
Esempio n. 14
0
void peakClusterMakerAddFromSource(struct peakClusterMaker *maker, struct peakSource *source)
/* Read through data source and add items to it to rangeTrees in maker */
{
struct hash *chromHash = maker->chromHash;
struct lineFile *lf = lineFileOpen(source->dataSource, TRUE);
struct lm *lm = chromHash->lm;	/* Local memory pool - share with hash */
char *row[source->minColCount];
struct peakItem *item;
char *line;
while (lineFileNextReal(lf, &line))
    {
    char *asciiLine = lmCloneString(lm, line);
    int wordCount = chopByWhite(line, row, source->minColCount);
    lineFileExpectAtLeast(lf, source->minColCount, wordCount);
    char *chrom = row[source->chromColIx];
    struct hashEl *hel = hashLookup(chromHash, chrom);
    if (hel == NULL)
        {
	struct rbTree *tree = rangeTreeNewDetailed(lm, maker->stack);
	hel = hashAdd(chromHash, chrom, tree);
	}
    struct rbTree *tree = hel->val;
    lmAllocVar(lm, item);
    item->chrom = hel->name;
    item->chromStart = sqlUnsigned(row[source->startColIx]);
    item->chromEnd = sqlUnsigned(row[source->endColIx]);
    item->score = sqlDouble(row[source->scoreColIx]) * source->normFactor;
    if (item->score > 1000) item->score = 1000;
    item->source = source;
    item->asciiLine = asciiLine;
    rangeTreeAddValList(tree, item->chromStart, item->chromEnd, item);
    }
lineFileClose(&lf);
}
Esempio n. 15
0
struct dyString *readAndReplaceTableName(char *fileName, char *table)
/* Read file into string.  While doing so strip any leading comments
 * and insist that the first non-comment line contain the words
 * "create table" followed by a table name.  Replace the table name,
 * and copy the rest of the file verbatem. */
{
    struct lineFile *lf = lineFileOpen(fileName, TRUE);
    struct dyString *dy = dyStringNew(0);
    char *line, *word;
    if (!lineFileNextReal(lf, &line))
        errAbort("No real lines in %s\n", fileName);
    word = nextWord(&line);
    if (!sameWord(word, "create"))
        errAbort("Expecting first word in file to be CREATE. Got %s", word);
    word = nextWord(&line);
    if (word == NULL || !sameWord(word, "table"))
        errAbort("Expecting second word in file to be table. Got %s", emptyForNull(word));
    word = nextWord(&line);
    if (word == NULL)
        errAbort("Expecting table name on same line as CREATE TABLE");
    sqlDyStringPrintf(dy, "CREATE TABLE %s ", table);
    if (line != NULL)
        dyStringAppend(dy, line);
    dyStringAppendC(dy, '\n');
    while (lineFileNext(lf, &line, NULL))
    {
        dyStringAppend(dy, line);
        dyStringAppendC(dy, '\n');
    }
    lineFileClose(&lf);
    return dy;
}
Esempio n. 16
0
int fillSizes(char *sizes)
/**
 * Fills the hash table of chrom sizes
 *
 *
 *
 */
{
  struct lineFile *lf;
  lf = lineFileOpen(sizes,TRUE);
  char *line;
  struct sizes_hash *s;
  while(lineFileNextReal(lf,&line)){
    char *split[2];
    chopByWhite(line,split,2);
    s = malloc(sizeof(struct sizes_hash));
    strcpy(s->name, split[0]);
    s->length = atoi(split[1]);
    int i;
    for(i=0;i<NUMSAMPLES;i++)
      s->numHets[i] = 0;
    HASH_ADD_STR(chrSizes,name,s);
  }
  return 0;
}
Esempio n. 17
0
void makeTableDescriptions(char *database, char *asFile)
/* makeTableDescriptions - Add table descriptions to database.. */
{
struct sqlConnection *conn = sqlConnect(database);
struct lineFile *lf = lineFileOpen(asFile, TRUE);
FILE *f = hgCreateTabFile(".", "tableDescriptions");
/* Open a tab file with name corresponding to tableName in tmpDir. */
char *line;

/* struct asObject *asList = */ asParseFile(asFile);	/* Just to check syntax */

if (sqlTableExists(conn, "chromInfo"))
    errAbort("%s looks like a genome database, has chromInfo, aborting", 
    	database);

sqlRemakeTable(conn, "tableDescriptions",
   "NOSQLINJ CREATE TABLE tableDescriptions (\n"
   "  tableName varchar(255) not null,\n"
   "  autoSqlDef longblob not null,\n"
   "  gbdAnchor varchar(255) not null,\n"
   "  PRIMARY KEY(tableName(32))\n"
   ")" );

while (lineFileNextReal(lf, &line))
    {
    if (startsWith("table", line))
        {
	struct dyString *as = dyStringNew(0);
	char *name = trimSpaces(line + 6);	/* Skip over table. */
	char *escaped = NULL;

	fprintf(f, "%s\t", name);

	/* Putting lines into as. */
	for (;;)
	    {
	    char *s;
	    dyStringAppend(as, line);
	    dyStringAppendC(as, '\n');
	    s = skipLeadingSpaces(line);
	    if (s[0] == ')')
	        break;
	    if (!lineFileNext(lf, &line, NULL))
	        errAbort("Unexpected end of file, missing closing paren in %s",
			lf->fileName);
	    }
	escaped = needMem(2*as->stringSize+1);
	fprintf(f, "%s\t", sqlEscapeTabFileString2(escaped, as->string));
	fprintf(f, "\n");

	freez(&escaped);
	dyStringFree(&as);
	}
    else
        errAbort("Expecting table line %d of %s", lf->lineIx, lf->fileName);
    }
hgLoadTabFile(conn, ".", "tableDescriptions", &f);
}
Esempio n. 18
0
void loadAccs(char *accFile, struct hash *accTbl)
/* load accessions from a file */
{
struct lineFile *lf = lineFileOpen(accFile, TRUE);
char *line;
while (lineFileNextReal(lf, &line))
    addAcc(accTbl, trimSpaces(line));

lineFileClose(&lf);
}
Esempio n. 19
0
void edwFixRevoked(char *database, char *inFile)
/* edwFixRevoked - Mark as deprecated files that are revoked in ENCODE2. */
/* inFile is in format:
 *    metaVariable objStatus revoked [- reason]
 *    metaObject name */
{
struct sqlConnection *conn = edwConnect();
struct lineFile *lf = lineFileOpen(inFile, TRUE);
char *line;
char *defaultReason = "Revoked in ENCODE2";
char *reason = defaultReason;
while (lineFileNextReal(lf, &line))
    {
    if (startsWithWord("metaVariable", line))
        {
	char *pattern = "metaVariable objStatus revoked";
	if (startsWithWord(pattern, line))
	    {
	    reason = skipLeadingSpaces(line + strlen(pattern));
	    if (isEmpty(reason))
	        reason = defaultReason;
	    else
	        {
		if (reason[0] == '-')
		   reason = skipLeadingSpaces(reason + 1);
		reason = cloneString(reason);
		}
	    }
	else
	    errAbort("??? %s\n", line);
	}
    else if (startsWithWord("metaObject", line))
        {
	char *row[3];
	int wordCount = chopLine(line, row);
	if (wordCount != 2)
	    errAbort("Strange metaobject line %d of %s\n", lf->lineIx, lf->fileName);
	char *prefix = row[1];
	if (!startsWith("wgEncode", prefix))
	    errAbort("Strange object line %d of %s\n", lf->lineIx, lf->fileName);
	char query[512];
	sqlSafef(query, sizeof(query), 
	    "select * from edwFile where submitFileName like '%s/%%/%s%%'", database, prefix);
	struct edwFile *ef, *efList = edwFileLoadByQuery(conn, query);
	printf("# %s %s\n", prefix, reason);
	for (ef = efList; ef != NULL; ef = ef->next)
	    {
	    long long id = ef->id;
	    printf("update edwFile set deprecated='%s' where id=%lld;\n", reason, id);
	    }
	}
    else
        errAbort("Unrecognized first word in %s\n", line);
    }
}
Esempio n. 20
0
char *raFoldInOneRetName(struct lineFile *lf, struct hash *hashOfHash)
/* Fold in one record from ra file into hashOfHash. 
 * This will add ra's and ra fields to whatever already
 * exists in the hashOfHash,  overriding fields of the
 * same name if they exist already. */
{
char *word, *line, *name;
struct hash *ra;
struct hashEl *hel;

/* Get first nonempty non-comment line and make sure
 * it contains name. */
if (!lineFileNextReal(lf, &line))
    return NULL;
word = nextWord(&line);
if (!sameString(word, "name"))
    errAbort("Expecting 'name' line %d of %s, got %s", 
    	lf->lineIx, lf->fileName, word);
name = nextWord(&line);
if (name == NULL)
    errAbort("Short name field line %d of %s", lf->lineIx, lf->fileName);

/* Find ra hash associated with name, making up a new
 * one if need be. */
if ((ra = hashFindVal(hashOfHash, name)) == NULL)
    {
    ra = newHash(7);
    hashAdd(hashOfHash, name, ra);
    hashAdd(ra, "name", lmCloneString(ra->lm, name));
    }

/* Fill in fields of ra hash with data up to next
 * blank line or end of file. */
for (;;)
    {
    if (!lineFileNext(lf, &line, NULL))
        break;
    line = skipLeadingSpaces(line);
    if (line[0] == 0)
        break;
    if (line[0] == '#')
        continue;
    word = nextWord(&line);
    line = skipLeadingSpaces(line);
    if (line == NULL)
        line = "";
    hel = hashLookup(ra, word);
    if (hel == NULL)
        hel = hashAdd(ra, word, lmCloneString(ra->lm, line));
    else
        hel->val = lmCloneString(ra->lm, line);
    }
return hashFindVal(ra, "name");
}
Esempio n. 21
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;
}
Esempio n. 22
0
void cnvBedToGenePred(char *bedFile, char *genePredFile)
/* convert bed format files to genePred format */
{
struct lineFile *bedLf = lineFileOpen(bedFile, TRUE);
FILE *gpFh = mustOpen(genePredFile, "w");
char *line;

while (lineFileNextReal(bedLf, &line))
    cnvBedRec(line, gpFh);

carefulClose(&gpFh);
lineFileClose(&bedLf);
}
Esempio n. 23
0
static char *mkChimeraPyScript(char *scriptFile)
/* create chimera python script from commands in scriptFile */
{
struct dyString *buf = dyStringNew(0);
dyStringAppend(buf, "from chimera import runCommand\n");
struct lineFile *lf = lineFileOpen(scriptFile, TRUE);
char *line;
while (lineFileNextReal(lf, &line))
    dyStringPrintf(buf, "runCommand(\"%s\")\n", line);

lineFileClose(&lf);
return dyStringCannibalize(&buf);
}
Esempio n. 24
0
void cnvBedToPsl(char *chromSizesFile, char *bedFile, char *pslFile)
/* convert bed format files to PSL format */
{
struct hash *chromSizes = loadChromSizes(chromSizesFile);
struct lineFile *bedLf = lineFileOpen(bedFile, TRUE);
FILE *pslFh = mustOpen(pslFile, "w");
char *line;

while (lineFileNextReal(bedLf, &line))
    cnvBedRec(line, chromSizes, pslFh);

carefulClose(&pslFh);
lineFileClose(&bedLf);
}
Esempio n. 25
0
struct hash *hashFirstWord(char *fileName)
/* Hash first word in each line. */
{
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *line, *word;
struct hash *hash = newHash(16);
while (lineFileNextReal(lf, &line))
    {
    word = nextWord(&line);
    hashAdd(hash, word, NULL);
    }
lineFileClose(&lf);
return hash;
}
struct slName *getWhiteListFromFile()
/* Read in the -justThese file and store the names of the enzymes */
/* in a list of slNames. */
{
struct slName *whiteList = NULL;
struct lineFile *lf = lineFileOpen(justThese, TRUE);
char *line;
while (lineFileNextReal(lf, &line))
    {
    struct slName *newName = newSlName(line);
    slAddHead(&whiteList, newName);
    }
lineFileClose(&lf);
return whiteList;
}
Esempio n. 27
0
void lineFileRemoveInitialCustomTrackLines(struct lineFile *lf)
/* remove initial browser and track lines */
{
char *line;
while (lineFileNextReal(lf, &line))
    {
    if (!(startsWith("browser", line) || startsWith("track", line) ))
        {
        verbose(2, "found line not browser or track: %s\n", line);
        lineFileReuse(lf);
        break;
        }
    verbose(2, "skipping %s\n", line);
    }
}
Esempio n. 28
0
void bedClip(char *inFile, char *chromSizes, char *outFile)
/* bedClip - Remove lines from bed file that refer to off-chromosome places.. */
{
struct hash *chromSizesHash = bbiChromSizesFromFile(chromSizes);
struct lineFile *lf = lineFileOpen(inFile, TRUE);
FILE *f = mustOpen(outFile, "w");
char *line;
while (lineFileNextReal(lf, &line))
    {
    char *chrom = nextWord(&line);
    char *startString = nextWord(&line);
    char *endString = nextWord(&line);
    if (endString == NULL)
        errAbort("Need at least three fields line %d of %s", lf->lineIx, lf->fileName);
    if (startString[0] == '-')
	{
	verbose(2, "Clipping negative line %d of %s\n", lf->lineIx, lf->fileName);
        continue;		// Clip off negatives
	}
    if (!isdigit(startString[0]))
        errAbort("Expecting number got %s line %d of %s", startString, lf->lineIx, lf->fileName);
    if (!isdigit(endString[0]))
        errAbort("Expecting number got %s line %d of %s", endString, lf->lineIx, lf->fileName);
    int start = sqlUnsigned(startString);
    int end = sqlUnsigned(endString);
    if (start >= end)
	{
	verbose(2, "Clipping end <= start line %d of %s\n", lf->lineIx, lf->fileName);
	continue;
	}
    struct hashEl *hel = hashLookup(chromSizesHash, chrom);
    if (hel == NULL)
        errAbort("Chromosome %s isn't in %s line %d of %s\n", chrom, chromSizes, lf->lineIx, lf->fileName);
    int chromSize = ptToInt(hel->val);
    if (end > chromSize)
	{
	verbose(2, "Clipping end > chromSize line %d of %s\n", lf->lineIx, lf->fileName);
	continue;
	}
    fprintf(f, "%s\t%s\t%s", chrom, startString, endString);
    line = skipLeadingSpaces(line);
    if (line == NULL || line[0] == 0)
        fputc('\n', f);
    else
        fprintf(f, "\t%s\n", line);
    }
carefulClose(&f);
}
Esempio n. 29
0
struct slName* loadAccList(char *fname)
{
struct slName* accList = NULL;
struct lineFile* accFh;
char *line;
accFh = lineFileOpen(fname, TRUE);

while (lineFileNextReal(accFh, &line))
    {
    line = trimSpaces(line);
    slSafeAddHead(&accList, newSlName(line));
    }

lineFileClose(&accFh);
return accList;
}
void wigSort(char *input, char *output)
/* wigSort - Sort a wig file.. */
{
struct lineFile *lf = lineFileOpen(input, TRUE);
struct pos *pos, *posList = NULL;
char *line;
while (lineFileNextReal(lf, &line))
    {
    verbose(2, "processing %s\n", line);
    AllocVar(pos);
    pos->fileOffset = lineFileTell(lf);
    if (posList != NULL)
        posList->fileSize = pos->fileOffset - posList->fileOffset;
    slAddHead(&posList, pos);
    if (stringIn("chrom=", line))
	{
	parseSteppedSection(lf, line, pos);
	}
    else
        {
	/* Check for bed... */
	char *words[5];
	int wordCount = chopLine(line, words);
	if (wordCount != 4)
	    errAbort("Unrecognized format line %d of %s:\n", lf->lineIx, lf->fileName);
	pos->chrom = cloneString(words[0]);
	pos->start = lineFileNeedNum(lf, words, 1);
	}
    }
if (posList != NULL)
    {
    posList->fileSize = lineFileTell(lf) - posList->fileOffset;
    slReverse(&posList);
    slSort(&posList, posCmp);
    }
lineFileClose(&lf);

FILE *in = mustOpen(input, "r");
FILE *out = mustOpen(output, "w");
for (pos = posList; pos != NULL; pos = pos->next)
    {
    fseek(in, pos->fileOffset, SEEK_SET);
    copyFileBytes(in, out, pos->fileSize);
    }
carefulClose(&in);
carefulClose(&out);
}