Skip to content

Commit

Permalink
Merge pull request #78 from kbestak/mindagap_skip
Browse files Browse the repository at this point in the history
Mindagap skip
  • Loading branch information
kbestak authored Sep 24, 2024
2 parents b5aee86 + 6dbf1b1 commit b12929c
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 8 deletions.
8 changes: 8 additions & 0 deletions bin/collect_QC.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd
from PIL import Image, ImageDraw, ImageFont
import os
import numpy as np


def combine_png_files(input_paths, output_path):
Expand Down Expand Up @@ -85,6 +86,13 @@ def summarize_segmasks(cellxgene_table, spots_summary):

## Read in spot table
spots = pd.read_table(args.spots, sep="\t", names=["x", "y", "z", "gene"])
# below code had to be added to account for the spots.txt inputs if mindagap is skipped
if (([val for val in spots.index.values] == [val for val in range(len(spots.index.values))]) == False):
spots["gene"] = spots["z"]
spots["z"] = spots["y"]
spots["y"] = spots["x"]
spots["x"] = spots.index
spots.index = range(len(spots))
duplicated = sum(spots.gene.str.contains("Duplicated"))
spots = spots[~spots.gene.str.contains("Duplicated")]

Expand Down
4 changes: 3 additions & 1 deletion conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ process {
publishDir = [
path: { "${params.outdir}/segmentation/filtered_masks" },
mode: params.publish_dir_mode,
pattern: "*.{tiff,tif}"
pattern: "*.{tiff,tif,csv}"
]
}

withName: "MINDAGAP_MINDAGAP" {
ext.when = { !params.skip_mindagap }
ext.args = [ "",
params.mindagap_boxsize ? "${params.mindagap_boxsize}" : "",
params.mindagap_loopnum ? "${params.mindagap_loopnum}" : "",
Expand All @@ -83,6 +84,7 @@ process {
}

withName: "MINDAGAP_DUPLICATEFINDER" {
ext.when = { !params.skip_mindagap }
ext.args = [ "",
params.mindagap_tilesize ? "${params.mindagap_tilesize}" : ""
].join(" ").trim()
Expand Down
1 change: 1 addition & 0 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ params {
ilastik_multicut_project = null

// Preprocessing command line flags
skip_mindagap = false
mindagap_tilesize = 2144
mindagap_boxsize = 3
mindagap_loopnum = 40
Expand Down
5 changes: 5 additions & 0 deletions nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
"default": "",
"fa_icon": "fas fa-adjust",
"properties": {
"skip_mindagap": {
"type": "boolean",
"fa_icon": "fas fa-th-large",
"description": "Skip mindagap if your data does not contain gaps between tiles."
},
"mindagap_boxsize": {
"type": "integer",
"default": 3,
Expand Down
4 changes: 2 additions & 2 deletions subworkflows/local/utils_nfcore_molkart_pipeline/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def toolCitationText() {
// Uncomment function in methodsDescriptionText to render in MultiQC report
def citation_text = [
"Tools used in the workflow included:",
"Mindagap (Guerreiro et al. 2023),",
params.skip_mindagap ? "" : "Mindagap (Guerreiro et al. 2023),",
params.segmentation_method.split(',').contains('mesmer') ? "Mesmer (Greenwald et al. 2021)," : "",
params.segmentation_method.split(',').contains('ilastik') ? "ilastik (Berg et al. 2019)," : "",
params.segmentation_method.split(',').contains('cellpose') ? "Cellpose (Stringer et al. 2021; Pachitariu et al 2022)," : "",
Expand All @@ -184,7 +184,7 @@ def toolBibliographyText() {
// Can use ternary operators to dynamically construct based conditions, e.g. params["run_xyz"] ? "<li>Author (2023) Pub name, Journal, DOI</li>" : "",
// Uncomment function in methodsDescriptionText to render in MultiQC report
def reference_text = [
"<li>Ricardo Guerreiro, Florian Wuennemann, & pvtodorov. (2023). ViriatoII/MindaGap: v0.0.3 (0.0.3). Zenodo. https://doi.org/10.5281/zenodo.8120559",
params.skip_mindagap ? "" : "<li>Ricardo Guerreiro, Florian Wuennemann, & pvtodorov. (2023). ViriatoII/MindaGap: v0.0.3 (0.0.3). Zenodo. https://doi.org/10.5281/zenodo.8120559",
params.segmentation_method.split(',').contains('mesmer') ? "<li>Greenwald, N.F., Miller, G., Moen, E. et al. Whole-cell segmentation of tissue images with human-level performance using large-scale data annotation and deep learning. Nat Biotechnol 40, 555–565 (2022). https://doi.org/10.1038/s41587-021-01094-0</li>" : "",
params.segmentation_method.split(',').contains('ilastik') ? "<li>Berg, S., Kutra, D., Kroeger, T. et al. ilastik: interactive machine learning for (bio)image analysis. Nat Methods 16, 1226–1232 (2019). https://doi.org/10.1038/s41592-019-0582-9</li>" : "",
params.segmentation_method.split(',').contains('cellpose') ? "<li>Stringer, C., Wang, T., Michaelos, M. et al. Cellpose: a generalist algorithm for cellular segmentation. Nat Methods 18, 100–106 (2021). https://doi.org/10.1038/s41592-020-01018-x</li>" : "",
Expand Down
26 changes: 26 additions & 0 deletions tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ nextflow_pipeline {
}
}

test("Skip mindagap - clahe - cellpose") {

when {
params {
input = 'https://raw.githubusercontent.com/nf-core/test-datasets/molkart/test_data/samplesheets/samplesheet_membrane.csv'
outdir = "$outputDir"
clahe_pyramid_tile = 368
segmentation_method = "cellpose"
skip_mindagap = true
}
}

then {
assert workflow.success
assert snapshot(
path("$outputDir/segmentation/cellpose/mem_only_cellpose_mask.tif"),
path("$outputDir/segmentation/filtered_masks/mem_only_cellpose_filtered.tif"),
path("$outputDir/spot2cell/cellxgene_mem_only_cellpose.csv"),
path("$outputDir/anndata/mem_only_cellpose.adata"),
path("$outputDir/molkartqc/mem_only.cellpose.spot_QC.csv"),
).match()
assert file("$outputDir/stack/mem_only_stack.ome.tif").exists()
assert file("$outputDir/multiqc/multiqc_report.html").exists()
}
}

test("Create training subset") {

when {
Expand Down
14 changes: 14 additions & 0 deletions tests/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@
},
"timestamp": "2024-06-11T11:47:51.185058276"
},
"Skip mindagap - clahe - cellpose": {
"content": [
"mem_only_cellpose_mask.tif:md5,8faad3e707aba96d3b93d9419311e843",
"mem_only_cellpose_filtered.tif:md5,5c566683d7af62721415329799ad2ac1",
"cellxgene_mem_only_cellpose.csv:md5,925f5fabeeafc520fe839cabc79fa9ce",
"mem_only_cellpose.adata:md5,a0aa767a32929417f7f3253d12278f3a",
"mem_only.cellpose.spot_QC.csv:md5,e393966b17effbc05c1b93bb590d7e80"
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "24.04.4"
},
"timestamp": "2024-09-10T15:07:17.243436747"
},
"Create training subset": {
"content": [
"nuc_only_nuclear_gridfilled.tiff:md5,123763d54f05b2274690b3b84f9690b1"
Expand Down
1 change: 1 addition & 0 deletions tests/nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
========================================================================================
*/

trace.overwrite = true
9 changes: 4 additions & 5 deletions workflows/molkart.nf
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ workflow MOLKART {
// MODULE: Apply Contrast-limited adaptive histogram equalization (CLAHE)
// CLAHE is either applied to all images, or none.
//
CLAHE(MINDAGAP_MINDAGAP.out.tiff)
clahe_in = params.skip_mindagap ? mindagap_in : MINDAGAP_MINDAGAP.out.tiff
CLAHE(clahe_in)
ch_versions = ch_versions.mix(CLAHE.out.versions)

map_for_stacks = !params.skip_clahe ? CLAHE.out.img_clahe : MINDAGAP_MINDAGAP.out.tiff
map_for_stacks = params.skip_clahe ? clahe_in : CLAHE.out.img_clahe

map_for_stacks
.map {
Expand Down Expand Up @@ -148,8 +149,7 @@ workflow MOLKART {
MINDAGAP_DUPLICATEFINDER(spot_tuple)
ch_versions = ch_versions.mix(MINDAGAP_DUPLICATEFINDER.out.versions)

qc_spots = MINDAGAP_DUPLICATEFINDER.out.marked_dups_spots

qc_spots = params.skip_mindagap ? spot_tuple : MINDAGAP_DUPLICATEFINDER.out.marked_dups_spots
//
// MODULE: DeepCell Mesmer segmentation
//
Expand Down Expand Up @@ -278,7 +278,6 @@ workflow MOLKART {
qc_spots
.combine(spot2cell_out, by: 0)
.set{ molkartqc }

MOLKARTQC(molkartqc)
ch_versions = ch_versions.mix(MOLKARTQC.out.versions)

Expand Down

0 comments on commit b12929c

Please sign in to comment.