def import_from_local_path(path, target_dir, fsc=None): fns = glob(os.path.join(path, '**', '*.*'), recursive=True) fns = [fn for fn in fns if is_ms_file(fn)] fns_out = [] n_files = len(fns) for i, fn in enumerate(tqdm(fns)): if fsc is not None: fsc.set('progress', int(100 * (1 + i) / n_files)) fn_out = P(target_dir) / P(fn).with_suffix('.feather').name if P(fn_out).is_file(): continue fns_out.append(fn_out) try: convert_ms_file_to_feather(fn, fn_out) except: logging.warning(f'Could not convert {fn}') return fns_out
def parse_ms_files(contents, filename, date, target_dir): content_type, content_string = contents.split(',') decoded = base64.b64decode(content_string) fn_abs = os.path.join(target_dir, filename) with lock(fn_abs): with open(fn_abs, 'wb') as file: file.write(decoded) new_fn = convert_ms_file_to_feather(fn_abs) if os.path.isfile(new_fn): os.remove(fn_abs)
def ms_convert(n_clicks, rows, wdir): target_dir = os.path.join(wdir, 'ms_files') if n_clicks is None: raise PreventUpdate fns = [row['MS-file'] for row in rows] fns = [fn for fn in fns if not fn.endswith('.feather')] fns = [os.path.join(target_dir, fn) for fn in fns] n_total = len(fns) for i, fn in enumerate(fns): fsc.set('progress', int(100 * (i + 1) / n_total)) new_fn = convert_ms_file_to_feather(fn) if os.path.isfile(new_fn): os.remove(fn) return dbc.Alert('Files converted to feather format.', color='info')
def test_convert_mzml_to_feather(tmp_path): fn_out = P(TEST_MZML).with_suffix('.feather') convert_ms_file_to_feather(TEST_MZML, fn_out) assert fn_out.is_file()