Last active
January 11, 2024 13:10
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think here should be ontologyPath.toString()
Path has no signature of method: getAbsolutePath()
toString() of ontologyPath can give you the absolutepath