nodes: 0, module; 1, function_definition; 2, function_name:_prep_vrn_file; 3, parameters; 4, block; 5, identifier:in_file; 6, identifier:vcaller; 7, identifier:work_dir; 8, identifier:somatic_info; 9, identifier:ignore_file; 10, identifier:config; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, if_statement; 15, return_statement; 16, comment:"""Create a variant file to feed into the PhyloWGS prep script, limiting records.
  
      Sorts by depth, adding top covered samples up to the sample_size supported
      by PhyloWGS. The logic is that the higher depth samples will have better
      resolution for frequency differences. More complex implementations could try
      to subset based on a distribution of frequencies to best sample the potential
      heterogeneity.
  
      Handles MuTect and VarDict as inputs to PhyloWGS.
  
      Fixes chromosome naming to use non chr-prefixed contigs, to match _prep_cnv_file.
      """; 17, call; 18, block; 19, elif_clause; 20, else_clause; 21, assignment; 22, not_operator; 23, block; 24, expression_list; 25, attribute; 26, argument_list; 27, expression_statement; 28, comparison_operator:vcaller == "mutect"; 29, block; 30, block; 31, identifier:out_file; 32, call; 33, call; 34, expression_statement; 35, with_statement; 36, identifier:variant_type; 37, identifier:out_file; 38, identifier:vcaller; 39, identifier:startswith; 40, string:"vardict"; 41, assignment; 42, identifier:vcaller; 43, string:"mutect"; 44, expression_statement; 45, raise_statement; 46, attribute; 47, argument_list; 48, attribute; 49, argument_list; 50, assignment; 51, with_clause; 52, block; 53, identifier:variant_type; 54, string:"vardict"; 55, assignment; 56, call; 57, attribute; 58, identifier:join; 59, identifier:work_dir; 60, binary_operator:"%s-%s-prep.vcf" % (utils.splitext_plus(os.path.basename(in_file))[0],
                                                            vcaller); 61, identifier:utils; 62, identifier:file_uptodate; 63, identifier:out_file; 64, identifier:in_file; 65, identifier:check_fn; 66, call; 67, with_item; 68, expression_statement; 69, comment:# Filter inputs; 70, with_statement; 71, with_statement; 72, comment:# Fix potential chromosome issues; 73, with_statement; 74, identifier:variant_type; 75, string:"mutect-smchet"; 76, identifier:ValueError; 77, argument_list; 78, identifier:os; 79, identifier:path; 80, string:"%s-%s-prep.vcf"; 81, tuple; 82, identifier:_min_sample_pass; 83, argument_list; 84, as_pattern; 85, assignment; 86, with_clause; 87, block; 88, with_clause; 89, block; 90, with_clause; 91, block; 92, binary_operator:"Unexpected variant caller for PhyloWGS prep: %s" % vcaller; 93, subscript; 94, identifier:vcaller; 95, identifier:ignore_file; 96, call; 97, as_pattern_target; 98, identifier:tx_out_file_raw; 99, binary_operator:"%s-raw%s" % utils.splitext_plus(tx_out_file); 100, with_item; 101, expression_statement; 102, expression_statement; 103, expression_statement; 104, with_item; 105, with_statement; 106, with_item; 107, with_statement; 108, string:"Unexpected variant caller for PhyloWGS prep: %s"; 109, identifier:vcaller; 110, call; 111, integer:0; 112, identifier:file_transaction; 113, argument_list; 114, identifier:tx_out_file; 115, string:"%s-raw%s"; 116, call; 117, as_pattern; 118, assignment; 119, call; 120, assignment; 121, as_pattern; 122, with_clause; 123, block; 124, as_pattern; 125, with_clause; 126, block; 127, attribute; 128, argument_list; 129, attribute; 130, identifier:out_file; 131, attribute; 132, argument_list; 133, call; 134, as_pattern_target; 135, identifier:depths; 136, list_comprehension; 137, attribute; 138, argument_list; 139, identifier:depth_thresh; 140, conditional_expression:depths[:config["sample_size"]][-1] if depths else 0; 141, call; 142, as_pattern_target; 143, with_item; 144, for_statement; 145, call; 146, as_pattern_target; 147, with_item; 148, for_statement; 149, identifier:utils; 150, identifier:splitext_plus; 151, call; 152, identifier:somatic_info; 153, identifier:tumor_data; 154, identifier:utils; 155, identifier:splitext_plus; 156, identifier:tx_out_file; 157, identifier:VariantFile; 158, argument_list; 159, identifier:bcf_in; 160, call; 161, for_in_clause; 162, identifier:depths; 163, identifier:sort; 164, keyword_argument; 165, subscript; 166, identifier:depths; 167, integer:0; 168, identifier:VariantFile; 169, argument_list; 170, identifier:bcf_in; 171, as_pattern; 172, identifier:rec; 173, identifier:bcf_in; 174, block; 175, identifier:open; 176, argument_list; 177, identifier:in_handle; 178, as_pattern; 179, identifier:line; 180, identifier:in_handle; 181, block; 182, attribute; 183, argument_list; 184, identifier:in_file; 185, identifier:_sample_depth; 186, argument_list; 187, identifier:rec; 188, call; 189, identifier:reverse; 190, True; 191, subscript; 192, unary_operator; 193, identifier:in_file; 194, call; 195, as_pattern_target; 196, if_statement; 197, identifier:tx_out_file_raw; 198, call; 199, as_pattern_target; 200, if_statement; 201, expression_statement; 202, attribute; 203, identifier:basename; 204, identifier:in_file; 205, identifier:rec; 206, attribute; 207, identifier:filter; 208, argument_list; 209, identifier:depths; 210, slice; 211, integer:1; 212, identifier:VariantFile; 213, argument_list; 214, identifier:bcf_out; 215, parenthesized_expression; 216, block; 217, identifier:open; 218, argument_list; 219, identifier:out_handle; 220, not_operator; 221, block; 222, call; 223, identifier:os; 224, identifier:path; 225, identifier:somatic_info; 226, identifier:tumor_name; 227, identifier:check_fn; 228, identifier:bcf_in; 229, subscript; 230, identifier:tx_out_file_raw; 231, string:"w"; 232, keyword_argument; 233, boolean_operator; 234, expression_statement; 235, identifier:tx_out_file; 236, string:"w"; 237, call; 238, expression_statement; 239, expression_statement; 240, expression_statement; 241, attribute; 242, argument_list; 243, identifier:config; 244, string:"sample_size"; 245, identifier:header; 246, attribute; 247, call; 248, parenthesized_expression; 249, call; 250, attribute; 251, argument_list; 252, assignment; 253, assignment; 254, assignment; 255, identifier:out_handle; 256, identifier:write; 257, identifier:line; 258, identifier:bcf_in; 259, identifier:header; 260, identifier:check_fn; 261, argument_list; 262, boolean_operator; 263, attribute; 264, argument_list; 265, identifier:line; 266, identifier:startswith; 267, string:"#"; 268, identifier:parts; 269, call; 270, subscript; 271, call; 272, identifier:line; 273, call; 274, identifier:rec; 275, comparison_operator:depth_thresh < 5; 276, comparison_operator:_sample_depth(rec, somatic_info.tumor_name) >= depth_thresh; 277, identifier:bcf_out; 278, identifier:write; 279, identifier:rec; 280, attribute; 281, argument_list; 282, identifier:parts; 283, integer:0; 284, identifier:_phylowgs_compatible_chroms; 285, argument_list; 286, attribute; 287, argument_list; 288, identifier:depth_thresh; 289, integer:5; 290, call; 291, identifier:depth_thresh; 292, identifier:line; 293, identifier:split; 294, string:"\t"; 295, subscript; 296, string:"\t"; 297, identifier:join; 298, identifier:parts; 299, identifier:_sample_depth; 300, argument_list; 301, identifier:parts; 302, integer:0; 303, identifier:rec; 304, attribute; 305, identifier:somatic_info; 306, identifier:tumor_name
code: def _prep_vrn_file(in_file, vcaller, work_dir, somatic_info, ignore_file, config):
      """Create a variant file to feed into the PhyloWGS prep script, limiting records.
  
      Sorts by depth, adding top covered samples up to the sample_size supported
      by PhyloWGS. The logic is that the higher depth samples will have better
      resolution for frequency differences. More complex implementations could try
      to subset based on a distribution of frequencies to best sample the potential
      heterogeneity.
  
      Handles MuTect and VarDict as inputs to PhyloWGS.
  
      Fixes chromosome naming to use non chr-prefixed contigs, to match _prep_cnv_file.
      """
      if vcaller.startswith("vardict"):
          variant_type = "vardict"
      elif vcaller == "mutect":
          variant_type = "mutect-smchet"
      else:
          raise ValueError("Unexpected variant caller for PhyloWGS prep: %s" % vcaller)
      out_file = os.path.join(work_dir, "%s-%s-prep.vcf" % (utils.splitext_plus(os.path.basename(in_file))[0],
                                                            vcaller))
      if not utils.file_uptodate(out_file, in_file):
          check_fn = _min_sample_pass(ignore_file)
          with file_transaction(somatic_info.tumor_data, out_file) as tx_out_file:
              tx_out_file_raw = "%s-raw%s" % utils.splitext_plus(tx_out_file)
              # Filter inputs
              with VariantFile(in_file) as bcf_in:
                  depths = [_sample_depth(rec, somatic_info.tumor_name) for rec in
                            filter(check_fn, bcf_in)]
                  depths.sort(reverse=True)
                  depth_thresh = depths[:config["sample_size"]][-1] if depths else 0
              with VariantFile(in_file) as bcf_in:
                  with VariantFile(tx_out_file_raw, "w", header=bcf_in.header) as bcf_out:
                      for rec in bcf_in:
                          if (check_fn(rec) and
                                (depth_thresh < 5 or _sample_depth(rec, somatic_info.tumor_name) >= depth_thresh)):
                              bcf_out.write(rec)
              # Fix potential chromosome issues
              with open(tx_out_file_raw) as in_handle:
                  with open(tx_out_file, "w") as out_handle:
                      for line in in_handle:
                          if not line.startswith("#"):
                              parts = line.split("\t")
                              parts[0] = _phylowgs_compatible_chroms(parts[0])
                              line = "\t".join(parts)
                          out_handle.write(line)
      return variant_type, out_file