Skip to content

Commit

Permalink
Add g2p_mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Mar 18, 2024
1 parent 41440f3 commit 89f136f
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 117 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"name": "MsaView"
},
"dependencies": {
"g2p_mapper": "^1.0.4",
"pako": "^2.1.0",
"react-msaview": "^3.0.3"
},
Expand Down
25 changes: 6 additions & 19 deletions src/MsaViewPanel/genomeToMSA.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSession, isContainedWithin } from '@jbrowse/core/util'
import { getSession } from '@jbrowse/core/util'
import { checkHovered } from './util'
import { JBrowsePluginMsaViewModel } from './model'

Expand All @@ -10,24 +10,11 @@ export function genomeToMSA({ model }: { model: JBrowsePluginMsaViewModel }) {
transcriptToMsaMap &&
checkHovered(hovered)
) {
const { coord: hoverCoord, refName: hoverRef } = hovered.hoverPosition
for (const entry of transcriptToMsaMap) {
const { featureStart, featureEnd, refName, proteinStart, strand } = entry
if (
refName === hoverRef &&
isContainedWithin(hoverCoord - 1, hoverCoord, featureStart, featureEnd)
) {
return model.seqCoordToRowSpecificGlobalCoord(
'QUERY',
Math.floor(
proteinStart +
(strand === -1
? featureEnd - hoverCoord
: hoverCoord - featureStart) /
3,
) + 1,
)
}
const { coord: hoverCoord } = hovered.hoverPosition
const { g2p } = transcriptToMsaMap
const ret = g2p[hoverCoord]
if (ret !== undefined) {
return model.seqCoordToRowSpecificGlobalCoord('QUERY', ret + 1)
}
}
return undefined
Expand Down
22 changes: 12 additions & 10 deletions src/MsaViewPanel/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@ import { Instance, addDisposer, cast, types } from 'mobx-state-tree'
import { autorun } from 'mobx'
import { MSAModelF } from 'react-msaview'

Check failure on line 3 in src/MsaViewPanel/model.ts

View workflow job for this annotation

GitHub Actions / Tests

'"react-msaview"' has no exported member named 'MSAModelF'. Did you mean 'MSAModel'?
import { Region } from '@jbrowse/core/util/types/mst'
import {
Feature,
SimpleFeature,
getSession,
notEmpty,
} from '@jbrowse/core/util'
import { Feature, getSession, notEmpty } from '@jbrowse/core/util'
import { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
import { BaseViewModel } from '@jbrowse/core/pluggableElementTypes'

// locals
import { doLaunchBlast } from './doLaunchBlast'
import { generateMap } from './util'
import { genomeToMSA } from './genomeToMSA'
import { msaCoordToGenomeCoord } from './msaCoordToGenomeCoord'
import { genomeToTranscriptSeqMapping } from 'g2p_mapper'

type LGV = LinearGenomeViewModel

type MaybeLGV = LGV | undefined

export interface IRegion {
assemblyName: string
refName: string
start: number
end: number
}

export interface BlastParams {
blastDatabase: string
msaAlgorithm: string
Expand Down Expand Up @@ -57,7 +52,13 @@ export default function stateModelFactory() {
/**
* #property
*/
connectedHighlights: types.array(Region),
connectedHighlights: types.array(
types.model({
refName: types.string,
start: types.number,
end: types.number,
}),
),
/**
* #property
*/
Expand Down Expand Up @@ -101,8 +102,9 @@ export default function stateModelFactory() {
* #getter
*/
get transcriptToMsaMap() {
console.log(self.connectedFeature)
return self.connectedFeature
? generateMap(new SimpleFeature(self.connectedFeature))
? genomeToTranscriptSeqMapping(self.connectedFeature)
: undefined
},
}))
Expand Down
44 changes: 12 additions & 32 deletions src/MsaViewPanel/msaCoordToGenomeCoord.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { doesIntersect2 } from '@jbrowse/core/util'

// locals
import { JBrowsePluginMsaViewModel } from './model'

Expand All @@ -10,40 +8,22 @@ export function msaCoordToGenomeCoord({
model: JBrowsePluginMsaViewModel
coord: number
}) {
const { transcriptToMsaMap, connectedView } = model
if (
!connectedView?.initialized ||
mouseCol === undefined ||
transcriptToMsaMap === undefined
) {
const { transcriptToMsaMap } = model
if (mouseCol === undefined || transcriptToMsaMap === undefined) {
return
}
for (const entry of transcriptToMsaMap) {
const {
featureStart,
featureEnd,
refName,
proteinStart,
proteinEnd,
strand,
} = entry
const c = mouseCol - 1
const k1 = model.seqCoordToRowSpecificGlobalCoord('QUERY', c) || 0
const k2 = model.seqCoordToRowSpecificGlobalCoord('QUERY', c + 1) || 0
if (doesIntersect2(proteinStart, proteinEnd, k1, k2)) {
// does not take into account phase, so 'incomplete CDS' might
// be buggy
const ret = Math.round((k1 - proteinStart) * 3)
const rev = strand === -1
const s = rev ? featureEnd - ret : featureStart + ret
const e = rev ? featureEnd - ret - 3 : featureStart + ret + 3
return {
assemblyName: 'hg38',

const c = mouseCol - 1
const k1 = model.globalCoordToRowSpecificSeqCoord('QUERY', c) || 0
const k2 = model.globalCoordToRowSpecificSeqCoord('QUERY', c + 1) || 0
const { refName, p2g } = transcriptToMsaMap
const s = p2g[k1]
const e = p2g[k2]
return s !== undefined && e !== undefined
? {
refName,
start: Math.min(s, e),
end: Math.max(s, e),
}
}
}
return undefined
: undefined
}
55 changes: 0 additions & 55 deletions src/MsaViewPanel/util.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,5 @@
import { Feature } from '@jbrowse/core/util'

// see similar function in protein3d plugin
export function generateMap(f: Feature) {
let iter = 0

const strand = f.get('strand')
const subs = f.children() ?? []
return strand === -1
? subs
.filter(f => f.get('type') === 'CDS')
.sort((a, b) => b.get('start') - a.get('start'))
.map(f => {
const refName = f.get('refName').replace('chr', '')
const featureStart = f.get('start')
const featureEnd = f.get('end')
const phase = f.get('phase')
const len = featureEnd - featureStart
const op = len / 3
const proteinStart = iter
const proteinEnd = iter + op
iter += op
return {
refName,
featureStart,
featureEnd,
proteinStart,
proteinEnd,
phase,
strand,
} as const
})
: subs
.filter(f => f.get('type') === 'CDS')
.sort((a, b) => a.get('start') - b.get('start'))
.map(f => {
const refName = f.get('refName').replace('chr', '')
const featureStart = f.get('start')
const featureEnd = f.get('end')
const phase = f.get('phase')
const len = featureEnd - featureStart
const op = len / 3
const proteinStart = iter
const proteinEnd = iter + op
iter += op
return {
refName,
featureStart,
featureEnd,
proteinStart,
proteinEnd,
phase,
strand,
} as const
})
}

export function checkHovered(hovered: unknown): hovered is {
hoverFeature: Feature
hoverPosition: { coord: number; refName: string }
Expand Down
65 changes: 64 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,15 @@ classnames@^2.2.6:
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.5.1.tgz#ba774c614be0f016da105c858e7159eae8e7687b"
integrity sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==

cliui@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa"
integrity sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==
dependencies:
string-width "^4.2.0"
strip-ansi "^6.0.1"
wrap-ansi "^7.0.0"

clone@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
Expand Down Expand Up @@ -1382,6 +1391,11 @@ esbuild@^0.20.2:
"@esbuild/win32-ia32" "0.20.2"
"@esbuild/win32-x64" "0.20.2"

escalade@^3.1.1:
version "3.1.2"
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.2.tgz#54076e9ab29ea5bf3d8f1ed62acffbb88272df27"
integrity sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==

escape-html@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
Expand Down Expand Up @@ -1653,13 +1667,25 @@ functions-have-names@^1.2.3:
resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834"
integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==

g2p_mapper@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/g2p_mapper/-/g2p_mapper-1.0.4.tgz#243730c33d92b093f61a18b05479465f67bd8612"
integrity sha512-Os3yuQZcTSuGbO4A7NuXmcfIu80IeOjyZYZ4Eow9Af0sb6IlcmymcA99gYjRUk4enKjRFAXjnCw6Y4rw7S7yww==
dependencies:
yargs "^17.7.2"

generic-filehandle@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/generic-filehandle/-/generic-filehandle-3.1.2.tgz#3b5f4cc927f7833d2d90157e0b12ce235526fa41"
integrity sha512-GmN3k7xfuH3Nb545WLl2ybmle4VvXbwspXtYnQZ2MpSIDbuQUoMXb2RObPgbs4wU3ggOojpGTJxYHzh3jvDkfw==
dependencies:
es6-promisify "^6.1.1"

get-caller-file@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==

get-intrinsic@^1.1.3, get-intrinsic@^1.2.1, get-intrinsic@^1.2.3, get-intrinsic@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.2.4.tgz#e385f5a4b5227d449c3eabbad05494ef0abbeadd"
Expand Down Expand Up @@ -2582,6 +2608,11 @@ regexp.prototype.flags@^1.5.0, regexp.prototype.flags@^1.5.2:
es-errors "^1.3.0"
set-function-name "^2.0.1"

require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==

reselect@^4.1.8:
version "4.1.8"
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.1.8.tgz#3f5dc671ea168dccdeb3e141236f69f02eaec524"
Expand Down Expand Up @@ -2766,7 +2797,7 @@ stockholm-js@^1.0.10:
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0:
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -3094,6 +3125,15 @@ which@^2.0.1:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand All @@ -3108,6 +3148,11 @@ wrappy@1:
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==

y18n@^5.0.5:
version "5.0.8"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==

yallist@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
Expand All @@ -3118,6 +3163,24 @@ yaml@^1.10.0:
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==

yargs-parser@^21.1.1:
version "21.1.1"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35"
integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==

yargs@^17.7.2:
version "17.7.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269"
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==
dependencies:
cliui "^8.0.1"
escalade "^3.1.1"
get-caller-file "^2.0.5"
require-directory "^2.1.1"
string-width "^4.2.3"
y18n "^5.0.5"
yargs-parser "^21.1.1"

yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
Expand Down

0 comments on commit 89f136f

Please sign in to comment.