def map_pits_heritability(template, side, areals, indir, cb, interval_cb, dict_freq, pval_thresh, outdir): """ Parameters template: path to template mesh file areals: path to gii file containing the texture of areals side: hemisphere side from which SOLAR estimates are displayed indir: directory containing h2 and pval dictionaries cb: colorbar names must be an array with [cb_h2, cb_pval] interval_cb: number boundaries for the colobar display must be a double array [inter_h2[0,1], inter_pval[0,1]] dict_freq: dictionary containing pits frequency per areal pval_thresh: p-value threshold outdir: output directory for the snapshots """ if not os.path.isdir(outdir): os.makedirs(outdir) # Define the quaternions that are gonna be used for the snapshots if (side == "L"): view_quaternions = { 'intern': [0.5, 0.5, 0.5, 0.5], 'extern': [0.5, -0.5, -0.5, 0.5], 'bottom': [1, 0, 0, 0], 'top': [0, 0, 1, 0] } else: view_quaternions = { 'intern': [0.5, 0.5, 0.5, 0.5], 'extern': [0.5, -0.5, -0.5, 0.5], 'bottom': [1, 0, 0, 0], 'top': [0, 0, 1, 0] } # Load h2 and pval dictionaries path_h2 = os.path.join(indir, 'h2_dict.json') with open(path_h2, 'r') as f: data = json.load(f) dict_h2 = json.loads(data) path_pval = os.path.join(indir, 'pval_dict.json') with open(path_pval, 'r') as f: data = json.load(f) dict_pval = json.loads(data) # Areal value in each vertex array_areals = gio.read(areals).darrays[0].data # Create arrays that will contain h2 and pval estimates on each vertex array_h2 = np.zeros(len(array_areals)) array_pval = np.zeros(len(array_areals)) list_areals = np.unique(array_areals) # Load the mesh in anatomist mesh = ana.loadObject(template) for areal in list_areals: # make sure areal has the right format areal = str(int(areal)) if (dict_h2[side].has_key(areal) and # Check if areal passed the threshold frequency in both hemispheres dict_freq['L']["Areal_" + areal] * dict_freq['R']["Areal_" + areal] > 0): # Finally, checl if the p-value pass the pval threshold if dict_pval[side][areal] < pval_thresh: # Select the index of vertices belonging to the areal ind = np.where(array_areals == float(areal))[0] # Give them the h2 estimate of this areal array_h2[ind] = dict_h2[side][areal] # And the log10 pvalue array_pval[ind] = -np.log10(dict_pval[side][areal]) ### Block performing the display of h2 estimates ### # Create anatomist window window = ana.createWindow('3D', geometry=[0, 0, 584, 584]) tex = aims.TimeTexture(dtype='FLOAT') tex[0].assign(array_h2) pits_tex = ana.toAObject(tex) tex_mesh = ana.fusionObjects([mesh, pits_tex], method='FusionTexSurfMethod') tex_mesh.assignReferential(ref) tex_mesh.setMaterial(front_face='counterclockwise') pits_tex.setPalette(cb[0], minVal=interval_cb[0][0], maxVal=interval_cb[0][1], absoluteMode=True) updateWindow(window, tex_mesh) # Loop through the quaternions and do the snapshot for sd in view_quaternions.keys(): q = aims.Quaternion(view_quaternions[sd]) window.camera(view_quaternion=view_quaternions[sd], zoom=0.65) # Snapshot file output output = os.path.join(outdir, 'snapshot_h2_' + side + '_' + sd + '.png') ana.execute('WindowConfig', windows=[window], snapshot=output) #### Block performing the display of pvalues estimates ### # Create anatomist window, second time (else zoom problem for snapshots) window = ana.createWindow('3D', geometry=[0, 0, 584, 584]) tex = aims.TimeTexture(dtype='FLOAT') tex[0].assign(array_pval) pits_tex = ana.toAObject(tex) tex_mesh = ana.fusionObjects([mesh, pits_tex], method='FusionTexSurfMethod') tex_mesh.assignReferential(ref) tex_mesh.setMaterial(front_face='counterclockwise') pits_tex.setPalette(cb[1], minVal=interval_cb[1][0], maxVal=interval_cb[1][1], absoluteMode=True) updateWindow(window, tex_mesh) # Loop through the quaternions and do the snapshot for sd in view_quaternions.keys(): q = aims.Quaternion(view_quaternions[sd]) window.camera(view_quaternion=view_quaternions[sd], zoom=0.65) # Snapshot file output output = os.path.join(outdir, 'snapshot_pval_' + side + '_' + sd + '.png') ana.execute('WindowConfig', windows=[window], snapshot=output)
cursor_visibility=0) if (side == "R" and "Freesurfer" not in path_parcels and not SYMMETRIC ) or (side == "L" and "Freesurfer" in path_parcels and not SYMMETRIC) or (SYMMETRIC and "Freesurfer" in path_parcels): view_quaternions = { 'intern': [0.5, 0.5, 0.5, 0.5], 'extern': [0.5, -0.5, -0.5, 0.5] } else: view_quaternions = { 'extern': [0.5, 0.5, 0.5, 0.5], 'intern': [0.5, -0.5, -0.5, 0.5] } for sd in view_quaternions.keys(): q = aims.Quaternion(view_quaternions[sd]) windows[side].camera(view_quaternion=view_quaternions[sd], zoom=0.65) ana.execute('WindowConfig', windows=[windows[side]], snapshot=OUTPUT + 'snapshot_' + pheno + '_' + sd + '.jpg') for side in sides: if SYMMETRIC: sid = 'L' else: sid = side pheno = pheno0 + sds[side] if "Freesurfer" in path_parcels:
def map_shared_genetic(template, sd, areals, indir, cb, interval_cb, rho, trait, pval_thresh, outdir): """ Parameters template: path to template mesh file areals: path to gii file containing the texture of areals sd: hemisphere side from which SOLAR estimates are displayed indir: directory containing h2 and pval dictionaries cb: colorbar names must be an array with [cb_h2, cb_pval] interval_cb: number boundaries for the colobar display must be a double array [inter_h2[0,1], inter_pval[0,1]] pval_thresh: p-value threshold outdir: output directory for the snapshots """ if not os.path.isdir(outdir): os.makedirs(outdir) # Define the quaternions that are gonna be used for the snapshots if (sd == "L"): view_quaternions = { 'intern': [0.5, 0.5, 0.5, 0.5], 'extern': [0.5, -0.5, -0.5, 0.5], 'bottom': [1, 0, 0, 0], 'top': [0, 0, 1, 0] } else: view_quaternions = { 'intern': [0.5, -0.5, -0.5, 0.5], 'extern': [0.5, 0.5, 0.5, 0.5], 'bottom': [1, 0, 0, 0], 'top': [0, 0, 1, 0] } # Load h2 and pval dictionaries path_h2 = os.path.join(indir, sd + rho + '_dict.json') with open(path_h2, 'r') as f: data = json.load(f) dict_h2 = json.loads(data) path_pval = os.path.join(indir, sd + rho + '_pval_dict.json') with open(path_pval, 'r') as f: data = json.load(f) dict_pval = json.loads(data) # Load h2 and pval dictionaries rho2 = 'scipy_rhop' path_h2 = os.path.join(indir, sd + rho2 + '_dict.json') with open(path_h2, 'r') as f: data = json.load(f) dict_rhop = json.loads(data) path_pval = os.path.join(indir, sd + rho2 + '_pval_dict.json') with open(path_pval, 'r') as f: data = json.load(f) dict_pval_rhop = json.loads(data) # Areal value in each vertex array_areals = gio.read(areals).darrays[0].data # Create arrays that will contain h2 and pval estimates on each vertex array_h2 = np.zeros(len(array_areals)) array_pval = np.zeros(len(array_areals)) list_areals = np.unique(array_areals) # Load the mesh in anatomist mesh = ana.loadObject(template) for areal in list_areals: # make sure areal has the right format areal = str(int(areal)) if dict_h2.has_key(areal + '_' + col): # Finally, checl if the p-value pass the pval threshold if (dict_pval[areal + '_' + col] < pval_thresh and # Force the phenotypic correlation to be significant dict_pval_rhop[areal + '_' + col] < 5e-2 / (2 * 180)): # Select the index of vertices belonging to the areal ind = np.where(array_areals == float(areal))[0] # Give them the h2 estimate of this areal if 'rhog' in rho: # Change this line for Figure 3 array_h2[ind] = abs(dict_h2[areal + '_' + col]) else: array_h2[ind] = dict_h2[areal + '_' + col] # And the log10 pvalue array_pval[ind] = -np.log10(dict_pval[areal + '_' + col]) ### Block performing the display of h2 estimates ### # Create anatomist window window = ana.createWindow('3D', geometry=[0, 0, 584, 584]) tex = aims.TimeTexture(dtype='FLOAT') tex[0].assign(array_h2) pits_tex = ana.toAObject(tex) tex_mesh = ana.fusionObjects([mesh, pits_tex], method='FusionTexSurfMethod') tex_mesh.assignReferential(ref) tex_mesh.setMaterial(front_face='counterclockwise') pits_tex.setPalette(cb[0], minVal=interval_cb[0][0], maxVal=interval_cb[0][1], absoluteMode=True) updateWindow(window, tex_mesh) ana.execute('TexturingParams', objects=[tex_mesh], interpolation='rgb') # Loop through the quaternions and do the snapshot for vw in view_quaternions.keys(): q = aims.Quaternion(view_quaternions[vw]) window.camera(view_quaternion=view_quaternions[vw], zoom=0.65) # Snapshot file output output = os.path.join( outdir, '_'.join(['snapshot', trait, rho, sd, vw + '.png'])) ana.execute('WindowConfig', windows=[window], snapshot=output) if False: ana.releaseObject(pits_tex) pits_tex = None ana.releaseObject(tex_mesh) tex_mesh = None #### Block performing the display of pvalues estimates ### # Create anatomist window, second time (else zoom problem for snapshots) window = ana.createWindow('3D', geometry=[0, 0, 584, 584]) tex = aims.TimeTexture(dtype='FLOAT') tex[0].assign(array_pval) pits_tex = ana.toAObject(tex) tex_mesh = ana.fusionObjects([mesh, pits_tex], method='FusionTexSurfMethod') tex_mesh.assignReferential(ref) tex_mesh.setMaterial(front_face='counterclockwise') pits_tex.setPalette(cb[1], minVal=interval_cb[1][0], maxVal=interval_cb[1][1], absoluteMode=True) updateWindow(window, tex_mesh) ana.execute('TexturingParams', objects=[tex_mesh], interpolation='rgb') # Loop through the quaternions and do the snapshot for vw in view_quaternions.keys(): q = aims.Quaternion(view_quaternions[vw]) window.camera(view_quaternion=view_quaternions[vw], zoom=0.65) # Snapshot file output output = os.path.join( outdir, '_'.join(['snapshot', trait, rho, 'pval', sd, vw + '.png'])) ana.execute('WindowConfig', windows=[window], snapshot=output) if False: ana.releaseObject(pits_tex) pits_tex = None ana.releaseObject(tex_mesh) tex_mesh = None