def _save_uploaded_file_list(samples, file_list_work, out_dir): """ Fixes all absolute work-rooted paths to relative final-rooted paths For CWL, prepare paths relative to output directory. """ if not utils.file_exists(file_list_work): return None if any([cwlutils.is_cwl_run(d) for d in samples]): upload_paths = [] with open(file_list_work) as f: for p in (l.strip() for l in f.readlines() if os.path.exists(l.strip())): if p.startswith(out_dir): upload_paths.append(p.replace(out_dir + "/", "")) else: upload_path_mapping = dict() for sample in samples: upload_path_mapping.update(get_all_upload_paths_from_sample(sample)) if not upload_path_mapping: return None with open(file_list_work) as f: paths = [l.strip() for l in f.readlines() if os.path.exists(l.strip())] upload_paths = [p for p in [ _work_path_to_rel_final_path(path, upload_path_mapping, samples[0]["upload"]["dir"]) for path in paths ] if p] if not upload_paths: return None file_list_final = os.path.join(out_dir, "list_files_final.txt") with open(file_list_final, "w") as f: for path in upload_paths: f.write(path + '\n') return file_list_final
def _save_uploaded_file_list(samples, file_list_work, out_dir): """ Fixes all absolute work-rooted paths to relative final-rooted paths """ if not utils.file_exists(file_list_work): return None upload_path_mapping = dict() for sample in samples: upload_path_mapping.update(get_all_upload_paths_from_sample(sample)) if not upload_path_mapping: return None with open(file_list_work) as f: paths = [l.strip() for l in f.readlines() if os.path.exists(l.strip())] upload_paths = [ p for p in [ _work_path_to_rel_final_path(path, upload_path_mapping, samples[0] ["upload"]["dir"]) for path in paths ] if p ] if not upload_paths: return None file_list_final = os.path.join(out_dir, "list_files_final.txt") with open(file_list_final, "w") as f: for path in upload_paths: f.write(path + '\n') return file_list_final
def _save_uploaded_data_json(samples, data_json_work, out_dir): """ Fixes all absolute work-rooted paths to relative final-rooted paths """ if not utils.file_exists(data_json_work): return None upload_path_mapping = dict() for sample in samples: upload_path_mapping.update(get_all_upload_paths_from_sample(sample)) if not upload_path_mapping: return data_json_work with open(data_json_work) as f: data = json.load(f, object_pairs_hook=OrderedDict) upload_base = samples[0]["upload"]["dir"] data = walk_json(data, lambda s: _work_path_to_rel_final_path(s, upload_path_mapping, upload_base)) data_json_final = os.path.join(out_dir, "multiqc_data_final.json") with open(data_json_final, "w") as f: json.dump(data, f, indent=4) return data_json_final
def _save_uploaded_file_list(samples, file_list_work, out_dir): if not utils.file_exists(file_list_work): return None file_list_final = os.path.join(out_dir, "list_files_final.txt") upload_path_mapping = dict() for sample in samples: upload_path_mapping.update(get_all_upload_paths_from_sample(sample)) if not upload_path_mapping: return None with open(file_list_work) as f: paths = [l.strip() for l in f.readlines() if os.path.exists(l.strip())] upload_paths = [] for path in paths: if path in upload_path_mapping: upload_path = upload_path_mapping[path] upload_base = samples[0]["upload"]["dir"] upload_relpath = os.path.relpath(upload_path, upload_base) upload_paths.append(upload_relpath) if not upload_paths: return None with open(file_list_final, "w") as f: for path in upload_paths: f.write(path + '\n') return file_list_final