Loading DB.c +187 −5 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include <ctype.h> #include <unistd.h> #include <dirent.h> #include <limits.h> #include "DB.h" Loading Loading @@ -599,8 +600,8 @@ error: // for the retained reads. void Trim_DB(DAZZ_DB *db) { int i, j, r; int allflag, cutoff; { int i, j, r, f; int allflag, cutoff, css; int64 totlen; int maxlen, nreads; DAZZ_TRACK *record; Loading Loading @@ -676,14 +677,23 @@ void Trim_DB(DAZZ_DB *db) record->anno = Realloc(record->anno,record->size*(j+1),NULL); } css = 0; totlen = maxlen = 0; for (j = i = 0; i < nreads; i++) { r = reads[i].rlen; if ((reads[i].flags & DB_BEST) >= allflag && r >= cutoff) { f = reads[i].flags; if ((f & DB_CSS) == 0) css = 0; r = reads[i].rlen; if ((f & DB_BEST) >= allflag && r >= cutoff) { totlen += r; if (r > maxlen) maxlen = r; reads[j++] = reads[i]; reads[j] = reads[i]; if (css) reads[j++].flags |= DB_CSS; else reads[j++].flags &= ~DB_CSS; css = 1; } } Loading Loading @@ -1989,3 +1999,175 @@ void Print_Read(char *s, int width) printf("\n"); } } /******************************************************************************************* * * COMMAND LINE BLOCK PARSER * Take a command line argument and interpret the '@' block number ranges. * Parse_Block_Arg produces an Block_Looper iterator object that can then * be invoked multiple times to iterate through all the files implied by * the @ pattern/range. * ********************************************************************************************/ typedef struct { int first, last, next; char *root, *pwd, *ppnt; char *slice; } _Block_Looper; // Advance the iterator e_parse to the next file, open it, and return the file pointer // to it. Return NULL if at the end of the list of files. FILE *Next_Block_Arg(Block_Looper *e_parse) { _Block_Looper *parse = (_Block_Looper *) e_parse; char *disp; FILE *input; parse->next += 1; if (parse->next > parse->last) return (NULL); if (parse->next < 0) disp = parse->root; else disp = Numbered_Suffix(parse->root,parse->next,parse->ppnt); if ((input = fopen(Catenate(parse->pwd,"/",disp,".las"),"r")) == NULL) { if (parse->last != INT_MAX) { fprintf(stderr,"%s: %s.las is not present\n",Prog_Name,disp); exit (1); } return (NULL); } return (input); } // Reset the iterator e_parse to the first file void Reset_Block_Arg(Block_Looper *e_parse) { _Block_Looper *parse = (_Block_Looper *) e_parse; parse->next = parse->first - 1; } // Return a pointer to the path for the current file char *Block_Arg_Path(Block_Looper *e_parse) { _Block_Looper *parse = (_Block_Looper *) e_parse; return (parse->pwd); } // Return a pointer to the root name for the current file char *Block_Arg_Root(Block_Looper *e_parse) { _Block_Looper *parse = (_Block_Looper *) e_parse; if (parse->next < 0) return (parse->root); else return (Numbered_Suffix(parse->root,parse->next,parse->ppnt)); } // Free the iterator void Free_Block_Arg(Block_Looper *e_parse) { _Block_Looper *parse = (_Block_Looper *) e_parse; free(parse->root); free(parse->pwd); free(parse->slice); free(parse); } char *Next_Block_Slice(Block_Looper *e_parse, int slice) { _Block_Looper *parse = (_Block_Looper *) e_parse; if (parse->slice == NULL) { int size = strlen(parse->pwd) + strlen(Block_Arg_Root(parse)) + 30; parse->slice = (char *) Malloc(size,"Block argument slice"); if (parse->slice == NULL) exit (1); } if (parse->first < 0) sprintf(parse->slice,"%s/%s",parse->pwd,parse->root); else sprintf(parse->slice,"%s/%s%c%d-%d%s",parse->pwd,parse->root,BLOCK_SYMBOL,parse->next+1, parse->next+slice,parse->ppnt); parse->next += slice; return (parse->slice); } // Parse the command line argument and return an iterator to move through the // file names, setting it up to report the first file. Block_Looper *Parse_Block_Arg(char *arg) { _Block_Looper *parse; char *pwd, *root; char *ppnt, *cpnt; int first, last; parse = (_Block_Looper *) Malloc(sizeof(_Block_Looper),"Allocating parse node"); pwd = PathTo(arg); root = Root(arg,".las"); if (parse == NULL || pwd == NULL || root == NULL) exit (1); ppnt = index(root,BLOCK_SYMBOL); if (ppnt == NULL) first = last = -1; else { if (index(ppnt+1,BLOCK_SYMBOL) != NULL) { fprintf(stderr,"%s: Two or more occurences of %c-sign in source name '%s'\n", Prog_Name,BLOCK_SYMBOL,root); exit (1); } *ppnt++ = '\0'; first = strtol(ppnt,&cpnt,10); if (cpnt == ppnt) { first = 1; last = INT_MAX; } else { if (first < 0) { fprintf(stderr, "%s: Integer following %c-sigan is less than 0 in source name '%s'\n", Prog_Name,BLOCK_SYMBOL,root); exit (1); } if (*cpnt == '-') { ppnt = cpnt+1; last = strtol(ppnt,&cpnt,10); if (cpnt == ppnt) { fprintf(stderr,"%s: Second integer must follow - in source name '%s'\n", Prog_Name,root); exit (1); } if (last < first) { fprintf(stderr, "%s: 2nd integer is less than 1st integer in source name '%s'\n", Prog_Name,root); exit (1); } ppnt = cpnt; } else { last = INT_MAX; ppnt = cpnt; } } } parse->pwd = pwd; parse->root = root; parse->ppnt = ppnt; parse->first = first; parse->last = last; parse->next = first-1; parse->slice = NULL; return ((Block_Looper *) parse); } DB.h +27 −6 Original line number Diff line number Diff line Loading @@ -59,6 +59,8 @@ typedef signed long long int64; typedef float float32; typedef double float64; #define LAST_READ_SYMBOL '$' #define BLOCK_SYMBOL '@' /******************************************************************************************* * Loading Loading @@ -215,12 +217,11 @@ int Count_Args(char *arg); SYSTEM_READ_ERROR \ } #define FTELLO(file) \ ( { int x = ftello(file); \ if (x < 0) \ #define FTELLO(val,file) \ { val = ftello(file); \ if (val < 0) \ SYSTEM_READ_ERROR \ ; x; \ } ) } /******************************************************************************************* * Loading Loading @@ -567,4 +568,24 @@ int Read_All_Sequences(DAZZ_DB *db, int ascii); int List_DB_Files(char *path, void actor(char *path, char *extension)); // Take a command line argument and interpret the '@' block number ranges. // Parse_Block_Arg produces a Block_Looper iterator object that can then // be invoked multiple times to iterate through all the files implied by // the @ pattern/range. Next_Block_Slice returns a string encoing the next // slice files represented by an @-notation, and advances the iterator by // that many files. typedef void Block_Looper; Block_Looper *Parse_Block_Arg(char *arg); FILE *Next_Block_Arg(Block_Looper *e_parse); char *Next_Block_Slice(Block_Looper *e_parse,int slice); void Reset_Block_Arg(Block_Looper *e_parse); // Reset iterator to first file char *Block_Arg_Path(Block_Looper *e_parse); // Path of current file char *Block_Arg_Root(Block_Looper *e_parse); // Root name of current file void Free_Block_Arg(Block_Looper *e_parse); // Free the iterator #endif // _DAZZ_DB HPC.daligner.c +348 −606 File changed.Preview size limit exceeded, changes collapsed. Show changes LAcat.c +102 −100 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ #include "DB.h" #include "align.h" static char *Usage = "[-v] <source:las> > <target>.las"; static char *Usage = "[-v] <source:las> ... > <target>.las"; #define MEMORY 1000 // How many megabytes for output buffer Loading @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) FILE *input; int64 novl, bsize, ovlsize, ptrsize; int tspace, tbytes; char *pwd, *root, *root2; int c; int VERBOSE; Loading @@ -51,6 +51,10 @@ int main(int argc, char *argv[]) if (argc <= 1) { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage); fprintf(stderr,"\n"); fprintf(stderr," <source>'s may contain a template that is %c-sign optionally\n", BLOCK_SYMBOL); fprintf(stderr," followed by an integer or integer range\n"); exit (1); } } Loading @@ -64,57 +68,49 @@ int main(int argc, char *argv[]) exit (1); iblock += ptrsize; pwd = PathTo(argv[1]); root = Root(argv[1],".las"); novl = 0; tspace = -1; for (c = 1; c < argc; c++) { Block_Looper *parse; FILE *input; root2 = index(root,'#'); if (root2 == NULL) { fprintf(stderr,"%s: No #-sign in source name '%s'\n",Prog_Name,root); exit (1); } if (index(root2+1,'#') != NULL) { fprintf(stderr,"%s: Two or more occurences of #-sign in source name '%s'\n",Prog_Name,root); exit (1); } *root2++ = '\0'; parse = Parse_Block_Arg(argv[c]); while ((input = Next_Block_Arg(parse)) != NULL) { int64 povl; int i, mspace; novl = 0; tspace = 0; mspace = 0; tbytes = 0; for (i = 0; 1; i++) { char *name = Catenate(pwd,"/",Numbered_Suffix(root,i+1,root2),".las"); if ((input = fopen(name,"r")) == NULL) break; int mspace; if (fread(&povl,sizeof(int64),1,input) != 1) SYSTEM_READ_ERROR novl += povl; if (fread(&mspace,sizeof(int),1,input) != 1) SYSTEM_READ_ERROR if (i == 0) { tspace = mspace; if (tspace <= TRACE_XOVR && tspace != 0) tbytes = sizeof(uint8); else tbytes = sizeof(uint16); } if (tspace < 0) tspace = mspace; else if (tspace != mspace) { fprintf(stderr,"%s: PT-point spacing conflict (%d vs %d)\n",Prog_Name,tspace,mspace); { fprintf(stderr,"%s: trace-point spacing conflict between %s and earlier files", Prog_Name,Block_Arg_Root(parse)); fprintf(stderr," (%d vs %d)\n",tspace,mspace); exit (1); } fclose(input); } Free_Block_Arg(parse); } if (tspace <= TRACE_XOVR && tspace != 0) tbytes = sizeof(uint8); else tbytes = sizeof(uint16); if (fwrite(&novl,sizeof(int64),1,stdout) != 1) SYSTEM_READ_ERROR if (fwrite(&tspace,sizeof(int),1,stdout) != 1) SYSTEM_READ_ERROR } { int i, j; { Block_Looper *parse; int c, j; Overlap *w; int64 tsize, povl; int mspace; Loading @@ -124,17 +120,20 @@ int main(int argc, char *argv[]) optr = oblock; otop = oblock + bsize; for (i = 0; 1; i++) { char *name = Catenate(pwd,"/",Numbered_Suffix(root,i+1,root2),".las"); if ((input = fopen(name,"r")) == NULL) break; for (c = 1; c < argc; c++) { parse = Parse_Block_Arg(argv[c]); if (fread(&povl,sizeof(int64),1,input) != 1) while ((input = Next_Block_Arg(parse)) != NULL) { if (fread(&povl,sizeof(int64),1,input) != 1) SYSTEM_READ_ERROR if (fread(&mspace,sizeof(int),1,input) != 1) SYSTEM_READ_ERROR if (VERBOSE) fprintf(stderr," Concatenating %s: %lld la\'s\n",Numbered_Suffix(root,i+1,root2),povl); { fprintf(stderr, " Concatenating %s: %lld la\'s\n",Block_Arg_Root(parse),povl); fflush(stderr); } iptr = iblock; itop = iblock + fread(iblock,1,bsize,input); Loading Loading @@ -179,6 +178,9 @@ int main(int argc, char *argv[]) fclose(input); } Free_Block_Arg(parse); } if (optr > oblock) { if (fwrite(oblock,1,optr-oblock,stdout) != (size_t) (optr-oblock)) SYSTEM_READ_ERROR Loading @@ -186,10 +188,10 @@ int main(int argc, char *argv[]) } if (VERBOSE) fprintf(stderr," Totalling %lld la\'s\n",novl); { fprintf(stderr," Totalling %lld la\'s\n",novl); fflush(stderr); } free(pwd); free(root); free(oblock); free(iblock-ptrsize); Loading LAcheck.c +247 −208 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ #include "DB.h" #include "align.h" static char *Usage = "[-vS] <src1:db|dam> [ <src2:db|dam> ] <align:las> ..."; static char *Usage = "[-vaS] <src1:db|dam> [ <src2:db|dam> ] <align:las> ..."; #define MEMORY 1000 // How many megabytes for output buffer Loading @@ -26,6 +26,7 @@ int main(int argc, char *argv[]) { DAZZ_DB _db1, *db1 = &_db1; DAZZ_DB _db2, *db2 = &_db2; int VERBOSE; int MAP_ORDER; int SORTED; int ISTWO; int status; Loading @@ -42,7 +43,7 @@ int main(int argc, char *argv[]) if (argv[i][0] == '-') switch (argv[i][1]) { default: ARG_FLAGS("vS") ARG_FLAGS("vaS") break; } else Loading @@ -50,18 +51,24 @@ int main(int argc, char *argv[]) argc = j; VERBOSE = flags['v']; MAP_ORDER = flags['a']; SORTED = flags['S']; if (argc <= 2) { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage); fprintf(stderr,"\n"); fprintf(stderr," -v: Verbose mode, output error messages.\n"); fprintf(stderr," -S: Check that .las is in sorted order.\n"); fprintf(stderr," -a: If -S, then check sorted by A-read, A-position pairs\n"); fprintf(stderr," off => check sorted by A,B-read pairs (LA-piles)\n"); exit (1); } } // Open trimmed DB { int status; char *pwd, *root; { Block_Looper *parse; int status; FILE *input; ISTWO = 0; Loading @@ -73,14 +80,12 @@ int main(int argc, char *argv[]) exit (1); } pwd = PathTo(argv[2]); root = Root(argv[2],".las"); if ((input = fopen(Catenate(pwd,"/",root,".las"),"r")) == NULL) { ISTWO = 1; if (argc <= 3) { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage); exit (1); } db2 = db1; else { parse = Parse_Block_Arg(argv[2]); if ((input = Next_Block_Arg(parse)) == NULL) { ISTWO = 1; status = Open_DB(argv[2],db2); if (status < 0) exit (1); Loading @@ -91,13 +96,12 @@ int main(int argc, char *argv[]) Trim_DB(db2); } else { fclose(input); db2 = db1; { db2 = db1; fclose(input); } Free_Block_Arg(parse); } Trim_DB(db1); free(root); free(pwd); } { char *iblock; Loading @@ -122,8 +126,9 @@ int main(int argc, char *argv[]) status = 0; for (i = 2+ISTWO; i < argc; i++) { char *pwd, *root; { Block_Looper *parse; FILE *input; char *disp; char *iptr, *itop; Overlap last, prev; int64 novl; Loading @@ -132,10 +137,10 @@ int main(int argc, char *argv[]) // Establish IO and (novl,tspace) header pwd = PathTo(argv[i]); root = Root(argv[i],".las"); if ((input = Fopen(Catenate(pwd,"/",root,".las"),"r")) == NULL) goto error; parse = Parse_Block_Arg(argv[i]); while ((input = Next_Block_Arg(parse)) != NULL) { disp = Block_Arg_Root(parse); if (fread(&novl,sizeof(int64),1,input) != 1) SYSTEM_READ_ERROR Loading @@ -143,12 +148,12 @@ int main(int argc, char *argv[]) SYSTEM_READ_ERROR if (novl < 0) { if (VERBOSE) fprintf(stderr," %s: Number of alignments < 0\n",root); fprintf(stderr," %s: Number of alignments < 0\n",disp); goto error; } if (tspace < 0) { if (VERBOSE) fprintf(stderr," %s: Trace spacing < 0\n",root); fprintf(stderr," %s: Trace spacing < 0\n",disp); goto error; } Loading Loading @@ -185,7 +190,7 @@ int main(int argc, char *argv[]) itop += fread(itop,1,bsize-remains,input); if (iptr + ovlsize > itop) { if (VERBOSE) fprintf(stderr," %s: Too few alignment records\n",root); fprintf(stderr," %s: Too few alignment records\n",disp); goto error; } } Loading @@ -203,7 +208,7 @@ int main(int argc, char *argv[]) itop += fread(itop,1,bsize-remains,input); if (iptr + tsize > itop) { if (VERBOSE) fprintf(stderr," %s: Too few alignment records\n",root); fprintf(stderr," %s: Too few alignment records\n",disp); goto error; } } Loading @@ -214,12 +219,12 @@ int main(int argc, char *argv[]) if (ovl.aread < 0 || ovl.bread < 0) { if (VERBOSE) fprintf(stderr," %s: Read indices < 0\n",root); fprintf(stderr," %s: Read indices < 0\n",disp); goto error; } if (ovl.aread >= nreads1 || ovl.bread >= nreads2) { if (VERBOSE) fprintf(stderr," %s: Read indices out of range\n",root); fprintf(stderr," %s: Read indices out of range\n",disp); goto error; } Loading @@ -227,38 +232,38 @@ int main(int argc, char *argv[]) ovl.path.bbpos >= ovl.path.bepos || ovl.path.bepos > reads2[ovl.bread].rlen || ovl.path.abpos < 0 || ovl.path.bbpos < 0 ) { if (VERBOSE) fprintf(stderr," %s: Non-sense alignment intervals\n",root); fprintf(stderr," %s: Non-sense alignment intervals\n",disp); goto error; } if (ovl.path.diffs < 0 || ovl.path.diffs > reads1[ovl.aread].rlen || ovl.path.diffs > reads2[ovl.bread].rlen) { if (VERBOSE) fprintf(stderr," %s: Non-sense number of differences\n",root); fprintf(stderr," %s: Non-sense number of differences\n",disp); goto error; } if (Check_Trace_Points(&ovl,tspace,VERBOSE,root)) if (Check_Trace_Points(&ovl,tspace,VERBOSE,disp)) goto error; if (j == 0) has_chains = ((ovl.flags & (START_FLAG | NEXT_FLAG | BEST_FLAG)) != 0); if (has_chains) { if ((ovl.flags & (START_FLAG | NEXT_FLAG)) == 0) { if (CHAIN_START(ovl.flags) && CHAIN_NEXT(ovl.flags)) { if (VERBOSE) fprintf(stderr," %s: LA has both start & next flag set\n",root); fprintf(stderr," %s: LA has both start & next flag set\n",disp); goto error; } if (BEST_CHAIN(ovl.flags) && CHAIN_NEXT(ovl.flags)) { if (VERBOSE) fprintf(stderr," %s: LA has both best & next flag set\n",root); fprintf(stderr," %s: LA has both best & next flag set\n",disp); goto error; } } else { if ((ovl.flags & (START_FLAG | NEXT_FLAG | BEST_FLAG)) != 0) { if (VERBOSE) fprintf(stderr," %s: LAs should not have chain flags\n",root); fprintf(stderr," %s: LAs should not have chain flags\n",disp); goto error; } } Loading @@ -267,9 +272,26 @@ int main(int argc, char *argv[]) equal = 0; if (SORTED) { if (CHAIN_NEXT(ovl.flags) || !has_chains) { if (CHAIN_NEXT(ovl.flags)) { if (ovl.aread == last.aread && ovl.bread != last.bread && COMP(ovl.flags) != COMP(last.flags) && ovl.path.abpos >= last.path.abpos && ovl.path.bbpos >= last.path.bbpos) goto dupcheck; if (VERBOSE) fprintf(stderr," %s: Chain is not valid (%d vs %d)\n", disp,ovl.aread+1,ovl.bread+1); goto error; } else if (!has_chains) { if (ovl.aread > last.aread) goto inorder; if (ovl.aread == last.aread) { if (MAP_ORDER) { if (ovl.path.abpos > prev.path.abpos) goto inorder; if (ovl.path.abpos == prev.path.abpos) goto dupcheck; } else { if (ovl.bread > last.bread) goto inorder; if (ovl.bread == last.bread) { if (COMP(ovl.flags) > COMP(last.flags)) goto inorder; Loading @@ -282,26 +304,37 @@ int main(int argc, char *argv[]) } } } if (VERBOSE) { if (CHAIN_NEXT(ovl.flags)) fprintf(stderr," %s: Chain is not valid (%d vs %d)\n", root,ovl.aread+1,ovl.bread+1); else fprintf(stderr," %s: Reads are not sorted (%d vs %d)\n", root,ovl.aread+1,ovl.bread+1); } if (VERBOSE) fprintf(stderr," %s: LAs are not sorted (%d vs %d)\n", disp,ovl.aread+1,ovl.bread+1); goto error; } else else // First element of a chain { if (ovl.aread > prev.aread) goto inorder; if (ovl.aread == prev.aread) { if (MAP_ORDER) { if (ovl.path.abpos > prev.path.abpos) goto inorder; if (ovl.path.abpos == prev.path.abpos) goto dupcheck; } else { if (ovl.bread > prev.bread) goto inorder; if (ovl.bread == prev.bread) { if (COMP(ovl.flags) > COMP(prev.flags)) goto inorder; if (COMP(ovl.flags) == COMP(prev.flags)) { if (ovl.path.abpos > prev.path.abpos) goto inorder; if (ovl.path.abpos == prev.path.abpos) { equal = 1; goto dupcheck; } } } } } if (VERBOSE) fprintf(stderr," %s: Chains are not sorted (%d vs %d)\n", root,ovl.aread+1,ovl.bread+1); disp,ovl.aread+1,ovl.bread+1); goto error; } } Loading @@ -315,8 +348,8 @@ int main(int argc, char *argv[]) ovl.path.bbpos == last.path.bbpos && ovl.path.bepos == last.path.bepos) { if (VERBOSE) fprintf(stderr," %s: Duplicate overlap (%d vs %d)\n", root,ovl.aread+1,ovl.bread+1); fprintf(stderr," %s: Duplicate LAs (%d vs %d)\n", disp,ovl.aread+1,ovl.bread+1); goto error; } } Loading @@ -330,24 +363,30 @@ int main(int argc, char *argv[]) if (iptr < itop) { if (VERBOSE) fprintf(stderr," %s: Too many alignment records\n",root); fprintf(stderr," %s: Too many alignment records\n",disp); goto error; } if (VERBOSE) { fprintf(stderr," %s: ",root); Print_Number(novl,0,stderr); fprintf(stderr," all OK\n"); { printf(" %s: ",disp); Print_Number(novl,0,stdout); printf(" all OK\n"); fflush(stdout); } goto cleanup; error: status = 1; if (VERBOSE) { printf(" %s: Not OK, see stderr\n",disp); fflush(stdout); } cleanup: if (input != NULL) fclose(input); free(pwd); free(root); } Free_Block_Arg(parse); } free(iblock-ptrsize); Loading Loading
DB.c +187 −5 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include <ctype.h> #include <unistd.h> #include <dirent.h> #include <limits.h> #include "DB.h" Loading Loading @@ -599,8 +600,8 @@ error: // for the retained reads. void Trim_DB(DAZZ_DB *db) { int i, j, r; int allflag, cutoff; { int i, j, r, f; int allflag, cutoff, css; int64 totlen; int maxlen, nreads; DAZZ_TRACK *record; Loading Loading @@ -676,14 +677,23 @@ void Trim_DB(DAZZ_DB *db) record->anno = Realloc(record->anno,record->size*(j+1),NULL); } css = 0; totlen = maxlen = 0; for (j = i = 0; i < nreads; i++) { r = reads[i].rlen; if ((reads[i].flags & DB_BEST) >= allflag && r >= cutoff) { f = reads[i].flags; if ((f & DB_CSS) == 0) css = 0; r = reads[i].rlen; if ((f & DB_BEST) >= allflag && r >= cutoff) { totlen += r; if (r > maxlen) maxlen = r; reads[j++] = reads[i]; reads[j] = reads[i]; if (css) reads[j++].flags |= DB_CSS; else reads[j++].flags &= ~DB_CSS; css = 1; } } Loading Loading @@ -1989,3 +1999,175 @@ void Print_Read(char *s, int width) printf("\n"); } } /******************************************************************************************* * * COMMAND LINE BLOCK PARSER * Take a command line argument and interpret the '@' block number ranges. * Parse_Block_Arg produces an Block_Looper iterator object that can then * be invoked multiple times to iterate through all the files implied by * the @ pattern/range. * ********************************************************************************************/ typedef struct { int first, last, next; char *root, *pwd, *ppnt; char *slice; } _Block_Looper; // Advance the iterator e_parse to the next file, open it, and return the file pointer // to it. Return NULL if at the end of the list of files. FILE *Next_Block_Arg(Block_Looper *e_parse) { _Block_Looper *parse = (_Block_Looper *) e_parse; char *disp; FILE *input; parse->next += 1; if (parse->next > parse->last) return (NULL); if (parse->next < 0) disp = parse->root; else disp = Numbered_Suffix(parse->root,parse->next,parse->ppnt); if ((input = fopen(Catenate(parse->pwd,"/",disp,".las"),"r")) == NULL) { if (parse->last != INT_MAX) { fprintf(stderr,"%s: %s.las is not present\n",Prog_Name,disp); exit (1); } return (NULL); } return (input); } // Reset the iterator e_parse to the first file void Reset_Block_Arg(Block_Looper *e_parse) { _Block_Looper *parse = (_Block_Looper *) e_parse; parse->next = parse->first - 1; } // Return a pointer to the path for the current file char *Block_Arg_Path(Block_Looper *e_parse) { _Block_Looper *parse = (_Block_Looper *) e_parse; return (parse->pwd); } // Return a pointer to the root name for the current file char *Block_Arg_Root(Block_Looper *e_parse) { _Block_Looper *parse = (_Block_Looper *) e_parse; if (parse->next < 0) return (parse->root); else return (Numbered_Suffix(parse->root,parse->next,parse->ppnt)); } // Free the iterator void Free_Block_Arg(Block_Looper *e_parse) { _Block_Looper *parse = (_Block_Looper *) e_parse; free(parse->root); free(parse->pwd); free(parse->slice); free(parse); } char *Next_Block_Slice(Block_Looper *e_parse, int slice) { _Block_Looper *parse = (_Block_Looper *) e_parse; if (parse->slice == NULL) { int size = strlen(parse->pwd) + strlen(Block_Arg_Root(parse)) + 30; parse->slice = (char *) Malloc(size,"Block argument slice"); if (parse->slice == NULL) exit (1); } if (parse->first < 0) sprintf(parse->slice,"%s/%s",parse->pwd,parse->root); else sprintf(parse->slice,"%s/%s%c%d-%d%s",parse->pwd,parse->root,BLOCK_SYMBOL,parse->next+1, parse->next+slice,parse->ppnt); parse->next += slice; return (parse->slice); } // Parse the command line argument and return an iterator to move through the // file names, setting it up to report the first file. Block_Looper *Parse_Block_Arg(char *arg) { _Block_Looper *parse; char *pwd, *root; char *ppnt, *cpnt; int first, last; parse = (_Block_Looper *) Malloc(sizeof(_Block_Looper),"Allocating parse node"); pwd = PathTo(arg); root = Root(arg,".las"); if (parse == NULL || pwd == NULL || root == NULL) exit (1); ppnt = index(root,BLOCK_SYMBOL); if (ppnt == NULL) first = last = -1; else { if (index(ppnt+1,BLOCK_SYMBOL) != NULL) { fprintf(stderr,"%s: Two or more occurences of %c-sign in source name '%s'\n", Prog_Name,BLOCK_SYMBOL,root); exit (1); } *ppnt++ = '\0'; first = strtol(ppnt,&cpnt,10); if (cpnt == ppnt) { first = 1; last = INT_MAX; } else { if (first < 0) { fprintf(stderr, "%s: Integer following %c-sigan is less than 0 in source name '%s'\n", Prog_Name,BLOCK_SYMBOL,root); exit (1); } if (*cpnt == '-') { ppnt = cpnt+1; last = strtol(ppnt,&cpnt,10); if (cpnt == ppnt) { fprintf(stderr,"%s: Second integer must follow - in source name '%s'\n", Prog_Name,root); exit (1); } if (last < first) { fprintf(stderr, "%s: 2nd integer is less than 1st integer in source name '%s'\n", Prog_Name,root); exit (1); } ppnt = cpnt; } else { last = INT_MAX; ppnt = cpnt; } } } parse->pwd = pwd; parse->root = root; parse->ppnt = ppnt; parse->first = first; parse->last = last; parse->next = first-1; parse->slice = NULL; return ((Block_Looper *) parse); }
DB.h +27 −6 Original line number Diff line number Diff line Loading @@ -59,6 +59,8 @@ typedef signed long long int64; typedef float float32; typedef double float64; #define LAST_READ_SYMBOL '$' #define BLOCK_SYMBOL '@' /******************************************************************************************* * Loading Loading @@ -215,12 +217,11 @@ int Count_Args(char *arg); SYSTEM_READ_ERROR \ } #define FTELLO(file) \ ( { int x = ftello(file); \ if (x < 0) \ #define FTELLO(val,file) \ { val = ftello(file); \ if (val < 0) \ SYSTEM_READ_ERROR \ ; x; \ } ) } /******************************************************************************************* * Loading Loading @@ -567,4 +568,24 @@ int Read_All_Sequences(DAZZ_DB *db, int ascii); int List_DB_Files(char *path, void actor(char *path, char *extension)); // Take a command line argument and interpret the '@' block number ranges. // Parse_Block_Arg produces a Block_Looper iterator object that can then // be invoked multiple times to iterate through all the files implied by // the @ pattern/range. Next_Block_Slice returns a string encoing the next // slice files represented by an @-notation, and advances the iterator by // that many files. typedef void Block_Looper; Block_Looper *Parse_Block_Arg(char *arg); FILE *Next_Block_Arg(Block_Looper *e_parse); char *Next_Block_Slice(Block_Looper *e_parse,int slice); void Reset_Block_Arg(Block_Looper *e_parse); // Reset iterator to first file char *Block_Arg_Path(Block_Looper *e_parse); // Path of current file char *Block_Arg_Root(Block_Looper *e_parse); // Root name of current file void Free_Block_Arg(Block_Looper *e_parse); // Free the iterator #endif // _DAZZ_DB
LAcat.c +102 −100 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ #include "DB.h" #include "align.h" static char *Usage = "[-v] <source:las> > <target>.las"; static char *Usage = "[-v] <source:las> ... > <target>.las"; #define MEMORY 1000 // How many megabytes for output buffer Loading @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) FILE *input; int64 novl, bsize, ovlsize, ptrsize; int tspace, tbytes; char *pwd, *root, *root2; int c; int VERBOSE; Loading @@ -51,6 +51,10 @@ int main(int argc, char *argv[]) if (argc <= 1) { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage); fprintf(stderr,"\n"); fprintf(stderr," <source>'s may contain a template that is %c-sign optionally\n", BLOCK_SYMBOL); fprintf(stderr," followed by an integer or integer range\n"); exit (1); } } Loading @@ -64,57 +68,49 @@ int main(int argc, char *argv[]) exit (1); iblock += ptrsize; pwd = PathTo(argv[1]); root = Root(argv[1],".las"); novl = 0; tspace = -1; for (c = 1; c < argc; c++) { Block_Looper *parse; FILE *input; root2 = index(root,'#'); if (root2 == NULL) { fprintf(stderr,"%s: No #-sign in source name '%s'\n",Prog_Name,root); exit (1); } if (index(root2+1,'#') != NULL) { fprintf(stderr,"%s: Two or more occurences of #-sign in source name '%s'\n",Prog_Name,root); exit (1); } *root2++ = '\0'; parse = Parse_Block_Arg(argv[c]); while ((input = Next_Block_Arg(parse)) != NULL) { int64 povl; int i, mspace; novl = 0; tspace = 0; mspace = 0; tbytes = 0; for (i = 0; 1; i++) { char *name = Catenate(pwd,"/",Numbered_Suffix(root,i+1,root2),".las"); if ((input = fopen(name,"r")) == NULL) break; int mspace; if (fread(&povl,sizeof(int64),1,input) != 1) SYSTEM_READ_ERROR novl += povl; if (fread(&mspace,sizeof(int),1,input) != 1) SYSTEM_READ_ERROR if (i == 0) { tspace = mspace; if (tspace <= TRACE_XOVR && tspace != 0) tbytes = sizeof(uint8); else tbytes = sizeof(uint16); } if (tspace < 0) tspace = mspace; else if (tspace != mspace) { fprintf(stderr,"%s: PT-point spacing conflict (%d vs %d)\n",Prog_Name,tspace,mspace); { fprintf(stderr,"%s: trace-point spacing conflict between %s and earlier files", Prog_Name,Block_Arg_Root(parse)); fprintf(stderr," (%d vs %d)\n",tspace,mspace); exit (1); } fclose(input); } Free_Block_Arg(parse); } if (tspace <= TRACE_XOVR && tspace != 0) tbytes = sizeof(uint8); else tbytes = sizeof(uint16); if (fwrite(&novl,sizeof(int64),1,stdout) != 1) SYSTEM_READ_ERROR if (fwrite(&tspace,sizeof(int),1,stdout) != 1) SYSTEM_READ_ERROR } { int i, j; { Block_Looper *parse; int c, j; Overlap *w; int64 tsize, povl; int mspace; Loading @@ -124,17 +120,20 @@ int main(int argc, char *argv[]) optr = oblock; otop = oblock + bsize; for (i = 0; 1; i++) { char *name = Catenate(pwd,"/",Numbered_Suffix(root,i+1,root2),".las"); if ((input = fopen(name,"r")) == NULL) break; for (c = 1; c < argc; c++) { parse = Parse_Block_Arg(argv[c]); if (fread(&povl,sizeof(int64),1,input) != 1) while ((input = Next_Block_Arg(parse)) != NULL) { if (fread(&povl,sizeof(int64),1,input) != 1) SYSTEM_READ_ERROR if (fread(&mspace,sizeof(int),1,input) != 1) SYSTEM_READ_ERROR if (VERBOSE) fprintf(stderr," Concatenating %s: %lld la\'s\n",Numbered_Suffix(root,i+1,root2),povl); { fprintf(stderr, " Concatenating %s: %lld la\'s\n",Block_Arg_Root(parse),povl); fflush(stderr); } iptr = iblock; itop = iblock + fread(iblock,1,bsize,input); Loading Loading @@ -179,6 +178,9 @@ int main(int argc, char *argv[]) fclose(input); } Free_Block_Arg(parse); } if (optr > oblock) { if (fwrite(oblock,1,optr-oblock,stdout) != (size_t) (optr-oblock)) SYSTEM_READ_ERROR Loading @@ -186,10 +188,10 @@ int main(int argc, char *argv[]) } if (VERBOSE) fprintf(stderr," Totalling %lld la\'s\n",novl); { fprintf(stderr," Totalling %lld la\'s\n",novl); fflush(stderr); } free(pwd); free(root); free(oblock); free(iblock-ptrsize); Loading
LAcheck.c +247 −208 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ #include "DB.h" #include "align.h" static char *Usage = "[-vS] <src1:db|dam> [ <src2:db|dam> ] <align:las> ..."; static char *Usage = "[-vaS] <src1:db|dam> [ <src2:db|dam> ] <align:las> ..."; #define MEMORY 1000 // How many megabytes for output buffer Loading @@ -26,6 +26,7 @@ int main(int argc, char *argv[]) { DAZZ_DB _db1, *db1 = &_db1; DAZZ_DB _db2, *db2 = &_db2; int VERBOSE; int MAP_ORDER; int SORTED; int ISTWO; int status; Loading @@ -42,7 +43,7 @@ int main(int argc, char *argv[]) if (argv[i][0] == '-') switch (argv[i][1]) { default: ARG_FLAGS("vS") ARG_FLAGS("vaS") break; } else Loading @@ -50,18 +51,24 @@ int main(int argc, char *argv[]) argc = j; VERBOSE = flags['v']; MAP_ORDER = flags['a']; SORTED = flags['S']; if (argc <= 2) { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage); fprintf(stderr,"\n"); fprintf(stderr," -v: Verbose mode, output error messages.\n"); fprintf(stderr," -S: Check that .las is in sorted order.\n"); fprintf(stderr," -a: If -S, then check sorted by A-read, A-position pairs\n"); fprintf(stderr," off => check sorted by A,B-read pairs (LA-piles)\n"); exit (1); } } // Open trimmed DB { int status; char *pwd, *root; { Block_Looper *parse; int status; FILE *input; ISTWO = 0; Loading @@ -73,14 +80,12 @@ int main(int argc, char *argv[]) exit (1); } pwd = PathTo(argv[2]); root = Root(argv[2],".las"); if ((input = fopen(Catenate(pwd,"/",root,".las"),"r")) == NULL) { ISTWO = 1; if (argc <= 3) { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage); exit (1); } db2 = db1; else { parse = Parse_Block_Arg(argv[2]); if ((input = Next_Block_Arg(parse)) == NULL) { ISTWO = 1; status = Open_DB(argv[2],db2); if (status < 0) exit (1); Loading @@ -91,13 +96,12 @@ int main(int argc, char *argv[]) Trim_DB(db2); } else { fclose(input); db2 = db1; { db2 = db1; fclose(input); } Free_Block_Arg(parse); } Trim_DB(db1); free(root); free(pwd); } { char *iblock; Loading @@ -122,8 +126,9 @@ int main(int argc, char *argv[]) status = 0; for (i = 2+ISTWO; i < argc; i++) { char *pwd, *root; { Block_Looper *parse; FILE *input; char *disp; char *iptr, *itop; Overlap last, prev; int64 novl; Loading @@ -132,10 +137,10 @@ int main(int argc, char *argv[]) // Establish IO and (novl,tspace) header pwd = PathTo(argv[i]); root = Root(argv[i],".las"); if ((input = Fopen(Catenate(pwd,"/",root,".las"),"r")) == NULL) goto error; parse = Parse_Block_Arg(argv[i]); while ((input = Next_Block_Arg(parse)) != NULL) { disp = Block_Arg_Root(parse); if (fread(&novl,sizeof(int64),1,input) != 1) SYSTEM_READ_ERROR Loading @@ -143,12 +148,12 @@ int main(int argc, char *argv[]) SYSTEM_READ_ERROR if (novl < 0) { if (VERBOSE) fprintf(stderr," %s: Number of alignments < 0\n",root); fprintf(stderr," %s: Number of alignments < 0\n",disp); goto error; } if (tspace < 0) { if (VERBOSE) fprintf(stderr," %s: Trace spacing < 0\n",root); fprintf(stderr," %s: Trace spacing < 0\n",disp); goto error; } Loading Loading @@ -185,7 +190,7 @@ int main(int argc, char *argv[]) itop += fread(itop,1,bsize-remains,input); if (iptr + ovlsize > itop) { if (VERBOSE) fprintf(stderr," %s: Too few alignment records\n",root); fprintf(stderr," %s: Too few alignment records\n",disp); goto error; } } Loading @@ -203,7 +208,7 @@ int main(int argc, char *argv[]) itop += fread(itop,1,bsize-remains,input); if (iptr + tsize > itop) { if (VERBOSE) fprintf(stderr," %s: Too few alignment records\n",root); fprintf(stderr," %s: Too few alignment records\n",disp); goto error; } } Loading @@ -214,12 +219,12 @@ int main(int argc, char *argv[]) if (ovl.aread < 0 || ovl.bread < 0) { if (VERBOSE) fprintf(stderr," %s: Read indices < 0\n",root); fprintf(stderr," %s: Read indices < 0\n",disp); goto error; } if (ovl.aread >= nreads1 || ovl.bread >= nreads2) { if (VERBOSE) fprintf(stderr," %s: Read indices out of range\n",root); fprintf(stderr," %s: Read indices out of range\n",disp); goto error; } Loading @@ -227,38 +232,38 @@ int main(int argc, char *argv[]) ovl.path.bbpos >= ovl.path.bepos || ovl.path.bepos > reads2[ovl.bread].rlen || ovl.path.abpos < 0 || ovl.path.bbpos < 0 ) { if (VERBOSE) fprintf(stderr," %s: Non-sense alignment intervals\n",root); fprintf(stderr," %s: Non-sense alignment intervals\n",disp); goto error; } if (ovl.path.diffs < 0 || ovl.path.diffs > reads1[ovl.aread].rlen || ovl.path.diffs > reads2[ovl.bread].rlen) { if (VERBOSE) fprintf(stderr," %s: Non-sense number of differences\n",root); fprintf(stderr," %s: Non-sense number of differences\n",disp); goto error; } if (Check_Trace_Points(&ovl,tspace,VERBOSE,root)) if (Check_Trace_Points(&ovl,tspace,VERBOSE,disp)) goto error; if (j == 0) has_chains = ((ovl.flags & (START_FLAG | NEXT_FLAG | BEST_FLAG)) != 0); if (has_chains) { if ((ovl.flags & (START_FLAG | NEXT_FLAG)) == 0) { if (CHAIN_START(ovl.flags) && CHAIN_NEXT(ovl.flags)) { if (VERBOSE) fprintf(stderr," %s: LA has both start & next flag set\n",root); fprintf(stderr," %s: LA has both start & next flag set\n",disp); goto error; } if (BEST_CHAIN(ovl.flags) && CHAIN_NEXT(ovl.flags)) { if (VERBOSE) fprintf(stderr," %s: LA has both best & next flag set\n",root); fprintf(stderr," %s: LA has both best & next flag set\n",disp); goto error; } } else { if ((ovl.flags & (START_FLAG | NEXT_FLAG | BEST_FLAG)) != 0) { if (VERBOSE) fprintf(stderr," %s: LAs should not have chain flags\n",root); fprintf(stderr," %s: LAs should not have chain flags\n",disp); goto error; } } Loading @@ -267,9 +272,26 @@ int main(int argc, char *argv[]) equal = 0; if (SORTED) { if (CHAIN_NEXT(ovl.flags) || !has_chains) { if (CHAIN_NEXT(ovl.flags)) { if (ovl.aread == last.aread && ovl.bread != last.bread && COMP(ovl.flags) != COMP(last.flags) && ovl.path.abpos >= last.path.abpos && ovl.path.bbpos >= last.path.bbpos) goto dupcheck; if (VERBOSE) fprintf(stderr," %s: Chain is not valid (%d vs %d)\n", disp,ovl.aread+1,ovl.bread+1); goto error; } else if (!has_chains) { if (ovl.aread > last.aread) goto inorder; if (ovl.aread == last.aread) { if (MAP_ORDER) { if (ovl.path.abpos > prev.path.abpos) goto inorder; if (ovl.path.abpos == prev.path.abpos) goto dupcheck; } else { if (ovl.bread > last.bread) goto inorder; if (ovl.bread == last.bread) { if (COMP(ovl.flags) > COMP(last.flags)) goto inorder; Loading @@ -282,26 +304,37 @@ int main(int argc, char *argv[]) } } } if (VERBOSE) { if (CHAIN_NEXT(ovl.flags)) fprintf(stderr," %s: Chain is not valid (%d vs %d)\n", root,ovl.aread+1,ovl.bread+1); else fprintf(stderr," %s: Reads are not sorted (%d vs %d)\n", root,ovl.aread+1,ovl.bread+1); } if (VERBOSE) fprintf(stderr," %s: LAs are not sorted (%d vs %d)\n", disp,ovl.aread+1,ovl.bread+1); goto error; } else else // First element of a chain { if (ovl.aread > prev.aread) goto inorder; if (ovl.aread == prev.aread) { if (MAP_ORDER) { if (ovl.path.abpos > prev.path.abpos) goto inorder; if (ovl.path.abpos == prev.path.abpos) goto dupcheck; } else { if (ovl.bread > prev.bread) goto inorder; if (ovl.bread == prev.bread) { if (COMP(ovl.flags) > COMP(prev.flags)) goto inorder; if (COMP(ovl.flags) == COMP(prev.flags)) { if (ovl.path.abpos > prev.path.abpos) goto inorder; if (ovl.path.abpos == prev.path.abpos) { equal = 1; goto dupcheck; } } } } } if (VERBOSE) fprintf(stderr," %s: Chains are not sorted (%d vs %d)\n", root,ovl.aread+1,ovl.bread+1); disp,ovl.aread+1,ovl.bread+1); goto error; } } Loading @@ -315,8 +348,8 @@ int main(int argc, char *argv[]) ovl.path.bbpos == last.path.bbpos && ovl.path.bepos == last.path.bepos) { if (VERBOSE) fprintf(stderr," %s: Duplicate overlap (%d vs %d)\n", root,ovl.aread+1,ovl.bread+1); fprintf(stderr," %s: Duplicate LAs (%d vs %d)\n", disp,ovl.aread+1,ovl.bread+1); goto error; } } Loading @@ -330,24 +363,30 @@ int main(int argc, char *argv[]) if (iptr < itop) { if (VERBOSE) fprintf(stderr," %s: Too many alignment records\n",root); fprintf(stderr," %s: Too many alignment records\n",disp); goto error; } if (VERBOSE) { fprintf(stderr," %s: ",root); Print_Number(novl,0,stderr); fprintf(stderr," all OK\n"); { printf(" %s: ",disp); Print_Number(novl,0,stdout); printf(" all OK\n"); fflush(stdout); } goto cleanup; error: status = 1; if (VERBOSE) { printf(" %s: Not OK, see stderr\n",disp); fflush(stdout); } cleanup: if (input != NULL) fclose(input); free(pwd); free(root); } Free_Block_Arg(parse); } free(iblock-ptrsize); Loading