GMOD / JBrowseR

R interface to the JBrowse 2 Linear Genome View.
https://gmod.github.io/JBrowseR/
Apache License 2.0
35 stars 3 forks source link

search index not working #33

Closed kcamnairb closed 7 months ago

kcamnairb commented 9 months ago

Hi, thanks for this excellent software. I have a genome browser working with JBrowseR but when I add the text_index option to the JBrowseR function it just outputs a white screen. Here is my code:

data_server = serve_data('data')
assembly = assembly(
  'http://127.0.0.1:5000/Aspergillus_flavus.JCVI-afl1-v2.0.dna.toplevel.fa.gz',
  bgzip = TRUE
)
annotations_track = track_feature(
  'http://127.0.0.1:5000/Aspergillus_flavus.JCVI-afl1-v2.0.58_sorted_nosup.gff3.gz',
  assembly
)
tracks = tracks(annotations_track)
default_session = default_session(
  assembly,
  c(annotations_track)
)
JBrowseR('View', 
         assembly = assembly, 
         tracks = tracks,
         defaultSession = default_session,
         theme = theme('#2596be', '#2596be', '#2596be', '#2596be'),
         location = 'EQ963473:33515..37806',
         text_index = text_index('http://127.0.0.1:5000/trix/Aspergillus_flavus.ix',  
                                 'http://127.0.0.1:5000/trix/Aspergillus_flavus.ixx',  
                                 'http://127.0.0.1:5000/trix/Aspergillus_flavus_meta.json',
                                 assembly)
         )

and here are the first few lines of my indexes :

head  trix/{Aspergillus_flavus.ix,Aspergillus_flavus.ixx}
==> trix/Aspergillus_flavus.ix <==
gene:afla_000010 ["EQ963482%3A554..1192"|"Aspergillus_flavus_Aspergillus_flavus"|"gene%3AAFLA_000010"],1
gene:afla_000020 ["EQ963482%3A2089..3474"|"Aspergillus_flavus_Aspergillus_flavus"|"gene%3AAFLA_000020"],1
gene:afla_000330 ["EQ963482%3A13855..16656"|"Aspergillus_flavus_Aspergillus_flavus"|"gene%3AAFLA_000330"],1
gene:afla_000340 ["EQ963482%3A16835..17993"|"Aspergillus_flavus_Aspergillus_flavus"|"gene%3AAFLA_000340"],1
gene:afla_000350 ["EQ963482%3A18479..20528"|"Aspergillus_flavus_Aspergillus_flavus"|"gene%3AAFLA_000350"],1
gene:afla_000360 ["EQ963482%3A22423..22755"|"Aspergillus_flavus_Aspergillus_flavus"|"gene%3AAFLA_000360"],1
gene:afla_000370 ["EQ963482%3A22843..23942"|"Aspergillus_flavus_Aspergillus_flavus"|"gene%3AAFLA_000370"],1
gene:afla_000380 ["EQ963482%3A24324..25134"|"Aspergillus_flavus_Aspergillus_flavus"|"gene%3AAFLA_000380"],1
gene:afla_000390 ["EQ963482%3A25683..27173"|"Aspergillus_flavus_Aspergillus_flavus"|"gene%3AAFLA_000390"],1
gene:afla_000500 ["EQ963482%3A31216..31968"|"Aspergillus_flavus_Aspergillus_flavus"|"gene%3AAFLA_000500"],1

==> trix/Aspergillus_flavus.ixx <==
gene:0000000000
trans000016D97B

and here is my JSON metadata file:

cat trix/Aspergillus_flavus_meta.json
{
  "dateCreated": "2024-03-01T17:29:33.172Z",
  "tracks": [
    {
      "trackId": "Aspergillus_flavus_Aspergillus_flavus",
      "attributesIndexed": [
        "Name",
        "ID"
      ],
      "excludedTypes": [
        "CDS",
        "exon"
      ],
      "adapterConf": {
        "type": "Gff3TabixAdapter",
        "gffGzLocation": {
          "uri": "http://127.0.0.1:5000/Aspergillus_flavus.JCVI-afl1-v2.0.58_sorted_nosup.gff3.gz"
        },
        "index": {
          "location": {
            "uri": "http://127.0.0.1:5000/Aspergillus_flavus.JCVI-afl1-v2.0.58_sorted_nosup.gff3.gz.tbi"
          }
        }
      }
    }
  ],
  "assemblyNames": [
    "Aspergillus_flavus"
  ]
}

Do you see anything wrong with these files, or could you tell me what the proper way is to generate a search index for a single gff3 track? Thanks, Brian

cmdcolin commented 9 months ago

I think I can verify that there might be a bug. I saw our shinyapps.io demos were using an older version, and when i updated them to the latest version, it had a javascript error that caused it to crash (so just blank screen)

will look into this!

cmdcolin commented 9 months ago

if you want to try installing from github

devtools::install_github("GMOD/JBrowseR")

then it will get the latest master branch build and I believe it will have a bugfix for this!

kcamnairb commented 8 months ago

I installed the master branch, but unfortunately I still get the blank screen when I include the text_index option.

cmdcolin commented 8 months ago

hmmm....are you able to look at your "devtools" in your browser to see if there is an error message?

I am testing the following workflow

run "devtools::install_github("GMOD/JBrowseR")"

then clone https://github.com/GMOD/JBrowseR/

then "cd example_apps/basic_usage_with_text_index"

then "Rscript app.R"

I can try to release an official version with the fix I made earlier in case that helps, but it is a bit laborious submitting to CRAN so if what you are seeing is a different bug it would be great to find it before CRAN release :)

kcamnairb commented 8 months ago

It works fine running Rscript app.R in example_apps/basic_usage_with_text_index with the latest master branch. When I run my code with the search index it gives this error in the developer tools console:

react-dom.min.js:121  SyntaxError: Expected ',' or '}' after property value in JSON at position 61 (line 1 column 62)
    at JSON.parse (<anonymous>)
    at JBrowseR.js:2:5932769
    at Array.map (<anonymous>)
    at View (JBrowseR.js:2:5931774)
    at of (react-dom.min.js:109:301)
    at Rk (react-dom.min.js:250:214)
    at Si (react-dom.min.js:195:185)
    at Pk (react-dom.min.js:195:116)
    at Nd (react-dom.min.js:194:492)
    at Mi (react-dom.min.js:189:179)
wf @ react-dom.min.js:121
c.callback @ react-dom.min.js:121
Fh @ react-dom.min.js:92
Ki @ react-dom.min.js:180
Ii @ react-dom.min.js:179
Ik @ react-dom.min.js:178
Sk @ react-dom.min.js:197
yb @ react-dom.min.js:196
Mi @ react-dom.min.js:189
db @ react-dom.min.js:79
zb @ react-dom.min.js:190
$k @ react-dom.min.js:213
Wd @ react-dom.min.js:213
Q.render @ react-dom.min.js:266
renderValue @ widget.js:96
renderValue @ htmlwidgets.js:886
shinyBinding.renderValue @ htmlwidgets.js:541
value @ outputBinding.ts:48
delegator.<computed> @ htmlwidgets.js:112
value @ outputAdapter.ts:38
value @ shinyapp.ts:559
(anonymous) @ shinyapp.ts:736
value @ shinyapp.ts:717
value @ shinyapp.ts:700
i.onmessage @ shinyapp.ts:350
_conn.onmessage @ shiny-server-client.min.js:1
MultiplexClient._conn.onmessage @ shiny-server-client.min.js:1
BufferedResendConnection._handleMessage @ shiny-server-client.min.js:1
RobustConnection._handleMessage @ shiny-server-client.min.js:1
conn.<computed> @ shiny-server-client.min.js:1
r.dispatchEvent @ eventtarget.js:51
(anonymous) @ main.js:282
w._transportMessage @ main.js:280
i.emit @ emitter.js:50
ws.onmessage @ websocket.js:35
react-dom.min.js:79  Uncaught SyntaxError: Expected ',' or '}' after property value in JSON at position 61 (line 1 column 62)
    at JSON.parse (<anonymous>)
    at JBrowseR.js:2:5932769
    at Array.map (<anonymous>)
    at View (JBrowseR.js:2:5931774)
    at of (react-dom.min.js:109:301)
    at Rk (react-dom.min.js:250:214)
    at Si (react-dom.min.js:195:185)
    at Pk (react-dom.min.js:195:116)
    at Nd (react-dom.min.js:194:492)
    at Mi (react-dom.min.js:189:179)

Does is look like something is wrong with my search index.? I tried a couple different ways of creating the index, one with jbrowse text-index --file Aspergillus_flavus.JCVI-afl1-v2.0.58_sorted_nosup.gff3.gz --out Aspergillus_flavus.JCVI-afl1-v2.0.58_sorted_nosup.gff3.gz. The other method I tried was to create a config.json and run jbrowse text-index --out trix . Are these the recommended ways to create a text index?

cmdcolin commented 8 months ago

i believe that it can be fixed like this

JBrowseR("View",
      assembly = assembly,
      tracks = tracks,
      defaultSession = default_session,
      theme = theme("#2596be", "#2596be", "#2596be", "#2596be"),
      location = "EQ963473:33515..37806",
      text_index = text_index(
        "http://127.0.0.1:5000/trix/Aspergillus_flavus.ix",
        "http://127.0.0.1:5000/trix/Aspergillus_flavus.ixx",
        "http://127.0.0.1:5000/trix/Aspergillus_flavus_meta.json",
        "Aspergillus_flavus" 
      )
    )

so, instead of the variable named "assembly" for that fourth argument, pass the assembly name as a string. this is autocomputed from the file name that was supplied initially, so "Aspergillus_flavus" i believe works

using that will solve the problem you saw i believe

I will keep this open. there is a potential to accept the code case you described, and improve the API potentially!

kcamnairb commented 7 months ago

Colin,

I've still been struggling to get the search index working. I tried to set up a reproducible example that includes a bash script to download the files and index them, and then my R code that I used. None of the gene names are searchable through the text box using the JBrowseR function, but when I use these same exact files with JBrowse2 I can search the gene names just fine. For example, typeing "F9C" brings up a list of gene names in JBrowse2 but nothing in JBrowseR. My JBrowse2 version is @jbrowse/cli/2.11.0 linux-x64 node-v16.13.0 and JBrowseR is JBrowseR_0.10.2. I've tried it on both Windows 10 and Ubuntu 20.04. If you have a chance to take a look at this, I'd greatly appreciate it.

download_script:

#!/bin/bash
wget https://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/009/017/415/GCA_009017415.1_ASM901741v1/GCA_009017415.1_ASM901741v1_genomic.fna.gz
wget https://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/009/017/415/GCA_009017415.1_ASM901741v1/GCA_009017415.1_ASM901741v1_genomic.gff.gz
gunzip GCA_009017415.1_ASM901741v1_genomic.fna.gz
gunzip GCA_009017415.1_ASM901741v1_genomic.gff.gz
jbrowse sort-gff GCA_009017415.1_ASM901741v1_genomic.gff | bgzip > GCA_009017415.1_ASM901741v1_genomic.gff.gz
tabix GCA_009017415.1_ASM901741v1_genomic.gff.gz
samtools faidx GCA_009017415.1_ASM901741v1_genomic.fna
jbrowse add-assembly GCA_009017415.1_ASM901741v1_genomic.fna --load inPlace 
jbrowse add-track GCA_009017415.1_ASM901741v1_genomic.gff.gz --load inPlace --assemblyNames GCA_009017415.1_ASM901741v1_genomic.fna
jbrowse text-index

JBrowseR:

library(JBrowseR)
setwd("test")
data_server = serve_data(".", port=5011)
assembly = assembly(
  "http://127.0.0.1:5011/GCA_009017415.1_ASM901741v1_genomic.fna",
  bgzip = FALSE
)
annotations_track = track_feature(
  "http://127.0.0.1:5011/GCA_009017415.1_ASM901741v1_genomic.gff.gz",
  assembly
)
tracks = tracks(annotations_track)
default_session = default_session(
  assembly,
  c(annotations_track)
)
JBrowseR("View", 
         assembly = assembly,
         tracks = tracks,
         defaultSession = default_session,
         text_index = text_index("http://127.0.0.1:5011/trix/GCA_009017415.1_ASM901741v1_genomic.fna.ix",
                                 "http://127.0.0.1:5011/trix/GCA_009017415.1_ASM901741v1_genomic.fna.ixx",
                                 "http://127.0.0.1:5011/trix/GCA_009017415.1_ASM901741v1_genomic.fna_meta.json",
                                 "GCA_009017415.1_ASM901741v1_genomic.fna"),
         location = "CP044620.1:5,082,369..5,101,183"
)
cmdcolin commented 7 months ago

thanks for posting this with the reproducible script, I think I can confirm the issue. I'll check into it!

cmdcolin commented 7 months ago

@kcamnairb the error I believe is fixed by changing the 'assembly name' for the text_index call in your code. fixed code

library("JBrowseR")
data_server <- serve_data(".", port = 5020)
assembly <- assembly(
  "http://127.0.0.1:5020/GCA_009017415.1_ASM901741v1_genomic.fna",
  bgzip = FALSE
)
annotations_track <- track_feature(
  "http://127.0.0.1:5020/GCA_009017415.1_ASM901741v1_genomic.gff.gz",
  assembly
)
tracks <- tracks(annotations_track)
default_session <- default_session(
  assembly,
  c(annotations_track)
)
JBrowseR("View",
  assembly = assembly,
  tracks = tracks,
  defaultSession = default_session,
  text_index = text_index(
    "http://127.0.0.1:5020/trix/GCA_009017415.1_ASM901741v1_genomic.fna.ix",
    "http://127.0.0.1:5020/trix/GCA_009017415.1_ASM901741v1_genomic.fna.ixx",
    "http://127.0.0.1:5020/trix/GCA_009017415.1_ASM901741v1_genomic.fna_meta.json",
    "GCA_009017415"
  ),
  location = "CP044620.1:5,082,369..5,101,183"
)

I determined the new assembly name by going to the "Return to import form" and selecting the auto-generated name there. I believe the auto-generated assembly name GCA_009017415 was calculated by splitting the file name by "." and selecting the "first value" with was GCA_009017415 (of the file name GCA_009017415.1_ASM901741v1_genomic.fna)

image

kcamnairb commented 7 months ago

That works! Thanks you so much.