-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh5ad.html
59 lines (45 loc) · 1.84 KB
/
h5ad.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>h5ad via h5wasm</title>
</head>
<body>
<input type="file" id="file_input" accept=".h5ad">
</body>
<script type="module">
import h5wasm from "https://cdn.jsdelivr.net/npm/[email protected]/dist/esm/hdf5_hl.js";
document.getElementById('file_input').focus();
document.getElementById('file_input').addEventListener('change', async function (e) {
console.log(e.target.files[0]);
const Module = await h5wasm.ready;
const { FS } = Module;
console.log("h5wasm loaded");
const work_dir = await FS.mkdir("/work");
const fs_mount = await FS.mount(
FS.filesystems.WORKERFS,
{ files: [e.target.files[0]] },
"/work"
);
const annData = new h5wasm.File(`/work/${e.target.files[0].name}`, "r+");
console.log(annData);
// Load an h5ad file from the server and write to the file system and open
// let response = await fetch("data/test.h5ad");
// let ab = await response.arrayBuffer();
// FS.writeFile("temp.h5ad", new Uint8Array(ab));
// Then open the file using h5wasm
let f = new h5wasm.File("temp.h5ad", "a");
console.log(f);
f.create_group("foo");
f.get("foo").create_dataset({ name: "bar", data: [3.1, 4.1, 0.0, -1.0] });
f.flush();
f.close();
console.log("Done.")
// document.write(`<div>Top Level Keys: ${f.keys()}</div>`);
// document.write(`<div>X shape: ${f.get("X").shape}</div>`);
// document.write(`<div>Genes: ${f.get("var/index").value.slice(0, 10)}...</div>`);
// document.write(`<div>X Cell 0 Expression: ${f.get("X").value.slice(0, 10)}...</div>`);
});
</script>
</html>