#cp sim_mmns_savespikesonly.py sim_fI.py
#cp sim_mmns_savespikesonly.py sim_mmns_sep_savespikesonly.py #Add slowly excited population
from pylab import *
import scipy.io
import time
from os.path import exists
import mytools
import pickle
taus = [50.0*i for i in range(1,25)]
tauNeurs = taus[::-1]
amps = [100.0*i for i in range(0,11)]
AUCs = []
for itau in range(0,len(tauNeurs)):
print('Loading itau = '+str(itau))
nSps = []
tauNeur = tauNeurs[itau]
for iamp in range(0,len(amps)):
stimAmp = amps[iamp]
if exists('fIs/fI_highamps_tau'+str(tauNeur)+'_gLeak4.0_thresh0.0_amp'+str(stimAmp)+'.mat'):
A = scipy.io.loadmat('fIs/fI_highamps_tau'+str(tauNeur)+'_gLeak4.0_thresh0.0_amp'+str(stimAmp)+'.mat')
else:
print('fIs/fI_highamps_tau'+str(tauNeur)+'_gLeak4.0_thresh0.0_amp'+str(stimAmp)+'.mat not found')
continue
nSps.append(len(A['spikes'][0]))
AUCs.append(sum([x/10.0 for x in nSps]))
areas = ['ACC','PFC']
Is = []
AUCdata_both = []
tau_interpolated_both = []
isubjs_HC_both = []
isubjs_SCZ_both = []
for iarea in range(0,2):
area = areas[iarea]
#From spineNg5d/drawfig2.py
if area == 'ACC':
isubjs_HC = [1, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 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, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 73, 75, 76, 77, 78, 79, 80, 83, 84, 86, 90, 91, 92, 95, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 124, 126, 127, 129, 130, 131, 132, 133, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 152, 154, 159, 161, 163, 164, 167, 169, 170, 172, 174, 175, 176, 177, 182, 199, 208, 235, 240, 243, 249, 253, 256, 257, 260, 261, 262, 263, 265, 266, 267, 268, 271, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 329, 330, 331, 332, 343, 349, 350, 352, 353, 355, 360, 366, 369, 370, 371, 372, 374, 375, 376, 378, 381, 382, 383, 385, 388, 389, 392, 393, 395, 396, 397, 398, 401, 402, 409, 410, 414, 416, 418, 421, 422, 426, 427, 431, 432, 433, 434, 435, 437, 438, 442, 443, 444, 446, 447, 448, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480]
isubjs_SCZ = [0, 2, 3, 12, 17, 28, 31, 58, 69, 70, 71, 72, 74, 81, 82, 85, 87, 88, 89, 93, 94, 96, 97, 98, 99, 100, 116, 117, 118, 119, 120, 121, 122, 123, 125, 134, 151, 155, 156, 157, 158, 160, 162, 165, 166, 168, 171, 173, 178, 179, 180, 181, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 200, 201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 236, 237, 238, 239, 241, 242, 244, 245, 246, 247, 248, 250, 251, 252, 254, 255, 258, 259, 264, 269, 270, 272, 273, 274, 275, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 344, 345, 346, 347, 348, 351, 354, 356, 357, 358, 359, 361, 362, 363, 364, 365, 367, 368, 373, 377, 379, 380, 384, 386, 387, 390, 391, 394, 399, 400, 403, 404, 405, 406, 407, 411, 412, 413, 415, 417, 419, 420, 423, 424, 425, 428, 429, 430, 436, 439, 440, 441, 445, 449, 450, 451, 452]
elif area == 'PFC':
isubjs_HC = [0, 1, 2, 3, 5, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 19, 20, 22, 23, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 39, 41, 42, 43, 47, 51, 52, 53, 54, 63, 64, 66, 69, 73, 80, 81, 82, 83, 84, 87, 88, 89, 90, 92, 93, 94, 96, 97, 100, 105, 107, 111, 112, 118, 119, 120, 125, 127, 128, 135, 139, 140, 142, 143, 145, 146, 152, 154, 156, 165, 168, 176, 181, 182, 187, 192, 194, 201, 203, 204, 205, 207, 210, 211, 217, 220, 222, 223, 225, 226, 232, 235, 236, 240, 241, 242, 243, 244, 247, 248, 249, 251, 252, 253, 254, 257, 258, 262, 263, 265, 266, 267, 268, 269, 270, 271, 272, 283, 290, 291, 293, 294, 295, 296, 297, 298, 299, 300, 301, 305, 306, 308, 313, 314, 315, 317, 319, 320, 321, 323, 324, 325, 326, 329, 330, 332, 333, 335, 336, 339, 340, 341, 342, 343, 344, 345, 347, 351, 352, 354, 355, 356, 359, 361, 362, 368, 371, 373, 374, 375, 376, 377, 380, 381, 382, 383, 384, 386, 387, 388, 389, 390, 393, 396, 397, 398, 399, 400, 402, 403, 405, 406, 407, 408, 415, 416, 417, 420, 421, 422, 423, 424, 425, 426, 427, 428]
isubjs_SCZ = [4, 6, 15, 17, 21, 24, 26, 29, 30, 38, 40, 44, 45, 46, 48, 49, 50, 55, 56, 57, 58, 59, 60, 61, 62, 65, 67, 68, 70, 71, 72, 74, 75, 76, 77, 78, 79, 85, 86, 91, 95, 98, 99, 101, 102, 103, 104, 106, 108, 109, 110, 113, 114, 115, 116, 117, 121, 122, 123, 124, 126, 129, 130, 131, 132, 133, 134, 136, 137, 138, 141, 144, 147, 148, 149, 150, 151, 153, 155, 157, 158, 159, 160, 161, 162, 163, 164, 166, 167, 169, 170, 171, 172, 173, 174, 175, 177, 178, 179, 180, 183, 184, 185, 186, 188, 189, 190, 191, 193, 195, 196, 197, 198, 199, 200, 202, 206, 208, 209, 212, 213, 214, 215, 216, 218, 219, 221, 224, 227, 228, 229, 230, 231, 233, 234, 237, 238, 239, 245, 246, 250, 255, 256, 259, 260, 261, 264, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 285, 286, 287, 288, 289, 292, 302, 303, 304, 307, 309, 310, 311, 312, 316, 318, 322, 327, 328, 334, 337, 338, 346, 348, 349, 350, 353, 357, 358, 360, 363, 364, 365, 366, 367, 369, 370, 372, 378, 379, 385, 392, 394, 395, 401, 404, 409, 410, 411, 412, 413, 414, 418, 419]
meanfs = []
meanfdict = {}
isubjs = list(range(0,481 if area == 'ACC' else 429))
spikfreqdata = []
AUCdata = []
for iisubj in range(0,len(isubjs)):
isubj = isubjs[iisubj]
#print('Loading hay/saves_'+area+'/'+area+'_patientID_'+str(isubj+1)+'.sav', 'rb')
unpicklefile = open('hay/saves_'+area+'/'+area+'_patientID_'+str(isubj+1)+'.sav', 'rb')
unpickledlist = pickle.load(unpicklefile,encoding='bytes')
unpicklefile.close()
spikfreqsAll = unpickledlist[0]
if len(Is) > 0:
if any([Is[i] != unpickledlist[-1][i] for i in range(0,len(unpickledlist[0]))]):
print('Mismatch len(is)')
Is = unpickledlist[-1]
meanfs.append(mean(unpickledlist[0]))
meanfdict[isubj] = meanfs[-1]
spikfreqdata.append(spikfreqsAll[:])
AUCdata.append(sum(spikfreqsAll[0]))
scipy.io.savemat('data_Hay_'+area+'.mat',{'spikfreqdata': spikfreqdata, 'AUCdata': AUCdata, 'isubjs_SCZ': isubjs_SCZ, 'isubjs_HC': isubjs_HC, 'Is': Is})
for i in range(0,481 if area == 'ACC' else 429):
if isnan(AUCdata[i]):
print(area+' subj '+str(i)+' nan')
taus_all = []
taus_pop_all = []
#Subject-wise:
ordAUCdata = argsort(AUCdata)
tau_interpolated_sorted = mytools.interpolate_extrapolate_constant(AUCs,tauNeurs,sort(AUCdata))
tau_interpolated = [[tau_interpolated_sorted[i] for i in range(0,len(ordAUCdata)) if ordAUCdata[i] == j][0] for j in range(0,len(ordAUCdata))]
taus_all.append(tau_interpolated[:])
#Population-averaged:
tau_interpolated_pop = mytools.interpolate_extrapolate_constant(AUCs,tauNeurs,[mean([AUCdata[i] for i in isubjs_HC])])[0]
#for itau in range(0,len(AUCs)):
# print('iclass = '+str(iclass)+', tau = '+str(tauNeurs[itau])+' AUC = '+str(AUCs_norm[itau]))
# #for isubj in range(0,len(AUCcoeffs)):
# # if itau < len(tauNeurs)-1 and (AUCs_norm[itau] <= AUCcoeff < AUCs_norm[itau+1] or AUCs_norm[itau] >= AUCcoeff > AUCs_norm[itau+1]):
# # print('iclass = '+str(iclass)+', tau = '+str(tau_interpolated[0])+' AUC = '+str(AUCcoeff)+' (interpolated)')
file=open('taus_cortical_subjectwise_'+area+'.sav', 'wb')
pickle.dump([tau_interpolated,AUCdata,tau_interpolated_pop,isubjs_HC,isubjs_SCZ,taus_pop_all,meanfs],file)
file.close()
print(area+' AUC in HCs: '+str(mean([AUCdata[i] for i in isubjs_HC]))+', in SCZ: '+str(mean([AUCdata[i] for i in isubjs_SCZ])))
print(area+' tau in HCs: '+str(mean([tau_interpolated[i] for i in isubjs_HC]))+', in SCZ: '+str(mean([tau_interpolated[i] for i in isubjs_SCZ])))
#qwe
AUCdata_both.append(AUCdata[:])
tau_interpolated_both.append(tau_interpolated[:])
isubjs_HC_both.append(isubjs_HC[:])
isubjs_SCZ_both.append(isubjs_SCZ[:])
qwe