示例#1
0
if __name__ == "__main__":
    tic = time()
    parser = argparse.ArgumentParser(description="Find 'hit' Keio knockout strains that alter worm behaviour")
    parser.add_argument('-j', '--json', help="Path to JSON parameters file", 
                        default=JSON_PARAMETERS_PATH, type=str)
    parser.add_argument('--features_path', help="Path to feature summaries file", 
                        default=None, type=str)
    parser.add_argument('--metadata_path', help="Path to metadata file", 
                        default=None, type=str)
    args = parser.parse_args()
    
    FEATURES_PATH = args.features_path
    METADATA_PATH = args.metadata_path
    
    args = load_json(args.json)

    if FEATURES_PATH is None:
        FEATURES_PATH = Path(args.save_dir) / 'features.csv'
    if METADATA_PATH is None:
        METADATA_PATH = Path(args.save_dir) / 'metadata.csv'
        
    # load feature summaries and metadata
    features = pd.read_csv(FEATURES_PATH)
    metadata = pd.read_csv(METADATA_PATH, dtype={'comments':str, 'source_plate_id':str})
    
    # subset for desired imaging dates
    if args.dates is not None:
        assert type(args.dates) == list
        metadata = metadata.loc[metadata['date_yyyymmdd'].astype(str).isin(args.dates)]
        features = features.reindex(metadata.index)
    window_summary_paths = list(window_dir.rglob(pattern))
    window_feats = [f for f in window_summary_paths if 'features' in str(f)]
    window_feats.sort(key=find_window)
    window_files = [f for f in window_summary_paths if 'filenames' in str(f)]
    window_files.sort(key=find_window)
    
    assert all(find_window(f[0]) == find_window(f[1]) for f in zip(window_feats, window_files))
    
    return window_feats, window_files

#%% Main

if __name__ == "__main__":
    tic = time()
    
    args = load_json(JSON_PARAMETERS_PATH)
    
    strain_list = read_list_from_file(STRAIN_LIST_PATH)
    
    window_dir = Path(args.project_dir) / 'Results'
    window_date_dir = window_dir / str(DATE)
    
    window_feats, window_files = find_window_summaries((window_date_dir if DATE is not None 
                                                        else window_dir), pattern='*_window_*')
    
    window_list = [find_window(p) for p in window_feats]
    
    for w in tqdm(window_list):
        
        compiled_feat_path = window_dir / 'features_summary_compiled_window_{}.csv'.format(str(w))
        compiled_file_path = window_dir / 'filenames_summary_compiled_window_{}.csv'.format(str(w))