Skip to content

Commit

Permalink
Report structure existance on alphafolddb
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 27, 2024
1 parent 0fbdbab commit 86334a7
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 72 deletions.
1 change: 1 addition & 0 deletions .ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/ProteinView/proteinAbbreviationMapping.ts
132 changes: 101 additions & 31 deletions src/LaunchProteinView/components/AlphaFoldDBSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,80 @@ import useMyGeneInfo from '../useMyGeneInfo'
import useAllSequences from '../useProteinSequences'

const useStyles = makeStyles()(theme => ({
section: {
marginTop: theme.spacing(6),
},
dialogContent: {
marginTop: theme.spacing(6),
width: '80em',
},
}))

type LGV = LinearGenomeViewModel

function SearchStatus({
foundStructureId,
selectedTranscript,
success,
loading,
}: {
foundStructureId?: string
selectedTranscript: Feature
success: boolean
loading: boolean
}) {
return !foundStructureId ? (
<Typography>
Searching {getDisplayName(selectedTranscript)} for UniProt ID
</Typography>
) : (
<>
<Typography>Found Uniprot ID: {foundStructureId}</Typography>
{loading ? (
<LoadingEllipses title="Looking up structure in AlphaFoldDB" />
) : success ? (
<Typography>Found structure in AlphaFoldDB</Typography>
) : (
<Typography>
No structure found for this UniProtID in AlphaFoldDB{' '}
<a
href={`https://alphafold.ebi.ac.uk/search/text/${foundStructureId}`}
>
(search for results)
</a>
</Typography>
)}
</>
)
}

function useCheckAlphaFoldDBExistence({
foundStructureId,
}: {
foundStructureId?: string
}) {
const [error, setError] = useState<unknown>()
const [loading, setLoading] = useState(false)
const [success, setSuccess] = useState(false)
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
try {
if (foundStructureId) {
setLoading(true)
await fetch(
`https://alphafold.ebi.ac.uk/files/AF-${foundStructureId}-F1-model_v4.cif`,
{ method: 'HEAD' },
)
setLoading(false)
setSuccess(true)
}
} catch (e) {
console.error(e)
setError(e)
}
})()
}, [foundStructureId])
return { error, loading, success }
}

const MyGeneInfoSearch = observer(function MyGeneInfoSearch({
feature,
model,
Expand Down Expand Up @@ -66,40 +130,46 @@ const MyGeneInfoSearch = observer(function MyGeneInfoSearch({
setUserSelection(options.find(f => !!seqs[f.id()])?.id())
}
}, [options, userSelection, seqs])
const {
success,
loading,
error: error3,
} = useCheckAlphaFoldDBExistence({
foundStructureId,
})

const e = error || error2
const e = error || error2 || error3
const url = `https://alphafold.ebi.ac.uk/files/AF-${foundStructureId}-F1-model_v4.cif`
return (
<>
<DialogContent className={classes.dialogContent}>
<div className={classes.section}>
{e ? <ErrorMessage error={e} /> : null}
<div>
Look up AlphaFoldDB structure for given transcript <HelpButton />
</div>
{seqs ? (
<>
<TranscriptSelector
val={userSelection ?? ''}
setVal={setUserSelection}
options={options}
feature={feature}
seqs={seqs}
/>
{!foundStructureId && selectedTranscript ? (
<Typography>
Searching {getDisplayName(selectedTranscript)} for UniProt ID
</Typography>
) : (
<Typography>Found Uniprot ID: {foundStructureId}</Typography>
)}
</>
) : (
<div style={{ margin: 20 }}>
<LoadingEllipses title="Loading protein sequences" variant="h6" />
</div>
)}
{e ? <ErrorMessage error={e} /> : null}
<div>
Look up AlphaFoldDB structure for given transcript <HelpButton />
</div>
{seqs ? (
<>
<TranscriptSelector
val={userSelection ?? ''}
setVal={setUserSelection}
options={options}
feature={feature}
seqs={seqs}
/>
{selectedTranscript ? (
<SearchStatus
foundStructureId={foundStructureId}
selectedTranscript={selectedTranscript}
success={success}
loading={loading}
/>
) : null}
</>
) : (
<div style={{ margin: 20 }}>
<LoadingEllipses title="Loading protein sequences" variant="h6" />
</div>
)}
</DialogContent>
<DialogActions>
<Button
Expand Down
2 changes: 1 addition & 1 deletion src/ProteinView/components/HelpDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function HelpDialog({
</Typography2>
<Typography2>
If you need a 100% fidelity protein, you can do a folding with e.g.
AlphaFold to make sure the stucture you are using matches exactly the
AlphaFold to make sure the structure you are using matches exactly the
sequence of the transcript
</Typography2>
</DialogContent>
Expand Down
8 changes: 4 additions & 4 deletions src/ProteinView/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ function stateModelFactory() {
/**
* #getter
*/
get transcriptSeqToStructureSeqPositon() {
get transcriptSeqToStructureSeqPosition() {
return self.alignment
? structureSeqVsTranscriptSeqMap(self.alignment)
.transcriptSeqToStructureSeqPositon
.transcriptSeqToStructureSeqPosition
: undefined
},
/**
Expand Down Expand Up @@ -315,7 +315,7 @@ function stateModelFactory() {
autorun(() => {
const { hovered } = getSession(self)
const {
transcriptSeqToStructureSeqPositon,
transcriptSeqToStructureSeqPosition,
genomeToTranscriptSeqMapping,
connectedView,
} = self
Expand All @@ -330,7 +330,7 @@ function stateModelFactory() {
const pos =
genomeToTranscriptSeqMapping.g2p[hovered.hoverPosition.coord]
const c0 = pos
? transcriptSeqToStructureSeqPositon?.[pos]
? transcriptSeqToStructureSeqPosition?.[pos]
: undefined
if (c0 !== undefined) {
self.setHoveredPosition({
Expand Down
24 changes: 24 additions & 0 deletions src/ProteinView/proteinAbbreviationMapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const proteinAbbreviationMapping = Object.fromEntries(
[
{ name: 'alanine', abbreviation: 'Ala', singleLetterCode: 'A' },
{ name: 'arginine', abbreviation: 'Arg', singleLetterCode: 'R' },
{ name: 'asparagine', abbreviation: 'Asn', singleLetterCode: 'N' },
{ name: 'aspartic acid', abbreviation: 'Asp', singleLetterCode: 'D' },
{ name: 'cysteine', abbreviation: 'Cys', singleLetterCode: 'C' },
{ name: 'glutamic acid', abbreviation: 'Glu', singleLetterCode: 'E' },
{ name: 'glutamine', abbreviation: 'Gln', singleLetterCode: 'Q' },
{ name: 'glycine', abbreviation: 'Gly', singleLetterCode: 'G' },
{ name: 'histidine', abbreviation: 'His', singleLetterCode: 'H' },
{ name: 'isoleucine', abbreviation: 'Ile', singleLetterCode: 'I' },
{ name: 'leucine', abbreviation: 'Leu', singleLetterCode: 'L' },
{ name: 'lysine', abbreviation: 'Lys', singleLetterCode: 'K' },
{ name: 'methionine', abbreviation: 'Met', singleLetterCode: 'M' },
{ name: 'phenylalanine', abbreviation: 'Phe', singleLetterCode: 'F' },
{ name: 'proline', abbreviation: 'Pro', singleLetterCode: 'P' },
{ name: 'serine', abbreviation: 'Ser', singleLetterCode: 'S' },
{ name: 'threonine', abbreviation: 'Thr', singleLetterCode: 'T' },
{ name: 'tryptophan', abbreviation: 'Trp', singleLetterCode: 'W' },
{ name: 'tyrosine', abbreviation: 'Tyr', singleLetterCode: 'Y' },
{ name: 'valine', abbreviation: 'Val', singleLetterCode: 'V' },
].map(r => [r.abbreviation.toUpperCase(), r]),
)
25 changes: 0 additions & 25 deletions src/ProteinView/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,6 @@ import { Feature } from '@jbrowse/core/util'
import { Structure } from 'molstar/lib/mol-model/structure'
import { Script } from 'molstar/lib/mol-script/script'

export const proteinAbbreviationMapping = Object.fromEntries(
[
{ name: 'alanine', abbreviation: 'Ala', singleLetterCode: 'A' },
{ name: 'arginine', abbreviation: 'Arg', singleLetterCode: 'R' },
{ name: 'asparagine', abbreviation: 'Asn', singleLetterCode: 'N' },
{ name: 'aspartic acid', abbreviation: 'Asp', singleLetterCode: 'D' },
{ name: 'cysteine', abbreviation: 'Cys', singleLetterCode: 'C' },
{ name: 'glutamic acid', abbreviation: 'Glu', singleLetterCode: 'E' },
{ name: 'glutamine', abbreviation: 'Gln', singleLetterCode: 'Q' },
{ name: 'glycine', abbreviation: 'Gly', singleLetterCode: 'G' },
{ name: 'histidine', abbreviation: 'His', singleLetterCode: 'H' },
{ name: 'isoleucine', abbreviation: 'Ile', singleLetterCode: 'I' },
{ name: 'leucine', abbreviation: 'Leu', singleLetterCode: 'L' },
{ name: 'lysine', abbreviation: 'Lys', singleLetterCode: 'K' },
{ name: 'methionine', abbreviation: 'Met', singleLetterCode: 'M' },
{ name: 'phenylalanine', abbreviation: 'Phe', singleLetterCode: 'F' },
{ name: 'proline', abbreviation: 'Pro', singleLetterCode: 'P' },
{ name: 'serine', abbreviation: 'Ser', singleLetterCode: 'S' },
{ name: 'threonine', abbreviation: 'Thr', singleLetterCode: 'T' },
{ name: 'tryptophan', abbreviation: 'Trp', singleLetterCode: 'W' },
{ name: 'tyrosine', abbreviation: 'Tyr', singleLetterCode: 'Y' },
{ name: 'valine', abbreviation: 'Val', singleLetterCode: 'V' },
].map(r => [r.abbreviation.toUpperCase(), r]),
)

export function checkHovered(hovered: unknown): hovered is {
hoverFeature: Feature
hoverPosition: { coord: number; refName: string }
Expand Down
2 changes: 1 addition & 1 deletion src/__snapshots__/mappings.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ exports[`test 1`] = `
"611": 219,
"612": 220,
},
"transcriptSeqToStructureSeqPositon": {
"transcriptSeqToStructureSeqPosition": {
"0": 392,
"1": 393,
"10": 402,
Expand Down
8 changes: 4 additions & 4 deletions src/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function structureSeqVsTranscriptSeqMap(alignment: Alignment) {
string,
number | undefined
>
const transcriptSeqToStructureSeqPositon = {} as Record<
const transcriptSeqToStructureSeqPosition = {} as Record<
string,
number | undefined
>
Expand All @@ -32,7 +32,7 @@ export function structureSeqVsTranscriptSeqMap(alignment: Alignment) {

if (c1 === c2) {
structureSeqToTranscriptSeqPosition[j] = k
transcriptSeqToStructureSeqPositon[k] = j
transcriptSeqToStructureSeqPosition[k] = j
k++
j++
} else if (c2 === '-') {
Expand All @@ -41,15 +41,15 @@ export function structureSeqVsTranscriptSeqMap(alignment: Alignment) {
k++
} else {
structureSeqToTranscriptSeqPosition[j] = k
transcriptSeqToStructureSeqPositon[k] = j
transcriptSeqToStructureSeqPosition[k] = j

k++
j++
}
}
return {
structureSeqToTranscriptSeqPosition,
transcriptSeqToStructureSeqPositon,
transcriptSeqToStructureSeqPosition,
}
}

Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2241,9 +2241,9 @@
"@types/react" "*"

"@types/react@*", "@types/react@^18.2.54":
version "18.2.59"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.59.tgz#14c7bcab22e2ce71d9eaa02f78d3d55067724d7f"
integrity sha512-DE+F6BYEC8VtajY85Qr7mmhTd/79rJKIHCg99MU9SWPB4xvLb6D1za2vYflgZfmPqQVEr6UqJTnLXEwzpVPuOg==
version "18.2.60"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.60.tgz#df026eaef1100b6dafe420f36fecb1d209a8cee1"
integrity sha512-dfiPj9+k20jJrLGOu9Nf6eqxm2EyJRrq2NvwOFsfbb7sFExZ9WELPs67UImHj3Ayxg8ruTtKtNnbjaF8olPq0A==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
Expand Down Expand Up @@ -3048,9 +3048,9 @@ camelcase@^7.0.0:
integrity sha512-xlx1yCK2Oc1APsPXDL2LdlNP6+uu8OCDdhOBSVT279M/S+y75O30C2VuD8T2ogdePBBl7PfPF4504tnLgX3zfw==

caniuse-lite@^1.0.30001587:
version "1.0.30001589"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001589.tgz#7ad6dba4c9bf6561aec8291976402339dc157dfb"
integrity sha512-vNQWS6kI+q6sBlHbh71IIeC+sRwK2N3EDySc/updIGhIee2x5z00J4c1242/5/d6EpEMdOnk/m+6tuk4/tcsqg==
version "1.0.30001591"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001591.tgz#16745e50263edc9f395895a7cd468b9f3767cf33"
integrity sha512-PCzRMei/vXjJyL5mJtzNiUCKP59dm8Apqc3PH8gJkMnMXZGox93RbE76jHsmLwmIo6/3nsYIpJtx0O7u5PqFuQ==

canvas-sequencer@^3.1.0:
version "3.1.0"
Expand Down

0 comments on commit 86334a7

Please sign in to comment.