I'm using the equation

    Num_Reads * Avg_Read_Length / Genome Size

To calculate coverage. Here are my questions

 1. Should I only consider mapped bases in the Query to calculate the read length? Specifically,  `M`,`=` tags in the CIGAR string? For example, if a read has `60M10S` for a CIGAR string, would the read length be 60 since 10 were not aligned properly? 

 2. Given 1. why is it that my calculation of coverage differs from `samtools mpileup`? Wouldn't the average of column 4 in mpileup output equal the average coverage? 

 Thanks for any help. 
1) yes M , = and even X

2) yes , ignore the clip

3) did you consider some options like:

      -Q, --min-BQ INT        skip bases with baseQ/BAQ smaller than INT [13]
      --ff, --excl-flags STR|INT  filter flags: skip reads with mask bits set
                                                [UNMAP,SECONDARY,QCFAIL,DUP]


what's the output of `samtools depth`
