nodes: 0, module; 1, function_definition; 2, function_name:_prep_callable_bed; 3, parameters; 4, block; 5, identifier:in_file; 6, identifier:work_dir; 7, identifier:stats; 8, identifier:data; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, return_statement; 14, comment:"""Sort and merge callable BED regions to prevent SV double counting
      """; 15, assignment; 16, assignment; 17, not_operator; 18, block; 19, call; 20, identifier:out_file; 21, call; 22, identifier:gsort; 23, call; 24, call; 25, with_statement; 26, attribute; 27, argument_list; 28, attribute; 29, argument_list; 30, attribute; 31, argument_list; 32, attribute; 33, argument_list; 34, with_clause; 35, block; 36, identifier:vcfutils; 37, identifier:bgzip_and_index; 38, identifier:out_file; 39, subscript; 40, attribute; 41, identifier:join; 42, identifier:work_dir; 43, binary_operator:"%s-merge.bed.gz" % utils.splitext_plus(os.path.basename(in_file))[0]; 44, identifier:config_utils; 45, identifier:get_program; 46, string:"gsort"; 47, identifier:data; 48, identifier:utils; 49, identifier:file_uptodate; 50, identifier:out_file; 51, identifier:in_file; 52, with_item; 53, expression_statement; 54, expression_statement; 55, expression_statement; 56, identifier:data; 57, string:"config"; 58, identifier:os; 59, identifier:path; 60, string:"%s-merge.bed.gz"; 61, subscript; 62, as_pattern; 63, assignment; 64, assignment; 65, call; 66, call; 67, integer:0; 68, call; 69, as_pattern_target; 70, identifier:fai_file; 71, call; 72, identifier:cmd; 73, parenthesized_expression; 74, attribute; 75, argument_list; 76, attribute; 77, argument_list; 78, identifier:file_transaction; 79, argument_list; 80, identifier:tx_out_file; 81, attribute; 82, argument_list; 83, concatenated_string; 84, identifier:do; 85, identifier:run; 86, call; 87, string:"Prepare SV callable BED regions"; 88, identifier:utils; 89, identifier:splitext_plus; 90, call; 91, identifier:data; 92, identifier:out_file; 93, identifier:ref; 94, identifier:fasta_idx; 95, call; 96, string:"{gsort} {in_file} {fai_file} | bedtools merge -i - -d {stats[merge_size]} | "; 97, string:"bgzip -c > {tx_out_file}"; 98, attribute; 99, argument_list; 100, attribute; 101, argument_list; 102, attribute; 103, argument_list; 104, identifier:cmd; 105, identifier:format; 106, dictionary_splat; 107, attribute; 108, identifier:basename; 109, identifier:in_file; 110, identifier:dd; 111, identifier:get_ref_file; 112, identifier:data; 113, call; 114, identifier:os; 115, identifier:path; 116, identifier:locals; 117, argument_list
code: def _prep_callable_bed(in_file, work_dir, stats, data):
      """Sort and merge callable BED regions to prevent SV double counting
      """
      out_file = os.path.join(work_dir, "%s-merge.bed.gz" % utils.splitext_plus(os.path.basename(in_file))[0])
      gsort = config_utils.get_program("gsort", data)
      if not utils.file_uptodate(out_file, in_file):
          with file_transaction(data, out_file) as tx_out_file:
              fai_file = ref.fasta_idx(dd.get_ref_file(data))
              cmd = ("{gsort} {in_file} {fai_file} | bedtools merge -i - -d {stats[merge_size]} | "
                     "bgzip -c > {tx_out_file}")
              do.run(cmd.format(**locals()), "Prepare SV callable BED regions")
      return vcfutils.bgzip_and_index(out_file, data["config"])