Thanks for your kind answer, I try your method to calculate the average length (result is 124.946, when I use samtools depth the result is 124.31), but it also not 125.What could cause this? And I also want to know if samtools depth can't calculate the inserted base?
Add: thanks geek_y, yes, we should consider clipping reads, it's the reason