Skip to content

Commit 9cffb48

Browse files
committed
Add hts_parse_region() with flags parameter [DRAFT]
[IN PROGRESS] Need to figure out whether hts_parse_region() is workable with a strend argument and the possibility of colons in chromosome names...
1 parent f859e8d commit 9cffb48

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

hts.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,12 @@ long long hts_parse_decimal(const char *str, char **strend, int flags)
18691869
}
18701870

18711871
const char *hts_parse_reg(const char *s, int *beg, int *end)
1872+
{
1873+
return hts_parse_region(s, NULL, beg, end, HTS_PARSE_THOUSANDS_SEP);
1874+
}
1875+
1876+
const char *
1877+
hts_parse_region(const char *s, char **strend, int *beg, int *end, int flags)
18721878
{
18731879
char *hyphen;
18741880
const char *colon = strrchr(s, ':');
@@ -1877,11 +1883,12 @@ const char *hts_parse_reg(const char *s, int *beg, int *end)
18771883
return s + strlen(s);
18781884
}
18791885

1880-
*beg = hts_parse_decimal(colon+1, &hyphen, HTS_PARSE_THOUSANDS_SEP) - 1;
1886+
*beg = hts_parse_decimal(colon+1, &hyphen, flags) - 1;
18811887
if (*beg < 0) *beg = 0;
18821888

1889+
// FIXME \0 vs. return NULL
18831890
if (*hyphen == '\0') *end = INT_MAX;
1884-
else if (*hyphen == '-') *end = hts_parse_decimal(hyphen+1, NULL, HTS_PARSE_THOUSANDS_SEP);
1891+
else if (*hyphen == '-') *end = hts_parse_decimal(hyphen+1, strend, flags);
18851892
else return NULL;
18861893

18871894
if (*beg >= *end) return NULL;

htslib/hts.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,23 @@ hts_idx_t *hts_idx_load2(const char *fn, const char *fnidx);
494494
*/
495495
long long hts_parse_decimal(const char *str, char **strend, int flags);
496496

497+
/// Equivalent to hts_parse_region(str, NULL, beg, end, HTS_PARSE_THOUSANDS_SEP)
498+
const char *hts_parse_reg(const char *str, int *beg, int *end);
499+
497500
/// Parse a "CHR:START-END"-style region string
498-
/** @param str String to be parsed
499-
@param beg Set on return to the 0-based start of the region
500-
@param end Set on return to the 1-based end of the region
501-
@return Pointer to the colon or '\0' after the reference sequence name,
502-
or NULL if @a str could not be parsed.
501+
/** @param str String to be parsed
502+
@param strend If non-NULL, set on return to point to the first character
503+
in @a str after those forming the parsed region
504+
@param beg Set on return to the 0-based start of the region
505+
@param end Set on return to the 1-based end of the region
506+
@param flags Or'ed-together combination of HTS_PARSE_* flags
507+
@return Pointer to the colon or terminating character after the reference
508+
sequence name, or NULL if @a str could not be parsed.
509+
510+
When @a strend is NULL, a warning will be printed (if hts_verbose is 2
511+
or more) if there are any trailing characters after the region string.
503512
*/
504-
const char *hts_parse_reg(const char *str, int *beg, int *end);
513+
const char *hts_parse_region(const char *str, char **strend, int *beg, int *end, int flags);
505514

506515
hts_itr_t *hts_itr_query(const hts_idx_t *idx, int tid, int beg, int end, hts_readrec_func *readrec);
507516
void hts_itr_destroy(hts_itr_t *iter);

0 commit comments

Comments
 (0)