int main(int argc, char *argv[]) { HITS_DB _db, *db = &_db; HITS_READ *reads; int VERBOSE; int SORTED; int RANGE; // Process options { int i, j, k; int flags[128]; ARG_INIT("LAcheck") RANGE = 0; reads = NULL; j = 1; for (i = 1; i < argc; i++) if (argv[i][0] == '-') switch (argv[i][1]) { default: ARG_FLAGS("vS") break; case 'a': RANGE = 1; if (argv[i][2] != ':') { fprintf(stderr,"%s: Unrecognizable option %s\n",Prog_Name,argv[i]); exit (1); } if (Open_DB(argv[i]+3,db)) exit (1); Trim_DB(db); reads = db->reads; break; } else argv[j++] = argv[i]; argc = j; VERBOSE = flags['v']; SORTED = flags['S']; if (argc < 2) { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage); exit (1); } }
static int read_DB(DAZZ_DB *block, char *name, int kmer) { int i, isdam; isdam = Open_DB(name,block); if (isdam < 0) Clean_Exit(1); Trim_DB(block); if (block->cutoff < kmer) { for (i = 0; i < block->nreads; i++) if (block->reads[i].rlen < kmer) { fprintf(stderr,"%s: Block %s contains reads < %dbp long ! Run DBsplit.\n", Prog_Name,name,kmer); Clean_Exit(1); } } Read_All_Sequences(block,0); return (isdam); }
static HITS_DB *read_DB(char *name, int dust) { static HITS_DB block; HITS_TRACK *dtrack; if (Open_DB(name,&block)) exit (1); if (dust) dtrack = Load_Track(&block,"dust"); else dtrack = NULL; Trim_DB(&block); if (block.totlen > 0x7fffffffll) { fprintf(stderr,"File (%s) is too large\n",name); exit (1); } if (block.nreads > 0xffff) { fprintf(stderr,"There are more than %d reads in file (%s)\n",0xffff,name); exit (1); } if (block.maxlen > 0xffff) { fprintf(stderr,"Reads are over %d bases long in file (%s)\n",0xffff,name); exit (1); } Read_All_Sequences(&block,0); if (dtrack != NULL) { int *anno = (int *) (dtrack->anno); int i; for (i = 0; i <= block.nreads; i++) anno[i] /= sizeof(int); } return (&block); }
static int read_DB(DAZZ_DB *block, char *name, char **mask, int *mstat, int mtop, int kmer) { int i, isdam, status, kind, stop; isdam = Open_DB(name,block); if (isdam < 0) Clean_Exit(1); for (i = 0; i < mtop; i++) { status = Check_Track(block,mask[i],&kind); if (status >= 0) if (kind == MASK_TRACK) mstat[i] = 0; else { if (mstat[i] != 0) mstat[i] = -3; } else { if (mstat[i] == -2) mstat[i] = status; } if (status == 0 && kind == MASK_TRACK) Open_Track(block,mask[i]); } Trim_DB(block); stop = 0; for (i = 0; i < mtop; i++) { DAZZ_TRACK *track; int64 *anno; int j; status = Check_Track(block,mask[i],&kind); if (status < 0 || kind != MASK_TRACK) continue; stop += 1; track = Open_Track(block,mask[i]); Load_All_Track_Data(track); anno = (int64 *) (track->anno); for (j = 0; j <= block->nreads; j++) anno[j] /= sizeof(int); } if (stop > 1) { int64 nsize; DAZZ_TRACK *track; nsize = merge_size(block,stop); track = merge_tracks(block,stop,nsize); while (block->tracks != NULL) Close_Track(block,block->tracks); block->tracks = track; } if (block->cutoff < kmer) { for (i = 0; i < block->nreads; i++) if (block->reads[i].rlen < kmer) { fprintf(stderr,"%s: Block %s contains reads < %dbp long ! Run DBsplit.\n", Prog_Name,name,kmer); Clean_Exit(1); } } Load_All_Reads(block,0); return (isdam); }
char *openModel(char *Alas, char *Adb, char *Bdb, int first, int last, int nolink, int nolap, int elim, int max_comp, int max_expn) { static char buffer[2*MAX_NAME+100]; static DAZZ_DB _db1; static DAZZ_DB _db2; FILE *dbfile; if (FIRSTCALL) { FIRSTCALL = 0; Prog_Name = Strdup("DaViewer",""); } if ( ! UNDEFINED) { Close_DB(MODEL.db1); if (MODEL.db1 != MODEL.db2) Close_DB(MODEL.db2); fclose(MODEL.input); free(MODEL.local); free(MODEL.pile+MODEL.first); free(MODEL.tbuf); } UNDEFINED = 1; { int i, nfiles, nblocks, cutoff, all, oindx; int64 size; int la_first, la_last; int db_first, db_last; FILE *input; input = fopen(Alas,"r"); if (input == NULL) { if (rindex(Alas,'/') != NULL) Alas = rindex(Alas,'/')+1; EPRINTF(EPLACE,"%s: Cannot open file %s\n",Prog_Name,Alas); return (Ebuffer); } if (scanLAS(input,&la_first,&la_last)) { if (rindex(Alas,'/') != NULL) Alas = rindex(Alas,'/')+1; EPRINTF(EPLACE,"%s: LAS file %s has no overlaps !\n",Prog_Name,Alas); fclose(input); return (Ebuffer); } fclose(input); dbfile = Fopen(Adb,"r"); if (dbfile == NULL) return (Ebuffer); if (fscanf(dbfile,DB_NFILE,&nfiles) != 1) goto junk; for (i = 0; i < nfiles; i++) if (fgets(buffer,2*MAX_NAME+100,dbfile) == NULL) goto junk; if (fscanf(dbfile,DB_NBLOCK,&nblocks) != 1) { if (feof(dbfile)) { EPRINTF(EPLACE,"%s: Database has not been split!",Prog_Name); goto error; } goto junk; } if (fscanf(dbfile,DB_PARAMS,&size,&cutoff,&all) != 3) goto junk; for (i = 0; i <= nblocks; i++) { if (fscanf(dbfile,DB_BDATA,&oindx,&db_last) != 2) goto junk; if (la_first >= db_last) db_first = db_last; if (la_last < db_last) break; } fclose(dbfile); if (first >= 0) { if (first >= db_last) { EPRINTF(EPLACE,"First requested read %d is > last read in las block %d\n", first+1,db_last); return (Ebuffer); } else if (first > db_first) db_first = first; } if (last >= 0) { if (last <= db_first) { EPRINTF(EPLACE,"Last requested read %d is < first read in las block %d\n", last,db_first+1); return (Ebuffer); } else if (last < db_last) db_last = last; } MODEL.first = db_first; MODEL.last = db_last; } MODEL.db1 = &_db1; if (Open_DB(Adb,MODEL.db1) < 0) return (Ebuffer); if (Bdb == NULL) MODEL.db2 = MODEL.db1; else { MODEL.db2 = &_db2; if (Open_DB(Bdb,MODEL.db2) < 0) { Close_DB(MODEL.db1); return (Ebuffer); } Trim_DB(MODEL.db2); } Trim_DB(MODEL.db1); if (List_DB_Files(Adb,OPEN_MASKS)) return (Ebuffer); { int i, n; DAZZ_READ *read = MODEL.db2->reads; n = MODEL.db2->nreads; for (i = 0; i < n; i++) read[i].flags &= (DB_CSS | DB_BEST); } { int kind; if (Check_Track(MODEL.db1,"prof",&kind) > -2) { MODEL.prf = Load_Track(MODEL.db1,"prof"); if (MODEL.prf == NULL) { Close_DB(MODEL.db1); if (MODEL.db2 != MODEL.db1) Close_DB(MODEL.db2); return (Ebuffer); } } else MODEL.prf = NULL; if (Check_Track(MODEL.db1,"qual",&kind) > -2) { MODEL.qvs = Load_Track(MODEL.db1,"qual"); if (MODEL.qvs == NULL) { Close_DB(MODEL.db1); if (MODEL.db2 != MODEL.db1) Close_DB(MODEL.db2); return (Ebuffer); } } else MODEL.qvs = NULL; } MODEL.input = fopen(Alas,"r"); if (buildModel(nolink,nolap,elim,max_comp,max_expn)) { fclose(MODEL.input); Close_DB(MODEL.db1); if (MODEL.db2 != MODEL.db1) Close_DB(MODEL.db2); return (Ebuffer); } { DAZZ_TRACK *t, *u, *v; int j; int64 *anno; u = NULL; for (t = MODEL.db1->tracks; t != NULL; t = v) { v = t->next; t->next = u; u = t; } MODEL.db1->tracks = u; for (t = MODEL.db1->tracks; t != MODEL.qvs && t != MODEL.prf; t = t->next) { anno = (int64 *) (t->anno); for (j = 0; j <= MODEL.db1->nreads; j++) anno[j] >>= 2; } } UNDEFINED = 0; return (NULL); junk: if (rindex(Adb,'/') != NULL) Adb = rindex(Adb,'/')+1; EPRINTF(EPLACE,"%s: Stub file %s is junk!\n",Prog_Name,Adb); error: fclose(dbfile); return (Ebuffer); }