From cfbaa397354d8f82e220cd05fc8de837412d8908 Mon Sep 17 00:00:00 2001 From: Shashank B R Date: Wed, 25 Oct 2023 21:00:22 +0100 Subject: [PATCH] Fix crash with very long features (#282) * limit feature min max to 500000 bp * feature min max limit * change --- .../LinearApolloDisplay/stateModel/layouts.ts | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/layouts.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/layouts.ts index 84349c72..4232e9ac 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/layouts.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloDisplay/stateModel/layouts.ts @@ -16,6 +16,9 @@ export function layoutsModelFactory( const BaseLinearApolloDisplay = baseModelFactory(pluginManager, configSchema) return BaseLinearApolloDisplay.named('LinearApolloDisplayLayouts') + .props({ + featuresMinMaxLimit: 500_000, + }) .volatile(() => ({ seenFeatures: observable.map(), })) @@ -31,7 +34,8 @@ export function layoutsModelFactory( for (const [, feature] of self.seenFeatures) { if ( refName !== assembly?.getCanonicalRefName(feature.refSeq) || - !doesIntersect2(start, end, feature.min, feature.max) + !doesIntersect2(start, end, feature.min, feature.max) || + feature.length > self.featuresMinMaxLimit ) { continue } @@ -118,9 +122,13 @@ export function layoutsModelFactory( feature.max - feature.min === 0 ? feature.min + 1 : feature.max - return rowForFeature - .slice(feature.min - min, featureMax - min) - .some(Boolean) + let start = feature.min - min, + end = featureMax - min + if (feature.min - min < 0) { + start = 0 + end = featureMax - feature.min + } + return rowForFeature.slice(start, end).some(Boolean) }) .some(Boolean) ) { @@ -133,7 +141,13 @@ export function layoutsModelFactory( rowNum++ ) { const row = rows[rowNum] - row.fill(true, feature.min - min, feature.max - min) + let start = feature.min - min, + end = feature.max - min + if (feature.min - min < 0) { + start = 0 + end = feature.max - feature.min + } + row.fill(true, start, end) const layoutRow = featureLayout.get(rowNum) layoutRow?.push([rowNum - startingRow, feature]) }