Mercurial > repos > goeckslab > vitessce_spatial
annotate gate_finder.py @ 3:7cc457aa78b1 draft default tip
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit af71ccb3b89c9735c6f985a3e8ffe22cd14c0e04
author | goeckslab |
---|---|
date | Thu, 30 May 2024 17:24:44 +0000 |
parents | 9f60ef2d586e |
children |
rev | line source |
---|---|
0
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
1 import argparse |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
2 import json |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
3 import warnings |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
4 from pathlib import Path |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
5 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
6 import numpy as np |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
7 import pandas as pd |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
8 from anndata import read_h5ad |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
9 from sklearn.mixture import GaussianMixture |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
10 from sklearn.preprocessing import MinMaxScaler |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
11 from vitessce import ( |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
12 AnnDataWrapper, |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
13 Component as cm, |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
14 MultiImageWrapper, |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
15 OmeTiffWrapper, |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
16 VitessceConfig, |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
17 ) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
18 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
19 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
20 # Generate binarized phenotype for a gate |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
21 def get_gate_phenotype(g, d): |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
22 dd = d.copy() |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
23 dd = np.where(dd < g, 0, dd) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
24 np.warnings.filterwarnings('ignore') |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
25 dd = np.where(dd >= g, 1, dd) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
26 return dd |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
27 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
28 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
29 def get_gmm_phenotype(data): |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
30 low = np.percentile(data, 0.01) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
31 high = np.percentile(data, 99.99) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
32 data = np.clip(data, low, high) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
33 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
34 sum = np.sum(data) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
35 median = np.median(data) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
36 data_med = data / sum * median |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
37 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
38 data_log = np.log1p(data_med) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
39 data_log = data_log.reshape(-1, 1) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
40 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
41 scaler = MinMaxScaler(feature_range=(0, 1)) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
42 data_norm = scaler.fit_transform(data_log) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
43 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
44 gmm = GaussianMixture(n_components=2) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
45 gmm.fit(data_norm) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
46 gate = np.mean(gmm.means_) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
47 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
48 return get_gate_phenotype(gate, np.ravel(data_norm)) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
49 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
50 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
51 def main(inputs, output, image, anndata, masks=None): |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
52 """ |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
53 Parameter |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
54 --------- |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
55 inputs : str |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
56 File path to galaxy tool parameter. |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
57 output : str |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
58 Output folder for saving web content. |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
59 image : str |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
60 File path to the OME Tiff image. |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
61 anndata : str |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
62 File path to anndata containing phenotyping info. |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
63 masks : str |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
64 File path to the image masks. |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
65 """ |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
66 warnings.simplefilter('ignore') |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
67 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
68 with open(inputs, 'r') as param_handler: |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
69 params = json.load(param_handler) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
70 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
71 marker = params['marker'].strip() |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
72 from_gate = params['from_gate'] |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
73 to_gate = params['to_gate'] |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
74 increment = params['increment'] |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
75 x_coordinate = params['x_coordinate'].strip() or 'X_centroid' |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
76 y_coordinate = params['y_coordinate'].strip() or 'Y_centroid' |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
77 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
78 adata = read_h5ad(anndata) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
79 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
80 # If no raw data is available make a copy |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
81 if adata.raw is None: |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
82 adata.raw = adata |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
83 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
84 # Copy of the raw data if it exisits |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
85 if adata.raw is not None: |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
86 adata.X = adata.raw.X |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
87 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
88 data = pd.DataFrame( |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
89 adata.X, |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
90 columns=adata.var.index, |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
91 index=adata.obs.index |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
92 ) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
93 marker_values = data[[marker]].values |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
94 marker_values_log = np.log1p(marker_values) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
95 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
96 # Identify the list of increments |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
97 gate_names = [] |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
98 for num in np.arange(from_gate, to_gate, increment): |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
99 num = round(num, 3) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
100 key = marker + '--' + str(num) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
101 adata.obs[key] = get_gate_phenotype(num, marker_values_log) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
102 gate_names.append(key) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
103 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
104 adata.obs['GMM_auto'] = get_gmm_phenotype(marker_values) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
105 gate_names.append('GMM_auto') |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
106 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
107 adata.obsm['XY_coordinate'] = adata.obs[[x_coordinate, y_coordinate]].values |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
108 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
109 vc = VitessceConfig(name=None, description=None) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
110 dataset = vc.add_dataset() |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
111 image_wrappers = [OmeTiffWrapper(img_path=image, name='OMETIFF')] |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
112 if masks: |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
113 image_wrappers.append( |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
114 OmeTiffWrapper(img_path=masks, name='MASKS', is_bitmask=True) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
115 ) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
116 dataset.add_object(MultiImageWrapper(image_wrappers)) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
117 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
118 dataset.add_object( |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
119 AnnDataWrapper( |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
120 adata, |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
121 spatial_centroid_obsm='XY_coordinate', |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
122 cell_set_obs=gate_names, |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
123 cell_set_obs_names=[obj[0].upper() + obj[1:] for obj in gate_names], |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
124 expression_matrix="X" |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
125 ) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
126 ) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
127 spatial = vc.add_view(dataset, cm.SPATIAL) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
128 cellsets = vc.add_view(dataset, cm.CELL_SETS) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
129 status = vc.add_view(dataset, cm.STATUS) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
130 lc = vc.add_view(dataset, cm.LAYER_CONTROLLER) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
131 genes = vc.add_view(dataset, cm.GENES) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
132 cell_set_sizes = vc.add_view(dataset, cm.CELL_SET_SIZES) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
133 cell_set_expression = vc.add_view(dataset, cm.CELL_SET_EXPRESSION) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
134 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
135 vc.layout( |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
136 (status / genes / cell_set_expression) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
137 | (cellsets / cell_set_sizes / lc) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
138 | (spatial) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
139 ) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
140 config_dict = vc.export(to='files', base_url='http://localhost', out_dir=output) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
141 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
142 with open(Path(output).joinpath('config.json'), 'w') as f: |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
143 json.dump(config_dict, f, indent=4) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
144 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
145 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
146 if __name__ == '__main__': |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
147 aparser = argparse.ArgumentParser() |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
148 aparser.add_argument("-i", "--inputs", dest="inputs", required=True) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
149 aparser.add_argument("-e", "--output", dest="output", required=True) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
150 aparser.add_argument("-g", "--image", dest="image", required=True) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
151 aparser.add_argument("-a", "--anndata", dest="anndata", required=True) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
152 aparser.add_argument("-m", "--masks", dest="masks", required=False) |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
153 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
154 args = aparser.parse_args() |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
155 |
9f60ef2d586e
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 9b2dc921e692af8045773013d9f87d4d790e2ea1
goeckslab
parents:
diff
changeset
|
156 main(args.inputs, args.output, args.image, args.anndata, args.masks) |