src/hg/bedSplitOnChrom/bedSplitOnChrom.c 1.4
1.4 2009/09/30 03:26:06 braney
add append option to add to, rather than create files
Index: src/hg/bedSplitOnChrom/bedSplitOnChrom.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/bedSplitOnChrom/bedSplitOnChrom.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -b -B -U 4 -r1.3 -r1.4
--- src/hg/bedSplitOnChrom/bedSplitOnChrom.c 29 Sep 2009 00:54:16 -0000 1.3
+++ src/hg/bedSplitOnChrom/bedSplitOnChrom.c 30 Sep 2009 03:26:06 -0000 1.4
@@ -10,8 +10,9 @@
int maxChromCount = 256;
boolean nfCheck; /* check for number of fields consistency */
boolean doStrand; /* append strand to file name */
+boolean doAppend; /* append to rather than create files */
void usage()
/* Explain usage and exit. */
{
@@ -19,15 +20,17 @@
"bedSplitOnChrom - Split bed into a directory with one file per chromosome.\n"
"usage:\n"
" bedSplitOnChrom inFile.bed outDir\n"
"options:\n"
+ " -append append to rather than create files\n"
" -strand append strand to file name\n"
" -noCheck do not check to see if number of fields is same in every record\n"
" -maxChromCount=N Maximum number of different chromosomes, default %d\n"
, maxChromCount);
}
static struct optionSpec options[] = {
+ {"append", OPTION_BOOLEAN},
{"strand", OPTION_BOOLEAN},
{"noCheck", OPTION_BOOLEAN},
{"maxChromCount", OPTION_INT},
{NULL, 0},
@@ -82,8 +85,9 @@
if (differentString(chrom, lastChrom))
{
f = hashFindVal(fileHash, chrom);
strcpy(lastChrom, chrom);
+ verbose(2, "new chrom %s f %p\n", lastChrom,f);
}
if (f == NULL)
{
@@ -91,9 +95,10 @@
errAbort("%s is the %dth chromosome, which is too many. "
"Use maxChromCount option if need be.",
chrom, fileHash->elCount+1);
safef(path, sizeof(path), "%s/%s.bed", outDir, chrom);
- f = mustOpen(path, "w");
+ f = mustOpen(path, doAppend ? "a" : "w");
+ verbose(2, "opened %s f %p\n",path, f);
hashAdd(fileHash, chrom, f);
}
/* Output line of bed file, starting with the three fields that are always there. */
@@ -135,7 +140,8 @@
if (argc != 3)
usage();
nfCheck = !optionExists("noCheck");
doStrand = optionExists("strand");
+doAppend = optionExists("append");
bedSplitOnChrom(argv[1], argv[2]);
return 0;
}