def __init__(self, chrom, start, end, name="track", vals=None, log=False): Chunk.__init__(self, chrom, start, end, name=name) self.log = log if vals is None: self.vals = None elif len(vals) == self.length(): self.vals = vals else: raise Exception("Input vals must be of length as set by start and end!")
def __init__(self, chrom, start, end, name = "track", vals=None , log = False): Chunk.__init__(self, chrom, start, end, name = name) self.log = log if vals is None: self.vals = None elif len(vals) == self.length(): self.vals = vals else: raise Exception("Input vals must be of length as set by start and end!")
def slop(self, chromDict, up=0, down=0, new=False): """Modification of slop method for Chunk class to check if vals are set""" if self.vals is None: out = Chunk.slop(self, chromDict, up=up, down=down, new=new) return out else: raise Exception("Cannot slop Track if vals are set")
def getInsertionSequences(self, fasta, nucleotides = ["C","G","A","T"], up = 10, down = 10): """Get sequence content at insertions""" mat = np.zeros((len(nucleotides), up + down +1)) if np.sum(self.vals) == 0: return mat offset = max(up,down) seq_chunk = Chunk(self.chrom, self.start - offset, self.end + offset) sequence = get_sequence(seq_chunk, fasta) seq_mat = seq_to_mat(sequence, nucleotides) for i in range(self.length()): mat += self.vals[i] * seq_mat[:,(offset + i - up):(offset + i + down + 1)] return mat
def getStrandedInsertionSequences(self, fasta, nucleotides = ["C","G","A","T"], up = 10, down = 10): """Get sequence content at insertions, taking into account strand""" mat = np.zeros((len(nucleotides), up + down +1)) if np.sum(self.vals) == 0: return mat offset = max(up,down) seq_chunk = Chunk(self.chrom, self.start - offset, self.end + offset) sequence = get_sequence(seq_chunk, fasta) minus_sequence = complement(sequence) seq_mat = seq_to_mat(sequence, nucleotides) minus_seq_mat = seq_to_mat(minus_sequence, nucleotides) for i in range(self.length()): mat += self.plus[i] * seq_mat[:,(offset + i - up):(offset + i + down + 1)] mat += self.minus[i] * np.fliplr(minus_seq_mat[:,(offset + i - down):(offset + i + up + 1)]) return mat