Guest User

Untitled

a guest
Mar 25th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import pysam
  2. import sys
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5.  
  6. def main(bam):
  7. samfile = pysam.AlignmentFile(bam)
  8. ratios = np.array([indelratio(read.cigartuples) for read in samfile.fetch()])
  9. n, bins, patches = plt.hist(ratios, bins=[i/10 for i in range(1,50, 1)])
  10. plt.xlabel('indel ratio')
  11. plt.ylabel('reads')
  12. plt.savefig("Indelratio.png")
  13. print(np.median(ratios))
  14.  
  15.  
  16. def indelratio(cigartuples):
  17. ins = sum([oplen for op, oplen in cigartuples if op == 1])
  18. dels = sum([oplen for op, oplen in cigartuples if op == 2]) or 1
  19. return ins/dels
  20.  
  21.  
  22. if __name__ == "__main__":
  23. main(sys.argv[1])
Add Comment
Please, Sign In to add comment