1 | /*global Module*/ |
---|
2 | "use strict"; |
---|
3 | |
---|
4 | /** |
---|
5 | * Class to keep genotypes data |
---|
6 | */ |
---|
7 | class Genotypes { |
---|
8 | |
---|
9 | /** |
---|
10 | * Default constructor for genotypes object |
---|
11 | * @param {string} path path to .gen file with genotypes |
---|
12 | */ |
---|
13 | constructor(obj, path) { |
---|
14 | this.parent = obj; |
---|
15 | this.loaded = false; |
---|
16 | this.id = []; |
---|
17 | this.name = []; |
---|
18 | this.genotype = []; |
---|
19 | this.readGenotypesFromFile(path); |
---|
20 | |
---|
21 | } |
---|
22 | |
---|
23 | /** |
---|
24 | * Read genotypes from genotypes.gen file. |
---|
25 | * @param {string} file path to genotypes.gen |
---|
26 | */ |
---|
27 | readGenotypesFromFile(file) { |
---|
28 | let rawFile = new XMLHttpRequest(); |
---|
29 | rawFile.open("GET", file, true); |
---|
30 | rawFile.onload = (e) => { |
---|
31 | if (rawFile.readyState === 4) { |
---|
32 | if (rawFile.status === 200 || rawFile.status === 0) { |
---|
33 | this.readGenotypesFromGenotypeLoader(rawFile.responseText); |
---|
34 | } else { |
---|
35 | console.error(rawFile.statusText); |
---|
36 | } |
---|
37 | } |
---|
38 | }; |
---|
39 | rawFile.onerror = (e) => { |
---|
40 | console.error(rawFile.statusText); |
---|
41 | }; |
---|
42 | rawFile.send(null); |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * Read genotypes from text read from genotypes.gen. |
---|
47 | * @param {string} text |
---|
48 | */ |
---|
49 | readGenotypesFromGenotypeLoader(text) { |
---|
50 | let textStringFile = new Module.StringFILE2(text, 0); |
---|
51 | let genotypeLoader = new Module.GenotypeMiniLoader(textStringFile); |
---|
52 | let loaded = genotypeLoader.loadNextGenotype(); |
---|
53 | let i = 0; |
---|
54 | while (loaded.genotype.c_str()!="") |
---|
55 | { |
---|
56 | this.name.push(loaded.name.c_str()); |
---|
57 | this.genotype.push(loaded.genotype.c_str()); |
---|
58 | this.id.push(i); |
---|
59 | i++; |
---|
60 | |
---|
61 | loaded = genotypeLoader.loadNextGenotype(); |
---|
62 | } |
---|
63 | this.loaded = true; |
---|
64 | this.parent.start(); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | export default Genotypes; |
---|