This notebook demonstrates how to process plates associated to the paper 'Integration of biological data by kernels on graph nodes allows prediction of new genes involved in mitotic chromosome condensation.' using CellProfiler. We use the example pipeline Cell/particle counting, and scoring the percentage of stained objects. This pipeline is for two channels images only.
# %tb
# Import Cell Profiler Dependencies
import cellprofiler
import cellprofiler.preferences as cpprefs
import cellprofiler.module as cpm
import cellprofiler.pipeline as cpp
cpprefs.set_headless()
# Inject Image module used to inject OMERO image planes into Cell Profiler Pipeline
from cellprofiler.modules.injectimage import InjectImage
# Import Numpy
import numpy as np
# Import Python System Packages
import os
import tempfile
import pandas
import warnings
# Import Matplotlib
import matplotlib
import matplotlib.pyplot as plt
new_output_directory = os.path.normcase(tempfile.mkdtemp())
cpprefs.set_default_output_directory(new_output_directory)
from idr import connection;
conn = connection()
print conn
plate_id = 422
plate = conn.getObject("Plate", plate_id)
print 'Plate Name: ', plate.getName()
# Load pipeline and inspect modules
from os.path import expanduser
home = expanduser("~")
pipeline = cpp.Pipeline()
pipeline.load(home+"/notebooks/includes/ExamplePercentPositive.cppipe")
# Remove first 4 modules: Images, Metadata, NamesAndTypes, Groups...
# (replaced by InjectImage module below)
for i in range(4):
print 'Remove module: ', pipeline.modules()[0].module_name
pipeline.remove_module(1)
print 'Pipeline modules:'
for module in pipeline.modules():
print module.module_num, module.module_name
warnings.filterwarnings('ignore')
Nuclei = pandas.DataFrame()
files = list()
# create list from generator
wells = list(plate.listChildren())
well_count = len(wells)
# Set the limit to a lower value e.g. 10 wells to speed up the process.
limit = well_count
for count, well in zip(range(limit), wells):
print 'Well: %s/%s' % (count + 1, well_count), 'row:', well.row, 'column:', well.column
# Load a single Image per Well
image = well.getImage(0)
pixels = image.getPrimaryPixels()
size_c = image.getSizeC()
# For each Image in IDR, we copy the pipeline and inject image modules
pipeline_copy = pipeline.copy()
# Inject image for each Channel (pipeline only handles 2 channels)
for c in range(0, size_c):
plane = pixels.getPlane(0, c, 0)
image_name = image.getName()
# Name of the channel expected in the pipeline
if c == 0:
image_name = 'OrigBlue'
if c == 1:
image_name = 'OrigGreen'
inject_image_module = InjectImage(image_name, plane)
inject_image_module.set_module_num(1)
pipeline_copy.add_module(inject_image_module)
m = pipeline_copy.run()
#Results obtained as CSV from Cell Profiler
path = new_output_directory + '/Nuclei.csv'
f = pandas.read_csv(path, index_col=None, header=0)
f['Image'] = image.getId()
f['Well'] = well.getId()
f['Cell_Count'] = len(f.index)
files.append(f)
Nuclei = pandas.concat(files, ignore_index=True)
Nuclei.describe()
matplotlib.rcParams['figure.figsize'] = (32.0, 30.0)
#Drop few columns
df = Nuclei.drop(['Image', 'ImageNumber', 'Well', 'ObjectNumber', 'Number_Object_Number', 'Classify_PH3Neg', 'Classify_PH3Pos'], axis=1)
df.hist();
conn.close()
Copyright (C) 2018 University of Dundee. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.