def test_04_02_alter_output_folder_path(self): s = cps.DirectoryPath("whatever") s.dir_choice = cps.DEFAULT_OUTPUT_FOLDER_NAME s.alter_for_create_batch_files(TestDirectoryPath.fn_alter_path) self.assertEqual( s.get_absolute_path(), cpprefs.get_default_output_directory())
def test_02_04_get_output_subfolder_path(self): s = cps.DirectoryPath("whatever") s.dir_choice = cps.DEFAULT_OUTPUT_SUBFOLDER_NAME s.custom_path = "0" self.assertEqual( s.get_absolute_path(), os.path.join(cpprefs.get_default_output_directory(), "0"))
def test_04_05_alter_absolute_path(self): s = cps.DirectoryPath("whatever") s.dir_choice = cps.ABSOLUTE_FOLDER_NAME s.custom_path = os.path.join(self.root_directory,"..","1","2") s.alter_for_create_batch_files(TestDirectoryPath.fn_alter_path) self.assertEqual(s.get_absolute_path(), os.path.join(self.root_directory, "2altered"))
def test_04_06_alter_url(self): s = cps.DirectoryPath("whatever") s.dir_choice = cps.URL_FOLDER_NAME s.custom_path = "http://www.cellprofiler.org" s.alter_for_create_batch_files(TestDirectoryPath.fn_alter_path) self.assertEqual(s.get_absolute_path(), "http://www.cellprofiler.org")
def create_settings(self): """Create the settings during initialization """ self.directory = cps.DirectoryPath( "Input image file location", support_urls=True, doc= '''Select the folder containing the image(s) to be loaded. Generally, it is best to store the image you want to load in either the Default Input or Output Folder, so that the correct image is loaded into the pipeline and typos are avoided. %(IO_FOLDER_CHOICE_HELP_TEXT)s <p>%(IO_WITH_METADATA_HELP_TEXT)s %(USING_METADATA_TAGS_REF)s For instance, if you have a "Plate" metadata tag, and your single files are organized in subfolders named with the "Plate" tag, you can select one of the subfolder options and then specify a subfolder name of "\g<Plate>" to get the files from the subfolder associated with that image's plate. The module will substitute the metadata values for the current image set for any metadata tags in the folder name. %(USING_METADATA_HELP_REF)s.</p>''' % globals()) self.file_settings = [] self.add_file(can_remove=False) self.add_button = cps.DoSomething("", "Add another image", self.add_file)
def create_settings(self): self.image_name = cps.ImageNameSubscriber("Select the input image", cps.NONE) self.probability_maps = [] self.probability_map_count = cps.HiddenCount(self.probability_maps, "Probability map count") self.add_probability_map(False) self.add_probability_button = cps.DoSomething( "", "Add another probability map", self.add_probability_map, doc=""" Press this button to output another probability map image from the classifier. Ilastik can be trained to recognize any number of classes of pixels. You can generate probability maps for any or all of them simultaneously by adding more images.""") self.h5_directory = cps.DirectoryPath( "Classifier file location", dir_choices=[ DEFAULT_OUTPUT_FOLDER_NAME, DEFAULT_INPUT_FOLDER_NAME, ABSOLUTE_FOLDER_NAME, DEFAULT_INPUT_SUBFOLDER_NAME, DEFAULT_OUTPUT_SUBFOLDER_NAME, URL_FOLDER_NAME ], allow_metadata=False, doc=""" Select the folder containing the classifier file to be loaded. %(IO_FOLDER_CHOICE_HELP_TEXT)s""" % globals()) def get_directory_fn(): '''Get the directory for the CSV file name''' return self.h5_directory.get_absolute_path() def set_directory_fn(path): dir_choice, custom_path = self.h5_directory.get_parts_from_path( path) self.h5_directory.join_parts(dir_choice, custom_path) self.classifier_file_name = cps.FilenameText( "Classfier file name", cps.NONE, doc="""This is the name of the Classfier file.""", get_directory_fn=get_directory_fn, set_directory_fn=set_directory_fn, browse_msg="Choose Classifier file", exts=[("Classfier file (*.h5)", "*.h5"), ("All files (*.*)", "*.*")]) self.no_ilastik_msg = cps.HTMLText("", content=""" ClassifyPixels cannot run on this platform because the necessary libraries are not available. ClassifyPixels is supported on 64-bit versions of Windows Vista, Windows 7 and Windows 8 and on Linux.""", size=(-1, 50))
def test_04_04_alter_output_subfolder_path(self): s = cps.DirectoryPath("whatever") s.dir_choice = cps.DEFAULT_OUTPUT_SUBFOLDER_NAME s.custom_path = "0" s.alter_for_create_batch_files(TestDirectoryPath.fn_alter_path) self.assertEqual( s.get_absolute_path(), os.path.join(cpprefs.get_default_output_directory(), "0altered"))
def create_settings(self): self.image_name = cps.ImageNameProvider( "Input image name", "TodaysImage") # # The DirectoryPath setting lets the user pick a directory # to be scanned. # self.folder = cps.DirectoryPath("Folder")
def test_01_02_split_and_join(self): gibberish = "aqwura[oijs|fd" for dir_choice in cps.DirectoryPath.DIR_ALL + [ cps.NO_FOLDER_NAME ]: s = cps.DirectoryPath("whatever") value = s.join_parts(dir_choice, gibberish) out_dir_choice = s.dir_choice custom_path = s.custom_path self.assertEqual(dir_choice, out_dir_choice) self.assertEqual(custom_path, gibberish)
def test_01_03_is_custom_choice(self): for dir_choice, expected in ((cps.DEFAULT_INPUT_FOLDER_NAME, False), (cps.DEFAULT_INPUT_SUBFOLDER_NAME, True), (cps.DEFAULT_OUTPUT_FOLDER_NAME, False), (cps.DEFAULT_OUTPUT_SUBFOLDER_NAME, True), (cps.ABSOLUTE_FOLDER_NAME, True), (cps.URL_FOLDER_NAME, True)): s = cps.DirectoryPath("whatever") s.dir_choice = dir_choice self.assertEqual(s.is_custom_choice, expected)
def test_04_03_alter_input_subfolder_path(self): s = cps.DirectoryPath("whatever") s.dir_choice = cps.DEFAULT_INPUT_SUBFOLDER_NAME s.custom_path = "2" def fn_alter_path(path, **kwargs): self.assertEqual(path, "2") return "3" s.alter_for_create_batch_files(fn_alter_path) self.assertEqual( s.get_absolute_path(), os.path.join(cpprefs.get_default_image_directory(), "3"))
def create_settings(self): self.image_name = cps.ImageNameSubscriber("Select the input image", "None") self.probability_maps = [] self.probability_map_count = cps.HiddenCount(self.probability_maps, "Probability map count") self.add_probability_map(False) self.add_probability_button = cps.DoSomething( "Add another probability map", "Add", self.add_probability_map, doc="""Press the <i>Add</i> button to output another probability map image from the classifier. Ilastik can be trained to recognize any number of classes of pixels. You can generate probability maps for any or all of them simultaneously by adding more images.""") self.h5_directory = cps.DirectoryPath( "Classifier file location", dir_choices=[ DEFAULT_OUTPUT_FOLDER_NAME, DEFAULT_INPUT_FOLDER_NAME, ABSOLUTE_FOLDER_NAME, DEFAULT_INPUT_SUBFOLDER_NAME, DEFAULT_OUTPUT_SUBFOLDER_NAME ], allow_metadata=False, doc= """Select the folder containing the classifier file to be loaded. %(IO_FOLDER_CHOICE_HELP_TEXT)s""" % globals()) def get_directory_fn(): '''Get the directory for the CSV file name''' return self.h5_directory.get_absolute_path() def set_directory_fn(path): dir_choice, custom_path = self.h5_directory.get_parts_from_path( path) self.h5_directory.join_parts(dir_choice, custom_path) self.classifier_file_name = cps.FilenameText( "Classfier file name", "None", doc="""This is the name of the Classfier file.""", get_directory_fn=get_directory_fn, set_directory_fn=set_directory_fn, browse_msg="Choose Classifier file", exts=[("Classfier file (*.h5)", "*.h5"), ("All files (*.*)", "*.*")])
def create_settings(self): self.image_name = cps.ImageNameSubscriber("Select the input image", "None") # The following settings are used for the combine option self.output_image = cps.ImageNameProvider( "Name the output probability map", "ProbabilityMap") self.class_sel = cps.Integer( "Select the class", 0, 0, 42, doc='''Select the class you want to use. The class number corresponds to the label-class in ilastik''') self.h5_directory = cps.DirectoryPath( "Classifier file location", dir_choices=[ DEFAULT_OUTPUT_FOLDER_NAME, DEFAULT_INPUT_FOLDER_NAME, ABSOLUTE_FOLDER_NAME, DEFAULT_INPUT_SUBFOLDER_NAME, DEFAULT_OUTPUT_SUBFOLDER_NAME ], allow_metadata=False, doc= """Select the folder containing the classifier file to be loaded. %(IO_FOLDER_CHOICE_HELP_TEXT)s""" % globals()) def get_directory_fn(): '''Get the directory for the CSV file name''' return self.h5_directory.get_absolute_path() def set_directory_fn(path): dir_choice, custom_path = self.h5_directory.get_parts_from_path( path) self.h5_directory.join_parts(dir_choice, custom_path) self.classifier_file_name = cps.FilenameText( "Classfier file name", "None", doc="""This is the name of the Classfier file.""", get_directory_fn=get_directory_fn, set_directory_fn=set_directory_fn, browse_msg="Choose Classifier file", exts=[("Classfier file (*.h5)", "*.h5"), ("All files (*.*)", "*.*")])
def test_03_07_metadata(self): m = cpmeas.Measurements() m.add_image_measurement("Metadata_Path", "2") s = cps.DirectoryPath("whatever", allow_metadata = True) for dir_choice, expected in ( ( cps.DEFAULT_INPUT_SUBFOLDER_NAME, os.path.join(cpprefs.get_default_image_directory(), "0", "2")), ( cps.DEFAULT_OUTPUT_SUBFOLDER_NAME, os.path.join(cpprefs.get_default_output_directory(), "0", "2")), ( cps.ABSOLUTE_FOLDER_NAME, os.path.join(self.root_directory, "2")), ( cps.URL_FOLDER_NAME, "http://www.cellprofiler.org/2")): s.dir_choice = dir_choice if dir_choice in (cps.DEFAULT_INPUT_SUBFOLDER_NAME, cps.DEFAULT_OUTPUT_SUBFOLDER_NAME): s.custom_path = "0" + os.path.sep.replace('\\','\\\\') + "\\g<Path>" elif dir_choice == cps.ABSOLUTE_FOLDER_NAME: s.custom_path = self.root_directory + os.path.sep.replace('\\','\\\\') + "\\g<Path>" else: s.custom_path = "http://www.cellprofiler.org/\\g<Path>" self.assertEqual(s.get_absolute_path(m), expected)
def add_measurement(self, flag_settings, can_delete=True): measurement_settings = flag_settings.measurement_settings group = cps.SettingsGroup() group.append("divider1", cps.Divider(line=False)) group.append("source_choice", cps.Choice( "Flag is based on", S_ALL, doc = ''' <ul> <li><i> Whole-image measurement:</i> A per-image measurement, such as intensity or granularity.</li> <li><i> Average measurement for all objects in each image:</i> The average of all object measurements in the image.</li> <li><i> Measurements for all objects in each image:</i> All the object measurements in an image, without averaging. In other words, if <i>any</i> of the objects meet the criteria, the image will be flagged.</li> <li><i>Rules:</i>Use a text file of rules produced by CellProfiler Analyst. If you choose <i>Rules</i>, you will have to ensure that this pipeline makes every measurement in the rules file prior to this module.</li> </ul>''')) group.append("object_name", cps.ObjectNameSubscriber( "Select the object whose measurements will be used to flag", "None", doc = '''<i>(Used only when flag is based on an object measurement)</i><br>What did you call the objects whose measurements you want to use for flagging?''')) def object_fn(): if group.source_choice == S_IMAGE: return cpmeas.IMAGE return group.object_name.value group.append("rules_directory", cps.DirectoryPath( "Rules file location", doc = """<i>(Used only when filtering by rules)</i> <br> Select the location of the rules file that will be used for filtering. %(IO_FOLDER_CHOICE_HELP_TEXT)s""" % globals())) def get_directory_fn(): '''Get the directory for the rules file name''' return group.rules_directory.get_absolute_path() def set_directory_fn(path): dir_choice, custom_path = group.rules_directory.get_parts_from_path(path) group.rules_directory.join_parts(dir_choice, custom_path) group.append("rules_file_name", cps.FilenameText( "Rules file name","rules.txt", get_directory_fn = get_directory_fn, set_directory_fn = set_directory_fn, doc="""<i>(Used only when filtering using rules)</i> <br>The name of the file holding the rules. Each line of this file should be a rule naming a measurement to be made on an image, for instance:<pre>IF (Image_ImageQuality_PowerLogLogSlope_DNA < -2.5, [0.79, -0.79], [-0.94, 0.94])</pre><br><br> The above rule will score +0.79 for the positive category and -0.94 for the negative category for images whose power log slope is less than -2.5 pixels and will score the opposite for images whose slope is larger. The filter adds positive and negative and flags the images whose positive score is higher than the negative score. <p>Note that if the rules are obtained from CellProfiler Analyst, the images that are fail are those represented by the second number between the brackets.</p>""")) group.append("measurement", cps.Measurement("Which measurement?", object_fn)) group.append("wants_minimum", cps.Binary("Flag images based on low values?", True, doc = '''Images with measurements below this cutoff will be flagged.''')) group.append("minimum_value", cps.Float("Minimum value", 0)) group.append("wants_maximum", cps.Binary("Flag images based on high values?", True, doc = '''Images with measurements above this cutoff will be flagged.''')) group.append("maximum_value", cps.Float("Maximum value", 1)) if can_delete: group.append("remover", cps.RemoveSettingButton("", "Remove this measurement", measurement_settings, group)) group.append("divider2", cps.Divider(line=True)) measurement_settings.append(group)
def create_settings(self): self.delimiter = cps.CustomChoice( 'Select or enter the column delimiter', DELIMITERS, doc=""" What delimiter do you want to use? This is the character that separates columns in a file. The two default choices are tab and comma, but you can type in any single character delimiter you would prefer. Be sure that the delimiter you choose is not a character that is present within your data (for example, in file names).""" ) self.prepend_output_filename = cps.Binary( "Prepend the output file name to the data file names?", True, doc=""" This can be useful if you want to run a pipeline multiple times without overwriting the old results.""") self.directory = cps.DirectoryPath( "Output file location", dir_choices=[ DEFAULT_OUTPUT_FOLDER_NAME, DEFAULT_INPUT_FOLDER_NAME, ABSOLUTE_FOLDER_NAME, DEFAULT_INPUT_SUBFOLDER_NAME, DEFAULT_OUTPUT_SUBFOLDER_NAME ], doc="""This setting lets you choose the folder for the output files. %(IO_FOLDER_CHOICE_HELP_TEXT)s <p>%(IO_WITH_METADATA_HELP_TEXT)s %(USING_METADATA_TAGS_REF)s<br> For instance, if you have a metadata tag named "Plate", you can create a per-plate folder by selecting one of the subfolder options and then specifying the subfolder name as "\g<Plate>". The module will substitute the metadata values for the current image set for any metadata tags in the folder name. %(USING_METADATA_HELP_REF)s.</p>""" % globals()) self.add_metadata = cps.Binary( "Add image metadata columns to your object data file?", False, doc= """"Image_Metadata_" columns are normally exported in the Image data file, but if you check this box they will also be exported with the Object data file(s).""" ) self.excel_limits = cps.Binary( "Limit output to a size that is allowed in Excel?", False, doc=""" If your output has more than 256 columns, a window will open which allows you to select the columns you'd like to export. If your output exceeds 65,000 rows, you can still open the .csv in Excel, but not all rows will be visible.""" ) self.pick_columns = cps.Binary( "Select the columns of measurements to export?", False, doc=""" Checking this setting will open up a window that allows you to select the columns to export.""" ) self.columns = cps.MeasurementMultiChoice( "Press button to select measurements to export", doc= """<i>(Used only when selecting the columns of measurements to export)</i><br>This setting controls the columns to be exported. Press the button and check the measurements or categories to export""") self.wants_aggregate_means = cps.Binary( "Calculate the per-image mean values for object measurements?", False, doc=""" <b>ExportToSpreadsheet</b> can calculate population statistics over all the objects in each image and save that value as an aggregate measurement in the Image file. For instance, if you are measuring the area of the Nuclei objects and you check the box for this option, <b>ExportToSpreadsheet</b> will create a column in the Image file called "Mean_Nuclei_AreaShape_Area". <p>You may not want to use <b>ExportToSpreadsheet</b> to calculate these measurements if your pipeline generates a large number of per-object measurements; doing so might exceed Excel's limits on the number of columns (256). """ ) self.wants_aggregate_medians = cps.Binary( "Calculate the per-image median values for object measurements?", False) self.wants_aggregate_std = cps.Binary( "Calculate the per-image standard deviation values for object measurements?", False) self.wants_genepattern_file = cps.Binary( "Create a GenePattern GCT file?", False, doc=""" Create a GCT file compatible with <a href="http://www.broadinstitute.org/cancer/software/genepattern/">GenePattern</a>. The GCT file format is a tab-delimited text file format that describes a gene expression dataset; the specifics of the format are described <a href="http://www.broadinstitute.org/cancer/software/genepattern/tutorial/gp_fileformats.html#gct">here</a>. By converting your measurements into a GCT file, you can make use of GenePattern's data visualization and clustering methods. <p>Each row in the GCT file represents (ordinarily) a gene and each column represents a sample (in this case, a per-image set of measurements). In addition to any other spreadsheets desired, checking this box will produce a GCT file with the extension .gct, prepended with the text selection above. If per-image aggregate measurements are requested above, those measurements are included in the GCT file as well.</p>""") self.how_to_specify_gene_name = cps.Choice( "Select source of sample row name", GP_NAME_OPTIONS, GP_NAME_METADATA, doc=""" <i>(Used only if a GenePattern file is requested)</i><br> The first column of the GCT file is the unique identifier for each sample, which is ordinarily the gene name. This information may be specified in one of two ways: <ul> <li><i>Metadata:</i> If you used <b>LoadData</b> or <b>LoadImages</b> to input your images, you may use a per-image data measurement (such as metadata) that corresponds to the identifier for this column. %(USING_METADATA_HELP_REF)s.</li> <li><i>Image filename:</i> If the gene name is not available, the image filename can be used as a surrogate identifier.</li> </ul>""" % globals()) self.gene_name_column = cps.Measurement( "Select the metadata to use as the identifier", lambda: cpmeas.IMAGE, doc=""" <i>(Used only if a GenePattern file is requested and metadata is used to name each row)</i><br> Choose the measurement that corresponds to the identifier, such as metadata from <b>LoadData</b>'s input file. %(USING_METADATA_HELP_REF)s.""" % globals()) self.use_which_image_for_gene_name = cps.ImageNameSubscriber( "Select the image to use as the identifier", "None", doc=""" <i>(Used only if a GenePattern file is requested and image filename is used to name each row)</i><br> Select which image whose filename will be used to identify each sample row.""" ) self.wants_everything = cps.Binary( "Export all measurements, using default file names?", True, doc="""Check this setting to export every measurement. <b>ExportToSpreadsheet</b> will create one file per object type, as well as per-image, per-experiment and object relationships, if relevant. It will use the object name as the file name, optionally prepending the output file name if specified above. Leave this box unchecked to specify which objects should be exported or to override the automatic names.""") self.object_groups = [] self.add_object_group() self.add_button = cps.DoSomething("", "Add another data set", self.add_object_group)
def test_02_06_get_url(self): s = cps.DirectoryPath("whatever") s.dir_choice = cps.URL_FOLDER_NAME s.custom_path = "http://www.cellprofiler.org" self.assertEqual(s.get_absolute_path(), "http://www.cellprofiler.org")
def test_02_05_get_absolute_path(self): s = cps.DirectoryPath("whatever") s.dir_choice = cps.ABSOLUTE_FOLDER_NAME s.custom_path = os.path.join(self.root_directory,"..","1","2") self.assertEqual(s.get_absolute_path(), os.path.join(self.root_directory, "2"))
def test_01_08_get_parts_from_abspath(self): s = cps.DirectoryPath("whatever") dir_choice, custom_path = s.get_parts_from_path(self.root_directory) self.assertEqual(dir_choice, cps.ABSOLUTE_FOLDER_NAME) self.assertEqual(custom_path, self.root_directory)
def create_settings(self): '''Create the settings for the module''' self.images = [] self.objects_name = cps.ObjectNameSubscriber( 'Select the input untangled worm objects', 'OverlappingWorms', doc = """This is the name of the objects produced by the <b>UntangleWorms</b> module. <b>StraightenWorms</b> can use either the overlapping or non-overlapping objects as input. It will use the control point measurements associated with the objects to reconstruct the straight worms. You can also use objects saved from a previous run and loaded via <b>LoadImages</b>, objects edited using <b>EditObjectsManually</b> or objects from one of the Identify modulues. <b>StraightenWorms</b> will recalculate the control points for these images.""") self.straightened_objects_name = cps.ObjectNameProvider( "Name the output straightened worm objects", "StraightenedWorms", doc = """This is the name that will be given to the straightened worm objects. These objects can then be used in a subsequent measurement module.""") self.width = cps.Integer( "Worm width", 20, minval = 3, doc = """This setting determines the width of the image of each worm. The width should be set to at least the maximum width of any untangled worm, but can be set to be larger to include the worm's background in the straightened image.""") self.training_set_directory = cps.DirectoryPath( "Training set file location", support_urls = True, allow_metadata = False, doc = """Select the folder containing the training set to be loaded. %(IO_FOLDER_CHOICE_HELP_TEXT)s <p>An additional option is the following: <ul> <li><i>URL</i>: Use the path part of a URL. For instance, your training set might be hosted at <i>http://university.edu/~johndoe/TrainingSet.mat</i> To access this file, you would choose <i>URL</i> and enter <i>https://svn.broadinstitute.org/CellProfiler/trunk/ExampleImages/ExampleSBSImages</i> as the path location.</li> </ul></p>"""%globals()) def get_directory_fn(): '''Get the directory for the CSV file name''' return self.training_set_directory.get_absolute_path() def set_directory_fn(path): dir_choice, custom_path = self.training_set_directory.get_parts_from_path(path) self.training_set_directory.join_parts(dir_choice, custom_path) self.training_set_file_name = cps.FilenameText( "Training set file name", "TrainingSet.mat", doc = "This is the name of the training set file.", get_directory_fn = get_directory_fn, set_directory_fn = set_directory_fn, browse_msg = "Choose training set", exts = [("Worm training set (*.xml)", "*.xml"), ("All files (*.*)", "*.*")]) self.wants_measurements = cps.Binary( "Measure intensity distribution?", True, doc = """<b>StraightenWorms</b> can divide a worm into sections and measure the intensities of each section in each of the straightened images. These measurements can help classify phenotypes if the staining pattern across the segments differs between phenotypes.""") self.number_of_segments = cps.Integer( "Number of transverse segments", 4, 1, doc = """(<i>Only displayed if intensities are measured</i>)<br> This setting controls the number of segments measured, dividing the worm longitudally into transverse segments starting at the head and ending at the tail. These measurements might be used to identify a phenotype in which a stain is localized longitudally, for instance, in the head. Set the number of vertical segments to 1 to only measure intensity in the horizontal direction.""") self.number_of_stripes = cps.Integer( "Number of longitudinal stripes", 3, 1, doc = """(<i>Only displayed if intensities are measured</i>)<br> This setting controls the number of stripes measured, dividing the worm transversely into areas that run longitudally. These measurements might be used to identify a phenotype in which a stain is localized transversely, for instance in the gut of the worm. Set the number of horizontal stripes to 1 to only measure intensity in the vertical direction.""") self.flip_worms = cps.Choice( "Align worms?", [FLIP_NONE, FLIP_TOP, FLIP_BOTTOM], doc = """(<i>Only displayed if intensities are measured</i>)<br> <b>StraightenWorms</b> can align worms so that the brightest half of the worm (the half with the highest mean intensity) is at the top of the image or at the bottom of the image. This can be used to align all worms similarly if some feature, such as the larynx, is stained and is always at the same end of the worm. Choose <i>%(FLIP_TOP)s</i> if the brightest part of the worm should be at the top of the image, <i>%(FLIP_BOTTOM)s</i> if the brightest part of the worm should be at the bottom or <i>%(FLIP_NONE)s</i> if the worm should not be aligned."""%globals()) def image_choices_fn(pipeline): '''Return the image choices for the alignment image''' return [ group.image_name.value for group in self.images ] self.flip_image = cps.Choice( "Alignment image", [ "None" ], choices_fn = image_choices_fn, doc = """(<i>Only displayed if aligning worms</i>)<br> This is the image whose intensity will be used to align the worms. You must use one of the straightened images below.""") self.image_count = cps.HiddenCount(self.images, "Image count") self.add_image(False) self.add_image_button = cps.DoSomething( "", "Add another image", self.add_image, doc = """Press this button to add another image to be straightened""")
def create_settings(self): '''Create the UI settings for the module''' self.seed_objects_name = cps.ObjectNameSubscriber( "Select the seed objects", cps.NONE, doc=""" Select the previously identified objects that you want to use as the seeds for measuring branches and distances. Branches and trunks are assigned per seed object. Seed objects are typically not single points/pixels but instead are usually objects of varying sizes.""") self.image_name = cps.ImageNameSubscriber( "Select the skeletonized image", cps.NONE, doc=""" Select the skeletonized image of the dendrites and/or axons as produced by the <b>Morph</b> module's <i>Skel</i> operation.""") self.wants_branchpoint_image = cps.Binary( "Retain the branchpoint image?", False, doc=""" Select <i>%(YES)s</i> if you want to save the color image of branchpoints and trunks. This is the image that is displayed in the output window for this module.""" % globals()) self.branchpoint_image_name = cps.ImageNameProvider( "Name the branchpoint image", "BranchpointImage", doc=""" <i>(Used only if a branchpoint image is to be retained)</i><br> Enter a name for the branchpoint image here. You can then use this image in a later module, such as <b>SaveImages</b>.""") self.wants_to_fill_holes = cps.Binary("Fill small holes?", True, doc=""" The algorithm reskeletonizes the image and this can leave artifacts caused by small holes in the image prior to skeletonizing. These holes result in false trunks and branchpoints. Select <i>%(YES)s</i> to fill in these small holes prior to skeletonizing.""" % globals()) self.maximum_hole_size = cps.Integer("Maximum hole size:", 10, minval=1, doc=""" <i>(Used only when filling small holes)</i><br> This is the area of the largest hole to fill, measured in pixels. The algorithm will fill in any hole whose area is this size or smaller.""") self.wants_neuron_graph = cps.Binary( "Export the neuron graph relationships?", False, doc=""" Select <i>%(YES)s</i> to produce an edge file and a vertex file that give the relationships between trunks, branchpoints and vertices.""" % globals()) self.intensity_image_name = cps.ImageNameSubscriber("Intensity image", cps.NONE, doc=""" Select the image to be used to calculate the total intensity along the edges between the vertices.""") self.directory = cps.DirectoryPath( "File output directory", dir_choices=[ cps.DEFAULT_OUTPUT_FOLDER_NAME, cps.DEFAULT_INPUT_FOLDER_NAME, cps.ABSOLUTE_FOLDER_NAME, cps.DEFAULT_OUTPUT_SUBFOLDER_NAME, cps.DEFAULT_INPUT_SUBFOLDER_NAME ]) self.directory.dir_choice = cps.DEFAULT_OUTPUT_FOLDER_NAME self.vertex_file_name = cps.Text("Vertex file name", "vertices.csv", doc=""" Enter the name of the file that will hold the edge information. You can use metadata tags in the file name. <p>Each line of the file is a row of comma-separated values. The first row is the header; this names the file's columns. Each subsequent row represents a vertex in the neuron skeleton graph: either a trunk, a branchpoint or an endpoint. The file has the following columns: <br><ul> <li><i>image_number:</i> The image number of the associated image</li> <li><i>vertex_number:</i> The number of the vertex within the image</li> <li><i>i:</i> The I coordinate of the vertex.</li> <li><i>j:</i> The J coordinate of the vertex.</li> <li><i>label:</i> The label of the seed object associated with the vertex.</li> <li><i>kind:</i> The vertex type, with the following choices: <ul><li><b>T:</b> Trunk</li> <li><b>B:</b> Branchpoint</li> <li><b>E:</b> Endpoint</li></ul></li></ul> </p>""") self.edge_file_name = cps.Text("Edge file name", "edges.csv", doc=""" Enter the name of the file that will hold the edge information. You can use metadata tags in the file name. Each line of the file is a row of comma-separated values. The first row is the header; this names the file's columns. Each subsequent row represents an edge or connection between two vertices (including between a vertex and itself for certain loops). <p>The file has the following columns: <br><ul> <li><i>image_number:</i> The image number of the associated image</li> <li><i>v1:</i> The zero-based index into the vertex table of the first vertex in the edge.</li> <li><i>v2:</i> The zero-based index into the vertex table of the second vertex in the edge.</li> <li><i>length:</i> The number of pixels in the path connecting the two vertices, including both vertex pixels.</li> <li><i>total_intensity:</i> The sum of the intensities of the pixels in the edge, including both vertex pixel intensities.</li> </ul> </p>""")
def create_settings(self): '''Create the settings for the ExportToCellH5 module''' self.directory = cps.DirectoryPath("Output file location", doc=""" This setting lets you choose the folder for the output files. %(IO_FOLDER_CHOICE_HELP_TEXT)s """ % globals()) def get_directory_fn(): '''Get the directory for the CellH5 file''' return self.directory.get_absolute_path() def set_directory_fn(path): dir_choice, custom_path = self.directory.get_parts_from_path(path) self.directory.join_parts(dir_choice, custom_path) self.file_name = cps.FilenameText("Output file name", "DefaultOut.ch5", get_directory_fn=get_directory_fn, set_directory_fn=set_directory_fn, metadata=True, browse_msg="Choose CellH5 file", mode=cps.FilenameText.MODE_APPEND, exts=[("CellH5 file (*.cellh5)", "*.ch5"), ("HDF5 file (*.h5)", "*.h5"), ("All files (*.*", "*.*")], doc=""" This setting lets you name your CellH5 file. If you choose an existing file, CellProfiler will add new data to the file or overwrite existing locations. <p>%(IO_WITH_METADATA_HELP_TEXT)s %(USING_METADATA_TAGS_REF)s. For instance, if you have a metadata tag named "Plate", you can create a per-plate folder by selecting one the subfolder options and then specifying the subfolder name as "\g<Plate>". The module will substitute the metadata values for the current image set for any metadata tags in the folder name.%(USING_METADATA_HELP_REF)s.</p> """ % globals()) self.overwrite_ok = cps.Binary( "Overwrite existing data without warning?", False, doc=""" Select <i>%(YES)s</i> to automatically overwrite any existing data for a site. Select <i>%(NO)s</i> to be prompted first. If you are running the pipeline on a computing cluster, select <i>%(YES)s</i> unless you want execution to stop because you will not be prompted to intervene. Also note that two instances of CellProfiler cannot write to the same file at the same time, so you must ensure that separate names are used on a cluster. """ % globals()) self.repack = cps.Binary("Repack after analysis", True, doc=""" This setting determines whether CellProfiler in multiprocessing mode repacks the data at the end of analysis. If you select <i>%(YES)s</i>, CellProfiler will combine all of the satellite files into a single file upon completion. This option requires some extra temporary disk space and takes some time at the end of analysis, but results in a single file which may occupy less disk space. If you select <i>%(NO)s</i>, CellProfiler will create a master file using the name that you give and this file will have links to individual data files that contain the actual data. Using the data generated by this option requires that you keep the master file and the linked files together when copying them to a new folder. """ % globals()) self.plate_metadata = cps.Choice("Plate metadata", [], value="Plate", choices_fn=self.get_metadata_choices, doc=""" This is the metadata tag that identifies the plate name of the images for the current cycle. Choose <i>None</i> if your assay does not have metadata for plate name. If your assay is slide-based, you can use a metadata item that identifies the slide as the choice for this setting and set the well and site metadata items to <i>None</i>.""") self.well_metadata = cps.Choice( "Well metadata", [], value="Well", choices_fn=self.get_metadata_choices, doc="""This is the metadata tag that identifies the well name for the images in the current cycle. Choose <i>None</i> if your assay does not have metadata for the well.""") self.site_metadata = cps.Choice( "Site metadata", [], value="Site", choices_fn=self.get_metadata_choices, doc="""This is the metadata tag that identifies the site name for the images in the current cycle. Choose <i>None</i> if your assay doesn't divide wells up into sites or if this tag is not required for other reasons.""") self.divider = cps.Divider() self.wants_to_choose_measurements = cps.Binary("Choose measurements?", False, doc=""" This setting lets you choose between exporting all measurements or just the ones that you choose. Select <i>%(YES)s</i> to pick the measurements to be exported. Select <i>%(NO)s</i> to automatically export all measurements available at this stage of the pipeline. """ % globals()) self.measurements = cps.MeasurementMultiChoice( "Measurements to export", doc=""" <i>(Used only if choosing measurements.)</i> <br> This setting lets you choose individual measurements to be exported. Check the measurements you want to export. """) self.objects_to_export = [] self.add_objects_button = cps.DoSomething("Add objects to export", "Add objects", self.add_objects) self.images_to_export = [] self.add_image_button = cps.DoSomething("Add an image to export", "Add image", self.add_image) self.objects_count = cps.HiddenCount(self.objects_to_export) self.images_count = cps.HiddenCount(self.images_to_export)
def create_settings(self): self.input_type = cps.Choice("Select the type of input", [IF_IMAGE, IF_OBJECTS], IF_IMAGE) self.image_name = cps.ImageNameSubscriber("Select the image to save", cps.NONE, doc=""" <i>(Used only if "%(IF_IMAGE)s", "%(IF_MASK)s" or "%(IF_CROPPING)s" are selected to save)</i><br> Select the image you want to save.""" % globals()) self.input_object_name = cps.ObjectNameSubscriber( "Select the objects to save", cps.NONE) self.objects_name = cps.ObjectNameSubscriber( "Select the objects to crop and save", cps.NONE, doc=""" Select the objects that you want to save.""" % globals()) self.file_name_method = cps.Choice( "Select method for constructing file names", [ FN_FROM_IMAGE, ], doc=""" Several choices are available for constructing the image file name: <ul> <li><i>%(FN_FROM_IMAGE)s:</i> The filename will be constructed based on the original filename of an input image specified in <b>NamesAndTypes</b>. You will have the opportunity to prefix or append additional text. <p>If you have metadata associated with your images, you can append an text to the image filename using a metadata tag. This is especially useful if you want your output given a unique label according to the metadata corresponding to an image group. The name of the metadata to substitute can be provided for each image for each cycle using the <b>Metadata</b> module. %(USING_METADATA_TAGS_REF)s%(USING_METADATA_HELP_REF)s.</p></li> </ul>""" % globals()) self.file_image_name = cps.FileImageNameSubscriber( "Select image name for file prefix", cps.NONE, doc=""" <i>(Used only when "%(FN_FROM_IMAGE)s" is selected for contructing the filename)</i><br> Select an image loaded using <b>NamesAndTypes</b>. The original filename will be used as the prefix for the output filename.""" % globals()) self.wants_file_name_suffix = cps.Binary( "Append a suffix to the image file name?", False, doc=""" Select <i>%(YES)s</i> to add a suffix to the image's file name. Select <i>%(NO)s</i> to use the image name as-is.""" % globals()) self.file_name_suffix = cps.Text("Text to append to the image name", "", metadata=True, doc=""" <i>(Used only when constructing the filename from the image filename)</i><br> Enter the text that should be appended to the filename specified above.""" ) self.file_format = cps.Choice("Saved file format", [FF_TIFF], value=FF_TIFF, doc=""" <i>(Used only when saving non-movie files)</i><br> Select the image or movie format to save the image(s). Most common image formats are available; MAT-files are readable by MATLAB.""") self.pathname = SaveImagesDirectoryPath("Output file location", self.file_image_name, doc=""" <i>(Used only when saving non-movie files)</i><br> This setting lets you choose the folder for the output files. %(IO_FOLDER_CHOICE_HELP_TEXT)s <p>An additional option is the following: <ul> <li><i>Same folder as image</i>: Place the output file in the same folder that the source image is located.</li> </ul></p> <p>%(IO_WITH_METADATA_HELP_TEXT)s %(USING_METADATA_TAGS_REF)s. For instance, if you have a metadata tag named "Plate", you can create a per-plate folder by selecting one the subfolder options and then specifying the subfolder name as "\g<Plate>". The module will substitute the metadata values for the current image set for any metadata tags in the folder name.%(USING_METADATA_HELP_REF)s.</p> <p>If the subfolder does not exist when the pipeline is run, CellProfiler will create it.</p> <p>If you are creating nested subfolders using the sub-folder options, you can specify the additional folders separated with slashes. For example, "Outlines/Plate1" will create a "Plate1" folder in the "Outlines" folder, which in turn is under the Default Input/Output Folder. The use of a forward slash ("/") as a folder separator will avoid ambiguity between the various operating systems.</p>""" % globals()) self.bit_depth = cps.Choice( "Image bit depth", [BIT_DEPTH_8, BIT_DEPTH_16, BIT_DEPTH_FLOAT], doc=""" <i>(Used only when saving files in a non-MAT format)</i><br> Select the bit-depth at which you want to save the images. <i>%(BIT_DEPTH_FLOAT)s</i> saves the image as floating-point decimals with 32-bit precision in its raw form, typically scaled between 0 and 1. <b>%(BIT_DEPTH_16)s and %(BIT_DEPTH_FLOAT)s images are supported only for TIF formats. Currently, saving images in 12-bit is not supported.</b>""" % globals()) self.object_extension = cps.Integer("Object extension", value=1, doc=""" How many pixels should the bounding box of the objects be extended before cropping""") self.overwrite = cps.Binary( "Overwrite existing files without warning?", False, doc=""" Select <i>%(YES)s</i> to automatically overwrite a file if it already exists. Select <i>%(NO)s</i> to be prompted for confirmation first. <p>If you are running the pipeline on a computing cluster, select <i>%(YES)s</i> since you will not be able to intervene and answer the confirmation prompt.</p>""" % globals()) self.when_to_save = cps.Choice("When to save", [WS_FIRST_CYCLE], doc="""<a name='when_to_save'> <i>(Used only when saving non-movie files)</i><br> Specify at what point during pipeline execution to save file(s). </a> <ul> <li><i>%(WS_EVERY_CYCLE)s:</i> Useful for when the image of interest is created every cycle and is not dependent on results from a prior cycle.</li> </ul> """ % globals()) self.update_file_names = cps.Binary( "Record the file and path information to the saved image?", False, doc=""" Select <i>%(YES)s</i> to store filename and pathname data for each of the new files created via this module as a per-image measurement. <p>Instances in which this information may be useful include: <ul> <li>Exporting measurements to a database, allowing access to the saved image. If you are using the machine-learning tools or image viewer in CellProfiler Analyst, for example, you will want to enable this setting if you want the saved images to be displayed along with the original images.</li> <li>Allowing downstream modules (e.g., <b>CreateWebPage</b>) to access the newly saved files.</li> </ul></p>""" % globals()) self.create_subdirectories = cps.Binary( "Create subfolders in the output folder?", False, doc=""" Select <i>%(YES)s</i> to create subfolders to match the input image folder structure.""" % globals()) self.root_dir = cps.DirectoryPath("Base image folder", doc=""" <i>Used only if creating subfolders in the output folder</i> In subfolder mode, <b>SaveImages</b> determines the folder for an image file by examining the path of the matching input file. The path that SaveImages uses is relative to the image folder chosen using this setting. As an example, input images might be stored in a folder structure of "images%(sep)s<i>experiment-name</i>%(sep)s <i>date</i>%(sep)s<i>plate-name</i>". If the image folder is "images", <b>SaveImages</b> will store images in the subfolder, "<i>experiment-name</i>%(sep)s<i>date</i>%(sep)s<i>plate-name</i>". If the image folder is "images%(sep)s<i>experiment-name</i>", <b>SaveImages</b> will store images in the subfolder, <i>date</i>%(sep)s<i>plate-name</i>". """ % dict(sep=os.path.sep))
def test_02_02_get_default_output_folder_path(self): s = cps.DirectoryPath("whatever") s.dir_choice = cps.DEFAULT_OUTPUT_FOLDER_NAME self.assertEqual(s.get_absolute_path(), cpprefs.get_default_output_directory())
def test_04_07_no_folder(self): s = cps.DirectoryPath("whatever") s.dir_choice = cps.NO_FOLDER_NAME s.custom_path = "gibberish" self.assertEqual(s.get_absolute_path(), '')
def add_dose_value(self, can_remove=True): '''Add a dose value measurement to the list can_delete - set this to False to keep from showing the "remove" button for images that must be present.''' group = cps.SettingsGroup() group.append("measurement", cps.Measurement("Select the image measurement describing the treatment dose", lambda: cpmeas.IMAGE, doc=""" The V and Z' factor, a measure of assay quality, and the EC50, indicating dose/response, are calculated by this module based on each image being specified as a particular treatment dose. Choose a measurement that gives the dose of some treatment for each of your images. <p> The typical way to provide this information in the pipeline is to create a comma-delimited text file (CSV) outside of CellProfiler and then load that file into the pipeline using <b>Metadata</b> or the <b>LoadData</b>. In that case, choose the measurement that matches the column header of the measurement in the CSV input file. See <b>LoadData</b> help for an example text file. """)) group.append("log_transform", cps.Binary( "Log-transform the dose values?", False, doc=''' Select <i>%(YES)s</i> if you have dose-response data and you want to log-transform the dose values before fitting a sigmoid curve. <p>Select <i>%(NO)s</i> if your data values indicate only positive vs. negative controls.</p>''' % globals())) group.append('wants_save_figure', cps.Binary( '''Create dose/response plots?''', False, doc='''<a name='wants_save_figure'></a> Select <i>%(YES)s</i> if you want to create and save dose response plots. You will be asked for information on how to save the plots.''' % globals())) group.append('figure_name', cps.Text( "Figure prefix", "", doc=''' <i>(Used only when creating dose/response plots)</i><br> CellProfiler will create a file name by appending the measurement name to the prefix you enter here. For instance, if you have objects named, "Cells", the "AreaShape_Area measurement", and a prefix of "Dose_", CellProfiler will save the figure as <i>Dose_Cells_AreaShape_Area.m</i>. Leave this setting blank if you do not want a prefix.''' )) group.append('pathname', cps.DirectoryPath( "Output file location", dir_choices=[ cps.DEFAULT_OUTPUT_FOLDER_NAME, cps.DEFAULT_INPUT_FOLDER_NAME, cps.ABSOLUTE_FOLDER_NAME, cps.DEFAULT_OUTPUT_SUBFOLDER_NAME, cps.DEFAULT_INPUT_SUBFOLDER_NAME], doc=""" <i>(Used only when creating dose/response plots)</i><br> This setting lets you choose the folder for the output files. %(IO_FOLDER_CHOICE_HELP_TEXT)s <p>%(IO_WITH_METADATA_HELP_TEXT)s %(USING_METADATA_TAGS_REF)s For instance, if you have a metadata tag named "Plate", you can create a per-plate folder by selecting one of the subfolder options and then specifying the subfolder name as "\g<Plate>". The module will substitute the metadata values for the current image set for any metadata tags in the folder name. %(USING_METADATA_HELP_REF)s.</p>""" % globals())) group.append("divider", cps.Divider()) group.append("remover", cps.RemoveSettingButton("", "Remove this dose measurement", self.dose_values, group)) self.dose_values.append(group)
def test_01_05_get_parts_from_output_folder_path(self): s = cps.DirectoryPath("whatever") dir_choice, custom_path = s.get_parts_from_path(cpprefs.get_default_output_directory()) self.assertEqual(dir_choice, cps.DEFAULT_OUTPUT_FOLDER_NAME)
def test_01_07_get_parts_from_output_subfolder_path(self): s = cps.DirectoryPath("whatever") dir_choice, custom_path = s.get_parts_from_path( os.path.join(cpprefs.get_default_output_directory(), "2")) self.assertEqual(dir_choice, cps.DEFAULT_OUTPUT_SUBFOLDER_NAME) self.assertEqual(custom_path, "2")
def add_measurement(self, flag_settings, can_delete=True): measurement_settings = flag_settings.measurement_settings group = cps.SettingsGroup() group.append("divider1", cps.Divider(line=False)) group.append( "source_choice", cps.Choice("Flag is based on", S_ALL, doc=''' <ul> <li><i>%(S_IMAGE)s:</i> A per-image measurement, such as intensity or granularity.</li> <li><i>%(S_AVERAGE_OBJECT)s:</i> The average of all object measurements in the image.</li> <li><i>%(S_ALL_OBJECTS)s:</i> All the object measurements in an image, without averaging. In other words, if <i>any</i> of the objects meet the criteria, the image will be flagged.</li> <li><i>%(S_RULES)s:</i>Use a text file of rules produced by CellProfiler Analyst. If you choose <i>Rules</i>, you will have to ensure that this pipeline makes every measurement in the rules file prior to this module.</li> </ul>''' % globals())) group.append( "object_name", cps.ObjectNameSubscriber( "Select the object to be used for flagging", cps.NONE, doc=''' <i>(Used only when flag is based on an object measurement)</i><br> Select the objects whose measurements you want to use for flagging.''' )) def object_fn(): if group.source_choice == S_IMAGE: return cpmeas.IMAGE return group.object_name.value group.append( "rules_directory", cps.DirectoryPath("Rules file location", doc=""" <i>(Used only when flagging using %(S_RULES)s)</i><br> Select the location of the rules file that will be used for filtering. %(IO_FOLDER_CHOICE_HELP_TEXT)s""" % globals())) def get_directory_fn(): '''Get the directory for the rules file name''' return group.rules_directory.get_absolute_path() def set_directory_fn(path): dir_choice, custom_path = group.rules_directory.get_parts_from_path( path) group.rules_directory.join_parts(dir_choice, custom_path) group.append( "rules_file_name", cps.FilenameText("Rules file name", "rules.txt", get_directory_fn=get_directory_fn, set_directory_fn=set_directory_fn, doc=""" <i>(Used only when flagging using %(S_RULES)s)</i><br> The name of the rules file. This file should be a plain text file containing the complete set of rules. <p>Each line of this file should be a rule naming a measurement to be made on an image, for instance: <pre>IF (Image_ImageQuality_PowerLogLogSlope_DNA < -2.5, [0.79, -0.79], [-0.94, 0.94])</pre><br><br> The above rule will score +0.79 for the positive category and -0.94 for the negative category for images whose power log slope is less than -2.5 pixels and will score the opposite for images whose slope is larger. The filter adds positive and negative and flags the images whose positive score is higher than the negative score.</p>""" % globals())) def get_rules_class_choices(group=group): '''Get the available choices from the rules file''' try: rules = self.get_rules(group) nclasses = len(rules.rules[0].weights[0]) return [str(i) for i in range(1, nclasses + 1)] except: return [str(i) for i in range(1, 3)] group.append( "rules_class", cps.MultiChoice("Class number", choices=["1", "2"], doc=""" <i>(Used only when flagging using %(S_RULES)s)</i><br> Select which classes to flag when filtering. The CellProfiler Analyst classifier user interface lists the names of the classes in order. By default, these are the positive (class 1) and negative (class 2) classes. <b>FlagImage</b> uses the first class from CellProfiler Analyst if you choose "1", etc. <p>Please note the following: <ul> <li>The flag is set if the image falls into the selected class.</li> <li>You can make multiple class selections. If you do so, the module will set the flag if the image falls into any of the selected classes.</li> </ul></p>""" % globals())) group.rules_class.get_choices = get_rules_class_choices group.append("measurement", cps.Measurement("Which measurement?", object_fn)) group.append( "wants_minimum", cps.Binary("Flag images based on low values?", True, doc=''' Select <i>%(YES)s</i> to flag images with measurements below the specified cutoff.''' % globals())) group.append("minimum_value", cps.Float("Minimum value", 0)) group.append( "wants_maximum", cps.Binary("Flag images based on high values?", True, doc=''' Select <i>%(YES)s</i> to flag images with measurements above the specified cutoff.''' % globals())) group.append("maximum_value", cps.Float("Maximum value", 1)) if can_delete: group.append( "remover", cps.RemoveSettingButton("", "Remove this measurement", measurement_settings, group)) group.append("divider2", cps.Divider(line=True)) measurement_settings.append(group)
def create_settings(self): '''Create the initial settings and name the module''' self.target_name = cps.ObjectNameProvider('Name the output objects', 'FilteredBlue', doc=""" What do you want to call the filtered objects? This will be the name for the collection of objects that are retained after applying the filter(s).""" ) self.object_name = cps.ObjectNameSubscriber( 'Select the object to filter', 'None', doc=""" What object would you like to filter? This setting also controls which measurement choices appear for filtering: you can only filter based on measurements made on the object you select. If you intend to use a measurement calculated by the <b>CalculateMath</b> module to to filter objects, select the first operand's object here, because <b>CalculateMath</b> measurements are stored with the first operand's object.""") self.spacer_1 = cps.Divider(line=False) self.rules_or_measurement = cps.Choice( 'Filter using classifier rules or measurements?', [ROM_MEASUREMENTS, ROM_RULES], doc="""You can choose either a measurement made on the objects or a rules file produced by CellProfiler Analyst. If you choose <i>Rules</i>, you will have to ensure that this pipeline makes every measurement in that rules file.""") self.spacer_2 = cps.Divider(line=False) self.measurements = [] self.measurement_count = cps.HiddenCount(self.measurements, "Measurement count") self.add_measurement(False) self.add_measurement_button = cps.DoSomething( "Add another measurement", "Add", self.add_measurement) self.filter_choice = cps.Choice("Select the filtering method", FI_ALL, FI_LIMITS, doc=""" <i>(Used only if filtering using measurements)</i><br> There are five different ways to filter objects: <ul> <li><i>Limits:</i> Keep an object if its measurement value falls within a range you specify.</li> <li><i>Maximal:</i> Keep the object with the maximum value for the measurement of interest. If multiple objects share a maximal value, retain one object selected arbitrarily per image.</li> <li><i>Minimal:</i> Keep the object with the minimum value for the measurement of interest. If multiple objects share a minimal value, retain one object selected arbitrarily per image.</li> <li><i>Maximal per object:</i> This option requires you to choose a parent object. The parent object might contain several child objects of choice (for instance, mitotic spindles within a cell or FISH probe spots within a nucleus). Only the child object whose measurements equal the maximum child-measurement value among that set of child objects will be kept (for example, the longest spindle in each cell). You do not have to explicitly relate objects before using this module.</li> <li><i>Minimal per object:</i> Same as <i>Maximal per object</i>, except filtering is based on the minimum value.</li> </ul>""") self.enclosing_object_name = cps.ObjectNameSubscriber( 'Select the objects that contain the filtered objects', 'None', doc=""" <i>(Used only if a per-object filtering method is selected)</i><br> This setting selects the container (i.e., parent) objects for the <i>Maximal per object</i> and <i>Minimal per object</i> filtering choices.""" ) self.rules_directory = cps.DirectoryPath( "Rules file location", doc="""<i>(Used only when filtering by rules)</i> <br> Select the location of the rules file that will be used for filtering. %(IO_FOLDER_CHOICE_HELP_TEXT)s""" % globals()) def get_directory_fn(): '''Get the directory for the rules file name''' return self.rules_directory.get_absolute_path() def set_directory_fn(path): dir_choice, custom_path = self.rules_directory.get_parts_from_path( path) self.rules_directory.join_parts(dir_choice, custom_path) self.rules_file_name = cps.FilenameText( "Rules file name", "rules.txt", get_directory_fn=get_directory_fn, set_directory_fn=set_directory_fn, doc="""<i>(Used only when filtering using rules)</i> <br>The name of the file holding the rules. Each line of this file should be a rule naming a measurement to be made on the object you selected, for instance: <br><tt> IF (Nuclei_AreaShape_Area < 351.3, [0.79, -0.79], [-0.94, 0.94]) </tt><br> The above rule will score +.79 for the positive category and -0.94 for the negative category for nuclei whose area is less than 351.3 pixels and will score the opposite for nuclei whose area is larger. The filter adds positive and negative and keeps only objects whose positive score is higher than the negative score""") self.wants_outlines = cps.Binary( 'Retain outlines of the identified objects?', False) self.outlines_name = cps.OutlineNameProvider('Name the outline image', 'FilteredObjects', doc=''' <i>(Used only if the outline image is to be retained for later use in the pipeline)</i> <br> Choose a name by which the outline image can be selected later in the pipeline. <p><i>Special note on saving images:</i> You can use the settings in this module to pass object outlines along to the module <b>OverlayOutlines</b>, and then save them with the <b>SaveImages</b> module. Also, the identified objects themselves can be passed along to the object processing module <b>ConvertToImage</b> and then saved with the <b>SaveImages</b> module.''' ) self.additional_objects = [] self.additional_object_count = cps.HiddenCount( self.additional_objects, "Additional object count") self.spacer_3 = cps.Divider(line=False) self.additional_object_button = cps.DoSomething( 'Relabel additional objects to match the filtered object?', 'Add an additional object', self.add_additional_object, doc=""" Click this button to add an object to receive the same post-filtering labels as the filtered object. This is useful in making sure that labeling is maintained between related objects (e.g., primary and secondary objects) after filtering.""" )