Hi guys !

From a bam alignment file, I want to compute the ratio between the number of reads terminating and overlapping at all genomic positions (called *psi-ratio* in this figure). 

![image description][1]

For the number of reads overlapping, it's easy (its basically the coverage, given by `samtools depth` for instance), but for the reads terminating I'm a bit lost. I guess this has to do with the POS field of the sam/bam alignment (1-based leftmost mapping POSition) but I can't go much further than that... Any help or resource will be appreciated !

Subsidiary question : what if the input data is paired-end and I want the ratio between the **FRAGMENTS** terminating and overlapping ?


For those interested in why I want to do that, the idea is very similar to the recently described [psi-seq][2] : I want to detect positions on RNAs that blocks the reaction of reverse transcription during the library preparation.

Thanks a lot !


  [1]: http://i.imgur.com/WlQko3x.png
  [2]: http://www.ncbi.nlm.nih.gov/pubmed/25219674
>  for the reads terminating I'm a bit lost.

using **bioalcidae** : https://github.com/lindenb/jvarkit/wiki/BioAlcidae

```
$ java -jar dist/bioalcidae.jar input.bam \
    -e 'while(iter.hasNext()) { var rec = iter.next(); if(rec.getReadUnmappedFlag()) continue; out.println(rec.getContig()+"\t"+rec.getAlignmentEnd()); }'   | LC_ALL=C sort -k1,1 -k2,2n | LC_ALL=C  uniq -c 

      1 rotavirus	52
      1 rotavirus	56
      1 rotavirus	64
      1 rotavirus	66
      1 rotavirus	67
      2 rotavirus	68
      1 rotavirus	69
      6 rotavirus	70
      8 rotavirus	71
      5 rotavirus	72
      5 rotavirus	73
      7 rotavirus	74
      4 rotavirus	75
      6 rotavirus	76
      7 rotavirus	77
      5 rotavirus	78
      8 rotavirus	79
      3 rotavirus	80
     10 rotavirus	81
      4 rotavirus	82
      6 rotavirus	83
      7 rotavirus	84
      4 rotavirus	85
      3 rotavirus	86
     10 rotavirus	87
      5 rotavirus	88
      6 rotavirus	89
      4 rotavirus	90
      9 rotavirus	91
      7 rotavirus	92
      4 rotavirus	93
      1 rotavirus	94
      5 rotavirus	95
      5 rotavirus	96
      6 rotavirus	97
      7 rotavirus	98
      3 rotavirus	99
      4 rotavirus	100
(...)
```

you might use getUnclippedEnd instead of getAlignmentEnd if you want the unclipped alignments.
