meta_windows = pd.concat(meta_windows)
        meta_windows.reset_index(drop=True,
                                 inplace=True)
        meta_windows.worm_gene.replace({'C43B7.2':'figo-1'},
                                       inplace=True)
        
        feat_windows = pd.concat(feat_windows)
        feat_windows.reset_index(drop=True,
                                 inplace=True)


#%% N2 analysis only
    if N2_analysis:
        feat_df, meta_df, idx, gene_list = select_strains(['N2'],
                                                          CONTROL_STRAIN,
                                                          feat_df=feat,
                                                          meta_df=meta)

        feat_df.drop_duplicates(inplace=True)
        meta_df.drop_duplicates(inplace=True)

        # filter features
        feat_df, meta_df, featsets = filter_features(feat_df,
                                                     meta_df)

        stim_cmap = sns.color_palette('Pastel1',3)
        stim_lut = dict(zip(STIMULI_ORDER.keys(), stim_cmap))

        feat_lut = {f:v for f in featsets['all'] for k,v in stim_lut.items() if k in f}

        feat_nonan = impute_nan_inf(feat_df)
    window_files = list(WINDOW_FILES.rglob('*_window_*'))
    window_feat_files = [f for f in window_files if 'features' in str(f)]
    window_feat_files.sort(key=find_window)
    window_fname_files = [f for f in window_files if 'filenames' in str(f)]
    window_fname_files.sort(key=find_window)

    assert (find_window(f[0]) == find_window(f[1])
            for f in list(zip(window_feat_files, window_fname_files)))

    genes = [g for g in meta.worm_gene.unique() if g != CONTROL_STRAIN]
    # genes = [g.replace('C43B7.2', 'figo-1') for g in genes]
    genes = [g for g in genes if 'myo' not in g and 'unc-54' not in g]

    #%%
    feat_df, meta_df, idx, gene_list = select_strains(STRAINS,
                                                      CONTROL_STRAIN,
                                                      feat_df=feat,
                                                      meta_df=meta)
    # filter features
    feat_df, meta_df, featsets = filter_features(feat_df, meta_df)

    strain_lut, stim_lut, feat_lut = make_colormaps(gene_list,
                                                    featlist=featsets['all'],
                                                    idx=idx,
                                                    candidate_gene=STRAINS)

    # colorbars to map colors to strains
    plot_colormap(strain_lut)
    plt.savefig(saveto / 'strain_cmap.png')
    plot_cmap_text(strain_lut)
    plt.savefig(saveto / 'strain_cmap_text.png')
    genes = [g for g in meta_ts.worm_gene.unique() if g != CONTROL_STRAIN]
    genes = [g for g in genes if 'myo' not in g and 'unc-54' not in g]

    #%%

    for g in genes:
        print('making ts stimuli plots for {}'.format(g))
        candidate_gene = g
        timeseries_fname = RAW_DATA_DIR / 'Results' / '{}_timeseries.hdf5'.format(
            candidate_gene)
        (saveto / candidate_gene).mkdir(exist_ok=True)

        # only select strains of interest
        meta, idx, gene_list = select_strains(candidate_gene,
                                              CONTROL_STRAIN,
                                              meta_df=meta_ts)
        strain_lut, stim_lut = make_colormaps(gene_list, [], idx,
                                              candidate_gene)

        if g == 'figo-1':
            strain_lut['C43B7.2'] = strain_lut['figo-1']

        timeseries_df = pd.read_hdf(timeseries_fname, 'timeseries_df')
        # hires_df = pd.read_hdf(timeseries_fname, 'hires_df')

        # test_feats = [f for f in timeseries_df.columns if 'radial_velocity' in f]

        # t = ['d_relative_to_neck_radial_velocity_head_tip',
        #      'relative_to_neck_radial_velocity_head_tip']
示例#4
0
    meta = pd.read_csv(METADATA_FILE, index_col=None)  
    assert meta.worm_strain.unique().shape[0] == meta.worm_gene.unique().shape[0]
    meta.loc[:,'date_yyyymmdd'] = meta['date_yyyymmdd'].apply(lambda x: str(int(x)))     
    #drop nan wells
    meta.dropna(axis=0,
                subset=['worm_gene'],
                inplace=True)   
    # remove data from dates to exclude
    good_date = meta.query('@DATES_TO_DROP not in imaging_date_yyyymmdd').index
    # bad wells
    good_wells_from_gui = meta.query('is_bad_well == False').index
    meta = meta.loc[good_wells_from_gui & good_date,:]
    
    # only select strains of interest
    meta, idx, gene_list = select_strains(CANDIDATE_GENE,
                                          CONTROL_STRAIN,
                                          meta_df=meta,
                                          feat_df=None)        
    strain_lut, stim_lut = make_colormaps(gene_list,
                                            idx,
                                            CANDIDATE_GENE,
                                            CONTROL_STRAIN,
                                            featlist=[])
    #strain to gene dictionary
    strain_dict = strain_gene_dict(meta)
    gene_dict = {v:k for k,v in strain_dict.items()}

    meta = align_bluelight_meta(meta)
    
    if is_reload_timeseries_from_results:
        # this uses tierpytools under the hood
        timeseries_df, hires_df  = load_bluelight_timeseries_from_results(