int main(int argc, char *argv[]) { int initialize_flag; char config_value[255]; int i; int total_lanes; char acqcfgpath[127]; char command_buffer[255]; char base_dir[255]; sprintf(base_dir, "%s/polonator/G.007/acquisition", getenv("HOME")); sprintf(log_dir, "%s/logs", base_dir); sprintf(command_buffer, "mkdir -p %s", log_dir); system(command_buffer); if(argc == 3){ initialize_flag = atoi(argv[2]); } else{ initialize_flag = 0; } fprintf(stdout, "the initialize flag is %d\n", initialize_flag); /* Open config file */ strcpy(acqcfgpath, getenv("POLONATOR_PATH")); strcat(acqcfgpath, "/config_files/polonator-acq.cfg"); config_open(acqcfgpath); if(!config_getvalue("stagealign_wells_per_fc", config_value)){ p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_wells_per_fc) returned no value"); exit(0); } total_lanes = atoi(config_value); if(!config_getvalue("stagealign_outputdir", config_value)){ p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_outputdir) returned no value"); exit(0); } strcpy(output_directory, base_dir); strcat(output_directory, "/"); strcat(output_directory, config_value); config_close(); fprintf(stdout, "=%s=\n", output_directory); /* Make sure stagealign output directory exists */ mkdir(output_directory, S_IRWXU); sprintf(log_string, "Create new directory %s :", output_directory); p_log_simple(log_string); for(i = 0; i < total_lanes; i++) { stagealign(atoi(argv[1]), i, initialize_flag); } return 0; }
void stagealign(int fcnum, int lane_num, int initialize) { short unsigned int *testimage; short unsigned int *baseimage; FILE *baseimgfp; FILE *offsetfp; /* used to dump score matrix to file when debugging */ FILE *score_matrixfp; /* Maestro declarations */ int m_sock; /* socket for the Maestro controller */ char config_value[255]; char logfilename[255]; char offsetfilename[255]; char stagealign_baseimgfilename[255]; char acqcfgpath[255]; /* Used to send commands and receive responses from Maestro */ char command[255]; char response[255]; int response_length; /* Image acquisition settings, populated from config file */ int stagealign_integration_inmsec; int stagealign_gain; int stagealign_well; int stagealign_wells_per_fc; /* Values used for conversion between pixels and stage units */ int stagealign_optical_mag; int ccd_pixel_size; double pixelsize_at_stage; /* size of a pixel at the stage in microns */ /* Hold offsets found by alignment in pixels and stageunits */ int pixel_offset_x, pixel_offset_y; double stageunit_offset_x, stageunit_offset_y; int lane_index; /* Holds previous offsets from controller in case the alignment doesn't work */ int curr_offset_x, curr_offset_y; /* Holds encoder resolutions from controller, used for calculating distance of move */ double encoder_res_X, encoder_res_Y; /* 'score' of best alignment */ int score; /* Largest pixel offset allowable _after_ the adjustment has been made */ /* if there is still a shift larger than this, conclude something is wrong */ /* and go back to the previous offset */ int successful_move_threshold = 150; /*RCT was = 12*/ int i; /* in debugging mode, dump internal data to files */ #ifdef DEBUG_STAGEALIGN FILE *imgfp; sprintf(command, "%s/stagealign-image%d_%d.raw", output_directory, fcnum, lane_num); imgfp = fopen(command, "w"); sprintf(command, "%s/stagealign-scorematrix%d_%d", output_directory, fcnum, lane_num); score_matrixfp = fopen(command, "w"); #endif p_log_simple("awesome2\n"); /* Open config file */ strcpy(acqcfgpath, getenv("POLONATOR_PATH")); strcat(acqcfgpath, "/config_files/polonator-acq.cfg"); config_open(acqcfgpath); p_log_simple("awesome1\n"); /* Initialize variables */ if(!config_getvalue("stagealign_logfilename", config_value)){ fprintf(stderr, "ERROR:\tPolonator-stagealign: config_getval(key logfilename) returned no value\n"); exit(0); } p_log_simple("awesome0\n"); strcpy(logfilename, log_dir); strcat(logfilename, "/"); strcat(logfilename, config_value); sprintf(command, "%d", fcnum); strcat(logfilename, command); strcat(logfilename, ".log"); p_log_simple(logfilename); start_logger(logfilename, 1); strcpy(offsetfilename, log_dir); strcat(offsetfilename, "/"); strcat(offsetfilename, config_value); strcat(offsetfilename, command); strcat(offsetfilename, ".offsetlog"); fprintf(stdout, offsetfilename); fflush(stdout); /* if this is being run in 'initialize mode' -- the first scan of a run -- overwrite the offset logfile */ p_log_simple("awesome66\n"); if(initialize){ offsetfp = fopen(offsetfilename, "w"); } else{ offsetfp = fopen(offsetfilename, "a"); } p_log_simple("awesome00\n"); if(!config_getvalue("stagealign_baseimgfilename", config_value)){ p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_baseimgfilename) returned no value"); exit(0); } sprintf(stagealign_baseimgfilename, "%s/%s%s_%d.raw", output_directory, config_value, command, lane_num); p_log_simple("awesome01\n"); if(!config_getvalue("stagealign_integration_inmsec", config_value)){ p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_integration_inmsec) returned no value"); exit(0); } stagealign_integration_inmsec = atoi(config_value); p_log_simple("awesome02\n"); if(!config_getvalue("stagealign_gain", config_value)){ p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_gain) returned no value"); exit(0); } stagealign_gain = atoi(config_value); p_log_simple("awesome03\n"); if(!config_getvalue("stagealign_optical_mag", config_value)){ p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_optical_mag) returned no value"); exit(0); } stagealign_optical_mag = atoi(config_value); p_log_simple("awesome04\n"); if(!config_getvalue("stagealign_ccd_pixel_size", config_value)){ p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_ccd_pixel_size) returned no value"); exit(0); } ccd_pixel_size = atoi(config_value); p_log_simple("awesome05\n"); if(!config_getvalue("stagealign_wells_per_fc", config_value)){ p_log("ERROR:\tPolonator-stagealign: config_getval(key stagealign_wells_per_fc) returned no value"); exit(0); } stagealign_wells_per_fc = atoi(config_value); config_close(); p_log_simple("awesome06\n"); stagealign_well = lane_num; lane_index = (fcnum * stagealign_wells_per_fc) + stagealign_well; baseimage = (short unsigned int*)malloc(1000000 * sizeof(short unsigned int)); /*-------------------------------------------------------------------------- // // MAESTRO SETUP /*/ p_log_simple("STATUS:\tPolonator-stagealign: Opening connection to Maestro..."); maestro_open(&m_sock); /* //-------------------------------------------------------------------------- */ /*-------------------------------------------------------------------------- // // CAMERA SETUP /*/ p_log_simple("STATUS:\tPolonator-stagealign: Opening camera handle..."); py_cameraInit(0); /* use non-TDI config file */ py_set_gain(stagealign_gain); py_setupSnap(); /* setup capture software to wait for images from camera */ /* //-------------------------------------------------------------------------- */ /*p_log("STATUS:\tPolonator-stagealign: Darkfield illuminator on..."); rolony*/ /*maestro_darkfield_on(m_sock); p_log("STATUS:\tPolonator-stagealign: Select darkfield filter block..."); rolony*/ maestro_setcolor(m_sock, "cy5"); /* IF INITIALIZING, RESET OFFSETS */ if(initialize){ p_log_simple("INITIALIZING STAGEALIGN"); sprintf(command, "PolonatorScan.OFFSET_X[%d]=0\n\r", lane_index); p_log_simple(command); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); p_log_simple(response); sprintf(command, "PolonatorScan.OFFSET_Y[%d]=0\n\r", lane_index); p_log_simple(command); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); p_log_simple(response); } /* GET OFFSETS IN CASE ALIGNMENT FAILS */ else{ p_log_simple("Storing current offsets..."); sprintf(command, "PolonatorScan.OFFSET_X[%d]\n\r", lane_index); p_log_simple(command); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); p_log_simple(response); curr_offset_x = atoi(response); sprintf(command, "PolonatorScan.OFFSET_Y[%d]\n\r", lane_index); p_log_simple(command); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); p_log_simple(response); curr_offset_y = atoi(response); } /* MOVE STAGE TO ORIGIN */ maestro_gotostagealign_position(m_sock, fcnum, lane_num); p_log_simple("awesome fool00\n"); /* ACQUIRE IMAGE */ p_log("STATUS:\tPolonator-stagealign: Acquire image..."); maestro_snap(m_sock, stagealign_integration_inmsec, 1); /*rolony*/ while(!py_snapReceived()){;} testimage = py_getSnapImage(); /* IF INITIALIZING, RE-WRITE THE BASE IMAGE; THE OFFSET FOUND SHOULD BE ZERO */ p_log_simple(stagealign_baseimgfilename); if(initialize){ baseimgfp = fopen(stagealign_baseimgfilename, "w"); fwrite(testimage, 1000000, sizeof(short unsigned int), baseimgfp); fclose(baseimgfp); } p_log_simple("awesome fool01\n"); #ifdef DEBUG_STAGEALIGN fwrite(testimage, 1000000, sizeof(short unsigned int), imgfp); #endif /* LOAD BASE IMAGE */ p_log("STATUS:\tPolonator-stagealign: Load base image and determine offset..."); baseimgfp = fopen(stagealign_baseimgfilename, "r"); fread(baseimage, 1000000, sizeof(short unsigned int), baseimgfp); fclose(baseimgfp); p_log("STATUS:\tPolonator-stagealign: Load base image and determine offset2..."); /* DETERMINE OFFSETS */ register_image(baseimage, testimage, &pixel_offset_x, &pixel_offset_y, &score, score_matrixfp); sprintf(log_string, "STATUS:\tPolonator-stagealign: Found pixel offsets X:%d, Y:%d, score:%d", pixel_offset_x, pixel_offset_y, score); p_log(log_string); /* LOAD ENCODER RESOLUTIONS FOR CONVERSION BELOW; THESE ARE STORED ON */ /* THE CONTROLLER AS COUNTS PER MILLIMETER */ p_log("Retrieving encoder resolutions..."); sprintf(command, "PolonatorScan.cENCODER_X_RESOLUTION\n\r"); p_log(command); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); p_log(response); encoder_res_X = atof(response); sprintf(command, "PolonatorScan.cENCODER_Y_RESOLUTION\n\r"); p_log(command); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); p_log(response); encoder_res_Y = atof(response); /* CONVERT FROM PIXELS TO STAGE UNITS */ /* CALCULATE PIXEL SIZE IN MILLIMTERS AT THE STAGE BASED */ /* ON THE MAGNIFICATION AND THE CCD PIXEL SIZE */ pixelsize_at_stage = ((double)ccd_pixel_size / (double)stagealign_optical_mag) / 1000; stageunit_offset_x = (double)pixel_offset_x * pixelsize_at_stage * encoder_res_X * -1; stageunit_offset_y = (double)pixel_offset_y * pixelsize_at_stage * encoder_res_Y * -1; /* SET NEW OFFSETS ON CONTROLLER USING VALUES */ /* CALCULATED ABOVE */ sprintf(command, "PolonatorScan.OFFSET_X[%d]\n\r", lane_index); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); fprintf(offsetfp, "%d\t%d\t", fcnum, stagealign_well); fprintf(offsetfp, "%d\t", atoi(response)); sprintf(command, "PolonatorScan.OFFSET_Y[%d]\n\r", lane_index); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); fprintf(offsetfp, "%d\t", atoi(response)); fprintf(offsetfp, "%d\t%d\t%d\t%d\t", (int)stageunit_offset_x, (int)stageunit_offset_y, pixel_offset_x, pixel_offset_y); /* ISSUE COMMANDS TO ADJUST STAGE COORDS */ p_log("STATUS:\tPolonator-stagealign: Set offset variables on Maestro..."); sprintf(command, "PolonatorScan.OFFSET_X[%d]=PolonatorScan.OFFSET_X[%d]+%d\n\r", lane_index, lane_index, (int)stageunit_offset_x); p_log(command); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); p_log(response); sprintf(command, "PolonatorScan.OFFSET_Y[%d]=PolonatorScan.OFFSET_Y[%d]+%d\n\r", lane_index, lane_index, (int)stageunit_offset_y); p_log(command); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); p_log(response); /* MOVE, THEN ACQUIRE ANOTHER IMAGE TO VERIFY OFFSET WORKED */ /* maestro_gotostagealign_position(m_sock, fcnum, lane_num); maestro_snap(m_sock, stagealign_integration_inmsec, 0); while(!py_snapReceived()){;} testimage = py_getSnapImage(); */ #ifdef DEBUG_STAGEALIGN fwrite(testimage, 1000000, sizeof(short unsigned int), imgfp); fclose(imgfp); #endif /* DETERMINE OFFSET TO CONFIRM */ /* p_log("STATUS:\tPolonator-stagealign: Re-compute alignment to verify move..."); register_image(baseimage, testimage, &pixel_offset_x, &pixel_offset_y, &score, score_matrixfp); sprintf(log_string, "STATUS:\tPolonator-stagealign: Found pixel offsets X:%d, Y:%d, score:%d", pixel_offset_x, pixel_offset_y, score); p_log(log_string); fprintf(offsetfp, "%d\t%d", pixel_offset_x, pixel_offset_y); */ /* DID THE MOVE WORK? */ if(((abs(pixel_offset_x)>successful_move_threshold) || (abs(pixel_offset_y)>successful_move_threshold)) && (!initialize)) { sprintf(log_string, "ERROR:\tPolonator-stagealign: one or more offsets are greater that the %d-pixel maximum; X:%d, Y:%d", successful_move_threshold, pixel_offset_x, pixel_offset_y); p_log(log_string); fprintf(offsetfp, "*"); /* mark current line in offsetlog, since offsets found will not be the offsets stored on the controller */ sprintf(log_string, "Restoring previous offsets X:%d, Y:%d", curr_offset_x, curr_offset_y); sprintf(command, "PolonatorScan.OFFSET_X[%d]=%d\n\r", lane_index, curr_offset_x); p_log(command); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); p_log(response); sprintf(command, "PolonatorScan.OFFSET_Y[%d]=%d\n\r", lane_index, curr_offset_y); p_log(command); send(m_sock, command, strlen(command), 0); maestro_readresponse(m_sock, response, &response_length); p_log(response); } /* EXIT */ #ifdef DEBUG_STAGEALIGN fclose(score_matrixfp); #endif fprintf(offsetfp, "\n"); fclose(offsetfp); /*maestro_darkfield_off(m_sock); rolony*/ py_cameraClose(); free(baseimage); close_logger(); p_log_simple("awesome fool02\n"); }
int run_autoexp(char *argv, int cell_num) { FILE *full_pix_list; FILE *regpixfile; FILE *beadfile; FILE *sumfile; FILE *imgsumfile; FILE *reglogfile; FILE *bead_value_file; FILE *bead_sum_file; short unsigned int *reg_pix_list_xcols; short unsigned int *reg_pix_list_yrows; short unsigned int *beadvals; int fcnum =0; fpos_t pix_list_offset; int reg_X_pointer_offset; int reg_Y_pointer_offset; int portnum;// = atoi(argv[2]); char filename[255]; char autoefilename[255]; char autoefilename2[255]; char rcvfilename[255]; char posfilename[200]; char reglogfilename[200]; char temp_string[255]; char log_string[255]; char outputfilename[500]; int num_regs_skipped; int num_fcs; int i; int h =0; start_logger((char*)DEFAULT_PROCESSOR_LOGFILENAME, 1); strcpy(posfilename, "autoexp_pos"); portnum = PORTNUM; num_fcs = cell_num; p_log((char*)"processor:\tAllocating memory for arrays ..."); if( (reg_pix_list_xcols=(short unsigned int*)malloc(REG_PIXELS*ARRAYS_PER_FC*15*sizeof(short unsigned int))) == NULL) { p_log((char*)"malloc() for reg_pixel_list_xcols failed..."); } if( (reg_pix_list_yrows=(short unsigned int*)malloc(REG_PIXELS*ARRAYS_PER_FC*15*sizeof(short unsigned int))) == NULL) { p_log((char*)"malloc() for reg_pixel_list_yrows failed..."); } if((beadvals=(short unsigned int*)malloc(MAX_BEADS_PERFRAME*sizeof(short unsigned int))) == NULL) { p_log((char*)"malloc() for beadvals failed..."); } memset(&pix_list_offset, 0, sizeof(pix_list_offset)); if( (full_pix_list = fopen(posfilename, "r")) == NULL) { sprintf(log_string, "ERROR opening pixel list file %s", posfilename); p_log(log_string); perror(NULL); return 1; } strcat(posfilename, ".reg"); if( (regpixfile = fopen(posfilename, "r")) == NULL) { sprintf(log_string, "ERROR opening reg pixel list file %s", posfilename); p_log(log_string); exit(0); } //LOAD REGISTRATION PIXEL LIST INTO MEMORY //IF A SET OF COORDS IS WITHIN THE BORDER //OF THE IMAGE (SIZE SPECIFIED BY SEARCH_XCOLS //AND SEARCH_YROWS, DO NOT USE THAT POINT -- INSTEAD, //USE THE PREVIOUS POINT num_regs_skipped=0; sprintf(log_string, "processor:\tLoading regpix file %s ...", posfilename); p_log(log_string); sprintf(log_string, "processor:\tautoe %s ...", posfilename); p_log(log_string); for(i=0; i<(REG_PIXELS*ARRAYS_PER_FC*15); i++) { if((fread(reg_pix_list_xcols+i, 2, 1, regpixfile)) < 1) { sprintf(log_string, "ERROR reading from file regpix_list at data element %d", i); p_log_errorno(log_string); exit(0); } if((fread(reg_pix_list_yrows+i, 2, 1, regpixfile)) < 1) { sprintf(log_string, "ERROR reading from file regpix_list at data element %d", i); p_log_errorno(log_string); exit(0); } if( (*(reg_pix_list_xcols+i) <= (SEARCH_XCOLS+MAX_ADDITIONAL_OFFSET+1)) || (*(reg_pix_list_yrows+i) <= (SEARCH_YROWS+MAX_ADDITIONAL_OFFSET+1)) || ((NUM_XCOLS - *(reg_pix_list_xcols+i)) <= (SEARCH_XCOLS+MAX_ADDITIONAL_OFFSET+1)) || ((NUM_YROWS - *(reg_pix_list_yrows+i)) <= (SEARCH_YROWS+MAX_ADDITIONAL_OFFSET+1))) { num_regs_skipped++; if(i==0) { *(reg_pix_list_xcols + i) = (int)(NUM_XCOLS/2); *(reg_pix_list_yrows + i) = (int)(NUM_YROWS/2); } else { *(reg_pix_list_xcols + i) = *(reg_pix_list_xcols + i - 1); *(reg_pix_list_yrows + i) = *(reg_pix_list_yrows + i - 1); } } // end if } // end for fclose(regpixfile); /* int percentage_skipped = (int)( ((float)(num_regs_skipped) / (REG_PIXELS)) * 100);*/ int percentage_skipped = num_regs_skipped*100.0 / (15*ARRAYS_PER_FC*REG_PIXELS); int avg_regpix_perframe = REG_PIXELS - (int)( ((float)(percentage_skipped)/100) * REG_PIXELS); sprintf(log_string, "processor:\tSkipped %d reg coords (%d%%), using avg of %d/%d reg pixels at window size %d/%d ...", num_regs_skipped, percentage_skipped, avg_regpix_perframe, REG_PIXELS, SEARCH_XCOLS, SEARCH_YROWS); p_log(log_string); ReceiveFilename(argv, portnum, rcvfilename); /* p_log((char*)"processor:\tRequesting flowcell number from server ..."); fcnum = ReceiveFCNum(argv[1], portnum); */ strcpy(filename, "autoexp_images/beads/"); sprintf(temp_string, "%d_", fcnum); strcat(filename, temp_string); strcat(filename, rcvfilename); #ifdef SAVE_FL_IMAGES strcpy(CYCLE_NAME, temp_string); strcpy(CYCLE_NAME, rcvfilename); #endif sprintf(log_string, "processor:\tReceived filename %s from server ...", rcvfilename); p_log(log_string); sprintf(temp_string, "autoexp_images/logs/%s.processorlog", rcvfilename); change_logfile(temp_string); p_log(log_string); strcat(filename, ".beads"); if( (beadfile = fopen(filename, "wb")) == NULL) { sprintf(log_string, "ERROR opening output bead file %s", filename); p_log_errorno(log_string); exit(0); } strcpy(autoefilename, "autoexp_images/"); strcat(autoefilename,CYCLE_NAME); strcat(autoefilename,"_bead_value_file.txt"); if( (bead_value_file = fopen(autoefilename, "w")) == NULL) { sprintf(log_string, "ERROR opening output bead file %s", filename); p_log_errorno(log_string); exit(0); } strcpy(autoefilename2, "autoexp_images/"); strcat(autoefilename2,CYCLE_NAME); strcat(autoefilename2,"_bead_sum_file.txt"); if( (bead_sum_file = fopen(autoefilename2, "w")) == NULL) { sprintf(log_string, "ERROR opening output bead file %s", filename); p_log_errorno(log_string); exit(0); } sprintf(temp_string, "autoexp_images/logs/%d_", fcnum); strcpy(reglogfilename, temp_string); strcat(reglogfilename, rcvfilename); strcat(reglogfilename, ".register-log"); if( (reglogfile = fopen(reglogfilename, "wb")) == NULL) { sprintf(log_string, "ERROR opening output reglog file %s", reglogfilename); p_log_errorno(log_string); exit(0); } sprintf(log_string, "processor:\tRequesting data from server for file %s ...", filename); p_log(log_string); strcat(filename, "ums"); if( (sumfile = fopen(filename, "wb")) == NULL) { sprintf(log_string, "ERROR opening output sum file %s", filename); p_log_errorno(log_string); exit(0); } strcat(filename, "_full"); if( (imgsumfile = fopen(filename, "wb")) == NULL) { sprintf(log_string, "ERROR opening output imgsum file %s", filename); p_log_errorno(log_string); exit(0); } // seek to correct place in object table, and advance pointer to // correct place in reg object table if(fcnum == 0) { // fcnum is either 0 or 1 // seek to start of object table file if(fseek(full_pix_list, 0, SEEK_SET)!=0) { p_log_errorno((char*)"ERROR "); } // set reg pointer offsets reg_X_pointer_offset = 0; reg_Y_pointer_offset = 0; } else { // seek to position in object table where the current flowcell starts // we know where to go because the last time through the loop when we // were on FC0, we recorded the position after ReceiveData finished fsetpos(full_pix_list, &pix_list_offset); // set reg pointer offsets reg_X_pointer_offset = 0; reg_Y_pointer_offset = 0; } p_log((char*)"READY TO RECEIVE IMAGE DATA"); ReceiveData_new(argv, portnum, reg_pix_list_xcols + reg_X_pointer_offset, reg_pix_list_yrows + reg_Y_pointer_offset, full_pix_list, beadvals, beadfile, sumfile, imgsumfile, reglogfile,bead_value_file,bead_sum_file, fcnum, pix_list_offset); // remember position in object table so we can get back later if(fcnum == 0) { fgetpos(full_pix_list, &pix_list_offset); } fclose(beadfile); fclose(sumfile); fclose(imgsumfile); fclose(reglogfile); fclose(bead_value_file); fclose(bead_sum_file); change_logfile((char*)DEFAULT_PROCESSOR_LOGFILENAME); p_log_simple((char*)"processor:\tAutoexposure exited; waiting before attempting to reconnect..."); sleep(10); fclose(full_pix_list); } // end function
// RETURN 1 ON SUCCESS, // -1 ON MISSING IMAGE int ProcessImage(short unsigned int *reg_pix_list_xcols, short unsigned int *reg_pix_list_yrows, FILE *full_pixel_list, short unsigned int *image, short unsigned int *image_info, short unsigned int *beadvals, FILE *beadfile, FILE *sumfile, FILE *imgsumfile, FILE *reglogfile, int *offsetx_history, int *offsety_history){ // IMAGE INFO VARIABLES int curr_imgnum; int curr_arraynum; int curr_fcnum; // REGISTRATION VARIABLES int reg_pointer_offset; int offset_xcols; int offset_yrows; int score; // BEAD VARIABLES short unsigned int num_beads; // number of beads in current frame int i; double *temp_img; //gets sorted to find median pixel val short unsigned int *temp_img2; //bg subtracted image passed to register int percentile_val; int temp_val; unsigned long long int beadsum; unsigned long long int imgsum; int index; char log_string[255]; // ALLOCATE MEMORY if((temp_img = (double*)malloc((NUM_XCOLS*NUM_YROWS) * sizeof(double)))==NULL){ p_log_errorno((char*)"ERROR:\tProcessImage memory allocation failed (double *temp_img)"); exit(1); } if((temp_img2 = (short unsigned int*)malloc((NUM_XCOLS*NUM_YROWS) * sizeof(short unsigned int)))==NULL){ p_log_errorno((char*)"ERROR:\tProcessImage memory allocation failed (short unsigned int *temp_img2)"); exit(1); } // PARSE IMAGE INFO FIELDS curr_imgnum = (int)(*(image_info + 2)); curr_arraynum = (int)(*(image_info + 1)); curr_fcnum = (int)(*(image_info + 0)); // ERROR WITH CURRENT IMAGE; PROBABLY FAILURE TO ACQUIRE if(*(image_info + 3) == 1){ sprintf(log_string, "ERROR:\tProcessImage: image header indicates problem with image %d %d %d", curr_fcnum, curr_arraynum, curr_imgnum); p_log(log_string); } // UPDATE POINTER TO CURRENT POSITION IN REG_PIXEL_LIST reg_pointer_offset = ((curr_fcnum * ARRAYS_PER_FC * IMGS_PER_ARRAY) + (curr_arraynum * IMGS_PER_ARRAY) + curr_imgnum); reg_pointer_offset = reg_pointer_offset * REG_PIXELS; sprintf(log_string, "STATUS:\tProcessImage: started operating on image %d, array %d, fc %d", curr_imgnum, curr_arraynum, curr_fcnum); p_log_simple(log_string); #ifdef DEBUG1 p_log((char*)"STATUS:\tProcessImage: calling ProcessImage_register"); //sprintf(log_string, "STATUS:\tProcessImage: seek to position %ld", reg_pointer_offset); sprintf(log_string, "STATUS:\tProcessImage: seek to position %d", reg_pointer_offset); p_log(log_string); #endif // BACKGROUND SUBTRACT IMAGE FOR REGISTRATION index=0; for(i=0; i<1000000; i+=135){ temp_img[index] = (double)*(image + i); index++; } quickSort(temp_img, index); percentile_val = (int)temp_img[index-(int)((double)index*0.9)]; for(i=0; i<1000000; i++){ temp_val = (int)*(image+i) - percentile_val; if(temp_val<0){ temp_img2[i]=0; } else{ temp_img2[i] = (short unsigned int)temp_val; } } // Added to correct offset history for discontinuous image tracking. if((curr_imgnum)%218==0){ p_log((char*)"STATUS:\tProcessImage: RESET HISTORY"); for(i=0; i<OFFSET_HISTORY_LENGTH; i++){ *(offsetx_history + i) = 0; *(offsety_history + i) = 0; } } // REGISTER IMAGE WITH 'BEAD PIXELS' FROM MASK IMAGE ProcessImage_register(reg_pix_list_xcols, reg_pix_list_yrows, //image, temp_img2, reg_pointer_offset, REG_PIXELS, SEARCH_XCOLS, SEARCH_YROWS, &offset_xcols, &offset_yrows, &score, *(image_info+3), reglogfile, offsetx_history, offsety_history); //fprintf(reglogfile, "=%d\t%d\t%d\t%d\t%d\n", curr_arraynum, curr_imgnum, offset_xcols, offset_yrows, score); #ifdef DEBUG1 sprintf(log_string, "STATUS:\tProcessImage: calling ProcessImage_extract w/ offsets %d %d", offset_xcols, offset_yrows); p_log(log_string); #endif // PULL 'BEAD PIXELS' FROM IMAGE USING FULL MASK ON DISK ProcessImage_extract(image, offset_xcols, offset_yrows, *(image_info+3), full_pixel_list, curr_imgnum, curr_arraynum, curr_fcnum, &num_beads, beadvals, &beadsum); #ifdef DEBUG1 p_log((char*)"STATUS:\tProcessImage: writing output to files"); #endif if(fwrite(beadvals, sizeof(short unsigned int), num_beads, beadfile) < num_beads){ p_log_errorno((char*)"ERROR:\tProcessImage: write to bead file failed"); exit(1); } if(fwrite(&beadsum, sizeof(long long int), 1, sumfile) < 1){ p_log_errorno((char*)"ERROR:\tProcessImage: write to sum file failed"); exit(1); } imgsum=0; for(i=0; i<100000; i+=100){ imgsum+=*(image+i); } if(fwrite(&imgsum, sizeof(long long int), 1, imgsumfile) < 1){ p_log_errorno((char*)"ERROR:\tProcessImage: write to imgsum file failed"); exit(1); } free(temp_img); free(temp_img2); #ifdef DEBUG1 p_log_simple((char*)"STATUS:\tProcessImage: finished image"); #endif } // end function
int main(int argc, char *argv[]){ FILE *posfile; FILE *cy3_posfile; FILE *fam_posfile; FILE *txred_posfile; FILE *final_posfile; FILE *obj_logfile; FILE *infofile; fpos_t offsetval; char regfilename[200]; char logfilename[200]; char log_string[500]; char info_filename[200]; int i, j, k, l,m,n,o,convert,sconvert, object_count; int curr_fc, curr_array, curr_img; int num_fcs; int cy5_proceed, cy3_proceed, txred_proceed,fam_proceed; long long int found_object = 0; long long int total_object = 0; int curr_numobjs,cy3_curr_numobjs,txred_curr_numobjs,fam_curr_numobjs, max_curr_numobjs = 0; int **objects_array; int p,q; short unsigned int cy5_x,cy3_x,cy3_y,txred_x,txred_y,fam_x,fam_y,cy5_y; short unsigned int *curr_img_x; short unsigned int *curr_img_y; short unsigned int *regindices; short unsigned int temp; start_logger((char*)"initialize_processor-log", 1); system("rm 00_*.info"); system("rm autoexp_pos.info"); objects_array = (int**) malloc(sizeof(int) * 4000); for (i = 0; i < 2000; i++) { objects_array[i] = (int*) malloc(sizeof(int) * 2000); } for(p=0;p<2000;p++){ for(q=0;q<2000;q++){ objects_array[p][q] = -1; } } if((curr_img_x = (short unsigned int*) malloc(MAX_BEADS_PERFRAME * sizeof(short unsigned int))) == NULL){ p_log_errorno((char*)"ERROR allocating memory for curr_img_x"); exit(0); } if((curr_img_y = (short unsigned int*) malloc(MAX_BEADS_PERFRAME * sizeof(short unsigned int))) == NULL){ p_log_errorno((char*)"ERROR allocating memory for curr_img_y"); exit(0); } if( (obj_logfile=fopen("merge.log", "w")) == NULL){ sprintf(log_string, "ERROR opening reglog file %s for output", argv[2]); p_log_errorno(log_string); exit(0); } if((cy3_posfile=fopen("00_cy3", "rb")) == NULL){ sprintf(log_string, "ERROR opening position file %s for input", "cy3"); p_log_errorno(log_string); exit(0); } if( (txred_posfile=fopen("00_txr", "rb")) == NULL){ sprintf(log_string, "ERROR opening position file %s for input", "txred"); p_log_errorno(log_string); exit(0); } if( (fam_posfile=fopen("00_fam", "rb")) == NULL){ sprintf(log_string, "ERROR opening position file %s for input", "fam"); p_log_errorno(log_string); exit(0); } if( (posfile=fopen("00_cy5", "rb")) == NULL){ sprintf(log_string, "ERROR opening position file %s for input", "cy5"); p_log_errorno(log_string); exit(0); } if( (final_posfile=fopen(argv[1], "wb")) == NULL){ sprintf(log_string, "ERROR opening position file %s for input", argv[1]); p_log_errorno(log_string); exit(0); } strcpy(info_filename,argv[1]); strcat(info_filename,".info"); if( (infofile=fopen(info_filename, "wb")) == NULL){ sprintf(log_string, "ERROR opening reg file %s for output", info_filename); p_log_errorno(log_string); exit(0); } // loop through FC, ARRAY, IMAGE: for(i=0; i<1; i++){ for(j=0; j<ARRAYS_PER_FC; j++){ for(k=0; k<IMGS_PER_ARRAY; k++){ // load positions for current image // ------ // each 'record' in the pos file is as follows: // 4 bytes: -1 // 4 bytes: flowcell # ([0..num_fcs]) // 4 bytes: array # ([0..ARRAYS_PER_FC]) // 4 bytes: image # ([0..IMGS_PER_ARRAY]) // 4 bytes: # of beads // 2 bytes: beadpos_xcol // 2 bytes: beadpos_yrow // ... // 2 bytes: 0 // // ------ if( (fread(&curr_fc, sizeof(int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(1) from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(2) from posfile"); } if( (fread(&curr_array, sizeof(int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_array from posfile"); } if( (fread(&curr_img, sizeof(int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if( (fread(&curr_numobjs, sizeof(int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_numobjs from posfile"); } /* sprintf(log_string, "flowcell %d, curr_array %d, curr_img %d",curr_fc, curr_array, curr_img); p_log(log_string); */ if( (fread(&curr_fc, sizeof(int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(1) from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(2) from posfile"); } if( (fread(&curr_array, sizeof(int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_array from posfile"); } if( (fread(&curr_img, sizeof(int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(1) from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(2) from posfile"); } if( (fread(&curr_array, sizeof(int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_array from posfile"); } if( (fread(&curr_img, sizeof(int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(1) from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(2) from posfile"); } if( (fread(&curr_array, sizeof(int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_array from posfile"); } if( (fread(&curr_img, sizeof(int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } max_curr_numobjs = 0; if(max_curr_numobjs<curr_numobjs) max_curr_numobjs=curr_numobjs; if( (fread(&cy3_curr_numobjs, sizeof(int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_numobjs from posfile"); } if(max_curr_numobjs<cy3_curr_numobjs) max_curr_numobjs=cy3_curr_numobjs; if( (fread(&txred_curr_numobjs, sizeof(int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_numobjs from posfile"); } if(max_curr_numobjs<txred_curr_numobjs) max_curr_numobjs=txred_curr_numobjs; if( (fread(&fam_curr_numobjs, sizeof(int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_numobjs from posfile"); } if(max_curr_numobjs<fam_curr_numobjs) max_curr_numobjs=fam_curr_numobjs; l = 0; m = 0; n = 0; o = 0; p = 0; q = 0; cy5_proceed = 1; cy3_proceed = 1; txred_proceed = 1; fam_proceed = 1; found_object = 0; total_object = 0; for(p=0;p<2000;p++){ for(q=0;q<2000;q++){ objects_array[p][q] = -1; } } while(l<max_curr_numobjs) { if(l<curr_numobjs) { if((fread(&cy5_x, sizeof(short unsigned int), 1, posfile)) < 1){ sprintf(log_string, "ERROR reading x from posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if((fread(&cy5_y, sizeof(short unsigned int), 1, posfile)) < 1){ sprintf(log_string, "ERROR reading y from posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if ((objects_array[(int)cy5_x][(int)cy5_y] == -1)&&((int)cy5_y!=1000 && (int)cy5_x!=1000)){ objects_array[(int)cy5_x][(int)cy5_y] = 1; total_object++; } } if(l<cy3_curr_numobjs) { if((fread(&cy3_x, sizeof(short unsigned int), 1, cy3_posfile)) < 1){ sprintf(log_string, "ERROR reading x from posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if((fread(&cy3_y, sizeof(short unsigned int), 1, cy3_posfile)) < 1){ sprintf(log_string, "ERROR reading y from posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if ((objects_array[(int)cy3_x][(int)cy3_y] == -1)&&((int)cy3_y!=1000 && (int)cy3_x!=1000)){ objects_array[(int)cy3_x][(int)cy3_y] = 1; total_object++; } } if(l<txred_curr_numobjs) { if((fread(&txred_x, sizeof(short unsigned int), 1, txred_posfile)) < 1){ sprintf(log_string, "ERROR reading x from posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if((fread(&txred_y, sizeof(short unsigned int), 1, txred_posfile)) < 1){ sprintf(log_string, "ERROR reading y from posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if ((objects_array[(int)txred_x][(int)txred_y] == -1)&&((int)txred_y!=1000 && (int)txred_x!=1000)){ objects_array[(int)txred_x][(int)txred_y] = 1; total_object++; } } if(l<fam_curr_numobjs) { if((fread(&fam_x, sizeof(short unsigned int), 1, fam_posfile)) < 1){ sprintf(log_string, "ERROR reading x from posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if((fread(&fam_y, sizeof(short unsigned int), 1, fam_posfile)) < 1){ sprintf(log_string, "ERROR reading y from posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if ((objects_array[(int)fam_x][(int)fam_y] == -1)&&((int)fam_y!=1000 && (int)fam_x!=1000)){ objects_array[(int)fam_x][(int)fam_y] = 1; total_object++; } } l++; } convert=-1; // make sure we are where we think we are in the position file if( (fread(&temp, sizeof(short unsigned int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if(temp!=0){ sprintf(log_string, "ERROR: 1expecting delimiter value of 0, read %d", temp); p_log(log_string); exit(0); } // make sure we are where we think we are in the position file if( (fread(&temp, sizeof(short unsigned int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if(temp!=0){ sprintf(log_string, "ERROR: 2expecting delimiter value of 0, read %d", temp); p_log(log_string); exit(0); } // make sure we are where we think we are in the position file if( (fread(&temp, sizeof(short unsigned int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if(temp!=0){ sprintf(log_string, "ERROR: 3expecting delimiter value of 0, read %d", temp); p_log(log_string); exit(0); } // make sure we are where we think we are in the position file if( (fread(&temp, sizeof(short unsigned int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if(temp!=0){ sprintf(log_string, "ERROR: 4expecting delimiter value of 0, read %d", temp); p_log(log_string); exit(0); } //p_log((char*)"Write data to object table"); if(fwrite(&convert, sizeof(int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of -1 to posfile failed"); exit(0); } if(fwrite(&i, sizeof(int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of curr_fcnum to posfile failed"); exit(0); } if(fwrite(&j, sizeof(int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of curr_arraynum to posfile failed"); exit(0); } if(fwrite(&k, sizeof(int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of curr_imagenum to posfile failed"); exit(0); } convert = (int)total_object; if(fwrite(&convert, sizeof(int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of num_beads to posfile failed"); exit(0); } object_count=0; for(q=0;q<1000;q++){ for(p=0;p<1000;p++){ if(objects_array[p][q] == 1){ if(fwrite(&p, sizeof(short unsigned int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of beadpos_xcol to posfile failed"); exit(0); } if(fwrite(&q, sizeof(short unsigned int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of beadpos_yrow to posfile failed"); exit(0); } object_count++; } } } //sprintf(log_string, "Position %d %d %d... %d cy5_objects, %d cy3_objects, %d txred_objects, %d fam_objects, total_object %d, total_object_count %d\n", i, j, k, curr_numobjs,cy3_curr_numobjs,txred_curr_numobjs,fam_curr_numobjs,total_object,object_count); sprintf(log_string, "Position %d %d %d... %d cy5_objects, %d cy3_objects, %d txred_objects, %d fam_objects, total_object %lld, total_object_count %d\n", i, j, k, curr_numobjs,cy3_curr_numobjs,txred_curr_numobjs,fam_curr_numobjs,total_object,object_count); p_log_simple(log_string); fprintf(obj_logfile,log_string); sconvert=0; if(fwrite(&sconvert, sizeof(short unsigned int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of 0 to posfile failed"); exit(0); } //write to the info file sconvert = i; if(fwrite(&sconvert, sizeof(short unsigned int), 1, infofile) < 1){ p_log_errorno((char*)"write of curr_fcnum to infofile failed"); exit(0); } sconvert = j; if(fwrite(&sconvert, sizeof(short unsigned int), 1, infofile) < 1){ p_log_errorno((char*)"write of curr_arraynum to infofile failed"); exit(0); } sconvert = k; if(fwrite(&sconvert, sizeof(short unsigned int), 1, infofile) < 1){ p_log_errorno((char*)"write of curr_imagenum to infofile failed"); exit(0); } sconvert = (int)total_object; if(fwrite(&sconvert, sizeof(short unsigned int), 1, infofile) < 1){ p_log_errorno((char*)"write of num_beads to infofile failed"); exit(0); } } } } fclose(posfile); fclose(cy3_posfile); fclose(fam_posfile); fclose(txred_posfile); fclose(final_posfile); fclose(infofile); fclose(obj_logfile); //merge the autoexp object table if((cy3_posfile=fopen("autoexp_pos_cy3", "rb")) == NULL){ sprintf(log_string, "ERROR opening position file %s for input", "autoexp_pos_cy3"); p_log_errorno(log_string); exit(0); } if( (txred_posfile=fopen("autoexp_pos_txr", "rb")) == NULL){ sprintf(log_string, "ERROR opening position file %s for input", "autoexp_pos_txred"); p_log_errorno(log_string); exit(0); } if( (fam_posfile=fopen("autoexp_pos_fam", "rb")) == NULL){ sprintf(log_string, "ERROR opening position file %s for input", "autoexp_pos_fam"); p_log_errorno(log_string); exit(0); } if( (posfile=fopen("autoexp_pos_cy5", "rb")) == NULL){ sprintf(log_string, "ERROR opening position file %s for input", "autoexp_pos_cy5"); p_log_errorno(log_string); exit(0); } if( (final_posfile=fopen("autoexp_pos", "wb")) == NULL){ sprintf(log_string, "ERROR opening position file %s for input", argv[1]); p_log_errorno(log_string); exit(0); } strcpy(info_filename,"autoexp_pos"); strcat(info_filename,".info"); if( (infofile=fopen(info_filename, "wb")) == NULL){ sprintf(log_string, "ERROR opening reg file %s for output", info_filename); p_log_errorno(log_string); exit(0); } i = 0; j = 0; k = 0; for(j=0; j<ARRAYS_PER_FC; j++){ for(k = 0;k<15;k++){ if( (fread(&curr_fc, sizeof(int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading autoe curr_fc(1) from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading autoe curr_fc(2) from posfile"); } if( (fread(&curr_array, sizeof(int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading autoe curr_array from posfile"); } if( (fread(&curr_img, sizeof(int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if( (fread(&curr_numobjs, sizeof(int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_numobjs from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(1) from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(2) from posfile"); } if( (fread(&curr_array, sizeof(int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_array from posfile"); } if( (fread(&curr_img, sizeof(int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(1) from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(2) from posfile"); } if( (fread(&curr_array, sizeof(int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_array from posfile"); } if( (fread(&curr_img, sizeof(int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(1) from posfile"); } if( (fread(&curr_fc, sizeof(int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_fc(2) from posfile"); } if( (fread(&curr_array, sizeof(int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_array from posfile"); } if( (fread(&curr_img, sizeof(int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } max_curr_numobjs = 0; if(max_curr_numobjs<curr_numobjs) max_curr_numobjs=curr_numobjs; if( (fread(&cy3_curr_numobjs, sizeof(int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_numobjs from posfile"); } if(max_curr_numobjs<cy3_curr_numobjs) max_curr_numobjs=cy3_curr_numobjs; if( (fread(&txred_curr_numobjs, sizeof(int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_numobjs from posfile"); } if(max_curr_numobjs<txred_curr_numobjs) max_curr_numobjs=txred_curr_numobjs; if( (fread(&fam_curr_numobjs, sizeof(int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_numobjs from posfile"); } if(max_curr_numobjs<fam_curr_numobjs) max_curr_numobjs=fam_curr_numobjs; l = 0; m = 0; n = 0; o = 0; p = 0; q = 0; cy5_proceed = 1; cy3_proceed = 1; txred_proceed = 1; fam_proceed = 1; found_object = 0; total_object = 0; for(p=0;p<2000;p++){ for(q=0;q<2000;q++){ objects_array[p][q] = -1; } } while(l<max_curr_numobjs) { if(l<curr_numobjs) { if((fread(&cy5_x, sizeof(short unsigned int), 1, posfile)) < 1){ sprintf(log_string, "ERROR reading x from autoe posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if((fread(&cy5_y, sizeof(short unsigned int), 1, posfile)) < 1){ sprintf(log_string, "ERROR reading y from autoe posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if ((objects_array[(int)cy5_x][(int)cy5_y] == -1)&&((int)cy5_y!=1000 && (int)cy5_x!=1000)){ objects_array[(int)cy5_x][(int)cy5_y] = 1; total_object++; } } if(l<cy3_curr_numobjs) { if((fread(&cy3_x, sizeof(short unsigned int), 1, cy3_posfile)) < 1){ sprintf(log_string, "ERROR reading x from autoe posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if((fread(&cy3_y, sizeof(short unsigned int), 1, cy3_posfile)) < 1){ sprintf(log_string, "ERROR reading y from autoe posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if ((objects_array[(int)cy3_x][(int)cy3_y] == -1)&&((int)cy3_y!=1000 && (int)cy3_x!=1000)){ objects_array[(int)cy3_x][(int)cy3_y] = 1; total_object++; } } if(l<txred_curr_numobjs) { if((fread(&txred_x, sizeof(short unsigned int), 1, txred_posfile)) < 1){ sprintf(log_string, "ERROR reading x from autoe posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if((fread(&txred_y, sizeof(short unsigned int), 1, txred_posfile)) < 1){ sprintf(log_string, "ERROR reading y from autoe posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if ((objects_array[(int)txred_x][(int)txred_y] == -1)&&((int)txred_y!=1000 && (int)txred_x!=1000)){ objects_array[(int)txred_x][(int)txred_y] = 1; total_object++; } } if(l<fam_curr_numobjs) { if((fread(&fam_x, sizeof(short unsigned int), 1, fam_posfile)) < 1){ sprintf(log_string, "ERROR reading x from autoe posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if((fread(&fam_y, sizeof(short unsigned int), 1, fam_posfile)) < 1){ sprintf(log_string, "ERROR reading y from autoe posfile at %d %d %d %d", i, j, k, l); p_log_errorno(log_string); } if ((objects_array[(int)fam_x][(int)fam_y] == -1)&&((int)fam_y!=1000 && (int)fam_x!=1000)){ objects_array[(int)fam_x][(int)fam_y] = 1; total_object++; } } l++; } // make sure we are where we think we are in the position file if( (fread(&temp, sizeof(short unsigned int), 1, posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from autoe posfile"); } if(temp!=0){ sprintf(log_string, "ERROR: 1expecting delimiter value of 0, read %d", temp); p_log(log_string); exit(0); } // make sure we are where we think we are in the position file if( (fread(&temp, sizeof(short unsigned int), 1, cy3_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from autoe posfile"); } if(temp!=0){ sprintf(log_string, "ERROR: 2expecting delimiter value of 0, read %d", temp); p_log(log_string); exit(0); } // make sure we are where we think we are in the position file if( (fread(&temp, sizeof(short unsigned int), 1, txred_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if(temp!=0){ sprintf(log_string, "ERROR: 3expecting delimiter value of 0, read %d", temp); p_log(log_string); exit(0); } // make sure we are where we think we are in the position file if( (fread(&temp, sizeof(short unsigned int), 1, fam_posfile)) < 1){ p_log_errorno((char*)"ERROR reading curr_img from posfile"); } if(temp!=0){ sprintf(log_string, "ERROR: 4expecting delimiter value of 0, read %d", temp); p_log(log_string); exit(0); } convert=-1; //p_log((char*)"Write data to object table"); if(fwrite(&convert, sizeof(int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of -1 to posfile failed"); exit(0); } if(fwrite(&i, sizeof(int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of curr_fcnum to posfile failed"); exit(0); } if(fwrite(&j, sizeof(int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of curr_arraynum to posfile failed"); exit(0); } if(fwrite(&k, sizeof(int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of curr_imagenum to posfile failed"); exit(0); } convert = (int)total_object; if(fwrite(&convert, sizeof(int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of num_beads to posfile failed"); exit(0); } object_count=0; for(q=0;q<1000;q++){ for(p=0;p<1000;p++){ if(objects_array[p][q] == 1){ if(fwrite(&p, sizeof(short unsigned int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of beadpos_xcol to posfile failed"); exit(0); } if(fwrite(&q, sizeof(short unsigned int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of beadpos_yrow to posfile failed"); exit(0); } object_count++; } } } sprintf(log_string, "autoe1 Position %d %d %d... %d cy5_objects, %d cy3_objects, %d txred_objects, %d fam_objects, total_object %lld, total_object_count %d\n", curr_fc, curr_array, curr_img, curr_numobjs,cy3_curr_numobjs,txred_curr_numobjs,fam_curr_numobjs,total_object,object_count); p_log_simple(log_string); sconvert=0; if(fwrite(&sconvert, sizeof(short unsigned int), 1, final_posfile) < 1){ p_log_errorno((char*)"write of 0 to posfile failed"); exit(0); } //write to the info file sconvert = i; if(fwrite(&sconvert, sizeof(short unsigned int), 1, infofile) < 1){ p_log_errorno((char*)"write of curr_fcnum to infofile failed"); exit(0); } sconvert = j; if(fwrite(&sconvert, sizeof(short unsigned int), 1, infofile) < 1){ p_log_errorno((char*)"write of curr_arraynum to infofile failed"); exit(0); } sconvert = k; if(fwrite(&sconvert, sizeof(short unsigned int), 1, infofile) < 1){ p_log_errorno((char*)"write of curr_imagenum to infofile failed"); exit(0); } sconvert = (int)total_object; if(fwrite(&sconvert, sizeof(short unsigned int), 1, infofile) < 1){ p_log_errorno((char*)"write of num_beads to infofile failed"); exit(0); } } } fclose(posfile); fclose(cy3_posfile); fclose(fam_posfile); fclose(txred_posfile); fclose(final_posfile); fclose(infofile); //system("rm 00_*"); }
int main(int argc, char *argv[]) { int m_sock,i,j, autoexp_gain; char autoe_filename[500]; char autoe_dirname[500]; char command_buffer[255]; // buffer for commands to be executed char image_dir[255]; sprintf(image_dir, "%s/polonator/G.007/acquisition", getenv("HOME")); sprintf(command_buffer, "mkdir -p %s", image_dir); system(command_buffer); if(argc < 2) { fprintf(stdout, "%s must be called w/ one of the following arguments:\n", argv[0]); fprintf(stdout, "\treset\t\t -- restart software on controller and home all axes\n"); fprintf(stdout, "\tunlock\t\t -- 'unlock' stage for manual movement\n"); fprintf(stdout, "\tlock\t\t -- 'lock' stage for servo movement\n"); fprintf(stdout, "\tlive\t\t -- display live darkfield image (%s live <integration in seconds> <EM gain>)\n", argv[0]); fprintf(stdout, "\tsnap\t\t -- snap image and save to disk (%s snap <color[fam, cy5, cy3, txred, spare, or none]> <integration in seconds> <EM gain>)\n", argv[0]); fprintf(stdout, "\tcolorsnap\t -- snap images in all 4 channels and save to disk (%s colorsnap <integration in seconds> <fam gain> <cy5 gain> <cy3 gain> <txred gain>)\n", argv[0]); fprintf(stdout, "\tstatus\t\t -- get motion controller status and last errors, if any\n"); fprintf(stdout, "\tcomplete-scan\t -- if scanning was interrupted, and reset the controller software gracefully to its starting state\n"); fprintf(stdout, "\tdarkfield-off\t -- turn the darkfield ring illuminator off\n"); fprintf(stdout, "\tdarkfield-on\t -- turn the darkfield ring illuminator on\n"); fprintf(stdout, "\thometheta\t -- 'lock' theta (filter cube) axis and re-home\n"); fprintf(stdout, "\tunlocktheta\t -- 'unlock' theta (filter cube) axis\n"); fprintf(stdout, "\tpower-on\t -- turn camera and fluorescence light source on\n"); fprintf(stdout, "\tpower-off\t -- turn camera and fluorescence light source off\n"); fprintf(stdout, "\tgotostagealignpos\t -- goto position used for stage alignment (%s gotostagealignpos <flowcell> <lane>)\n", argv[0]); fprintf(stdout, "\tgetfocus\t -- get current 'focus' value from Z axis (this is the offset applied to focus error signal)\n"); fprintf(stdout, "\tsetfocus\t -- set focus value for Z axis; note this DOES NOT write to non-volatile memory (%s setfocus <focus_value>)\n", argv[0]); fprintf(stdout, "\twritefocus\t -- write current focus value to non-volatile memory; should be used after correct value is found with setfocus\n"); exit(1); } /* Reset the controller software and re-home the stage */ if(strcmp(argv[1], "reset") == 0) { maestro_open(&m_sock); maestro_reset(m_sock); } else if(strcmp(argv[1], "unlock") == 0) { maestro_open(&m_sock); maestro_unlock(m_sock); } else if(strcmp(argv[1], "lock") == 0) { maestro_open(&m_sock); maestro_lock(m_sock); } else if(strcmp(argv[1], "getfocus") == 0) { maestro_open(&m_sock); return maestro_getfocus(m_sock); } else if(strcmp(argv[1], "setfocus") == 0) { maestro_open(&m_sock); maestro_setfocus(m_sock, atoi(argv[2])); } else if(strcmp(argv[1], "writefocus") == 0) { maestro_open(&m_sock); maestro_writefocus(m_sock); } /* Display a live darkfield image */ else if((strcmp(argv[1], "live") == 0) && ((argc == 4)||(argc == 5))) { maestro_open(&m_sock); maestro_darkfield_on(m_sock); maestro_setcolor(m_sock, "none"); if(argc == 4) { camera_live(argc, argv); } else { camera_live(argc, argv); } maestro_darkfield_off(m_sock); } else if((strcmp(argv[1], "live_new") == 0) && ((argc == 5)||(argc == 6))) { maestro_open(&m_sock); maestro_setcolor(m_sock, argv[4]); if(strcmp(argv[4],"none") == 0) { maestro_darkfield_on(m_sock); maestro_shutterclose(m_sock); } else { maestro_darkfield_off(m_sock); maestro_shutteropen(m_sock); } fprintf(stdout, "Live view starting"); if(argc==5) { fprintf(stdout, "Live view argc == 5"); camera_live(argc, argv); } else { fprintf(stdout, "Live view argc != 5"); camera_live(argc, argv); } fprintf(stdout, "Live view done"); if(strcmp(argv[4],"none")==0) { maestro_darkfield_off(m_sock); } else { maestro_shutterclose(m_sock); } } else if (strcmp(argv[1],"shutter_close")==0) { maestro_open(&m_sock); maestro_shutterclose(m_sock); } /* Acquire an image at the current stage position */ else if((strcmp(argv[1], "snap") == 0) && (argc == 5)) { sprintf(command_buffer, "%s/snap-image.raw", image_dir); snap(atof(argv[3]), atof(argv[4]), argv[2], command_buffer); } else if((strcmp(argv[1], "snap1") == 0) && (argc == 6)) { sprintf(command_buffer, "mkdir -p %s/autoexp_FL_images/cy3", image_dir); system(command_buffer); sprintf(command_buffer, "mkdir -p %s/autoexp_FL_images/fam", image_dir); system(command_buffer); sprintf(command_buffer, "mkdir -p %s/autoexp_FL_images/cy5", image_dir); system(command_buffer); sprintf(command_buffer, "mkdir -p %s/autoexp_FL_images/txred", image_dir); system(command_buffer); for(j = 0; j < atoi(argv[5]); j++) { maestro_open(&m_sock); maestro_gotostagealign_position(m_sock, 0, j); for(i = 0; i < 15; i++) { attempt_counter = 0; autoexp_gain = atoi(argv[4])+i*10; sprintf(autoe_filename, " ... start acquring FL image in lane %d, for %s with autoexposure gain of %d ... ",j, argv[2],autoexp_gain); p_log_simple(autoe_filename); sprintf(autoe_filename, "%s/autoexp_FL_images/%s/%d_image_%d.raw", image_dir,argv[2],j,autoexp_gain); p_log_simple(autoe_filename); wait_counter = 0; snap(atof(argv[3]), autoexp_gain, argv[2], autoe_filename); sprintf(autoe_filename, " ... acquired FL image in %d ms ...\n", wait_counter); p_log_simple(autoe_filename); while((attempt_counter < 4) && (attempt_counter > 0)) { sprintf(autoe_filename, "... ACQUIRING FAILED !!! Re-acquring FL image in lane %d, for %s with autoexposure gain of %d ...\n",atoi(argv[5]), argv[2],atoi(argv[4])); p_log_errorno(autoe_filename); snap(atof(argv[3]), atof(argv[4]), argv[2], autoe_filename); } } // end for i } // end for j } // end else if /* Acquire 4 fluorescence images */ else if((strcmp(argv[1], "colorsnap") == 0) && (argc == 7)) { sprintf(command_buffer, "%s/colorsnap-fam.raw", image_dir); snap(atof(argv[2]), atof(argv[3]), "fam", command_buffer); sprintf(command_buffer, "%s/colorsnap-cy5.raw", image_dir); snap(atof(argv[2]), atof(argv[4]), "cy5", command_buffer); sprintf(command_buffer, "%s/colorsnap-cy3.raw", image_dir); snap(atof(argv[2]), atof(argv[5]), "cy3", command_buffer); sprintf(command_buffer, "%s/colorsnap-txr.raw", image_dir); snap(atof(argv[2]), atof(argv[6]), "txred", command_buffer); } else if(strcmp(argv[1], "complete-scan") == 0) { maestro_open(&m_sock); maestro_stop(m_sock); } else if(strcmp(argv[1], "darkfield-off") == 0) { maestro_open(&m_sock); maestro_darkfield_off(m_sock); } else if(strcmp(argv[1], "darkfield-on") == 0) { maestro_open(&m_sock); maestro_darkfield_on(m_sock); } else if(strcmp(argv[1], "hometheta") == 0) { maestro_open(&m_sock); maestro_hometheta(m_sock); } else if(strcmp(argv[1], "unlocktheta") == 0) { maestro_open(&m_sock); maestro_unlocktheta(m_sock); } else if(strcmp(argv[1], "status") == 0) { maestro_open(&m_sock); maestro_getstatus(m_sock); } else if(strcmp(argv[1], "power-on") == 0) { network_iboot_on(&m_sock); } else if(strcmp(argv[1], "power-off") == 0) { network_iboot_off(&m_sock); } else if(strcmp(argv[1], "gotostagealignpos") == 0) { maestro_open(&m_sock); maestro_gotostagealign_position(m_sock, atoi(argv[2]), atoi(argv[3])); } else { main(1, argv); } } // end function