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

Defined color function prevents saving igv session. #1541

Open
SchwarzMarek opened this issue Sep 5, 2022 · 5 comments
Open

Defined color function prevents saving igv session. #1541

SchwarzMarek opened this issue Sep 5, 2022 · 5 comments

Comments

@SchwarzMarek
Copy link
Contributor

When I have defined function for coloring features loaded in annotation track it prevents me from storing the session object with the

browser.toJSON() and browser.loadSessionObject() functionality.

Console log from [igv.min.js:72:216962]

# [igv.min.js:72:216771]
Track: yyy: Error: Property 'color' of track 'yyy is a function. Functions cannot be saved in sessions.

# [igv.min.js:72:216962]
Uncaught Error: Errors encountered saving session: </br> (1) Track: yyy: Error: Property 'color' of track 'yyy is a function. Functions cannot be saved in sessions. <br/>

Is there any solution apart from removing the color function?

If more details are needed, or there is some sensible workaround that I'm missing, do tell please.

Best regards
Marek

@jrobinso
Copy link
Contributor

jrobinso commented Sep 5, 2022

Its not possible to save functions as text, so I don't have any solution. If you have suggestions which would not open igv.js to code injection vulnerabilities please post them for discussion.

I will update the documentation to make this clear.

@jrobinso
Copy link
Contributor

jrobinso commented Sep 5, 2022

If you could describe your use case in some detail there might be a workaround for specific cases.

@SchwarzMarek
Copy link
Contributor Author

Thank you for your fast response.

I have a presentation with igv.js where user can choose which predefined tracks are loaded into the igv view. I also wanted to incorporate the multi-view option and since I didn't find any function (there may be one, but I haven't found it) that would allow me to specify mutliple locations once the igv, I figured, that to preserve the user-chosen tracks, it should be possible to save the current igv state, rewrite the location specification in the object and load it back. This works well, except for the tracks with custom function for color specification.

As to the code injection vulnerabilities I'm no expert in javascript but I think that it should be possible to have the function pre-defined at the web-page context and then have the igv look for function with such name (I imagine an attribute with the browser variable, some immutable object accessed in key-value manner)?

Since my usage of the store/load is workaround itself it might suffice to have the ability to pass location in the browser API. However, I easily can imagine a case when user can store browser configuration to have it loaded with selected tracks when he comes back. Then it would be useful to have it possible to store the session even with functions in tracks.

Other possible workaround that occurs to me is to precompute the color specification and store it with the annotations.

@jrobinso
Copy link
Contributor

jrobinso commented Sep 6, 2022

For multi-view you can pass a space delimited list of loci to the "search" function. I just noticed this was not documented, it is now, for example

browser.search('chr10:1000-2000' 'EGFR')

RE code injection, yes that was exactly the solution I thought of as well. This will require some development in igv.js, obviously. Leave this open until I have more time to consider how best to do this.

Another possible workaround, which may or may not work for you, is to use a lookup table for color instead of a function. See examples/gff-colors.html and examples/variant-colors.html

                        name: "Color by source",
                        format: "gff3",
                        displayMode: "expanded",
                        height: 300,
                        url: "https://s3.amazonaws.com/igv.org.genomes/hg38/Homo_sapiens.GRCh38.94.chr.gff3.gz",
                        indexURL: "https://s3.amazonaws.com/igv.org.genomes/hg38/Homo_sapiens.GRCh38.94.chr.gff3.gz.tbi",
                        visibilityWindow: 1000000,
                        colorBy: "source",
                        colorTable: {
                            "Ensembl": "blueviolet",
                            "ensembl": "blueviolet",
                            "ensembl_havana": "purple",
                            "havana": "blue",
                            "insdc": "#7fff00",
                            "mirbase": "#d2691e",
                            "*": "black"
                        }
                    }

@SchwarzMarek
Copy link
Contributor Author

Thank you for the browser.search, this works well currently my intended purpose.

Leaving this open as requested.

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