QuPath: importing TMA data within script


I would like to automatically import csv.-files containing the TMA metadata (that have the same name as the image file) within a QuPath script. Is there an easy way to do this?


What kind of metadata is it, and in what form? For example, is it a rectangular grid of values where the shape corresponds to the TMA grid, or does it contain columns with one column used to identify the core (e.g. with a Unique ID, or a label like A-1)?

There is a trick for importing Unique IDs, similar to the grid shown at https://github.com/qupath/qupath/wiki/TMA-CD3-analysis#import-a-tma-map
Basically you’d create a tab-delimited file with the extension .qpmap and just drag it on to of the viewer containing the TMA grid. But it doesn’t work for other kinds of metadata (as far as I recall…).

1 Like

Thanks, Pete! That is indeed convenient. Is there a possibility to script this? I would like to import the qpmap for each image within a project within the script automatically.

Certainly. You could do it properly, although if you don’t mind a brittle solution that secretly calls a private static method you could try this:

import static qupath.lib.gui.commands.TMAScoreImportCommand.*

def imageName = getProjectEntry().getImageName()
def path = buildFilePath(PROJECT_BASE_DIR, imageName + '.qpmap')
def file = new File(path)
def text = file.text
def hierarchy = getCurrentHierarchy()
handleImportGrid(hierarchy.getTMAGrid(), text)

This assumes that the .qpmap file as the same name as the image, and is found in the base directory of the project (you’ll probably want it somewhere else…).

The private method is here, which is also where to look if you want to see how it probably should be done…

1 Like

Great, it works! Thank you!

1 Like