-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
76 lines (65 loc) · 1.91 KB
/
server.js
1
2
3
4
5
6
7
8
9
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const express = require("express");
const bodyParser = require("body-parser");
const config = require("./config");
const parseFile = require("./parseFile");
const database = require("./database");
const app = new express();
const fs = require("fs");
const csvWriter = require("csv-write-stream");
const writer = csvWriter();
const gene_details = fs.readFileSync(
"fasta_file_samples/GeneDetails.txt",
"utf8"
);
writer.pipe(
fs.createWriteStream("./gene.csv"),
{ flags: "a" }
);
app.use(bodyParser.json({ limit: "10mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "10mb", extended: true }));
app.get("/", (req, res) => {
console.log("Got connection");
res.status(200).send({
message: "hello"
});
});
app.get("/genes",(req, res) => {
database.readGenes("complete_gene",(result)=>{
// console.log(result);
res.status(200).send(result);
});
});
app.post("/upload", function (req, res) {
console.log("upload");
let data = parseFile.handleFileChosen(req.body.files);
if (data != null) {
let details = parseFile.getDetails(gene_details);
// console.log(details);
console.log("done");
database.insert("gene_data", data);
database.insert("gene_details", details);
let complete_gene = [];
for (let k = 0; k < data.length; k++) {
for (let l = 0; l < details.length; l++) {
if (data[k]["Location"] == details[l]["Location"]) {
if (data[k]["correct"] == false) {
console.log(`Stop codon found in gene ${details[l]["Gene"]}`)
}
complete_gene.push({
...data[k], ...details[l]
})
}
}
}
// console.log(complete_gene[0]);
database.insert("complete_gene", complete_gene);
// writing to file
for (const gene of data) {
writer.write(gene);
}
writer.end();
}
});
app.listen(config.PORT, () => {
console.log(`server started at port : ${config.PORT}`);
});