index.ts 1.75 KB
Newer Older
1
import GeneComponent, { GeneData } from "./component/sequence/gene";
Remi  PLANEL's avatar
Remi PLANEL committed
2
import GenomeAxis from "./component/sequence/genome-axis";
Remi  PLANEL's avatar
Remi PLANEL committed
3
import { select } from "d3-selection";
4
import { of } from "rxjs";
Remi  PLANEL's avatar
Remi PLANEL committed
5
6

const width = 1500;
7
const genomeWindowSize = 6000;
Remi  PLANEL's avatar
Remi PLANEL committed
8
const geneComponent = GeneComponent();
Remi  PLANEL's avatar
Remi PLANEL committed
9
const genomeAxis = GenomeAxis();
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const clickHandler = ([begin, end]: [number, number]) => draw((end + begin) / 2);
const genes: Array<GeneData> = [
    {
        name: "gene 1",
        strand: "-",
        begin: 20815,
        end: 21078,
        gene: "insA",
        eventHandler: {
            click: clickHandler
        }
    },
    {
        name: "gene 2",
        strand: "+",
        begin: 21181,
        end: 21399,
        gene: "yaaY",
        eventHandler: {
            click: clickHandler
        }
    },
    {
        name: "gene 3", strand: "+", begin: 21407, end: 22348, gene: "ribF", eventHandler: {
            click: clickHandler
        }
    },
    {
        name: "gene 4", strand: "+", begin: 22391, end: 25207, gene: "ileS", eventHandler: {
            click: clickHandler
        }
    }
]
Remi  PLANEL's avatar
Remi PLANEL committed
43

Remi  PLANEL's avatar
Remi PLANEL committed
44
45


46
47
48
49
50
51
52
53
54
55
56
57
function draw(centerGenome: number) {
    const svg = select<SVGSVGElement, any>("svg").attr("width", width + 100).attr("height", 900);
    const genomeAxisElem = svg.select<SVGElement>("#axis");
    const geneElem = svg.select<SVGElement>("#genes");
    genomeAxisElem
        .datum(getGenomeWindow(centerGenome, genomeWindowSize))
        .call(genomeAxis, width, 0);
    geneElem
        .datum<Array<GeneData>>(genes)
        .call(geneComponent, genomeAxis.scale(), 40);
}
draw(23000);
Remi  PLANEL's avatar
Remi PLANEL committed
58
59
60
61
62
function getGenomeWindow(middle: number, genomeWindowSize: number): [number, number] {
    const halfWindow = genomeWindowSize / 2;
    return [middle - halfWindow, middle + halfWindow]

}