diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f5f266..f2b1cb5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,8 @@ repos: (?x)^( .*\.lock | .*\.json | - .*\.ipynb + .*\.ipynb | + .*\.cppipe )$ - repo: https://github.com/executablebooks/mdformat rev: 0.7.17 diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/NF1_plate2_export_masks.cppipe b/tests/data/cytotable/NF1_cellpainting_data_shrunken/NF1_plate2_export_masks.cppipe new file mode 100644 index 0000000..b9c4567 --- /dev/null +++ b/tests/data/cytotable/NF1_cellpainting_data_shrunken/NF1_plate2_export_masks.cppipe @@ -0,0 +1,227 @@ +CellProfiler Pipeline: http://www.cellprofiler.org +Version:5 +DateRevision:424 +GitHash: +ModuleCount:13 +HasImagePlaneDetails:False + +Images:[module_num:1|svn_version:'Unknown'|variable_revision_number:2|show_window:False|notes:['Images module is left blank as we are giving the path to the corrected images in the CLI']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + : + Filter images?:Images only + Select the rule criteria:and (extension does isimage) (directory doesnot containregexp "[\\\\/]\\.") + +Metadata:[module_num:2|svn_version:'Unknown'|variable_revision_number:6|show_window:False|notes:['Extract metadata from file names and folder names using regular expressions.', '', 'The only metadata that will be outputed in the SQLite DB file are:', '', 'Plate', 'Well', 'Site', '', 'The rest of the information is useful to make sure that the expression is working, but can be removed/not necessary.']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Extract metadata?:Yes + Metadata data type:Text + Metadata types:{"Channel": "integer", "FileLocation": "text", "Frame": "text", "Plate": "text", "Series": "text", "Site": "integer", "Stain": "float", "Well": "text"} + Extraction method count:2 + Metadata extraction method:Extract from file/folder names + Metadata source:File name + Regular expression to extract from file name:(?P[A-Z]{1}[0-9]{1,2})_01_(?P[1-3]{1})_(?P[1-4]{1})_(?PDAPI|GFP|RFP) + Regular expression to extract from folder name:(?P[0-9]{4}_[0-9]{2}_[0-9]{2})$ + Extract metadata from:All images + Select the filtering criteria:and (file does contain "") + Metadata file location:Elsewhere...| + Match file and image metadata:[] + Use case insensitive matching?:No + Metadata file name:None + Does cached metadata exist?:No + Metadata extraction method:Extract from file/folder names + Metadata source:Folder name + Regular expression to extract from file name:^(?P.*)_(?P[A-P][0-9]{2})_s(?P[0-9])_w(?P[0-9]) + Regular expression to extract from folder name:Corrected_(?PPlate_[0-9]{1}) + Extract metadata from:All images + Select the filtering criteria:and (file does contain "") + Metadata file location:Elsewhere...| + Match file and image metadata:[] + Use case insensitive matching?:No + Metadata file name:None + Does cached metadata exist?:No + +NamesAndTypes:[module_num:3|svn_version:'Unknown'|variable_revision_number:8|show_window:False|notes:['Assign files to their respective channel (only 3):', '', 'DAPI', 'GFP', 'RFP']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Assign a name to:Images matching rules + Select the image type:Grayscale image + Name to assign these images:DNA + Match metadata:[] + Image set matching method:Order + Set intensity range from:Image metadata + Assignments count:3 + Single images count:0 + Maximum intensity:255.0 + Process as 3D?:No + Relative pixel spacing in X:1.0 + Relative pixel spacing in Y:1.0 + Relative pixel spacing in Z:1.0 + Select the rule criteria:and (file does contain "DAPI") + Name to assign these images:DAPI + Name to assign these objects:Cell + Select the image type:Grayscale image + Set intensity range from:Image metadata + Maximum intensity:255.0 + Select the rule criteria:and (file does contain "GFP") + Name to assign these images:GFP + Name to assign these objects:Nucleus + Select the image type:Grayscale image + Set intensity range from:Image metadata + Maximum intensity:255.0 + Select the rule criteria:and (file does contain "RFP") + Name to assign these images:RFP + Name to assign these objects:Cytoplasm + Select the image type:Grayscale image + Set intensity range from:Image metadata + Maximum intensity:255.0 + +Groups:[module_num:4|svn_version:'Unknown'|variable_revision_number:2|show_window:False|notes:['We do not use the Groups module.']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Do you want to group your images?:No + grouping metadata count:1 + Metadata category:None + +IdentifyPrimaryObjects:[module_num:5|svn_version:'Unknown'|variable_revision_number:15|show_window:False|notes:['These are the current best parameters to segment nuclei from the DAPI channel']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Select the input image:DAPI + Name the primary objects to be identified:Nuclei + Typical diameter of objects, in pixel units (Min,Max):30,90 + Discard objects outside the diameter range?:Yes + Discard objects touching the border of the image?:Yes + Method to distinguish clumped objects:None + Method to draw dividing lines between clumped objects:Shape + Size of smoothing filter:10 + Suppress local maxima that are closer than this minimum allowed distance:7.0 + Speed up by using lower-resolution image to find local maxima?:Yes + Fill holes in identified objects?:After both thresholding and declumping + Automatically calculate size of smoothing filter for declumping?:Yes + Automatically calculate minimum allowed distance between local maxima?:Yes + Handling of objects if excessive number of objects identified:Continue + Maximum number of objects:500 + Use advanced settings?:Yes + Threshold setting version:12 + Threshold strategy:Global + Thresholding method:Otsu + Threshold smoothing scale:1.3488 + Threshold correction factor:1.0 + Lower and upper bounds on threshold:0.0,1.0 + Manual threshold:0.0 + Select the measurement to threshold with:None + Two-class or three-class thresholding?:Three classes + Log transform before thresholding?:No + Assign pixels in the middle intensity class to the foreground or the background?:Foreground + Size of adaptive window:50 + Lower outlier fraction:0.05 + Upper outlier fraction:0.05 + Averaging method:Mean + Variance method:Standard deviation + # of deviations:2.0 + Thresholding method:Minimum Cross-Entropy + +IdentifySecondaryObjects:[module_num:6|svn_version:'Unknown'|variable_revision_number:10|show_window:False|notes:['These are the current best parameters to segment whole cells using the RFP (actin) channel']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Select the input objects:Nuclei + Name the objects to be identified:Cells + Select the method to identify the secondary objects:Propagation + Select the input image:RFP + Number of pixels by which to expand the primary objects:10 + Regularization factor:0.05 + Discard secondary objects touching the border of the image?:Yes + Discard the associated primary objects?:No + Name the new primary objects:Nuclei + Fill holes in identified objects?:Yes + Threshold setting version:12 + Threshold strategy:Global + Thresholding method:Otsu + Threshold smoothing scale:1.3488 + Threshold correction factor:1.0 + Lower and upper bounds on threshold:0.0,1.0 + Manual threshold:0.0 + Select the measurement to threshold with:None + Two-class or three-class thresholding?:Three classes + Log transform before thresholding?:No + Assign pixels in the middle intensity class to the foreground or the background?:Foreground + Size of adaptive window:50 + Lower outlier fraction:0.05 + Upper outlier fraction:0.05 + Averaging method:Mean + Variance method:Standard deviation + # of deviations:2.0 + Thresholding method:Otsu + +IdentifyTertiaryObjects:[module_num:7|svn_version:'Unknown'|variable_revision_number:3|show_window:False|notes:['This module creates a third object from the first two where the nuclei is subtracted from the cells to create cytoplasm']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Select the larger identified objects:Cells + Select the smaller identified objects:Nuclei + Name the tertiary objects to be identified:Cytoplasm + Shrink smaller object prior to subtraction?:Yes + +ConvertObjectsToImage:[module_num:8|svn_version:'Unknown'|variable_revision_number:1|show_window:False|notes:[]|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Select the input objects:Nuclei + Name the output image:MaskNuclei + Select the color format:Binary (black & white) + Select the colormap:Default + +ConvertObjectsToImage:[module_num:9|svn_version:'Unknown'|variable_revision_number:1|show_window:False|notes:[]|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Select the input objects:Cells + Name the output image:MaskCells + Select the color format:Binary (black & white) + Select the colormap:Default + +ConvertObjectsToImage:[module_num:10|svn_version:'Unknown'|variable_revision_number:1|show_window:False|notes:[]|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Select the input objects:Cytoplasm + Name the output image:MaskCytoplasm + Select the color format:Binary (black & white) + Select the colormap:Default + +SaveImages:[module_num:11|svn_version:'Unknown'|variable_revision_number:16|show_window:False|notes:[]|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Select the type of image to save:Image + Select the image to save:MaskNuclei + Select method for constructing file names:From image filename + Select image name for file prefix:DAPI + Enter single file name:OrigBlue + Number of digits:4 + Append a suffix to the image file name?:Yes + Text to append to the image name:_MaskNuclei + Saved file format:tiff + Output file location:Default Output Folder| + Image bit depth:8-bit integer + Overwrite existing files without warning?:No + When to save:Every cycle + Record the file and path information to the saved image?:No + Create subfolders in the output folder?:No + Base image folder:Elsewhere...| + How to save the series:T (Time) + Save with lossless compression?:Yes + +SaveImages:[module_num:12|svn_version:'Unknown'|variable_revision_number:16|show_window:False|notes:[]|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Select the type of image to save:Image + Select the image to save:MaskCells + Select method for constructing file names:From image filename + Select image name for file prefix:RFP + Enter single file name:OrigBlue + Number of digits:4 + Append a suffix to the image file name?:Yes + Text to append to the image name:_MaskCells + Saved file format:tiff + Output file location:Default Output Folder| + Image bit depth:8-bit integer + Overwrite existing files without warning?:No + When to save:Every cycle + Record the file and path information to the saved image?:No + Create subfolders in the output folder?:No + Base image folder:Elsewhere...| + How to save the series:T (Time) + Save with lossless compression?:Yes + +SaveImages:[module_num:13|svn_version:'Unknown'|variable_revision_number:16|show_window:False|notes:[]|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False] + Select the type of image to save:Image + Select the image to save:MaskCytoplasm + Select method for constructing file names:From image filename + Select image name for file prefix:RFP + Enter single file name:OrigBlue + Number of digits:4 + Append a suffix to the image file name?:Yes + Text to append to the image name:_MaskCytoplasm + Saved file format:tiff + Output file location:Default Output Folder| + Image bit depth:8-bit integer + Overwrite existing files without warning?:No + When to save:Every cycle + Record the file and path information to the saved image?:No + Create subfolders in the output folder?:No + Base image folder:Elsewhere...| + How to save the series:T (Time) + Save with lossless compression?:Yes diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/B7_01_1_3_DAPI_001_MaskNuclei.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/B7_01_1_3_DAPI_001_MaskNuclei.tiff new file mode 100644 index 0000000..18624f6 Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/B7_01_1_3_DAPI_001_MaskNuclei.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/B7_01_3_3_RFP_001_MaskCells.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/B7_01_3_3_RFP_001_MaskCells.tiff new file mode 100644 index 0000000..57ce2cd Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/B7_01_3_3_RFP_001_MaskCells.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/B7_01_3_3_RFP_001_MaskCytoplasm.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/B7_01_3_3_RFP_001_MaskCytoplasm.tiff new file mode 100644 index 0000000..9d2c91d Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/B7_01_3_3_RFP_001_MaskCytoplasm.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D6_01_1_2_DAPI_001_MaskNuclei.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D6_01_1_2_DAPI_001_MaskNuclei.tiff new file mode 100644 index 0000000..0bee012 Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D6_01_1_2_DAPI_001_MaskNuclei.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D6_01_3_2_RFP_001_MaskCells.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D6_01_3_2_RFP_001_MaskCells.tiff new file mode 100644 index 0000000..3a4c1c6 Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D6_01_3_2_RFP_001_MaskCells.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D6_01_3_2_RFP_001_MaskCytoplasm.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D6_01_3_2_RFP_001_MaskCytoplasm.tiff new file mode 100644 index 0000000..e7a1226 Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D6_01_3_2_RFP_001_MaskCytoplasm.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D7_01_1_1_DAPI_001_MaskNuclei.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D7_01_1_1_DAPI_001_MaskNuclei.tiff new file mode 100644 index 0000000..9a02ece Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D7_01_1_1_DAPI_001_MaskNuclei.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D7_01_3_1_RFP_001_MaskCells.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D7_01_3_1_RFP_001_MaskCells.tiff new file mode 100644 index 0000000..dc61efd Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D7_01_3_1_RFP_001_MaskCells.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D7_01_3_1_RFP_001_MaskCytoplasm.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D7_01_3_1_RFP_001_MaskCytoplasm.tiff new file mode 100644 index 0000000..8e8917d Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/D7_01_3_1_RFP_001_MaskCytoplasm.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/F7_01_1_2_DAPI_001_MaskNuclei.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/F7_01_1_2_DAPI_001_MaskNuclei.tiff new file mode 100644 index 0000000..00f573c Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/F7_01_1_2_DAPI_001_MaskNuclei.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/F7_01_3_2_RFP_001_MaskCells.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/F7_01_3_2_RFP_001_MaskCells.tiff new file mode 100644 index 0000000..2fe1ce7 Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/F7_01_3_2_RFP_001_MaskCells.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/F7_01_3_2_RFP_001_MaskCytoplasm.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/F7_01_3_2_RFP_001_MaskCytoplasm.tiff new file mode 100644 index 0000000..68fee4f Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/F7_01_3_2_RFP_001_MaskCytoplasm.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/H12_01_1_1_DAPI_001_MaskNuclei.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/H12_01_1_1_DAPI_001_MaskNuclei.tiff new file mode 100644 index 0000000..bc822eb Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/H12_01_1_1_DAPI_001_MaskNuclei.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/H12_01_3_1_RFP_001_MaskCells.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/H12_01_3_1_RFP_001_MaskCells.tiff new file mode 100644 index 0000000..477405c Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/H12_01_3_1_RFP_001_MaskCells.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/H12_01_3_1_RFP_001_MaskCytoplasm.tiff b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/H12_01_3_1_RFP_001_MaskCytoplasm.tiff new file mode 100644 index 0000000..be1103a Binary files /dev/null and b/tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks/H12_01_3_1_RFP_001_MaskCytoplasm.tiff differ diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/create.py b/tests/data/cytotable/NF1_cellpainting_data_shrunken/create_image_data.py similarity index 100% rename from tests/data/cytotable/NF1_cellpainting_data_shrunken/create.py rename to tests/data/cytotable/NF1_cellpainting_data_shrunken/create_image_data.py diff --git a/tests/data/cytotable/NF1_cellpainting_data_shrunken/create_mask_data.py b/tests/data/cytotable/NF1_cellpainting_data_shrunken/create_mask_data.py new file mode 100644 index 0000000..d360508 --- /dev/null +++ b/tests/data/cytotable/NF1_cellpainting_data_shrunken/create_mask_data.py @@ -0,0 +1,51 @@ +""" +Creates image masks for images in +coSMicQC/tests/data/cytotable/NF1_cellpainting_data (Plate 2) + +Note: expects Docker to be installed as a CLI on the system. + +This file may be processed using the following command from the root +of the project repository: +`poetry run python \ +tests/data/cytotable/NF1_cellpainting_data_shrunken/create_mask_data.py` +""" + +import os +import pathlib +import subprocess + +# create a dir for segmentation masks +pathlib.Path("tests/data/cytotable/NF1_cellpainting_data_shrunken/Plate_2_masks").mkdir( + exist_ok=True +) + +# define docker command for CellProfiler use with provided pipeline file +command = [ + "docker", + "run", + "--platform", + "linux/amd64", + "--rm", + "-v", + f"{os.getcwd()}/tests/data/cytotable/NF1_cellpainting_data_shrunken:/app", + "cellprofiler/cellprofiler:4.2.4", + "cellprofiler", + "-c", + "-r", + "-p", + "/app/NF1_plate2_export_masks.cppipe", + "-o", + "/app/Plate_2_masks", + "-i", + "/app/Plate_2_images", +] + +# Run the command and show output +try: + result = subprocess.run(command, check=True, text=True, capture_output=True) + print("Command Output:\n", result.stdout) + print("Command Error:\n", result.stderr) +except subprocess.CalledProcessError as e: + print("Error:", e) + print("Command Output:\n", e.stdout) + print("Command Error:\n", e.stderr)