diff --git a/.ignore b/.ignore new file mode 100644 index 0000000..032cdc0 --- /dev/null +++ b/.ignore @@ -0,0 +1 @@ +src/ProteinView/proteinAbbreviationMapping.ts diff --git a/src/LaunchProteinView/components/AlphaFoldDBSearch.tsx b/src/LaunchProteinView/components/AlphaFoldDBSearch.tsx index 5c3b429..8815c82 100644 --- a/src/LaunchProteinView/components/AlphaFoldDBSearch.tsx +++ b/src/LaunchProteinView/components/AlphaFoldDBSearch.tsx @@ -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 ? ( + + Searching {getDisplayName(selectedTranscript)} for UniProt ID + + ) : ( + <> + Found Uniprot ID: {foundStructureId} + {loading ? ( + + ) : success ? ( + Found structure in AlphaFoldDB + ) : ( + + No structure found for this UniProtID in AlphaFoldDB{' '} + + (search for results) + + + )} + + ) +} + +function useCheckAlphaFoldDBExistence({ + foundStructureId, +}: { + foundStructureId?: string +}) { + const [error, setError] = useState() + 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, @@ -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 ( <> -
- {e ? : null} -
- Look up AlphaFoldDB structure for given transcript -
- {seqs ? ( - <> - - {!foundStructureId && selectedTranscript ? ( - - Searching {getDisplayName(selectedTranscript)} for UniProt ID - - ) : ( - Found Uniprot ID: {foundStructureId} - )} - - ) : ( -
- -
- )} + {e ? : null} +
+ Look up AlphaFoldDB structure for given transcript
+ {seqs ? ( + <> + + {selectedTranscript ? ( + + ) : null} + + ) : ( +
+ +
+ )}