bam_utils.py 539B

123456789101112131415161718
  1. from frst.dependences import pybam
  2. def parse_bam(bam_file):
  3. cov = {}
  4. cov_val = 0
  5. for alignment in pybam.read(bam_file):
  6. #pos 1 based (see Pybam doc)
  7. start_pos = alignment.sam_pos1
  8. end_pos = alignment.sam_pos1 + alignment.sam_block_size
  9. if start_pos not in cov:
  10. cov[start_pos] = 0
  11. if end_pos not in cov:
  12. cov[end_pos] = 0
  13. # add a weight on the start and lower on the end
  14. cov[start_pos] = cov_val +1
  15. cov[end_pos] = cov_val -1
  16. return cov