align_file = "/home/theo/dev/git/cnvCallerGPU/test_depth.txt" depth_sup_mean = "/home/theo/dev/git/cnvCallerGPU/depth_sup_mean.txt" def calc_depth_mean(align_file): with open(align_file, 'r') as file: total_depth = 0 total_window = 0 for line in file: depth_str_split = line.split() depth_str_value = depth_str_split[6:] total_depth += float(depth_str_value[0]) total_window += 1 mean = total_depth / total_window return mean with open(depth_sup_mean, 'w') as output: with open(align_file, 'r') as file: mean = calc_depth_mean(align_file) for line in file: depth_str_split = line.split() depth_str_value = depth_str_split[6:] if float(depth_str_value[0]) > mean: output.write(f"{depth_str_split[5]}: {depth_str_value[0]}\n")