GMOD / jbrowse-components

Source code for JBrowse 2, a modern React-based genome browser
https://jbrowse.org/jb2
Apache License 2.0
211 stars 63 forks source link

Color by modifications option ignores BAM reverse reads #4629

Closed shaperones closed 3 weeks ago

shaperones commented 3 weeks ago

Describe the bug

Modifications in a BAM file are ignored on reverse reads, even though the MM string seems to be recognized on both forward and reverse reads (the MM string appears in Feature details after clicking on individual reverse reads; see screenshot).

To Reproduce

  1. Add-assembly (TAIR10 genome release ) + add-track (BAM file)
  2. Select BAM file in track selector
  3. Click on BAM track label menu
  4. Select Pileup settings -> Color by... -> Modifications or methylation -> Modifications
  5. (See that reverse read modifications are not colored)
  6. Click on any reverse read -> Feature details -> See that ML and MM strings are present

Expected behavior

Modifications should be displayed on both strands.

Screenshots

The lower track is the BAM of interest, the upper BAM is Dorado modified base calling output for comparison. Feature details for a selected reverse read show the presence of MM/ML tags.

image

Version:

Jbrowse-cli was installed via npm (v.2.16.0 on linux-x64 node-v20.12.2.) P.S. I tried to install older versions (npm install -g @jbrowse/cli@2.10.0, jbrowse create jbrowse2), but the About tab still displays "JBrowse 2 2.16.0"

Additional context

Modifications calling was performed by DeepSignal-Plant, and MM/ML were added with DeepS2bam, which uses pysam and Biopython. This approach allowed modification visualization in JBrowse2 at least 2 years ago. I suspect JBrowse2 may have changed its display method for modifications or added hidden validation checks for reads...

Notably, IGV encountered a similar issue recently. Also I checked if Jbrowse2 fails to show reverse strand modifications from other modified base callers - Dorado output is totally OK (see upper BAM track in the screenshot).

I appreciate any help and suggestions, including ways to adjust MM/ML tags to enable visualization in Jbrowse2.

cmdcolin commented 3 weeks ago

thanks for reporting this! I found a potential fix here #4630. it is a little bit of a band-aid solution, but i think it helps

what i was seeing is that somehow a modification with a "-1" offset to the read was calculated in your BAM files, and it made the renderer just stop everything

here is a screenshot with the fix

image

i am wondering if there is something weird about this BAM that you posted. i noted that it actually has trouble loading in IGV desktop, it gives a weird error for me (?)

Screenshot From 2024-10-30 10-51-00

but anyways, after this PR your BAM renders (screenshot above) with negative strand reads showing modifications.

note that this bug did not affect all files: this existing file in our test data works fine in the existing releases with negative strand https://jbrowse.org/code/jb2/v2.16.0/?config=test_data%2Fconfig_demo.json&session=share-qnDdO29QC0&password=hvYQX

you can try out the beta branch with

jbrowse create --branch fix_negative_modifications newinstance

or

# run in your current folder
jbrowse upgrade --branch fix_negative_modifications 
cmdcolin commented 3 weeks ago

random note:

P.S. I tried to install older versions (npm install -g @jbrowse/cli@2.10.0, jbrowse create jbrowse2), but the About tab still displays "JBrowse 2 2.16.0"

the CLI and the version on the web can be different versions

to install specific versions via the CLI you can use e.g.

jbrowse create --tag v2.10.1 newinstance

similar to the --branch for the beta branch i posted above

shaperones commented 3 weeks ago

Thanks for the quick reply!

I created new JBrowse instance from the beta branch. It works!

P.S. A modification with a "-1" offset to the read seems strange. The reason may be due to DeepS2bam, mentioned above, but I’m not entirely sure... I’ll investigate it further.

P.P.S. I also tried opening the BAM in IGV and encountered the same error recently.

cmdcolin commented 3 weeks ago

I went ahead and merged the fix, should be out in next official release too... if you have any other issues you run into let me know though

cmdcolin commented 1 week ago

@shaperones I made a number of additional bugfixes/improvements in the latest nightly (can try with jbrowse create --nightly newinstance) related to modifications rendering.

for example, I noticed that in your screenshot you have the "blue and red" bars for the dorado track. those are actually a little bit buggy because jbrowse was double counting M (methylation) and H (hydroxy-) for each position, when really it is better to look at the likelihood of each modification to determine which is the best call at each position...the new updates make jbrowse much more aligned essentially with what igv renders

should be out in an official release shortly also but thought i'd let you know