Пример #1
0
    int main(){
        int res;

        char *a = calloc(16, sizeof(char));
        sprintf(a, "%s", "AAATTTTTTTGCAAGA");
        char *b = calloc(11, sizeof(char));
        sprintf(b, "%s", "ATTGGCAAAG");
        int lena = 15;
        int lenb = 10;

        int *m = calloc(lena * lenb, sizeof(int));
        int *horizGap_m = calloc(lena * lenb, sizeof(int));
        int *vertGap_m = calloc(lena * lenb, sizeof(int));
        int *trBack = calloc(lena + lenb, sizeof(int));

        res = needlemanWunsch(a, b,
            1, 0, 0,
            3, 0,
            0, 0,
            lena, lenb,
            m, horizGap_m, vertGap_m, trBack,
            1, "log.txt", 0, "seq1", "seq2", 0, 0);

            return 0;
        }
Пример #2
0
int alignAll(int nI, int nLenI, int *pnBest, int *pnBestJ, int *anRestrict, int nK, t_Data *ptSeqData, t_Data *ptRefData, t_Align* atAlign, t_Params *ptParams, int* anChi)
{
  int j = 0, nCompare = 0, nBest = BIG_INT, nBestJ = -1;
  int nNLen = ptSeqData->nMaxLen, nKLen = ptRefData->nMaxLen;

  for(j = 0; j < nK; j++){
    int     nDist = 0;

    if(anChi[j] == FALSE && (strcmp(ptRefData->aszID[j],ptSeqData->aszID[nI]) != 0 && ptRefData->anFreq[j] > ptParams->nSkew*ptSeqData->anFreq[nI])){

      needlemanWunsch(&atAlign[j], &ptSeqData->acSequences[nI*nNLen], &ptRefData->acSequences[j*nKLen], nLenI, ptRefData->anLen[j]);
      
      nDist = atAlign[j].nDiff;
	
      if(nDist < nBest){
	nBest  = nDist;
	nBestJ = j;
      }
      
      nCompare++;
      anRestrict[j] = FALSE;
    }
    else{
      anRestrict[j] = TRUE;
    }
  }

  (*pnBest) = nBest;
  (*pnBestJ) = nBestJ;

  return nCompare;
}
Пример #3
0
int main() {
	unsigned int k, i;		// loop variables
	unsigned int max;
	init();							// Should init count as part of the time?

	for (k=0; k<NUM_READS; k++) { // Loop through each read
		best_fits[k] = needlemanWunsch(reads[k], ref_genome);
		// Print the results
		printf("READ #%d - Best fit at index %d\n", k, best_fits[k]);
	}

	return 0;
}
Пример #4
0
int main(int argc, char* argv[]){
  int a = 0, i = 0, j = 0, nN = 0, nM = 0;
  t_Params tParams;
  t_Data   tData;
  double *adDists = NULL;
  int    numtasks, rank, rc; 
  int    offset, nA, nA0, nSize, nCount, nStart, nFinish, nTag = 1;
  int    nPackets = 0, nPacketSize = 0, nPacketCurr = 0;
  MPI_Status   status;

  fflush(stdout);

  rc = MPI_Init(&argc,&argv);
  if (rc != MPI_SUCCESS) {
    printf ("Error starting MPI program. Terminating.\n");
    MPI_Abort(MPI_COMM_WORLD, rc);
  }

  MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
  MPI_Comm_rank(MPI_COMM_WORLD,&rank);

  /*get command line params*/
  getCommandLineParams(&tParams, argc, argv);
  
  fflush(stdout);

  if(rank == 0){ /*head node reads data*/
    
    //printf("%d read data\n",rank); fflush(stdout);

    initLookUp(&tParams);

    readData(&tData, &tParams);
 
    MPI_Bcast(adLookUp, N_BASES*N_BASES, MPI_DOUBLE, 0, MPI_COMM_WORLD);

    //printf("%d broadcast data\n",rank); fflush(stdout);

    /*sends it out to other nodes*/
    broadcastData(&tData);

    /*do my bit*/
    nN = tData.nSeq; nM = tData.nMaxLen;

    /*allocate memory for whole dist matrix*/
    nSize = (nN*(nN - 1))/2;
    
    nA = (int) (floor(nSize / numtasks));

    nA0 = nA + (nSize % numtasks);

    adDists = (double *) malloc(nA*sizeof(double)); 
    if(!adDists)
      goto memoryError;

    printf("%d\n",nN);
    /*output identifiers here*/
    if(tParams.bIdent == TRUE){
      for(i = 0; i < tData.nSeq; i++){
	printf("%s\n", tData.aszID[i]);
      }
    }
    nCount = 0;
    for(i = 0; i < nN; i++){
      for(j = 0; j < i; j++){
	double  dDist = needlemanWunsch(&tData.acSequences[i*nM], &tData.acSequences[j*nM],tData.anLen[i], tData.anLen[j], tData.nMaxLen);

	printf("%.8e\n",dDist);

	nCount++;
	if(nCount == nA0){
	  goto finish;
	}
      }
      fflush(stdout);
    }

  finish:
    nPackets = ((nA - 1)/MAX_PACKET_SIZE) + 1;

    for (i = 1; i < numtasks; i++){
      
      nPacketCurr = 0;
      for(j = 0; j < nPackets; j++){
       	
	if(j < nPackets - 1){
	  nPacketSize = MAX_PACKET_SIZE;
	}
	else{
	  nPacketSize = nA % MAX_PACKET_SIZE;
	}
	
	MPI_Recv((void *) (&adDists[nPacketCurr]), nPacketSize, 
		 MPI_DOUBLE, i, nTag, MPI_COMM_WORLD, &status);
	
	nPacketCurr += nPacketSize;
      }
      

      for(j = 0; j < nA; j++){	
	printf("%.8e\n",adDists[j]); 
      }
    }
    
  }
  else{
    /* receive data*/
    adLookUp = (double *) malloc(N_BASES*N_BASES*sizeof(double));
    if(!adLookUp)
      goto memoryError;

    MPI_Bcast(adLookUp, N_BASES*N_BASES, MPI_DOUBLE, 0, MPI_COMM_WORLD);

    receiveData(&tData);

    nN = tData.nSeq; nM = tData.nMaxLen;
    
    nSize = (nN*(nN - 1))/2;
    
    nA = (int) floor(nSize / numtasks);

    nA0 = nA + (nSize % numtasks);

    adDists = (double *) malloc(nA*sizeof(double)); 
    if(!adDists)
      goto memoryError;

    nCount = 0; nStart = nA0 + (rank - 1)*nA; nFinish = nA0 + rank*nA;
    
    for(i = 0; i < nN; i++){
      for(j = 0; j < i; j++){

	if(nCount >= nStart){
	  double  dDist = needlemanWunsch(&tData.acSequences[i*nM], &tData.acSequences[j*nM],tData.anLen[i], tData.anLen[j], tData.nMaxLen);

	  adDists[nCount - nStart] = dDist;
	}	

  	nCount++;
	if(nCount == nFinish){
	    goto finish2;
	}
	
      }
    }
  
  finish2:
      
    nPackets = ((nA - 1)/MAX_PACKET_SIZE) + 1;
      
    nPacketCurr = 0;
    for(j = 0; j < nPackets; j++){
      if(j < nPackets - 1){
	nPacketSize = MAX_PACKET_SIZE;
      }
      else{
	nPacketSize = nA % MAX_PACKET_SIZE;
      }   

      //printf("Send %d %d %d\n",rank, nPacketCurr, nPacketSize);
      MPI_Send((void *) (&adDists[nPacketCurr]), nPacketSize, 
		 MPI_DOUBLE, 0, nTag, MPI_COMM_WORLD);
      nPacketCurr += nPacketSize;
    }

    if(nPacketCurr != nA){
      printf("Message error\n");
    }
  }
 
  /*free allocated memory*/
  free(adDists);
  free(tData.acSequences);
  free(tData.anLen);
  // Wait for everyone to stop   
  
  MPI_Barrier(MPI_COMM_WORLD);

  // Always use MPI_Finalize as the last instruction of the program

  MPI_Finalize();
  exit(EXIT_SUCCESS);

 memoryError:
  fprintf(stderr, "Failed allocating memory in main\n");
  fflush(stderr);
  exit(EXIT_FAILURE);
}