Lattice-Automation / seqviz

a JavaScript DNA, RNA, and protein sequence viewer
https://tools.latticeautomation.com/seqviz
MIT License
247 stars 53 forks source link

snapgene format #241

Open mcmanuslab opened 1 year ago

mcmanuslab commented 1 year ago

The bug

The goal is to display a snapgene formated file in a browser. This does not appear to be working correctly. However, a genbank formatted vector of the same file works perfectly.

Expected and observed behavior

The expected behavior is to display a map and a sequence. However, the map is missing features and a title. The sequence displays, but it appears that non-DNA text also appears.

Screenshot

Screenshot 2023-11-19 at 5 14 13 PM

The local environment:

Test code below

Screenshot 2023-11-19 at 5 38 06 PM
isaacguerreir commented 1 year ago

I think passing a File to be parsed using the file field of the Seqviz component is now deprecated.

The recommendation is to use seqparse. It seems to me the library supports Snapgene file format. I would recommend trying two alternatives. One uses an async function to the change listener so you can make use of the await syntax on seqparse.

<script src="https://unpkg.com/seqparse"></script>
document.getElementById('snapgeneFileInput').addEventListener('change', async function(event) {
<!-- some lines below -->
    var fileContent = e.target.result[0]
    var parsedFile = await seqparse(fileContent)
    window.seqviz
         .Viewer("seqvizViewer", {
              seq: parsedFile.seq,
              annotations: parsedFile.annotations,
              name: parsedFile.name,
              ....
         })
<!-- some more lines -->

The second option would be to pass a callback function on the then function to instantiate your page.

<!-- some lines below -->
    var fileContent = e.target.result[0]
    seqparse(fileContent).then((parsedFile) => {
       window.seqviz
         .Viewer("seqvizViewer", {
              seq: parsedFile.seq,
              annotations: parsedFile.annotations,
              name: parsedFile.name,
              ....
         })
    })

<!-- some more lines -->

Let us know if it works for you.

mcmanuslab commented 1 year ago

Thanks! If it's deprecated, I'll note that genebank formatted files display quite nicely-- it seems like a Snapgene format issue.

From a quick glance at the Seqparse GitHub repository, it seems that this library is primarily designed to be used in a Node.js environment or in backend Python applications, rather than directly in the browser like I am using Seqviz.

Do you know whether Seqparse is feasible in a front-end browser implementation?

isaacguerreir commented 1 year ago

Is it possible to share your snapgene file? Possibly seqparse used on the deprecated parameter file is not correct parsing your file.

jjti commented 1 year ago

Is it possible to share your snapgene file? Possibly seqparse used on the deprecated parameter file is not correct parsing your file.

I agree this is likely (a bug in seqparse). If you share the file @mcmanuslab (either the exact one or a modified one w/ the same errant behavior) we can add it to our test cases and fix it in seqparse: https://github.com/Lattice-Automation/seqparse/tree/main/src/examples/snapgene

FWIW seqviz should still work file with file input... and that's unlikely to be removed (for backwards compatibility). The flag being deprecated is to signal that seqviz is really about visualization/presentation, and parsing sequence files is a bit more business logic than should have been in the library at the start

guzmanvig commented 4 months ago

Hello @mcmanuslab , is this still an issue? If so, could you share the file that was causing the issue? Thank you!