Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
122 lines (91 loc) · 3.42 KB
/
Copy pathmain.js
File metadata and controls
122 lines (91 loc) · 3.42 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
let pyodideReady = (async () => {
const pyodide = await loadPyodide();
pyodide.setStdout({
batched: (data) => console.log(data)
});
pyodide.setStderr({
batched: (data) => console.error(data)
});
await pyodide.loadPackage("micropip");
await pyodide.runPythonAsync(`
import micropip
await micropip.install("biopython")
await micropip.install("https://ainaescobet.github.io/wa_entrez/wa_entrez-1.0.0-py3-none-any.whl")
`);
console.log("Packages installed")
await pyodide.runPythonAsync(`
from wa_entrez import WAEntrezClient
print("WAEntrezClient imported successfully")
`);
console.log("Pyodide ready");
return pyodide;
})();
let lastResultFile = null;
async function runPubMedApp() {
const pyodide = await pyodideReady;
const pmid = document.getElementById("pmid").value;
// Create a config object
const config = {
pmid: pmid
}
// Write config object to a file in the Pyodide filesystem (FS)
pyodide.FS.writeFile("config.json", JSON.stringify(config));
// Load Python code
const response = await fetch("python_pipeline.py");
const pythonCode = await response.text();
await pyodide.runPythonAsync(pythonCode);
// Execute the pipline
const resultPy = await pyodide.runPythonAsync(`fetch_pubmed()`);
const result = resultPy.toJs();
lastResultFile = result.file;
console.log(result);
const outputDiv = document.getElementById("pubmed-output");
outputDiv.innerHTML = `
<p><strong>Title:</strong> ${result.title}</p>
<p><strong>Journal:</strong> ${result.journal}</p>
<p><strong>Authors:</strong> ${result.authors}</p>
`;
outputDiv.parentElement.style.display = "block";
document.getElementById("download-btn-pubmed").disabled = false;
}
async function runGenomicsApp() {
const pyodide = await pyodideReady;
const genome = document.getElementById("genome").value;
const config = {
genome: genome
}
pyodide.FS.writeFile("config.json", JSON.stringify(config));
const response = await fetch("python_pipeline.py");
const pythonCode = await response.text();
await pyodide.runPythonAsync(pythonCode);
const resultPy = await pyodide.runPythonAsync(`fetch_genomics()`);
const result = resultPy.toJs();
lastResultFile = result.file;
console.log(result);
const outputDiv = document.getElementById("genomics-output");
outputDiv.innerHTML = `
<p><strong>Genome ID:</strong> ${result.id}</p>
<p><strong>Name:</strong> ${result.name}</p>
<p><strong>Description:</strong> ${result.description}</p>
<p><strong>Sequence Length:</strong> ${result.sequence_length}</p>
<p><strong>Organism:</strong> ${result.organism}</p>
`;
outputDiv.parentElement.style.display = "block";
document.getElementById("download-btn-genomics").disabled = false;
}
async function download(){
const pyodide = await pyodideReady;
if (!lastResultFile) {
alert("No results to download");
return;
}
const content = pyodide.FS.readFile(lastResultFile, {encoding: "utf8"});
const blob = new Blob([content], {type: "text/plain"});
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "result.txt";
a.click();
URL.revokeObjectURL(url);
}
// NZ_JBQPCT010000034.1