Skip to content

Instantly share code, notes, and snippets.

@NicoKiaru
Last active January 11, 2024 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NicoKiaru/723d8e628a3bb03902bb3f0f2f0fa466 to your computer and use it in GitHub Desktop.
Save NicoKiaru/723d8e628a3bb03902bb3f0f2f0fa466 to your computer and use it in GitHub Desktop.
Import Atlas regions in QuPath from an ABBA registered project #BIOP #ABBA #QuPath
/**
* Import regions from an ABBA registered project into QuPath
* See https://biop.github.io/ijp-imagetoatlas/
* Author: Olivier Burri, Nicolas Chiaruttini, BIOP, EPFL
* Date: 2022-01-26
*/
// Erase and re import regions, the string should specify an existing key in the atlas ontology
// Available properties for Allen Brain Atlas are "acronym", "atlas_id", "color_hex_triplet", "graph_order", "hemisphere_id", "id", "name", "ontology_id", "parent_structure_id", "st_level"
importAbbaRegions( "acronym" )
// ------------- FUNCTIONS ------------------------
// 0 - Re-import regions
// Necessary import, requires qupath-extension-abba, see: https://github.com/BIOP/qupath-biop-extensions
def importAbbaRegions( String namingProperty ) {
clearAllObjects()
ImageData imageData = getCurrentImageData()
List<String> atlasNames = AtlasTools.getAvailableAtlasRegistration( imageData )
if ( atlasNames.size() == 0 ) {
logger.error( "No atlas registration found for image {}.", getProjectEntry().getImageName() )
return;
}
// Pick a default one in case there are multiple.
String atlasName = atlasNames.get( 0 )
if ( atlasNames.size() > 1 ) {
logger.warn( "{} Atlases Registrations have been found. Importing atlas: {}", atlasNames.size(), atlasName )
}
// Figure out the Ontology for finally loading the annotations
Path ontologyPath = Paths.get( Projects.getBaseDirectory( getProject() ).getAbsolutePath(), atlasName + "-Ontology.json" )
AtlasOntology ontology = AtlasHelper.openOntologyFromJsonFile( ontologyPath.getAbsolutePath() )
// Get naming possibilities
ontology.setNamingProperty( namingProperty )
AtlasTools.loadWarpedAtlasAnnotations( ontology, imageData, atlasName, true )
logger.info( "Finished loading regions named after '{}' for image '{}' from Atlas {}", namingProperty, getProjectEntry().getImageName(), atlasName )
}
import qupath.ext.biop.abba.struct.AtlasHelper
import qupath.ext.biop.abba.struct.AtlasOntology
import qupath.ext.biop.abba.AtlasTools
import qupath.lib.images.ImageData
import java.nio.file.Path
import java.nio.file.Paths
import java.util.List
@522848942
Copy link

image

I think here should be ontologyPath.toString()

Path has no signature of method: getAbsolutePath()

toString() of ontologyPath can give you the absolutepath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment