086a23bbef21c818e6809f13c6ffe3bbe5e540c8 kent Wed Feb 13 13:56:44 2013 -0800 A little program to massage Karen's centromeric data which looks maybe like it's reversed in some cases. diff --git src/kehayden/reverseCenReads/reverseCenReads.c src/kehayden/reverseCenReads/reverseCenReads.c new file mode 100644 index 0000000..bdca8d0 --- /dev/null +++ src/kehayden/reverseCenReads/reverseCenReads.c @@ -0,0 +1,56 @@ +/* reverseCenReads - Reverse order of monomers in semi-parsed centromeric reads.. */ +#include "common.h" +#include "linefile.h" +#include "hash.h" +#include "options.h" + +void usage() +/* Explain usage and exit. */ +{ +errAbort( + "reverseCenReads - Reverse order of monomers in semi-parsed centromeric reads.\n" + "usage:\n" + " reverseCenReads input.txt output.txt\n" + "Assumes first word in each line is readID, and rest of words are monomers.\n" + ); +} + +/* Command line validation table. */ +static struct optionSpec options[] = { + {NULL, 0}, +}; + +void reverseCenReads(char *input, char *output) +/* reverseCenReads - Reverse order of monomers in semi-parsed centromeric reads.. */ +{ +struct lineFile *lf = lineFileOpen(input, TRUE); +FILE *f = mustOpen(output, "w"); +char *line; +int maxWords = 16; +char *words[maxWords]; +while (lineFileNext(lf, &line, NULL)) + { + int wordCount = chopByWhite(line, words, maxWords); + if (wordCount >= maxWords) + errAbort("Too many words (%d) line %d of %s", wordCount, lf->lineIx, lf->fileName); + if (wordCount < 2) + errAbort("Need at least 2 words, got %d line %d of %s", + wordCount, lf->lineIx, lf->fileName); + fprintf(f, "%s", words[0]); /* First word - readId - not reversed. */ + int i; + for (i=wordCount-1; i>1; --i) + fprintf(f, "\t%s", words[i]); + fprintf(f, "\n"); + } +carefulClose(&f); +} + +int main(int argc, char *argv[]) +/* Process command line. */ +{ +optionInit(&argc, argv, options); +if (argc != 3) + usage(); +reverseCenReads(argv[1], argv[2]); +return 0; +}