nodes: 0, module; 1, function_definition; 2, function_name:bamsort_and_index; 3, parameters; 4, block; 5, identifier:job; 6, identifier:job_vars; 7, expression_statement; 8, comment:# Unpack variables; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, comment:# I/O; 13, expression_statement; 14, expression_statement; 15, comment:# Command -- second argument is "Output Prefix"; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, comment:# Write to FileStore; 21, expression_statement; 22, expression_statement; 23, comment:# Run child job; 24, expression_statement; 25, expression_statement; 26, return_statement; 27, comment:"""
      Sorts bam file and produces index file
  
      job_vars: tuple     Tuple of dictionaries: input_args and ids
      """; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, assignment; 35, call; 36, call; 37, assignment; 38, assignment; 39, assignment; 40, assignment; 41, expression_list; 42, pattern_list; 43, identifier:job_vars; 44, identifier:work_dir; 45, call; 46, identifier:sudo; 47, subscript; 48, identifier:rg_alignments; 49, call; 50, identifier:output; 51, call; 52, identifier:cmd1; 53, list; 54, identifier:cmd2; 55, list; 56, identifier:docker_call; 57, argument_list; 58, identifier:docker_call; 59, argument_list; 60, subscript; 61, call; 62, subscript; 63, call; 64, identifier:output_ids; 65, call; 66, identifier:rseq_id; 67, call; 68, identifier:rseq_id; 69, identifier:output_ids; 70, identifier:input_args; 71, identifier:ids; 72, attribute; 73, argument_list; 74, identifier:input_args; 75, string; 76, identifier:return_input_paths; 77, argument_list; 78, attribute; 79, argument_list; 80, string; 81, call; 82, call; 83, string; 84, call; 85, keyword_argument; 86, keyword_argument; 87, keyword_argument; 88, keyword_argument; 89, keyword_argument; 90, keyword_argument; 91, keyword_argument; 92, keyword_argument; 93, identifier:ids; 94, string; 95, attribute; 96, argument_list; 97, identifier:ids; 98, string; 99, attribute; 100, argument_list; 101, attribute; 102, argument_list; 103, attribute; 104, argument_list; 105, attribute; 106, identifier:getLocalTempDir; 107, string_content:sudo; 108, identifier:job; 109, identifier:work_dir; 110, identifier:ids; 111, string; 112, attribute; 113, identifier:join; 114, identifier:work_dir; 115, string; 116, string_content:sort; 117, identifier:docker_path; 118, argument_list; 119, identifier:docker_path; 120, argument_list; 121, string_content:index; 122, identifier:docker_path; 123, argument_list; 124, identifier:tool; 125, string; 126, identifier:tool_parameters; 127, identifier:cmd1; 128, identifier:work_dir; 129, identifier:work_dir; 130, identifier:sudo; 131, identifier:sudo; 132, identifier:tool; 133, string; 134, identifier:tool_parameters; 135, identifier:cmd2; 136, identifier:work_dir; 137, identifier:work_dir; 138, identifier:sudo; 139, identifier:sudo; 140, string_content:sorted.bam; 141, attribute; 142, identifier:writeGlobalFile; 143, identifier:output; 144, string_content:sorted.bam.bai; 145, attribute; 146, identifier:writeGlobalFile; 147, call; 148, call; 149, identifier:rv; 150, call; 151, identifier:rv; 152, identifier:job; 153, identifier:fileStore; 154, string_content:rg_alignments.bam; 155, identifier:os; 156, identifier:path; 157, string_content:sorted.bam; 158, identifier:rg_alignments; 159, string; 160, identifier:output; 161, string_content:quay.io/ucsc_cgl/samtools:0.1.19--dd5ac549b95eb3e5d166a5e310417ef13651994e; 162, string_content:quay.io/ucsc_cgl/samtools:0.1.19--dd5ac549b95eb3e5d166a5e310417ef13651994e; 163, identifier:job; 164, identifier:fileStore; 165, identifier:job; 166, identifier:fileStore; 167, attribute; 168, argument_list; 169, attribute; 170, argument_list; 171, attribute; 172, argument_list; 173, string_content:sorted; 174, attribute; 175, identifier:join; 176, identifier:work_dir; 177, string; 178, identifier:job; 179, identifier:addChildJobFn; 180, identifier:sort_bam_by_reference; 181, identifier:job_vars; 182, keyword_argument; 183, identifier:job; 184, identifier:addChildJobFn; 185, identifier:rseq_qc; 186, identifier:job_vars; 187, keyword_argument; 188, identifier:os; 189, identifier:path; 190, string_content:sorted.bam.bai; 191, identifier:disk; 192, string; 193, identifier:disk; 194, string; 195, string_content:50 G; 196, string_content:20 G
code: def bamsort_and_index(job, job_vars):
      """
      Sorts bam file and produces index file
  
      job_vars: tuple     Tuple of dictionaries: input_args and ids
      """
      # Unpack variables
      input_args, ids = job_vars
      work_dir = job.fileStore.getLocalTempDir()
      sudo = input_args['sudo']
      # I/O
      rg_alignments = return_input_paths(job, work_dir, ids, 'rg_alignments.bam')
      output = os.path.join(work_dir, 'sorted.bam')
      # Command -- second argument is "Output Prefix"
      cmd1 = ['sort', docker_path(rg_alignments), docker_path('sorted')]
      cmd2 = ['index', docker_path(output)]
      docker_call(tool='quay.io/ucsc_cgl/samtools:0.1.19--dd5ac549b95eb3e5d166a5e310417ef13651994e',
                  tool_parameters=cmd1, work_dir=work_dir, sudo=sudo)
      docker_call(tool='quay.io/ucsc_cgl/samtools:0.1.19--dd5ac549b95eb3e5d166a5e310417ef13651994e',
                  tool_parameters=cmd2, work_dir=work_dir, sudo=sudo)
      # Write to FileStore
      ids['sorted.bam'] = job.fileStore.writeGlobalFile(output)
      ids['sorted.bam.bai'] = job.fileStore.writeGlobalFile(os.path.join(work_dir, 'sorted.bam.bai'))
      # Run child job
      output_ids = job.addChildJobFn(sort_bam_by_reference, job_vars, disk='50 G').rv()
      rseq_id = job.addChildJobFn(rseq_qc, job_vars, disk='20 G').rv()
      return rseq_id, output_ids