-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:saeyslab/polygloty
- Loading branch information
Showing
24 changed files
with
807 additions
and
62 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/work | ||
/target | ||
/.nextflow* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: polygloty_usecase | ||
version: 0.1.0 | ||
viash_version: 0.9.0 |
56 changes: 56 additions & 0 deletions
56
book/workflow_frameworks/examples/viash_nextflow/src/compute_pseudobulk/config.vsh.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: compute_pseudobulk | ||
description: Compute pseudobulk expression from anndata object | ||
|
||
argument_groups: | ||
- name: Inputs | ||
arguments: | ||
- type: file | ||
name: --input | ||
description: Path to the input h5ad file | ||
example: /path/to/input.h5ad | ||
required: true | ||
- name: Pseudobulk arguments | ||
arguments: | ||
- type: string | ||
name: --obs_column_index | ||
description: Name of the column to pseudobulk on | ||
example: cell_type | ||
required: true | ||
- type: string | ||
name: --obs_column_values | ||
description: List of column names for the new obs data frame | ||
example: ["batch", "sample"] | ||
multiple: true | ||
required: true | ||
- name: Outputs | ||
arguments: | ||
- type: file | ||
name: --output | ||
description: Path to the output h5ad file | ||
example: /path/to/output.h5ad | ||
required: true | ||
direction: output | ||
|
||
resources: | ||
- type: python_script | ||
path: script.py | ||
|
||
test_resources: | ||
- type: python_script | ||
path: test.py | ||
|
||
engines: | ||
- type: docker | ||
image: python:3.10 | ||
setup: | ||
- type: python | ||
pypi: | ||
- anndata | ||
test_setup: | ||
- type: python | ||
pypi: | ||
- viashpy | ||
|
||
runners: | ||
- type: executable | ||
- type: nextflow |
41 changes: 41 additions & 0 deletions
41
book/workflow_frameworks/examples/viash_nextflow/src/compute_pseudobulk/script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import anndata as ad | ||
import pandas as pd | ||
import numpy as np | ||
|
||
## VIASH START | ||
par = {"input": "", "obs_column_index": "", "obs_column_values": [], "output": ""} | ||
## VIASH END | ||
|
||
print("Load data", flush=True) | ||
adata = ad.read_h5ad(par["input"]) | ||
|
||
print(f"Format of input data: {adata}", flush=True) | ||
assert par["obs_column_index"] in adata.obs.columns, f"Column '{par['obs_column']}' not found in obs." | ||
for col in par["obs_column_values"]: | ||
assert col in adata.obs.columns, f"Column '{col}' not found in obs." | ||
|
||
print("Compute pseudobulk", flush=True) | ||
X = adata.X | ||
if not isinstance(X, np.ndarray): | ||
X = X.toarray() | ||
combined = pd.DataFrame( | ||
X, | ||
index=adata.obs[par["obs_column_index"]], | ||
) | ||
combined.columns = adata.var_names | ||
pb_X = combined.groupby(level=0).sum() | ||
|
||
print("Construct obs for pseudobulk") | ||
pb_obs = adata.obs[par["obs_column_values"]].copy() | ||
pb_obs.index = adata.obs[par["obs_column_index"]] | ||
pb_obs = pb_obs.drop_duplicates() | ||
|
||
print("Create AnnData object") | ||
pb_adata = ad.AnnData( | ||
X=pb_X.loc[pb_obs.index].values, | ||
obs=pb_obs, | ||
var=adata.var, | ||
) | ||
|
||
print("Store to disk") | ||
pb_adata.write_h5ad(par["output"], compression="gzip") |
43 changes: 43 additions & 0 deletions
43
book/workflow_frameworks/examples/viash_nextflow/src/compute_pseudobulk/test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import sys | ||
import anndata as ad | ||
import pytest | ||
import numpy as np | ||
|
||
def test_subset_var(run_component, tmp_path): | ||
input_path = tmp_path / "input.h5ad" | ||
output_path = tmp_path / "output.h5ad" | ||
|
||
# create data | ||
adata_in = ad.AnnData( | ||
X=np.array([[1, 2], [3, 4], [5, 6], [7, 8]]), | ||
obs={ | ||
"cell_type": ["A", "A", "B", "B"], | ||
"time": [1, 2, 1, 2], | ||
"condition": ["ctrl", "ctrl", "trt", "trt"], | ||
}, | ||
var={"highly_variable": [True, False]}, | ||
) | ||
|
||
adata_in.write_h5ad(input_path) | ||
|
||
# run component | ||
run_component([ | ||
"--input", str(input_path), | ||
"--obs_column_index", "cell_type", | ||
"--obs_column_values", "condition", | ||
"--output", str(output_path), | ||
]) | ||
|
||
# load output | ||
adata_out = ad.read_h5ad(output_path) | ||
|
||
# check output | ||
assert adata_out.X.shape == (2, 2) | ||
assert np.all(adata_out.X == np.array([[4, 6], [12, 14]])) | ||
assert adata_out.obs.index.tolist() == ["A", "B"] | ||
assert adata_out.obs["condition"].tolist() == ["ctrl", "trt"] | ||
assert adata_out.var["highly_variable"].tolist() == [True, False] | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(pytest.main([__file__])) |
68 changes: 68 additions & 0 deletions
68
book/workflow_frameworks/examples/viash_nextflow/src/differential_expression/config.vsh.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: differential_expression | ||
description: Compute differential expression between two observation types | ||
|
||
argument_groups: | ||
- name: Inputs | ||
arguments: | ||
- type: file | ||
name: --input | ||
description: Path to the input h5ad file | ||
example: /path/to/input.h5ad | ||
required: true | ||
- name: Differential expression arguments | ||
arguments: | ||
- type: string | ||
name: --contrast | ||
description: | | ||
Contrast to compute. Must be of length 3: | ||
1. The name of the column to contrast on | ||
2. The name of the first observation type | ||
3. The name of the second observation type | ||
example: ["cell_type", "batch", "sample"] | ||
multiple: true | ||
required: true | ||
- type: string | ||
name: --design_formula | ||
description: Design formula for the differential expression model | ||
example: ~ batch + cell_type | ||
- name: Outputs | ||
arguments: | ||
- type: file | ||
name: --output | ||
description: Path to the output h5ad file | ||
example: /path/to/output.h5ad | ||
required: true | ||
direction: output | ||
|
||
resources: | ||
- type: r_script | ||
path: script.R | ||
|
||
test_resources: | ||
- type: r_script | ||
path: test.R | ||
|
||
engines: | ||
- type: docker | ||
image: rocker/r2u:22.04 | ||
setup: | ||
- type: apt | ||
packages: | ||
- python3 | ||
- python3-pip | ||
- python3-dev | ||
- python-is-python3 | ||
- type: python | ||
pypi: | ||
- anndata | ||
- type: r | ||
cran: | ||
- anndata | ||
- processx | ||
bioc: | ||
- DESeq2 | ||
|
||
runners: | ||
- type: executable | ||
- type: nextflow |
Oops, something went wrong.