Esempio n. 1
0
void output_matches (struct MATCH *matches, char *strand, char *id, int nrow, struct MOTIF *motif)
{
    int lowest_cutoff;
    struct MATCH *step;

    //'chr22',50427,50436,'GATA-1','+++',0.87,'$V_GATA-1_01'
    step = matches;
    while (step)
    {
    	lowest_cutoff = (int) ((floor ((step->lowest_score - motif->min) / ((float) (motif->max - motif->min)) * 100) / 100) * 1000);
	if (lowest_cutoff < 0)
	    lowest_cutoff = -1;        
	printf ("chr?	%d	%d	", step->pos, (step->pos + motif->len - 1));
	printf ("%s	%d	", motif->id, lowest_cutoff);
        print_strand (strand, step->dir, nrow);
     	putchar ('\n');
        step = step->next;
    }
//printf ("---NEXT---\n");
}   
Esempio n. 2
0
File: main.c Progetto: SunnyQ/cmu
int main(int argc, char **argv) {
  char *strandsFilePath = NULL;
  char *centroidsFilePath = NULL;
  int numStrands = -1;
  int numCentroids = -1;
  int lenStrand = -1;
  int opt, i, numItrs;
  double currTime, ioWallTime, kmeansWallTime;

  int numProcs, rank, namelen;
  char processor_name[MPI_MAX_PROCESSOR_NAME];

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
  MPI_Get_processor_name(processor_name, &namelen);

  while ((opt = getopt(argc, argv, "f:p:c:l:i:")) != -1) {
    switch (opt) {
      case 'f': 
        strandsFilePath = optarg;
        break;
      case 'i': 
        centroidsFilePath = optarg;
        break;
      case 'c': 
        numCentroids = atoi(optarg);
        break;
      case 'p': 
        numStrands = atoi(optarg);
        break;
      case 'l': 
        lenStrand = atof(optarg);
        break;
      case '?': 
        usage(argv[0]);
        break;
      default: 
        usage(argv[0]);
        break;
    }
  }

  if (strandsFilePath == NULL || 
      numStrands <= 0 ||
      numCentroids <= 0 || 
      lenStrand < 0) {
    usage(argv[0]);
    MPI_Finalize();
    exit(-1);
  }

  ioWallTime = get_curr_time();

  MPI_Barrier(MPI_COMM_WORLD);

  Strand *strands = NULL;
  Strand *centroids = NULL;
  char *strandsMem = NULL;
  char *centroidsMem = NULL;

  if (rank == 0) {

    // load strands 
    init_memory_space(&strands, &strandsMem, numStrands, lenStrand);

    int numStrandsLoaded = load_strands(strands, strandsFilePath, 
        numStrands, lenStrand);
    if (numStrandsLoaded != numStrands) {
      fprintf(stderr, "Error: could only load %d strands from sources\n", 
          numStrandsLoaded);
      MPI_Finalize();
      exit(-1);
    }

    // load or generate initial centroids
    init_memory_space(&centroids, &centroidsMem, numCentroids, lenStrand);
    
    if (centroidsFilePath != NULL) {  // load centroids from given file
      int numCentroidsLoaded = load_strands(centroids, centroidsFilePath, 
          numCentroids, lenStrand);
      if (numCentroidsLoaded != numCentroids) {
        fprintf(stderr, "Error: could only load %d centroids from sources\n",
            numCentroidsLoaded);
        MPI_Finalize();
        exit(-1);
      }
    } else {  // randomly choose centroids
      random_choose_centroids(strands, centroids, 
        numStrands, numCentroids, lenStrand);
    }

    // distributed strands 
    numStrands = distribute_strands(strands, numStrands, lenStrand,
        numProcs, MPI_COMM_WORLD);

    // destroy distributed strands
    strandsMem = realloc(strandsMem, numStrands * lenStrand * sizeof(char));
    assert(strandsMem != NULL);
    strands = realloc(strands, numStrands * sizeof(Strand));
    assert(strands != NULL);

  } else {

    numStrands = get_portion_size(numStrands, numProcs, rank);

    // receive strands 
    init_memory_space(&strands, &strandsMem, numStrands, lenStrand);

    int numStrandsReceived = receive_strands(strands, numStrands, lenStrand,
        rank, MPI_COMM_WORLD);

    if (numStrandsReceived != numStrands) {
      fprintf(stderr, "Error: could only receive %d strands from root\n", 
          numStrandsReceived);
      MPI_Finalize();
      exit(-1);
    }

    // load or generate initial centroids
    init_memory_space(&centroids, &centroidsMem, numCentroids, lenStrand);
  }

  currTime = get_curr_time();
  ioWallTime = currTime - ioWallTime;

  kmeansWallTime = get_curr_time();

  // broadcast centroids
  MPI_Bcast(centroidsMem, numCentroids * lenStrand, MPI_CHAR, 0, MPI_COMM_WORLD);

  numItrs = do_kmeans(strands, centroids, 
      numStrands, numCentroids, lenStrand,
      rank, MPI_COMM_WORLD);

  currTime = get_curr_time();
  kmeansWallTime = currTime - kmeansWallTime;

  if (rank == 0) {
    printf("========================================\n");
    printf("Number of Iterations: %d\n", numItrs);
    printf("========================================\n");
    printf("K-Means Centroids: \n");
    for (i = 0; i < numCentroids; i++) {
      print_strand(centroids[i], lenStrand);
    }
    printf("========================================\n");
    printf("IO wall time: \t\t%10.4f sec\n", ioWallTime);
    printf("KMeans wall time: \t%10.4f sec\n", kmeansWallTime);
    printf("Total wall time: \t%10.4f sec\n", (kmeansWallTime + ioWallTime));
    printf("========================================\n");
  }

  free(centroidsMem);
  free(centroids);
  free(strandsMem);
  free(strands);
  MPI_Finalize();
  return 0;
}