def _insHelper(arg): (chunk, args) = arg try: ins = InsertionTrack(chunk.chrom, chunk.start, chunk.end) ins.calculateInsertions( args.bam, lower = args.lower, upper = args.upper, atac = args.atac) except Exception as e: print('Caught exception when processing:\n'+ chunk.asBed()+"\n") traceback.print_exc() print() raise e return ins
def test_ins_methods(self): """test that two methods for getting insertion track give same result""" ins1 = InsertionTrack(self.chunk.chrom, self.chunk.start, self.chunk.end) ins1.calculateInsertions("example/single_read.bam") mat = FragmentMat2D(self.chunk.chrom, self.chunk.start, self.chunk.end, 0, 100) mat.makeFragmentMat("example/single_read.bam") ins2 = mat.getIns() self.assertTrue( np.array_equal( ins1.get(self.chunk.start + 100, self.chunk.start + 300), ins2.get(self.chunk.start + 100, self.chunk.start + 300), ) )
def test_ins_methods(self): """test that two methods for getting insertion track give same result""" ins1 = InsertionTrack(self.chunk.chrom, self.chunk.start, self.chunk.end) ins1.calculateInsertions('example/single_read.bam') mat = FragmentMat2D(self.chunk.chrom, self.chunk.start, self.chunk.end, 0, 100) mat.makeFragmentMat('example/single_read.bam') ins2 = mat.getIns() self.assertTrue( np.array_equal( ins1.get(self.chunk.start + 100, self.chunk.start + 300), ins2.get(self.chunk.start + 100, self.chunk.start + 300)))
def _insHelperSmooth(arg): """Computes smoothed insertion track for a particular set of bed regions""" (chunk, args) = arg try: offset = args.smooth / 2 ins = InsertionTrack(chunk.chrom, chunk.start - offset, chunk.end + offset) ins.calculateInsertions( args.bam, lower = args.lower, upper = args.upper, atac = args.atac) ins.smooth_track(args.smooth, window = "gaussian", mode= 'valid') except Exception as e: print('Caught exception when processing:\n'+ chunk.asBed()+"\n") traceback.print_exc() print() raise e return ins
def _insHelper(arg): (chunk, args) = arg try: ins = InsertionTrack(chunk.chrom, chunk.start, chunk.end) ins.calculateInsertions(args.bam, lower=args.lower, upper=args.upper, atac=args.atac) except Exception as e: print('Caught exception when processing:\n' + chunk.asBed() + "\n") traceback.print_exc() print() raise e return ins
def getIns(self): """Collape matrix into insertions. Will reduce span on chromosome""" pattern = np.zeros( (self.upper - self.lower, self.upper + (self.upper - 1) % 2)) mid = self.upper / 2 for i in range(self.lower, self.upper): pattern[i - self.lower, mid + (i - 1) / 2] = 1 pattern[i - self.lower, mid - (i / 2)] = 1 ins = signal.correlate2d(self.mat, pattern, mode="valid")[0] insertion_track = InsertionTrack(self.chrom, self.start + pattern.shape[1] / 2, self.end - (pattern.shape[1] / 2)) insertion_track.assign_track(ins) return insertion_track
def _pwmHelper(arg): """"Helper function for multiprocessing acquisition of sequence around insertions""" (chunks, params) = arg try: n = 0.0 mat = np.zeros((len(params.nucleotides), params.up + params.down + 1)) for chunk in chunks: ins = InsertionTrack(chunk.chrom, chunk.start, chunk.end) if params.sym: ins.calculateInsertions(params.bam, lower=params.lower, upper=params.upper, atac=params.atac) mat += ins.getInsertionSequences(params.fasta, params.nucleotides, up=params.up, down=params.down) else: ins.calculateStrandedInsertions(params.bam, lower=params.lower, upper=params.upper, atac=params.atac) mat += ins.getStrandedInsertionSequences(params.fasta, params.nucleotides, up=params.up, down=params.down) n += sum(ins.vals) except Exception as e: print('Caught exception when processing:\n' + chunk.asBed() + "\n") traceback.print_exc() print() raise e return mat, n
def getIns(self): """gets insertion track-- reads in from bedgraph""" if self.params.ins_track is None: self.ins = InsertionTrack(self.chrom, self.start, self.end) self.ins.calculateInsertions(self.params.bam) else: self.ins = Track(self.chrom, self.start, self.end, "Insertion") self.ins.read_track(self.params.ins_track)
def _pwmHelper(arg): """"Helper function for multiprocessing acquisition of sequence around insertions""" (chunks, params) = arg try: n = 0.0 mat = np.zeros((len(params.nucleotides), params.up + params.down + 1)) for chunk in chunks: ins = InsertionTrack(chunk.chrom, chunk.start, chunk.end) if params.sym: ins.calculateInsertions( params.bam, lower = params.lower, upper = params.upper, atac = params.atac) mat += ins.getInsertionSequences(params.fasta, params.nucleotides, up = params.up, down = params.down) else: ins.calculateStrandedInsertions( params.bam, lower = params.lower, upper = params.upper, atac = params.atac) mat += ins.getStrandedInsertionSequences(params.fasta, params.nucleotides, up = params.up, down = params.down) n += sum(ins.vals) except Exception as e: print('Caught exception when processing:\n'+ chunk.asBed()+"\n") traceback.print_exc() print() raise e return mat, n
def _insHelperSmooth(arg): """Computes smoothed insertion track for a particular set of bed regions""" (chunk, args) = arg try: offset = args.smooth / 2 ins = InsertionTrack(chunk.chrom, chunk.start - offset, chunk.end + offset) ins.calculateInsertions(args.bam, lower=args.lower, upper=args.upper, atac=args.atac) ins.smooth_track(args.smooth, window="gaussian", mode='valid') except Exception as e: print('Caught exception when processing:\n' + chunk.asBed() + "\n") traceback.print_exc() print() raise e return ins