nodes: 0, module; 1, function_definition; 2, function_name:make_feature_bed; 3, parameters; 4, block; 5, identifier:gtf; 6, identifier:feature; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, with_statement; 11, expression_statement; 12, comment:# We'll sort so bedtools operations can be done faster.; 13, expression_statement; 14, if_statement; 15, return_statement; 16, identifier:out; 17, None; 18, comment:"""
      Make a bed file with the start and stop coordinates for all of a particular
      feature in Gencode. Valid features are the features present in the third
      column of the Gencode GTF file.
  
      Parameters
      ----------
      gtf : str
          Filename of the Gencode gtf file.
  
      feature : str
          Feature from third column of Gencode GTF file. As of v19, these include
          CDS, exon, gene, Selenocysteine, start_codon, stop_codon, transcript,
          and UTR.
  
      out : str
          If provided, the bed file will be written to a file with this name.
  
      Returns
      -------
      bed : pybedtools.BedTool
          A sorted pybedtools BedTool object. 
  
      """; 19, assignment; 20, with_clause; 21, block; 22, assignment; 23, assignment; 24, identifier:out; 25, block; 26, identifier:bt; 27, identifier:bed_lines; 28, list; 29, with_item; 30, expression_statement; 31, while_statement; 32, identifier:bt; 33, call; 34, identifier:bt; 35, call; 36, expression_statement; 37, as_pattern; 38, assignment; 39, comparison_operator:line != ''; 40, block; 41, attribute; 42, argument_list; 43, attribute; 44, argument_list; 45, call; 46, call; 47, as_pattern_target; 48, identifier:line; 49, call; 50, identifier:line; 51, string; 52, if_statement; 53, expression_statement; 54, identifier:pbt; 55, identifier:BedTool; 56, call; 57, keyword_argument; 58, identifier:bt; 59, identifier:sort; 60, attribute; 61, argument_list; 62, identifier:open; 63, argument_list; 64, identifier:f; 65, attribute; 66, argument_list; 67, comparison_operator:line[0] != '#'; 68, block; 69, assignment; 70, attribute; 71, argument_list; 72, identifier:from_string; 73, True; 74, identifier:bt; 75, identifier:saveas; 76, identifier:out; 77, identifier:gtf; 78, call; 79, identifier:strip; 80, subscript; 81, string; 82, expression_statement; 83, if_statement; 84, identifier:line; 85, call; 86, string; 87, identifier:join; 88, identifier:bed_lines; 89, attribute; 90, argument_list; 91, identifier:line; 92, integer:0; 93, string_content:#; 94, assignment; 95, comparison_operator:line[2] == feature; 96, block; 97, attribute; 98, argument_list; 99, identifier:f; 100, identifier:readline; 101, identifier:line; 102, call; 103, subscript; 104, identifier:feature; 105, expression_statement; 106, expression_statement; 107, expression_statement; 108, if_statement; 109, expression_statement; 110, expression_statement; 111, call; 112, identifier:strip; 113, attribute; 114, argument_list; 115, identifier:line; 116, integer:2; 117, assignment; 118, assignment; 119, assignment; 120, comparison_operator:feature == 'gene'; 121, block; 122, else_clause; 123, assignment; 124, call; 125, attribute; 126, argument_list; 127, identifier:line; 128, identifier:split; 129, string; 130, identifier:chrom; 131, subscript; 132, identifier:start; 133, call; 134, identifier:end; 135, subscript; 136, identifier:feature; 137, string; 138, expression_statement; 139, comment:# TODO: I may want to have some smarter naming for; 140, comment:# things that aren't genes or transcripts.; 141, block; 142, identifier:strand; 143, subscript; 144, attribute; 145, argument_list; 146, identifier:f; 147, identifier:readline; 148, string_content; 149, identifier:line; 150, integer:0; 151, identifier:str; 152, argument_list; 153, identifier:line; 154, integer:4; 155, string_content:gene; 156, assignment; 157, expression_statement; 158, identifier:line; 159, integer:6; 160, identifier:bed_lines; 161, identifier:append; 162, binary_operator:'\t'.join([chrom, start, end, name, '.',
                                                  strand]) + '\n'; 163, escape_sequence:\t; 164, binary_operator:int(line[3]) - 1; 165, identifier:name; 166, call; 167, assignment; 168, call; 169, string; 170, call; 171, integer:1; 172, attribute; 173, argument_list; 174, identifier:name; 175, call; 176, attribute; 177, argument_list; 178, string_content; 179, identifier:int; 180, argument_list; 181, subscript; 182, identifier:strip; 183, string:'"'; 184, attribute; 185, argument_list; 186, string; 187, identifier:join; 188, list; 189, escape_sequence:\n; 190, subscript; 191, call; 192, integer:1; 193, subscript; 194, identifier:strip; 195, string:'"'; 196, string_content; 197, identifier:chrom; 198, identifier:start; 199, identifier:end; 200, identifier:name; 201, string; 202, identifier:strand; 203, identifier:line; 204, integer:3; 205, attribute; 206, argument_list; 207, call; 208, integer:2; 209, escape_sequence:\t; 210, string_content:.; 211, subscript; 212, identifier:split; 213, string; 214, attribute; 215, argument_list; 216, call; 217, integer:0; 218, string_content:; 219, subscript; 220, identifier:split; 221, string; 222, attribute; 223, argument_list; 224, call; 225, integer:1; 226, string_content:; 227, subscript; 228, identifier:split; 229, string; 230, attribute; 231, argument_list; 232, identifier:line; 233, integer:8; 234, string_content:;; 235, subscript; 236, identifier:split; 237, string; 238, identifier:line; 239, integer:8; 240, string_content:;
code: def make_feature_bed(gtf, feature, out=None):
      """
      Make a bed file with the start and stop coordinates for all of a particular
      feature in Gencode. Valid features are the features present in the third
      column of the Gencode GTF file.
  
      Parameters
      ----------
      gtf : str
          Filename of the Gencode gtf file.
  
      feature : str
          Feature from third column of Gencode GTF file. As of v19, these include
          CDS, exon, gene, Selenocysteine, start_codon, stop_codon, transcript,
          and UTR.
  
      out : str
          If provided, the bed file will be written to a file with this name.
  
      Returns
      -------
      bed : pybedtools.BedTool
          A sorted pybedtools BedTool object. 
  
      """
      bed_lines = []
      with open(gtf) as f:
          line = f.readline().strip()
          while line != '':
              if line[0] != '#':
                  line = line.split('\t')
                  if line[2] == feature:
                      chrom = line[0]
                      start = str(int(line[3]) - 1)
                      end = line[4]
                      if feature == 'gene':
                          name = line[8].split(';')[0].split(' ')[1].strip('"')
                      else:
                          # TODO: I may want to have some smarter naming for
                          # things that aren't genes or transcripts.
                          name = line[8].split(';')[1].split(' ')[2].strip('"')
                      strand = line[6]
                      bed_lines.append('\t'.join([chrom, start, end, name, '.',
                                                  strand]) + '\n')
              line = f.readline().strip()
      bt = pbt.BedTool(''.join(bed_lines), from_string=True)
      # We'll sort so bedtools operations can be done faster.
      bt = bt.sort()
      if out:
          bt.saveas(out)
      return bt