I have a json file of protein data of mouse and human like
{
"name": "P04202",
"full_name": "Transforming growth factor beta-1 proprotein",
"symbol": "TGFB1_MOUSE",
"length": 390,
"species": "mouse",
"function": "Transforming growth factor beta-1 proprotein: Precursor of the Latency-associated peptide (LAP) and Transforming growth factor beta-1 (TGF-beta-1) chains, which constitute the regulatory and active subunit of TGF-beta-1, respectively.",
"nr_modifications": 2821,
"residues": [
{
"pos": 1,
"residue": "M",
"modifications": []
},
{
"pos": 2,
"residue": "P",
"modifications": []
},
...
{
"pos": 60,
"residue": "A",
"modifications": [
{
"mod": "[127] Fluoro",
"type": "Chemical derivative",
"prob": 1
},
{
"mod": "[53] HNE",
"type": "Post-translational",
"prob": 0.25
}
]
},
...
]
}
How do I create a scatter plot [![enter image description here][1]][1]
Thanks for any idea
So far I gathered a code to fetch the data from an online json
export const load = ({ fetch }) => {
const fetchProteins = async () => {
const res = await fetch('https:address/assets/ptm.json')
const data = await res.json()
return data
}
return {
Proteins: fetchProteins()
}
}
This code generates a scatter plot but I will need to hover around the dots
script>
import { extent } from 'd3-array';
import { scaleLinear } from 'd3-scale';
export let data = [];
const margin = 30;
$: xScale = scaleLinear()
.domain(extent(data.proteins.map((d) => d.length)))
.range([0, 800 - (margin * 2)]);
$: yScale = scaleLinear()
.domain(extent(data.proteins.map((d) => d.nr_modifications)))
.range([0, 400 - (margin * 2)]);
</script>
<svg width="800" height="400">
<g transform="translate({margin}, {margin})">
{#each data.proteins as datapoint}
<circle
cx={xScale(datapoint.length)}
cy={yScale(datapoint.nr_modifications)}
class:human={datapoint.species === 'human'}
r="20"
/>
{/each}
<circle
cx={10}
cy={10}
class="human"
r="10"
/>
<circle
cx={10}
cy={40}
class="mouse"
r="10"
/>
</g>
</svg>
<style>
svg {
border: 1px;
border-style: solid;
}
circle {
fill: steelblue;
fill-opacity: 0.5;
}
.human {
fill: red;
}
</style>