def _biasVplotHelper(arg): """function to make vplot for a particular set of bed regions """ (chunks, params) = arg mat = np.zeros((params.upper - params.lower, 2 * params.flank + 1)) for chunk in chunks: try: chunk.center() biastrack = InsertionBiasTrack( chunk.chrom, chunk.start - params.flank - 1 - (params.upper / 2), chunk.end + params.flank + params.upper / 2 + 1) if params.bg is not None: biastrack.read_track(params.bg, empty=0) else: biastrack.computeBias(params.fasta, params.chrs, params.pwm) biasmat = BiasMat2D(chunk.chrom, chunk.start - params.flank - 1, chunk.end + params.flank, params.lower, params.upper) biasmat.makeBiasMat(biastrack) biasmat.normByInsertDist(params.fragmentsizes) add = biasmat.get(start=chunk.start - params.flank, end=chunk.end + params.flank, flip=(chunk.strand == "-")) if params.scale: mat += add / np.sum(add) else: mat += add except Exception as e: print('Caught exception when processing:\n' + chunk.asBed() + "\n") traceback.print_exc() print() raise e return mat
def makeBiasMat(self): self.bias_mat = BiasMat2D(self.chrom, self.start - self.params.flank, self.end + self.params.flank, 0, self.params.upper) if self.params.fasta is not None: bias_track = InsertionBiasTrack(self.chrom, self.start - self.params.window - self.params.upper/2, self.end + self.params.window + self.params.upper/2 + 1, log = True) bias_track.computeBias(self.params.fasta, self.params.chrs, self.params.pwm) self.bias_mat.makeBiasMat(bias_track)
def getBias(self): """get bias""" self.bias = InsertionBiasTrack(self.chrom, self.start, self.end, log=True) if self.params.fasta is not None: self.bias.computeBias(self.params.fasta, self.params.chrs, self.params.pwm)
def setUp(self): """setup Test_BiasMat class with construction of a biasmat""" bed_list = ChunkList.read('example/example.bed') self.chunk = bed_list[0] self.biastrack = InsertionBiasTrack(self.chunk.chrom, self.chunk.start, self.chunk.end) self.biastrack.read_track('example/example.Scores.bedgraph.gz') self.biasmat = BiasMat2D(self.chunk.chrom, self.chunk.start + 100, self.chunk.end - 100, 100, 200) self.biasmat.makeBiasMat(self.biastrack)
def setUp(self): """ set up class for testing variance calculation for background signal """ bed_list = ChunkList.read('example/example.bed') chunk = bed_list[0] vmat = V.VMat.open('example/example.VMat') biastrack = InsertionBiasTrack(chunk.chrom, chunk.start, chunk.end) biastrack.read_track('example/example.Scores.bedgraph.gz') biasmat = BiasMat2D(chunk.chrom,chunk.start+200,chunk.end-200,100,250) biasmat.makeBiasMat(biastrack) self.signaldist = Nuc.SignalDistribution(chunk.start+300,vmat,biasmat,35)
def _biasHelper(arg): """Helper function to multiprocess computation of bias tracks""" (chunk, params) = arg try: bias = InsertionBiasTrack(chunk.chrom, chunk.start, chunk.end) bias.computeBias(params.fasta, params.chrs, params.pwm) except Exception as e: print(('Caught exception when processing:\n' + chunk.asBed() + "\n")) traceback.print_exc() print() raise e return bias
def makeBiasMat(self): self.bias_mat = BiasMat2D(self.chrom, self.start - self.params.window, self.end + self.params.window, 0, self.params.upper) bias_track = InsertionBiasTrack(self.chrom, self.start - self.params.window - self.params.upper/2, self.end + self.params.window + self.params.upper/2 + 1, log = True) if self.params.fasta is not None: bias_track.computeBias(self.params.fasta, self.params.chrs, self.params.pwm) self.bias_mat.makeBiasMat(bias_track) self.bias_mat_prenorm = BiasMat2D(self.chrom, self.start - self.params.window, self.end + self.params.window, 0, self.params.upper) self.bias_mat_prenorm.mat = copy(self.bias_mat.mat) self.bias_mat.normByInsertDist(self.params.fragmentsizes)