filter::filter(argStruct *arguments){ //below if shared for all analysis classes header = arguments->hd; revMap = arguments->revMap; //his is used by this class keepsChr = NULL; curChr = -1; fp = NULL; minInd = -1; fname = NULL; doMajorMinor =0; doFilter =0; if(arguments->argc==2){ if(!strcmp(arguments->argv[1],"-filter")){ printArg(stdout); exit(0); }else return; } //get options and print them getOptions(arguments); printArg(arguments->argumentFile); }
abcFilter::abcFilter(argStruct *arguments){ //below if shared for all analysis classes strict =1; shouldRun[index] = 1; header = arguments->hd; revMap = arguments->revMap; setMinIndDepth=1; fl = NULL; //his is used by this class keepsChr = NULL; curChr = -1; fp = NULL; minInd = 0; fname = NULL; doMajorMinor =0; capDepth = -1; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-sites")){ printArg(stdout); exit(0); }else return; } //get options and print them getOptions(arguments); printArg(arguments->argumentFile); }
abcScounts::abcScounts(const char *outfiles,argStruct *arguments,int inputtype){ vcfname = NULL; doScounts = 0; outfile = NULL; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doScounts")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); if(doScounts==0) return ; printArg(arguments->argumentFile); outfile = aio::openFileBG(outfiles,".scounts.gz"); if(!vcfname){ fprintf(stderr,"\t-> Must supply a file for screening\n"); exit(0); } int docounts =0; docounts = angsd::getArg("-docounts",docounts,arguments); if(docounts==0){ fprintf(stderr,"\t-> -doScounts requires -doCounts\n"); exit(0); } am = readvcf(vcfname); }
//constructor abcWriteBcf::abcWriteBcf(const char *outfiles_a,argStruct *arguments,int inputtype){ fp=NULL; doBcf =0; args=arguments; outfiles=outfiles_a; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doBcf")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); if(doBcf==0){ shouldRun[index] =0; return; }else shouldRun[index] =1; printArg(arguments->argumentFile); }
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); } }
abcHWE::abcHWE(const char *outfiles,argStruct *arguments,int inputtype){ chisq = NULL; outfileZ = NULL; doHWE=0; HWE_pval = 0; testMe=0; tolStop = 0.00001; bufstr.s=NULL;bufstr.l=bufstr.m=0; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-HWE_pval")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); if(doHWE==0){ shouldRun[index] = 0; return; } printArg(arguments->argumentFile); //make output files const char* postfix; postfix=".hwe.gz"; if(doHWE>0){ outfileZ = aio::openFileBG(outfiles,postfix); //print header const char *str = "Chromo\tPosition\tMajor\tMinor\thweFreq\tFreq\tF\tLRT\tp-value\n"; aio::bgzf_write(outfileZ,str,strlen(str)); } }
hwe::hwe(const char *outfiles,argStruct *arguments,int inputtype){ doHWE=0; if(arguments->argc==2){ if(!strcmp(arguments->argv[1],"-doHWE")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); printArg(arguments->argumentFile); if(doHWE==0) return; //make output files const char* postfix; postfix=".hwe.gz"; if(doHWE>0){ outfileZ = openFileGz(outfiles,postfix,GZOPT); //print header gzprintf(outfileZ,"Chromo\tPosition\tMajor\tMinor\tFreq\thweFreq\tF\tLRT\n"); } }
abcSmartCounts::abcSmartCounts(const char *outfiles,argStruct *arguments,int inputtype){ doSmartCounts =0; fidx=NULL; fbin=NULL; curChr=-1; len =-1; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doSmartCounts")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); printArg(arguments->argumentFile); if(doSmartCounts==0) return; counts = new unsigned char*[4]; counts[0]=counts[1]=counts[2]=counts[3]=NULL; const char * BIN= ".counts.bin"; const char * IDX= ".counts.idx"; fidx=aio::openFile(outfiles,IDX); fbin=aio::openFileBG(outfiles,BIN,GZOPT); }
abcSaf2::abcSaf2(const char *outfiles,argStruct *arguments,int inputtype){ const char *SAF = ".saf.gz"; const char *SFSPOS =".saf.pos.gz"; //default underFlowProtect = 0; fold =0; isSim =0; outputBanded=1; //from command line anc=NULL; noTrans = 0; mode=0; //0,1,2,3 [EJ] doSaf2=0; outfileSFS = Z_NULL; outfileSFSPOS = Z_NULL; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doSaf2")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); printArg(arguments->argumentFile); if(doSaf2==0){ shouldRun[index] =0; return; } newDim = 2*arguments->nInd+1; if(fold) newDim = arguments->nInd+1; if(doSaf2==1){ outfileSFS = aio::openFileGz(outfiles,SAF,GZOPT); // Output tag at start to mark as saf version 2 (banded) char buf[8]="safv2"; gzwrite(outfileSFS,buf,8); outfileSFSPOS = aio::openFileGz(outfiles,SFSPOS,GZOPT); } }
majorminor::majorminor(const char *outfiles,argStruct *arguments,int inputtype){ if(arguments->argc==2){ if(!strcmp(arguments->argv[1],"-doMajorMinor")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); printArg(arguments->argumentFile); }
abcAncError::abcAncError(const char *outfiles,argStruct *arguments,int inputtype){ tsk_outname=NULL; doAncError=0; currentChr=-1; refName=NULL; ancName=NULL; outfile = NULL; outfile2= NULL; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doAncError")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); if(doAncError==0){ shouldRun[index] =0; return; } printArg(arguments->argumentFile); //make output files const char* postfix; postfix=".ancError"; outfile = aio::openFile(outfiles,postfix); //put the name of the outputfile into tsk_outname tsk_outname=(char*)malloc(strlen(outfiles)+strlen(postfix)+1); sprintf(tsk_outname,"%s%s",outfiles,postfix); const char* postfix2; postfix2=".ancErrorChr"; outfile2 = aio::openFile(outfiles,postfix2); //allocate allele counts alleleCounts = new size_t *[nInd]; for(int i=0;i<nInd;i++) alleleCounts[i] = new size_t [256]; for(int i=0;i<nInd;i++) for(int j=0;j<256;j++) alleleCounts[i][j]=0; alleleCountsChr = new size_t *[nInd]; for(int i=0;i<nInd;i++) alleleCountsChr[i] = new size_t [256]; for(int i=0;i<nInd;i++) for(int j=0;j<256;j++) alleleCountsChr[i][j]=0; }
abcDstat::abcDstat(const char *outfiles,argStruct *arguments,int inputtype){ rmTrans = 0; outfile=NULL; ancName=NULL; doAbbababa=0; doCount=0; currentChr=-1; NbasesPerLine=50; blockSize=5000000; block=0; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doAbbababa")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); printArg(arguments->argumentFile); if(doAbbababa==0){ shouldRun[index] = 0; return; } //make output files const char* postfix; postfix=".abbababa"; outfile = aio::openFile(outfiles,postfix); // const char* postfix2; // postfix2=".fastaChr"; // outfile2 = openFile(outfiles,postfix2); bufstr.s=NULL; bufstr.m=0; bufstr.l=0; //the number of combinations nComb=arguments->nInd*(arguments->nInd-1)*(arguments->nInd-2)/2; ABBA = new int[nComb]; BABA = new int[nComb]; calcMatCat(); //pre calc all posible combinations }
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; }
void printArgs(char* argv[]) { for (int i = 0; argv[i] != '\0'; ++i) { cout << '\''; printArg(argv[i]); cout << '\''; if (argv[i+1] != '\0') cout << ' '; } }
void multiReader::getOptions(argStruct *arguments){ nLines=angsd::getArg("-nLines",nLines,arguments); arguments->nLines = nLines; fname=angsd::getArg("-beagle",fname,arguments); fname=angsd::getArg("-pileup",fname,arguments); minQ=angsd::getArg("-minQ",minQ,arguments); fname=angsd::getArg("-glf",fname,arguments); fname=angsd::getArg("-glf3",fname,arguments); fname=angsd::getArg("-vcf-GL",fname,arguments); fname=angsd::getArg("-vcf-GP",fname,arguments); fname=angsd::getArg("-vcf-pl",fname,arguments); fname=angsd::getArg("-glf10_text",fname,arguments); intName=angsd::getArg("-intName",intName,arguments); isSim=angsd::getArg("-isSim",intName,arguments); nInd=angsd::getArg("-nInd",nInd,arguments); arguments->nInd = nInd; //read fai if suppplied (used by other than native bam readers) char *tmptmp=NULL; tmptmp=angsd::getArg("-fai",arguments->fai,arguments); if(tmptmp){ free(arguments->fai); arguments->fai=tmptmp; } printArg(arguments->argumentFile,arguments); }
void abcSaf2::getOptions(argStruct *arguments){ doSaf2=angsd::getArg("-doSaf2",doSaf2,arguments); noTrans = angsd::getArg("-noTrans",noTrans,arguments); mode = angsd::getArg("-mode",mode,arguments); //[EJ] int GL = 0; GL = angsd::getArg("-GL",GL,arguments); underFlowProtect=angsd::getArg("-underFlowProtect",underFlowProtect,arguments); fold=angsd::getArg("-fold",fold,arguments); char *sim1 = NULL; isSim=angsd::getArg("-isSim",isSim,arguments); // fprintf(stderr,"sim1=%p %s\n",sim1,sim1); if(doSaf2==0) return; anc = angsd::getArg("-anc",anc,arguments); if(doSaf2 && (anc==NULL&&isSim==0)){ if(doSaf2!=3){ fprintf(stderr,"Must supply -anc for polarizing the spectrum\n"); exit(0); } } if(GL==0 &&arguments->inputtype==7){//DRAGON this is not enough, but this is most likely what everyone done... fprintf(stderr,"Must supply genotype likelihoods (-GL [INT])\n"); printArg(arguments->argumentFile); exit(0); } }
abbababa::abbababa(const char *outfiles,argStruct *arguments,int inputtype){ doAbbababa=0; minQ=MINQ;//<-general.h sample=1; currentChr=-1; if(arguments->argc==2){ if(!strcmp(arguments->argv[1],"-doAbbababa")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); printArg(arguments->argumentFile); if(doAbbababa==0) return; //make output files const char* postfix; postfix=".abbababa.gz"; outfileZ = openFileGz(outfiles,postfix,GZOPT); const char* postfix2; postfix2=".abbababa2"; outfile = openFile(outfiles,postfix2); //allocate allele counts alleleCounts = new size_t *[nInd]; for(int i=0;i<nInd;i++) alleleCounts[i] = new size_t [256]; for(int i=0;i<nInd;i++) for(int j=0;j<256;j++) alleleCounts[i][j]=0; alleleCountsChr = new size_t *[nInd]; for(int i=0;i<nInd;i++) alleleCountsChr[i] = new size_t [256]; for(int i=0;i<nInd;i++) for(int j=0;j<256;j++) alleleCountsChr[i][j]=0; }
//read program parameters args *getArgsBambi(argStruct *arguments){ args *ret = allocArgs(); ret->inputfiles=angsd::getArg("-bam",ret->inputfiles,arguments); ret->inputfile=angsd::getArg("-i",ret->inputfile,arguments); if(ret->inputfiles==NULL && ret->inputfile==NULL) return NULL; if(ret->inputfiles!=NULL&&strcmp(ret->inputfiles,"-999")==0){//DRAGON fix this ret->inputfiles=NULL; printArg(stdout,ret); exit(0); } remove_bads = angsd::getArg("-remove_bads",remove_bads,arguments); uniqueOnly = angsd::getArg("-uniqueOnly",uniqueOnly,arguments); only_proper_pairs =angsd::getArg("-only_proper_pairs",only_proper_pairs,arguments); minMapQ = angsd::getArg("-minMapQ",minMapQ,arguments); adjustMapQ = angsd::getArg("-C",adjustMapQ,arguments); baq = angsd::getArg("-baq",baq,arguments); ret->region =angsd::getArg("-r",ret->region,arguments); ret->regionfile = angsd::getArg("-rf",ret->regionfile,arguments); ret->nInd = angsd::getArg("-nInd",ret->nInd,arguments); ret->nLines = angsd::getArg("-nLines",ret->nLines,arguments); ret->type = angsd::getArg("-type",ret->type,arguments); ret->show = angsd::getArg("-show",ret->show,arguments); // minQ = angsd::getArg("-minQ",minQ,arguments); if(ret->inputfile && ret->inputfile[0]=='-'){ fprintf(stderr,"[Error] Problem understanding inputfilename: %s\n",ret->inputfile); return NULL; } char *tmp = ""; tmp = angsd::getArg("-ref",tmp,arguments); if(strcmp(tmp,"")==0&&adjustMapQ!=0){ fprintf(stderr,"Must also supply -ref for adjusting the mapping quality\n"); exit(0); } if(strcmp(tmp,"")==0&&baq!=0){ fprintf(stderr,"Must also supply -ref for adjusting base qualities (baq)\n"); exit(0); } printArg(arguments->argumentFile,ret); return ret; }
abcMajorMinor::abcMajorMinor(const char *outfiles,argStruct *arguments,int inputtype){ //default doMajorMinor = 0; doSaf = 0; pest = NULL; if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doMajorMinor")){ printArg(stdout); exit(0); }else return; } getOptions(arguments); if(doMajorMinor==0 || doMajorMinor ==3 ) shouldRun[index] =0; printArg(arguments->argumentFile); }
void likeClass::getOptions(argStruct *arguments){ //parse all parameters that this class could use GL=angsd::getArg("-GL",GL,arguments); minQ = angsd::getArg("-minQ",minQ,arguments); trim = angsd::getArg("-trim",trim,arguments); angsd_tmpdir = angsd::getArg("-tmpdir",angsd_tmpdir,arguments); doGlf=angsd::getArg("-doGlf",doGlf,arguments); errorFname = angsd::getArg("-errors",errorFname,arguments); minInd = angsd::getArg("-minInd",minInd,arguments); int doCounts=0; int doMajorMinor =0; doCounts=angsd::getArg("-doCounts",doCounts,arguments); doMajorMinor=angsd::getArg("-doMajorMinor",doMajorMinor,arguments); if(arguments->inputtype==4&&GL!=0){ fprintf(stderr,"Can't calculate genotype likelihoods from simulation files\n"); exit(0); } if(arguments->inputtype==4) return; if(doGlf&&GL==0){ fprintf(stderr,"You need to choose a genotype likelihood model -GL for dumping genotype likelihoods\n"); exit(0); } if(GL==0) return; if(GL<0||GL>4){ fprintf(stderr,"You've choosen a GL model=%d, only 1,2,3,4 are implemented\n",GL); exit(0); } if(GL==4&&(doCounts==0)){ fprintf(stderr,"Must supply -doCounts for SYK model\n"); exit(0); } if((doGlf==2||doGlf==3) && doMajorMinor==0){ fprintf(stderr,"For dumping beaglestyle output you need to estimate major/minor: -doMajorMinor\n"); exit(0); } if(arguments->inputtype==5&&doGlf){ fprintf(stderr,"cannot output likelihoods (doGlf) when input is beagle\n"); exit(0); } if(arguments->inputtype!=0&&arguments->inputtype!=7){ fprintf(stderr,"Error: Likelihoods can only be estimated based on SOAP input and uppile input\n"); exit(0); } printArg(arguments->argumentFile); }
void printHelp(const QString &name) { QString description{QCoreApplication::translate("main", "chewing-editor is a cross platform chewing user phrase editor written " "in Qt5. It provides a user friendly GUI to manage user phrase. With it," " user can customize user phrase to enhance chewing input performance.")}; printf("%s\n\n", description.toUtf8().constData()); printArg( QCoreApplication::translate("main", "-d, --debug"), QCoreApplication::translate("main", "Enable debug message.")); printArg( QCoreApplication::translate("main", "-v, --version"), QCoreApplication::translate("main", "Print program version.")); printArg( QCoreApplication::translate("main", "-h, --help"), QCoreApplication::translate("main", "Print help message.")); }
static void printArg(const QVariant &v) { if (printArgumentsLiterally) { printf("%s\n", qPrintable(QDBusUtil::argumentToString(v))); return; } if (v.userType() == QVariant::StringList) { foreach (QString s, v.toStringList()) printf("%s\n", qPrintable(s)); } else if (v.userType() == QVariant::List) { foreach (const QVariant &var, v.toList()) printArg(var); } else if (v.userType() == QVariant::Map) {
//read program parameters void setArgsBam(argStruct *arguments){ remove_bads = angsd::getArg("-remove_bads",remove_bads,arguments); uniqueOnly = angsd::getArg("-uniqueOnly",uniqueOnly,arguments); only_proper_pairs =angsd::getArg("-only_proper_pairs",only_proper_pairs,arguments); minMapQ = angsd::getArg("-minMapQ",minMapQ,arguments); minQ = angsd::getArg("-minQ",minQ,arguments); trim = angsd::getArg("-trim",trim,arguments); adjustMapQ = angsd::getArg("-C",adjustMapQ,arguments); baq = angsd::getArg("-baq",baq,arguments); regfile =angsd::getArg("-r",regfile,arguments); regfiles = angsd::getArg("-rf",regfiles,arguments); checkBamHeaders = angsd::getArg("-checkBamHeaders",checkBamHeaders,arguments); arguments->show = angsd::getArg("-show",arguments->show,arguments); char *tmp = NULL; tmp = angsd::getArg("-ref",tmp,arguments); if(tmp==NULL && adjustMapQ!=0){ fprintf(stderr,"Must also supply -ref for adjusting the mapping quality\n"); exit(0); } if(tmp==NULL&&baq!=0){ fprintf(stderr,"Must also supply -ref for adjusting base qualities (baq)\n"); exit(0); } free(tmp); std::vector<char *> regionsRaw; if(regfiles) regionsRaw = angsd::getFilenames(regfiles,0); if(regfile) regionsRaw.push_back(regfile); for(size_t i=0;i<regionsRaw.size();i++){ regs tmpRegs; if(parse_region(regionsRaw[i],arguments->hd,tmpRegs.refID,tmpRegs.start,tmpRegs.stop,arguments->revMap)<0||tmpRegs.stop<tmpRegs.start){ fprintf(stderr,"[%s] problems with indexing: %s\n",__FUNCTION__,regionsRaw[i]); exit(0); }else arguments->regions.push_back(tmpRegs); } printArg(arguments->argumentFile,arguments); free(regfile); free(regfiles); }
//constructor abcTemplate::abcTemplate(const char *outfiles,argStruct *arguments,int inputtype){ doTemplate = 0; //defaults= dont do analysis outfile = NULL; //first a hook for the interactive help: // ./angsd -doTemplate if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doTemplate")){ printArg(stdout); exit(0); }else return; } //now parse the arguments getOptions(arguments); //now print the arguments printArg(arguments->argumentFile); if(doTemplate==0) return ; //initalize outputfile outfile = aio::openFile(outfiles,".results"); fprintf(outfile,"Chromo\tPosition\t+A\t+C\t+G\t+T\t-A\t-C\t-G\t-T\n"); }
void multiReader::getOptions(argStruct *arguments){ nLines=angsd::getArg("-nLines",nLines,arguments); arguments->nLines = nLines; bytesPerLine=angsd::getArg("-bytesPerLine",bytesPerLine,arguments); fname=angsd::getArg("-beagle",fname,arguments); fname=angsd::getArg("-pileup",fname,arguments); minQ=angsd::getArg("-minQ",minQ,arguments); fname=angsd::getArg("-glf",fname,arguments); intName=angsd::getArg("-intName",intName,arguments); isSim=angsd::getArg("-isSim",intName,arguments); nInd=angsd::getArg("-nInd",nInd,arguments); from=angsd::getArg("-from",from,arguments); to=angsd::getArg("-to",to,arguments); arguments->nInd = nInd; //read fai if suppplied (used by other than native bam readers) fai=angsd::getArg("-fai",fai,arguments); printArg(arguments->argumentFile); }
void printInfo(char* login, char host[]) { printArg(login); cout << '@'; printArg(host); return; }
void FormatPrinter::print(const char* format, va_list args) { const char* p = format; const char* errorStr; // buffer is only used for 2 purposes: // 1. To temporarily hold a copy of normal chars (not needing formatting) // to be passed to printArg() and printed. // // The incoming format string may contain a string of normal chars much // longer than 128, but we handle this by breaking them out to 128 chars // fragments and printing each fragment before re-using the buffer to // load up the next fragment. // // 2. To hold a single "%..." format to be passed to printArg() to process // a single va_arg. char buffer[129]; // 128 chars + null terminator. char* end = &buffer[sizeof(buffer) - 1]; const char* startOfFormatSpecifier = 0; while (true) { char c = *p++; char* curr = buffer; // Print leading normal chars: while (c != '\0' && c != '%') { *curr++ = c; if (curr == end) { // Out of buffer space. Flush the fragment, and start over. *curr = '\0'; bool success = printArg("%s", buffer); if (!success) { errorStr = buffer; goto handleError; } curr = buffer; } c = *p++; } // If we have stuff in the buffer, flush the fragment: if (curr != buffer) { ASSERT(curr < end + 1); *curr = '\0'; bool success = printArg("%s", buffer); if (!success) { errorStr = buffer; goto handleError; } } // End if there are not more chars to print: if (c == '\0') break; // If we get here, we've must have seen a '%': startOfFormatSpecifier = p - 1; ASSERT(*startOfFormatSpecifier == '%'); c = *p++; // Check for "%%" case: if (c == '%') { bool success = printArg("%c", '%'); if (!success) { errorStr = p - 2; goto handleError; } continue; } // Check for JS (%J<x>) formatting extensions: if (c == 'J') { bool verbose = false; c = *p++; if (UNLIKELY(c == '\0')) { errorStr = p - 2; // Rewind to % in "%J\0" goto handleError; } if (c == '+') { verbose = true; c= *p++; if (UNLIKELY(c == '\0')) { errorStr = p - 3; // Rewind to % in "%J+\0" goto handleError; } } switch (c) { // %Js - WTF::String* case 's': { printWTFString(args, verbose); continue; } } // END switch. // Check for non-JS extensions: } else if (c == 'b') { int value = va_arg(args, int); printArg("%s", value ? "TRUE" : "FALSE"); continue; } // If we didn't handle the format in one of the above cases, // rewind p and let the standard formatting check handle it // if possible: p = startOfFormatSpecifier; ASSERT(*p == '%'); // Check for standard formatting: // A format specifier always starts with a % and ends with some // alphabet. We'll do the simple thing and scan until the next // alphabet, or the end of string. // In the following, we're going to use buffer as storage for a copy // of a single format specifier. Hence, conceptually, we can think of // 'buffer' as synonymous with 'argFormat' here: #define ABORT_IF_FORMAT_TOO_LONG(curr) \ do { \ if (UNLIKELY(curr >= end)) \ goto formatTooLong; \ } while (false) curr = buffer; *curr++ = *p++; // Output the first % in the format specifier. c = *p++; // Grab the next char in the format specifier. // Checks for leading modifiers e.g. "%-d": // 0, -, ' ', +, '\'' if (c == '0' || c == '-' || c == ' ' || c == '+' || c == '\'' || c == '#') { ABORT_IF_FORMAT_TOO_LONG(curr); *curr++ = c; c = *p++; } // Checks for decimal digit field width modifiers e.g. "%2f": while (c >= '0' && c <= '9') { ABORT_IF_FORMAT_TOO_LONG(curr); *curr++ = c; c = *p++; } // Checks for '.' e.g. "%2.f": if (c == '.') { ABORT_IF_FORMAT_TOO_LONG(curr); *curr++ = c; c = *p++; // Checks for decimal digit precision modifiers e.g. "%.2f": while (c >= '0' && c <= '9') { ABORT_IF_FORMAT_TOO_LONG(curr); *curr++ = c; c = *p++; } } // Checks for the modifier <m> where <m> can be: // l, h, j, t, z // e.g. "%ld" if (c == 'l' || c == 'h' || c == 'j' || c == 't' || c == 'z' || c == 'L') { ABORT_IF_FORMAT_TOO_LONG(curr); *curr++ = c; char prevChar = c; c = *p++; // Checks for the modifier ll or hh in %<x><m>: if ((prevChar == 'l' || prevChar == 'h') && c == prevChar) { ABORT_IF_FORMAT_TOO_LONG(curr); *curr++ = c; c = *p++; } } // Checks for %<x> where <x> can be: // d, i, n, o, u, x, X // But hey, we're just going to do the simple thing and allow any // alphabet. The user is expected to pass correct format specifiers. // We won't do any format checking here. We'll just pass it on, and the // underlying ...printf() implementation may do the needed checking // at its discretion. while (c != '\0' && !isASCIIAlpha(c)) { ABORT_IF_FORMAT_TOO_LONG(curr); *curr++ = c; c = *p++; } ABORT_IF_FORMAT_TOO_LONG(curr); *curr++ = c; if (c == '\0') { // Uh oh. Bad format. We should have gotten an alphabet instead. // Print the supposed format as a string instead: errorStr = buffer; goto handleError; } // Otherwise, we have the alpha that terminates the format. // Terminate the buffer (i.e. argFormat) string: ASSERT(isASCIIAlpha(c)); ABORT_IF_FORMAT_TOO_LONG(curr); *curr = '\0'; bool success = printArg(buffer, args); if (!success) { errorStr = buffer; goto handleError; } }
multiReader::multiReader(int argc,char**argv){ gz=Z_NULL; myglf=NULL;myvcf=NULL;mpil=NULL;bglObj=NULL; nLines=50; fname=NULL; intName=1; minQ = MINQ; nInd =0; isSim =0; args=NULL; args = setArgStruct(argc,argv); fprintf(args->argumentFile,"\t-> Command: \n"); for(int i=0;i<argc;i++) fprintf(args->argumentFile,"%s ",argv[i]); // fprintf(args->argumentFile,"\n\n"); if(args->argumentFile!=stderr) fprintf(args->argumentFile,"\n\t-> angsd version: %s (htslib: %s) build(%s %s)\n",ANGSD_VERSION,hts_version(),__DATE__,__TIME__); void printTime(FILE *fp); printTime(args->argumentFile); //type = args->inputtype; if(args->argc==2) { if((!strcasecmp(args->argv[1],"-beagle")) || (!strcasecmp(args->argv[1],"-glf")) || (!strcasecmp(args->argv[1],"-glf3")) || (!strcasecmp(args->argv[1],"-pileup")) || (!strcasecmp(args->argv[1],"-vcf-GL")) || (!strcasecmp(args->argv[1],"-vcf-pl")) || (!strcasecmp(args->argv[1],"-glf10_text")) || (!strcasecmp(args->argv[1],"-vcf-GP"))) { printArg(stdout,args); exit(0); }else if ((!strcasecmp(args->argv[1],"-bam")) || (!strcasecmp(args->argv[1],"-b"))){ setArgsBam(args); exit(0); }else return; } getOptions(args); if(args->fai==NULL){ int printAndExit =0; switch(args->inputtype) { case INPUT_GLF: printAndExit=1; break; case INPUT_GLF10_TEXT: printAndExit=1; break; case INPUT_GLF3: printAndExit=1; break; case INPUT_BEAGLE: printAndExit=1; break; case INPUT_PILEUP: printAndExit=1; break; } if(printAndExit){ fprintf(stderr,"\t-> Must supply -fai file\n"); exit(0); } } if(args->fai){ if(!(args->hd=getHeadFromFai(args->fai))) exit(0); }else{ if(args->nams.size()==0){ fprintf(stderr,"\t-> Must choose inputfile -bam/-glf/-glf3/-pileup/-i/-vcf-gl/-vcf-gp/-vcf-pl/-glf10_text filename\n"); exit(0); } if(args->inputtype==INPUT_BAM){ htsFile *in=sam_open(args->nams[0],"r"); assert(in); args->hd= sam_hdr_read(in); hts_close(in); } } if(!(INPUT_VCF_GL||INPUT_VCF_GP)){ if(args->hd==NULL){ fprintf(stderr,"For non-bams you should include -fai arguments\n"); exit(0); } } if((args->inputtype==INPUT_PILEUP||args->inputtype==INPUT_GLF||args->inputtype==INPUT_GLF3||args->inputtype==INPUT_GLF10_TEXT)){ if(nInd==0){ fprintf(stderr,"\t-> Must supply -nInd when using -glf/-glf3/-pileup/-glf10_text files\n"); exit(0); } }else args->nInd = args->nams.size(); if(args->inputtype==INPUT_VCF_GP||args->inputtype==INPUT_VCF_GL){ if(args->regions.size()>1){ fprintf(stderr,"\t-> Only one region can be specified with using bcf (i doubt more is needed) will exit\n"); exit(0); }else if(args->regions.size()<=1){ myvcf = new vcfReader(args->infile,NULL); args->hd=bcf_hdr_2_bam_hdr_t(myvcf->hs); args->nInd = myvcf->hs->nsamples; } } //make args->hd revMap = buildRevTable(args->hd); args->revMap = revMap; setArgsBam(args); if(args->inputtype==INPUT_VCF_GL){ if(args->regions.size()==1){ char tmp[1024]; int start=args->regions[0].start; int stop=args->regions[0].stop; int ref=args->regions[0].refID; snprintf(tmp,1024,"%s:%d-%d",args->hd->target_name[ref],start+1,stop); // fprintf(stderr,"tmp:%s\n",tmp); // exit(0); myvcf->seek(tmp); } } if(fname==NULL) return; gz=Z_NULL; gz=gzopen(fname,"r"); if(gz==Z_NULL){ fprintf(stderr,"\t-> Problem opening file: \'%s\'\n",fname); exit(0); } switch(args->inputtype){ case INPUT_PILEUP:{ mpil = new mpileup(args->nInd,gz,args->revMap,minQ); break; } case INPUT_GLF:{ myglf = new glfReader(args->nInd,gz,10,isSim); break; } case INPUT_GLF3:{ isSim = 1; //Added by FGV on 22/02/2015: GLF3 is always simulated data until a better alternative can be found myglf = new glfReader(args->nInd,gz,3,isSim); break; } case INPUT_GLF10_TEXT:{ myglf_text = new glfReader_text(args->nInd,gz,args->revMap); break; } case INPUT_BEAGLE:{ bglObj = new beagle_reader(gz,args->revMap,intName,args->nInd); break; } default:{ break; } } if(args->inputtype==INPUT_VCF_GL||args->inputtype==INPUT_VCF_GL){ fprintf(stderr,"\t-> VCF still beta. Remember that\n"); fprintf(stderr,"\t 1. indels are are discarded\n"); fprintf(stderr,"\t 2. will use chrom, pos PL columns\n"); fprintf(stderr,"\t 3. GL tags are interpreted as log10 and are scaled to ln (NOT USED)\n"); fprintf(stderr,"\t 4. GP tags are interpreted directly as unscaled post probs (spec says phredscaled...) (NOT USED)\n"); fprintf(stderr,"\t 5. FILTER column is currently NOT used (not sure what concensus is)\n"); fprintf(stderr,"\t 6. -sites does NOT work with vcf input but -r does\n"); fprintf(stderr,"\t 7. vcffilereading is still BETA, please report strange behaviour\n"); } }
// Construction abcDstat2::abcDstat2(const char *outfiles, argStruct *arguments,int inputtype){ //default values rmTrans = 0; sample = 0; outfile=NULL; ancName=NULL; doAbbababa2=0; doCount=0; blockSize=5000000; block=0; NSITEprint=0; sizeH1 = 1; sizeH2 = 1; sizeH3 = 1; sizeH4 = 1; enhance = 1; DENprint=0; NUMprint=0; maxDepth=100; // you are starting before chromosome 0 currentChr=-1; NbasesPerLine=50; //if you dont use the -doAbbababa2 argument then return if(arguments->argc==2){ if(!strcasecmp(arguments->argv[1],"-doAbbababa2")){ printArg(stdout); exit(0); }else return; } //get all options getOptions(arguments); printArg(arguments->argumentFile); //ignore if(doAbbababa2==0){ shouldRun[index] = 0; return; } //make output files const char* postfix; postfix=".abbababa2"; outfile = aio::openFile(outfiles,postfix); //const char* postfix2; //postfix2=".abbababaComp"; //outfile2 = aio::openFile(outfiles,postfix2); // store large amounts of data for printing fast bufstr.s=NULL; bufstr.m=0; bufstr.l=0; //the number of combinations nComb=arguments->nInd*(arguments->nInd-1)*(arguments->nInd-2)/2; COMBprint = new double[256]; fprintf(outfile,"CHR\tBLOCKstart\tBLOCKend\tNumer\tDenom\tnumSites"); for(int a=0;a<4;a++) for(int b=0;b<4;b++) for(int c=0;c<4;c++) for(int d=0;d<4;d++) fprintf(outfile,"\t%d%d%d%d",a,b,c,d); fprintf(outfile,"\n"); }//---end of abcDstat2::abcDstat2(const char *outfiles, argStruct *arguments,int inputtype)
//read program parameters void setArgsBam(argStruct *arguments){ int seed=0; remove_bads = angsd::getArg("-remove_bads",remove_bads,arguments); uniqueOnly = angsd::getArg("-uniqueOnly",uniqueOnly,arguments); only_proper_pairs =angsd::getArg("-only_proper_pairs",only_proper_pairs,arguments); fai_fname =angsd::getArg("-f",fai_fname,arguments); minMapQ = angsd::getArg("-minMapQ",minMapQ,arguments); cigstat = angsd::getArg("-cigstat",cigstat,arguments); minQ = angsd::getArg("-minQ",minQ,arguments); downSample = angsd::getArg("-downSample",downSample,arguments); seed = angsd::getArg("-seed",seed,arguments); trim = angsd::getArg("-trim",trim,arguments); trim5 = angsd::getArg("-trim5",trim5,arguments); trim3 = angsd::getArg("-trim3",trim3,arguments); arguments->ref=angsd::getArg("-ref",arguments->ref,arguments); arguments->anc=angsd::getArg("-anc",arguments->anc,arguments); rghash_name= angsd::getArg("+RG",rghash_name,arguments); if(rghash_name&&!angsd::fexists(rghash_name)) rghash = add_read_group_single(rghash_name); if(rghash_name&&angsd::fexists(rghash_name)) rghash = add_read_groups_file(rghash_name); if(rghash) fprintf(stderr,"\t-> [READGROUP info] Number of readgroups to include: %d\n",khash_str2int_size(rghash)); adjustMapQ = angsd::getArg("-C",adjustMapQ,arguments); baq = angsd::getArg("-baq",baq,arguments); redo_baq = angsd::getArg("-redo-baq",redo_baq,arguments); if(baq){ if(baq==1) baq=1; //wauv else if(baq==2) baq=3; else{ fprintf(stderr,"\t-> only supported options for -baq is: 1 (normal baq) and 2 (extended baq (SAMtools default)). Value supplied:%d\n",baq); exit(0);//ly su } if(redo_baq==1) baq |=4; } // fprintf(stderr,"baq:%d redobaq:%d\n",baq,redo_baq);exit(0); regfile =angsd::getArg("-r",regfile,arguments); regfiles = angsd::getArg("-rf",regfiles,arguments); MAX_SEQ_LEN = angsd::getArg("-setMinChunkSize",MAX_SEQ_LEN,arguments); checkBamHeaders = angsd::getArg("-checkBamHeaders",checkBamHeaders,arguments); doCheck = angsd::getArg("-doCheck",doCheck,arguments); MPLP_IGNORE_RG = angsd::getArg("--ignore-RG",MPLP_IGNORE_RG,arguments); arguments->nReads = angsd::getArg("-nReads",arguments->nReads,arguments); arguments->show = angsd::getArg("-show",arguments->show,arguments); if(regfile && regfiles) fprintf(stderr,"\t-> WARNING both -r and -rf has been set \n"); if(seed) srand48(seed); char *tmp = NULL; tmp = angsd::getArg("-ref",tmp,arguments); if(tmp==NULL && adjustMapQ!=0){ fprintf(stderr,"\t-> Must also supply -ref for adjusting the mapping quality\n"); exit(0); } if(tmp==NULL&&baq!=0){ fprintf(stderr,"\t-> Must also supply -ref for adjusting base qualities (baq)\n"); exit(0); } free(tmp); std::vector<char *> regionsRaw; if(regfiles) regionsRaw = angsd::getFilenames(regfiles,0); if(regfile) regionsRaw.push_back(strdup(regfile)); // fprintf(stderr,"\t-> RegionsRaw.size():%lu hd:%p\n",regionsRaw.size(),arguments->hd); for(size_t i=0;i<regionsRaw.size();i++){ regs tmpRegs; if(parse_region(regionsRaw[i],arguments->hd,tmpRegs.refID,tmpRegs.start,tmpRegs.stop,arguments->revMap)<0||tmpRegs.stop<tmpRegs.start){ fprintf(stderr,"[%s] Problems with indexing: %s\n",__FUNCTION__,regionsRaw[i]); exit(0); }else arguments->regions.push_back(tmpRegs); free(regionsRaw[i]); } printArg(arguments->argumentFile,arguments); if(regfile) free(regfile); if(regfiles) free(regfiles); }