def main(segfn, bedfn, outfn, pval=0.5): mysegs=sgh.read_in_segs(segfn) # get rid of chr if necessary, for s in mysegs: s.chr = s.chr.replace("chr", "") mysegs=sorted(mysegs, key=lambda x: (x.chr, x.start, x.end)) outfh=open(outfn, 'w') outfh.write("chr\tstart\tend\tname\tLtotal\tLmax\tpreval\tprevalsd\n") for l in open(bedfn, 'r'): bed=bedmod.BedEntry(l) seghist=get_best_overlapping_seghist(bed, mysegs) if seghist != 0: CNprofiles=seghist.CNprofiles ltot=get_total_likelihood(CNprofiles) else: ltot=0 if ltot > pval: bestCN=sorted(CNprofiles, key=lambda x: x.likelihood, reverse=True)[0] mypreval=bestCN.pvals[0] myprevalsd=bestCN.pvalsd[0] mylscore=bestCN.likelihood else: (mypreval, myprevalsd, mylscore)=(0,0, 0) outfh.write("\t".join(map(str, [ bed.chr, bed.start, bed.end, bed.name, ltot, mylscore, mypreval, myprevalsd]))+"\n")
def main(segfn, bedfn, outfn, pval=0.5): mysegs = sgh.read_in_segs(segfn) # get rid of chr if necessary, for s in mysegs: s.chr = s.chr.replace("chr", "") mysegs = sorted(mysegs, key=lambda x: (x.chr, x.start, x.end)) outfh = open(outfn, 'w') outfh.write("chr\tstart\tend\tname\tLtotal\tLmax\tpreval\tprevalsd\n") for l in open(bedfn, 'r'): bed = bedmod.BedEntry(l) seghist = get_best_overlapping_seghist(bed, mysegs) if seghist != 0: CNprofiles = seghist.CNprofiles ltot = get_total_likelihood(CNprofiles) else: ltot = 0 if ltot > pval: bestCN = sorted(CNprofiles, key=lambda x: x.likelihood, reverse=True)[0] mypreval = bestCN.pvals[0] myprevalsd = bestCN.pvalsd[0] mylscore = bestCN.likelihood else: (mypreval, myprevalsd, mylscore) = (0, 0, 0) outfh.write("\t".join( map(str, [ bed.chr, bed.start, bed.end, bed.name, ltot, mylscore, mypreval, myprevalsd ])) + "\n")
def main(segfn, bedfn, useall, outfn): mysegs=sgh.read_in_segs(segfn) for s in mysegs: s.chr = s.chr.replace("chr", "") mysegs=sorted(mysegs, key=lambda x: (x.chr, x.start, x.end)) mybeds=read_in_bedfile(bedfn) bestsegs=[] outfh=open(outfn, 'w') for s in mysegs: label=label_segment(s, mybeds) if not useall: CNprofs=s.CNprofiles bestcnp=sorted(CNprofs, key=lambda x: x.likelihood, reverse=True)[0] s.CNprofiles=[bestcnp] outstr="" for line in str(s).split("\n"): if line !="": outstr+=line.strip() + "\t"+label+"\n" outfh.write(outstr) outfh.close()