diff --git a/.github/workflows/build-tests.yml b/.github/workflows/build-tests.yml new file mode 100644 index 00000000..c668887a --- /dev/null +++ b/.github/workflows/build-tests.yml @@ -0,0 +1,32 @@ +name: build-tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-18.04 ] + compiler: [ clang, gcc ] + + steps: + - uses: actions/checkout@v2 + + - name: Checkout submodules + run: git submodule update --init --recursive + + - name: Install dependencies + run: | + sudo apt-get install -y libbz2-dev liblzma-dev libcurl4-openssl-dev + git clone --depth=5 git://github.com/ANGSD/smallBam.git + + - name: Run CMake + run: | + make + make test BAMDIR=./smallBam/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..9e410d0f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "htslib"] + path = htslib + url = https://github.com/samtools/htslib.git diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b352aea3..00000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -sudo: false - -os: linux -dist: trusty - -language: c - -compiler: - - clang - - gcc - -env: - global: - - MAKEFLAGS="-j2" - -matrix: - include: - # An unoptimised C99 build, for detecting non-static inline functions - - compiler: gcc - env: - - CFLAGS="-std=gnu99 -O0" - - CXXFLAGS="-O0" - -addons: - apt: - packages: - - liblzma-dev - - libbz2-dev - -before_script: - - git clone --branch=develop --recursive git://github.com/samtools/htslib.git - - cd htslib; make;cd .. - - git clone --depth=5 --branch=develop git://github.com/samtools/samtools.git - - cd samtools;make;cd .. - - - git clone --depth=5 git://github.com/ANGSD/smallBam.git - - export HTSSRC=`pwd`/htslib - - export BAMDIR=`pwd`/smallBam/ - -script: - - make - - make test BAMDIR=`pwd`/smallBam/ diff --git a/Makefile b/Makefile index f5aeb4bc..de3fb878 100644 --- a/Makefile +++ b/Makefile @@ -4,16 +4,50 @@ CXX ?= g++ LIBS = -lz -lm -lbz2 -llzma -lpthread -lcurl CRYPTOLIB = -lcrypto -# Adjust $(HTSSRC) to point to your top-level htslib directory +#if htslib source is defined ifdef HTSSRC + +#if hts source is set to systemwide +ifeq ($(HTSSRC),systemwide) +$(info HTSSRC set to systemwide; assuming systemwide installation) +LIBS += -lhts + +else + +#if hts source path is given +# Adjust $(HTSSRC) to point to your top-level htslib directory $(info HTSSRC defined: $(HTSSRC)) CPPFLAGS += -I"$(realpath $(HTSSRC))" -LIBS := "$(realpath $(HTSSRC))/libhts.a" $(LIBS) +LIBHTS := $(HTSSRC)/libhts.a +LIBS := $(LIBHTS) $(LIBS) + +endif + +#if htssrc not defined else -$(info HTSSRC not defined, assuming systemwide installation) -LIBS += -lhts + +$(info HTSSRC not defined; using htslib submodule) +$(info Use `make HTSSRC=/path/to/htslib` to build angsd using a local htslib installation) +$(info Use `make HTSSRC=systemwide` to build angsd using the systemwide htslib installation) + + +HTSSRC := $(CURDIR)/htslib +CPPFLAGS += -I$(HTSSRC) +LIBHTS := $(HTSSRC)/libhts.a +LIBS := $(LIBHTS) $(LIBS) + +all: .activate_module + endif +.PHONY: .activate_module + +.activate_module: + git submodule update --init --recursive + $(MAKE) -C $(HTSSRC) + + + #modied from htslib makefile FLAGS = -O3 FLAGS2 = $(CPPFLAGS) $(FLAGS) $(LDFLAGS) @@ -50,7 +84,7 @@ all: $(PROGRAMS) misc BAMDIR="" BDIR=$(realpath $(BAMDIR)) -PACKAGE_VERSION = 0.935 +PACKAGE_VERSION = 0.937 ifneq "$(wildcard .git)" "" PACKAGE_VERSION := $(shell git describe --always --dirty) @@ -75,9 +109,11 @@ misc: analysisFunction.o bfgs.o prep_sites.o $(CXX) -c $(CXXFLAGS) $*.cpp $(CXX) -MM $(CXXFLAGS) $*.cpp >$*.d + angsd: version.h $(OBJ) $(CXX) $(FLAGS) -o angsd *.o $(LIBS) $(CRYPTOLIB) + testclean: rm -rf test/sfstest/output test/tajima/output test/*.log version.h test/temp.txt diff --git a/README.md b/README.md index 1560929d..15c4a745 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/ANGSD/angsd.svg?branch=master)](https://travis-ci.com/ANGSD/angsd) +[![Build Status](https://img.shields.io/github/workflow/status/angsd/angsd/build-tests)](https://github.com/ANGSD/angsd) angsd: ===== @@ -25,6 +25,7 @@ cd angsd;make Notes ==== * I've switched over to using htslib for parsing single reads (to allow for CRAM reading, while avoid having to write my own CRAM parser). I'm still using my own readpools. Users should therefore also download and install htslib. +* If you are on a mac computer and the compilation process complains about a missnig crybtolib library then do 'make CRYPTOLIB=""' Program has a paper ===== diff --git a/abcCounts.cpp b/abcCounts.cpp index 078019be..e5208aae 100644 --- a/abcCounts.cpp +++ b/abcCounts.cpp @@ -273,7 +273,7 @@ abcCounts::abcCounts(const char *outfiles,argStruct *arguments,int inputtype){ if(dumpCounts!=5) ksprintf(&bufstr,"chr\tpos\ttotDepth\n"); else - ksprintf(&bufstr,"chr\tpos\tmeanReadLength\n"); + ksprintf(&bufstr,"chr\tpos\tmeanReadLength\tdepth\n"); aio::bgzf_write(oFileCountsPos,bufstr.s,bufstr.l);bufstr.l=0; if(dumpCounts>1) oFileCountsBin = aio::openFileBG(outfiles,postfix2); @@ -460,7 +460,7 @@ void abcCounts::print(funkyPars *pars){ nreads++; } } - ksprintf(&bpos, "%s\t%d\t%.2f\n",header->target_name[pars->refId],pars->posi[s]+1,readlensSum/nreads); + ksprintf(&bpos, "%s\t%d\t%.2f\t%d\n",header->target_name[pars->refId],pars->posi[s]+1,readlensSum/nreads,(int)nreads); // fprintf(stderr,"nraads: %f readlenssum: %f\n",nreads,readlensSum); } diff --git a/abcFreq.cpp b/abcFreq.cpp index db6ea9dd..1a34ce06 100644 --- a/abcFreq.cpp +++ b/abcFreq.cpp @@ -82,7 +82,7 @@ void abcFreq::printArg(FILE *argFile){ fprintf(argFile,"\t-minMaf \t%f\t(Remove sites with MAF below)\n",minMaf); fprintf(argFile,"\t-SNP_pval\t%f\t(Remove sites with a pvalue larger)\n",SNP_pval); fprintf(argFile,"\t-rmTriallelic\t%f\t(Remove sites with a pvalue lower)\n",rmTriallelic); - fprintf(argFile,"\t-forceMaf\t%f\t(Write .mafs file when running -doAsso (by default does not output .mafs file with -doAsso))\n",forceMaf); + fprintf(argFile,"\t-forceMaf\t%d\t(Write .mafs file when running -doAsso (by default does not output .mafs file with -doAsso))\n",forceMaf); fprintf(argFile,"\t-skipMissing\t%d\t(Set post to 0.33 if missing (do not use freq as prior))\n",skipMissing); fprintf(argFile,"Extras:\n"); fprintf(argFile,"\t-ref\t%s\t(Filename for fasta reference)\n",refName); diff --git a/abcScounts.cpp b/abcScounts.cpp index 4d2eaa63..099bd75d 100644 --- a/abcScounts.cpp +++ b/abcScounts.cpp @@ -33,8 +33,8 @@ aMap readvcf(const char *fname){ if(4!=sscanf(buf,"%s\t%d\t%c\t%c\n",chr,&pos,&al1,&al2)){ fprintf(stderr,"\t-> problem parsing line: %d which looks like: %s\n",at,buf); } - char tmpnam[1024]; - sprintf(tmpnam,"%s %d",chr,pos); + char tmpnam[2048]; + snprintf(tmpnam,2048,"%s %d",chr,pos); aMap::iterator it=am.find(tmpnam); if(it!=am.end()){ fprintf(stderr,"\t-> Problem with duplicate positions: %s \n",tmpnam); diff --git a/abcTemplate.cpp b/abcTemplate.cpp index 39de0cb6..5196015d 100644 --- a/abcTemplate.cpp +++ b/abcTemplate.cpp @@ -478,7 +478,8 @@ void abcTemplate::run(funkyPars *pars){ // Reference base: int refB = -1; - if (pars->ref == 0) fprintf(outfile," Warning: Ref not defined! %s \n", pars->ref); + if (pars->ref == NULL) + fprintf(outfile,"\t-> Warning: Ref not defined! \n"); else refB = refToInt[pars->ref[s]]; diff --git a/abcWriteBcf.cpp b/abcWriteBcf.cpp index d5ef3ebf..8db196e0 100644 --- a/abcWriteBcf.cpp +++ b/abcWriteBcf.cpp @@ -128,6 +128,7 @@ void abcWriteBcf::clean(funkyPars *pars){ } void abcWriteBcf::print(funkyPars *pars){ + assert(bcf_hdr_nsamples(hdr)>0); if(doBcf==0) return; @@ -143,7 +144,7 @@ void abcWriteBcf::print(funkyPars *pars){ rec->rid = bcf_hdr_name2id(hdr,header->target_name[pars->refId]); rec->pos = pars->posi[s];//<- maybe one index? // bcf_update_id(hdr, rec, "rs6054257"); - if(domcall!=NULL){ + if(domcall>0&&mcall!=NULL){ // char alleles[16]; int goa =0; @@ -376,7 +377,9 @@ abcWriteBcf::abcWriteBcf(const char *outfiles_a,argStruct *arguments,int inputty fp=aio::openFileHtsBcf(outfiles,".bcf"); rec = bcf_init1(); - if(arguments->inputtype==INPUT_BAM){ + whatIsTheInput(arguments->inputtype); + + if(arguments->inputtype==INPUT_BAM||arguments->inputtype==INPUT_GLF||arguments->inputtype==INPUT_GLF3||arguments->inputtype==INPUT_GLF10_TEXT){ hdr = bcf_hdr_init("w"); print_bcf_header(fp,hdr,args,buf,header,domcall); } else if(arguments->inputtype==INPUT_VCF_GP||arguments->inputtype==INPUT_VCF_GL){ @@ -396,9 +399,11 @@ abcWriteBcf::abcWriteBcf(const char *outfiles_a,argStruct *arguments,int inputty buf.l=0; if ( bcf_hdr_write(fp, hdr)!=0 ) fprintf(stderr,"Failed to write bcf %s:%d\n",__FILE__,__LINE__); + + if(buf.s) + free(buf.s); } - if(buf.s) - free(buf.s); + } diff --git a/aio.cpp b/aio.cpp index 42eaf1cd..3d718a9c 100644 --- a/aio.cpp +++ b/aio.cpp @@ -19,7 +19,7 @@ FILE *aio::openFile(const char* a,const char* b){ fprintf(stderr,"[%s] %s %s",__FUNCTION__,a,b); char *c = new char[strlen(a)+strlen(b)+1]; strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); // fprintf(stderr,"\t-> Dumping file: %s\n",c); dumpedFiles.push_back(strdup(c)); FILE *fp = NULL; @@ -36,7 +36,7 @@ BGZF *aio::openFileBG(const char* a,const char* b){ char *c = new char[strlen(a)+strlen(b)+1]; strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); dumpedFiles.push_back(strdup(c)); BGZF *fp = bgzf_open(c,"w6h"); delete [] c; @@ -47,7 +47,7 @@ htsFile *aio::openFileHts(const char* a,const char* b){ char *c = new char[strlen(a)+strlen(b)+1]; strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); dumpedFiles.push_back(strdup(c)); htsFile *fp = hts_open(c,"w"); delete [] c; @@ -58,7 +58,7 @@ htsFile *aio::openFileHtsBcf(const char* a,const char* b){ char *c = new char[strlen(a)+strlen(b)+1]; strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); dumpedFiles.push_back(strdup(c)); htsFile *fp = hts_open(c,"wb"); delete [] c; diff --git a/analysisFunction.cpp b/analysisFunction.cpp index 90fc2783..64a31ea6 100644 --- a/analysisFunction.cpp +++ b/analysisFunction.cpp @@ -39,12 +39,12 @@ double angsd::addProtectN(double a[],int len){ //function does: log(sum(exp(a))) while protecting for underflow double maxVal = a[0]; - for(int i=1;i<10;i++) + for(int i=1;i getFilenames(const char * name,int nInd); } +void whatIsTheInput(int type); diff --git a/bgenReader.cpp b/bgenReader.cpp index 2aa23642..1ac518b8 100644 --- a/bgenReader.cpp +++ b/bgenReader.cpp @@ -137,7 +137,7 @@ bgenLine *bgenReader::parseline(FILE *fp,header *hd){ unsigned short Lchr_l; assert(fread(&Lchr_l,sizeof(unsigned short),1,fp)==1); bgen->Lchr =(char*) calloc(Lchr_l+1,sizeof(char)); - fread(bgen->Lchr,sizeof(char),Lchr_l,fp); + assert(fread(bgen->Lchr,sizeof(char),Lchr_l,fp)==Lchr_l); assert(fread(&bgen->vpos,sizeof(unsigned),1,fp)==1); assert(fread(&bgen->nal,sizeof(unsigned short),1,fp)==1); diff --git a/doc/formats.pdf b/doc/formats.pdf index 4f8fa46d..948576f6 100644 Binary files a/doc/formats.pdf and b/doc/formats.pdf differ diff --git a/doc/formats.tex b/doc/formats.tex index 44f753c4..18af4d90 100644 --- a/doc/formats.tex +++ b/doc/formats.tex @@ -149,7 +149,7 @@ \subsubsection{Theta definitions} Let $\eta$ be the site frequency spectra. Then $\eta_i$ is the posterior probablity of being in frequency $i$. \begin{itemize} \item[Watterson] $\sum_{i=1}^{n-1}\eta_i/a^{-1}, a=\sum_{i=1}^{n-1}i$ -\item[$\pi$] $ {{n}\choose{2}}^{-1}\sum_{i=1}^{n-1}i(n-1)\eta_i$ +\item[$\pi$] $ {{n}\choose{2}}^{-1}\sum_{i=1}^{n-1}i(n-i)\eta_i$ \item[FuLi] $\eta_1$ \item[FayH] $ {{n}\choose{2}}^{-1}\sum_{i=1}^{n-1}i^2\eta_i$ \item[L] $ {n-1}^{-1}\sum_{i=1}^{n-1}i\eta_i$ diff --git a/htslib b/htslib new file mode 160000 index 00000000..e769401d --- /dev/null +++ b/htslib @@ -0,0 +1 @@ +Subproject commit e769401d18c19ce6150a1d40bdccd2af814e6b1c diff --git a/makeReadPool.cpp b/makeReadPool.cpp index c0142676..76af2ca5 100644 --- a/makeReadPool.cpp +++ b/makeReadPool.cpp @@ -260,7 +260,7 @@ void read_reads_noStop(htsFile *fp,int nReads,int &isEof,readPool &ret,int refTo rdObjRegionDone =1; break; }else if(ret.first[ret.l+i-1]>b->core.pos){ - fprintf(stderr,"[%s] unsorted file detected will exit new(-1)=%d new=%lld,ret.l=%d i=%d\n",__FUNCTION__,ret.first[ret.l+i-1],b->core.pos,ret.l,i); + fprintf(stderr,"[%s] unsorted file detected will exit new(-1)=%d new=%ld,ret.l=%d i=%d\n",__FUNCTION__,ret.first[ret.l+i-1],b->core.pos,ret.l,i); exit(0); } diff --git a/misc/fstreader.cpp b/misc/fstreader.cpp index cbe7d2d4..160471de 100644 --- a/misc/fstreader.cpp +++ b/misc/fstreader.cpp @@ -110,7 +110,7 @@ perfst * perfst_init(char *fname){ #endif fclose(fp); char *tmp =(char*)calloc(strlen(fname)+100,1);//that should do it - tmp=strncpy(tmp,fname,strlen(fname)-3); + memcpy(tmp,fname,strlen(fname)-3); // fprintf(stderr,"tmp:%s\n",tmp); char *tmp2 = (char*)calloc(strlen(fname)+100,1);//that should do it diff --git a/misc/header.cpp b/misc/header.cpp index 44f7e78c..b39586c3 100644 --- a/misc/header.cpp +++ b/misc/header.cpp @@ -28,7 +28,7 @@ BGZF *openFileBG(const char* a,const char* b){ char *c = new char[strlen(a)+strlen(b)+1]; strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); BGZF *fp = bgzf_open(c,"wb"); delete [] c; return fp; @@ -38,7 +38,7 @@ FILE *openFile(const char* a,const char* b){ fprintf(stderr,"[%s] %s %s",__FUNCTION__,a,b); char *c = new char[strlen(a)+strlen(b)+1]; strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); FILE *fp = fopen(c,"w"); delete [] c; return fp; diff --git a/misc/ibs.cpp b/misc/ibs.cpp index 9f735dae..25c4f3fa 100644 --- a/misc/ibs.cpp +++ b/misc/ibs.cpp @@ -78,7 +78,7 @@ std::vector dumpedFiles; FILE *openFile(const char* a,const char* b){ char *c = new char[strlen(a)+strlen(b)+1]; strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); fprintf(stderr,"\t-> Dumping file: %s\n",c); dumpedFiles.push_back(strdup(c)); diff --git a/misc/msHOT2glf.c b/misc/msHOT2glf.c index 021ccf1d..63c3630e 100644 --- a/misc/msHOT2glf.c +++ b/misc/msHOT2glf.c @@ -53,7 +53,7 @@ FILE *openFile(const char* a,const char* b){ // char *c = new char[strlen(a)+strlen(b)+1]; char *c = malloc(strlen(a)+strlen(b)+1); strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); // fprintf(stderr,"\t-> Dumping file: %s\n",c); FILE *fp = getFILE(c,"w"); free(c); @@ -83,7 +83,7 @@ BGZF *openFileGz(const char* a,const char* b,const char *mode){ // char *c = new char[strlen(a)+strlen(b)+1]; char *c = malloc(strlen(a)+strlen(b)+1); strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); // fprintf(stderr,"\t-> Dumping file: %s\n",c); BGZF *fp = getGz(c,mode); //delete [] c; @@ -494,7 +494,7 @@ int main(int argc,char **argv){ char *pch = strstr(line,"msHOT-lite"); while(1){ char *tmppch=strstr(pch+1,"msHOT-lite"); - if(tmppch=='\0') + if(tmppch[0]=='\0') break; pch=tmppch; } diff --git a/misc/msToGlf.c b/misc/msToGlf.c index 914ea250..df39010e 100644 --- a/misc/msToGlf.c +++ b/misc/msToGlf.c @@ -436,9 +436,10 @@ void test ( int nsam, int segsites, char **list,int *positInt,BGZF* gz,double er for(int i=0;i Dumping file: %s\n",c); FILE *fp = getFILE(c,"w"); free(c); @@ -632,7 +633,7 @@ BGZF* openFileGz(const char* a,const char* b,const char *mode){ // char *c = new char[strlen(a)+strlen(b)+1]; char *c = malloc(strlen(a)+strlen(b)+1); strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); // fprintf(stderr,"\t-> Dumping file: %s\n",c); BGZF *fp = getGz(c,mode); //delete [] c; diff --git a/misc/ngsadmix32.cpp b/misc/ngsadmix32.cpp index d2918d59..e707fd14 100644 --- a/misc/ngsadmix32.cpp +++ b/misc/ngsadmix32.cpp @@ -420,7 +420,7 @@ FILE *openFile(const char* a,const char* b){ fprintf(stderr,"[%s] %s %s",__FUNCTION__,a,b); char *c = new char[strlen(a)+strlen(b)+1]; strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); //fprintf(stderr,"\t-> Dumping file: %s\n",c); if(0&&fexists(c)){//ANDERS DAEMON DRAGON HATES THIS fprintf(stderr,"File: %s exists will exist\n",c); @@ -438,7 +438,7 @@ gzFile openFileGz(const char* a,const char* b){ fprintf(stderr,"[%s] %s %s",__FUNCTION__,a,b); char *c = new char[strlen(a)+strlen(b)+1]; strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); // fprintf(stderr,"\t-> Dumping file: %s\n",c); if(0&&fexists(c)){//ANDERS DAEMON DRAGON HATES THIS fprintf(stderr,"File: %s exists will exist\n",c); diff --git a/misc/psmcreader.cpp b/misc/psmcreader.cpp index 8b8ff70d..dd127676 100644 --- a/misc/psmcreader.cpp +++ b/misc/psmcreader.cpp @@ -119,7 +119,7 @@ perpsmc * perpsmc_init(char *fname){ } fclose(fp); char *tmp =(char*)calloc(strlen(fname)+100,1);//that should do it - tmp=strncpy(tmp,fname,strlen(fname)-3); + memcpy(tmp,fname,strlen(fname)-3); // fprintf(stderr,"tmp:%s\n",tmp); char *tmp2 = (char*)calloc(strlen(fname)+100,1);//that should do it diff --git a/misc/realSFS.cpp b/misc/realSFS.cpp index a762b0ca..be9daac1 100644 --- a/misc/realSFS.cpp +++ b/misc/realSFS.cpp @@ -373,7 +373,7 @@ int print_multi(args *arg) for(int i=0;ifname)+100; char *tmp =(char*) calloc(newlen,sizeof(char)); - tmp = strncpy(tmp,saf[i]->fname,strlen(saf[i]->fname)-4); + memcpy(tmp,saf[i]->fname,strlen(saf[i]->fname)-4); fprintf(stderr,"\t-> Generating outputfile: %s\n",tmp); oldfp[i] = fopen(tmp,"wb"); free(tmp); diff --git a/misc/safreader.cpp b/misc/safreader.cpp index af658f4a..0caa330a 100644 --- a/misc/safreader.cpp +++ b/misc/safreader.cpp @@ -158,8 +158,10 @@ persaf * persaf_init(char *fname, int verbose) } fclose(fp); - char *tmp =(char*) calloc(strlen(fname)+100,1); - tmp=strncpy(tmp,fname,strlen(fname)-3); + + char *tmp =(char*)calloc(strlen(fname)+100,sizeof(char));//that should do it + memcpy(tmp,fname,strlen(fname)-3); + // fprintf(stderr,"tmp:%s\n",tmp); char *tmp2 = (char*)calloc(strlen(fname)+100,1); diff --git a/misc/smartCount.c b/misc/smartCount.c index 998ccfa4..3a66c183 100644 --- a/misc/smartCount.c +++ b/misc/smartCount.c @@ -478,7 +478,7 @@ int treemixer(int argc,char **argv){ } ++argv; } - fprintf(stderr,"reg:%s flis:%s\n",reg,flis ); + // fprintf(stderr,"reg:%s flis:%s\n",reg,flis ); if(!flis){ fprintf(stderr,"Must supply -bin/idx or bam\n"); return 0; diff --git a/misc/supersim.cpp b/misc/supersim.cpp index d4e8d61c..100a28ad 100644 --- a/misc/supersim.cpp +++ b/misc/supersim.cpp @@ -315,7 +315,7 @@ double simfreqBN(double F, double p_anc) { char *append(const char* a,const char *b){ char *c =(char *) malloc((strlen(a)+strlen(b)+1)*sizeof(char)); strcpy(c,a); - strncat(c,b,strlen(b)); + strcat(c,b); return c; } diff --git a/multiReader.cpp b/multiReader.cpp index bf6566f5..59772abf 100644 --- a/multiReader.cpp +++ b/multiReader.cpp @@ -199,7 +199,7 @@ multiReader::multiReader(argStruct *args_arg){ 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)){ @@ -207,6 +207,11 @@ multiReader::multiReader(argStruct *args_arg){ fprintf(stderr,"\t-> Must supply -nInd when using -glf/-glf3/-pileup/-glf10_text files\n"); exit(0); } + for(int i=0;ism, bufbuf, NULL); + } }else args->nInd = args->nams.size(); diff --git a/prep_sites.cpp b/prep_sites.cpp index 01d919c7..459af29f 100644 --- a/prep_sites.cpp +++ b/prep_sites.cpp @@ -215,8 +215,8 @@ filt *filt_read(const char *fname){ exit(0); } if(aio::isNewer(fname,bin_name)||aio::isNewer(fname,idx_name)){ - fprintf(stderr,"\t-> Potential problem: File: \'%s\' looks newer than files: \'%s\',\'%s\'\n\t-> Please delete %s/%s files and rerun.\n",fname,bin_name,idx_name,bin_name,idx_name); - exit(0); + fprintf(stderr,"\t-> Warning: File: \'%s\' looks newer than files: \'%s\',\'%s\'\n\t-> Please delete %s/%s files and rerun.\n",fname,bin_name,idx_name,bin_name,idx_name); + //exit(0); } ret->fp= fopen(idx_name,"r"); diff --git a/test/sfstest/md5/sfsinput.md5sum b/test/sfstest/md5/sfsinput.md5sum index 8ab1c694..d67b98ba 100644 --- a/test/sfstest/md5/sfsinput.md5sum +++ b/test/sfstest/md5/sfsinput.md5sum @@ -1,4 +1,4 @@ 85c66ad4ef883f536ba9f650e7f9ed75 sfstest.args 4c0b2d07602f53a21617f4da897b4eef sfstest.frq 597d6be8c6c07431b604045f69401909 sfstest.geno -f80248a9e0bfabba06615f0bf4549032 sfstest.glf.gz +#f80248a9e0bfabba06615f0bf4549032 sfstest.glf.gz diff --git a/vcfReader.cpp b/vcfReader.cpp index 6ae703c1..c81d9786 100644 --- a/vcfReader.cpp +++ b/vcfReader.cpp @@ -239,6 +239,8 @@ int vcfReader::parseline(bcf1_t *rec,htsstuff *hs,funkyPars *r,int &balcon,int t r->major[balcon] = refToChar[rec->d.allele[0][0]]; r->minor[balcon] = refToChar[rec->d.allele[1][0]]; + if(r->major[balcon]==4)//<- means N + return 0; // pl data for each call @@ -330,8 +332,7 @@ int vcfReader::parseline(bcf1_t *rec,htsstuff *hs,funkyPars *r,int &balcon,int t bcf_float_set_vector_end(ln_gl[i]); } else{ ln_gl[i] = farr[i]/M_LOG10E; - if(ln_gl[i]==0.0) - ln_gl[i] = -0.0; + // if(ln_gl[i]==0.0) ln_gl[i] = -0.0; } // fprintf(stderr, "%f %f\n", farr[i], ln_gl[i]); } @@ -340,24 +341,46 @@ int vcfReader::parseline(bcf1_t *rec,htsstuff *hs,funkyPars *r,int &balcon,int t fprintf(stderr, "\t\t-> BIG TROUBLE. Can only take one of two tags, PL or GL\n"); return 0; } - + /* + We assume we have data and set all to -inf + Then we check if something is nan, if one of them are nan we set all gls to missing -0.0 + Secondly we check that the gls we have plugged in contains information (difference between them), is not set to miggin + */ if(type==0||type==1){ if(n>=0){//case where we have data + // fprintf(stderr,"data\n"); assert((n % hs->nsamples)==0 ); int myofs=n/hs->nsamples; for(int ind=0;indnsamples;ind++){ int rollback =0; + int at =0; + double hastaken[10]; for(int o=0;o<10;o++){ - if(myreorder[o]!=-1) + if(myreorder[o]!=-1){ dupergl[ind*10+o] = ln_gl[ind*myofs+myreorder[o]]; + hastaken[at++] = ln_gl[ind*myofs+myreorder[o]]; + } if(std::isnan(dupergl[ind*10+o])){ rollback = 1; break; } } + + + for(int o=0;rollback&&o<10;o++) - if(myreorder[o]!=-1) - dupergl[ind*10+o] = -0.0; + dupergl[ind*10+o] = 0.0; + + rollback =0; + + for(int i=1;at>1&&i