void bwtool_find_thresh(struct hash *options, char *favorites, char *regions, double fill, char *thresh_type, char *thresh_s, char *bigfile, char *tmp_dir, char *outputfile) /* the other kind of finding, based on thresholding. */ { boolean inverse = (hashFindVal(options, "inverse") != NULL) ? TRUE : FALSE; enum bw_op_type op= get_bw_op_type(thresh_type, inverse); struct metaBig *mb = metaBigOpen_check(bigfile, tmp_dir, regions); double thresh = sqlDouble(thresh_s); FILE *out = mustOpen(outputfile, "w"); struct bed out_bed; struct bed *section; for (section = mb->sections; section != NULL; section = section->next) { struct perBaseWig *pbwList = perBaseWigLoadContinue(mb, section->chrom, section->chromStart, section->chromEnd); struct perBaseWig *pbw; int i, len; if (pbwList) { out_bed.chrom = pbwList->chrom; for (pbw = pbwList; pbw != NULL; pbw = pbw->next) { i = 0; len = pbw->chromEnd - pbw->chromStart; out_bed.chromStart = out_bed.chromEnd = 0; while (i < len) { while ((i < len) && (!fit_thresh(pbw->data[i], thresh, op))) i++; out_bed.chromStart = i + pbw->chromStart; while ((i < len) && (fit_thresh(pbw->data[i], thresh, op))) i++; out_bed.chromEnd = i + pbw->chromStart; if (out_bed.chromEnd > out_bed.chromStart) bedTabOutN(&out_bed, 3, out); } } perBaseWigFree(&pbwList); } } metaBigClose(&mb); carefulClose(&out); }
/*----------------------------- get_next_scan -------------------------------*/ int get_next_scan( int nscan) { if ( nscan != 1) { // we don't need to fit and save at the begining fit_thresh(nscan-1); save_hist(nscan-1); print_scan_result(nscan-1); HDELET(0); } init_hist (nscan); return 0; }