brittneybrinsfield / pysam

Automatically exported from code.google.com/p/pysam
0 stars 0 forks source link

Float tags prevent opt() from finding later tags (KeyError instead of value of present tag) #71

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I have added additional tags to a bam file, the tags are present in 
read.tags(), but calling read.opt("last_tag") raises a KeyError().

The minimal bam file exposing the problem (just one read) is attached.

I tracked the bug down to an interplay of bam_aux_get, __skip_tag and 
bam_aux_type2size in samtools.

Basically, bam_aux_get calls __skip_tag to get o the next tag, that converts 
the tag type code into uppercase (here: a float tag, type == 'f'), and passes 
it to bam_aux_type2size which expected a lowercase f.

So all that needs to be done is replace
static inline int bam_aux_type2size(int x)
{
    if (x == 'C' || x == 'c' || x == 'A') return 1;
    else if (x == 'S' || x == 's') return 2;
    else if (x == 'I' || x == 'i' || x == 'f') return 4;
    else return 0;
}
with 
static inline int bam_aux_type2size(int x)
{
    if (x == 'C' || x == 'c' || x == 'A') return 1;
    else if (x == 'S' || x == 's') return 2;
    else if (x == 'I' || x == 'i' || x == 'f' || x == 'F') return 4;
    else return 0;
}
in bam.h

Testcase:
    def test_float_tag_bug( self ): #a float tag before another exposed a parsing bug in bam_aux_get
        samfile = pysam.Samfile("tag_bug.bam")
        found = False
        read = samfile.fetch(until_eof=True).next()
        for tag, value in read.tags:
            if tag == 'XC':
                found = True
        self.assertTrue(found)
        self.assertEqual(read.opt('XC'), 1)

Guess we should also report this upstream - anybody got an already established 
contact?

So long,
Florian

Original issue reported on code.google.com by finkerna...@mathematik.uni-marburg.de on 5 Oct 2011 at 3:01

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for tracking this down - really well done.

I have verified this bug still exists in samtools 0.1.18 and I have added the 
unit test.

I have no established contact to the samtools developers - would you like to  
report it?

Best wishes,
Andreas

Original comment by andreas....@gmail.com on 27 Oct 2011 at 7:48

GoogleCodeExporter commented 9 years ago
I have done so: 
http://sourceforge.net/mailarchive/forum.php?thread_name=1317891536-sup-3704%40h
1610647.stratoserver.net&forum_name=samtools-devel

Thanks for your hard work on pysam!

Original comment by finkerna...@mathematik.uni-marburg.de on 28 Oct 2011 at 10:54

GoogleCodeExporter commented 9 years ago
Fixed in samtools 0.1.19

Many thanks!
Andreas

Original comment by andreas....@gmail.com on 26 Jun 2013 at 7:50