Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions loopy/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Callable, Literal, cast

import pandas as pd
from pandas.api.types import is_object_dtype, is_string_dtype
from pydantic import validator
from scipy.sparse import csc_matrix, csr_matrix
from typing_extensions import Self
Expand Down Expand Up @@ -112,15 +113,19 @@ def join_idx(template: pd.DataFrame, feat: pd.DataFrame) -> pd.DataFrame:
"""

for df in [template, feat]:
if not df.index.dtype == "object":
index = df.index
has_string_index = is_string_dtype(index.dtype) or (
is_object_dtype(index.dtype) and index.map(lambda value: isinstance(value, str)).all()
)
if not has_string_index:
raise ValueError(
"""Index must be string. This is to prevent subtle bugs.
Use`df.index = df.index.astype(str)` and verify that the index is unique with `df.index.is_unique`."""
)

if not df.index.is_unique:
if not index.is_unique:
raise ValueError(
f"Template (coords) index is not unique. {df.index[df.index.duplicated()]} duplicated"
f"Template (coords) index is not unique. {index[index.duplicated()]} duplicated"
)

joined = template.join(feat, validate="one_to_one")
Expand Down
6 changes: 5 additions & 1 deletion loopy/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import numpy as np
import pandas as pd
from pandas.api.types import is_object_dtype, is_string_dtype
from pydantic import BaseModel
from typing_extensions import Self

Expand Down Expand Up @@ -204,7 +205,10 @@ def run():
raise ValueError("x and y must be in columns")
if (df.x.isnull() | df.y.isnull()).any():
raise ValueError("x and y must not be null")
if df.index.dtype != "object":
has_string_index = is_string_dtype(df.index.dtype) or (
is_object_dtype(df.index.dtype) and df.index.map(lambda value: isinstance(value, str)).all()
)
if not has_string_index:
raise ValueError(
"""Index must be string. This is to prevent subtle bugs.
Use `df.index = df.index.astype(str)` and verify that it's what you want."""
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"devDependencies": {
"@eslint/js": "^9.35.0",
"@playwright/test": "1.58.2",
"playwright": "1.58.2",
"@sveltejs/adapter-static": "^3.0.10",
"@sveltejs/kit": "^2.54.0",
"@sveltejs/vite-plugin-svelte": "^6.2.4",
Expand All @@ -36,6 +35,7 @@
"@types/wicg-file-system-access": "^2023.10.7",
"@typescript-eslint/parser": "^8.57.0",
"@vitest/browser": "^4.1.0",
"@vitest/browser-playwright": "4.1.0",
"autoprefixer": "^10.4.27",
"clsx": "^2.1.1",
"d3": "^7.9.0",
Expand All @@ -48,6 +48,7 @@
"globals": "^16.3.0",
"jsdom": "^28.1.0",
"node-fetch": "^3.3.2",
"playwright": "1.58.2",
"postcss": "^8.5.8",
"postcss-load-config": "^6.0.1",
"prettier": "^3.8.1",
Expand Down Expand Up @@ -81,8 +82,10 @@
"file-saver": "^2.0.5",
"fzf": "^0.5.2",
"gdal3.js": "2.8.1",
"geotiff": "3.0.5",
"highlight.js": "^11.11.1",
"html-to-image": "^1.11.13",
"jpegxr": "0.3.0",
"loam": "^1.2.0",
"lodash-es": "^4.17.23",
"lru-cache": "^10.2.2",
Expand Down
72 changes: 49 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 11 additions & 23 deletions src/lib/components/ImportInstructionsDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@

const dispatch = createEventDispatcher<{ close: void }>();

const cliSnippet = `conda activate loopy
loopy image path/to/image.tif --scale 0.5e-6 --channels DAPI,GFAP

# Optional: integrate spaceranger output
loopy spaceranger /path/to/spaceranger --out ./loopy --name sample_name`;

const apiSnippet = `from pathlib import Path
from loopy.sample import Sample
import pandas as pd
Expand Down Expand Up @@ -59,8 +53,8 @@ coords = pd.read_csv("coords.csv", index_col=0)
Process Data for Samui
</Dialog.Title>
<Dialog.Description class="mt-1 text-sm text-neutral-300">
Follow these steps to prepare a sample folder that imports cleanly into the
browser.
Prepare a full sample folder for overlays and metadata, or drag a TIFF directly
into the browser for image-only viewing.
</Dialog.Description>
</div>
<Dialog.Close
Expand Down Expand Up @@ -97,22 +91,11 @@ coords = pd.read_csv("coords.csv", index_col=0)
<p class="mt-0.5 text-neutral-300">
Choose either the command line or Python API workflow; both populate
<code class="font-mono text-neutral-100">sample.json</code>
, which is the data manifest along with actual data files. In this example, we
process a large TIFF image for Samui and overlay it with a point cloud feature.
, which is the data manifest along with actual data files. In this example, we process
a large TIFF image for Samui and overlay it with a point cloud feature.
</p>

<div class="mt-3 grid gap-4 md:grid-cols-1 -ml-4">
<!-- <div class="rounded-xl border border-neutral-800 bg-neutral-950/70 p-4">
<p class="mb-1 text-xs uppercase tracking-wide text-neutral-400">CLI workflow</p>
<CodeHighlight
code={cliSnippet}
language="bash"
wrap
className="text-xs"
showCopy
ariaLabel="Loopy CLI example"
/>
</div> -->
<div class="mt-3 -ml-4 grid gap-4 md:grid-cols-1">
<div class="rounded-xl border border-neutral-800 bg-neutral-950/70 p-4">
<p class="mb-1 text-xs uppercase tracking-wide text-neutral-400">
Python API workflow
Expand Down Expand Up @@ -159,6 +142,11 @@ coords = pd.read_csv("coords.csv", index_col=0)
.
</li>
<li>Choose your prepared sample folder when prompted.</li>
<li>
Or drag a <code class="font-mono text-neutral-100">.tif</code>
directly onto the page for image-only browsing. Raw TIFF imports are capped at 1 GB
and do not create overlays.
</li>
</ol>
</section>

Expand All @@ -181,7 +169,7 @@ coords = pd.read_csv("coords.csv", index_col=0)
</li>
<li>
<strong>“Unsupported file type”</strong>
: single-file imports accept ROI/annotation JSON and feature CSVs only.
: single-file imports accept TIFF, ROI/annotation JSON, and feature CSVs only.
</li>
<li>
<strong>Slow conversion/large file size</strong>
Expand Down
Loading
Loading