[med-svn] [htslib] 04/10: regidx: simple file format autodetection
Charles Plessy
plessy at moszumanska.debian.org
Sun Oct 5 00:54:09 UTC 2014
This is an automated email from the git hooks/post-receive script.
plessy pushed a commit to branch debian/unstable
in repository htslib.
commit d2cb7bacc15bd20960e89cf46712551657512adb
Author: Petr Danecek <pd3 at sanger.ac.uk>
Date: Wed Oct 1 13:15:42 2014 +0100
regidx: simple file format autodetection
---
htslib/regidx.h | 5 ++++-
regidx.c | 15 +++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/htslib/regidx.h b/htslib/regidx.h
index 74dc8c7..69f0812 100644
--- a/htslib/regidx.h
+++ b/htslib/regidx.h
@@ -93,7 +93,10 @@ int regidx_parse_tab(const char*,char**,char**,reg_t*,void*,void*); // CHROM,P
/*
* regidx_init() - creates new index
* @param fname: input file name or NULL if regions will be added one-by-one via regidx_insert()
- * @param parsef: regidx_parse_bed, regidx_parse_tab or see description of regidx_parse_f
+ * @param parsef: regidx_parse_bed, regidx_parse_tab or see description of regidx_parse_f. If NULL,
+ * the format will be autodected, currently either regidx_parse_tab (the default) or
+ * regidx_parse_bed (file must be named 'bed' or 'bed.gz') will be used. Note that
+ * the exact autodetection algorithm will change.
* @param freef: NULL or see description of regidx_parse_f
* @param payload_size: 0 with regidx_parse_bed, regidx_parse_tab or see regidx_parse_f
* @param usr: optional user data passed to regidx_parse_f
diff --git a/regidx.c b/regidx.c
index 5dd3b0e..ac6562c 100644
--- a/regidx.c
+++ b/regidx.c
@@ -150,6 +150,21 @@ int regidx_insert(regidx_t *idx, char *line)
regidx_t *regidx_init(const char *fname, regidx_parse_f parser, regidx_free_f free_f, ssize_t payload_size, void *usr_dat)
{
+ if ( !parser )
+ {
+ if ( !fname ) parser = regidx_parse_tab;
+ else
+ {
+ int len = strlen(fname);
+ if ( len>=7 && !strcasecmp(".bed.gz",fname+len-7) )
+ parser = regidx_parse_bed;
+ else if ( len>=4 && !strcasecmp(".bed",fname+len-4) )
+ parser = regidx_parse_bed;
+ else
+ parser = regidx_parse_tab;
+ }
+ }
+
regidx_t *idx = (regidx_t*) calloc(1,sizeof(regidx_t));
idx->free = free_f;
idx->parse = parser;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/htslib.git
More information about the debian-med-commit
mailing list