Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]: Fix assert bug related to DNDEBUG flags #527 #533

Merged
merged 5 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# Other files
*.d
angsd
angsdput*
misc/NGSadmix
misc/contamination
misc/contamination2
Expand Down
3 changes: 1 addition & 2 deletions abcAncestry.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <cassert>
#include <ctype.h>
#include "shared.h"
#include "analysisFunction.h"
Expand Down Expand Up @@ -52,7 +51,7 @@ void abcAncestry::clean(funkyPars *pars){


void abcAncestry::print(funkyPars *pars){
assert(pars->anc!=NULL);
aio::doAssert(pars->anc!=NULL,1,AT,"");
if(doAncestry==1){

}
Expand Down
3 changes: 1 addition & 2 deletions abcCallGenotypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class to call genotypes
*/

#include <assert.h>
#include <htslib/kstring.h>
#include "shared.h"

Expand Down Expand Up @@ -189,7 +188,7 @@ void abcCallGenotypes::getGeno(funkyPars *pars){

void abcCallGenotypes::printGeno(funkyPars *pars){
genoCalls *geno =(genoCalls *) pars->extras[index];
assert(pars->keepSites!=NULL);
aio::doAssert(pars->keepSites!=NULL,1,AT,"");
bufstr.l=0;
int doGenoInner = abs(doGeno);
for(int s=0;s<pars->numSites;s++) {
Expand Down
5 changes: 2 additions & 3 deletions abcCounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

#include <htslib/kstring.h>
#include <cassert>
#include "analysisFunction.h"
#include "abc.h"
#include "abcCounts.h"
Expand Down Expand Up @@ -476,7 +475,7 @@ void abcCounts::print(funkyPars *pars){
countQs(pars->chk,qsDist,pars->keepSites,minQ);

if(doDepth!=0){
assert(pars->counts!=NULL);
aio::doAssert(pars->counts!=NULL,1,AT,"");
for(int s=0;s<pars->numSites;s++) {
if(pars->keepSites[s]==0)
continue;
Expand Down Expand Up @@ -673,7 +672,7 @@ suint **abcCounts::countNucs(const chunkyT *chk,int *keepSites,int mmin,int mmax
void abcCounts::run(funkyPars *pars){
if(doCounts==0)
return;
assert(pars->chk!=NULL&&pars->counts==NULL);
aio::doAssert(pars->chk!=NULL&&pars->counts==NULL,1,AT,"");
pars->counts = countNucs(pars->chk,pars->keepSites,setMinDepthInd,setMaxDepthInd);
if(doebd){
counts *cnts = new counts;
Expand Down
3 changes: 1 addition & 2 deletions abcError.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <list>
#include <cmath>
#include <cassert>
#include "bfgs.h"
#include "analysisFunction.h"
#include "abcError.h"
Expand Down Expand Up @@ -420,7 +419,7 @@ void abcError::clean(funkyPars *pars){
void abcError::run(funkyPars *pars){
if(doError==0)
return;
assert(pars->counts!=NULL);
aio::doAssert(pars->counts!=NULL,1,AT,"");


// pars->opt->emIter=emIter;
Expand Down
1 change: 0 additions & 1 deletion abcFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ osome if we have reached the last position from the keep list.
Maybe there are some memleaks. This will have to be fixed later.
*/

#include <cassert>
#include <sys/stat.h>
#include "shared.h"
#include "abc.h"
Expand Down
13 changes: 6 additions & 7 deletions abcFreq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

*/

#include <cassert>
#include <cmath>
#include <htslib/kstring.h>
#include <htslib/bgzf.h>
Expand Down Expand Up @@ -145,7 +144,7 @@ void abcFreq::getOptions(argStruct *arguments){
underflowprotect=angsd::getArg("-underFlowProtect",underflowprotect,arguments);

minMaf=angsd::getArg("-minMaf",minMaf,arguments);
// assert(minMaf<=1&&minMaf>=0);
// ASSERT(minMaf<=1&&minMaf>=0);

double tmp=-1;
tmp=angsd::getArg("-SNP_pval",tmp,arguments);
Expand Down Expand Up @@ -442,7 +441,7 @@ void abcFreq::print(funkyPars *pars) {

int major = pars->major[s];
int minor = pars->minor[s];
assert(major!=4&&minor!=4);
aio::doAssert(major!=4&&minor!=4,1,AT,"");

for(int i=0;i<3*pars->nInd;i++) {
ksprintf(&bufstr, "\t%f",pars->post[s][i]);
Expand Down Expand Up @@ -596,7 +595,7 @@ void abcFreq::run(funkyPars *pars) {
}
}
if(doPost) {
assert(pars->likes!=NULL);
aio::doAssert(pars->likes!=NULL,1,AT,"");

double **post = new double*[pars->numSites];
double **like=angsd::get3likes(pars);
Expand All @@ -622,7 +621,7 @@ void abcFreq::run(funkyPars *pars) {
fprintf(stderr,"\t-> Problem calling genotypes at: (%s,%d)\n",header->target_name[pars->refId],pars->posi[s]+1);
}
else if(doPost==4){
assert(fl!=NULL);
aio::doAssert(fl!=NULL,1,AT,"");
//af for this pos: fl->af[pars->posi[s]]
//an for this pos: fl->an[pars->posi[s]]
//ac for this pos: fl->ac[pars->posi[s]]
Expand Down Expand Up @@ -680,7 +679,7 @@ void abcFreq::likeFreq(funkyPars *pars,freqStruct *freq){//method=1: bfgs_known
loglike= pars->likes;
else
loglike=angsd::get3likesRescale(pars);
assert(loglike!=NULL);
aio::doAssert(loglike!=NULL,1,AT,"");

if(doSNP)
freq->lrt = new double[pars->numSites];
Expand Down Expand Up @@ -1283,7 +1282,7 @@ double abcFreq::emFrequency(double *loglike,int numInds, int iter,double start,i
break;
}
p=-999;
assert(p!=999);
aio::doAssert(p!=999,1,AT,"");
return p;
}

Expand Down
31 changes: 15 additions & 16 deletions abcGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

#include <cmath>
#include <assert.h>
#include <htslib/kstring.h>
#include "analysisFunction.h"
#include "abc.h"
Expand Down Expand Up @@ -294,9 +293,9 @@ abcGL::abcGL(const char *outfiles,argStruct *arguments,int inputtype){

abcGL::~abcGL(){
if(GL>0&&doGlf==5){
assert(outfileSAF!=NULL);
assert(outfileSAFIDX!=NULL);
assert(outfileSAFPOS!=NULL);
aio::doAssert(outfileSAF!=NULL,AT);
aio::doAssert(outfileSAFIDX!=NULL,AT);
aio::doAssert(outfileSAFPOS!=NULL,AT);
// fprintf(stderr,"nnnSites:%d\n",nnnSites);
if(nnnSites!=0&&tmpChr!=NULL){
size_t clen = strlen(tmpChr);
Expand Down Expand Up @@ -368,11 +367,11 @@ void abcGL::print(funkyPars *pars){


void abcGL::run(funkyPars *pars){
assert(pars!=NULL);
aio::doAssert(pars!=NULL,AT);

if(GL==0)
return;
//assert(pars->chk!=NULL);
//aio::doAssert(pars->chk!=NULL);
double **likes = NULL;
if(soap.doRecal!=1 || ancestral_lik.doRecal!=1)
likes = new double*[pars->chk->nSites];
Expand Down Expand Up @@ -482,7 +481,7 @@ void abcGL::getLikesFullError10Genotypes(int numSites,int nInd,suint **counts,do
}

void abcGL::printLike(funkyPars *pars) {
assert(pars->likes!=NULL);
aio::doAssert(pars->likes!=NULL,AT);


if(doGlf==1){
Expand All @@ -498,7 +497,7 @@ void abcGL::printLike(funkyPars *pars) {
bufstr.l = 0; //set tmpbuf beginning to zero
for(int s=0;s<pars->numSites;s++) {
lh3struct *lh3 = (lh3struct*) pars->extras[index+2];
assert(lh3);
aio::doAssert(lh3!=NULL,AT);
if(pars->keepSites[s]==0||lh3->hasAlloced[s]==0)
continue;

Expand All @@ -512,7 +511,7 @@ void abcGL::printLike(funkyPars *pars) {

int major = pars->major[s];
int minor = pars->minor[s];
assert(major!=4&&minor!=4);
aio::doAssert(major!=4&&minor!=4,AT);


for(int i=0;i<pars->nInd;i++) {
Expand All @@ -524,9 +523,9 @@ void abcGL::printLike(funkyPars *pars) {
ksprintf(&bufstr, "\t%f",val[0]);
ksprintf(&bufstr, "\t%f",val[1]);
ksprintf(&bufstr, "\t%f",val[2]);
assert(!std::isnan(val[0]));
assert(!std::isnan(val[1]));
assert(!std::isnan(val[2]));
aio::doAssert(!std::isnan(val[0]),AT);
aio::doAssert(!std::isnan(val[1]),AT);
aio::doAssert(!std::isnan(val[2]),AT);
}

if(bufstr.l!=0)
Expand All @@ -541,7 +540,7 @@ void abcGL::printLike(funkyPars *pars) {
continue;
char major = pars->major[s];
char minor = pars->minor[s] ;
assert(major!=4&&minor!=4);
aio::doAssert(major!=4&&minor!=4,AT);

for(int i=0;i<pars->nInd;i++) {
double dump[3];
Expand Down Expand Up @@ -592,9 +591,9 @@ void abcGL::printLike(funkyPars *pars) {
void abcGL::changeChr(int refId) {
// fprintf(stderr,"Charnge chr:%d\n",refId);
if(GL>0&&doGlf==5){
assert(outfileSAF!=NULL);
assert(outfileSAFIDX!=NULL);
assert(outfileSAFPOS!=NULL);
aio::doAssert(outfileSAF!=NULL,AT);
aio::doAssert(outfileSAFIDX!=NULL,AT);
aio::doAssert(outfileSAFPOS!=NULL,AT);
// fprintf(stderr,"nnnSites:%d\n",nnnSites);
if(nnnSites!=0&&tmpChr!=NULL){
size_t clen = strlen(tmpChr);
Expand Down
3 changes: 1 addition & 2 deletions abcGetFasta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Actually no need to mutex, except for the first chunk. Lets fix it at some point.
*/

#include <cassert>

#include "analysisFunction.h"
#include "shared.h"
Expand Down Expand Up @@ -137,7 +136,7 @@ char *abcGetFasta::loadChr(perFasta *f, char*chrName,int chrId){

char *abcGetFasta::magic(int refId,int *posi,int numSites,perFasta *f){
pthread_mutex_lock(&f->aMut);
assert(refId!=-1);
aio::doAssert(refId!=-1,1,AT,"");
//load new chr if different from last or if nothing has been loaded before
if(f->curChr==-1||refId!=f->curChr){
// fprintf(stderr,"[%s] chaning to chr: %d\n",__FUNCTION__,refId);
Expand Down
9 changes: 4 additions & 5 deletions abcHetPlas.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <cmath>
#include <ctype.h>
#include <assert.h>
#include "abc.h"
#include "analysisFunction.h"
#include "shared.h"
Expand Down Expand Up @@ -116,7 +115,7 @@ double em3(double *x,double **liks,int seqdepth,int maxIter,double tole,int &itr
break;
exit(0);
}
assert(newlike>=likev);
aio::doAssert(newlike>=likev);
//fprintf(stderr,"lik=%f newlike=%f\n",likev,newlike);

likev=newlike;
Expand Down Expand Up @@ -163,7 +162,7 @@ void abcHetPlas::doNew(funkyPars *pars){
//¯ fprintf(stderr,"lik=%f\n",like(par,liks,seqdepth));
em3(par,liks,seqdepth,maxIter,1e-6,rs->nItr[s][i],rs->diff[s][i]);
int maxBase=angsd::whichMax(par,4);
//assert(maxBase!=-1);//<- if vals are equal...
//aio::doAssert(maxBase!=-1);//<- if vals are equal...
if(maxBase==-1){
fprintf(stderr,"CHECK SITE: %d par=(%f,%f,%f,%f) seqdepth=%d\n",pars->posi[s]+1,par[0],par[1],par[2],par[3],seqdepth);
pars->keepSites[s] =0;
Expand Down Expand Up @@ -204,8 +203,8 @@ void abcHetPlas::run(funkyPars *pars){
fprintf(stderr,"skipping due to nos sites\n");
return;
}
assert(pars->numSites>0);
assert(pars->chk!=NULL);
aio::doAssert(pars->numSites>0);
aio::doAssert(pars->chk!=NULL);
if(doHetPlas){
//exit(0);
doNew(pars);
Expand Down
5 changes: 2 additions & 3 deletions abcIBS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
part of angsd
NB for cov. maf > 0.001 is hardcoded (don't want the world to explode)
*/
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <htslib/kstring.h>
Expand Down Expand Up @@ -268,12 +267,12 @@ void abcIBS::printHaplo(funkyPars *pars){
if(makeMatrix){
for(int i=0;i<pars->nInd;i++){
for(int j=0;j<pars->nInd;j++){
assert( haplo->ibsMatrix[i*pars->nInd+j] >= 0 || haplo->nonMis[i*pars->nInd+j] >= 0 );
aio::doAssert( haplo->ibsMatrix[i*pars->nInd+j] >= 0 || haplo->nonMis[i*pars->nInd+j] >= 0 ,1,AT,"");
// fprintf(stdout,"negative count %d\t%d\n",haplo->ibsMatrix[i*pars->nInd+j],haplo->nonMis[i*pars->nInd+j]);

ibsMatrixAll[i*pars->nInd+j] += haplo->ibsMatrix[i*pars->nInd+j];
nonMisAll[i*pars->nInd+j] += haplo->nonMis[i*pars->nInd+j];
assert(nonMisAll[i*pars->nInd+j] >= 0 || ibsMatrixAll[i*pars->nInd+j] >= 0);
aio::doAssert(nonMisAll[i*pars->nInd+j] >= 0 || ibsMatrixAll[i*pars->nInd+j] >= 0,1,AT,"");
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions abcMajorMinor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@


#include <cmath> //<- for log,exp
#include <cassert>
#include <cfloat>
#include "shared.h"
#include "analysisFunction.h"
#include "abc.h"
#include "abcMajorMinor.h"
#include "abcFilter.h"
#include "aio.h"

static int isnaninf(double *d,int l){
for(int i=0;i<l;i++)
if(std::isnan(d[i])||std::isinf(d[i]))
Expand Down Expand Up @@ -278,7 +279,7 @@ void abcMajorMinor::majorMinorGL(funkyPars *pars,int doMajorMinor){
fprintf(stdout,"\t-> Something has gone wrong trying to infer major/minor from GLS at \'%s\' %d will discard site from analysis\n",header->target_name[pars->refId],pars->posi[s]+1);
pars->keepSites[s]=0;
}
// assert(choiceMajor!=-1&&choiceMinor!=-1);
// aio::doAssert(choiceMajor!=-1&&choiceMinor!=-1);
for(int i=0;i<pars->nInd;i++){
W0=exp(pars->likes[s][i*10+angsd::majorminor[choiceMajor][choiceMajor]])*0.25;
W1=exp(pars->likes[s][i*10+angsd::majorminor[choiceMajor][choiceMinor]])*0.5;
Expand Down Expand Up @@ -389,7 +390,7 @@ int abcMajorMinor::majorMinorEBD(funkyPars *pars,int doMajorMinor){
}

void majorMinorCounts(suint **counts,int nFiles,int nSites,char *major,char *minor,int *keepSites,int doMajorMinor,char *ref,char *anc) {
assert(counts!=NULL);
aio::doAssert(counts!=NULL,1,AT,"");

for(int s=0;s<nSites;s++){
if(keepSites==0)
Expand Down Expand Up @@ -517,7 +518,7 @@ void abcMajorMinor::run(funkyPars *pars){
continue;
int major = pars->major[s];
int minor = pars->minor[s];
assert(major!=4&&minor!=4);
aio::doAssert(major!=4&&minor!=4,1,AT,"");

lh3->hasAlloced[s]=1;
lh3->lh3[s] = new double[3*pars->nInd];
Expand Down
8 changes: 4 additions & 4 deletions abcMcall.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <cassert>
#include "abc.h"
#include "aio.h"
#include "analysisFunction.h"
#include "shared.h"
#include "abcMcall.h"
Expand All @@ -22,7 +22,7 @@ void abcMcall::printArg(FILE *fp){
}

void offset2allele(int a,int &b,int &c){
assert(a>=0&&a<10);
aio::doAssert(a>=0&&a<10,1,AT,"");
if(a==0){//AA
b=0;
c=0;
Expand Down Expand Up @@ -605,8 +605,8 @@ void abcMcall::run(funkyPars *pars) {
int b2=refToInt[DAS_BEST[1]];
// fprintf(stderr,"offset2allele: which=%d a1=%d a2=%d DAS: b1=%d b2=%d lk: %f nd->l: %d\n",whichmax,a1,a2,b1,b2,gc_llh[i*10+whichmax],pars->chk->nd[s][i]?pars->chk->nd[s][i]->l:0);
if(b2!=4){
assert(a1==b1||a1==b2);
assert(a2==b1||a2==b2);
aio::doAssert(a1==b1||a1==b2);
aio::doAssert(a2==b1||a2==b2);
}
dat->gcdat[s][i] = -1;
if(pars->chk->nd[s][i]&&pars->chk->nd[s][i]->l>0){
Expand Down
Loading