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

Fix retrieval of reference sequence #562

Merged
merged 3 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions packages/apollo-mst/src/ApolloRefSeq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export const ApolloRefSeq = types
},
addSequence(seq: SnapshotOrInstance<typeof Sequence>) {
if (seq.sequence.length !== seq.stop - seq.start) {
throw new Error('sequence does not match declared length')
throw new Error(
`sequence does not match declared length: ${JSON.stringify(seq)}`,
)
}
if (self.sequence.length === 0) {
self.sequence.push(seq)
Expand All @@ -59,7 +61,13 @@ export const ApolloRefSeq = types
stop: seq.stop,
sequence: seq.sequence,
})
newSequences.sort((s1, s2) => s1.start - s2.start)
newSequences.sort((s1, s2) => {
if (s1.start === s2.start) {
return s1.stop - s2.stop
}
return s1.start - s2.start
})

// eslint-disable-next-line unicorn/no-array-reduce
const consolidatedSequences = newSequences.reduce<SequenceSnapshot[]>(
(result, current) => {
Expand All @@ -69,10 +77,9 @@ export const ApolloRefSeq = types
}
if (lastRange.stop >= current.start) {
if (current.stop > lastRange.stop) {
const overlapLength = lastRange.stop - current.start
lastRange.stop = current.stop
lastRange.sequence += current.sequence.slice(
current.stop - lastRange.stop,
)
lastRange.sequence += current.sequence.slice(overlapLength)
}
} else {
result.push(current)
Expand All @@ -81,6 +88,13 @@ export const ApolloRefSeq = types
},
[],
)
for (const seq of consolidatedSequences) {
if (seq.sequence.length !== seq.stop - seq.start) {
throw new Error(
'Consolidated sequence does not match declared length',
)
}
}
if (
self.sequence.length === consolidatedSequences.length &&
self.sequence.every(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@
const backendDriver = dataStore.getBackendDriver(
assemblyId,
) as BackendDriver
const regions = await backendDriver.getRegions(

Check warning on line 130 in packages/jbrowse-plugin-apollo/src/ApolloSequenceAdapter/ApolloSequenceAdapter.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/ApolloSequenceAdapter/ApolloSequenceAdapter.ts#L130

Added line #L130 was not covered by tests
regionWithAssemblyName.assemblyName,
)
const region = regions.find(
(region) => region.refName === regionWithAssemblyName.refName,

Check warning on line 134 in packages/jbrowse-plugin-apollo/src/ApolloSequenceAdapter/ApolloSequenceAdapter.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/ApolloSequenceAdapter/ApolloSequenceAdapter.ts#L133-L134

Added lines #L133 - L134 were not covered by tests
)
if (!region) {
observer.error('Cannot get region')
return

Check warning on line 138 in packages/jbrowse-plugin-apollo/src/ApolloSequenceAdapter/ApolloSequenceAdapter.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/ApolloSequenceAdapter/ApolloSequenceAdapter.ts#L137-L138

Added lines #L137 - L138 were not covered by tests
}
if (regionWithAssemblyName.end > region.end) {
regionWithAssemblyName.end = region.end

Check warning on line 141 in packages/jbrowse-plugin-apollo/src/ApolloSequenceAdapter/ApolloSequenceAdapter.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/ApolloSequenceAdapter/ApolloSequenceAdapter.ts#L141

Added line #L141 was not covered by tests
}
const { seq } = await backendDriver.getSequence(regionWithAssemblyName)
observer.next(
new SimpleFeature({
Expand Down