Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
143 lines (123 sloc) 5.29 KB
# To run everything:
#
# make
#
# For help running specific parts:
#
# make help
# Overwritable paths to executables
CELLPROFILER := cellprofiler
CELLPROFILERANALYST := cellprofiler-analyst
PARALLEL := parallel --eta
PYTHON := python
RSCRIPT := Rscript
TIME := command time --format "Completed in wall clock time [H:M:S]: %E"
# Make rule sources, targets and helper functions
SOURCES_img_raw := data/April_14_2016.tar.xz
TARGETS_img_raw := data/April_14_2016
SOURCES_img_zproj := $(TARGETS_img_raw)
TARGETS_img_zproj := results/z_projection
SOURCES_img_filelist := $(TARGETS_img_zproj)
TARGETS_img_filelist := results/cellprofiler/filelist
SOURCES_cellprofiler_filelist := $(TARGETS_img_filelist)
SOURCES_cellprofiler_pipe := src/image-processing-pipeline.cpproj
SOURCES_cellprofiler_img := $(TARGETS_zproj)
SOURCES_cellprofiler_common := $(SOURCES_cellprofiler_filelist) \
$(SOURCES_cellprofiler_img)
SOURCES_cellprofiler_gui := $(SOURCES_cellprofiler_common) \
$(SOURCES_cellprofiler_pipe)
SOURCES_cellprofiler_batch := $(SOURCES_cellprofiler_common) \
$(SOURCES_cellprofiler_pipe)
TARGETS_cellprofiler_batch := results/cellprofiler/Batch_data.h5
SOURCES_cellprofiler_commands := $(TARGETS_cellprofiler_batch)
TARGETS_cellprofiler_commands := results/cellprofiler/batch_commands.sh
SOURCES_cellprofiler_headless := $(TARGETS_cellprofiler_commands)
TARGETS_cellprofiler_db := results/cellprofiler/rnai-screen-tf.db
TARGETS_cellprofiler_prop := $(TARGETS_cellprofiler_db:.db=.properties)
TARGETS_cellprofiler := $(TARGETS_cellprofiler_db) $(TARGETS_cellprofiler_prop)
SOURCES_cellprofileranalyst_patch := $(TARGETS_cellprofiler_prop)
TARGETS_cellprofileranalyst_patch := \
$(SOURCES_cellprofileranalyst_patch:.properties=_patched.properties)
SOURCES_cellprofileranalyst := $(TARGETS_cellprofileranalyst_patch)
define CELLPROFILER_OPTS_COMMON
--file-list=$(SOURCES_cellprofiler_filelist) \
--output-directory=$(dir $(TARGETS_cellprofiler_db))
endef
define CELLPROFILER_OPTS_GUI
$(CELLPROFILER_OPTS_COMMON) \
--pipeline=$(SOURCES_cellprofiler_pipe)
endef
define CELLPROFILER_OPTS_BATCH
$(CELLPROFILER_OPTS_COMMON) \
--pipeline=$(SOURCES_cellprofiler_pipe) \
--run-headless
endef
define CELLPROFILER_OPTS_HEADLESS
$(CELLPROFILER_OPTS_COMMON) \
--pipeline=$(SOURCES_cellprofiler_commands) \
--run-headless
endef
SOURCES_signif_wells := src/overlap-analysis.R $(TARGETS_cellprofiler_db)
TARGETS_signif_wells := results/tables/rnai-p_values.csv
SOURCES_plot_overlap := src/plots.R $(TARGETS_signif_wells)
TARGETS_plot_overlap := results/plots/rnai-hist-signif.png
SOURCES_plot_plates := src/plot-plates.R $(TARGETS_signif_wells)
TARGETS_plot_plates := results/plots/stddev-scatter.png
TARGETS_plots := $(TARGETS_plot_overlap) $(TARGETS_plot_plates)
# Functions
#
# Hack of single rule invocation for multiple targets by substituting
# file extension "." with "%" per http://stackoverflow.com/a/3077254
define singleton
$(foreach path,$1,$(shell echo -n $(path) | sed 's#\(.*\)\.#\1%##'))
endef
.PHONY : all
all : z-projection cellprofiler stats plots ## (Default) Run full pipeline from image processing to plots.
# Self-documenting help modified from
# https://gist.github.com/prwhite/8168133#gistcomment-1737630
.PHONY : help
help : ## Show this help.
@echo -e 'Usage: make [TARGET] ...\n\nTargets:'
@sed -nE 's|^(\S+)[^#]+##(.+)|\1\t\2|p' $(MAKEFILE_LIST) | column -t -s ' '
# More robust would be to associate individual target TIF files
# contained in the tarball, but reading the archive takes a long time
# and adds overhead to Makefile processing.
$(TARGTS_img_raw) : $(SOURCES_img_raw)
cd data; tar -xvJpf $<
.PHONY : z-projection
z-projection : $(TARGETS_img_zproj) ## Generate maximum intensity projection images.
$(TARGETS_img_zproj) : $(SOURCES_img_zproj)
$(PYTHON) src/image_preprocessing_z_projection.py $< $@
.PHONY : cellprofiler
cellprofiler : $(TARGETS_cellprofiler) ## Collect statistics about all images.
$(call singleton,$(TARGETS_cellprofiler)) : $(SOURCES_cellprofiler_headless)
$(TIME) $(PARALLEL) :::: $<
$(TARGETS_cellprofiler_commands) : $(SOURCES_cellprofiler_commands)
$(TIME) $(CELLPROFILER) $(CELLPROFILER_OPTS_HEADLESS) --get-batch-commands=$< | sed 's#^CellProfiler#$(CELLPROFILER)#' | sort -nk 8 > $@
$(TARGETS_cellprofiler_batch) : $(SOURCES_cellprofiler_batch)
$(TIME) $(CELLPROFILER) $(CELLPROFILER_OPTS_BATCH)
.PHONY : gui-cp
gui-cp : $(SOURCES_cellprofiler_gui) ## Interactively run CellProfiler.
$(CELLPROFILER) $(CELLPROFILER_OPTS_GUI)
.PHONY : gui-cpa
gui-cpa : $(SOURCES_cellprofileranalyst) ## Interactively run CellProfiler Analyst.
cd $(<D); $(CELLPROFILERANALYST) $(<F)
$(TARGETS_cellprofileranalyst_patch) : $(SOURCES_cellprofileranalyst_patch)
@echo "Removing database path"
sed -E 's#^(db_sqlite_file[[:space:]]+=[[:space:]]).*/([^/]+)$$#\1\2#' $< > $@
$(TARGETS_img_filelist) : $(abspath $(SOURCES_img_filelist))
find $< -type f | sort > $@
.PHONY : stats
stats : $(TARGETS_signif_wells) ## Find significant wells from cellprofiler measurements.
$(TARGETS_signif_wells) : $(SOURCES_signif_wells)
cd $(<D); $(RSCRIPT) $(<F)
.PHONY : plots
plots : $(TARGETS_plots)
$(TARGETS_plot_overlap) : $(SOURCES_plot_overlap)
cd $(<D); $(RSCRIPT) $(<F)
$(TARGETS_plot_plates) : $(SOURCES_plot_plates)
cd $(<D); $(RSCRIPT) $(<F)
.PHONY : clean-all
clean-all : ## Delete all output.
rm -rf $(TARGETS_img_raw)
rm -rf results/*
You can’t perform that action at this time.