]> git.donarmstrong.com Git - samtools.git/commitdiff
Catch missing reference error in faidx (avoids floating point exception)
authorpeterjc <p.j.a.cock@googlemail.com>
Wed, 4 Apr 2012 10:43:12 +0000 (11:43 +0100)
committerpeterjc <p.j.a.cock@googlemail.com>
Tue, 19 Jun 2012 14:54:51 +0000 (15:54 +0100)
faidx.c

diff --git a/faidx.c b/faidx.c
index f0798fccc8057a5e33fdb04afaae1af084badbc9..51c82ac1dfdcd0baf31435a0fe5f8e45c3289d0f 100644 (file)
--- a/faidx.c
+++ b/faidx.c
@@ -337,6 +337,11 @@ char *fai_fetch(const faidx_t *fai, const char *str, int *len)
                        } else s[name_end] = ':', name_end = l;
                }
        } else iter = kh_get(s, h, str);
+       if(iter == kh_end(h)) {
+               fprintf(stderr, "[fai_fetch] Warning - Reference %s not found in FASTA file, returning empty sequence\n", str);
+               free(s);
+               return 0;
+       };
        val = kh_value(h, iter);
        // parse the interval
        if (name_end < l) {