Created
March 16, 2018 12:19
-
-
Save wdecoster/a2be73a676b68a9f92d07509e30d37a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pysam | |
| import sys | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| def main(bam): | |
| samfile = pysam.AlignmentFile(bam) | |
| ratios = np.array([indelratio(read.cigartuples) for read in samfile.fetch()]) | |
| n, bins, patches = plt.hist(ratios, bins=[i/10 for i in range(1,50, 1)]) | |
| plt.xlabel('indel ratio') | |
| plt.ylabel('reads') | |
| plt.savefig("Indelratio.png") | |
| print(np.median(ratios)) | |
| def indelratio(cigartuples): | |
| ins = sum([oplen for op, oplen in cigartuples if op == 1]) | |
| dels = sum([oplen for op, oplen in cigartuples if op == 2]) or 1 | |
| return ins/dels | |
| if __name__ == "__main__": | |
| main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment