Beispiel #1
0
struct lineFile *lineFileMayOpen(char *fileName, bool zTerm)
/* Try and open up a lineFile. */
{
if (sameString(fileName, "stdin"))
    return lineFileStdin(zTerm);
else if (getDecompressor(fileName) != NULL)
    return lineFileDecompress(fileName, zTerm);
else
    {
    int fd = open(fileName, O_RDONLY);
    if (fd == -1)
        return NULL;
    return lineFileAttach(fileName, zTerm, fd);
    }
}
void checkSymlinkTargetType(char *inputList)
/* Check out the symlink to determine its type. */
{
struct lineFile *lf = NULL;
if (startsWith("stdin",inputList))
    lf = lineFileStdin(TRUE);
else
    lf = lineFileOpen(inputList, TRUE);
char *line = NULL;
while (lineFileNext(lf, &line, NULL))
    {
    // find creates paths starting with ./ in the current dir.
    if (startsWith("./", line))
	line += 2;   // skip over it
    verbose(3, "%s\n", line);
    showSymlinkType(line, prefix);
    }
lineFileClose(&lf);
}
Beispiel #3
0
int *readInConservationVals(char *fileName)
/* Open up the file and read in the conservation scores.
   return an array indexed by base position with the conservation
   scores. Free with freez() */
{
struct lineFile *lf = NULL;
int *scores = NULL;
int chromSize = optionInt("chromSize", 0);
int i = 0;
char *words[2];
if(chromSize == 0)
    errAbort("Can't have chromSize set to 0.");
warn("Reading in conservation");
setMaxAlloc(sizeof(*scores)*chromSize+1);
AllocArray(scores, chromSize);

/* Make empty data be -1, a not possible score. */
for(i = 0; i < chromSize; i++)
    scores[i] = -1;

/* Open up our conservation file. */
if(sameString(fileName, "stdin"))
    lf = lineFileStdin(TRUE);
else
    lf = lineFileOpen(fileName, TRUE);

dotForUserInit( chromSize/10 > 1 ? chromSize/10 : 1);
while(lineFileNextRow(lf, words, ArraySize(words)))
    {
    scores[atoi(words[0])] = round(atof(words[1]) * FLOAT_CHEAT);
    dotForUser();
    }
lineFileClose(&lf);
warn("Done");
return scores;
}
void ffaToFa(char *inFile, char *outDir, char *outTabName)
/* convert Greg Schulers .ffa fasta files to our .fa files */
{
struct lineFile *in;
FILE *out = NULL, *tab;
int lineSize;
char *line;
char ucscName[128];
char path[512];
static char lastPath[512];
int outFileCount = 0;
struct hash *uniqClone = newHash(16);
struct hash *uniqFrag = newHash(19);
boolean ignore = FALSE;

makeDir(outDir);
errLog = mustOpen("ffaToFa.err", "w");
tab = mustOpen(outTabName, "w");
printf("Converting %s", inFile);
fflush(stdout);
if (sameString(inFile, "stdin"))
    in = lineFileStdin(TRUE);
else
    in = lineFileOpen(inFile, TRUE);
while (lineFileNext(in, &line, &lineSize))
    {
    if (line[0] == '>')
	{
	ignore = FALSE;
	gsToUcsc(line+1, ucscName);
	faRecNameToFaFileName(outDir, ucscName, path);
	if (hashLookup(uniqFrag, ucscName))
	    {
	    ignore = TRUE;
	    warn("Duplicate %s in %s, ignoring all but first",
	    	ucscName, inFile);
	    }
	else
	    {
	    hashAdd(uniqFrag, ucscName, NULL);
	    }
	if (!sameString(path, lastPath))
	    {
	    strcpy(lastPath, path);
	    carefulClose(&out);
	    if (hashLookup(uniqClone, path))
		{
		warn("Duplicate %s in %s ignoring all but first", 
		    ucscName, inFile);
		}
	    else
		{
		hashAdd(uniqClone, path, NULL);
		out = mustOpen(path, "w");
		++outFileCount;
		if ((outFileCount&7) == 0)
		    {
		    putc('.', stdout);
		    fflush(stdout);
		    }
		}
	    }
	if (out != NULL && !ignore)
	    {
	    fprintf(out, ">%s\n", ucscName);
	    fprintf(tab, "%s\t%s\n", ucscName, line+1);
	    }
	}
    else
	{
	if (out != NULL && !ignore)
	    {
	    fputs(line, out);
	    fputc('\n', out);
	    }
	}
    }
carefulClose(&out);
fclose(tab);
lineFileClose(&in);
printf("Made %d .fa files in %s\n", outFileCount, outDir);
}