Open keithmurphy opened 5 years ago
I haven't tried isolating this in such a way, and without knowing the biological question you have it's hard to suggest something, but maybe you could just "crop" the full heatmap around that region?
Here is how I did it. I have a .csv file with the list of regions I want to show in the heatmap. It has to be a list with the regions' number. In the zipped registration file you download from https://idisco.info/clearmap-2/ you have a file called regions IDs.csv they have all the codes of the regions in there.
Next, in the parameter_file_template.py file, I inserted the following piece of code in the end in the code, heatmap_ids.csv is MY list of regions of interest
# CESAR'S VARIABLES for visualizing counted cells in specific regions
outside = 0
with open('/home/cesar/Image_analysis/Python/Registration/parameter_25um/heatmap_ids.csv') as f:
region = list(csv.reader(f, delimiter = ";"))
region = numpy.array(region, dtype = numpy.int)
Then, in the process_template.py, the piece of code that generates the heatmap and saves it
# Heat map generation
#####################
points = io.readPoints(TransformedCellsFile)
intensities = io.readPoints(FilteredCellsFile[1])
#Without weigths:
vox = voxelize(points, AtlasFile, **voxelizeParameter);
if not isinstance(vox, basestring):
io.writeData(os.path.join(BaseDirectory, 'cells_heatmap.tif'), vox.astype('int32'));
#With weigths from the intensity file (here raw intensity):
voxelizeParameter["weights"] = intensities[:,0].astype(float);
vox = voxelize(points, AtlasFile, **voxelizeParameter);
if not isinstance(vox, basestring):
io.writeData(os.path.join(BaseDirectory, 'cells_heatmap_weighted.tif'), vox.astype('int32'));
I replaced that whole block of code for the following:
# Heat map generation
#####################
from ClearMap.Alignment.Resampling import sagittalToCoronalData
points = io.readPoints(TransformedCellsFile)
intensities = io.readPoints(FilteredCellsFile[1])
vox = voxelize(points, AtlasFile, **voxelizeParameter);
#### CESAR'S CODE
### In this piece, the heatmap generated affects only the regions defined in the variable region
label = io.readData(AnnotationFile);
label = label.astype('int32');
labelids = numpy.unique(label);
for l in labelids:
if not numpy.in1d(l,region): # matches the annotation file to list of regions of interest
outside = numpy.logical_or(outside, label == l); #this works for multiple brain regions
vox[outside] = 0;
io.writeData(os.path.join(BaseDirectory, 'cfos/overlays.mhd'), sagittalToCoronalData(vox.astype('int16')));
io.writeData(os.path.join(BaseDirectory, 'cfos/annotation_to_overlay.mhd'), sagittalToCoronalData(label.astype('int16')));
Now, just note that the heatmap is going to be saved in the coronal dimensions.
If you still want it in the sagital plan, remove the sagittalToCoronalData()
function from the two last lines and you are good.
Has anyone had any success making a region specific heatmap? I don't understand the region id hierarchy but am trying to use the lbl.labelAtLevel function to isolate the dorsomedial nucleus of the hypothalamus. Right now I'm using this bit of code
for l in labelids: if not lbl.labelAtLevel(l, 3) == 688: outside = numpy.logical_or(outside, label == l); Where 688 was the id in the region count csv output, but I don't think thats correct Any help would be much appreciated.