def test_load(): data = [1, 2, 3, 4, 5] assert pypickle.save('test.pkl', data, overwrite=True) data_load = pypickle.load('test.pkl') assert data_load == data
def process_csv_file(uploaded_filenames, uploaded_file_contents, y_min, alpha, k, excl_background, perc_min_num, specificity, multtest): """Save uploaded files and regenerate the file list.""" # Check input parameters [args, runOK, runtxt]=check_input(uploaded_filenames, uploaded_file_contents, y_min, alpha, k, excl_background, perc_min_num, specificity, multtest) if runOK==False: for txt in runtxt: print('[HNET-GUI] %s' %txt) return(runtxt) print('alpha:%s' %args['alpha']) print('y_min:%s' %args['y_min']) print('k:%s' %args['k']) print('multtest:%s' %args['multtest']) print('excl_background:%s' %args['excl_background']) print('perc_min_num:%s' %args['perc_min_num']) print('specificity:%s' %args['specificity']) print('dropna:%s' %args['dropna']) print('File input: %s' %(args['uploaded_filenames'])) # if uploaded_filenames is not None and uploaded_file_contents is not None: filepath = save_file(args['uploaded_filenames'], args['uploaded_file_contents'], TMP_DIRECTORY) [_,filename, _] = hnet.hnet.path_split(args['uploaded_filenames']) savepath = os.path.join(HNET_DIR_STABLE,filename+'_'+str(args['y_min'])+'_'+str(args['k'])+'_'+str(args['multtest'])+'_'+str(args['specificity'])+'_'+str(args['perc_min_num'])+'_'+str(args['excl_background'])+'/') d3path = get_d3path(savepath) pklpath = get_pklpath(savepath) print('filepath %s' %(filepath)) print('savepath %s' %(savepath)) print('d3path %s' %(d3path)) print('pklpath %s' %(pklpath)) # Progressbar # mGUI=tk.Tk() # mGUI.title('HNET '+ filename) # progressbar = ttk.Progressbar(mGUI, orient='horizontal', length=300) # progressbar.pack(side=tk.TOP) # progressbar.config(mode='determinate') # progressbar.update() # progressbar['value']=0 # progressbar['maximum']=5 # # Set starting position # progressbar['value']=progressbar['value']+1 # update bar # progressbar.update() # update gui # Make directory if not os.path.isdir(savepath): os.mkdir(savepath) # Make D3js path if not os.path.isfile(d3path): # Read file df = pd.read_csv(filepath) # Run HNet # progressbar['value']=progressbar['value']+1 # update bar # progressbar.update() # update gui HNET_OUT = hnet.fit(df, alpha=args['alpha'], y_min=args['y_min'], k=args['k'], multtest=args['multtest'], dtypes='pandas', specificity=args['specificity'], perc_min_num=args['perc_min_num'], dropna=args['dropna'], excl_background=args['excl_background'], verbose=3) # Save pickle file print('SAVING NETWORK FIGURE: %s' %(savepath)) # progressbar['value']=progressbar['value']+1 # update bar # progressbar.update() # update gui HNET_OUT['G'] = hnet.plot_network(HNET_OUT, dist_between_nodes=0.4, scale=2, dpi=250, figsize=[30,20], showfig=False, savepath=os.path.join(savepath,'hnet_network.png')) # Store pickle file print('STORE PICKLE') # progressbar['value']=progressbar['value']+1 # update bar # progressbar.update() # update gui pypickle.save(pklpath, HNET_OUT) #print('MAKE D3GRAPH') _ = hnet.plot_d3graph(HNET_OUT, savepath=savepath, showfig=False) else: print('dir exists, load stuff') HNET_OUT=pypickle.load(pklpath) # Open in browser if os.path.isfile(d3path): print('OPEN BROWSER') webbrowser.open(os.path.abspath(d3path), new=2) print('HNET_DIR_STABLE: %s!' %(HNET_DIR_STABLE)) print('%s done!' %(filename)) print('-----------------------Done!-----------------------') # progressbar['value']=progressbar['maximum'] # update bar # progressbar.update() # update gui # try: # mGUI.destroy() # except: # pass return(filename)
def test_save(): data = [1, 2, 3, 4, 5] assert pypickle.save('test.pkl', data, overwrite=True) assert pypickle.save('test.pkl', data, overwrite=False) == False
# %% import pypickle print(dir(pypickle)) print(pypickle.__version__) # %% filepath = 'tes1t.pkl' data = [1, 2, 3, 4, 5] status = pypickle.save(filepath, data, fix_imports=True, overwrite=True) #%% Load file data = pypickle.load(filepath, encoding="latin1") # %%
def save_proxy_list(proxy_list): proxy_list_name = get_proxy_list_file_name() pypickle.save(proxy_list, proxy_list_name)
def save_proxy_page(page): file = get_proxy_page_file_name() pypickle.save(page, file)
out['HNETGradientScoresDirected']=HNETGradientScoresDirected out['HNETGradientScoresUnDirected']=HNETGradientScoresUnDirected out['HNETGradientScores']=HNETGradientScores out['df_method_comparison']=df_method_comparison out['df_method_comparison_scores']=df_method_comparison_scores # Random scores out['scores_rand']=scores_rand #Best performing results idx=HNETGradientScores['mcc_undirected'].argmax() out['hnet_undirected_bestmodel_args']=HNETGradientScores.iloc[idx,:] out['hnet_directed_bestmodel_args']=HNETGradientScores.iloc[idx,:] out['hnet_undirected_bestmodel']=out_hnets['adjmat'][out_hnets['adjmat']>HNETGradientScores.iloc[idx,:]['minP']].fillna(0) #%% Save savename='hnet_'+arg['DAG']+'_'+str(arg['n_sampling'])+'.pkl' pypickle.save(os.path.join('../PROJECTS/hnet/results/',savename), out) #%% print(arg) print(df_method_comparison) print(df_method_comparison_scores) #%% Plot all results with these arguments # Real model _ = bayes.plot(modelTrue, pos=modelTrue['G']['pos']) ## Learned model using bayes _=bayes.plot(out_bayes['adjmat'], pos=modelTrue['G']['pos']) ## Learned model using hnets _=bayes.plot(out_hnets['adjmat']>0, pos=modelTrue['G']['pos']) #%% MAKE FIGURE
def create_labels(url=path): aliment_ids = {} with open(url + "img_annotations.json", "r") as json_file: photos = json.load(json_file) for k, v in photos.items(): aliment_ids.setdefault(k, []) aliment_ids[k] = [x["id"] for x in v] return aliment_ids def get_labels(tomatoes=get_ids_tomatoes(), aliment_ids=create_labels()): labels = {} for k, v in aliment_ids.items(): labels.setdefault(k, ) labels[k] = 0 for tomato in tomatoes: if tomato in v: labels[k] = 1 break return labels if __name__ == '__main__': print(get_labels()) pickle.save(var=get_labels(), filepath='/Users/RomainLejeune/Downloads/tomato_label.pkl')