Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seurat 4.4 #33

Merged
merged 11 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 10 additions & 23 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest"]
os: ["ubuntu-latest"]
defaults:
run:
shell: bash -l {0}
Expand All @@ -20,32 +20,19 @@ jobs:
run: |
echo "${GITHUB_WORKSPACE}" >> $GITHUB_PATH

- name: Cache conda
uses: actions/cache@v1
env:
# Increase this value to reset cache if etc/example-environment.yml has not changed
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key:
${{ matrix.os }}-conda-${{ env.CACHE_NUMBER }}-${{hashFiles('test-environment.yml') }}

- uses: conda-incubator/setup-miniconda@v2
- uses: mamba-org/setup-micromamba@v1
with:
activate-environment: test
micromamba-version: '1.4.5-0'
environment-file: test-environment.yml
mamba-version: "*"
miniforge-variant: Mambaforge
use-mamba: true
miniforge-version: latest
python-version: 3.6
channels: conda-forge,bioconda,defaults
allow-softlinks: true
channel-priority: flexible
show-channel-urls: true
use-only-tar-bz2: true
init-shell: >-
bash
cache-environment: true
create-args: |
python=${{ matrix.python-version }}
post-cleanup: 'all'

- name: Run tests
shell: bash -el {0}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# seurat-scripts 4.x.y for Seurat 4.0.0 [![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg?style=flat)](http://bioconda.github.io/recipes/seurat-scripts/README.html)
# seurat-scripts 4.x.y for Seurat 4.4.0 [![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg?style=flat)](http://bioconda.github.io/recipes/seurat-scripts/README.html)

In order to wrap Seurat's internal workflow in any given workflow language, it's important to have scripts to call each of those steps, which is what this package provides.

This version of seurat-scripts uses native conversions to Loom, SCE, Seurat H5 and AnnData.

Please note that given the little man power available to maintain this, we dropped MacOS support for Seurat version 4.4.0 onwards (not all tests were passing and there was no bandwidth to take care of the dependencies issues on both linux and macOS).

## Install

The recommended method for script installation is via a Bioconda recipe called seurat-scripts.
The recommended method for usage is through the [biocontainer](https://quay.io/repository/biocontainers/seurat-scripts?tab=tags&tag=latest) produced by Bioconda. If needed, scripts installation is via a Bioconda recipe called seurat-scripts.

With the [Bioconda channels](https://bioconda.github.io/#set-up-channels) configured the latest release version of the package can be installed via the regular conda install command:

Expand Down
5 changes: 3 additions & 2 deletions r-seurat-scripts-post-install-tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
}

@test "Classify against reference" {
# maybe this should be moved after PCA and UMAP of integrated object
if [ "$use_existing_outputs" = 'true' ] && [ -f "$classify_result_object" ]; then
skip "$classify_result_object exists and use_existing_outputs is set to true"
fi
Expand Down Expand Up @@ -466,7 +467,7 @@
-o $tmp_conserved_markers_fn_object && \
seurat-find-clusters.R -i $tmp_conserved_markers_fn_object --resolution 0.5 \
-o $tmp_conserved_markers_cl_object -t $cluster_text_file".conserved_tmp.txt" && \
seurat-find-conserved-markers.R -i $tmp_conserved_markers_cl_object --ident-1 6 --ident-2 4 --grouping-var "tech" -o $conserved_markers_result
seurat-find-conserved-markers.R -i $tmp_conserved_markers_cl_object --ident-1 1 --ident-2 2 --grouping-var "tech" -o $conserved_markers_result

[ "$status" -eq 0 ]
[ -f "$conserved_markers_result" ]
Expand Down Expand Up @@ -515,7 +516,7 @@
run rm -rf ${loom_converted_cluster_object}.loom && \
seurat-convert.R -i $singlecellexperiment_converted_cluster_object \
--input-format singlecellexperiment -o $loom_converted_cluster_object \
--output-format loom
--output-format loom --input-assay NULL

echo "status = ${status}"
echo "output = ${output}"
Expand Down
18 changes: 18 additions & 0 deletions seurat-classify-against-reference.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ option_list = list(
type = 'character',
help = "Dimensional reduction to perform when finding anchors."
),
make_option(
c("--reference_reduction"),
action = "store",
default = "pca",
type = 'character',
help = "Name of dimensional reduction to use from the reference if running the pcaproject workflow. Optionally enables reuse of precomputed reference dimensional reduction. If NULL (default), use a PCA computed on the reference object."
),
make_option(
c("--project-query"),
action = "store_false",
Expand Down Expand Up @@ -285,13 +292,24 @@ if (opt$query_format == "singlecellexperiment" | opt$reference_format == "single

seurat_query <- read_seurat4_object(input_path = opt$query_file, format = opt$query_format)
seurat_reference <- read_seurat4_object(input_path = opt$reference_file, format = opt$reference_format)

if(!(opt$reference_reduction %in% names(seurat_reference@reductions))) {
print(paste0("Calculating reduction ", opt$reference_reduction," as it is not present in the reference object."))
if(opt$reference_reduction == "pca") {
seurat_reference <- ScaleData(seurat_reference, verbose = FALSE)
seurat_reference <- RunPCA(seurat_reference, npcs=30, verbose = FALSE)
} else {
stop((paste('Reduction default calculation on reference not implemented for ', opt$reference_reduction, ', please compute previously on reference object.')))
}
}
#make the function work
anchor_object <- FindTransferAnchors(seurat_reference,
seurat_query,
normalization.method = opt$normalization_method,
reference.assay = opt$reference_assay,
query.assay = opt$query_assay,
reduction = opt$reduction,
reference.reduction = opt$reference_reduction,
project.query = opt$project_query,
features = opt$features,
npcs = opt$npcs,
Expand Down
12 changes: 11 additions & 1 deletion seurat-convert.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ option_list <- list(
default = "seurat",
type = "character",
help = "Either seurat, h5seurat, loom, singlecellexperiment or h5seurat (partial support)")
,
make_option(
c("--input-assay"),
action = "store",
default = "RNA",
type = "character",
help = "The assay to be read from the input object, if it corresponds")
)

opt <- wsc_parse_args(option_list,
Expand All @@ -49,9 +56,12 @@ if (!file.exists(opt$input_object_file)) {
stop((paste("File", opt$input_object_file, "does not exist")))
}

if(opt$input_assay == "NULL") {
opt$input_assay <- NULL
}

seurat_object <- read_seurat4_object(input_path = opt$input_object_file,
format = opt$input_format)
format = opt$input_format, assay = opt$input_assay)

write_seurat4_object(seurat_object = seurat_object,
output_path = opt$output_object_file,
Expand Down
15 changes: 11 additions & 4 deletions seurat-find-conserved-markers.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ suppressPackageStartupMessages(require(optparse))
suppressPackageStartupMessages(require(scater))
suppressPackageStartupMessages(require(Seurat))
suppressPackageStartupMessages(require(workflowscriptscommon))
suppressPackageStartupMessages(require(metap))

option_list <- list(
make_option(
Expand Down Expand Up @@ -65,9 +66,9 @@ option_list <- list(
make_option(
c("--meta-method"),
action = "store",
default = "metap::minimump",
default = "minimump",
type = "character",
help = "method for combining p-values. Should be a function from the metap package (NOTE: pass the function, not a string)"
help = "method for combining p-values. Should be a function from the metap package: invchisq, invt, logitp, meanp, meanz, maximump, minimump, sumlog, sumz, truncated, votep, wilkinsonp"
),
make_option(
c("--reduction"),
Expand Down Expand Up @@ -204,13 +205,19 @@ if (!file.exists(opt$input_object_file)) {
stop((paste("File", opt$input_object_file, "does not exist")))
}

list_of_meta_methods <- ls("package:metap")
metap_method <- NULL
if(!is.null(opt$meta_method) && !(opt$meta_method %in% list_of_meta_methods)) {
stop((paste("Metap method requested ", opt$meta_method, " doesn't exist, please choose from: ", list_of_meta_methods)))
} else {
# safer way of running eval parse
opt$meta_method <- eval(parse(text=paste0("metap::", opt$meta_method)))
}

load_seurat4_packages_for_format(formats = c(opt$query_format, opt$anchors_format, opt$reference_format))

seurat_object <- read_seurat4_object(input_path = opt$input_object_file,
format = opt$input_format)
# transform method name into actual R function. This should probably be sanitised in Galaxy
opt$meta_method <- eval(parse(text=opt$meta_method))

conserved_markers <- FindConservedMarkers(object = seurat_object,
ident.1 = opt$ident_1,
Expand Down
15 changes: 10 additions & 5 deletions test-environment.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
name: test
name: [email protected]
channels:
- defaults
- conda-forge
- bioconda
dependencies:
- bats
- bats-core
- r-optparse
- libpng
- r-cairo
- r-workflowscriptscommon >=0.0.8
- r-seurat=4.0.0
- r-uwot <0.1.11
- r-seurat<=4.4
# - r-uwot
- r-loom
- r-svglite
- bioconductor-scater
- r-seuratdisk
- r-remotes
- bioconductor-multtest
- r-metap
- pandoc
- pandoc
- bioconductor-limma
Loading