uint64_t n_lines;
};
-char **bam_load_pos(const char *fn, int *_n)
+char **__bam_get_lines(const char *fn, int *_n) // for bam_plcmd.c only
{
char **list = 0, *s;
- int n = 0, dret, m = 0, c;
+ int n = 0, dret, m = 0;
gzFile fp = (strcmp(fn, "-") == 0)? gzdopen(fileno(stdin), "r") : gzopen(fn, "r");
kstream_t *ks;
kstring_t *str;
str = (kstring_t*)calloc(1, sizeof(kstring_t));
ks = ks_init(fp);
- while (ks_getuntil(ks, 0, str, &dret) > 0) {
+ while (ks_getuntil(ks, '\n', str, &dret) > 0) {
if (n == m) {
m = m? m << 1 : 16;
list = (char**)realloc(list, m * sizeof(char*));
}
- s = list[n++] = (char*)calloc(str->l + 5, 1);
+ if (str->s[str->l-1] == '\r')
+ str->s[--str->l] = '\0';
+ s = list[n++] = (char*)calloc(str->l + 1, 1);
strcpy(s, str->s);
- s += str->l + 1;
- ks_getuntil(ks, 0, str, &dret);
- *((uint32_t*)s) = atoi(str->s);
- if (dret != '\n')
- while ((c = ks_getc(fp)) >= 0 && c != '\n');
}
ks_destroy(ks);
+ gzclose(fp);
free(str->s); free(str);
*_n = n;
return list;
if (*s) parse_error(fp->n_lines, "unmatched CIGAR operation");
c->bin = bam_reg2bin(c->pos, bam_calend(c, bam1_cigar(b)));
doff += c->n_cigar * 4;
- }
+ } else c->bin = bam_reg2bin(c->pos, c->pos + 1);
}
{ // mtid, mpos, isize
ret = ks_getuntil(ks, 0, str, &dret); c->mtid = strcmp(str->s, "=")? bam_get_tid(header, str->s) : c->tid;
type = str->s[3];
s = alloc_data(b, doff + 3) + doff;
s[0] = key[0]; s[1] = key[1]; s += 2; doff += 2;
- if (type == 'A' || type == 'a') {
+ if (type == 'A' || type == 'a' || type == 'c' || type == 'C') { // c and C for backward compatibility
s = alloc_data(b, doff + 2) + doff;
- *s++ = type; *s = str->s[5];
+ *s++ = 'A'; *s = str->s[5];
doff += 2;
} else if (type == 'I' || type == 'i') {
long long x;
int ret;
b = (bam1_t*)calloc(1, sizeof(bam1_t));
- fpbaf = bam_open(fnbaf, "w");
+ fpbaf = (strcmp(fnbaf, "-") == 0)? bam_dopen(fileno(stdout), "w") : bam_open(fnbaf, "w");
fp = sam_open(fntaf);
ret = sam_read1(fp, header, b);
bam_header_write(fpbaf, header);