def score_coded_seq_with_convolutional_filter( coded_seq, filt, direction): """Score coded sequence using the convolutional filter filt. input: coded_seq: hot-one encoded DNA sequence (Nx4) where N is the number of bases in the sequence. filt : the convolutional filter (e.g. pwm) to score the model with. direction: The direction to score the sequence in. FWD: score the forward sequence RC: score using the reverse complement of the filter MAX: score in both diretions, and then return the maximum score between the two directions returns : Nx(BS_len-seq_len+1) numpy array with binding sites scores """ assert direction in ScoreDirection.__slots__ if direction == ScoreDirection.FWD: return multichannel_convolve( np.fliplr(np.flipud(coded_seq)), filt, mode='valid') elif direction == ScoreDirection.RC: return multichannel_convolve( coded_seq, filt, mode='valid') elif direction == ScoreDirection.MAX: fwd_scores = multichannel_convolve( np.fliplr(np.flipud(coded_seq)), filt, mode='valid') rc_scores = multichannel_convolve( coded_seq, filt, mode='valid') # take the in-place maximum return np.maximum(fwd_scores, rc_scores, fwd_scores) assert False, 'Should be unreachable'
def score_coded_seq_with_convolutional_filter(coded_seq, filt): """Score coded sequence using the convolutional filter filt. input: coded_seq: hot-one encoded DNA sequence (Nx4) where N is the number of bases in the sequence. filt : the convolutional filter (e.g. pwm) to score the model with. returns : Nx(BS_len-seq_len+1) numpy array with binding sites scores """ return multichannel_convolve( np.fliplr(np.flipud(coded_seq)), filt, mode='valid')[::-1]