@@ -117,15 +117,11 @@ async function main(container, config) {
117117 // Initialize igv.js, creating the Browser instance
118118 const igvConfig = config . igvConfig
119119
120- // The configuration as given, before the last genome used is applied to it, and before igv.createBrowser merges
121- // the query parameters into it. A failed start is retried from this copy.
122- const configuredIgvConfig = { ...igvConfig , tracks : [ ...( igvConfig . tracks || [ ] ) ] , queryParametersSupported : false }
123-
124120 // Optionally change the igv genome to the last genome used.
125121 if ( config . restoreLastGenome ) {
126122 try {
127123 const lastGenomeId = localStorage . getItem ( "genomeID" )
128- if ( lastGenomeId && lastGenomeId !== configuredIgvConfig . genome ) {
124+ if ( lastGenomeId && lastGenomeId !== igvConfig . genome ) {
129125 if ( config . genomes && config . genomes . find ( elem => elem . id === lastGenomeId ) ||
130126 ( recentGenomes && recentGenomes . find ( elem => elem . id === lastGenomeId ) ) ||
131127 ( ( lastGenomeId . startsWith ( "GCA_" ) || lastGenomeId . startsWith ( "GCF_" ) ) && lastGenomeId . length >= 13 ) ) {
@@ -141,57 +137,25 @@ async function main(container, config) {
141137 // session is patched before the browser is created, so it opens at the requested locus directly.
142138 const sessionConfig = await loadSessionWithLocusOverride ( igvConfig )
143139
144- let browserConfig = sessionConfig || igvConfig
145- let { browser, error} = await tryCreateBrowser ( container , browserConfig )
146-
147- if ( error ) {
148- // A session is either merged into sessionConfig, or, when it was left to igv.js to load, visible in
149- // igvConfig, as is a genome from the query parameters (as genome, reference, or genarkAccession).
150- const failedSession = sessionConfig || igvConfig . sessionURL || igvConfig . session || igvConfig . hubURL
151- const failedOtherGenome = [ 'genome' , 'reference' , 'genarkAccession' ] . some ( key => igvConfig [ key ] !== configuredIgvConfig [ key ] )
152-
153- if ( failedSession ) {
154- // The session was explicitly requested, so report the failure, then continue without it.
155- alertSingleton . present ( error )
156- }
157-
158- if ( failedSession || failedOtherGenome ) {
159- // Retry with the genome from the configuration file, and no session.
160- browserConfig = { ...configuredIgvConfig }
161- delete browserConfig . sessionURL
162- delete browserConfig . session
163- delete browserConfig . hubURL
164- ; ( { browser, error} = await tryCreateBrowser ( container , browserConfig ) )
165- }
166- }
167-
168- if ( error ) {
169- // The genome from the configuration file failed to load. Report it, and load the first other genome from the
170- // genome list, so the app is usable and another genome can be chosen from the menu. Any other failure ends
171- // the startup.
172- const fallbackGenome = isGenomeLoadError ( error ) && config . genomes ?
173- config . genomes . find ( ( { id} ) => id !== configuredIgvConfig . genome ) :
174- undefined
175- if ( ! fallbackGenome ) {
176- alertSingleton . present ( error )
177- return
178- }
179- const genomeError = error
180- browserConfig = { ...configuredIgvConfig , genome : fallbackGenome . id , tracks : [ ] }
181- delete browserConfig . reference
182- delete browserConfig . genarkAccession
183- ; ( { browser, error} = await tryCreateBrowser ( container , browserConfig ) )
184- if ( error ) {
185- alertSingleton . present ( error )
140+ // igv.createBrowser leaves the browser in the page when it fails, on error.browser. Report the failure and
141+ // continue with that browser: if the failure came before a genome was set (the session, or the genome itself) it
142+ // has an empty genome, and a genome can be chosen from the Genome menu.
143+ let browser
144+ try {
145+ browser = await igv . createBrowser ( container , sessionConfig || igvConfig )
146+ } catch ( error ) {
147+ console . error ( error )
148+ alertSingleton . present ( error )
149+ browser = error . browser
150+ if ( ! browser ) {
186151 return
187152 }
188- alertSingleton . present ( new Error ( `${ genomeError . message } \n\nLoaded ${ fallbackGenome . name || fallbackGenome . id } instead.` ) )
189153 }
190154 Globals . browser = browser
191155
192156 if ( ! sessionConfig ) {
193157 // The session was loaded by igv.js, which ignores the locus parameter in favor of the session's own locus.
194- await applyLocusParameter ( browser , browserConfig )
158+ await applyLocusParameter ( browser , igvConfig )
195159 }
196160
197161 const igvMain = document . getElementById ( 'igv-main' )
@@ -518,41 +482,6 @@ async function applyLocusParameter(browser, igvConfig) {
518482 }
519483}
520484
521- /**
522- * Create the igv.js browser, returning it as {browser}, or the error it failed with as {error}.
523- */
524- async function tryCreateBrowser ( container , igvConfig ) {
525- try {
526- return { browser : await igv . createBrowser ( container , igvConfig ) }
527- } catch ( error ) {
528- console . error ( error )
529- removeOrphanedBrowsers ( )
530- return { error}
531- }
532- }
533-
534- /**
535- * Whether an igv.createBrowser failure is the genome failing to load, as opposed to a session, sample info, or
536- * anything else. igv.js reports a genome failure with a message that leads with the genome: "Genome hg38 could not be
537- * loaded: ..." or "The genome could not be loaded.", and a genome id it does not know with "Unknown genome id: ...".
538- */
539- function isGenomeLoadError ( error ) {
540- return / ^ ( ( G e n o m e .* | T h e g e n o m e ) c o u l d n o t b e l o a d e d | U n k n o w n g e n o m e i d ) / . test ( error . message || '' )
541- }
542-
543- /**
544- * Remove any igv.js browser instances left behind by a failed igv.createBrowser call. createBrowser inserts the
545- * browser into the DOM before loading the session, genome, and tracks, so a load failure leaves a non-functional
546- * instance in the container with no handle returned to the caller.
547- */
548- function removeOrphanedBrowsers ( ) {
549- try {
550- igv . removeAllBrowsers ( )
551- } catch ( e ) {
552- console . error ( e )
553- }
554- }
555-
556485function createAppBookmarkHandler ( $bookmark_button ) {
557486
558487 $bookmark_button . on ( 'click' , ( e ) => {
0 commit comments