Overview
drugsens is a R-package that allows users to automatically analyze QuPath™'s output data from imaging analysis. Here we include a QuPath™ script (the same that we regularly use) to run reproducible QuPath™-based image analysis, and some examples on how drugsens can be used. For more detailed examples of QuPath™ scripting and usage please refer to QuPath™'s Documentation. This script should be placed into scripts manager within QuPath™. We tested this code with previous versions of QuPath™, but new versions should also be compatible. This package is complementary to the STAR protocol: Protocol for quantifying drug sensitivity in 3D patient-derived ovarian cancer models DOI: 10.1016/j.xpro.2024.103274.
Installation
devtools::install_git("https://git.scicore.unibas.ch/ovca-research/drugsens")
# OR
devtools::install_github("https://github.com/flalom/drugsens") # this is the GitLab's mirroring repo
devtools
is required to install drugsens. If devtools
is not installed yet you can install it with:
# Install devtools from CRAN
install.packages("devtools")
# Or the development version from GitHub:
# install.packages("pak")
pak::pak("r-lib/devtools")
You can have a look at it devtools
QuPath script
This is the script used in the STAR protocol, regarding the QuPath imaging analysis.
/**
* This QuPath script will take a full image as an annotation
*
* 1. Change path to export data, line 41
* 2. Make sure that the channel order is DAPI, E-Cadherin, and Cleaved Caspase 3
* a) if this is not the case, change line 38 (setChannelNames) accordingly
* 3. Your QuPath project must contain classifiers called "Cleaved Caspase 3" and "E-Cadherin"
* If you do not have them, you can download them from our repository,
* or create them yourself:
* i) In a image, create a selection of the full image (run lines 52-59)
* ii) Detect cells (run line 61)
* iii) In the Annotation tab, create new classification classes (Add class) called "Cleaved Caspase 3" and "E-Cadherin"
* iv) Create classifiers (from the menu Classify > Object Classification > Create single measurement classifier)
* v) Name the new classifier "Cleaved Caspase 3", and use following parameters
* Object filter = Detections (all)
* Channel filter = Cleaved Caspase 3
* Measurement = Nucleus: Cleaved Caspase 3 mean
* Threshold = 200 (value may differ for your image)
* Above threshold = Cleaved Caspase 3
* vi) Name the new classifier "E-Cadherin", and use following parameters
* Object filter = Detections (all)
* Channel filter = E-Cadherin
* Measurement = Nucleus: E-Cadherin mean
* Threshold = 180 (value may differ for your image)
* Above threshold = E-Cadherin
* 4. Select Run -> Run for project
* It will go through all images in the project, run segmentation
* & apply those 2 classifiers we set up before.
*
* Note:
* You are encouraged to check and adjust the classifier before you run them on your own images.
* For this, follow steps 3.i) - 3.vi)
*/
import static qupath.lib.gui.scripting.QPEx.*
// Define the path for data export
def path = '<USER_DEFINED_PATH>'
setImageType('FLUORESCENCE');
setChannelNames ('DAPI', 'E-Cadherin', 'Cleaved Caspase 3')
def name = getProjectEntry().getImageName() + '.txt'
path = buildFilePath(path, '<PID>_<TISSUE>_',Sys.Date(),'_<SAMPLE_DOC>_<TREATMENT_INITIALS>_<CONCENTRATION>_<CONCENTRATION_UNITS>_<REPLICA_OR_NOT>_<TUMOR_MARKER>_<APOPTOTIC_MARKER>')
mkdirs(path)
path = buildFilePath(path, name)
// Create a new rectangle annotation & add it to the hierarchy
import qupath.lib.roi.RectangleROI
import qupath.lib.objects.PathAnnotationObject
def x_dim = getCurrentImageData().getServer().getWidth()
def y_dim = getCurrentImageData().getServer().getHeight()
def roi = new RectangleROI(0, 0, x_dim, y_dim)
def annotation = new PathAnnotationObject(roi)
addObject(annotation)
setSelectedObject(annotation)
runPlugin('qupath.imagej.detect.cells.WatershedCellDetection', '{"detectionImage": "DAPI", "requestedPixelSizeMicrons": 0.5, "backgroundRadiusMicrons": 8.0, "medianRadiusMicrons": 0.0, "sigmaMicrons": 2, "minAreaMicrons": 5.0, "maxAreaMicrons": 500.0, "threshold": 45.0, "watershedPostProcess": true, "cellExpansionMicrons": 7.5, "includeNuclei": true, "smoothBoundaries": true, "makeMeasurements": true}')
runObjectClassifier("Cleaved Caspase 3", "E-Cadherin")
saveAnnotationMeasurements(path)
print 'Results exported to ' + path
And this script for exporting the data:
/**
* QuPath script to export measurements from all analysed images in a project
*
* 1. Define columns you would like to export (line 28)
* 2. In line 17, specify the path where to save your results
*/
import qupath.lib.gui.tools.MeasurementExporter
import qupath.lib.objects.PathCellObject
import qupath.lib.objects.PathDetectionObject
import qupath.lib.objects.PathAnnotationObject
import qupath.lib.objects.PathRootObject
// Choose your *full* output path
def outputPath = "<PID>_<TISSUE>_',Sys.Date(),'_<SAMPLE_DOC>_<TREATMENT_INITIALS>_<CONCENTRATION>_<CONCENTRATION_UNITS>_<REPLICA_OR_NOT>_<TUMOR_MARKER>_<APOPTOTIC_MARKER>.csv"
// Get the list of all images in the current project
def project = getProject()
def imagesToExport = project.getImageList()
// Separate each measurement value in the output file with ","
def separator = ","
// Choose the columns that will be included in the export
// Note: if 'columnsToInclude' is empty, all columns will be included
def columnsToInclude = new String[]{"Image", "Name", "Class","Centroid X µm","Centroid Y µm","Nucleus: Area", "Nucleus: DAPI mean","Nucleus: E-Cadherin mean", "Nucleus: Cleaved Caspase 3 mean", "Cell: Area","Cell: E-Cadherin mean", "Cell: Cleaved Caspase 3 mean","Cytoplasm: E-Cadherin mean","Cytoplasm: Cleaved Caspase 3 mean","Nucleus/Cell area ratio"}
// Choose the type of objects that the export will process
// Other possibilities include:
// 1. PathAnnotationObject
// 2. PathDetectionObject
// 3. PathRootObject
// Note: import statements should then be modified accordingly
def exportType = PathCellObject.class
def outputFile = new File(outputPath)
// Create the measurementExporter and start the export
def exporter = new MeasurementExporter()
.imageList(imagesToExport) // Images from which measurements will be exported
.separator(separator) // Character that separates values
.includeOnlyColumns(columnsToInclude) // Columns are case-sensitive
.exportType(exportType) // Type of objects to export
.exportMeasurements(outputFile) // Start the export process
print "Done!"
Usage
Example
We recommend making a new project when working with drugsens
, to have clear and defined path. This will make the data analysis much easier and reproducible.
You can also set you working directory with setwd()
.
QuPath data in R
To make the QuPath script locally available within the working directory, with the currents date:
library("drugsens")
generate_qupath_script()
This function will generate a script_for_qupath.txt
file with the code that one can copy/paste into the QuPath's script manager. All the sections that contain <> should be replaced with the user experimental information. The columnsToInclude
in the script should also be user defined, depending on the markers used.
It is very important that the file naming structure of the QuPath's output is maintained for drugsens
to work correctly.