void printCounts(char *chr,int *posi,suint **counts,int nSites,size_t nInd,kstring_t &bpos,kstring_t &bbin,int dumpType,int *keepSites){ bpos.l=bbin.l=0; for(int s=0;s<nSites;s++){ if(keepSites[s]==0) continue; ksprintf(&bpos, "%s\t%d\t%d\n",chr,posi[s]+1,calcSum(counts[s],4*nInd)); //if we need per sample info if(dumpType>1) { if(dumpType==4)//count A,C,G,T for(int i=0;i<4*nInd;i++) ksprintf(&bbin,"%u\t",counts[s][i]); else if(dumpType==2){//print A+C+G+T for(int n=0;n<nInd;n++) ksprintf(&bbin,"%u\t",counts[s][n*4]+counts[s][n*4+1]+counts[s][n*4+2]+counts[s][n*4+3]); }else{//overall sum of A,C,G,T size_t tsum[4]={0,0,0,0}; for(int i=0;i<4*nInd;i++) tsum[i%4] +=counts[s][i]; ksprintf(&bbin,"%zu\t%zu\t%zu\t%zu",tsum[0],tsum[1],tsum[2],tsum[3]); } kputc('\n',&bbin); } } }
bam_header_t *sam_header_read2(const char *fn) { bam_header_t *header; int c, dret, n_targets = 0; gzFile fp; kstream_t *ks; kstring_t *str; kstring_t samstr = { 0, 0, NULL }; if (fn == 0) return 0; fp = (strcmp(fn, "-") == 0)? gzdopen(fileno(stdin), "r") : gzopen(fn, "r"); if (fp == 0) return 0; ks = ks_init(fp); str = (kstring_t*)calloc(1, sizeof(kstring_t)); while (ks_getuntil(ks, 0, str, &dret) > 0) { ksprintf(&samstr, "@SQ\tSN:%s", str->s); ks_getuntil(ks, 0, str, &dret); ksprintf(&samstr, "\tLN:%d\n", atoi(str->s)); n_targets++; if (dret != '\n') while ((c = ks_getc(ks)) != '\n' && c != -1); } ks_destroy(ks); gzclose(fp); free(str->s); free(str); header = sam_hdr_parse(samstr.l, samstr.s? samstr.s : ""); free(samstr.s); fprintf(pysamerr, "[sam_header_read2] %d sequences loaded.\n", n_targets); return header; }
static void afd_describe(device_t dev) { struct ata_channel *ch = device_get_softc(device_get_parent(dev)); struct ata_device *atadev = device_get_softc(dev); struct afd_softc *fdp = device_get_ivars(dev); char sizestring[16]; if (fdp->mediasize > 1048576 * 5) ksprintf(sizestring, "%lluMB", (unsigned long long) (fdp->mediasize / 1048576)); else if (fdp->mediasize) ksprintf(sizestring, "%lluKB", (unsigned long long) (fdp->mediasize / 1024)); else strcpy(sizestring, "(no media)"); device_printf(dev, "%s <%.40s %.8s> at ata%d-%s %s\n", sizestring, atadev->param.model, atadev->param.revision, device_get_unit(ch->dev), (atadev->unit == ATA_MASTER) ? "master" : "slave", ata_mode2str(atadev->mode)); if (bootverbose) { device_printf(dev, "%llu sectors [%lluC/%dH/%dS]\n", (unsigned long long)(fdp->mediasize / fdp->sectorsize), (unsigned long long) (fdp->mediasize/(fdp->sectorsize*fdp->sectors*fdp->heads)), fdp->heads, fdp->sectors); } }
/* * Executes hash_dmp_fn on each of the temporary files in the splitterhash * and cleans up if not disabled. */ void parallel_hash_dmp_core(marksplit_settings_t *settings, splitterhash_params_t *params, hash_dmp_fn func) { #pragma omp parallel for schedule(dynamic, 1) for(int i = 0; i < settings->n_handles; ++i) { LOG_DEBUG("Now running hash dmp core on input filename %s and output filename %s.\n", params->infnames_r1[i], params->outfnames_r1[i]); func(params->infnames_r1[i], params->outfnames_r1[i], settings->gzip_compression); if(settings->cleanup) { kstring_t ks{0, 0, nullptr}; ksprintf(&ks, "rm %s", params->infnames_r1[i]); dlib::check_call(ks.s); free(ks.s); } } if(settings->is_se) { LOG_DEBUG("Only dmp'ing single end.\n"); return; // Don't dmp imaginary files.... } #pragma omp parallel for schedule(dynamic, 1) for(int i = 0; i < settings->n_handles; ++i) { LOG_DEBUG("Now running hash dmp core on input filename %s and output filename %s.\n", params->infnames_r2[i], params->outfnames_r2[i]); func(params->infnames_r2[i], params->outfnames_r2[i], settings->gzip_compression); if(settings->cleanup) { kstring_t ks{0, 0, nullptr}; ksprintf(&ks, "rm %s", params->infnames_r2[i]); dlib::check_call(ks.s); free(ks.s); } } }
void cat_fastqs_pe(marksplit_settings_t *settings, splitterhash_params_t *params, char *ffq_r1, char *ffq_r2) { kstring_t ks1{0, 0, nullptr}; kputsnl("> ", &ks1), kputs(ffq_r1, &ks1); if(settings->gzip_output) kputsnl(".gz", &ks1); // Clear output files. //ksprintf(&ks1, settings->gzip_output ? "> %s.gz" : "> %s", ffq_r1); dlib::check_call(ks1.s); ks1.l = 0; ksprintf(&ks1, settings->gzip_output ? "> %s.gz" : "> %s", ffq_r2); dlib::check_call(ks1.s); ks1.l = 0; kputsnl("/bin/cat ", &ks1); kstring_t ks2{0}; kputsn(ks1.s, ks1.l, &ks2); for(int i(0); i < settings->n_handles; ++i) { if(!dlib::isfile(params->outfnames_r1[i])) LOG_EXIT("Output filename is not a file. Abort! ('%s').\n", params->outfnames_r1[i]); if(!dlib::isfile(params->outfnames_r2[i])) LOG_EXIT("Output filename is not a file. Abort! ('%s').\n", params->outfnames_r2[i]); ksprintf(&ks1, "%s ", params->outfnames_r1[i]); ksprintf(&ks2, "%s ", params->outfnames_r2[i]); } ksprintf(&ks1, " > %s", ffq_r1); ksprintf(&ks2, " > %s", ffq_r2); if(settings->gzip_output) { kputsnl(".gz", &ks1); kputsnl(".gz", &ks2); } FILE *c1_popen(popen(ks1.s, "w")); FILE *c2_popen(popen(ks2.s, "w")); int ret; if((ret = ((pclose(c2_popen) << 8) | pclose(c1_popen)))) { LOG_EXIT("Background cat command(s) failed. (Code: %i, '%s' or %i, '%s').\n", ret >> 8, ks1.s, ret & 0xff, ks2.s); }
int main(int argc, char *argv[]) { extern char *bwa_pg; int i, ret; double t_real; kstring_t pg = {0,0,0}; t_real = realtime(); ksprintf(&pg, "@PG\tID:biscuit\tPN:biscuit\tVN:%s\tCL:%s", PACKAGE_VERSION, argv[0]); for (i = 1; i < argc; ++i) ksprintf(&pg, " %s", argv[i]); bwa_pg = pg.s; if (argc < 2) return usage(); if (strcmp(argv[1], "index") == 0) ret = main_biscuit_index(argc-1, argv+1); else if (strcmp(argv[1], "align") == 0) ret = main_align(argc-1, argv+1); else if (strcmp(argv[1], "pileup") == 0) ret = main_pileup(argc-1, argv+1); else if (strcmp(argv[1], "somatic") == 0) ret = main_somatic(argc-1, argv+1); else { fprintf(stderr, "[main] unrecognized command '%s'\n", argv[1]); return 1; } err_fflush(stdout); err_fclose(stdout); if (ret == 0) { fprintf(stderr, "[%s] Version: %s\n", __func__, PACKAGE_VERSION); fprintf(stderr, "[%s] CMD:", __func__); for (i = 0; i < argc; ++i) fprintf(stderr, " %s", argv[i]); fprintf(stderr, "\n[%s] Real time: %.3f sec; CPU: %.3f sec\n", __func__, realtime() - t_real, cputime()); } free(bwa_pg); return ret; }
void usbd_devinfo(usbd_device_handle dev, int showclass, char *cp) { usb_device_descriptor_t *udd = &dev->ddesc; usbd_interface_handle iface; char vendor[USB_MAX_STRING_LEN]; char product[USB_MAX_STRING_LEN]; int bcdDevice, bcdUSB; usb_interface_descriptor_t *id; usbd_devinfo_vp(dev, vendor, product, 1); cp += ksprintf(cp, "%s %s", vendor, product); if (showclass & USBD_SHOW_DEVICE_CLASS) cp += ksprintf(cp, ", class %d/%d", udd->bDeviceClass, udd->bDeviceSubClass); bcdUSB = UGETW(udd->bcdUSB); bcdDevice = UGETW(udd->bcdDevice); cp += ksprintf(cp, ", rev "); cp += usbd_printBCD(cp, bcdUSB); *cp++ = '/'; cp += usbd_printBCD(cp, bcdDevice); cp += ksprintf(cp, ", addr %d", dev->address); if (showclass & USBD_SHOW_INTERFACE_CLASS) { /* fetch the interface handle for the first interface */ (void)usbd_device2interface_handle(dev, 0, &iface); id = usbd_get_interface_descriptor(iface); cp += ksprintf(cp, ", iclass %d/%d", id->bInterfaceClass, id->bInterfaceSubClass); } *cp = 0; }
bool addUser::checkMailBox() { QString mailboxpath; QString tmp; struct stat s; int r; ksprintf(&mailboxpath, "%s/%s", MAIL_SPOOL_DIR, (const char *)user->getName()); r = stat(mailboxpath, &s); if ((r == -1) && (errno == ENOENT)) return true; if (r == 0) if (S_ISREG(s.st_mode)) ksprintf(&tmp, i18n("Mailbox %s already exist (uid=%d)"), (const char *)mailboxpath, s.st_uid); else ksprintf(&tmp, i18n("%s exists but is not a regular file"), (const char *)mailboxpath); else ksprintf(&tmp, "checkMail: stat: %s ", strerror(errno)); err->addMsg(tmp, STOP); err->display(); return false; }
char *bwa_cal_md1(int n_cigar, jigsaw_cigar_t *cigar, int len, bwtint_t pos, ubyte_t *seq, bwtint_t l_pac, const ubyte_t *pacseq, kstring_t *str, int *_nm) { bwtint_t x, y; int z, u, c, nm = 0; str->l = 0; // reset x = pos; y = 0; if (cigar) { int k, l; for (k = u = 0; k < n_cigar; ++k) { l = __cigar_len(cigar[k]); uint8_t op = __cigar_op(cigar[k]); if (op == CIGAR_OP_M) { for (z = 0; z < l && x+z < l_pac; ++z) { c = get_pacseq_base (pacseq, x+z); //c = pacseq[(x+z)>>2] >> ((~(x+z)&3)<<1) & 3; if (c > 3 || seq[y+z] > 3 || c != seq[y+z]) {//mismatch ksprintf(str, "%d", u); kputc("ACGTN"[c], str); ++nm; u = 0; } else ++u; } x += l; y += l; /* } else if (cigar[k]>>14 == FROM_I || cigar[k]>>14 == 3) { */ } else if (op == CIGAR_OP_I || op == CIGAR_OP_S) { y += l; if (op == FROM_I) nm += l; } else if (op == CIGAR_OP_D) { ksprintf(str, "%d", u); kputc('^', str); for (z = 0; z < l && x+z < l_pac; ++z) kputc("ACGT"[get_pacseq_base (pacseq, x+z)], str); //kputc("ACGT"[pacseq[(x+z)>>2] >> ((~(x+z)&3)<<1) & 3], str); u = 0; x += l; nm += l; } else if (op == CIGAR_OP_N) { //intron ksprintf(str, "%d", u); kputc(',', str); u = 0; x += l; } } } else { // no gaps for (z = u = 0; z < len; ++z) { c = get_pacseq_base (pacseq, x+z); //c = pacseq[(x+z)>>2] >> ((~(x+z)&3)<<1) & 3; if (c > 3 || seq[y+z] > 3 || c != seq[y+z]) { ksprintf(str, "%d", u); kputc("ACGTN"[c], str); ++nm; u = 0; } else ++u; } } ksprintf(str, "%d", u); *_nm = nm; return strdup(str->s); }
void bcf_hdr_fmt_text(bcf_hdr_t *hdr) { int i,j; kstring_t txt = {0,0,0}; for (i=0; i<hdr->nhrec; i++) { if ( !hdr->hrec[i]->value ) { ksprintf(&txt, "##%s=<", hdr->hrec[i]->key); ksprintf(&txt,"%s=%s", hdr->hrec[i]->keys[0], hdr->hrec[i]->vals[0]); for (j=1; j<hdr->hrec[i]->nkeys; j++) ksprintf(&txt,",%s=%s", hdr->hrec[i]->keys[j], hdr->hrec[i]->vals[j]); ksprintf(&txt,">\n"); } else ksprintf(&txt,"##%s=%s\n", hdr->hrec[i]->key,hdr->hrec[i]->value); } ksprintf(&txt,"#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO"); if ( hdr->n[BCF_DT_SAMPLE] ) { ksprintf(&txt,"\tFORMAT"); for (i=0; i<hdr->n[BCF_DT_SAMPLE]; i++) ksprintf(&txt,"\t%s", hdr->samples[i]); } ksprintf(&txt,"\n"); if ( hdr->text ) free(hdr->text); hdr->text = txt.s; hdr->l_text = txt.l; }
static int auth_header_callback(void *ctx, char ***hdrs) { s3_auth_data *ad = (s3_auth_data *) ctx; time_t now = time(NULL); #ifdef HAVE_GMTIME_R struct tm tm_buffer; struct tm *tm = gmtime_r(&now, &tm_buffer); #else struct tm *tm = gmtime(&now); #endif kstring_t message = { 0, 0, NULL }; unsigned char digest[DIGEST_BUFSIZ]; size_t digest_len; if (!hdrs) { // Closing connection free_auth_data(ad); return 0; } if (now - ad->auth_time < AUTH_LIFETIME) { // Last auth string should still be valid *hdrs = NULL; return 0; } strftime(ad->date, sizeof(ad->date), "Date: %a, %d %b %Y %H:%M:%S GMT", tm); if (!ad->id.l || !ad->secret.l) { ad->auth_time = now; return copy_auth_headers(ad, hdrs); } if (ksprintf(&message, "%s\n\n\n%s\n%s%s%s/%s", ad->mode == 'r' ? "GET" : "PUT", ad->date + 6, ad->token.l ? "x-amz-security-token:" : "", ad->token.l ? ad->token.s : "", ad->token.l ? "\n" : "", ad->bucket) < 0) { return -1; } digest_len = s3_sign(digest, &ad->secret, &message); ad->auth_hdr.l = 0; if (ksprintf(&ad->auth_hdr, "Authorization: AWS %s:", ad->id.s) < 0) goto fail; base64_kput(digest, digest_len, &ad->auth_hdr); free(message.s); ad->auth_time = now; return copy_auth_headers(ad, hdrs); fail: free(message.s); return -1; }
int makeold(int argc,char **argv){ if(argc<1){ fprintf(stderr,"\t-> output is a vcf2fq style file \n"); return 0; } args *pars = getArgs(argc,argv); writepsmc_header(stderr,pars->perc); double *gls = new double[2*pars->perc->nSites]; size_t at=0; //first pull all the data for(myMap::iterator it=pars->perc->mm.begin();it!=pars->perc->mm.end();++it){ if(pars->chooseChr!=NULL) it = iter_init(pars->perc,pars->chooseChr,pars->start,pars->stop); else it = iter_init(pars->perc,it->first,pars->start,pars->stop); // fprintf(stderr,"it->first:%s\tlast:%lu\n",it->first,pars->perc->last); memcpy(gls+at,pars->perc->gls,sizeof(double)*2*pars->perc->last); at += pars->perc->last; if(pars->chooseChr!=NULL) break; } double opt = 0.01; double llh = em(opt,gls,at,1e-8); fprintf(stderr,"estimated het:%f with llh:%f\n",opt,llh); delete [] gls; kstring_t kstr;kstr.l=kstr.m=0;kstr.s=NULL; for(myMap::iterator it=pars->perc->mm.begin();it!=pars->perc->mm.end();++it){ if(pars->chooseChr!=NULL) it = iter_init(pars->perc,pars->chooseChr,pars->start,pars->stop); else it = iter_init(pars->perc,it->first,pars->start,pars->stop); ksprintf(&kstr,">%s\n",it->first); double *pp = new double[pars->perc->last]; calcpost(opt,pars->perc->gls,pars->perc->last,pp); writefa(&kstr,pp,pars->perc->last,100,50,0.9); if(kstr.l>0&&kstr.s[kstr.l-1]!='\n') ksprintf(&kstr,"\n"); fwrite(kstr.s,sizeof(char),kstr.l,stdout); kstr.l=0; delete [] pp; if(pars->chooseChr!=NULL) break; } free(kstr.s); /* break; */ return 0; }
void frequency::prepPrint(funkyPars *pars){ kstring_t *bufstr = new kstring_t ; bufstr->s=NULL; bufstr->l=bufstr->m=0; for(int s=0;s<pars->numSites;s++) { if(pars->keepSites[s]==0) continue; //plugin chr,pos,major,minor kputs(header->name[pars->refId],bufstr);kputc('\t',bufstr); kputw(pars->posi[s]+1,bufstr);kputc('\t',bufstr); kputc(intToRef[pars->major[s]],bufstr);kputc('\t',bufstr); kputc(intToRef[pars->minor[s]],bufstr);kputc('\t',bufstr); //plugin ref, anc if exists if(pars->ref!=NULL) {kputc(intToRef[pars->ref[s]],bufstr);kputc('\t',bufstr);} if(pars->anc!=NULL) {kputc(intToRef[pars->anc[s]],bufstr);kputc('\t',bufstr);} if(doMaf &1) ksprintf(bufstr,"%f\t",pars->results->freq->pml[s]); if(doMaf &2) ksprintf(bufstr,"%f\t",pars->results->freq->pEM[s]); if(doMaf &4) ksprintf(bufstr,"%f\t",pars->results->freq->pmlun[s]); if(doMaf &8) ksprintf(bufstr,"%f\t",pars->results->freq->pEMun[s]); if(doMaf &16) ksprintf(bufstr,"%f\t",pars->results->asso->freq[s]); if(doMaf &32) ksprintf(bufstr,"%f\t",pars->phat[s]); if(doSNP){ if(doMaf &1) ksprintf(bufstr,"%f\t",pars->results->freq->pmlSNP[s]); if(doMaf &2) ksprintf(bufstr,"%f\t",pars->results->freq->pEMSNP[s]); if(doMaf &4) ksprintf(bufstr,"%f\t",pars->results->freq->pmlunSNP[s]); if(doMaf &8) ksprintf(bufstr,"%f\t",pars->results->freq->pEMunSNP[s]); } kputw(pars->keepSites[s],bufstr);kputc('\n',bufstr); } pars->extras[index] = bufstr; }
void abcFilterSNP::run(funkyPars *pars){ if(!doSnpStat) return; chunkyT *chk = pars->chk; if(doSnpStat==1){ kstring_t *bufstr = new kstring_t; bufstr->s=NULL;bufstr->l=bufstr->m=0; //loop over sites; for(int s=0;s<pars->numSites;s++){ if(pars->keepSites[s]==0) continue; //loop over samples int cnts[4]={0,0,0,0}; for(int i=0;i<pars->nInd;i++){ tNode *nd = chk->nd[s][i]; if(nd==NULL) continue; for(int l=0;l<nd->l;l++){ int obB = refToInt[nd->seq[l]]; // fprintf(stderr,"%c ",nd.seq[l]); int strand = (isupper(nd->seq[l])==0)<<1; // fprintf(stderr,"strand:%d\n",strand); if(obB==4) continue; if((obB!=pars->major[s] && obB!=pars->minor[s]) ) continue; if(obB!=pars->major[s]) strand +=1; //fprintf(stderr,"strand=%d\n",strand); cnts[strand]++; } } ksprintf(bufstr,"%s\t%d\t%d %d %d %d\t",header->target_name[pars->refId],pars->posi[s]+1, cnts[0],cnts[1],cnts[2],cnts[3]); ksprintf(bufstr,"%f:%f:%f\t",sb1(cnts),sb2(cnts),sb3(cnts)); funkyHWE *hweStruct = (funkyHWE *) pars->extras[8];//THIS IS VERY NASTY! the ordering within general.cpp is now important double lrt = 2*hweStruct->like0[s]-2*hweStruct->likeF[s]; double pval; if(lrt<0) pval =1; else pval =1- chi.cdf(lrt); ksprintf(bufstr,"%f:%e\t",lrt,pval); double Z = baseQbias(chk->nd[s],pars->nInd,refToInt[pars->major[s]],refToInt[pars->minor[s]]); ksprintf(bufstr,"%f:%e\n",Z,2*phi(Z)); } pars->extras[index] = bufstr; } }
static int stat_gettext(int tag, char *buf) { char *original_buf = buf; /* TODO: Support more than one processors */ LARGE_INTEGER idle_time, kernel_time, user_time; GetSystemTimes((FILETIME *)&idle_time, (FILETIME *)&kernel_time, (FILETIME *)&user_time); uint64_t user = user_time.QuadPart / (TICKS_PER_SECOND / USER_HZ); uint64_t nice = 0; uint64_t system = kernel_time.QuadPart / (TICKS_PER_SECOND / USER_HZ); uint64_t idle = idle_time.QuadPart / (TICKS_PER_SECOND / USER_HZ); system -= idle; /* KernelTime includes IdleTime */ uint64_t iowait = 0; uint64_t irq = 0; uint64_t softirq = 0; uint64_t steal = 0, guest = 0, guest_nice = 0; buf += ksprintf(buf, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n", user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice); buf += ksprintf(buf, "intr %llu\n", 0); buf += ksprintf(buf, "swap %llu %llu\n", 0); uint64_t ctxt = 0; buf += ksprintf(buf, "ctxt %llu\n", ctxt); /* Boot time */ SYSTEM_TIMEOFDAY_INFORMATION tod_info; NtQuerySystemInformation(SystemTimeOfDayInformation, &tod_info, sizeof(tod_info), NULL); uint64_t btime = filetime_to_unix_sec((FILETIME *)&tod_info.BootTime); buf += ksprintf(buf, "btime %llu\n", btime); uint64_t processes = 0; buf += ksprintf(buf, "processes %llu\n", processes); int procs_running = 1; buf += ksprintf(buf, "procs_running %d\n", procs_running); int procs_blocked = 0; buf += ksprintf(buf, "procs_blocked %d\n", procs_blocked); return buf - original_buf; }
static void create_debug_thread(void) { static pthread_t test_tid; char buf[80]; char * newstack; errno = 0; if ((newstack = sbrk(1024)) == (void *)-1) { puts("Failed to create a stack\n"); return; } pthread_attr_t attr = { .tpriority = 0, .stackAddr = newstack, .stackSize = 1024 }; errno = 0; if (pthread_create(&test_tid, &attr, test_thread, 0)) { puts("Thread creation failed\n"); return; } ksprintf(buf, sizeof(buf), "Thread created with id: %u\n", test_tid); puts(buf); } static void * test_thread(void * arg) { while(1) { sleep(1); thread_stat(); } } static void thread_stat(void) { /* Print thread id & cpu mode */ char buf[80]; uint32_t mode, sp; pthread_t id = pthread_self(); __asm__ volatile ( "mrs %0, cpsr\n\t" "mov %1, sp" : "=r" (mode), "=r" (sp)); ksprintf(buf, sizeof(buf), "My id: %u, sp: %u, my mode: %x\n", id, sp, mode); puts(buf); }
int main(int argc, char *argv[]) { int i, ret; double t_real; kstring_t pg = {0,0,0}; t_real = realtime(); ksprintf(&pg, "@PG\tID:bwa\tPN:bwa\tVN:%s\tCL:%s", PACKAGE_VERSION, argv[0]); for (i = 1; i < argc; ++i) ksprintf(&pg, " %s", argv[i]); bwa_pg = pg.s; if (argc < 2) return usage(); if (strcmp(argv[1], "fa2pac") == 0) ret = bwa_fa2pac(argc-1, argv+1); else if (strcmp(argv[1], "pac2bwt") == 0) ret = bwa_pac2bwt(argc-1, argv+1); else if (strcmp(argv[1], "pac2bwtgen") == 0) ret = bwt_bwtgen_main(argc-1, argv+1); else if (strcmp(argv[1], "bwtupdate") == 0) ret = bwa_bwtupdate(argc-1, argv+1); else if (strcmp(argv[1], "bwt2sa") == 0) ret = bwa_bwt2sa(argc-1, argv+1); else if (strcmp(argv[1], "index") == 0) ret = bwa_index(argc-1, argv+1); else if (strcmp(argv[1], "aln") == 0) ret = bwa_aln(argc-1, argv+1); else if (strcmp(argv[1], "samse") == 0) ret = bwa_sai2sam_se(argc-1, argv+1); else if (strcmp(argv[1], "sampe") == 0) ret = bwa_sai2sam_pe(argc-1, argv+1); else if (strcmp(argv[1], "bwtsw2") == 0) ret = bwa_bwtsw2(argc-1, argv+1); else if (strcmp(argv[1], "dbwtsw") == 0) ret = bwa_bwtsw2(argc-1, argv+1); else if (strcmp(argv[1], "bwasw") == 0) ret = bwa_bwtsw2(argc-1, argv+1); else if (strcmp(argv[1], "fastmap") == 0) ret = main_fastmap(argc-1, argv+1); else if (strcmp(argv[1], "mem") == 0) ret = main_mem(argc-1, argv+1); else if (strcmp(argv[1], "pemerge") == 0) ret = main_pemerge(argc-1, argv+1); else { fprintf(stderr, "[main] unrecognized command '%s'\n", argv[1]); return 1; } #ifdef USE_HTSLIB if (strcmp(argv[1], "mem") != 0) { err_fflush(stdout); err_fclose(stdout); } #else err_fflush(stdout); err_fclose(stdout); #endif if (ret == 0) { fprintf(stderr, "[%s] Version: %s\n", __func__, PACKAGE_VERSION); fprintf(stderr, "[%s] CMD:", __func__); for (i = 0; i < argc; ++i) fprintf(stderr, " %s", argv[i]); fprintf(stderr, "\n[%s] Real time: %.3f sec; CPU: %.3f sec\n", __func__, realtime() - t_real, cputime()); } free(bwa_pg); return ret; }
abcHaploCall::abcHaploCall(const char *outfiles,argStruct *arguments,int inputtype){ doHaploCall=0; maxMis=-1; minMinor=0; doCount=0; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doHaploCall")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); printArg(arguments->argumentFile); if(doHaploCall==0){ shouldRun[index] =0; return; } //for kputs output bufstr.s=NULL;bufstr.l=bufstr.m=0; //make output files const char* postfix; postfix=".haplo.gz"; outfileZ = aio::openFileBG(outfiles,postfix); //write header bufstr.l=0; ksprintf(&bufstr,"chr\tpos\tmajor"); for(int i=0;i<arguments->nInd;i++) ksprintf(&bufstr,"\tind%d",i); ksprintf(&bufstr,"\n"); aio::bgzf_write(outfileZ,bufstr.s,bufstr.l); bufstr.l=0; }
/** * Get kmalloc'd array for full path name. */ static char * format_fpath(struct fatfs_inode * indir, const char * name) { char * fpath; size_t fpath_size; #ifdef configFATFS_DEBUG KERROR(KERROR_DEBUG, "format_fpath(indir \"%s\", name \"%s\")\n", indir->in_fpath, name); #endif fpath_size = strlenn(name, NAME_MAX + 1) + strlenn(indir->in_fpath, NAME_MAX + 1) + 6; fpath = kmalloc(fpath_size); if (!fpath) return NULL; ksprintf(fpath, fpath_size, "%s/%s", indir->in_fpath, name); #ifdef configFATFS_DEBUG KERROR(KERROR_DEBUG, "Formatted \"%s\" as \"%s\"\n", name, fpath); #endif return fpath; }
void call_stdout(marksplit_settings_t *settings, splitterhash_params_t *params, char *ffq_r1, char *ffq_r2) { kstring_t str1{0, 0, nullptr}, str2{0, 0, nullptr}; kstring_t final{0, 0, nullptr}; kputs((settings->gzip_output)? "zcat": "cat", &str1); ks_resize(&str1, 1 << 10); for(int i(0); i < settings->n_handles; ++i) ksprintf(&str1, " %s", params->outfnames_r1[i]); kputsnl(" | paste -d'~' - - - - ", &str1); str2.s = dlib::kstrdup(&str1); // strdup the string. for(uint32_t i(0); i < str2.l; ++i) { LOG_DEBUG("Current str.s + i: %s.\n", str2.s + i); if(memcmp(str2.s + i, "R1", 2) == 0) str2.s[i + 1] = '2'; } const char final_template[]{"pr -mts'~' <(%s) <(%s) | tr '~' '\\n'"}; ksprintf(&final, final_template, str1.s, str2.s); dlib::bash_system(final.s); free(str1.s), free(str2.s); free(final.s); } void cat_fastqs(marksplit_settings_t *settings, splitterhash_params_t *params, char *ffq_r1, char *ffq_r2) { settings->is_se ? cat_fastqs_se(settings, params, ffq_r1) : cat_fastqs_pe(settings, params, ffq_r1, ffq_r2); }
/* Note the specific MTT version can also be used */ SkelUserReturn SkelUserGetModuleVersion(SkelDrvrModuleContext *mcon, char *mver) { if (mtt_ping(mcon)) return SkelUserReturnFAILED; ksprintf(mver, "%d", mtt_readw(mcon, MTT_VHDL)); return SkelUserReturnOK; }
void abcHWE::print(funkyPars *pars){ if(doHWE<=0) return; funkyHWE *hweStruct = (funkyHWE *) pars->extras[index];//new bufstr.l=0; for(int s=0;s<pars->numSites;s++){ if(pars->keepSites[s]==0) continue; float lrt= 2*hweStruct->like0[s]-2*hweStruct->likeF[s]; //DRAGON lrt is sometimes nan float pval; if(std::isnan(lrt)) pval=lrt; else if(lrt<0) pval=1; else pval=1-chisq->cdf(lrt); // fprintf(stderr,"lrt:%f\n",lrt); ksprintf(&bufstr,"%s\t%d\t%c\t%c\t%f\t%f\t%f\t%e\t%e\n",header->target_name[pars->refId],pars->posi[s]+1,intToRef[pars->major[s]],intToRef[pars->minor[s]],hweStruct->freqHWE[s],hweStruct->freq[s],hweStruct->F[s],lrt,pval); } aio::bgzf_write(outfileZ,bufstr.s,bufstr.l);bufstr.l=0; }
// Added by JN void abcSaf2::printSparse(funkyPars *p,int index,gzFile outfileSFS,gzFile outfileSFSPOS,char *chr){ realRes2 *r=(realRes2 *) p->extras[index]; int id=0; // output site likelihoods in banded format for(int i=0;i<p->numSites;i++){ if(r->oklist[i]==1){ gzwrite(outfileSFS,&r->offset[i],sizeof(int)); gzwrite(outfileSFS,&r->Kval[i],sizeof(int)); gzwrite(outfileSFS,r->pLikes[id++],sizeof(double)*r->Kval[i]); } } kstring_t kbuf;kbuf.s=NULL;kbuf.l=kbuf.m=0; for(int i=0;i<p->numSites;i++) if(r->oklist[i]==1) ksprintf(&kbuf,"%s\t%d\t%d\t%d\t%d\t%d\n",chr,p->posi[i]+1,r->offset[i],r->Kval[i],i,p->numSites); else if (r->oklist[i]==2) fprintf(stderr,"PROBS at: %s\t%d\n",chr,p->posi[i]+1); gzwrite(outfileSFSPOS,kbuf.s,kbuf.l); free(kbuf.s); }
abcFilterSNP::abcFilterSNP(const char *outfiles,argStruct *arguments,int inputtype){ doSnpStat=0; outfileZ = NULL; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doSnpStat")||!strcasecmp(arguments->argv[1],"-doPost")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); printArg(arguments->argumentFile); if(doSnpStat==0){ shouldRun[index] =0; return; } if(doSnpStat){ // fprintf(stderr,"running doSnpStat=%d\n",doSnpStat); const char *postfix=".snpStat.gz"; outfileZ = aio::openFileBG(outfiles,postfix); kstring_t bufstr;bufstr.s=NULL;bufstr.l=bufstr.m=0; ksprintf(&bufstr,"Chromo\tPosition\t+Major +Minor -Major -Minor\tSB1:SB2:SB3\tHWE_LRT:HWE_pval\tbaseQ_Z:baseQ_pval\n"); aio::bgzf_write(outfileZ,bufstr.s,bufstr.l);bufstr.l=0; free(bufstr.s); } }
int PLUGIN_GLOBAL(hfile_plugin_init,_libcurl)(struct hFILE_plugin *self) { static const struct hFILE_scheme_handler handler = { hopen_libcurl, hfile_always_remote, "libcurl", 50 }; const curl_version_info_data *info; const char * const *protocol; CURLcode err; err = curl_global_init(CURL_GLOBAL_ALL); if (err != CURLE_OK) { errno = easy_errno(NULL, err); return -1; } curl.multi = curl_multi_init(); if (curl.multi == NULL) { curl_global_cleanup(); errno = EIO; return -1; } info = curl_version_info(CURLVERSION_NOW); ksprintf(&curl.useragent, "htslib/%s libcurl/%s", hts_version(), info->version); curl.nrunning = 0; curl.perform_again = 0; self->name = "libcurl"; self->destroy = libcurl_exit; for (protocol = info->protocols; *protocol; protocol++) hfile_add_scheme_handler(*protocol, &handler); hfile_add_scheme_handler("s3", &handler); hfile_add_scheme_handler("s3+http", &handler); if (info->features & CURL_VERSION_SSL) hfile_add_scheme_handler("s3+https", &handler); return 0; }
static int _log_exists(const char *dir, long long log_index, int *exists) { struct stat st; char *path; int ret = -1; if ((path = ksprintf("%s/%lld", dir, log_index)) == NULL) { perror("unco"); return -1; } if (lstat(path, &st) == 0) { *exists = 1; } else if (errno == ENOENT) { *exists = 0; } else { kerr_printf("failed to stat file:%s", path); goto Exit; } ret = 0; Exit: free(path); return 0; }
char *unco_get_default_dir(int (*default_mkdir)(const char *, mode_t)) { char *home, *dir; if ((dir = getenv("UNCO_HOME")) != NULL) { // got it if ((dir = strdup(dir)) == NULL) { perror("unco"); return NULL; } } else { // $HOME/.unco if ((home = getenv("HOME")) == NULL) { fprintf(stderr, "unco:$HOME is not set\n"); return NULL; } if ((dir = ksprintf("%s/.unco", home)) == NULL) { perror("unco"); return NULL; } } // mkdir if (default_mkdir(dir, 0700) == 0 || errno == EEXIST) { // ok } else { kerr_printf("failed to create dir:%s", dir); free(dir); return NULL; } return dir; }
/** * Copies contigs found in bcf header to another bcf header. */ void bcf_hdr_transfer_contigs(const bcf_hdr_t *hsrc, bcf_hdr_t *hdest) { vdict_t *d = (vdict_t*)hsrc->dict[BCF_DT_CTG]; int tid, m = kh_size(d); const char **names = (const char**) calloc(m,sizeof(const char*)); int len[m]; khint_t k; for (k=kh_begin(d); k<kh_end(d); k++) { if ( !kh_exist(d,k) ) continue; tid = kh_val(d,k).id; len[tid] = bcf_hrec_find_key(kh_val(d, k).hrec[0],"length"); int j; if ( sscanf(kh_val(d, k).hrec[0]->vals[len[tid]],"%d",&j) ) len[tid] = j; names[tid] = kh_key(d,k); } kstring_t s = {0,0,0}; for (tid=0; tid<m; tid++) { s.l = 0; ksprintf(&s, "##contig=<ID=%s,length=%d>", names[tid], len[tid]); bcf_hdr_append(hdest, s.s); } if (s.m) free(s.s); }
static void ls(char ** args) { char * path = kstrtok(0, DELIMS, args); int fildes, count; struct dirent dbuf[10]; if (path == 0 || !strcmp(path, "")) path = "./"; fildes = open(path, O_DIRECTORY | O_RDONLY | O_SEARCH); if (fildes < 0) { puts("Open failed\n"); return; } count = getdents(fildes, (char *)dbuf, sizeof(dbuf)); if (count < 0) { puts("Reading directory entries failed\n"); } for (int i = 0; i < count; i++) { char buf[80]; struct stat stat; fstatat(fildes, dbuf[i].d_name, &stat, 0); ksprintf(buf, sizeof(buf), "%u %o %u:%u %s\n", (uint32_t)dbuf[i].d_ino, (uint32_t)stat.st_mode, (uint32_t)stat.st_uid, (uint32_t)stat.st_gid, dbuf[i].d_name); puts(buf); } puts("\n"); close(fildes); }
void KFMServer::slotExec( const char* _url, const char * _documents ) { KURL u( _url ); if ( u.isMalformed() ) { QString msg; ksprintf(&msg, i18n( "The URL\n%s\nis malformed" ), _url); QMessageBox::warning( (QWidget*)0, i18n( "KFM Error" ), msg ); return; } if ( _documents == 0L && _url != 0L ) { KFMExec *e = new KFMExec; e->openURL( _url ); return; } QString s( _documents ); QStrList urlList; int i; while ( ( i = s.find( "\n" ) ) != -1 ) { QString t = s.left( i ); urlList.append( t.data() ); s = s.mid( i + 1, s.length() ); } urlList.append( s.data() ); KMimeType *typ = KMimeType::getMagicMimeType( _url ); typ->runAsApplication( _url, &urlList ); }