Skip to content

Commit

Permalink
migrate random_features component
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood committed Sep 2, 2024
1 parent dd5d21e commit 81b5330
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/control_methods/random_features/config.vsh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
__merge__: ../../api/comp_control_method.yaml
name: "random_features"
label: Random Features
summary: "Negative control by randomly embedding into a 2D space."
description: "This method serves as a negative control, where the data is randomly embedded into a two-dimensional space, with no attempt to preserve the original structure."
info:
v1:
path: openproblems/tasks/dimensionality_reduction/methods/baseline.py
commit: 80b37e7a6aa27df4436f400397564c01276817e0
preferred_normalization: counts
variants:
random_features:
resources:
- type: python_script
path: script.py
engines:
- type: docker
image: openproblems/base_python:1.0.0
runners:
- type: executable
- type: nextflow
directives:
label: [midtime, highmem, highcpu]
34 changes: 34 additions & 0 deletions src/control_methods/random_features/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import anndata as ad
import numpy as np

## VIASH START
par = {
"input": "resources_test/dimensionality_reduction/pancreas/test.h5ad",
"output": "reduced.h5ad",
}
meta = {
"functionality_name": "random_features",
}
## VIASH END

print("Load input data", flush=True)
input = ad.read_h5ad(par["input"])

print("Create random embedding", flush=True)
X_emb = np.random.normal(0, 1, (input.shape[0], 2))

print("Create output AnnData", flush=True)
output = ad.AnnData(
obs=input.obs[[]],
obsm={
"X_emb": X_emb
},
uns={
"dataset_id": input.uns["dataset_id"],
"normalization_id": input.uns["normalization_id"],
"method_id": meta["functionality_name"]
}
)

print("Write output to file", flush=True)
output.write_h5ad(par["output"], compression="gzip")

0 comments on commit 81b5330

Please sign in to comment.