nodes: 0, module; 1, function_definition; 2, function_name:align_to_sort_bam; 3, parameters; 4, block; 5, identifier:fastq1; 6, identifier:fastq2; 7, identifier:aligner; 8, identifier:data; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, if_statement; 17, if_statement; 18, return_statement; 19, comment:"""Align to the named genome build, returning a sorted BAM file.
      """; 20, assignment; 21, assignment; 22, call; 23, block; 24, assignment; 25, assignment; 26, assignment; 27, call; 28, block; 29, else_clause; 30, boolean_operator; 31, block; 32, identifier:data; 33, identifier:names; 34, subscript; 35, identifier:align_dir_parts; 36, list; 37, attribute; 38, argument_list; 39, expression_statement; 40, identifier:aligner_index; 41, call; 42, identifier:align_dir; 43, call; 44, identifier:ref_file; 45, call; 46, attribute; 47, argument_list; 48, expression_statement; 49, block; 50, subscript; 51, call; 52, if_statement; 53, for_statement; 54, identifier:data; 55, string:"rgnames"; 56, subscript; 57, string:"align"; 58, subscript; 59, identifier:data; 60, identifier:get; 61, string:"disambiguate"; 62, call; 63, identifier:_get_aligner_index; 64, argument_list; 65, attribute; 66, argument_list; 67, attribute; 68, argument_list; 69, identifier:fastq1; 70, identifier:endswith; 71, string:".bam"; 72, assignment; 73, expression_statement; 74, identifier:data; 75, string:"work_bam"; 76, attribute; 77, argument_list; 78, boolean_operator; 79, comment:# If merging later with with bamsormadup need query sorted inputs; 80, comment:# but CWL requires a bai file. Create a fake one to make it happy.; 81, block; 82, else_clause; 83, identifier:extra; 84, list; 85, block; 86, subscript; 87, string:"work"; 88, identifier:names; 89, string:"sample"; 90, attribute; 91, argument_list; 92, identifier:aligner; 93, identifier:data; 94, identifier:utils; 95, identifier:safe_makedir; 96, call; 97, identifier:tz; 98, identifier:get_in; 99, tuple; 100, identifier:data; 101, identifier:data; 102, call; 103, assignment; 104, identifier:utils; 105, identifier:file_exists; 106, subscript; 107, call; 108, call; 109, expression_statement; 110, block; 111, string:"-sr"; 112, string:"-disc"; 113, expression_statement; 114, if_statement; 115, identifier:data; 116, string:"dirs"; 117, identifier:align_dir_parts; 118, identifier:append; 119, subscript; 120, attribute; 121, argument_list; 122, string:"reference"; 123, string:"fasta"; 124, string:"base"; 125, identifier:_align_from_bam; 126, argument_list; 127, identifier:data; 128, call; 129, identifier:data; 130, string:"work_bam"; 131, attribute; 132, argument_list; 133, attribute; 134, argument_list; 135, call; 136, expression_statement; 137, assignment; 138, call; 139, block; 140, subscript; 141, string:"genome_build"; 142, attribute; 143, identifier:join; 144, list_splat; 145, identifier:fastq1; 146, identifier:aligner; 147, identifier:aligner_index; 148, identifier:ref_file; 149, identifier:names; 150, identifier:align_dir; 151, identifier:data; 152, identifier:_align_from_fastq; 153, argument_list; 154, identifier:data; 155, identifier:get; 156, string:"align_split"; 157, identifier:dd; 158, identifier:get_mark_duplicates; 159, identifier:data; 160, attribute; 161, argument_list; 162, call; 163, identifier:extra_bam; 164, call; 165, attribute; 166, argument_list; 167, expression_statement; 168, identifier:data; 169, string:"disambiguate"; 170, identifier:os; 171, identifier:path; 172, identifier:align_dir_parts; 173, identifier:fastq1; 174, identifier:fastq2; 175, identifier:aligner; 176, identifier:aligner_index; 177, identifier:ref_file; 178, identifier:names; 179, identifier:align_dir; 180, identifier:data; 181, identifier:bam; 182, identifier:fake_index; 183, subscript; 184, identifier:data; 185, attribute; 186, argument_list; 187, attribute; 188, argument_list; 189, identifier:utils; 190, identifier:file_exists; 191, identifier:extra_bam; 192, call; 193, identifier:data; 194, string:"work_bam"; 195, identifier:bam; 196, identifier:index; 197, subscript; 198, subscript; 199, identifier:utils; 200, identifier:append_stem; 201, subscript; 202, identifier:extra; 203, attribute; 204, argument_list; 205, identifier:data; 206, string:"work_bam"; 207, identifier:data; 208, string:"config"; 209, identifier:data; 210, string; 211, identifier:bam; 212, identifier:index; 213, identifier:extra_bam; 214, subscript; 215, string_content:work_bam; 216, identifier:data; 217, string:"config"
code: def align_to_sort_bam(fastq1, fastq2, aligner, data):
      """Align to the named genome build, returning a sorted BAM file.
      """
      names = data["rgnames"]
      align_dir_parts = [data["dirs"]["work"], "align", names["sample"]]
      if data.get("disambiguate"):
          align_dir_parts.append(data["disambiguate"]["genome_build"])
      aligner_index = _get_aligner_index(aligner, data)
      align_dir = utils.safe_makedir(os.path.join(*align_dir_parts))
      ref_file = tz.get_in(("reference", "fasta", "base"), data)
      if fastq1.endswith(".bam"):
          data = _align_from_bam(fastq1, aligner, aligner_index, ref_file,
                                 names, align_dir, data)
      else:
          data = _align_from_fastq(fastq1, fastq2, aligner, aligner_index, ref_file,
                                   names, align_dir, data)
      if data["work_bam"] and utils.file_exists(data["work_bam"]):
          if data.get("align_split") and dd.get_mark_duplicates(data):
              # If merging later with with bamsormadup need query sorted inputs
              # but CWL requires a bai file. Create a fake one to make it happy.
              bam.fake_index(data["work_bam"], data)
          else:
              bam.index(data["work_bam"], data["config"])
          for extra in ["-sr", "-disc"]:
              extra_bam = utils.append_stem(data['work_bam'], extra)
              if utils.file_exists(extra_bam):
                  bam.index(extra_bam, data["config"])
      return data