int compare_regions(void *region_1, void *region_2, char **chromosome_ordering, int num_chromosomes) { if (region_1 == NULL || region_2 == NULL) { return INT_MIN; } region_t *reg_1 = (region_t *) region_1; region_t *reg_2 = (region_t *) region_2; // TODO This could be avoided while inserting, because regions are classified by chromosome int result = compare_chromosomes(reg_1->chromosome, reg_2->chromosome, chromosome_ordering, num_chromosomes); if (result != 0) { return result; } else { // return compare_position_ranges(reg_1, reg_2); return compare_positions(reg_1->start_position, reg_2->start_position); } }
int merge_interval(kh_pos_t* positions_read, char *max_chromosome_merged, unsigned long max_position_merged, char **chromosome_order, int num_chromosomes, vcf_file_t **files, shared_options_data_t *shared_options_data, merge_options_data_t *options_data, list_t *output_list) { int num_entries = 0; #pragma omp parallel for num_threads(shared_options_data->num_threads) reduction(+:num_entries) for (int k = kh_begin(positions_read); k < kh_end(positions_read); k++) { if (kh_exist(positions_read, k)) { array_list_t *records_in_position = kh_value(positions_read, k); assert(records_in_position); vcf_record_t *record = ((vcf_record_file_link*) array_list_get(0, records_in_position))->record; vcf_record_file_link **links = NULL; int num_links = 0; // Remove positions prior to the last chromosome:position to merge int cmp_chrom = compare_chromosomes(record->chromosome, max_chromosome_merged, chromosome_order, num_chromosomes); if (cmp_chrom < 0 || (cmp_chrom == 0 && compare_positions(record->position, max_position_merged) <= 0)) { links = records_in_position->items; num_links = records_in_position->size; } // Launch merge if (num_links > 0) { // printf("links[0] = %s:%ld in file %s\n", links[0]->record->chromosome, links[0]->record->position, links[0]->file->filename); int err_code = 0; vcf_record_t *merged = merge_position(links, num_links, files, options_data->num_files, options_data, &err_code); if (!err_code) { list_item_t *item = list_item_new(k, MERGED_RECORD, merged); list_insert_item(item, output_list); num_entries += 1; } // Free empty nodes (lists of records in the same position) array_list_free(records_in_position, vcf_record_file_link_free); kh_del(pos, positions_read, k); } } // End kh_exist } return num_entries; }
void calculate_merge_interval(vcf_record_t* current_record, char** max_chromosome_merged, long unsigned int* max_position_merged, char **chromosome_order, int num_chromosomes) { if (*max_chromosome_merged == NULL) { // Max merged chrom:position not set, assign without any other consideration *max_chromosome_merged = strndup(current_record->chromosome, current_record->chromosome_len); *max_position_merged = current_record->position; } else { char *current_chromosome = strndup(current_record->chromosome, current_record->chromosome_len); long unsigned int current_position = current_record->position; // printf("current = %s:%ld\tmax = %s:%ld\n", current_chromosome, current_position, *max_chromosome_merged, *max_position_merged); int chrom_comparison = compare_chromosomes(current_chromosome, *max_chromosome_merged, chromosome_order, num_chromosomes); int position_comparison = compare_positions(current_position, *max_position_merged); // Max merged chrom:position is posterior to the last one in this batch if (chrom_comparison < 0 || (chrom_comparison == 0 && position_comparison < 0)) { *max_chromosome_merged = current_chromosome; *max_position_merged = current_position; } else { assert(current_chromosome); free(current_chromosome); } } }
int main(int argc, char ** argv){ MPI_Init(&argc,&argv); particle thing1,thing2; int nEach = 5; particle things1[nEach]; particle things2[nEach]; int i; MPI_Status status_ignore; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if(size != 1){ printf("%d/%d: too many processes\n", rank, size); MPI_Finalize(); return 1; } //MPI_Datatype MPI_particle; create_MPI_struct(&MPI_particle); MPI_Type_commit(&MPI_particle); double epsilon = DBL_EPSILON; double min = DBL_MIN; printf("epsilon = %g\n", epsilon); printf("dbl min = %g\n", min); for(i=0;i<nEach;i++){ basicParticle(things1+i); basicParticle(things2+i); } printf("things1 \n"); fprintParticles(stdout, things1,nEach); printf("things2 \n"); fprintParticles(stdout, things2,nEach); double diff, diffx, diffv, diffa; diff = compareMultipleParticles(things1, things2, nEach); printf("total diff of %d = %g\t expected 0\n", nEach, diff); diffx = compare_positions(things1, things2); printf("pos diff of %d = %g\t expected 0\n", 1, diffx); diffv = compare_positions(things1, things2); printf("vel diff of %d = %g\t expected 0\n", 1, diffv); diffa = compare_positions(things1, things2); printf("acc diff of %d = %g\t expected 0\n", 1, diffa); printf("\nchanging the values of stuff\n"); printf("0 and 1\t expected ~1/eps = %g\n",1/epsilon); things1[0].x = 0; things2[0].x = 1; diff = compareMultipleParticles(things1, things2, nEach); printf("total diff of %d = %g\n", nEach, diff); diffx = compare_positions(things1, things2); printf("pos diff of %d = %g\n", 1, diffx); printf("\n0 and dbl_min\t expected 0\n"); things1[0].x = 0; things2[0].x = min; diff = compareMultipleParticles(things1, things2, nEach); printf("total diff of %d = %g\n", nEach, diff); diffx = compare_positions(things1, things2); printf("pos diff of %d = %g\n", 1, diffx); printf("\n0 and eps\t expected 1/eps = %g\n", 1/epsilon); things2[0].x = epsilon; diff = compareMultipleParticles(things1, things2, nEach); printf("total diff of %d = %g\n", nEach, diff); diffx = compare_positions(things1, things2); printf("pos diff of %d = %g\n", 1, diffx); printf("\n1 and 1+eps\t expected 0\n"); things1[0].x = 1; things2[0].x = 1+ epsilon; diff = compareMultipleParticles(things1, things2, nEach); printf("total diff of %d = %g\n", nEach, diff); diffx = compare_positions(things1, things2); printf("pos diff of %d = %g\n", 1, diffx); printf("\n1^20 and 10^20+eps*10^20\t expected 0\n"); things1[0].x = 1E20; things2[0].x = 1E20 + 1E20 * epsilon; diff = compareMultipleParticles(things1, things2, nEach); printf("total diff of %d = %g\n", nEach, diff); diffx = compare_positions(things1, things2); printf("pos diff of %d = %g\n", 1, diffx); double y; printf("\ncomparing 1 and 1+y, expect eps*10\n"); things2[0].x = 1; for(y = 10;y>0;y*=0.5){ things1[0]. x = 1+y; diffx = compare_positions(things1, things2); if(diffx == 0){ printf("at y = %g, 1+y compares equal to 1\n", y); break; } } printf("\ncomparing 0 and y, expect min*10\n"); things2[0].x = 0; for(y = 10;y>0;y*=0.5){ things1[0]. x = y; diffx = compare_positions(things1, things2); if(diffx == 0){ printf("at y = %g, y compares equal to 0\n", y); break; } } printf("x position compared\n"); MPI_Type_free(&MPI_particle); MPI_Finalize(); return 0; }