diff --git a/.gitignore b/.gitignore index db343bd..fd3465c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,12 @@ # Data -cellprofiler_all-plates.tar.xz -cellprofiler_all-plates/all-plates.db -z_stack.tar.xz -z_stack/ +data/April_14_2016.tar.xz +data/April_14_2016/ +results/cellprofiler/2017-01-04/cellprofiler_all-plates.tar.xz +results/cellprofiler/2017-02-20/ +results/z_projection.tar.xz +results/z_projection/ *.csv +*.db *.pdf *.png *.svg @@ -12,4 +15,6 @@ z_stack/ *.log # R -.Rhistory \ No newline at end of file +.Rhistory +.Rproj.user +*.Rproj \ No newline at end of file diff --git a/plates/DRSC_TF_Library_Distribution.xls b/data/DRSC_TF_Library_Distribution.xls old mode 100755 new mode 100644 similarity index 100% rename from plates/DRSC_TF_Library_Distribution.xls rename to data/DRSC_TF_Library_Distribution.xls diff --git a/cellprofiler_all-plates/Makefile b/results/cellprofiler/2017-01-04/Makefile similarity index 100% rename from cellprofiler_all-plates/Makefile rename to results/cellprofiler/2017-01-04/Makefile diff --git a/cellprofiler_all-plates/all-plates.properties b/results/cellprofiler/2017-01-04/all-plates.properties similarity index 100% rename from cellprofiler_all-plates/all-plates.properties rename to results/cellprofiler/2017-01-04/all-plates.properties diff --git a/results/cellprofiler/cellprofiler.mk b/results/cellprofiler/cellprofiler.mk new file mode 100644 index 0000000..e573a60 --- /dev/null +++ b/results/cellprofiler/cellprofiler.mk @@ -0,0 +1,29 @@ +# Behavior: empty values are considered false +controls_only = yes + +# Paths +PREFIX_OUTPUT = 2017-02-20 +PREFIX_SRC = ../../src +IMAGES = ../z_projection +PIPELINE = $(PREFIX_SRC)/image-processing-pipeline.cpproj +FILELIST = $(PREFIX_OUTPUT)/filelist + +# Executables +cellprofiler = cellprofiler + +.PHONY: cellprofiler +cellprofiler : $(FILELIST) + $(cellprofiler) \ + --pipeline=$(PIPELINE) \ + --output-directory=$(PREFIX_OUTPUT) \ + --file-list=$(FILELIST) + +.PHONY : filelist +filelist : $(FILELIST) +$(FILELIST) : $(IMAGES) +ifneq ($(CLUSTER),) + find $< -type f | sort > $@ +else +#find $< -type f -regex '^502[^_]_(J18|I09|H09|N22|E20|M13|K11)' | sort > $@ + find $< -type f -regex '.*/502[^_]+_J18_S08.*' | sort > $@ +endif diff --git a/src/image-processing-pipeline.cpproj b/src/image-processing-pipeline.cpproj new file mode 100644 index 0000000..e22f3af Binary files /dev/null and b/src/image-processing-pipeline.cpproj differ diff --git a/src/image_preprocessing_z_projection.py b/src/image_preprocessing_z_projection.py new file mode 100644 index 0000000..503e999 --- /dev/null +++ b/src/image_preprocessing_z_projection.py @@ -0,0 +1,51 @@ +""" +Reduce image Z-stack to maximum intensity projection. +""" +# pylint: disable=invalid-name,superfluous-parens + +import glob +import multiprocessing as mp +import os + +import numpy as np +import scipy.misc + + +out_dir = "../results/z_projection" +z_slices = 3 +# Assume all files are tif, and therefore that the number of files is +# a multiple of z_slices. +print("Reading file list") +all_files = glob.glob('../data/April_14_2016/*/*') +all_files.sort() + +if not os.path.exists(out_dir): + print("Creating output directory") + os.mkdir(out_dir) + +print("Creating output file list") +all_files_out = [ + os.path.join(out_dir, + os.path.basename(all_files[i].replace("_Z1", ""))) + for i in xrange(0, len(all_files), z_slices) +] + +def max_projection(pool_index): + """ + Create and save image maximum intensity projection. + """ + offset = pool_index * z_slices + im1 = scipy.misc.imread(all_files[offset]) + shape = [1] + list(im1.shape) + for file_ in all_files[offset + 1:offset + z_slices]: + im2 = scipy.misc.imread(file_) + im_stack = np.concatenate((im1.reshape(shape), + im2.reshape(shape)), axis=0) + im1 = im_stack.max(axis=0) + scipy.misc.imsave(all_files_out[pool_index], im1) + +print("Reading images, merging and saving (this can take a while)") +pool = mp.Pool() +pool.map(max_projection, xrange(len(all_files_out))) + +print("Finished") diff --git a/analysis-only_overlap.R b/src/overlap-analysis.R similarity index 100% rename from analysis-only_overlap.R rename to src/overlap-analysis.R diff --git a/plot-plates.R b/src/plot-plates.R similarity index 100% rename from plot-plates.R rename to src/plot-plates.R diff --git a/plots.R b/src/plots.R similarity index 100% rename from plots.R rename to src/plots.R