nodes: 0, module; 1, function_definition; 2, function_name:apply_recal; 3, parameters; 4, block; 5, identifier:data; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, comment:# CWL does not have work/alignment BAM separation; 11, if_statement; 12, if_statement; 13, return_statement; 14, comment:"""Apply recalibration tables to the sorted aligned BAM, producing recalibrated BAM.
      """; 15, assignment; 16, assignment; 17, comparison_operator:dd.get_recalibrate(data) in [True, "gatk"]; 18, block; 19, elif_clause; 20, elif_clause; 21, boolean_operator; 22, block; 23, boolean_operator; 24, block; 25, identifier:data; 26, identifier:orig_bam; 27, boolean_operator; 28, identifier:had_work_bam; 29, comparison_operator:"work_bam" in data; 30, call; 31, list; 32, if_statement; 33, comparison_operator:dd.get_recalibrate(data) == "sentieon"; 34, block; 35, call; 36, block; 37, not_operator; 38, call; 39, expression_statement; 40, comparison_operator:orig_bam != dd.get_work_bam(data); 41, comparison_operator:orig_bam != dd.get_align_bam(data); 42, expression_statement; 43, call; 44, call; 45, string:"work_bam"; 46, identifier:data; 47, attribute; 48, argument_list; 49, True; 50, string:"gatk"; 51, call; 52, block; 53, call; 54, string:"sentieon"; 55, if_statement; 56, attribute; 57, argument_list; 58, raise_statement; 59, identifier:had_work_bam; 60, attribute; 61, argument_list; 62, assignment; 63, identifier:orig_bam; 64, call; 65, identifier:orig_bam; 66, call; 67, call; 68, attribute; 69, argument_list; 70, attribute; 71, argument_list; 72, identifier:dd; 73, identifier:get_recalibrate; 74, identifier:data; 75, attribute; 76, argument_list; 77, expression_statement; 78, expression_statement; 79, attribute; 80, argument_list; 81, call; 82, block; 83, identifier:dd; 84, identifier:get_recalibrate; 85, identifier:data; 86, call; 87, identifier:dd; 88, identifier:get_work_bam; 89, identifier:data; 90, subscript; 91, call; 92, attribute; 93, argument_list; 94, attribute; 95, argument_list; 96, attribute; 97, argument_list; 98, identifier:dd; 99, identifier:get_align_bam; 100, identifier:data; 101, identifier:dd; 102, identifier:get_work_bam; 103, identifier:data; 104, identifier:data; 105, identifier:get; 106, string:"prep_recal"; 107, call; 108, assignment; 109, identifier:dd; 110, identifier:get_recalibrate; 111, identifier:data; 112, attribute; 113, argument_list; 114, expression_statement; 115, expression_statement; 116, identifier:NotImplementedError; 117, argument_list; 118, identifier:data; 119, string:"align_bam"; 120, attribute; 121, argument_list; 122, identifier:dd; 123, identifier:get_work_bam; 124, identifier:data; 125, identifier:dd; 126, identifier:get_align_bam; 127, identifier:data; 128, identifier:utils; 129, identifier:save_diskspace; 130, identifier:orig_bam; 131, binary_operator:"BAM recalibrated to %s" % dd.get_work_bam(data); 132, subscript; 133, attribute; 134, argument_list; 135, subscript; 136, call; 137, identifier:data; 138, identifier:get; 139, string:"prep_recal"; 140, call; 141, assignment; 142, binary_operator:"Unsupported recalibration type: %s" % (dd.get_recalibrate(data)); 143, identifier:dd; 144, identifier:get_work_bam; 145, identifier:data; 146, string:"BAM recalibrated to %s"; 147, call; 148, identifier:data; 149, string:"config"; 150, identifier:logger; 151, identifier:info; 152, binary_operator:"Applying BQSR recalibration with GATK: %s " % str(dd.get_sample_name(data)); 153, identifier:data; 154, string:"work_bam"; 155, identifier:_gatk_apply_bqsr; 156, argument_list; 157, attribute; 158, argument_list; 159, subscript; 160, call; 161, string:"Unsupported recalibration type: %s"; 162, parenthesized_expression; 163, attribute; 164, argument_list; 165, string:"Applying BQSR recalibration with GATK: %s "; 166, call; 167, identifier:data; 168, identifier:logger; 169, identifier:info; 170, binary_operator:"Applying BQSR recalibration with sentieon: %s " % str(dd.get_sample_name(data)); 171, identifier:data; 172, string:"work_bam"; 173, attribute; 174, argument_list; 175, call; 176, identifier:dd; 177, identifier:get_work_bam; 178, identifier:data; 179, identifier:str; 180, argument_list; 181, string:"Applying BQSR recalibration with sentieon: %s "; 182, call; 183, identifier:sentieon; 184, identifier:apply_bqsr; 185, identifier:data; 186, attribute; 187, argument_list; 188, call; 189, identifier:str; 190, argument_list; 191, identifier:dd; 192, identifier:get_recalibrate; 193, identifier:data; 194, attribute; 195, argument_list; 196, call; 197, identifier:dd; 198, identifier:get_sample_name; 199, identifier:data; 200, attribute; 201, argument_list; 202, identifier:dd; 203, identifier:get_sample_name; 204, identifier:data
code: def apply_recal(data):
      """Apply recalibration tables to the sorted aligned BAM, producing recalibrated BAM.
      """
      orig_bam = dd.get_align_bam(data) or dd.get_work_bam(data)
      had_work_bam = "work_bam" in data
      if dd.get_recalibrate(data) in [True, "gatk"]:
          if data.get("prep_recal"):
              logger.info("Applying BQSR recalibration with GATK: %s " % str(dd.get_sample_name(data)))
              data["work_bam"] = _gatk_apply_bqsr(data)
      elif dd.get_recalibrate(data) == "sentieon":
          if data.get("prep_recal"):
              logger.info("Applying BQSR recalibration with sentieon: %s " % str(dd.get_sample_name(data)))
              data["work_bam"] = sentieon.apply_bqsr(data)
      elif dd.get_recalibrate(data):
          raise NotImplementedError("Unsupported recalibration type: %s" % (dd.get_recalibrate(data)))
      # CWL does not have work/alignment BAM separation
      if not had_work_bam and dd.get_work_bam(data):
          data["align_bam"] = dd.get_work_bam(data)
      if orig_bam != dd.get_work_bam(data) and orig_bam != dd.get_align_bam(data):
          utils.save_diskspace(orig_bam, "BAM recalibrated to %s" % dd.get_work_bam(data), data["config"])
      return data