modified: myjupyterlab.sh
[GalaxyCodeBases.git] / c_cpp / salusFstReCoord / src1 / worker.c
blobb91d1a735406b9131de614099e12cc70067bbe50
1 #include <float.h> // DBL_MAX
2 #include <math.h> // floor, nextafter, INFINITY
4 #include "common.h"
6 FORCE_INLINE void transCorrd(double *restrict ChipXY, const double *restrict FovXY, const int_least16_t *restrict FovRowCol) {
7 double new_x = (FovRowCol[1] - (CenterFOV_COL - 1)) * FOV_USED_WIDTH - FovXY[1] - 1;
8 double new_y = FovXY[0] + (FovRowCol[0] - (CenterFOV_ROW - 1) - 1) * FOV_USED_HEIGHT;
9 ChipXY[0] = floor(nextafter(new_x * RECIPROCALPRECISION, copysign(INFINITY, new_x))) * OUTPUTPRECISION;
10 ChipXY[1] = floor(nextafter(new_y * RECIPROCALPRECISION, copysign(INFINITY, new_y))) * OUTPUTPRECISION;
11 // ChipXY[0] = floor(new_x * RECIPROCALPRECISION) * OUTPUTPRECISION;
12 // ChipXY[1] = floor(new_y * RECIPROCALPRECISION) * OUTPUTPRECISION;
15 FORCE_INLINE char *strncpy_no_colon(char *restrict dest, const char *restrict src, size_t n) {
16 size_t j = 0; // destination index
17 for (size_t i = 0; i < n && src[i] != '\0'; i++) {
18 if (src[i] != ':') dest[j++] = src[i];
20 // for ( ; j < n; j++) dest[j] = '\0';
21 if (j < n) dest[j] = '\0';
22 return dest;
25 void worker(int_least16_t worker_id) {
26 workerArray_t *worker = &Parameters.worksQuene[worker_id];
27 regmatch_t matches[2];
28 char **splitSets = worker->tokens;
29 // char* readName = malloc(91); // for testing CHARsCPYSTR
30 char readName[MAXFQIDLEN + 1] = {0}; // 81 => [0,80]
31 char fovRC[9] = {0}; // R123C567
32 double GIVENunZoomRatio = (double)Parameters.unZoomRatio;
33 double unZoomRatio = 0;
34 for (uint64_t index = 0; index < JOBITEMSIZE; index++) {
35 fstBCdata_t *fstBCdata_p = &worker->jobDatArray[index];
36 if (fstBCdata_p->name[0] == 0) {
37 break;
39 // fstBCoutput_t *fstBCoutput_p = &worker->output_array[index];
40 ARRAYcpySTR(readName, fstBCdata_p->name);
41 assert(readName[sizeof(fstBCdata_p->name)] == '\0');
42 #ifndef RELEASE
43 fprintf(stderr, "###### %llu\t[%s] %d <--\n", index, readName, readName[sizeof(fstBCdata_p->name)]);
44 #endif
45 int_least16_t RowCol[2] = {0};
46 double oldXY[2] = {0.0};
47 double newXY[2] = {0.0};
48 char *delim = ":";
49 if (regexec(&Parameters.regex, readName, 2, matches, 0) != 0) {
50 fstBCdata_p->name[0] = 0;
51 continue;
53 //__builtin_dump_struct(&matches[0], &printf);
54 //__builtin_dump_struct(&matches[1], &printf);
55 size_t relen = matches[0].rm_eo - matches[0].rm_so;
56 strncpy_no_colon(fovRC, readName + matches[0].rm_so, relen);
57 // fovRC[relen-1] = '\0';
58 assert(fovRC[sizeof(fovRC) - 1] == '\0');
59 // memcpy(fstBCdata_p->RowCol, fovRC, relen-1);
60 fstBCdata_p->fov_row = (uint8_t)(RowCol[0] = atoi(fovRC + 1));
61 fstBCdata_p->fov_column = (uint8_t)(RowCol[1] = atoi(fovRC + 5));
62 if (unlikely(matches[1].rm_so == -1)) {
63 delim = "_";
64 unZoomRatio = 1.0;
65 } else {
66 delim = ":";
67 unZoomRatio = GIVENunZoomRatio;
69 assert(relen == (delim[0] == ':' ? sizeof(fovRC) : sizeof(fovRC) - 1));
70 // printf("%llu\t[%s], delim:[%s], fov[%s]\n", index, readName, delim, fovRC);
71 const char *theDelim = delim;
72 char *saveptr = NULL;
73 char *token = strtok_r(readName, theDelim, &saveptr);
74 // printf("-f- [%zu] [%zu] [%s]\n", readName, token, token);
75 if (unlikely(token == NULL)) {
76 // printf("-b->\t[%s], delim:[%s]\n", readName, theDelim);
77 fstBCdata_p->name[0] = 0;
78 break;
79 } else {
80 int_least16_t idx = 0;
81 for (idx = 0; likely(token != NULL); token = strtok_r(NULL, theDelim, &saveptr), idx++) {
82 splitSets[idx] = token;
83 // printf("-s- %d:[%zu] [%s]\n", idx, splitSets[idx], token);
85 oldXY[1] = atof(splitSets[idx - 1]);
86 oldXY[0] = atof(splitSets[idx - 2]);
87 #ifdef DEBUG
88 fprintf(stderr, "oldXY: [%s],[%s] as [%.2f %.2f]\n", splitSets[idx - 2], splitSets[idx - 1], oldXY[0], oldXY[1]);
89 /* for (idx = 0; idx < MAXDELIMITEMS; idx++) {
90 printf("-t- %d:[%zu] [%s]\n", idx, (void *)splitSets[idx], splitSets[idx]);
91 } */
92 #endif
94 if (unlikely(unZoomRatio != 1.0f)) {
95 oldXY[0] /= unZoomRatio;
96 oldXY[1] /= unZoomRatio;
98 #ifdef DEBUG
99 fprintf(stderr, "[%s]->[%s]=RC(%d,%d), X:%f Y:%f\n", readName, fovRC, RowCol[0], RowCol[1], oldXY[0], oldXY[1]);
100 #endif
101 if ((FOV_X_MIN < oldXY[0] && oldXY[0] <= FOV_X_MAX) && (FOV_Y_MIN < oldXY[1] && oldXY[1] <= FOV_Y_MAX)) {
102 oldXY[0] -= FOV_X_MIN;
103 oldXY[1] -= FOV_Y_MIN;
104 transCorrd(newXY, oldXY, RowCol);
105 // printf("-->gX:%.2f gY:%.2f\n", newXY[0], newXY[1]);
106 memcpy(fstBCdata_p->newXY, newXY, sizeof(newXY));
107 #ifdef DEBUG
108 char readSeq[BARCODELEN + 1];
109 ARRAYcpySTR(readSeq, fstBCdata_p->seq);
110 fprintf(stderr, "->SpatiaStr:[%s %.2f %.2f]\n", readSeq, fstBCdata_p->newXY[0], fstBCdata_p->newXY[1]);
111 #endif
112 } else {
113 fstBCdata_p->name[0] = 0;