filelist_t *get_filelist(const char *path, const char *filter) { DIR *d; struct stat st_in; struct dirent *de, **names=0, **tmp; size_t cnt=0, len=0; filelist_t *filelist; if (stat(path, &st_in) != 0 ) { return NULL; } if (!S_ISDIR(st_in.st_mode)) { filelist = filelist_alloc(1); sprintf(filelist->files[0],"%s",path); return filelist; } if ((d = opendir(path)) == NULL) { return(NULL); } while ((de = readdir(d))) { if (!file_selector(de->d_name, filter)) { continue; } if (cnt >= len) { len = 2*len+1; if (len > SIZE_MAX/sizeof *names) { break; } tmp = realloc(names, len * sizeof *names); if (!tmp) { break; } names = tmp; } names[cnt] = malloc(de->d_reclen); if (!names[cnt]) { break; } memcpy(names[cnt++], de, de->d_reclen); } closedir(d); filelist = filelist_alloc(cnt); if (names) { while (cnt-->0) { sprintf(filelist->files[cnt],"%s/%s",path,names[cnt]->d_name); free(names[cnt]); } free(names); } return filelist; }
filelist_t *MainWindow::QStringToFilelist(QFileInfoList list) { int i = 0; filelist_t *fileList = filelist_alloc(list.size()); while (!list.isEmpty()) { sprintf(fileList->files[i++],"%s",list.takeFirst().absoluteFilePath().toUtf8().data()); } return fileList; }
filelist_t *MainWindow::QStringToFilelist(QFileInfoList list) { int i = 0; filelist_t *fileList = filelist_alloc(list.size()); while (!list.isEmpty()) { sprintf(fileList->files[i++],"%s",list.takeFirst().absoluteFilePath().toUtf8().data()); if (is_filename_ascii(fileList->files[i-1]) == 0) { QString message = tr("Unicode is not supported. Filenames must contain only ASCII characters. File: ") + fileList->files[i-1]; QMessageBox::critical(this, tr("Invalid Characters in filename"), message); return NULL; } } return fileList; }
void MxfWriter::run() { int i = 0; opendcpMxf->mxf.frame_done.callback = MxfWriter::frameDoneCb; opendcpMxf->mxf.frame_done.argument = this; filelist_t *fileList = filelist_alloc(mxfFileList.size()); while (!mxfFileList.isEmpty()) { sprintf(fileList->files[i++],"%s",mxfFileList.takeFirst().absoluteFilePath().toUtf8().data()); } rc = write_mxf(opendcpMxf, fileList, mxfOutputFile.toUtf8().data()); filelist_free(fileList); emit setResult(rc); emit finished(); }
filelist_t *get_filelist(const char *path, const char *filter) { DIR *d; struct stat st_in; struct dirent *de; char **names = 0, **tmp; size_t cnt = 0, len = 0; filelist_t *filelist; if (stat(path, &st_in) != 0 ) { OPENDCP_LOG(LOG_DEBUG, "path not found %s", path); return NULL; } if (!S_ISDIR(st_in.st_mode)) { OPENDCP_LOG(LOG_DEBUG, "single file mode"); filelist = filelist_alloc(1); snprintf(filelist->files[0], MAX_FILENAME_LENGTH, "%s", path); return filelist; } if ((d = opendir(path)) == NULL) { return(NULL); } OPENDCP_LOG(LOG_DEBUG, "reading directory"); while ((de = readdir(d))) { if (!file_selector(de->d_name, filter)) { continue; } if (cnt >= len) { len = 2 * len + 1; if (len > SIZE_MAX / sizeof * names) { break; } tmp = realloc(names, len * sizeof * names); if (!tmp) { break; } names = tmp; } names[cnt] = malloc(strlen(de->d_name) + 1); if (!names[cnt]) { break; } snprintf(names[cnt++], strlen(de->d_name) + 1, "%s", de->d_name); OPENDCP_LOG(LOG_DEBUG, "Found %s", de->d_name); } closedir(d); OPENDCP_LOG(LOG_DEBUG, "found %d files", cnt); filelist = filelist_alloc(cnt); if (names) { while (cnt-- > 0) { OPENDCP_LOG(LOG_DEBUG, "Adding file %s", names[cnt]); snprintf(filelist->files[cnt], MAX_FILENAME_LENGTH, "%s/%s", path, names[cnt]); free(names[cnt]); } free(names); } return filelist; }
int main(int argc, char **argv) { if(argc < 3) print_usage(usage, NULL); // Sample reads from ref char *refpath = NULL; // int optt = 0, tlen = 800; double tlen_stddev = 0.1; int insert = 250, rlen = 250, single_ended = 0; double depth = 1.0, insert_stddev_prop = 0.2; // stddev as proportion of insert int optr = 0, opti = 0, optv = 0, optl = 0, optd = 0; // keeps track of values uint64_t seed = generate_seed(); // default RNG seed char *in0path = NULL, *in1path = NULL; char *profile_paths[argc]; size_t num_profile_paths = 0, i, total_seq = 0; float err_rate = -1; int c; while((c = getopt(argc, argv, "p:r:i:v:l:d:s1:2:e:g:")) >= 0) { switch (c) { case 'p': profile_paths[num_profile_paths++] = optarg; break; case 'r': refpath = optarg; optr++; break; // case 't': tlen = atoi(optarg); optt++; break; // case 'v': tlen_stddev = atof(optarg); optv++; break; case 'i': insert = atoi(optarg); opti++; break; case 'v': insert_stddev_prop = atof(optarg); optv++; break; case 'l': rlen = atoi(optarg); optl++; break; case 'd': depth = atof(optarg); optd++; break; case 's': single_ended = 1; break; case '1': in0path = optarg; break; case '2': in1path = optarg; break; case 'e': err_rate = atof(optarg); break; case 'g': seed = atoi(optarg); break; default: die("Unknown option: %c", c); } } // Set up seed_random(seed); init_qual_prob(); char *outbase = NULL; if(optind == argc) {}//print_usage(usage, "Missing <out_base>"); else if(optind + 1 == argc) outbase = argv[optind]; else if(optind + 1 < argc) print_usage(usage, "Too many args after %s", outbase); if(depth <= 0) print_usage(usage, "Depth [-d] cannot be <= 0"); if(insert_stddev_prop < 0) print_usage(usage, "Insert length standard deviation [-v] cannot be < 0"); if((opti > 0 || optv > 0 || optl > 0 || optd > 0) && refpath == NULL) print_usage(usage, "Missing -r <in.fa>"); if(optr > 1 || opti > 1 || optv > 1 || optl > 1 || optd > 1) print_usage(usage, "Duplicate args"); if(in0path == NULL && in1path != NULL) print_usage(usage, "-2 <in> requires -1 <in>"); if(in0path != NULL && in1path == NULL) { if(refpath == NULL) single_ended = 1; else if(!single_ended) print_usage(usage, "Missing -2 for paired-end output"); } if(in0path != NULL && num_profile_paths == 0) print_usage(usage, "Need at least one -p <profile.fq.gz> to use -1 .. -2 .."); if(num_profile_paths == 0 && refpath == NULL) print_usage(usage, "Need one of -p or -r"); if(num_profile_paths == 0 && outbase == NULL) print_usage(usage, "More options required"); if(num_profile_paths > 0 && err_rate >= 0) print_usage(usage, "Cannot use both -p and -E"); // Profile reads FileList fliststore, *flist = NULL; if(num_profile_paths > 0) { flist = &fliststore; filelist_alloc(flist, profile_paths, num_profile_paths); } if(outbase == NULL) { // Summarise error profile in input filelist_mean_err(flist); } else { size_t outlen = strlen(outbase), extlen = strlen(".1.fa.gz"); char out0path[outlen+extlen+1], out1path[outlen+extlen+1]; memcpy(out0path, outbase, outlen); memcpy(out1path, outbase, outlen); if(single_ended) strcpy(out0path+outlen, ".fa.gz"); else { strcpy(out0path+outlen, ".1.fa.gz"); strcpy(out1path+outlen, ".2.fa.gz"); } gzFile gzout0 = NULL, gzout1 = NULL; seq_file_t *sf0 = NULL, *sf1 = NULL, *reffile = NULL; if(in0path != NULL && (sf0 = seq_open(in0path)) == NULL) die("Cannot read: %s", in0path); if(in1path != NULL && (sf1 = seq_open(in1path)) == NULL) die("Cannot read: %s", in1path); if(refpath != NULL) { if((reffile = seq_open(refpath)) == NULL) die("Cannot read: %s", refpath); if((gzout0 = gzopen(out0path, "w")) == NULL) die("Cannot open: %s", out0path); if(!single_ended && (gzout1 = gzopen(out1path, "w")) == NULL) die("Cannot open: %s", out1path); } if(sf0 != NULL) { printf("Adding error to input reads...\n"); total_seq += mutate_reads(sf0, gzout0, flist, err_rate); seq_close(sf0); } if(sf1 != NULL) { total_seq += mutate_reads(sf1, single_ended ? gzout0 : gzout1, flist, err_rate); seq_close(sf1); } if(refpath != NULL) { printf("Sampling from %s\n", refpath); printf(" sequencing depth: %.2f\n", depth); printf(" read length: %i\n", rlen); printf(" read pairs: %s\n", single_ended ? "no" : "yes"); if(!single_ended) { printf(" insert length: %i\n", insert); printf(" insert stddev: %.2f * insert = %.2f\n", insert_stddev_prop, insert_stddev_prop*insert); } if(num_profile_paths > 0) { printf(" seq error files: %s", flist->files[0]->path); for(i = 1; i < num_profile_paths; i++) printf(",%s", flist->files[i]->path); printf("\n"); } else if(err_rate >= 0) { printf(" seq error rate: %.2f%%\n", err_rate * 100.0); } else { printf(" sequencing errors: no\n"); } total_seq += sim_reads(reffile, gzout0, gzout1, flist, err_rate, insert, insert_stddev_prop*insert, rlen, depth); seq_close(reffile); } if(gzout0 != NULL && gzout1 != NULL) printf("Wrote %zu bases to: %s and %s\n", total_seq, out0path, out1path); else if(gzout0 != NULL) printf("Wrote %zu bases to: %s\n", total_seq, out0path); if(gzout0 != NULL) gzclose(gzout0); if(gzout1 != NULL) gzclose(gzout1); } if(flist != NULL) { // Print error distribution size_t err_total = 0; for(i = 0; i < flist->errors_len; i++) err_total += flist->errors[i]; printf("Errors: %zu / %zu (%.2f%%)\n", err_total, total_seq, (100.0*err_total) / total_seq); for(i = 0; i < flist->errors_len; i++) printf(" %zu", flist->errors[i]); printf("\n"); filelist_dealloc(flist); } return EXIT_SUCCESS; }