nodes: 0, module; 1, function_definition; 2, function_name:alignment; 3, parameters; 4, block; 5, identifier:job; 6, identifier:ids; 7, identifier:input_args; 8, identifier:sample; 9, expression_statement; 10, expression_statement; 11, comment:# ids['bam'] = job.fileStore.getEmptyFileStoreID(); 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, comment:# I/O; 17, expression_statement; 18, comment:# Get fastqs associated with this sample; 19, for_statement; 20, comment:# Parameters for BWA and Bamsort; 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, comment:# Piping the output to a file handle; 25, with_statement; 26, with_statement; 27, comment:# Save in JobStore; 28, comment:# job.fileStore.updateGlobalFile(ids['bam'], os.path.join(work_dir, uuid + '.bam')); 29, expression_statement; 30, comment:# Copy file to S3; 31, if_statement; 32, comment:# Move file in output_dir; 33, if_statement; 34, comment:"""
      Runs BWA and then Bamsort on the supplied fastqs for this sample
  
      Input1: Toil Job instance
      Input2: jobstore id dictionary
      Input3: Input arguments dictionary
      Input4: Sample tuple -- contains uuid and urls for the sample
      """; 35, assignment; 36, assignment; 37, assignment; 38, assignment; 39, assignment; 40, call; 41, identifier:url; 42, identifier:urls; 43, block; 44, assignment; 45, assignment; 46, assignment; 47, with_clause; 48, block; 49, with_clause; 50, block; 51, assignment; 52, subscript; 53, block; 54, subscript; 55, block; 56, pattern_list; 57, identifier:sample; 58, identifier:work_dir; 59, call; 60, identifier:output_dir; 61, subscript; 62, identifier:key_path; 63, subscript; 64, identifier:cores; 65, call; 66, identifier:return_input_paths; 67, argument_list; 68, expression_statement; 69, identifier:docker_cmd; 70, list; 71, identifier:bwa_command; 72, binary_operator:["jvivian/bwa",
                     "mem",
                     "-R", "@RG\tID:{0}\tPL:Illumina\tSM:{0}\tLB:KapaHyper".format(uuid),
                     "-T", str(0),
                     "-t", str(cores),
                     "/data/ref.fa"] + [os.path.join('/data/',  os.path.basename(x)) for x in urls]; 73, identifier:bamsort_command; 74, list; 75, with_item; 76, expression_statement; 77, with_item; 78, expression_statement; 79, subscript; 80, call; 81, identifier:input_args; 82, string; 83, expression_statement; 84, identifier:input_args; 85, string; 86, expression_statement; 87, identifier:uuid; 88, identifier:urls; 89, attribute; 90, argument_list; 91, identifier:input_args; 92, string; 93, identifier:input_args; 94, string; 95, attribute; 96, argument_list; 97, identifier:job; 98, identifier:work_dir; 99, identifier:ids; 100, string; 101, string; 102, string; 103, string; 104, string; 105, string; 106, string; 107, call; 108, string; 109, string; 110, string; 111, string; 112, call; 113, list; 114, list_comprehension; 115, string:"jeltje/biobambam"; 116, string:"/usr/local/bin/bamsort"; 117, string:"inputformat=sam"; 118, string:"level=1"; 119, call; 120, call; 121, string:"calmdnm=1"; 122, string:"calmdnmrecompindetonly=1"; 123, string:"calmdnmreference=/data/ref.fa"; 124, call; 125, as_pattern; 126, call; 127, as_pattern; 128, call; 129, identifier:ids; 130, string; 131, attribute; 132, argument_list; 133, string_content:s3_dir; 134, call; 135, string_content:output_dir; 136, call; 137, attribute; 138, identifier:getLocalTempDir; 139, string_content:output_dir; 140, string_content:ssec; 141, identifier:multiprocessing; 142, identifier:cpu_count; 143, string_content:ref.fa; 144, string_content:ref.fa.amb; 145, string_content:ref.fa.ann; 146, string_content:ref.fa.bwt; 147, string_content:ref.fa.pac; 148, string_content:ref.fa.sa; 149, string_content:ref.fa.fai; 150, identifier:download_encrypted_file; 151, argument_list; 152, string_content:docker; 153, string_content:run; 154, string_content:--rm; 155, string_content:-v; 156, attribute; 157, argument_list; 158, string:"jvivian/bwa"; 159, string:"mem"; 160, string:"-R"; 161, call; 162, string:"-T"; 163, call; 164, string:"-t"; 165, call; 166, string:"/data/ref.fa"; 167, call; 168, for_in_clause; 169, attribute; 170, argument_list; 171, attribute; 172, argument_list; 173, attribute; 174, argument_list; 175, call; 176, as_pattern_target; 177, attribute; 178, argument_list; 179, call; 180, as_pattern_target; 181, attribute; 182, argument_list; 183, string_content:bam; 184, attribute; 185, identifier:writeGlobalFile; 186, call; 187, attribute; 188, argument_list; 189, identifier:move_to_output_dir; 190, argument_list; 191, identifier:job; 192, identifier:fileStore; 193, identifier:work_dir; 194, identifier:url; 195, identifier:key_path; 196, call; 197, string; 198, identifier:format; 199, identifier:work_dir; 200, attribute; 201, argument_list; 202, identifier:str; 203, argument_list; 204, identifier:str; 205, argument_list; 206, attribute; 207, argument_list; 208, identifier:x; 209, identifier:urls; 210, string:"inputthreads={}"; 211, identifier:format; 212, identifier:cores; 213, string:"outputthreads={}"; 214, identifier:format; 215, identifier:cores; 216, string:"I=/data/{}"; 217, identifier:format; 218, binary_operator:uuid + '.sam'; 219, identifier:open; 220, argument_list; 221, identifier:f_out; 222, identifier:subprocess; 223, identifier:check_call; 224, binary_operator:docker_cmd + bwa_command; 225, keyword_argument; 226, identifier:open; 227, argument_list; 228, identifier:f_out; 229, identifier:subprocess; 230, identifier:check_call; 231, binary_operator:docker_cmd + bamsort_command; 232, keyword_argument; 233, identifier:job; 234, identifier:fileStore; 235, attribute; 236, argument_list; 237, identifier:job; 238, identifier:addChildJobFn; 239, identifier:upload_bam_to_s3; 240, identifier:ids; 241, identifier:input_args; 242, identifier:sample; 243, keyword_argument; 244, keyword_argument; 245, keyword_argument; 246, identifier:work_dir; 247, identifier:output_dir; 248, keyword_argument; 249, keyword_argument; 250, attribute; 251, argument_list; 252, string_content:{}:/data; 253, string:"@RG\tID:{0}\tPL:Illumina\tSM:{0}\tLB:KapaHyper"; 254, identifier:format; 255, identifier:uuid; 256, integer:0; 257, identifier:cores; 258, attribute; 259, identifier:join; 260, string; 261, call; 262, identifier:uuid; 263, string; 264, call; 265, string; 266, identifier:docker_cmd; 267, identifier:bwa_command; 268, identifier:stdout; 269, identifier:f_out; 270, call; 271, string; 272, identifier:docker_cmd; 273, identifier:bamsort_command; 274, identifier:stdout; 275, identifier:f_out; 276, attribute; 277, identifier:join; 278, identifier:work_dir; 279, binary_operator:uuid + '.bam'; 280, identifier:cores; 281, integer:32; 282, identifier:memory; 283, string; 284, identifier:disk; 285, string; 286, identifier:uuid; 287, None; 288, identifier:files; 289, list; 290, attribute; 291, identifier:basename; 292, identifier:url; 293, identifier:os; 294, identifier:path; 295, string_content:/data/; 296, attribute; 297, argument_list; 298, string_content:.sam; 299, attribute; 300, argument_list; 301, string_content:w; 302, attribute; 303, argument_list; 304, string_content:w; 305, identifier:os; 306, identifier:path; 307, identifier:uuid; 308, string; 309, string_content:20 G; 310, string_content:30 G; 311, binary_operator:uuid + '.bam'; 312, identifier:os; 313, identifier:path; 314, attribute; 315, identifier:basename; 316, identifier:x; 317, attribute; 318, identifier:join; 319, identifier:work_dir; 320, binary_operator:uuid + '.sam'; 321, attribute; 322, identifier:join; 323, identifier:work_dir; 324, binary_operator:uuid + '.bam'; 325, string_content:.bam; 326, identifier:uuid; 327, string; 328, identifier:os; 329, identifier:path; 330, identifier:os; 331, identifier:path; 332, identifier:uuid; 333, string; 334, identifier:os; 335, identifier:path; 336, identifier:uuid; 337, string; 338, string_content:.bam; 339, string_content:.sam; 340, string_content:.bam
code: def alignment(job, ids, input_args, sample):
      """
      Runs BWA and then Bamsort on the supplied fastqs for this sample
  
      Input1: Toil Job instance
      Input2: jobstore id dictionary
      Input3: Input arguments dictionary
      Input4: Sample tuple -- contains uuid and urls for the sample
      """
      uuid, urls = sample
      # ids['bam'] = job.fileStore.getEmptyFileStoreID()
      work_dir = job.fileStore.getLocalTempDir()
      output_dir = input_args['output_dir']
      key_path = input_args['ssec']
      cores = multiprocessing.cpu_count()
  
      # I/O
      return_input_paths(job, work_dir, ids, 'ref.fa', 'ref.fa.amb', 'ref.fa.ann',
                                                       'ref.fa.bwt', 'ref.fa.pac', 'ref.fa.sa', 'ref.fa.fai')
      # Get fastqs associated with this sample
      for url in urls:
          download_encrypted_file(work_dir, url, key_path, os.path.basename(url))
  
      # Parameters for BWA and Bamsort
      docker_cmd = ['docker', 'run', '--rm', '-v', '{}:/data'.format(work_dir)]
  
      bwa_command = ["jvivian/bwa",
                     "mem",
                     "-R", "@RG\tID:{0}\tPL:Illumina\tSM:{0}\tLB:KapaHyper".format(uuid),
                     "-T", str(0),
                     "-t", str(cores),
                     "/data/ref.fa"] + [os.path.join('/data/',  os.path.basename(x)) for x in urls]
  
      bamsort_command = ["jeltje/biobambam",
                         "/usr/local/bin/bamsort",
                         "inputformat=sam",
                         "level=1",
                         "inputthreads={}".format(cores),
                         "outputthreads={}".format(cores),
                         "calmdnm=1",
                         "calmdnmrecompindetonly=1",
                         "calmdnmreference=/data/ref.fa",
                         "I=/data/{}".format(uuid + '.sam')]
      # Piping the output to a file handle
      with open(os.path.join(work_dir, uuid + '.sam'), 'w') as f_out:
          subprocess.check_call(docker_cmd + bwa_command, stdout=f_out)
  
      with open(os.path.join(work_dir, uuid + '.bam'), 'w') as f_out:
          subprocess.check_call(docker_cmd + bamsort_command, stdout=f_out)
  
      # Save in JobStore
      # job.fileStore.updateGlobalFile(ids['bam'], os.path.join(work_dir, uuid + '.bam'))
      ids['bam'] = job.fileStore.writeGlobalFile(os.path.join(work_dir, uuid + '.bam'))
      # Copy file to S3
      if input_args['s3_dir']:
          job.addChildJobFn(upload_bam_to_s3, ids, input_args, sample, cores=32, memory='20 G', disk='30 G')
      # Move file in output_dir
      if input_args['output_dir']:
          move_to_output_dir(work_dir, output_dir, uuid=None, files=[uuid + '.bam'])