def do_stats(path,data,d1_arena,note):

    datasets = {}
    laser_powers = set()
    for gt in data:
        laser_powers_sorted = sorted(data[gt], cmp=flymad_analysis.cmp_laser, reverse=True)
        for order,laser in enumerate(laser_powers_sorted):
            laser_powers.add( laser )
            gtdf = data[gt][laser][gt]
            fake_gt_name = '%s-%s'%(gt,laser)
            datasets[fake_gt_name] = gtdf

    # do the stats
    stat_info = [
        ('trp_basic_control1', ['50660trp-350iru','50660-350iru']),
        ('trp_basic_control2', ['50660trp-350iru','wtrp-350iru']),
        ('trp_basic_pooled_controls', ['50660trp-350iru','my_pooled_controls-350iru']),

        ('chrimson_crosstalk_controls', ['50660chrim-350iru','50660-350iru']),
        ('chrimson_crosstalk_activation_low_1', ['50660chrim-350iru','50660chrim-028ru']),
        ('chrimson_crosstalk_activation_low_2', ['50660-350iru','50660chrim-028ru']),
        ('chrimson_activation_high', ['50660-350ru','50660chrim-028ru']),

        ('trp_crosstalk_activation_low', ['50660trp-183iru','50660trp-350ru']),
        ('trp_activation_high', ['50660trp-183iru','50660trp-434iru']),
        ]
    gt_names = {'50660':'Gal4-control',
                'wtrp':'UAS-control',
                'my_pooled_controls':'controls',
                '50660chrim':'MW>Chrim',
                '50660trp':'MW>TrpA1',
                }
    human_label_dict = {}
    for laser in laser_powers:
        laser_human = flymad_analysis.laser_desc(laser)
        assert laser_human != laser
        for gt in ['50660','50660chrim','50660trp','wtrp','my_pooled_controls']:
            gt_human = gt_names[gt]
            assert gt_human != gt
            key = '%s-%s'%(gt,laser)
            value = '%s %s'%(gt_human,laser_human)
            human_label_dict[key] = value

    pooldf = pd.concat([datasets['wtrp-350iru']['df'],datasets['50660-350iru']['df']])
    datasets['my_pooled_controls-350iru'] = dict(df=pooldf)

    num_bins = [40]
    for num_bin in num_bins:
        for experiment_name, exp_gts in stat_info:
            fname_prefix = flymad_plot.get_plotpath(path,'moonwalker_stats_%s_%d_bins'%(experiment_name,num_bin))
            madplot.view_pairwise_stats_plotly(datasets, exp_gts, fname_prefix,
                                               align_colname='t',
                                               stat_colname='Vfwd',
                                               layout_title='p-values',
                                               num_bins=num_bin,
                                               human_label_dict=human_label_dict,
                                               )
Esempio n. 2
0
def plot_all_data(path, data, arena, note):

    for gt in data:
        datasets = {}
        color_cycle = itertools.cycle(flymad_plot.EXP_COLORS)

        laser_powers_sorted = sorted(data[gt],
                                     cmp=flymad_analysis.cmp_laser,
                                     reverse=True)

        for order, laser in enumerate(laser_powers_sorted):

            #also sort to make cross-activation first
            cross_activation = (re.match('[0-9]+iru$',laser) and gt.endswith('chrim')) or \
                               (re.match('[0-9]+ru$',laser) and gt.endswith('trp'))

            gtdf = data[gt][laser][gt]

            laser_desc = flymad_analysis.laser_desc(laser)
            datasets[laser] = dict(
                xaxis=gtdf['mean']['t'].values,
                value=gtdf['mean']['Vfwd'].values,
                std=gtdf['std']['Vfwd'].values,
                n=gtdf['n']['Vfwd'].values,
                label=laser_desc,
                order=50 if cross_activation else order,
                color=color_cycle.next(),
                N=len(gtdf['df']['obj_id'].unique()),
                df=gtdf['df'],
            )

        if 1:
            if gt == "50660chrim":
                cgt = "50660"
                gtdf = data[cgt]["350iru"][cgt]
                datasets['control'] = dict(
                    xaxis=gtdf['mean']['t'].values,
                    value=gtdf['mean']['Vfwd'].values,
                    std=gtdf['std']['Vfwd'].values,
                    n=gtdf['n']['Vfwd'].values,
                    label=flymad_analysis.human_label(cgt),  #laser_desc,
                    order=100,
                    color=flymad_plot.BLACK,
                    N=len(gtdf['df']['obj_id'].unique()),
                    df=gtdf['df'],
                )

        figure_title = "Moonwalker Thorax %s (%s)" % (gt, smoothstr)

        fig = plt.figure(figure_title, figsize=(10, 8))
        ax = fig.add_subplot(1, 1, 1)
        l, axs, figs = flymad_plot.plot_timeseries_with_activation(
            ax,
            targetbetween=dict(xaxis=gtdf['first']['t'].values,
                               where=gtdf['first']['laser_state'].values > 0),
            sem=True,
            downsample=5,
            note="%s\n%s\n" % (gt, note),
            individual={
                k: {
                    'groupby': ('obj_id', 'trial'),
                    'xaxis': 't',
                    'yaxis': 'Vfwd'
                }
                for k in datasets
            },
            individual_title=figure_title + ' Individual Traces',
            **datasets)

        ax.axhline(color='k', linestyle='--', alpha=0.8)
        ax.set_ylim(YLIM)
        ax.set_xlabel('Time (s)')
        ax.set_ylabel('Fwd Velocity (%s/s)' % arena.unit)
        ax.set_xlim(XLIM)

        flymad_plot.retick_relabel_axis(ax, XTICKS, YTICKS)

        fig.savefig(flymad_plot.get_plotpath(path, "moonwalker_%s.png" % gt),
                    bbox_inches='tight')
        fig.savefig(flymad_plot.get_plotpath(path, "moonwalker_%s.svg" % gt),
                    bbox_inches='tight')

        for efigname, efig in figs.iteritems():
            efig.savefig(flymad_plot.get_plotpath(
                path, "moonwalker_%s_individual_%s.png" % (gt, efigname)),
                         bbox_inches='tight')
Esempio n. 3
0
def do_stats(path, data, d1_arena, note):

    datasets = {}
    laser_powers = set()
    for gt in data:
        laser_powers_sorted = sorted(data[gt],
                                     cmp=flymad_analysis.cmp_laser,
                                     reverse=True)
        for order, laser in enumerate(laser_powers_sorted):
            laser_powers.add(laser)
            gtdf = data[gt][laser][gt]
            fake_gt_name = '%s-%s' % (gt, laser)
            datasets[fake_gt_name] = gtdf

    # do the stats
    stat_info = [
        ('trp_basic_control1', ['50660trp-350iru', '50660-350iru']),
        ('trp_basic_control2', ['50660trp-350iru', 'wtrp-350iru']),
        ('trp_basic_pooled_controls',
         ['50660trp-350iru', 'my_pooled_controls-350iru']),
        ('chrimson_crosstalk_controls', ['50660chrim-350iru', '50660-350iru']),
        ('chrimson_crosstalk_activation_low_1',
         ['50660chrim-350iru', '50660chrim-028ru']),
        ('chrimson_crosstalk_activation_low_2',
         ['50660-350iru', '50660chrim-028ru']),
        ('chrimson_activation_high', ['50660-350ru', '50660chrim-028ru']),
        ('trp_crosstalk_activation_low', ['50660trp-183iru',
                                          '50660trp-350ru']),
        ('trp_activation_high', ['50660trp-183iru', '50660trp-434iru']),
    ]
    gt_names = {
        '50660': 'Gal4-control',
        'wtrp': 'UAS-control',
        'my_pooled_controls': 'controls',
        '50660chrim': 'MW>Chrim',
        '50660trp': 'MW>TrpA1',
    }
    human_label_dict = {}
    for laser in laser_powers:
        laser_human = flymad_analysis.laser_desc(laser)
        assert laser_human != laser
        for gt in [
                '50660', '50660chrim', '50660trp', 'wtrp', 'my_pooled_controls'
        ]:
            gt_human = gt_names[gt]
            assert gt_human != gt
            key = '%s-%s' % (gt, laser)
            value = '%s %s' % (gt_human, laser_human)
            human_label_dict[key] = value

    pooldf = pd.concat(
        [datasets['wtrp-350iru']['df'], datasets['50660-350iru']['df']])
    datasets['my_pooled_controls-350iru'] = dict(df=pooldf)

    num_bins = [40]
    for num_bin in num_bins:
        for experiment_name, exp_gts in stat_info:
            fname_prefix = flymad_plot.get_plotpath(
                path,
                'moonwalker_stats_%s_%d_bins' % (experiment_name, num_bin))
            madplot.view_pairwise_stats_plotly(
                datasets,
                exp_gts,
                fname_prefix,
                align_colname='t',
                stat_colname='Vfwd',
                layout_title='p-values',
                num_bins=num_bin,
                human_label_dict=human_label_dict,
            )
Esempio n. 4
0
def plot_cross_activation_only(path, data, arena, note):

    PLOTS = [
        ('50660chrim', {
            'activation': '350ru',
            'cross_activation': '350iru'
        }),
        ('50660trp', {
            'activation': '434iru',
            'cross_activation': '350ru'
        }),
        ('50660trp', {
            'activation': '350iru',
            'cross_activation': '350ru'
        }),
    ]

    for gt, lasers in PLOTS:
        figname = 'vs'.join(lasers.values())

        alaser = lasers['activation']
        adf = data[gt][alaser][gt]
        claser = lasers['cross_activation']
        cdf = data[gt][claser][gt]
        datasets = {
            'activation':
            dict(xaxis=adf['mean']['t'].values,
                 value=adf['mean']['Vfwd'].values,
                 std=adf['std']['Vfwd'].values,
                 n=adf['n']['Vfwd'].values,
                 label='Activation (%s)' % flymad_analysis.laser_desc(alaser),
                 order=0,
                 color=flymad_plot.RED,
                 N=len(adf['df']['obj_id'].unique()),
                 df=adf['df']),
            'cross_activation':
            dict(xaxis=cdf['mean']['t'].values,
                 value=cdf['mean']['Vfwd'].values,
                 std=cdf['std']['Vfwd'].values,
                 n=cdf['n']['Vfwd'].values,
                 label='Cross Activation (%s)' %
                 flymad_analysis.laser_desc(claser),
                 order=1,
                 color=flymad_plot.BLACK,
                 N=len(cdf['df']['obj_id'].unique()),
                 df=cdf['df']),
        }

        figure_title = "Moonwalker Thorax Crosstalk %s (%s)" % (gt, figname)

        fig = plt.figure(figure_title, figsize=(10, 8))
        ax = fig.add_subplot(1, 1, 1)
        l, axs, figs = flymad_plot.plot_timeseries_with_activation(
            ax,
            targetbetween=dict(xaxis=adf['first']['t'].values,
                               where=adf['first']['laser_state'].values > 0),
            sem=True,
            downsample=5,
            note="%s\n%s\n" % (gt, note),
            individual={
                k: {
                    'groupby': ('obj_id', 'trial'),
                    'xaxis': 't',
                    'yaxis': 'Vfwd'
                }
                for k in datasets
            },
            individual_title=figure_title + ' Individual Traces',
            **datasets)

        ax.axhline(color='k', linestyle='--', alpha=0.8)
        ax.set_ylim(YLIM)
        ax.set_xlabel('Time (s)')
        ax.set_ylabel('Fwd Velocity (%s/s)' % arena.unit)
        ax.set_xlim(XLIM)

        flymad_plot.retick_relabel_axis(ax, XTICKS, YTICKS)

        fig.savefig(flymad_plot.get_plotpath(
            path, "moonwalker_%s_%s.png" % (gt, figname)),
                    bbox_inches='tight')
        fig.savefig(flymad_plot.get_plotpath(
            path, "moonwalker_%s_%s.svg" % (gt, figname)),
                    bbox_inches='tight')

        for efigname, efig in figs.iteritems():
            efig.savefig(flymad_plot.get_plotpath(
                path, "moonwalker_%s_%s_individual_%s.png" %
                (gt, figname, efigname)),
                         bbox_inches='tight')
def plot_all_data(path, data, arena, note):

    for gt in data:
        datasets = {}
        color_cycle = itertools.cycle(flymad_plot.EXP_COLORS)

        laser_powers_sorted = sorted(data[gt], cmp=flymad_analysis.cmp_laser, reverse=True)

        for order,laser in enumerate(laser_powers_sorted):

            #also sort to make cross-activation first
            cross_activation = (re.match('[0-9]+iru$',laser) and gt.endswith('chrim')) or \
                               (re.match('[0-9]+ru$',laser) and gt.endswith('trp'))

            gtdf = data[gt][laser][gt]

            laser_desc = flymad_analysis.laser_desc(laser)
            datasets[laser] = dict(xaxis=gtdf['mean']['t'].values,
                                   value=gtdf['mean']['Vfwd'].values,
                                   std=gtdf['std']['Vfwd'].values,
                                   n=gtdf['n']['Vfwd'].values,
                                   label=laser_desc,
                                   order=50 if cross_activation else order,
                                   color=color_cycle.next(),
                                   N=len(gtdf['df']['obj_id'].unique()),
                                   df=gtdf['df'],
            )

        if 1:
            if gt == "50660chrim":
                cgt = "50660"
                gtdf = data[cgt]["350iru"][cgt]
                datasets['control'] = dict(xaxis=gtdf['mean']['t'].values,
                                   value=gtdf['mean']['Vfwd'].values,
                                   std=gtdf['std']['Vfwd'].values,
                                   n=gtdf['n']['Vfwd'].values,
                                   label=flymad_analysis.human_label(cgt),#laser_desc,
                                   order=100,
                                   color=flymad_plot.BLACK,
                                   N=len(gtdf['df']['obj_id'].unique()),
                                   df=gtdf['df'],
            )

        figure_title = "Moonwalker Thorax %s (%s)" % (gt,smoothstr)

        fig = plt.figure(figure_title, figsize=(10,8))
        ax = fig.add_subplot(1,1,1)
        l, axs, figs = flymad_plot.plot_timeseries_with_activation(ax,
                            targetbetween=dict(xaxis=gtdf['first']['t'].values,
                                               where=gtdf['first']['laser_state'].values>0),
                            sem=True,
                            downsample=5,
                            note="%s\n%s\n" % (gt,note),
                            individual={k:{'groupby':('obj_id','trial'),'xaxis':'t','yaxis':'Vfwd'} for k in datasets},
                            individual_title=figure_title + ' Individual Traces',
                            **datasets
        )

        ax.axhline(color='k', linestyle='--',alpha=0.8)
        ax.set_ylim(YLIM)
        ax.set_xlabel('Time (s)')
        ax.set_ylabel('Fwd Velocity (%s/s)' % arena.unit)
        ax.set_xlim(XLIM)

        flymad_plot.retick_relabel_axis(ax, XTICKS, YTICKS)

        fig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s.png" % gt), bbox_inches='tight')
        fig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s.svg" % gt), bbox_inches='tight')

        for efigname, efig in figs.iteritems():
            efig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s_individual_%s.png" % (gt, efigname)), bbox_inches='tight')
def plot_cross_activation_only(path, data, arena, note):

    PLOTS = [('50660chrim',{'activation':'350ru','cross_activation':'350iru'}),
             ('50660trp',{'activation':'434iru','cross_activation':'350ru'}),
             ('50660trp',{'activation':'350iru','cross_activation':'350ru'}),
    ]

    for gt,lasers in PLOTS:
        figname = 'vs'.join(lasers.values())

        alaser = lasers['activation']
        adf = data[gt][alaser][gt]
        claser = lasers['cross_activation']
        cdf = data[gt][claser][gt]
        datasets = {
            'activation':dict(xaxis=adf['mean']['t'].values,
                              value=adf['mean']['Vfwd'].values,
                              std=adf['std']['Vfwd'].values,
                              n=adf['n']['Vfwd'].values,
                              label='Activation (%s)' % flymad_analysis.laser_desc(alaser),
                              order=0,
                              color=flymad_plot.RED,
                              N=len(adf['df']['obj_id'].unique()),
                              df=adf['df']),
            'cross_activation':dict(
                              xaxis=cdf['mean']['t'].values,
                              value=cdf['mean']['Vfwd'].values,
                              std=cdf['std']['Vfwd'].values,
                              n=cdf['n']['Vfwd'].values,
                              label='Cross Activation (%s)' % flymad_analysis.laser_desc(claser),
                              order=1,
                              color=flymad_plot.BLACK,
                              N=len(cdf['df']['obj_id'].unique()),
                              df=cdf['df']),
        }

        figure_title = "Moonwalker Thorax Crosstalk %s (%s)" % (gt,figname)

        fig = plt.figure(figure_title, figsize=(10,8))
        ax = fig.add_subplot(1,1,1)
        l,axs, figs = flymad_plot.plot_timeseries_with_activation(ax,
                    targetbetween=dict(xaxis=adf['first']['t'].values,
                                       where=adf['first']['laser_state'].values>0),
                    sem=True,
                    downsample=5,
                    note="%s\n%s\n" % (gt,note),
                    individual={k:{'groupby':('obj_id','trial'),'xaxis':'t','yaxis':'Vfwd'} for k in datasets},
                    individual_title=figure_title + ' Individual Traces',
                    **datasets
        )

        ax.axhline(color='k', linestyle='--',alpha=0.8)
        ax.set_ylim(YLIM)
        ax.set_xlabel('Time (s)')
        ax.set_ylabel('Fwd Velocity (%s/s)' % arena.unit)
        ax.set_xlim(XLIM)

        flymad_plot.retick_relabel_axis(ax, XTICKS, YTICKS)

        fig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s_%s.png" % (gt, figname)), bbox_inches='tight')
        fig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s_%s.svg" % (gt, figname)), bbox_inches='tight')

        for efigname, efig in figs.iteritems():
            efig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s_%s_individual_%s.png" % (gt, figname, efigname)), bbox_inches='tight')