123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- """Figure 1S33S1 Ntsr versions of fig1S33S1.py, use run -i fig1S33S1_ntsr.py. Currently used
- for rebuttal figure R2"""
- assert EXPTYPE == 'ntsrmvis'
- from matplotlib.patches import Rectangle
- chirptype = pd.read_csv('csv/ntsr_unit_celltypes_yannik.csv')
- chirptype.set_index(['msu'], inplace=True)
- ## strip plot max FMI of movie and grating meanrate and meanburstratio,
- ## each msu classified as chirp ON/OFF/transient/mixed by Yannik:
- np.random.seed(0) # to get identical horizontal jitter in strip plots on every run
- figsize = DEFAULTFIGURESIZE
- chirp2clr = {'On':green, 'Off':'red', 'Transient':'black', 'Mixed':'gray'}
- for stimtype in STIMTYPES:
- stimtypelabel = stimtype2axislabel[stimtype]
- for measure in ['meanrate', 'meanburstratio']:
- axislabel = measure2axislabel[measure]
- if axislabel.islower():
- axislabel = axislabel.capitalize()
- fmis, onoffs = [], []
- for msustr in mvigrtmsustrs:
- fmi = maxFMI.loc[msustr, 'none', stimtype][measure]
- if pd.isna(fmi):
- continue
- try:
- onoff = chirptype.loc[msustr]['clu_label']
- except KeyError:
- continue # no chirp cell type for this msu
- fmis.append(fmi)
- onoffs.append(onoff)
- fmis = np.asarray(fmis)
- onoffs = np.asarray(onoffs)
- onfmis = fmis[onoffs == 'ON-sust.']
- offfmis = fmis[onoffs == 'OFF-sust.']
- onofffmis = fmis[onoffs == 'ON-OFF-trans.']
- mixedfmis = fmis[onoffs == 'mixed']
- f, a = plt.subplots(figsize=figsize)
- wintitle('maxFMI chirp %s %s stripplot' % (stimtypelabel, measure))
- dfdict = {'On':onfmis, 'Off':offfmis, 'Transient':onofffmis, 'Mixed':mixedfmis}
- data = pd.DataFrame.from_dict(dfdict, orient='index').transpose()
- sns.stripplot(ax=a, data=data, palette=chirp2clr, clip_on=False,
- marker='.', size=np.sqrt(70))
- a.set_ylabel('FMI')
- a.set_xlim(0, 3)
- a.set_ylim(-1, 1)
- a.set_yticks([-1, 0, 1])
- a.spines['left'].set_position(('outward', 10))
- a.spines['bottom'].set_position(('outward', 5))
- #a.spines['bottom'].set_visible(False)
- #a.tick_params(bottom=False)
- plt.xticks(rotation=45)
- print(stimtype, measure)
- print(data)
- ## scatter plot grating meanrates, coloured by chirp ON sustained/OFF sustained/transient/mixed
- ## as classified by Yannik:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate grating %s chirp' % st8)
- rons, roffs, onoffs = [], [], []
- for mseustr in grtmseustrs:
- meanrate = grtresp.loc[mseustr, st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- try:
- onoff = chirptype.loc[msustr]['clu_label']
- except KeyError:
- continue # no chirp experiment for cell typing
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- onoffs.append(onoff)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- onoffs = np.asarray(onoffs)
- clrs = []
- chirptype2clr = {'ON-sust.':green, 'OFF-sust.':'red', 'ON-OFF-trans.':'black',
- 'mixed':'gray'}
- for onoff in onoffs:
- clr = chirptype2clr[onoff]
- clrs.append(clr)
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- ## scatter plot movie meanrates, coloured by chirp ON sustained/OFF sustained/transient/mixed
- ## as classified by Yannik:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate movie nat %s chirp' % st8)
- rons, roffs, onoffs = [], [], []
- for mseustr in mvimseustrs:
- meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- try:
- onoff = chirptype.loc[msustr]['clu_label']
- except KeyError:
- continue # no chirp experiment for cell typing
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- print(mseustr)
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- onoffs.append(onoff)
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- clrs = []
- chirptype2clr = {'ON-sust.':green, 'OFF-sust.':'red', 'ON-OFF-trans.':'black',
- 'mixed':'gray'}
- for onoff in onoffs:
- clr = chirptype2clr[onoff]
- clrs.append(clr)
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- ## scatter plot grating burst ratio, coloured by chirp ON sustained/OFF sustained/transient/mixed
- ## as classified by Yannik:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio grating %s chirp' % st8)
- brons, broffs, onoffs = [], [], []
- for mseustr in grtmseustrs:
- br = grtresp.loc[mseustr, st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- try:
- onoff = chirptype.loc[msustr]['clu_label']
- except KeyError:
- continue # no chirp experiment for cell typing
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- onoffs.append(onoff)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs, onoffs = np.asarray(brons), np.asarray(broffs), np.asarray(onoffs)
- clrs = []
- chirptype2clr = {'ON-sust.':green, 'OFF-sust.':'red', 'ON-OFF-trans.':'black',
- 'mixed':'gray'}
- for onoff in onoffs:
- clr = chirptype2clr[onoff]
- clrs.append(clr)
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- ## scatter plot movie burst ratio, coloured by chirp ON sustained/OFF sustained/transient/mixed
- ## as classified by Yannik:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio movie nat %s chirp' % st8)
- brons, broffs, onoffs = [], [], []
- for mseustr in mvimseustrs:
- br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- msustr = mseustr2msustr(mseustr)
- try:
- onoff = chirptype.loc[msustr]['clu_label']
- except KeyError:
- continue # no chirp experiment for cell typing
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- onoffs.append(onoff)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs, onoffs = np.asarray(brons), np.asarray(broffs), np.asarray(onoffs)
- clrs = []
- chirptype2clr = {'ON-sust.':green, 'OFF-sust.':'red', 'ON-OFF-trans.':'black',
- 'mixed':'gray'}
- for onoff in onoffs:
- clr = chirptype2clr[onoff]
- clrs.append(clr)
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #TRANSTHRESH = 0.2
- #ONOFFTHRESH = 0.2
- ## generate celltype vs chirptype on/off/transient/other matrix, requires that celltype code
- ## from fig1S33S1.py has been run with EXPTYPE == 'ntsrmvis' set.
- ## The two classification methods correspond very poorly:
- # join on msu index, those rows that don't overlap have chirp type fields left as NaN
- celltypechirptype = celltype.join(chirptype)
- mat = np.zeros((4, 4), dtype=int)
- chrptypestr2i = {'ON-sust.':0, 'OFF-sust.':1, 'ON-OFF-trans.':2, 'mixed':3}
- mvitypestr2i = {'On':0, 'Off':1, 'Trans':2, '':3}
- for msustr, row in celltypechirptype.iterrows():
- chrptypestr = row['clu_label']
- if pd.isna(chrptypestr):
- continue # mvi unit doesn't have a chirp experiment?
- onoff = row['onoff']
- trans = row['trans']
- mvitypestr = ''
- if trans >= TRANSTHRESH: # first try and classify by trans
- mvitypestr = 'Trans'
- elif onoff >= ONOFFTHRESH: # try and classify by on/off
- mvitypestr = 'On'
- elif onoff < -ONOFFTHRESH:
- mvitypestr = 'Off'
- chrptypei = chrptypestr2i[chrptypestr]
- mvitypei = mvitypestr2i[mvitypestr]
- mat[mvitypei, chrptypei] += 1
- figsize = 4, 3
- f, a = plt.subplots(figsize=figsize)
- wintitle('celltype vs chirptype matrix ONOFFTHRESH=%.2f TRANSTHRESH=%.2f'
- % (ONOFFTHRESH, TRANSTHRESH))
- #a.imshow(mat, origin='upper', aspect='equal', cmap='gray')
- img = a.matshow(mat)
- #a.set_xticks(np.arange(4))
- #a.set_yticks(np.arange(4))
- #a.set_xticklabels(list(chrptypestr2i.keys()))
- #a.set_yticklabels(list(mvitypestr2i.keys()))
- f.colorbar(img, ticks=[mat.min(), mat.max()], label='Unit count')
- a.set_xlabel('Chirp type')
- a.set_ylabel('Movie onset type')
- f.tight_layout(pad=1)
|