Skip to content

Instantly share code, notes, and snippets.

@petebankhead
Last active December 9, 2016 16:10
Show Gist options
  • Save petebankhead/34bfd59546cd8e6a46ecf0c600b5bf45 to your computer and use it in GitHub Desktop.
Save petebankhead/34bfd59546cd8e6a46ecf0c600b5bf45 to your computer and use it in GitHub Desktop.
Simple script to assign metadata values to TMA cores according to row in QuPath
/**
* Simple script to assign metadata values to TMA cores according to row.
*
* @author Pete Bankhead
*/
import qupath.lib.scripting.QP
// Define the metadata values required
def metadataKey = "Region"
def rowValues = [
"Center",
"Center",
"Center",
"Margin",
"Margin",
"Margin"
]
// Get the grid & dimensions
def grid = QP.getCurrentHierarchy().getTMAGrid()
int h = grid.getGridHeight()
int w = grid.getGridWidth()
// Loop through entries
for (row in 0..h-1) {
if (row >= rowValues.size())
break
for (col in 0..w-1) {
def core = grid.getTMACore(row, col)
core.putMetadataValue(metadataKey, rowValues[row])
}
}
// Fire update
QP.fireHierarchyUpdate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment