Skip to content
Open
Show file tree
Hide file tree
Changes from 14 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
41 changes: 40 additions & 1 deletion js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,54 @@
);
};

const fetchTechnology = async (base_url, model) => {
const path_parameters_json = `${base_url || ''}/landscape_parameters.json`;

try {
const response = await fetch(path_parameters_json);
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const landscape_parameters = await response.json();
return landscape_parameters.technology || 'Xenium';
} catch (err) {
const msg = `Could not read technology from ${path_parameters_json}. Using default 'Xenium'`;
console.warn(msg, err);

Check warning on line 137 in js/widget.js

View workflow job for this annotation

GitHub Actions / quality

Unexpected console statement

if (model?.send) {
model.send({
event: 'technology_fetch_warning',
message: msg,
error: err.message || '',
});
}

return 'Xenium';
}
};

const render_landscape = async ({ model, el }) => {
const technology = model.get('technology');
let technology;

try {
technology = model.get('technology');
} catch {
technology = null; // fallback to fetching from JSON
}

if (!technology) {
const base_url = model.get('base_url');
technology = await fetchTechnology(base_url, model);
model.set('technology', technology);
}

if (['MERSCOPE', 'Xenium'].includes(technology)) {
return render_landscape_ist({ model, el });
} else if (['Visium-HD'].includes(technology)) {
return render_landscape_sst({ model, el });
} else if (['h&e'].includes(technology)) {
return render_landscape_h_e({ model, el });
} else {
// eslint-disable-next-line no-console
console.warn(`Unknown technology "${technology}". Rendering skipped.`);
}
};

Expand Down
174 changes: 43 additions & 131 deletions notebooks/Custom_Segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"id": "9bd79809-7286-463c-a92a-e6315856d0a1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n",
"env: ANYWIDGET_HMR=1\n"
]
}
Expand All @@ -24,17 +22,17 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 2,
"id": "236fbcbe-36de-483b-9afd-13a379a56899",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'0.4.0'"
"'0.9.0'"
]
},
"execution_count": 6,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -57,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"id": "46377171-5592-418f-a6a1-0658a8494954",
"metadata": {},
"outputs": [],
Expand All @@ -76,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 5,
"id": "cb0602d3-c572-417b-88e3-ba036098f050",
"metadata": {},
"outputs": [
Expand All @@ -90,126 +88,48 @@
"Calculating mean expression\n",
"Calculating variance\n",
"All meta gene files are succesfully saved.\n",
"data/xenium_landscape_files/Xenium_Prime_Human_Skin_FFPE_outs/cbg_cellpose2\n",
"\n",
"========Write gene-specific parquet files========\n",
"Processing gene 0: A2ML1\n",
"Processing gene 100: ADIPOR1\n",
"Processing gene 200: ANKRD40\n",
"Processing gene 300: ATF2\n",
"Processing gene 400: BDNF\n",
"Processing gene 500: CALCRL\n",
"Processing gene 600: CCL20\n",
"Processing gene 700: CD72\n",
"Processing gene 800: CFC1\n",
"Processing gene 900: CNKSR3\n",
"Processing gene 1000: CSNK1A1\n",
"Processing gene 1100: CYTH2\n",
"Processing gene 1200: DMKN\n",
"Processing gene 1300: DeprecatedCodeword_0994\n",
"Processing gene 1400: DeprecatedCodeword_15617\n",
"Processing gene 1500: DeprecatedCodeword_4666\n",
"Processing gene 1600: ECD\n",
"Processing gene 1700: EPCAM\n",
"Processing gene 1800: FANCC\n",
"Processing gene 1900: FMO3\n",
"Processing gene 2000: GALNS\n",
"Processing gene 2100: GPATCH11\n",
"Processing gene 2200: H3F3B\n",
"Processing gene 2300: HOXB9\n",
"Processing gene 2400: IFNW1\n",
"Processing gene 2500: INCA1\n",
"Processing gene 2600: JAM2\n",
"Processing gene 2700: KIR3DL1\n",
"Processing gene 2800: LILRA6\n",
"Processing gene 2900: MALL\n",
"Processing gene 3000: MEST\n",
"Processing gene 3100: MTCH2\n",
"Processing gene 3200: NCSTN\n",
"Processing gene 3300: NORAD\n",
"Processing gene 3400: NXPH2\n",
"Processing gene 3500: NegControlCodeword_18746\n",
"Processing gene 3600: NegControlCodeword_18846\n",
"Processing gene 3700: NegControlCodeword_18946\n",
"Processing gene 3800: NegControlCodeword_19046\n",
"Processing gene 3900: NegControlCodeword_19146\n",
"Processing gene 4000: NegControlCodeword_19246\n",
"Processing gene 4100: P2RX1\n",
"Processing gene 4200: PDE6H\n",
"Processing gene 4300: PKIA\n",
"Processing gene 4400: PPARD\n",
"Processing gene 4500: PRXL2A\n",
"Processing gene 4600: RABL2B\n",
"Processing gene 4700: RGN\n",
"Processing gene 4800: RUBCN\n",
"Processing gene 4900: SERPINA9\n",
"Processing gene 5000: SLC17A8\n",
"Processing gene 5100: SMC1A\n",
"Processing gene 5200: SPATS2L\n",
"Processing gene 5300: STX7\n",
"Processing gene 5400: TENT5B\n",
"Processing gene 5500: TMEM130\n",
"Processing gene 5600: TPX2\n",
"Processing gene 5700: TUFM\n",
"Processing gene 5800: UnassignedCodeword_0100\n",
"Processing gene 5900: UnassignedCodeword_0579\n",
"Processing gene 6000: UnassignedCodeword_0998\n",
"Processing gene 6100: UnassignedCodeword_10427\n",
"Processing gene 6200: UnassignedCodeword_10846\n",
"Processing gene 6300: UnassignedCodeword_11242\n",
"Processing gene 6400: UnassignedCodeword_11661\n",
"Processing gene 6500: UnassignedCodeword_12151\n",
"Processing gene 6600: UnassignedCodeword_12526\n",
"Processing gene 6700: UnassignedCodeword_12880\n",
"Processing gene 6800: UnassignedCodeword_13294\n",
"Processing gene 6900: UnassignedCodeword_13728\n",
"Processing gene 7000: UnassignedCodeword_14115\n",
"Processing gene 7100: UnassignedCodeword_14486\n",
"Processing gene 7200: UnassignedCodeword_1487\n",
"Processing gene 7300: UnassignedCodeword_15237\n",
"Processing gene 7400: UnassignedCodeword_15662\n",
"Processing gene 7500: UnassignedCodeword_16071\n",
"Processing gene 7600: UnassignedCodeword_16476\n",
"Processing gene 7700: UnassignedCodeword_16830\n",
"Processing gene 7800: UnassignedCodeword_17241\n",
"Processing gene 7900: UnassignedCodeword_17672\n",
"Processing gene 8000: UnassignedCodeword_18196\n",
"Processing gene 8100: UnassignedCodeword_1886\n",
"Processing gene 8200: UnassignedCodeword_2384\n",
"Processing gene 8300: UnassignedCodeword_2846\n",
"Processing gene 8400: UnassignedCodeword_3332\n",
"Processing gene 8500: UnassignedCodeword_3845\n",
"Processing gene 8600: UnassignedCodeword_4262\n",
"Processing gene 8700: UnassignedCodeword_4726\n",
"Processing gene 8800: UnassignedCodeword_5195\n",
"Processing gene 8900: UnassignedCodeword_5693\n",
"Processing gene 9000: UnassignedCodeword_6174\n",
"Processing gene 9100: UnassignedCodeword_6629\n",
"Processing gene 9200: UnassignedCodeword_7161\n",
"Processing gene 9300: UnassignedCodeword_7569\n",
"Processing gene 9400: UnassignedCodeword_8046\n",
"Processing gene 9500: UnassignedCodeword_8534\n",
"Processing gene 9600: UnassignedCodeword_9011\n",
"Processing gene 9700: UnassignedCodeword_9525\n",
"Processing gene 9800: UnassignedCodeword_9939\n",
"Processing gene 9900: XPO1\n",
"Processing gene 10000: ZNF687\n",
"All gene-specific parquet files are succesfully saved.\n",
"========Make meta cells in pixel space========\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/jishar/Documents/celldega/src/celldega/pre/__init__.py:656: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.\n",
"\n",
"========Make meta cells in pixel space========\n",
" meta_cell[\"center_x\"] = meta_cell.centroid.x\n",
"/Users/jishar/Documents/celldega/src/celldega/pre/__init__.py:657: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.\n",
"\n",
" meta_cell[\"center_y\"] = meta_cell.centroid.y\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n",
"data/landscape_files/Xenium_V1_human_Pancreas_FFPE_outs_test/cbg_proseg\n",
"Processing gene 0: AMY2A\n",
"Processing gene 100: PTGDS\n",
"Processing gene 200: EGFL7\n",
"Processing gene 300: ESR1\n",
"Processing gene 400: NegControlCodeword_0523\n",
"Processing gene 500: UnassignedCodeword_0459\n",
"All gene-specific parquet files are succesfully saved.\n",
"\n",
"========Create clusters and meta clusters files========\n",
"Cell clusters and meta cluster files created successfully.\n",
"\n",
"========Create cell boundary spatial tiles========\n"
"========Create cell boundary spatial tiles========\n",
"custom technology\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Processing coarse tiles: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 9/9 [00:15<00:00, 1.77s/it]\n"
"Processing coarse tiles: 100%|███████████████████████████████████████████████████████████████████████████████████| 7/7 [00:24<00:00, 3.56s/it]\n"
]
},
{
Expand All @@ -227,8 +147,8 @@
}
],
"source": [
"path_landscape_files=\"data/xenium_landscape_files/Xenium_Prime_Human_Skin_FFPE_outs\"\n",
"path_segmentation_files=\"data/processed_data/xenium_skin/cellpose2/\"\n",
"path_landscape_files=\"data/landscape_files/Xenium_V1_human_Pancreas_FFPE_outs_test/\"\n",
"path_segmentation_files=\"data/processed_data/xenium_pancreas/proseg/\"\n",
"\n",
"dega.pre.add_custom_segmentation(path_landscape_files=path_landscape_files, \n",
" path_segmentation_files=path_segmentation_files)"
Expand All @@ -244,29 +164,22 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"id": "7d440da2-1354-4653-ab09-bc24400f8833",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Server running on port 55358\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "767f649f38764b20815f31721dc9be66",
"model_id": "60e4ec5c3c0e402f86228e2b4a6cf8a9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Landscape(base_url='http://localhost:55358/data/xenium_landscape_files/Xenium_Prime_Human_Skin_FFPE_outs', seg…"
"Landscape(base_url='http://localhost:52696/data/landscape_files/Xenium_V1_human_Pancreas_FFPE_outs_test/', cel…"
]
},
"execution_count": 9,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -275,9 +188,8 @@
"server_address = dega.viz.get_local_server()\n",
"\n",
"landscape_ist = dega.viz.Landscape(\n",
" technology='Xenium',\n",
" base_url = f\"http://localhost:{server_address}/{path_landscape_files}\",\n",
" segmentation='cellpose2'\n",
" segmentation='proseg'\n",
")\n",
"\n",
"landscape_ist"
Expand Down Expand Up @@ -308,7 +220,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.20"
"version": "3.11.5"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down
Loading
Loading