/
plotTransformedCellCenters.py
67 lines (46 loc) · 2.2 KB
/
plotTransformedCellCenters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 7 10:36:50 2020
@author: smith
This file writes a TIF stack containing cell center coordinates transformed to the atlas, and then
isolates a region, and splits into two hemispheres. The result can be used as input for the clearMapSubregionParser script."
"""
import ClearMap.IO.IO as io
import os
import ClearMap.Visualization.Plot as plt
import ClearMap.Analysis.Label as lbl
import numpy as np
sampleName = 'LowNIC'
#execfile('/d2/studies/ClearMap/IA_iDISCO/' + sampleName + '/parameter_file_' + sampleName + '.py')
execfile('/d2/studies/ClearMap/Alex_Acute_iDISCO/3RB_HighNIC/parameter_file_template_3RB.py')
baseDirectory = '/d2/studies/ClearMap/Alex_Acute_iDISCO/NIC_HeatMaps/FiguresForPaper/'
region = 'MSC'
points = io.readPoints(TransformedCellsFile)
data = plt.overlayPoints(AnnotationFile, points.astype(int), pointColor = None)
io.writeData(os.path.join(BaseDirectory, sampleName + '_Annotations_Points_Overlay_newAtlas2.tif'), data)
data = data[:,:,:,1:]
io.writeData(os.path.join(BaseDirectory, sampleName + '_Points_Transformed_newAtlas2.tif'), data)
label = io.readData(AnnotationFile)
label = label.astype('int32')
labelids = np.unique(label)
outside = np.zeros(label.shape, dtype = bool);
"""
In order to find out the level to use, in console input:
>>> lbl.labelAtLevel(r, n)
where r is region ID, and n is level (usually start at 5), if the output is not the
region ID, increase n.
"""
for l in labelids:
if not (lbl.labelAtLevel(l, 6) == 672):
outside = np.logical_or(outside, label == l);
heatmap = io.readData(os.path.join(baseDirectory, sampleName + '_Points_Transformed.tif'))
heatmap[outside] = 0;
Xmin = np.amin(np.nonzero(heatmap)[1])
Xmax = np.amax(np.nonzero(heatmap)[1])
Ymin = np.amin(np.nonzero(heatmap)[0])
Ymax = np.amax(np.nonzero(heatmap)[0])
heatmap_left = heatmap[Xmin-10:heatmap.shape[0]/2,Ymin-10:Ymax+10,:]
heatmap_right = heatmap[heatmap.shape[0]/2:Xmax+10,Ymin-10:Ymax+10:,:]
io.writeData(os.path.join(baseDirectory, sampleName + '_' + region + '_isolated_points_left.tif'), heatmap_left)
io.writeData(os.path.join(baseDirectory, sampleName + '_' + region + '_isolated_points_right.tif'), heatmap_right)