nodes: 0, module; 1, function_definition; 2, function_name:sort_bamfile; 3, parameters; 4, block; 5, identifier:job; 6, identifier:bamfile; 7, identifier:sample_type; 8, identifier:univ_options; 9, identifier:samtools_options; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, return_statement; 21, comment:"""
      Sort `bamfile` using samtools
  
      :param toil.fileStore.FileID bamfile: fsID for the bam file
      :param str sample_type: Description of the sample to inject into the filename
      :param dict univ_options: Dict of universal options used by almost all tools
      :param dict samtools_options: Options specific to samtools
      :return: fsID for the sorted bamfile
      :rtype: toil.fileStore.FileID
      """; 22, assignment; 23, assignment; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, call; 29, call; 30, call; 31, call; 32, identifier:work_dir; 33, call; 34, identifier:in_bamfile; 35, call; 36, identifier:out_bamfile; 37, call; 38, identifier:input_files; 39, dictionary; 40, identifier:input_files; 41, call; 42, identifier:parameters; 43, list; 44, identifier:docker_call; 45, argument_list; 46, attribute; 47, argument_list; 48, attribute; 49, argument_list; 50, attribute; 51, argument_list; 52, attribute; 53, argument_list; 54, attribute; 55, argument_list; 56, attribute; 57, argument_list; 58, pair; 59, identifier:get_files_from_filestore; 60, argument_list; 61, string; 62, string; 63, call; 64, string; 65, string; 66, string; 67, string; 68, string; 69, call; 70, subscript; 71, keyword_argument; 72, keyword_argument; 73, keyword_argument; 74, keyword_argument; 75, keyword_argument; 76, attribute; 77, identifier:deleteGlobalFile; 78, identifier:bamfile; 79, attribute; 80, identifier:logToMaster; 81, binary_operator:'Ran samtools-sort on %s:%s successfully'
                                % (univ_options['patient'], sample_type); 82, attribute; 83, identifier:writeGlobalFile; 84, identifier:out_bamfile; 85, identifier:os; 86, identifier:getcwd; 87, string; 88, identifier:join; 89, list; 90, string; 91, identifier:join; 92, list; 93, identifier:in_bamfile; 94, identifier:bamfile; 95, identifier:job; 96, identifier:input_files; 97, identifier:work_dir; 98, keyword_argument; 99, string_content:sort; 100, string_content:-o; 101, identifier:docker_path; 102, argument_list; 103, string_content:-O; 104, string_content:bam; 105, string_content:-T; 106, string_content:temp_sorted; 107, string_content:-@; 108, identifier:str; 109, argument_list; 110, identifier:input_files; 111, identifier:in_bamfile; 112, identifier:tool; 113, string; 114, identifier:tool_parameters; 115, identifier:parameters; 116, identifier:work_dir; 117, identifier:work_dir; 118, identifier:dockerhub; 119, subscript; 120, identifier:tool_version; 121, subscript; 122, identifier:job; 123, identifier:fileStore; 124, identifier:job; 125, identifier:fileStore; 126, string; 127, tuple; 128, identifier:job; 129, identifier:fileStore; 130, identifier:sample_type; 131, string; 132, string_content:_; 133, identifier:sample_type; 134, string; 135, identifier:docker; 136, True; 137, identifier:out_bamfile; 138, subscript; 139, string_content:samtools; 140, identifier:univ_options; 141, string; 142, identifier:samtools_options; 143, string; 144, string_content:Ran samtools-sort on %s:%s successfully; 145, subscript; 146, identifier:sample_type; 147, string_content:.bam; 148, string_content:sorted.bam; 149, identifier:samtools_options; 150, string; 151, string_content:dockerhub; 152, string_content:version; 153, identifier:univ_options; 154, string; 155, string_content:n; 156, string_content:patient
code: def sort_bamfile(job, bamfile, sample_type, univ_options, samtools_options):
      """
      Sort `bamfile` using samtools
  
      :param toil.fileStore.FileID bamfile: fsID for the bam file
      :param str sample_type: Description of the sample to inject into the filename
      :param dict univ_options: Dict of universal options used by almost all tools
      :param dict samtools_options: Options specific to samtools
      :return: fsID for the sorted bamfile
      :rtype: toil.fileStore.FileID
      """
      work_dir = os.getcwd()
      in_bamfile = ''.join([sample_type, '.bam'])
      out_bamfile = '_'.join([sample_type, 'sorted.bam'])
      input_files = {
          in_bamfile: bamfile}
      input_files = get_files_from_filestore(job, input_files, work_dir, docker=True)
      parameters = ['sort',
                    '-o', docker_path(out_bamfile),
                    '-O', 'bam',
                    '-T', 'temp_sorted',
                    '-@', str(samtools_options['n']),
                    input_files[in_bamfile]]
      docker_call(tool='samtools', tool_parameters=parameters, work_dir=work_dir,
                  dockerhub=univ_options['dockerhub'], tool_version=samtools_options['version'])
      job.fileStore.deleteGlobalFile(bamfile)
      job.fileStore.logToMaster('Ran samtools-sort on %s:%s successfully'
                                % (univ_options['patient'], sample_type))
      return job.fileStore.writeGlobalFile(out_bamfile)