nodes: 0, module; 1, function_definition; 2, function_name:nt_counts; 3, parameters; 4, block; 5, identifier:bam; 6, identifier:positions; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, if_statement; 13, expression_statement; 14, for_statement; 15, expression_statement; 16, return_statement; 17, identifier:stranded; 18, False; 19, identifier:vcf; 20, False; 21, identifier:bed; 22, False; 23, comment:"""
      Find the number of nucleotides covered at all positions in a bed or vcf
      file.
  
      Parameters
      ----------
      bam : str or pysam.calignmentfile.AlignmentFile 
          Bam file opened with pysam or path to bam file (must
          be sorted and indexed).
      
      positions : str or pybedtools.BedTool
          Path to bed or vcf file or pybedtools.BedTool object. The extension is
          used to determine whether the file is a bed or vcf (.bed vs .vcf).
  
      stranded : boolean
          Boolean indicating whether read data is stranded and stranded nucleotide
          counts should be returned. Assumes R1 read on reverse strand implies +
          strand coverage etc.
  
      vcf : boolean
          Set to True if you are providing a vcf file that doesn't have a .vcf
          suffix.
  
      bed : boolean
          Set to True if you are providing a bed file that doesn't have a .bed
          suffix.
  
      Returns
      -------
      counts : pandas.DataFrame
          Data frame with the counts for each base in the region. The index of
          this data frame is one-based for compatibility with VCF files.
  
      """; 24, boolean_operator; 25, block; 26, identifier:bed; 27, block; 28, elif_clause; 29, assignment; 30, identifier:i; 31, attribute; 32, block; 33, assignment; 34, identifier:res; 35, not_operator; 36, not_operator; 37, if_statement; 38, expression_statement; 39, identifier:vcf; 40, block; 41, identifier:res; 42, list; 43, identifier:df; 44, identifier:index; 45, expression_statement; 46, expression_statement; 47, identifier:res; 48, call; 49, identifier:bed; 50, identifier:vcf; 51, comparison_operator:type(positions) == pbt.bedtool.BedTool; 52, block; 53, elif_clause; 54, elif_clause; 55, else_clause; 56, assignment; 57, import_from_statement; 58, expression_statement; 59, expression_statement; 60, expression_statement; 61, expression_statement; 62, expression_statement; 63, assignment; 64, call; 65, attribute; 66, argument_list; 67, call; 68, attribute; 69, expression_statement; 70, comparison_operator:positions[-4:] == '.bed'; 71, block; 72, comparison_operator:positions[-4:] == '.vcf'; 73, block; 74, block; 75, identifier:df; 76, call; 77, dotted_name; 78, dotted_name; 79, assignment; 80, assignment; 81, assignment; 82, assignment; 83, assignment; 84, identifier:region; 85, list; 86, attribute; 87, argument_list; 88, identifier:pd; 89, identifier:concat; 90, identifier:res; 91, identifier:type; 92, argument_list; 93, attribute; 94, identifier:BedTool; 95, assignment; 96, subscript; 97, string; 98, expression_statement; 99, subscript; 100, string; 101, expression_statement; 102, expression_statement; 103, attribute; 104, argument_list; 105, identifier:variants; 106, identifier:vcf_as_df; 107, identifier:tdf; 108, call; 109, identifier:df; 110, call; 111, subscript; 112, attribute; 113, subscript; 114, binary_operator:tdf.POS - 1; 115, subscript; 116, attribute; 117, subscript; 118, subscript; 119, subscript; 120, identifier:res; 121, identifier:append; 122, call; 123, identifier:positions; 124, identifier:pbt; 125, identifier:bedtool; 126, identifier:df; 127, call; 128, identifier:positions; 129, slice; 130, string_content:.bed; 131, assignment; 132, identifier:positions; 133, slice; 134, string_content:.vcf; 135, assignment; 136, call; 137, call; 138, identifier:to_dataframe; 139, identifier:vcf_as_df; 140, argument_list; 141, attribute; 142, argument_list; 143, identifier:df; 144, string; 145, identifier:tdf; 146, identifier:CHROM; 147, identifier:df; 148, string; 149, attribute; 150, integer:1; 151, identifier:df; 152, string; 153, identifier:tdf; 154, identifier:POS; 155, attribute; 156, identifier:i; 157, string; 158, attribute; 159, identifier:i; 160, string; 161, attribute; 162, identifier:i; 163, string; 164, identifier:get_region_nt_counts; 165, argument_list; 166, attribute; 167, argument_list; 168, unary_operator; 169, identifier:bed; 170, True; 171, unary_operator; 172, identifier:vcf; 173, True; 174, attribute; 175, argument_list; 176, attribute; 177, argument_list; 178, identifier:positions; 179, identifier:pd; 180, identifier:DataFrame; 181, keyword_argument; 182, string_content:chrom; 183, string_content:start; 184, identifier:tdf; 185, identifier:POS; 186, string_content:end; 187, identifier:df; 188, identifier:ix; 189, string_content:chrom; 190, identifier:df; 191, identifier:ix; 192, string_content:start; 193, identifier:df; 194, identifier:ix; 195, string_content:end; 196, identifier:region; 197, identifier:bam; 198, identifier:stranded; 199, identifier:positions; 200, identifier:to_dataframe; 201, integer:4; 202, integer:4; 203, attribute; 204, identifier:write; 205, concatenated_string; 206, identifier:pbt; 207, identifier:BedTool; 208, identifier:positions; 209, identifier:index; 210, attribute; 211, identifier:sys; 212, identifier:stderr; 213, string; 214, string; 215, identifier:tdf; 216, identifier:index; 217, string_content:Positions must be BedTool, bed file, or vcf; 218, string_content; 219, escape_sequence:\n
code: def nt_counts(bam, positions, stranded=False, vcf=False, bed=False):
      """
      Find the number of nucleotides covered at all positions in a bed or vcf
      file.
  
      Parameters
      ----------
      bam : str or pysam.calignmentfile.AlignmentFile 
          Bam file opened with pysam or path to bam file (must
          be sorted and indexed).
      
      positions : str or pybedtools.BedTool
          Path to bed or vcf file or pybedtools.BedTool object. The extension is
          used to determine whether the file is a bed or vcf (.bed vs .vcf).
  
      stranded : boolean
          Boolean indicating whether read data is stranded and stranded nucleotide
          counts should be returned. Assumes R1 read on reverse strand implies +
          strand coverage etc.
  
      vcf : boolean
          Set to True if you are providing a vcf file that doesn't have a .vcf
          suffix.
  
      bed : boolean
          Set to True if you are providing a bed file that doesn't have a .bed
          suffix.
  
      Returns
      -------
      counts : pandas.DataFrame
          Data frame with the counts for each base in the region. The index of
          this data frame is one-based for compatibility with VCF files.
  
      """
      if not bed and not vcf:
          if type(positions) == pbt.bedtool.BedTool:
              df = positions.to_dataframe()
          elif positions[-4:] == '.bed':
              bed = True
          elif positions[-4:] == '.vcf':
              vcf = True
          else:
              sys.stderr.write('Positions must be BedTool, bed file, or vcf '
                               'file.\n')
  
      if bed:
          df = pbt.BedTool(positions).to_dataframe()
      elif vcf:
          from variants import vcf_as_df
          tdf = vcf_as_df(positions)
          df = pd.DataFrame(index=tdf.index)
          df['chrom'] = tdf.CHROM
          df['start'] = tdf.POS - 1
          df['end'] = tdf.POS
  
      res = []
      for i in df.index:
          region = [df.ix[i, 'chrom'], df.ix[i, 'start'], df.ix[i, 'end']]
          res.append(get_region_nt_counts(region, bam, stranded))
      res = pd.concat(res)
      return res