def compute_fragments_statistics(settings, limit=None): ''' ''' sam_file = settings["sam_file"] image_file = settings["image_file"] lengths = defaultdict(int) zeros = 0 if not limit: print "Process full SAM file..." else: print "Process %s lines from SAM file..." % limit for i, sam_obj in enumerate(sc_sam_reader(sam_file)): print i, "\r", if limit and i > limit: break if sam_obj.TLEN > 0: lengths[sam_obj.TLEN] += 1 else: zeros += 1 keys = lengths.keys() keys.sort() for k in keys: print k, lengths[k], round(100.*lengths[k]/i, 3) print "Write image to %s" % image_file draw_distribution_plot(lengths, image_file) print "Fragments of zero length: %s" % zeros
def main(settings, limit=None): ''' ''' sam_file = settings["sam_file"] results = defaultdict(int) for i, sam_obj in enumerate(sc_sam_reader(sam_file)): results[sam_obj.FLAG] += 1 print results, "\r", print print "results", results
def main(settings, limit=None): ''' ''' sam_file = settings["sam_file"] output_file = settings["output_file"] unmapped = 0 with open(output_file, "w") as fh: for i, sam_obj in enumerate(sc_sam_reader(sam_file)): if sam_obj.RNAME == "*": fh.write(sam_obj.as_sam()) unmapped += 1 print i, unmapped, "\r", print print "Unmapped fraction:", float(unmapped)/(i+1)