-
Notifications
You must be signed in to change notification settings - Fork 1
/
hani-ms2-sample-1.imjoy.html
111 lines (96 loc) · 2.76 KB
/
hani-ms2-sample-1.imjoy.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
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
<docs>
Mosaic image from Hani et al.
Sample 1.
</docs>
<config lang="json">
{
"name": "hani-ms2-sample-1",
"type": "web-worker",
"tags": [],
"ui": "",
"version": "0.1.0",
"cover": "",
"description": "Hani et al., Sample 1",
"icon": "extension",
"inputs": null,
"outputs": null,
"api_version": "0.1.8",
"env": "",
"permissions": [],
"requirements": ["https://unpkg.com/zarr@0.4.0/zarr.umd.js"],
"dependencies": []
}
</config>
<script lang="javascript">
// Using the FileReferenceStore made by Trevor Manz
// https://observablehq.com/d/a417a770860fbb64
class FileReferenceStore {
constructor(ref, target) {
this.ref = ref;
this.target = target;
}
_url(urlPath) {
if(!urlPath){
return this.target
}
const [protocol, path] = urlPath.split('://');
if (protocol === 'https' || protocol === 'http') {
return urlPath;
}
if (protocol === 'gc') {
return 'https://storage.googleapis.com/' + path;
}
throw Error("Protocol not supported, got: " + JSON.stringify(protocol));
}
async getItem(key) {
const res = this.ref[key];
if (!res) {
// Key not in store
throw new zarr.KeyError(key);
}
if (res?.length !== 3) {
// JSON data entry in reference
const meta = typeof res === 'string' ? res : JSON.stringify(res)
const enc = new TextEncoder().encode(meta);
return enc.buffer;
}
const [urlPath, offset, size] = res;
const url = this._url(urlPath);
const headers = {
Range: `bytes=${offset}-${offset + size - 1}`
};
const value = await fetch(url, { headers}).then(res => res.arrayBuffer());
return value;
}
containsItem(key) {
return key in this.ref;
}
static async fromUrl(url, targetUrl) {
const ref = await fetch(url).then(res => res.json());
return new FileReferenceStore(ref, targetUrl);
}
}
class ImJoyPlugin {
async setup() {
api.log('initialized')
}
async run(ctx) {
const refUrl = 'https://imjoy-s3.pasteur.fr/public/mueller-hani-ms2/sample-1/image.ome.tif_offsets.json'
const targetUrl = 'https://imjoy-s3.pasteur.fr/public/mueller-hani-ms2/sample-1/image.ome.tif'
const store = await FileReferenceStore.fromUrl(refUrl, targetUrl);
const viewer = await api.createWindow({src: 'https://hms-dbmi.github.io/vizarr', fullscreen: true, name: 'Hani et al., Sample 1'})
const img = {
"source": store,
"name": "pSPX1::MS2x128, S line",
"channel_axis": 0,
"axis_labels": ["Channel", "w", "h"],
"colors": [ "00FF00", "#0000FF"],
"names": ["MCP-GFP", "DAPI"],
"visibilities": [true, true],
"contrast_limits": [[60, 12000], [0, 10000]],
}
viewer.add_image(img)
}
}
api.export(new ImJoyPlugin())
</script>