nodes: 0, module; 1, function_definition; 2, function_name:clean_file; 3, parameters; 4, block; 5, identifier:in_file; 6, identifier:data; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, comment:# Remove non-ascii characters. Used in coverage analysis, to support JSON code in one column; 12, comment:#   and be happy with sambamba:; 13, expression_statement; 14, if_statement; 15, identifier:prefix; 16, string:""; 17, identifier:bedprep_dir; 18, None; 19, identifier:simple; 20, None; 21, comment:"""Prepare a clean sorted input BED file without headers
      """; 22, assignment; 23, identifier:in_file; 24, block; 25, identifier:simple; 26, conditional_expression:"iconv -c -f utf-8 -t ascii | sed 's/ //g' |" if simple else ""; 27, if_statement; 28, comment:# Avoid running multiple times with same prefix; 29, if_statement; 30, expression_statement; 31, expression_statement; 32, if_statement; 33, if_statement; 34, expression_statement; 35, return_statement; 36, string:"iconv -c -f utf-8 -t ascii | sed 's/ //g' |"; 37, identifier:simple; 38, string:""; 39, not_operator; 40, block; 41, boolean_operator; 42, block; 43, assignment; 44, assignment; 45, call; 46, block; 47, not_operator; 48, block; 49, call; 50, identifier:out_file; 51, identifier:bedprep_dir; 52, expression_statement; 53, identifier:prefix; 54, call; 55, return_statement; 56, identifier:out_file; 57, call; 58, identifier:out_file; 59, call; 60, attribute; 61, argument_list; 62, expression_statement; 63, call; 64, expression_statement; 65, expression_statement; 66, with_statement; 67, attribute; 68, argument_list; 69, assignment; 70, attribute; 71, argument_list; 72, identifier:in_file; 73, attribute; 74, argument_list; 75, attribute; 76, argument_list; 77, identifier:out_file; 78, identifier:endswith; 79, string:".gz"; 80, assignment; 81, attribute; 82, argument_list; 83, call; 84, call; 85, with_clause; 86, block; 87, identifier:vcfutils; 88, identifier:bgzip_and_index; 89, identifier:out_file; 90, call; 91, keyword_argument; 92, identifier:bedprep_dir; 93, call; 94, call; 95, identifier:startswith; 96, identifier:prefix; 97, attribute; 98, identifier:join; 99, identifier:bedprep_dir; 100, binary_operator:"%s%s" % (prefix, os.path.basename(in_file)); 101, identifier:out_file; 102, identifier:replace; 103, string:".interval_list"; 104, string:".bed"; 105, identifier:out_file; 106, subscript; 107, identifier:utils; 108, identifier:file_uptodate; 109, identifier:out_file; 110, identifier:in_file; 111, identifier:check_bed_contigs; 112, argument_list; 113, identifier:check_bed_coords; 114, argument_list; 115, with_item; 116, expression_statement; 117, expression_statement; 118, expression_statement; 119, expression_statement; 120, expression_statement; 121, attribute; 122, argument_list; 123, identifier:remove_orig; 124, False; 125, attribute; 126, argument_list; 127, attribute; 128, argument_list; 129, identifier:os; 130, identifier:path; 131, string:"%s%s"; 132, tuple; 133, identifier:out_file; 134, slice; 135, identifier:in_file; 136, identifier:data; 137, identifier:in_file; 138, identifier:data; 139, as_pattern; 140, assignment; 141, assignment; 142, assignment; 143, assignment; 144, call; 145, identifier:data; 146, identifier:get; 147, string:"config"; 148, dictionary; 149, identifier:utils; 150, identifier:safe_makedir; 151, call; 152, attribute; 153, identifier:basename; 154, identifier:in_file; 155, identifier:prefix; 156, call; 157, unary_operator; 158, call; 159, as_pattern_target; 160, identifier:bcbio_py; 161, attribute; 162, identifier:cat_cmd; 163, conditional_expression:"zcat" if in_file.endswith(".gz") else "cat"; 164, identifier:sort_cmd; 165, call; 166, identifier:cmd; 167, parenthesized_expression; 168, attribute; 169, argument_list; 170, attribute; 171, argument_list; 172, identifier:os; 173, identifier:path; 174, attribute; 175, argument_list; 176, integer:3; 177, identifier:file_transaction; 178, argument_list; 179, identifier:tx_out_file; 180, identifier:sys; 181, identifier:executable; 182, string:"zcat"; 183, call; 184, string:"cat"; 185, identifier:get_sort_cmd; 186, argument_list; 187, concatenated_string; 188, identifier:do; 189, identifier:run; 190, call; 191, string:"Prepare cleaned BED file"; 192, identifier:data; 193, attribute; 194, identifier:join; 195, subscript; 196, string:"bedprep"; 197, attribute; 198, identifier:basename; 199, identifier:in_file; 200, identifier:data; 201, identifier:out_file; 202, attribute; 203, argument_list; 204, call; 205, string:"{cat_cmd} {in_file} | grep -v ^track | grep -v ^browser | grep -v ^@ | "; 206, string:"grep -v ^# | {simple} "; 207, string:"{bcbio_py} -c 'from bcbio.variation import bedutils; bedutils.remove_bad()' | "; 208, string:"{sort_cmd} -k1,1 -k2,2n > {tx_out_file}"; 209, attribute; 210, argument_list; 211, identifier:os; 212, identifier:path; 213, subscript; 214, string:"work"; 215, identifier:os; 216, identifier:path; 217, identifier:in_file; 218, identifier:endswith; 219, string:".gz"; 220, attribute; 221, argument_list; 222, identifier:cmd; 223, identifier:format; 224, dictionary_splat; 225, identifier:data; 226, string:"dirs"; 227, attribute; 228, identifier:dirname; 229, identifier:tx_out_file; 230, call; 231, identifier:os; 232, identifier:path; 233, identifier:locals; 234, argument_list
code: def clean_file(in_file, data, prefix="", bedprep_dir=None, simple=None):
      """Prepare a clean sorted input BED file without headers
      """
      # Remove non-ascii characters. Used in coverage analysis, to support JSON code in one column
      #   and be happy with sambamba:
      simple = "iconv -c -f utf-8 -t ascii | sed 's/ //g' |" if simple else ""
      if in_file:
          if not bedprep_dir:
              bedprep_dir = utils.safe_makedir(os.path.join(data["dirs"]["work"], "bedprep"))
          # Avoid running multiple times with same prefix
          if prefix and os.path.basename(in_file).startswith(prefix):
              return in_file
          out_file = os.path.join(bedprep_dir, "%s%s" % (prefix, os.path.basename(in_file)))
          out_file = out_file.replace(".interval_list", ".bed")
          if out_file.endswith(".gz"):
              out_file = out_file[:-3]
          if not utils.file_uptodate(out_file, in_file):
              check_bed_contigs(in_file, data)
              check_bed_coords(in_file, data)
              with file_transaction(data, out_file) as tx_out_file:
                  bcbio_py = sys.executable
                  cat_cmd = "zcat" if in_file.endswith(".gz") else "cat"
                  sort_cmd = get_sort_cmd(os.path.dirname(tx_out_file))
                  cmd = ("{cat_cmd} {in_file} | grep -v ^track | grep -v ^browser | grep -v ^@ | "
                         "grep -v ^# | {simple} "
                         "{bcbio_py} -c 'from bcbio.variation import bedutils; bedutils.remove_bad()' | "
                         "{sort_cmd} -k1,1 -k2,2n > {tx_out_file}")
                  do.run(cmd.format(**locals()), "Prepare cleaned BED file", data)
          vcfutils.bgzip_and_index(out_file, data.get("config", {}), remove_orig=False)
          return out_file