Skip to content

Commit

Permalink
- added qupath script to rename and reclassify annotations
Browse files Browse the repository at this point in the history
- renamed a script to make it more explicit
  • Loading branch information
GuillaumeLeGoc committed Jan 8, 2025
1 parent f3a5d6d commit 53cc03f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cuisto"
version = "2025.01.07"
version = "2025.01.7"
authors = [{ name = "Guillaume Le Goc", email = "[email protected]" }]
description = "Quantification of objects in histological slices"
readme = "README.md"
Expand Down
36 changes: 36 additions & 0 deletions scripts/qupath-utils/tools/renameAndReclassifyAnnotations.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* renameAndReclassifyAnnotations.groovy
*
* Set the name and classification of existing annotations based
* on their actual name and classification.
* Assumes the classification AND name is in the form "Name Hemisphere",
* and does not contain blank spaces other than the one separating
* the region name and the hemisphere.
* Hemispheres can be renamed.
* Note that this processes all existing annotations, so proceed with
* caution.
*/

// Parameters
// Hesmishere names : [existing: new]
def hemispheresMap = ["Ipsi": "Left", "Contra": "Right"]

// Get all annotations objects
def annotations = getAnnotationObjects()

// Set classification based on the name
for (annotation in annotations) {
// split name on blank space
oldNameParts = annotation.getName().split()
// get region name which is the first part
regionName = oldNameParts[0]
// get hemisphere name which is the second part
// and convert it to the new name
hemisphereName = hemispheresMap[oldNameParts[1]]
// build the new name as hemisphere: region
newClassification = hemisphereName + ": " + regionName
// set the new classification
annotation.setPathClass(getPathClass(newClassification))
// set the name to the region name only
annotation.setName(regionName)
}
8 changes: 0 additions & 8 deletions scripts/qupath-utils/tools/setClassificationAsName.groovy

This file was deleted.

10 changes: 10 additions & 0 deletions scripts/qupath-utils/tools/setNameAsClassification.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* setNameAsClassification.groovy
*
* Set all annotations' names to their derived classification.
* Useful to rename the annotations with the region name in the
* case where the classification is in the form "Left: Region name".
*/

getAnnotationObjects().findAll {
it.setName(it.getClassifications()[-1])}

0 comments on commit 53cc03f

Please sign in to comment.