- x = (uint64_t)bam_get_tid(h, list[i]) << 32;
- s = list[i];
- while (*s++);
- x |= *((uint32_t*)s) - 1;
- kh_put(64, hash, x, &tmp);
- free(list[i]);
+ char *str = list[i];
+ int chr, n_fields, ret;
+ khint_t k;
+ uint64_t x;
+ n_fields = ksplit_core(str, 0, &max_fields, &fields);
+ if (n_fields < 2) continue;
+ chr = bam_get_tid(h, str + fields[0]);
+ if (chr < 0) {
+ fprintf(stderr, "[load_pos] unknown reference sequence name: %s\n", str + fields[0]);
+ continue;
+ }
+ x = (uint64_t)chr << 32 | (atoi(str + fields[1]) - 1);
+ k = kh_put(64, hash, x, &ret);
+ if (ret == 0) {
+ fprintf(stderr, "[load_pos] position %s:%s has been loaded.\n", str+fields[0], str+fields[1]);
+ continue;
+ }
+ kh_val(hash, k) = 0;
+ if (n_fields > 2) {
+ // count
+ for (j = 2; j < n_fields; ++j) {
+ char *s = str + fields[j];
+ if ((*s != '+' && *s != '-') || !isdigit(s[1])) break;
+ }
+ if (j > 2) { // update kh_val()
+ int *q, y, z;
+ q = kh_val(hash, k) = (int*)calloc(j - 1, sizeof(int));
+ q[0] = j - 2; z = j; y = 1;
+ for (j = 2; j < z; ++j)
+ q[y++] = atoi(str + fields[j]);
+ }
+ }
+ free(str);