Skip to content

Commit 606648f

Browse files
committed
Crazy
1 parent d805079 commit 606648f

2 files changed

Lines changed: 52 additions & 35 deletions

File tree

src/LinearMafDisplay/components/GetSequenceDialog/index.tsx

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import React, { useEffect, useState } from 'react'
22

33
import { Dialog, ErrorMessage, LoadingEllipses } from '@jbrowse/core/ui'
4-
import { getContainingView, getSession } from '@jbrowse/core/util'
5-
import { getRpcSessionId } from '@jbrowse/core/util/tracks'
4+
import { getSession } from '@jbrowse/core/util'
65
import { Button, DialogActions, DialogContent, TextField } from '@mui/material'
76
import { observer } from 'mobx-react'
87
import { makeStyles } from 'tss-react/mui'
98

9+
import { fetchSequences } from '../../../util/fetchSequences'
1010
import type { LinearMafDisplayModel } from '../../stateModel'
11-
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
1211

1312
const useStyles = makeStyles()({
1413
dialogContent: {
@@ -36,7 +35,6 @@ const SequenceDialog = observer(function ({
3635
dragEndX: number
3736
}
3837
}) {
39-
const { samples } = model
4038
const [sequence, setSequence] = useState<string>('')
4139
const [loading, setLoading] = useState(true)
4240
const [error, setError] = useState<unknown>()
@@ -53,38 +51,9 @@ const SequenceDialog = observer(function ({
5351

5452
try {
5553
setLoading(true)
56-
setError(null)
54+
setError(undefined)
5755

58-
const { rpcManager } = getSession(model)
59-
const sessionId = getRpcSessionId(model)
60-
const view = getContainingView(model) as LinearGenomeViewModel
61-
const { refName, assemblyName } = view.displayedRegions[0]!
62-
const { dragStartX, dragEndX } = selectionCoords
63-
const [s, e] = [
64-
Math.min(dragStartX, dragEndX),
65-
Math.max(dragStartX, dragEndX),
66-
]
67-
68-
const fastaSequence = await rpcManager.call(
69-
sessionId,
70-
'MafGetSequences',
71-
{
72-
sessionId,
73-
adapterConfig: model.adapterConfig,
74-
samples,
75-
regions: [
76-
{
77-
refName,
78-
start: view.pxToBp(s).coord,
79-
end: view.pxToBp(e).coord,
80-
assemblyName,
81-
},
82-
],
83-
},
84-
)
85-
86-
// Set the sequence data
87-
setSequence(fastaSequence as string)
56+
setSequence(await fetchSequences({ model, selectionCoords }))
8857
} catch (e) {
8958
console.error(e)
9059
setError(e)

src/util/fetchSequences.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { getContainingView, getSession } from '@jbrowse/core/util'
2+
import { getRpcSessionId } from '@jbrowse/core/util/tracks'
3+
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
4+
import type { LinearMafDisplayModel } from '../LinearMafDisplay/stateModel'
5+
6+
/**
7+
* Fetch sequences for the given selection coordinates
8+
* @param model - The LinearMafDisplayModel
9+
* @param selectionCoords - The selection coordinates (dragStartX and dragEndX)
10+
* @returns Promise that resolves to the FASTA sequence
11+
*/
12+
export async function fetchSequences({
13+
model,
14+
selectionCoords,
15+
}: {
16+
model: LinearMafDisplayModel
17+
selectionCoords: {
18+
dragStartX: number
19+
dragEndX: number
20+
}
21+
}): Promise<string> {
22+
const { samples, adapterConfig } = model
23+
const { rpcManager } = getSession(model)
24+
const sessionId = getRpcSessionId(model)
25+
const view = getContainingView(model) as LinearGenomeViewModel
26+
const { refName, assemblyName } = view.displayedRegions[0]!
27+
const { dragStartX, dragEndX } = selectionCoords
28+
const [s, e] = [
29+
Math.min(dragStartX, dragEndX),
30+
Math.max(dragStartX, dragEndX),
31+
]
32+
33+
const fastaSequence = await rpcManager.call(sessionId, 'MafGetSequences', {
34+
sessionId,
35+
adapterConfig,
36+
samples,
37+
regions: [
38+
{
39+
refName,
40+
start: view.pxToBp(s).coord,
41+
end: view.pxToBp(e).coord,
42+
assemblyName,
43+
},
44+
],
45+
})
46+
47+
return fastaSequence as string
48+
}

0 commit comments

Comments
 (0)