Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric tags in BAM files interpreted incorrectly #1328

Closed
rsmeral opened this issue May 12, 2021 · 5 comments
Closed

Numeric tags in BAM files interpreted incorrectly #1328

rsmeral opened this issue May 12, 2021 · 5 comments
Assignees
Milestone

Comments

@rsmeral
Copy link

rsmeral commented May 12, 2021

I have a BAM file with a read with this tag (as shown by samtools view): AS:i:-8 (alignment score, 32-bit signed int, value = -8).

However, when I view the same read in IGV.js, it shows AS: 248.
I think the issue is in how IGV interprets data types of tags in BAM files.

In the BAM file, this number is represented as the c type (8-bit signed int), since "...while all single (i.e., non-array) integer types are stored in SAM as i, in BAM any of cCsSiI maybe used together with the correspondingly-sized binary integer value, chosen according to the field value’s magnitude." (as per 4.2.4. Auxiliary data encoding of the SAM Spec).

Samtools does the following:

Specifically, for conversion of a c type, it does (simplified):

le_to_i8 = (val) => 
  val < 0x80
    ? val
    : -(0xff - val) - 1

Which, when tried with 248 (0xf8), does return the proper -8, like samtools.

I see that IGV.js skips conversion for the c type, and interprets it as is, yielding the incorrect value of 248 (instead of expected -8):
https://github.com/igvteam/igv.js/blob/master/js/bam/bamAlignment.js#L149

@jrobinso jrobinso self-assigned this May 17, 2021
@jrobinso jrobinso added this to the 2.8.4 milestone May 17, 2021
@rsmeral
Copy link
Author

rsmeral commented Jun 11, 2021

Hi @jrobinso – is there any timeline for the 2.8.4 release?
Not trying to rush you – just curious, so that we can plan around it in my product.

Have you started work on this yet? I think I could make a PR if not.

@jrobinso
Copy link
Contributor

@rsmeral Apologies, 2.8.4 was released but this is still open. If you can make a PR that would be helpful, otherwise I will get to it ASAP.

@rsmeral
Copy link
Author

rsmeral commented Jun 11, 2021

@jrobinso Thanks for the quick fix!

@jrobinso
Copy link
Contributor

@rsmeral Have you tested it? I don't have any bams with "C" tags so I had to simulate it.

@rsmeral
Copy link
Author

rsmeral commented Jun 13, 2021

@jrobinso Yeah, just tested on a BAM file with a c (signed):

  • in 2.7.3 – AS: 239
  • in 2.8.6 – AS: -17

Thanks 👍

(Can't confirm for C (unsigned) though either).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants