nodes: 0, module; 1, function_definition; 2, function_name:picard_prep; 3, parameters; 4, block; 5, identifier:in_bam; 6, identifier:names; 7, identifier:ref_file; 8, identifier:dirs; 9, identifier:data; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, if_statement; 16, expression_statement; 17, expression_statement; 18, return_statement; 19, comment:"""Prepare input BAM using Picard and GATK cleaning tools.
  
      - ReorderSam to reorder file to reference
      - AddOrReplaceReadGroups to add read group information and coordinate sort
      - PrintReads to filters to remove problem records:
      - filterMBQ to remove reads with mismatching bases and base qualities
      """; 20, assignment; 21, assignment; 22, call; 23, assignment; 24, not_operator; 25, block; 26, assignment; 27, assignment; 28, call; 29, identifier:runner; 30, call; 31, identifier:work_dir; 32, call; 33, attribute; 34, argument_list; 35, identifier:reorder_bam; 36, call; 37, call; 38, expression_statement; 39, identifier:reorder_bam; 40, call; 41, identifier:rg_bam; 42, call; 43, identifier:_filter_bad_reads; 44, argument_list; 45, attribute; 46, argument_list; 47, attribute; 48, argument_list; 49, identifier:runner; 50, identifier:run_fn; 51, string:"picard_index_ref"; 52, identifier:ref_file; 53, attribute; 54, argument_list; 55, attribute; 56, argument_list; 57, assignment; 58, attribute; 59, argument_list; 60, attribute; 61, argument_list; 62, identifier:rg_bam; 63, identifier:ref_file; 64, identifier:data; 65, identifier:broad; 66, identifier:runner_from_path; 67, string:"picard"; 68, subscript; 69, identifier:utils; 70, identifier:safe_makedir; 71, call; 72, attribute; 73, identifier:join; 74, identifier:work_dir; 75, binary_operator:"%s-reorder.bam" %
                                 os.path.splitext(os.path.basename(in_bam))[0]; 76, identifier:utils; 77, identifier:file_exists; 78, identifier:reorder_bam; 79, identifier:reorder_bam; 80, call; 81, identifier:runner; 82, identifier:run_fn; 83, string:"picard_reorder"; 84, identifier:in_bam; 85, identifier:ref_file; 86, identifier:reorder_bam; 87, identifier:runner; 88, identifier:run_fn; 89, string:"picard_fix_rgs"; 90, identifier:reorder_bam; 91, identifier:names; 92, identifier:data; 93, string:"config"; 94, attribute; 95, argument_list; 96, identifier:os; 97, identifier:path; 98, string:"%s-reorder.bam"; 99, subscript; 100, attribute; 101, argument_list; 102, attribute; 103, identifier:join; 104, subscript; 105, string:"bamclean"; 106, subscript; 107, call; 108, integer:0; 109, attribute; 110, identifier:join; 111, identifier:work_dir; 112, binary_operator:"%s-reorder.bam" % dd.get_sample_name(data); 113, identifier:os; 114, identifier:path; 115, identifier:dirs; 116, string:"work"; 117, identifier:names; 118, string:"sample"; 119, attribute; 120, argument_list; 121, identifier:os; 122, identifier:path; 123, string:"%s-reorder.bam"; 124, call; 125, attribute; 126, identifier:splitext; 127, call; 128, attribute; 129, argument_list; 130, identifier:os; 131, identifier:path; 132, attribute; 133, argument_list; 134, identifier:dd; 135, identifier:get_sample_name; 136, identifier:data; 137, attribute; 138, identifier:basename; 139, identifier:in_bam; 140, identifier:os; 141, identifier:path
code: def picard_prep(in_bam, names, ref_file, dirs, data):
      """Prepare input BAM using Picard and GATK cleaning tools.
  
      - ReorderSam to reorder file to reference
      - AddOrReplaceReadGroups to add read group information and coordinate sort
      - PrintReads to filters to remove problem records:
      - filterMBQ to remove reads with mismatching bases and base qualities
      """
      runner = broad.runner_from_path("picard", data["config"])
      work_dir = utils.safe_makedir(os.path.join(dirs["work"], "bamclean", names["sample"]))
      runner.run_fn("picard_index_ref", ref_file)
      reorder_bam = os.path.join(work_dir, "%s-reorder.bam" %
                                 os.path.splitext(os.path.basename(in_bam))[0])
      if not utils.file_exists(reorder_bam):
          reorder_bam = os.path.join(work_dir, "%s-reorder.bam" % dd.get_sample_name(data))
      reorder_bam = runner.run_fn("picard_reorder", in_bam, ref_file, reorder_bam)
      rg_bam = runner.run_fn("picard_fix_rgs", reorder_bam, names)
      return _filter_bad_reads(rg_bam, ref_file, data)