Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
23e3e15
add method and metric descriptions
scottgigante-immunai Feb 1, 2023
ba97255
missed some
scottgigante-immunai Feb 1, 2023
345c823
pre-commit
github-actions[bot] Feb 1, 2023
89f4240
Merge remote-tracking branch 'base/main' into docs/metric_descriptions
scottgigante-immunai Feb 2, 2023
13fc168
merge
scottgigante-immunai Feb 2, 2023
66a1fe1
pre-commit
github-actions[bot] Feb 2, 2023
02a0505
normalize strings
scottgigante-immunai Feb 2, 2023
a9b75d0
Merge branch 'docs/metric_descriptions' of github.com:scottgigante-im…
scottgigante-immunai Feb 2, 2023
3a43224
revert
scottgigante-immunai Feb 2, 2023
7fca16b
fix knn smoothing
scottgigante-immunai Feb 2, 2023
9375e16
add method descriptions where available
scottgigante-immunai Feb 2, 2023
c50ae88
repro repo structure broke update script
scottgigante-immunai Feb 5, 2023
5490687
rename ALRA sqrt
scottgigante-immunai Feb 7, 2023
80b37e7
Fix DR baselines (#816)
scottgigante-immunai Feb 8, 2023
52d1ecc
set adata.uns['is_baseline'] (#820)
scottgigante-immunai Feb 8, 2023
fe02c56
copy anndata in metric decorator (#819)
scottgigante-immunai Feb 8, 2023
97f4573
bugfix n_svd < adata.shape
scottgigante-immunai Feb 10, 2023
91059f0
explicitly avoid `main`
scottgigante-immunai Feb 10, 2023
07f9775
don't require branch other than main
scottgigante-immunai Feb 10, 2023
8b409cd
make small data dense
scottgigante-immunai Feb 10, 2023
ee78362
Don't recompute X_emb and neighborhood graph for baseline datasets (#…
danielStrobl Feb 10, 2023
8e26833
test distance correlation
scottgigante-immunai Feb 13, 2023
05a4c72
Changes in destVI code (#826) (#827)
scottgigante-immunai Feb 13, 2023
2923b24
set explicit token permissions (#828)
scottgigante-immunai Feb 13, 2023
24efa89
Ignore setuptools+pkg_resources warning
scottgigante-immunai Feb 15, 2023
964122e
require matplotlib <3.7
scottgigante-immunai Feb 15, 2023
59fb5d8
Merge remote-tracking branch 'upstream/main' into docs/metric_descrip…
rcannood Feb 16, 2023
deec9f0
add summary for diffusion map
rcannood Feb 16, 2023
5b63940
pre-commit
github-actions[bot] Feb 16, 2023
840263c
add heading
rcannood Feb 20, 2023
e5bd4db
use heading to detect task description
rcannood Feb 20, 2023
60444e7
Merge remote-tracking branch 'scottgigante/docs/metric_descriptions' …
rcannood Feb 20, 2023
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
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

### Testing

* [ ] This submission was written on a forked copy of openproblems
* [ ] This submission was written in a forked copy of openproblems
* [ ] Nextflow test pipeline is passing on this base branch of this pull
request (include link to passed test on NF Tower found in GitHub Actions summary: )

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/check_r_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write
pull-requests: write

jobs:
check-r-dependencies:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/comment_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]

permissions:
pull-requests: write

jobs:
comment_pr:

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/process_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
process_results:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -83,7 +86,6 @@ jobs:
S3_URI="s3://openproblems-nextflow/cwd_example"
fi
aws s3 cp --quiet --recursive "${S3_URI}" /tmp/results/
rm -r nbt2022-reproducibility/results/*/*.json
rm -r website/data/results/*/
python openproblems/workflow/parse_nextflow.py /tmp website/data/results

Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ on:
types:
- 'submitted'

permissions:
contents: write
packages: write
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -85,7 +90,10 @@ jobs:
if: |
!(
startsWith(github.ref, 'refs/heads/test_docker') ||
startsWith(github.ref, 'refs/heads/main')
(
startsWith(github.ref, 'refs/heads/main') &&
github.repository == 'openproblems-bio/openproblems'
)
)
run: |
cd workflow
Expand All @@ -102,7 +110,8 @@ jobs:

- name: Build and push Docker images
if: |
startsWith(github.ref, 'refs/heads/main')
startsWith(github.ref, 'refs/heads/main') &&
github.repository == 'openproblems-bio/openproblems'
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/update_website_content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
update_content:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ Metrics should take an AnnData object and return a `float`.
function metric(AnnData adata) -> float
```

Note that the AnnData object is passed to the metric function as a copy, so there is no
need to copy it internally, even if you modify the object.

Task-specific APIs are described in the README for each task.

* [Label Projection](openproblems/tasks/label_projection)
Expand Down
10 changes: 6 additions & 4 deletions openproblems/api/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ def docker_token(image_name):
[
"curl",
"--silent",
f"https://auth.docker.io/token?scope=repository:{image_name}:"
"pull&service=registry.docker.io",
(
f"https://auth.docker.io/token?scope=repository:{image_name}:"
"pull&service=registry.docker.io"
),
]
)
)
Expand Down Expand Up @@ -88,8 +90,8 @@ def docker_hash(image_name):
return docker_labels_from_api(image_name)["bio.openproblems.hash"]
except Exception: # pragma: nocover
warnings.warn(
"Failed to access docker or the docker API; docker image hash failed. "
f"All jobs using {image_name} will not be cached."
"Failed to access docker or the docker API; docker image hash failed. All"
f" jobs using {image_name} will not be cached."
)
return str(random.getrandbits(256))

Expand Down
8 changes: 4 additions & 4 deletions openproblems/data/tabula_muris_senis.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def check_unknown_organs(datasets, organ_list):
unknown_organs = set(organ_list) - known_organs
if unknown_organs:
raise ValueError(
f"Unknown organs provided in `organ_list': {', '.join(unknown_organs)}. "
f"Known organs are {', '.join(known_organs)}"
f"Unknown organs provided in `organ_list': {', '.join(unknown_organs)}."
f" Known organs are {', '.join(known_organs)}"
)


Expand Down Expand Up @@ -107,8 +107,8 @@ def load_tabula_muris_senis(test=False, method_list=None, organ_list=None):
unknown_methods = set(method_list) - set(["facs", "droplet"])
if unknown_methods:
raise ValueError(
f"Unknown methods provided in `method_list': {','.join(unknown_methods)}. "
"Known methods are `facs' and `droplet'"
f"Unknown methods provided in `method_list': {','.join(unknown_methods)}."
" Known methods are `facs' and `droplet'"
)

datasets_path = f"/curation/v1/collections/{COLLECTION_ID}"
Expand Down
2 changes: 1 addition & 1 deletion openproblems/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _download_aftp(
if timeout:
wget_command_list += ["-T", str(timeout)]

log.debug("Running: %s" % (" ".join(wget_command_list)))
log.debug("Running: %s" % " ".join(wget_command_list))
subprocess.call(wget_command_list)
return tmp_path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
dataset_name="Immune (by batch)",
data_url=load_immune.metadata["data_url"],
data_reference=load_immune.metadata["data_reference"],
dataset_summary="Human immune cells from peripheral blood and bone marrow "
"taken from 5 datasets comprising 10 batches across technologies (10X, "
"Smart-seq2).",
dataset_summary=(
"Human immune cells from peripheral blood and bone marrow taken from 5 datasets"
" comprising 10 batches across technologies (10X, Smart-seq2)."
),
image="openproblems",
)
def immune_batch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
dataset_name="Lung (Viera Braga et al.)",
data_url=load_lung.metadata["data_url"],
data_reference=load_lung.metadata["data_reference"],
dataset_summary="Human lung scRNA-seq data from 3 datasets with 32,472 cells. "
"From Vieira Braga et al. Technologies: 10X and Drop-seq.",
dataset_summary=(
"Human lung scRNA-seq data from 3 datasets with 32,472 cells. From Vieira Braga"
" et al. Technologies: 10X and Drop-seq."
),
image="openproblems",
)
def lung_batch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
dataset_name="Pancreas (by batch)",
data_url=load_pancreas.metadata["data_url"],
data_reference=load_pancreas.metadata["data_reference"],
dataset_summary="Human pancreatic islet scRNA-seq data from 6 datasets "
"across technologies (CEL-seq, CEL-seq2, Smart-seq2, inDrop, Fluidigm C1, "
"and SMARTER-seq).",
dataset_summary=(
"Human pancreatic islet scRNA-seq data from 6 datasets across technologies"
" (CEL-seq, CEL-seq2, Smart-seq2, inDrop, Fluidigm C1, and SMARTER-seq)."
),
image="openproblems",
)
def pancreas_batch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,6 @@ This sub-task was taken from a
[benchmarking study of data integration
methods](https://openproblems.bio/bibliography#luecken2022benchmarking).

## The metrics

Metrics for batch integration (embed) measure how well batches are mixed while
biological signals are preserved. They are divided into batch correction and biological
variance conservation metrics.

### Batch correction

* **kBET**: kBET determines whether the label composition of a k nearest neighborhood of
a cell is similar to the expected (global) label composition
([Buettner et al., Nat Meth 2019](https://openproblems.bio/bibliography#bttner2018test)).
The test is repeated for a random subset of cells,
and the results are summarized as a rejection rate over all tested neighborhoods.
* **Silhouette batch score**: The absolute silhouette width is computed over batch
labels per cell. As 0 then indicates that batches are well mixed and any deviation from
0 indicates a batch effect, we use the 1-abs(ASW) to map the score to the scale [0;1].
* **Principal component regression (PC regression)**: This compare the explained
variance by batch before and after integration. It returns a score between 0 and 1
(scaled=True) with 0 if the variance contribution hasn’t changed. The larger the score,
the more different the variance contributions are before and after integration.

### Biological variance conservation

* **Cell cycle score**: The cell-cycle conservation score evaluates how well the
cell-cycle effect can be captured before and after integration.
* **Isolated label silhouette**: This score evaluates the compactness for the label(s)
that is(are) shared by fewest batches. It indicates how well rare cell types can be
preserved after integration.
* **Cell type ASW**: The absolute silhouette with is computed on cell identity labels,
measuring their compactness.

## API

WARNING: other than most tasks, `adata.X` should contain log-normalized data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ def sample_method(adata):
"""Create sample method output for testing metrics in this task."""

adata.obsm["X_emb"] = adata.obsm["X_uni_pca"]
adata.uns["is_baseline"] = False
return adata
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
from .....tools.decorators import method
from .....tools.decorators import baseline_method
from .....tools.utils import check_version
from ...batch_integration_graph.methods.baseline import _random_embedding
from ...batch_integration_graph.methods.baseline import _randomize_features

import functools
import numpy as np
import scanpy as sc

_baseline_method = functools.partial(
method,
paper_name="Open Problems for Single Cell Analysis",
paper_reference="openproblems",
paper_year=2022,
code_url="https://github.com/openproblems-bio/openproblems",
is_baseline=True,
)


@_baseline_method(
@baseline_method(
method_name="No Integration",
method_summary="TODO",
)
def no_integration(adata, test=False):
adata.obsm["X_emb"] = adata.obsm["X_uni_pca"]
adata.uns["method_code_version"] = check_version("openproblems")
return adata


@_baseline_method(
@baseline_method(
method_name="Random Integration",
method_summary="TODO",
)
def random_integration(adata, test=False):
adata.obsm["X_emb"] = _randomize_features(adata.obsm["X_uni_pca"])
adata.uns["method_code_version"] = check_version("openproblems")
return adata


@method(
@baseline_method(
method_name="Random Integration by Celltype",
paper_name="Random Integration by Celltype (baseline)",
paper_reference="openproblems",
paper_year=2022,
code_url="https://github.com/openproblems-bio/openproblems",
is_baseline=True,
method_summary="TODO",
)
def celltype_random_integration(adata, test=False):
adata.obsm["X_emb"] = _randomize_features(
Expand All @@ -51,17 +39,19 @@ def celltype_random_integration(adata, test=False):
return adata


@_baseline_method(
@baseline_method(
method_name="Random Embedding by Celltype",
method_summary="TODO",
)
def celltype_random_embedding(adata, test=False):
adata.obsm["X_emb"] = _random_embedding(partition=adata.obs["labels"])
adata.uns["method_code_version"] = check_version("openproblems")
return adata


@_baseline_method(
@baseline_method(
method_name="Random Integration by Batch",
method_summary="TODO",
)
def batch_random_integration(adata, test=False):
adata.obsm["X_emb"] = _randomize_features(
Expand All @@ -71,8 +61,9 @@ def batch_random_integration(adata, test=False):
return adata


@_baseline_method(
@baseline_method(
method_name="No Integration by Batch",
method_summary="TODO",
)
def no_integration_batch(adata, test=False):
"""Compute PCA independently on each batch
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .....tools.decorators import metric
from ...batch_integration_graph import metrics as graph_metrics
from .utils import embedding_to_graph

"""
The Rand index compares the overlap of two clusterings;
Expand All @@ -16,7 +17,4 @@

@metric(**graph_metrics.ari.metadata)
def ari(adata):
from scanpy.pp import neighbors

neighbors(adata, use_rep="X_emb")
return graph_metrics.ari(adata)
return graph_metrics.ari(embedding_to_graph(adata))
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .....tools.decorators import metric
from .utils import get_split

"""
The cell-cycle conservation score evaluates how well the cell-cycle effect can be
Expand All @@ -20,17 +21,20 @@

@metric(
metric_name="Cell Cycle Score",
metric_summary=(
"The cell-cycle conservation score evaluates how well the cell-cycle effect can"
" be captured before and after integration."
),
paper_reference="luecken2022benchmarking",
maximize=True,
image="openproblems-r-pytorch",
)
def cc_score(adata, test=False):
from ._utils import _get_split
def cc_score(adata):
from scib.metrics import cell_cycle

try:
cc = cell_cycle(
*_get_split(adata), "batch", embed="X_emb", organism=adata.uns["organism"]
*get_split(adata), "batch", embed="X_emb", organism=adata.uns["organism"]
)

except ValueError:
Expand Down
Loading