Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MAINT: Rearrange files to comply with http://arxiv.org/abs/1609.00037
  • Loading branch information
pan14001 committed Feb 21, 2017
1 parent 2ffbf61 commit d5f9931
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 5 deletions.
15 changes: 10 additions & 5 deletions .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
Expand All @@ -12,4 +15,6 @@ z_stack/
*.log

# R
.Rhistory
.Rhistory
.Rproj.user
*.Rproj
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions 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
Binary file added src/image-processing-pipeline.cpproj
Binary file not shown.
51 changes: 51 additions & 0 deletions 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")
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d5f9931

Please sign in to comment.