Commit 83d36367 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

Calculate gene position depending on begin and end

parent 4f4f7c21
import { GeneData, PositionedGeneData } from "../component/sequence/gene";
import { scaleLinear } from "d3-scale";
import { extent } from "d3-array";
export default function linearGene(
data: Array<GeneData>,
width: number,
geneOffset: number
) {
const sumLength = data.reduce((accum, gene) => accum + gene.length, 0);
const sumGeneOffset = (data.length - 1) * geneOffset;
const xScale = scaleLinear().domain([0, sumLength - sumGeneOffset]).range([0, width])
const sequenceInterval = extent(data.reduce(
(accum, gene) => [...accum, gene.begin, gene.end],
[] as Array<number>
));
const xScale = scaleLinear()
.domain([sequenceInterval[0] || 0, sequenceInterval[1] || 0])
.range([0, width])
return data.reduce(function (
accum: PositionedGeneData[],
......@@ -16,32 +22,17 @@ export default function linearGene(
i: number,
data: GeneData[]
) {
if (i > 0) {
const previousGene = accum[i - 1];
accum.push({
...gene,
position: {
x: previousGene.position.x + previousGene.position.width + geneOffset,
y: 0,
width: xScale(gene.length)
}
});
return accum;
}
else {
accum.push({
...gene,
position: {
x: 0,
y: 0,
width: xScale(gene.length)
}
});
return accum;
}
const x = xScale(gene.begin);
const width = xScale(gene.end) - x;
accum.push({
...gene,
position: {
x,
y: 0,
width
}
});
return accum;
}, []);
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment