def __call_peaks_wo_control (self): """To call peaks w/o control data. """ #self.lambda_bg = float(self.scan_window)*self.treat.total/self.gsize #self.debug("#3 background lambda: %.2f " % (self.lambda_bg)) #self.min_tags = poisson_cdf_inv(1-pow(10,self.pvalue/-10),self.lambda_bg)+1 #self.debug("#3 min tags: %d" % (self.min_tags)) self.info("#3 shift treatment data") self.__shift_trackI(self.treat) self.info("#3 merge +/- strand of treatment data") self.treat.merge_plus_minus_locations_naive () self.debug("#3 after shift and merging, tags: %d" % (self.treat.total)) if self.opt.store_bdg: self.info("#3 save the shifted and merged tag counts into bedGraph file...") zbdg_write(self.treat,self.opt.wig_dir_tr,self.zwig_tr,self.d,log=self.info,single=self.opt.single_profile) elif self.opt.store_wig: self.info("#3 save the shifted and merged tag counts into wiggle file...") #if self.opt.wigextend: # zwig_write(self.treat,self.opt.wig_dir_tr,self.zwig_tr,self.opt.wigextend,log=self.info,space=self.opt.space,single=self.opt.single_profile) #else: zwig_write(self.treat,self.opt.wig_dir_tr,self.zwig_tr,self.d,log=self.info,space=self.opt.space,single=self.opt.single_profile) self.info("#3 call peak candidates") peak_candidates = self.__call_peaks_from_trackI (self.treat) self.info("#3 use self to calculate local lambda and filter peak candidates...") self.final_peaks = self.__filter_w_control(peak_candidates,self.treat,self.treat,pass_sregion=True) return self.final_peaks
def __call_peaks_wo_control(self): """To call peaks w/o control data. """ #self.lambda_bg = float(self.scan_window)*self.treat.total/self.gsize #self.debug("#3 background lambda: %.2f " % (self.lambda_bg)) #self.min_tags = poisson_cdf_inv(1-pow(10,self.pvalue/-10),self.lambda_bg)+1 #self.debug("#3 min tags: %d" % (self.min_tags)) self.info("#3 shift treatment data") self.__shift_trackI(self.treat) self.info("#3 merge +/- strand of treatment data") self.treat.merge_plus_minus_locations_naive() self.debug("#3 after shift and merging, tags: %d" % (self.treat.total)) if self.opt.store_bdg: self.info( "#3 save the shifted and merged tag counts into bedGraph file..." ) zbdg_write(self.treat, self.opt.wig_dir_tr, self.zwig_tr, self.d, log=self.info, single=self.opt.single_profile) elif self.opt.store_wig: self.info( "#3 save the shifted and merged tag counts into wiggle file..." ) #if self.opt.wigextend: # zwig_write(self.treat,self.opt.wig_dir_tr,self.zwig_tr,self.opt.wigextend,log=self.info,space=self.opt.space,single=self.opt.single_profile) #else: zwig_write(self.treat, self.opt.wig_dir_tr, self.zwig_tr, self.d, log=self.info, space=self.opt.space, single=self.opt.single_profile) self.info("#3 call peak candidates") peak_candidates = self.__call_peaks_from_trackI(self.treat) self.info( "#3 use self to calculate local lambda and filter peak candidates..." ) self.final_peaks = self.__filter_w_control(peak_candidates, self.treat, self.treat, pass_sregion=True) return self.final_peaks
def __call_peaks_w_control(self): """To call peaks with control data. A peak info type is a: dictionary key value: chromosome items: (peak start,peak end, peak length, peak summit, peak height, number of tags in peak region, peak pvalue, peak fold_enrichment) <-- tuple type """ #self.lambda_bg = float(self.scan_window)*self.treat.total/self.gsize #self.debug("#3 background lambda: %.2f " % (self.lambda_bg)) #self.min_tags = poisson_cdf_inv(1-pow(10,self.pvalue/-10),self.lambda_bg)+1 #self.debug("#3 min tags: %d" % (self.min_tags)) self.ratio_treat2control = float(self.treat.total) / self.control.total if self.ratio_treat2control > 2 or self.ratio_treat2control < 0.5: self.warn( "Treatment tags and Control tags are uneven! FDR may be wrong!" ) self.info("#3 shift treatment data") self.__shift_trackI(self.treat) self.info("#3 merge +/- strand of treatment data") self.treat.merge_plus_minus_locations_naive() self.debug("#3 after shift and merging, tags: %d" % (self.treat.total)) if self.opt.store_bdg: self.info( "#3 save the shifted and merged tag counts into bedGraph file..." ) zbdg_write(self.treat, self.opt.wig_dir_tr, self.zwig_tr, self.d, log=self.info, single=self.opt.single_profile) elif self.opt.store_wig: self.info( "#3 save the shifted and merged tag counts into wiggle file..." ) #if self.opt.wigextend: # zwig_write(self.treat,self.opt.wig_dir_tr,self.zwig_tr,self.opt.wigextend,log=self.info,space=self.opt.space,single=self.opt.single_profile) #else: zwig_write(self.treat, self.opt.wig_dir_tr, self.zwig_tr, self.d, log=self.info, space=self.opt.space, single=self.opt.single_profile) self.info("#3 call peak candidates") peak_candidates = self.__call_peaks_from_trackI(self.treat) self.info("#3 shift control data") self.info("#3 merge +/- strand of control data") self.__shift_trackI(self.control) self.control.merge_plus_minus_locations_naive() self.debug("#3 after shift and merging, tags: %d" % (self.control.total)) if self.opt.store_bdg: self.info( "#3 save the shifted and merged tag counts into bedGraph file..." ) zbdg_write(self.control, self.opt.wig_dir_ctl, self.zwig_ctl, self.d, log=self.info, single=self.opt.single_profile) if self.opt.store_wig: self.info( "#3 save the shifted and merged tag counts into wiggle file..." ) #if self.opt.wigextend: # zwig_write(self.control,self.opt.wig_dir_ctl,self.zwig_ctl,self.opt.wigextend,log=self.info,space=self.opt.space,single=self.opt.single_profile) #else: zwig_write(self.control, self.opt.wig_dir_ctl, self.zwig_ctl, self.d, log=self.info, space=self.opt.space, single=self.opt.single_profile) self.info("#3 call negative peak candidates") negative_peak_candidates = self.__call_peaks_from_trackI(self.control) # build score #if self.save_score: # self.info("#4 build scores") # scoreswig = self.__build_score_wigtrackI(treatwig,controlbkI,self.d,space=self.opt.space,bglambda=self.lambda_bg) # zwigfile = file(self.opt.name+".score.wig","w") # self.info("#4.1 save scores to wiggle file") # scoreswig.write_wig(zwigfile,"score") # self.info("compress the wiggle file using gzip...") # os.system("gzip "+self.opt.name+".score.wig") self.info("#3 use control data to filter peak candidates...") #self.final_peaks = self.__filter_w_control(peak_candidates,self.treat,self.control, self.ratio_treat2control,fake_when_missing=True) self.final_peaks = self.__filter_w_control( peak_candidates, self.treat, self.control, fake_when_missing=True, to_small_sample=self.opt.tosmall) self.info("#3 find negative peaks by swapping treat and control") #self.final_negative_peaks = self.__filter_w_control(negative_peak_candidates,self.control,self.treat, 1.0/self.ratio_treat2control,fake_when_missing=True) self.final_negative_peaks = self.__filter_w_control( negative_peak_candidates, self.control, self.treat, fake_when_missing=True, to_small_sample=self.opt.tosmall) return self.__add_fdr(self.final_peaks, self.final_negative_peaks)
def __call_peaks_w_control (self): """To call peaks with control data. A peak info type is a: dictionary key value: chromosome items: (peak start,peak end, peak length, peak summit, peak height, number of tags in peak region, peak pvalue, peak fold_enrichment) <-- tuple type """ #self.lambda_bg = float(self.scan_window)*self.treat.total/self.gsize #self.debug("#3 background lambda: %.2f " % (self.lambda_bg)) #self.min_tags = poisson_cdf_inv(1-pow(10,self.pvalue/-10),self.lambda_bg)+1 #self.debug("#3 min tags: %d" % (self.min_tags)) self.ratio_treat2control = float(self.treat.total)/self.control.total if self.ratio_treat2control > 2 or self.ratio_treat2control < 0.5: self.warn("Treatment tags and Control tags are uneven! FDR may be wrong!") self.info("#3 shift treatment data") self.__shift_trackI(self.treat) self.info("#3 merge +/- strand of treatment data") self.treat.merge_plus_minus_locations_naive () self.debug("#3 after shift and merging, tags: %d" % (self.treat.total)) if self.opt.store_bdg: self.info("#3 save the shifted and merged tag counts into bedGraph file...") zbdg_write(self.treat,self.opt.wig_dir_tr,self.zwig_tr,self.d,log=self.info,single=self.opt.single_profile) elif self.opt.store_wig: self.info("#3 save the shifted and merged tag counts into wiggle file...") #if self.opt.wigextend: # zwig_write(self.treat,self.opt.wig_dir_tr,self.zwig_tr,self.opt.wigextend,log=self.info,space=self.opt.space,single=self.opt.single_profile) #else: zwig_write(self.treat,self.opt.wig_dir_tr,self.zwig_tr,self.d,log=self.info,space=self.opt.space,single=self.opt.single_profile) self.info("#3 call peak candidates") peak_candidates = self.__call_peaks_from_trackI (self.treat) self.info("#3 shift control data") self.info("#3 merge +/- strand of control data") self.__shift_trackI(self.control) self.control.merge_plus_minus_locations_naive () self.debug("#3 after shift and merging, tags: %d" % (self.control.total)) if self.opt.store_bdg: self.info("#3 save the shifted and merged tag counts into bedGraph file...") zbdg_write(self.control,self.opt.wig_dir_ctl,self.zwig_ctl,self.d,log=self.info,single=self.opt.single_profile) if self.opt.store_wig: self.info("#3 save the shifted and merged tag counts into wiggle file...") #if self.opt.wigextend: # zwig_write(self.control,self.opt.wig_dir_ctl,self.zwig_ctl,self.opt.wigextend,log=self.info,space=self.opt.space,single=self.opt.single_profile) #else: zwig_write(self.control,self.opt.wig_dir_ctl,self.zwig_ctl,self.d,log=self.info,space=self.opt.space,single=self.opt.single_profile) self.info("#3 call negative peak candidates") negative_peak_candidates = self.__call_peaks_from_trackI (self.control) # build score #if self.save_score: # self.info("#4 build scores") # scoreswig = self.__build_score_wigtrackI(treatwig,controlbkI,self.d,space=self.opt.space,bglambda=self.lambda_bg) # zwigfile = file(self.opt.name+".score.wig","w") # self.info("#4.1 save scores to wiggle file") # scoreswig.write_wig(zwigfile,"score") # self.info("compress the wiggle file using gzip...") # os.system("gzip "+self.opt.name+".score.wig") self.info("#3 use control data to filter peak candidates...") #self.final_peaks = self.__filter_w_control(peak_candidates,self.treat,self.control, self.ratio_treat2control,fake_when_missing=True) self.final_peaks = self.__filter_w_control(peak_candidates,self.treat,self.control, fake_when_missing=True, to_small_sample=self.opt.tosmall) self.info("#3 find negative peaks by swapping treat and control") #self.final_negative_peaks = self.__filter_w_control(negative_peak_candidates,self.control,self.treat, 1.0/self.ratio_treat2control,fake_when_missing=True) self.final_negative_peaks = self.__filter_w_control(negative_peak_candidates,self.control,self.treat, fake_when_missing=True, to_small_sample=self.opt.tosmall) return self.__add_fdr (self.final_peaks, self.final_negative_peaks)