Skip to content

Commit

Permalink
Merge pull request #36 from will-moore/v05-dev2
Browse files Browse the repository at this point in the history
V05 dev2
  • Loading branch information
will-moore authored Oct 28, 2024
2 parents 24f187f + 74f4e6f commit d0eab86
Show file tree
Hide file tree
Showing 26 changed files with 988 additions and 271 deletions.
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@
cursor: default;
}
body {
--omeRed: #df283f;
--omeGreen: #128669;
--omeLinkBlue: #1d8dcd;
padding: 0;
font-family: "Overpass", -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
Expand All @@ -230,7 +233,7 @@
background: white;
margin: 10px 0;
text-align: center;
box-shadow: 10px 10px 20px rgba(125, 22, 2, 0.5);
box-shadow: 10px 10px 20px rgba(212, 239, 253, 0.5);
width: 100%;
position: relative;
}
Expand Down
248 changes: 178 additions & 70 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
},
"dependencies": {
"ajv": "^8.11.0",
"ndarray": "^1.0.19",
"svelte-icons-pack": "^1.4.6",
"svelte-simple-modal": "^1.4.1",
"zarr": "^0.6.0"
"zarrita": "^0.4.0-next.15"
}
}
43 changes: 43 additions & 0 deletions public/ome-main-nav.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 10 additions & 32 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Modal from "svelte-simple-modal";
import SplashScreen from "./SplashScreen.svelte";
import { getJson } from "./utils";
import { getZarrGroupAttrs } from "./utils";
import CheckMark from "./CheckMark.svelte";
const searchParams = new URLSearchParams(window.location.search);
Expand All @@ -15,14 +15,17 @@
source = source.slice(0, -1);
}
let location = window.location.href;
let promise;
if (source) {
// load JSON to be validated...
console.log("Loading JSON... " + source + "/.zattrs");
promise = getJson(source + "/.zattrs");
console.log("Loading JSON... " + source);
promise = getZarrGroupAttrs(source);
}
function isBioFormats2Raw(data) {
let omeAttrs = data?.attributes?.ome || data;
return omeAttrs["bioformats2raw.layout"] === 3 && !omeAttrs.plate;
}
</script>
Expand All @@ -38,7 +41,7 @@
{:then data}
<Title {source} zattrs={data} />
<div>
{#if data["bioformats2raw.layout"] === 3 && !data.plate}
{#if isBioFormats2Raw(data)}
<Bioformats2rawLayout rootAttrs={data} {source} />
{:else}
<JsonValidator rootAttrs={data} {source} />
Expand Down Expand Up @@ -74,24 +77,7 @@
width: 100%;
flex: 1;
padding: 15px 0;
background: #ff512f; /* fallback for old browsers */
background: -webkit-linear-gradient(
to right,
#f09819,
#ff512f
); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(
to right,
#f09819,
#ff512f
); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
/* https://uigradients.com/ */
/* OME green->blue rgb(61,132,107), rgb(68,139,200) */
}
article {
width: 90%;
margin: auto;
background: white;
}
section > div {
Expand All @@ -108,14 +94,6 @@
section > div {
flex-direction: row;
}
article {
width: 60%;
margin: auto;
}
a {
white-space: nowrap;
}
}
.error {
Expand Down
105 changes: 87 additions & 18 deletions src/Bioformats2rawLayout/index.svelte
Original file line number Diff line number Diff line change
@@ -1,27 +1,83 @@
<script>
import { getXmlDom, getJson, validate } from "../utils";
import {
getJson,
getXmlDom,
getZarrGroupAttrs,
validate,
getVersion,
getZarrGroupAttrsFileName,
} from "../utils";
import JsonBrowser from "../JsonBrowser/index.svelte";
import ImageContainer from "../JsonValidator/Well/ImageContainer.svelte";
import RoCrate from "../JsonValidator/RoCrate/index.svelte";
import OpenWith from "../JsonValidator/OpenWithViewers/index.svelte";
export let source;
export let rootAttrs;
const metadataName = "OME/METADATA.ome.xml";
const version = getVersion(rootAttrs);
console.log("BF2RAW version", version, rootAttrs);
const zarrAttrsFileName = getZarrGroupAttrsFileName(version);
console.log("zarrAttrsFileName", zarrAttrsFileName);
// source/OME/METADATA.ome.xml
const metadataUrl = `${source}/${metadataName}`;
async function loadXml(url) {
let dom = await getXmlDom(url);
async function loadXmlOrSeries(url) {
// We can get the series info from /OME/METADATA.ome.xml or
// /OME/zarr.json group attributes
// returns {images: [{name, id}]} or {error: message}
let dom;
try {
dom = await getXmlDom(url);
} catch (error) {}
let xmlRsp;
if (dom) {
xmlRsp = parseXml(dom);
}
// Try to get series info
let rsp = {};
let series;
try {
let zarrAttrs = await getJson(`${source}/OME/${zarrAttrsFileName}`);
series = zarrAttrs?.attributes?.ome?.series || zarrAttrs.series;
} catch (error) {}
if (series && xmlRsp && xmlRsp?.images) {
// MUST match if we have both...
if (series.length !== xmlRsp.images.length) {
rsp.errors = [
`Images length mismatch: series: ${series.length} != ome.xml: ${xmlRsp.images.length}`,
];
}
}
if (series) {
rsp.images = series.map((seriesName) => ({
name: seriesName,
path: seriesName,
}));
} else if (xmlRsp) {
rsp = xmlRsp;
} else {
rsp.errors = ["No OME/METADATA.ome.xml or /OME series found"];
}
return rsp;
}
function parseXml(dom) {
const root = dom.documentElement;
let rsp = { images: [] };
let index = 0;
for (const child of root.children) {
console.log(child.tagName);
if (child.tagName === "Image") {
rsp.images.push({
name: child.getAttribute("Name"),
id: child.getAttribute("ID"),
path: "" + index++,
});
}
// error handling - parsererror gives html doc
Expand All @@ -35,12 +91,12 @@
}
return rsp;
}
const promise = loadXml(metadataUrl);
const promise = loadXmlOrSeries(metadataUrl);
// wait for schema to be cached, so we don't load them multiple times
// let schemasPromise = getSchema("0.2", "image");
async function preloadSchema(imagePath) {
let imgAttrs = await getJson(imagePath + "/.zattrs");
let imgAttrs = getZarrGroupAttrs(imagePath);
console.log("preloadSchema", imgAttrs);
let errs = await validate(imgAttrs);
return errs;
Expand All @@ -53,32 +109,36 @@
</script>
<article>
Reading: <a href={source}>/{zarrName}/.zattrs</a>

<div class="json">
<JsonBrowser name="" version="" contents={rootAttrs} expanded />
</div>
Reading: <a href={source}/{zarrAttrsFileName}>/{zarrName}/{zarrAttrsFileName}</a>
Loading metadata:<a href={metadataUrl}>{metadataName}</a><br />
{#await promise}
<div>loading {metadataUrl}...</div>
{:then metadataJson}
<!-- Show list of Images -->
<h1>Images</h1>
<h1>{metadataJson.images.length} Images</h1>
<ol>
{#await preloadSchema(source + "/0")}
<div>loading schema...</div>
{:then ok}
<ul>
{#each metadataJson.images as image, i}
{#each metadataJson.images as image}
<li class="image">
/{i}
<a title="Open Image" href="{url}?source={source}/{i}/"
/{image.path}
<a title="Open Image" href="{url}?source={source}/{image.path}/"
>{image.name}</a
>
<ImageContainer {source} path={i} />
<ImageContainer {source} path={image.path} />
<a title="Open Image" href="{url}?source={source}/{image.path}/"
>Open in validator</a
>
<div style="margin-top: 10px">
<OpenWith source={`${source}/${image.path}`} dtype={"image"} {version} />
</div>
</li>
{/each}
</ul>
Expand All @@ -87,10 +147,15 @@
{/await}
</ol>
<h3>{zarrName}/{zarrAttrsFileName}</h3>
<div class="json">
<JsonBrowser name="" version="" contents={rootAttrs} expanded />
</div>
<!-- Error handling... -->
{#if metadataJson.errors}
<div class="error">
<h2>Error parsing {metadataName}</h2>
<h3>Error loading series metadata:</h3>
{#each metadataJson.errors as err, i}
<div>{err}</div>
{/each}
Expand All @@ -99,16 +164,20 @@
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
<!-- for v0.5+ we check for ro-crate-metadata.json -->
{#if !["0.1", "0.2", "0.3", "0.4"].includes(version)}
<RoCrate {source}></RoCrate>
{/if}
</article>
<style>
h1 {
margin-top: 20px;
}
a,
a:visited {
color: #ff512f;
color: var(--omeLinkBlue);
}
.json {
Expand Down
31 changes: 31 additions & 0 deletions src/JsonBrowser/DetailsPrePanel.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@


<script>
export let jsonData;
export let summary;
</script>

<details>
<summary>{summary}</summary>
<pre><code>{JSON.stringify(jsonData, null, 2)}</code></pre>
</details>


<style>
details {
font-size: 1.1em;
text-align: left;
margin: 0 15px;
}
pre {
margin-top: 10px;
color: #faebd7;
background-color: #2c3e50;
padding: 10px;
font-size: 14px;
border-radius: 10px;
overflow: auto;
}
</style>
Loading

0 comments on commit d0eab86

Please sign in to comment.