Esempio n. 1
0
void CAMdataHandler::initialize(long size, int dType)
{
        destroyData();
        allocateData(size,dType);
        setTypeFlag(dType);
        temporaryFlag   = 0;
}
Esempio n. 2
0
Boolean List_destroyListAndData(List * list, void (*destroyData)(void * data))
{
    ListNode * currentNode;
    
    if(list == NULL)
        return false;
    destroyData(NULL);

    while ((currentNode = detachFront(list)) != NULL) {
        destroyData(currentNode->data);
        if(!destroyNode(currentNode))
            return false;
    }
    
    free(list);

    return true;
}
Esempio n. 3
0
void CThreadPoolJob::perform()
{
   if (mPerformer)
   {
      mPerformer(mpJobData);
   }

   destroyData();
}
Esempio n. 4
0
void  CAMdataHandler::initialize()
{
    destroyData();

    dataType        = 0;
    dataPointer     = 0;
    dataSize        = 0;
    temporaryFlag   = 0;
    referenceCount  = 0;
}
Esempio n. 5
0
void destroyGame() {

   destroyTimer();
   destroyData();

   inGame = 0;

   pthread_mutex_destroy(&resourceMutex);
   return;
}
Esempio n. 6
0
static void destroySubTree(TreeNode * node, void (*destroyData)(void * data))
{
	if(node == NULL)
		return;

	destroySubTree(node->left, destroyData);
	destroySubTree(node->right, destroyData);

	if(destroyData != NULL)
		destroyData(node->data);

	destroyNode(node);
}
bool DrawProfiler::loadSystemProperties() {
    bool changed = false;
    ProfileType newType = loadRequestedProfileType();
    if (newType != mType) {
        mType = newType;
        if (mType == kNone) {
            destroyData();
        } else {
            createData();
        }
        changed = true;
    }
    bool showDirty = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
    if (showDirty != mShowDirtyRegions) {
        mShowDirtyRegions = showDirty;
        changed = true;
    }
    return changed;
}
Esempio n. 8
0
void  CAMdataHandler::initialize(const CAMdataHandler& A)
{


    if(A.temporaryFlag == 1)
    {
        dataType        = A.dataType;
        dataSize        = A.dataSize;
        dataPointer     = A.dataPointer;
        temporaryFlag   = 0;
    }
    else
    {
        destroyData();
        allocateData(A.dataSize,A.dataType);
        setTypeFlag(A.dataType);
        copyData(A.dataSize,A.dataPointer);
        temporaryFlag   = 0;
    }
}
bool FrameInfoVisualizer::consumeProperties() {
    bool changed = false;
    ProfileType newType = Properties::getProfileType();
    if (newType != mType) {
        mType = newType;
        if (mType == ProfileType::None) {
            destroyData();
        } else {
            createData();
        }
        changed = true;
    }

    bool showDirty = Properties::showDirtyRegions;
    if (showDirty != mShowDirtyRegions) {
        mShowDirtyRegions = showDirty;
        changed = true;
    }
    return changed;
}
Esempio n. 10
0
//
//********************************************************************************
//                    ASSIGNMENT
//********************************************************************************
//
CAMdataHandler&  CAMdataHandler::operator =( const CAMdataHandler& A)
{
    if(A.temporaryFlag == 1)
    {
        dataType        = A.dataType;
        dataSize        = A.dataSize;
        dataPointer     = A.dataPointer;
        temporaryFlag   = 0;
        referenceCount  = 0;
    }
    else
    {
        destroyData();
        allocateData(A.dataSize,A.dataType);
        setTypeFlag(A.dataType);
        copyData(A.dataSize,A.dataPointer);
        temporaryFlag   = 0;
        referenceCount  = 0;
    }
    return *this;
}
Esempio n. 11
0
 CollisionModel::~CollisionModel()
 {
     destroyData();
 }
Esempio n. 12
0
//
//********************************************************************************
//                    DESTRUCTOR
//********************************************************************************
//
CAMdataHandler::~CAMdataHandler()
{
    if(temporaryFlag == 0) destroyData();
}
FrameInfoVisualizer::~FrameInfoVisualizer() {
    destroyData();
}
Esempio n. 14
0
int main(int argc, char* argv[]){
  int a = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, nN = 0, nK = 0;
  int nNLen = 0, nKLen = 0;
  t_Params tParams;
  t_Data   tSeqData, tRefData;
  char *acTest = NULL;
  int    nTestMatch = -1, nTestLength = -1;
  double dTest = 0.0;
  int nParentD = 0;
  int* anChi = NULL;
  t_Result *atResult;

  /*get command line params*/
  getCommandLineParams(&tParams, argc, argv);
  
  /*read sequences to chimera check*/
  readData(tParams.szSeqInputFile, &tSeqData);

  /*read sequences to compare too*/
  readData(tParams.szRefInputFile, &tRefData);
 
  /*set parameters for sequence distances*/
  initLookUp(&tParams);

  /*number of sequences*/
  nN = tSeqData.nSeq; 

  /*number of reference sequences*/
  nK = tRefData.nSeq;
  
  atResult = (t_Result *) malloc(nN*sizeof(t_Result));
  if(!atResult)
    goto memoryError;
  
  anChi = (int *) malloc(sizeof(int)*nN);
  if(!anChi){
    goto memoryError;
  }
  for(i = 0; i < nN; i++){
    anChi[i] = FALSE;
    atResult[i].dX = 0.0;
    atResult[i].dY = 0.0;
    atResult[i].dZ = 0.0;
    atResult[i].dP = 0.0;
  }

  /*max length of sequences*/
  nNLen = tSeqData.nMaxLen; 

  /*max length of references*/
  nKLen = tRefData.nMaxLen;
  
  sortByFreq(&tSeqData);
  
  for(i = 0; i < nN; i++){
    t_Align atAlign[nK];
    double dBest  = BIG_DBL, dBestChi = 0.0, dBestTri = 0.0;
    int    nBestJ = -1;
    int    nBest = BIG_INT, nBestChi = BIG_INT, nBestTri = BIG_INT;
    int    nSplit = -1, nSplit1 = -1, nSplit2 = -1, nP1 = -1, nP2 = -1, nT1 = -1, nT2 = -1, nT3 = -1;
    int    anRestrict[nK];
    int    nCompare = 0;
    double dLoon = 0.0, dCIndex = 0.0, dP = 0.0, dR = 0.0;
    int    nI = tSeqData.anSort[i];
    int    nLenI = tSeqData.anLen[nI];
    int    anD[nLenI], anR[nLenI], anBestD[nLenI], anBestR[nLenI];

    /*do pairwise alignments and get best hit for each sequence i*/
    nCompare = alignAll(nI, nLenI, &nBest, &nBestJ, anRestrict, nK, &tSeqData, &tRefData, atAlign, &tParams, anChi);

    if(nCompare >= 2){

      nBestChi = getBestChimera(nK, &tRefData, &nP1, &nP2, &nSplit, anRestrict, nLenI, atAlign, anD, anR, anBestD, anBestR);

      if(nBestChi >= 3 && nCompare >= 3){
	nBestTri = getBestTrimera(nK, &tRefData, &nT1, &nT2, &nT3, &nSplit1, &nSplit2, anRestrict, nLenI, atAlign, anD, anR, anBestD, anBestR);
      }
      
      dBestChi = ((double) nBestChi)/((double) nLenI);
      dBestTri = ((double) nBestTri)/((double) nLenI);
	
      dBest = needlemanWunschN(&tSeqData.acSequences[nI*nNLen],&tRefData.acSequences[nBestJ*nKLen] , nLenI, tRefData.anLen[nBestJ], nKLen);
	
      if(nBestChi - nBestTri >= 3){
	
	nTestMatch = TRIMERA;

	acTest =  getTrimera(&nTestLength, &atAlign[nT1], &atAlign[nT2], &atAlign[nT3],nSplit1, nSplit2,nLenI);
	  /*Trimera*/
      }
      else{
	/*Chimera*/
	nTestMatch = CHIMERA;

	acTest =  getChimera(&nTestLength, &atAlign[nP1], &atAlign[nP2], nSplit, nLenI);
      }
    	
      dTest = needlemanWunschN(&tSeqData.acSequences[nI*nNLen], acTest, nLenI, nTestLength, nKLen);

      dCIndex = calcCIndex(nI, nP1, nP2, acTest, nTestLength, &tRefData, &tSeqData);

      dLoon = calcLoonIndex(&tSeqData, &tRefData, nI, nP1, nP2, &nSplit, &nParentD, &tParams);
      
      if(dCIndex >= 0.15 || dCIndex - dBest > 0.0){
        dP = 0.0;
      }
      else{
        dR = tParams.dAlpha + tParams.dBeta*dLoon;
        dP = 1.0/(1.0 + exp(-dR));
      }
      if(dP > 0.5){
	anChi[nI] = TRUE;
      }
      atResult[nI].dX = dCIndex;
      atResult[nI].dY = dCIndex - dBest;
      atResult[nI].dZ = dLoon;
      atResult[nI].dP = dP;

      switch(nTestMatch){
      case GOOD:
	//printf("Good\n");
	break;
      case CHIMERA:
	//printf("Chimera\n");
	break;
      case TRIMERA:
	//printf("Trimera\n");
	break;
      case QUAMERA:
	//printf("Quamera\n");
	break;
      }

      free(acTest);
    }
    else{
      //printf("0 0 Null 0 0 0 Null Null 0.0 0.0 0.0 0.0 0 0 0 Null\n");
    }

    for(j = 0; j < nK; j++){
      if(anRestrict[j] == FALSE){
	free(atAlign[j].acA);
	free(atAlign[j].acB);
	free(atAlign[j].anD);
	free(atAlign[j].anR);
	free(atAlign[j].anMapD);
	free(atAlign[j].anMapR);
      }
    }
    
  }

  for(i = 0; i < nN; i++){
    printf("%s %f %f %f %f\n",tSeqData.aszID[i],atResult[i].dX, atResult[i].dY, atResult[i].dZ, atResult[i].dP);
  }

  /*free allocated memory*/
  free(adLookUp);
  free(anChi);
  free(atResult);
  destroyData(&tSeqData);
  destroyData(&tRefData);

  exit(EXIT_SUCCESS);

 memoryError:
  fprintf(stderr, "Failed allocating memory in main\n");
  fflush(stderr);
  exit(EXIT_FAILURE);
}
Esempio n. 15
0
double calcLoonIndex(t_Data *ptSeqData, t_Data *ptRefData, int nI, int nP1, int nP2, int* pnSplit, int* pnParentD, t_Params *ptParams)
{
  int i = 0, nLenI = ptSeqData->anLen[nI], nLenP1 = ptRefData->anLen[nP1], nLenP2 = ptRefData->anLen[nP2];
  FILE *ofp = NULL;
  char szCommand[MAX_LINE_LENGTH];
  t_Data tAlign;
  int nDiff1 = 0, anDiff1[MAX_DIFF + 1];
  int nDiff2 = 0, anDiff2[MAX_DIFF + 1];
  int anSplits[2*MAX_DIFF], s = 0, s1 = 0, s2 = 0;
  int nSplit = -1, sMin = 0, nMinD = BIG_INT;
  int anD[2*MAX_DIFF];
  int nMaxLen = 0, nTLen = 0;
  char* acSequences = NULL;
  double dRet = 0;
  char szTempFasta[MAX_LINE_LENGTH], szTempAlign[MAX_LINE_LENGTH];
  int nTGap1 = 0, nTGap2 = 0, nTGap3 = 0,nMaxTGap = -1;
  int nParentD = 0;

  /*create sequence filenames*/
  if(ptParams->bOutputAlignments == FALSE){
  	sprintf(szTempFasta, "Temp%s",FASTA_SUFFIX);
  	sprintf(szTempAlign, "Temp%s",ALIGN_SUFFIX);
  }
  else{
  	sprintf(szTempFasta, "Temp%d%s",nI,FASTA_SUFFIX);
  	sprintf(szTempAlign, "Temp%d%s",nI,ALIGN_SUFFIX);
  }

  /*write sequences*/
  ofp = fopen(szTempFasta, "w");
  if(ofp){
    writeSequenceI(ofp, ptSeqData, nI);
    writeSequenceI(ofp, ptRefData, nP1);
    writeSequenceI(ofp, ptRefData, nP2);
    fclose(ofp);
  }
  else{
    fprintf(stderr, "Failed to open %s for writing ... abort\n",szTempFasta);
    exit(EXIT_FAILURE);
  }
  /*run mafft remotely*/
  sprintf(szCommand,"mafft-linsi %s > %s 2> %s",szTempFasta,szTempAlign, TEMP_ERROR_FILE);

  system(szCommand);

  /*read in mafft output - three sequence alignment*/
  readData(szTempAlign, &tAlign);
 
  acSequences = tAlign.acSequences;  nMaxLen = tAlign.nMaxLen;

  /*alignment length*/
  nTLen = tAlign.nMaxLen;

  /*find largest terminal gap*/
  while(acSequences[nTLen - 1 - nTGap1] == GAP && nTLen - nTGap1> 1){
    nTGap1++;
  }

  while(acSequences[nMaxLen + nTLen - 1 - nTGap2] == GAP && nTLen - nTGap2> 1){
    nTGap2++;
  }

  while(acSequences[2*nMaxLen + nTLen - 1 - nTGap3] == GAP && nTLen - nTGap3> 1){
    nTGap3++;
  }

  nMaxTGap = nTGap1 > nTGap2 ? nTGap1 : nTGap2;		
  nMaxTGap = nTGap3 > nMaxTGap ? nTGap3 : nMaxTGap;
  /*remove from alignment*/
  nTLen -= nMaxTGap;	

  /*find all differences between chimera and parents and positions*/
  for(i = 0; i < nTLen; i++){
    if(acSequences[i] != acSequences[nMaxLen + i]){
      if(nDiff1 < MAX_DIFF){
	anDiff1[nDiff1] = i;
	nDiff1++;
      }
      else{
	fprintf(stderr,"Max diff reached in calcLoon\n");
      }
    }

    if(acSequences[i] != acSequences[2*nMaxLen + i]){
      if(nDiff2 < MAX_DIFF){
	anDiff2[nDiff2] = i;
	nDiff2++;
      }
      else{
	fprintf(stderr,"Max diff reached in calcLoon\n");
      }
    }
  }

  for(i = 0; i < nTLen; i++){
    if(acSequences[nMaxLen + i] != acSequences[2*nMaxLen + i]){
      nParentD++;
    }
  }


  anDiff1[nDiff1] = nTLen;
  anDiff2[nDiff2] = nTLen;

  s = 0; s1 = 0; s2 = 0;
  
  anSplits[s] = -1;
  anD[s] = nDiff2;
  s++;
  /*loop differences to find optimal split point*/
  while(s1 < nDiff1 || s2 < nDiff2){
    if(anDiff1[s1] <= anDiff2[s2]){
      anD[s] = anD[s - 1] + 1;
      anSplits[s] = anDiff1[s1];

      s++;
      s1++;
    }
    else if(anDiff1[s1] > anDiff2[s2]){
      anD[s] = anD[s - 1] - 1;
      anSplits[s] = anDiff2[s2];

      s++;
      s2++;
    }
  
  }
  

  for(i = 0; i < s; i++){
    if(anD[i] < nMinD){
      nMinD = anD[i];
      sMin = i;
    }
  }
  
  if(sMin < s - 1){
    nSplit = (anSplits[sMin] + anSplits[sMin + 1])/2;
  }
  else{
    nSplit = nTLen - 1;
  }

  /*dummy if, as we always do this*/
  if(TRUE){
    int nA = -1, nB = -1;
    int nDLP1 = 0, nDRP1 = 0, nDLP2 = 0, nDRP2 = 0;
    int nX = 0, nY = 0, nZ = 0, nXZ = 0;
    int nXA = 0, nXB = 0, nYA = 0, nYB = 0;
    char cC = '\0';
    double pA = 0.0, pB = 0.0;
    double dP = 0.0;

    for(i = 0; i < nTLen; i++){
      char cI = acSequences[i], cP1 = acSequences[nMaxLen + i], cP2 = acSequences[2*nMaxLen + i];
      /*get consenus base*/
      cC = getC(cI, cP1, cP2);

      /*count number of differences between chimera and consensus*/
      if(cI != cC){
	nZ++;
      }
      /*count number of differences between chimera and parent 1*/
      if(cP1 != cC){
	/*count number to left*/
	if(i <= nSplit){
	  nDLP1++;
	}
	/*count number to right*/
	else{
	  nDRP1++;
	}
      }
      /*count number of differences between chimera and parent 2*/
      if(cP2 != cC){
	if(i <= nSplit){
	  nDLP2++;
	}
	else{
	  nDRP2++;
	}
      }
    }
    /*if Parent1 is left*/
    if(nDiff1 <= nDiff2){
      nA = nP1;
      nB = nP2;

      nX = nDLP1 + nDRP1;
      nXA = nDLP1; nXB = nDRP1;

      nY = nDLP2 + nDRP2;
      nYA = nDLP2; nYB = nDRP2;

      pA = ((double) nSplit + 1)/((double) nTLen); /*probability of change to left*/
      pB = ((double) nTLen - nSplit - 1)/((double) nTLen);/*prob. to right*/
    }
    else{
      /*if parent 1 is right*/
      nA = nP2;
      nB = nP1;

      nX = nDLP2 + nDRP2;
      nXA = nDRP2; nXB = nDLP2;

      nY = nDLP1 + nDRP1;
      nYA = nDRP1; nYB = nDLP1;

      pB = ((double) nSplit + 1)/((double) nTLen);
      pA = ((double) nTLen - nSplit - 1)/((double) nTLen);
    }

    nXZ = nX + nZ;
    
    dRet = 0.0;
    dP = 0.0;
    
    /*adds extra factor for tree imbalance - not generally used*/
    if(ptParams->bImbalance){
      if(nXZ > 0){
	for(i = nX; i <= nXZ; i++){
	  dP += gsl_ran_binomial_pdf (i, 0.5, nXZ);
	}

	dRet += -log(dP);
      }
    }

    /*contribution from right parent*/
    if(nY > 0){
      dP = 0.0;
      for(i = nYA; i <= nY; i++){
	dP += gsl_ran_binomial_pdf(i, pA, nY);
      }
      dRet += -log(dP);
    }

    /*contribution from left*/
    if(nX > 0){
      dP = 0.0;
      for(i = nXB; i <= nX; i++){
	dP += gsl_ran_binomial_pdf(i, pB, nX);
      }
      dRet += -log(dP);
    }
  }

  (*pnSplit) = nSplit;
  (*pnParentD) = nParentD;

  /*free up memory*/
  destroyData(&tAlign);
  return dRet;
} 
DrawProfiler::~DrawProfiler() {
    destroyData();
}
Esempio n. 17
0
int driver(const char* szFileStub, int nKStart, int nLMin, unsigned long lSeed, int nMaxIter, double dEpsilon, int bCOut)
{
  t_Params           tParams;
  t_Data             tData;
  gsl_rng            *ptGSLRNG     = NULL;
  const gsl_rng_type *ptGSLRNGType = NULL;
  int i = 0, k = 0, nD = 0, nN = 0;
  char szOFile[MAX_FILE_NAME_LENGTH];
  FILE *ofp = NULL;
  t_VBParams tVBParams;
  t_Cluster  *ptBestCluster = NULL;
  gsl_matrix *ptTemp = NULL;
  gsl_matrix *ptTVar = NULL;
  /*initialise GSL RNG*/
  gsl_rng_env_setup();

  gsl_set_error_handler_off();
  
  ptGSLRNGType = gsl_rng_default;
  ptGSLRNG     = gsl_rng_alloc(ptGSLRNGType);
  
  /*get command line params*/
  tParams.nKStart  = nKStart;
  tParams.nLMin    = nLMin;
  tParams.nMaxIter = nMaxIter;
  tParams.dEpsilon = dEpsilon;
  tParams.lSeed    = lSeed;

  setParams(&tParams,szFileStub);

  /*read in input data*/
  readInputData(tParams.szInputFile, &tData);

  readPInputData(tParams.szPInputFile, &tData);

  nD = tData.nD;
  nN = tData.nN;

  ptTemp = gsl_matrix_alloc(tData.nT,nD);
  ptTVar = gsl_matrix_alloc(tData.nT,tData.nT);

  setVBParams(&tVBParams, &tData);
  
  ptBestCluster = (t_Cluster *) malloc(sizeof(t_Cluster));

  ptBestCluster->nN = nN;
  ptBestCluster->nK = tParams.nKStart;
  ptBestCluster->nD = nD;
  ptBestCluster->ptData = &tData;
  ptBestCluster->ptVBParams = &tVBParams;
  ptBestCluster->lSeed = tParams.lSeed;
  ptBestCluster->nMaxIter = tParams.nMaxIter;
  ptBestCluster->dEpsilon = tParams.dEpsilon;

  if(bCOut > 0){
	ptBestCluster->szCOutFile = szFileStub;
  }
  else{
	ptBestCluster->szCOutFile = NULL;
  }
  runRThreads((void *) &ptBestCluster);

  compressCluster(ptBestCluster);

  calcCovarMatrices(ptBestCluster,&tData);

  sprintf(szOFile,"%sclustering_gt%d.csv",tParams.szOutFileStub,tParams.nLMin);
  writeClusters(szOFile,ptBestCluster,&tData);

  sprintf(szOFile,"%spca_means_gt%d.csv",tParams.szOutFileStub,tParams.nLMin);
  writeMeans(szOFile,ptBestCluster);

  sprintf(szOFile,"%smeans_gt%d.csv",tParams.szOutFileStub,tParams.nLMin);
  writeTMeans(szOFile,ptBestCluster,&tData);

  for(k = 0; k < ptBestCluster->nK; k++){
    sprintf(szOFile,"%spca_variances_gt%d_dim%d.csv",tParams.szOutFileStub,tParams.nLMin,k);
    
    writeSquareMatrix(szOFile, ptBestCluster->aptSigma[k], nD);
  
    /*not entirely sure this is correct?*/
    gsl_blas_dgemm (CblasNoTrans,CblasNoTrans,1.0,tData.ptTMatrix,ptBestCluster->aptSigma[k],0.0,ptTemp);
  
    gsl_blas_dgemm (CblasNoTrans,CblasTrans,1.0,ptTemp,tData.ptTMatrix,0.0,ptTVar);

    sprintf(szOFile,"%svariances_gt%d_dim%d.csv",tParams.szOutFileStub,tParams.nLMin,k);

    writeSquareMatrix(szOFile, ptTVar, nD);
  }

  sprintf(szOFile,"%sresponsibilities.csv",tParams.szOutFileStub);

  ofp = fopen(szOFile,"w");
  if(ofp){    

    for(i = 0; i < nN; i++){
      for(k = 0; k < ptBestCluster->nK - 1; k++){
	fprintf(ofp,"%f,",ptBestCluster->aadZ[i][k]);
      }
      fprintf(ofp,"%f\n",ptBestCluster->aadZ[i][ptBestCluster->nK - 1]);
    }

    fclose(ofp);
  }
  else{
    fprintf(stderr,"Failed openining %s in main\n", szOFile);
    fflush(stderr);
  }

  sprintf(szOFile,"%svbl.csv",tParams.szOutFileStub);

  ofp = fopen(szOFile,"w");
  if(ofp){    
    fprintf(ofp,"%d,%f,%d\n",ptBestCluster->nK,ptBestCluster->dVBL,ptBestCluster->nThread);

    fclose(ofp);
  }
  else{
    fprintf(stderr,"Failed openining %s in main\n", szOFile);
    fflush(stderr);
  }

  /*free up memory in data object*/
  destroyData(&tData);

  /*free up best BIC clusters*/

  destroyCluster(ptBestCluster);
  free(ptBestCluster);

  destroyParams(&tParams);
  gsl_rng_free(ptGSLRNG);
  gsl_matrix_free(tVBParams.ptInvW0);
  gsl_matrix_free(ptTemp);
  gsl_matrix_free(ptTVar);

  return EXIT_SUCCESS;
}