def fom_saliency_mul(X, layer, alphabet, nntrainer, sess, ax, title='notitle'): ''' requires that deepomics is being used and the appropriate architecture has already been constructed Must first initialize the session and set best parameters layer is the activation layer we want to use as a string figsize is the figure size we want to use''' #first mutate the sequence X_mut = mutate(X, X.shape[1], X.shape[3]) #take all the mutations and assign them into a dict for deepomics mutations = {'inputs': X_mut, 'targets': np.ones((X_mut.shape[0], 1))} #Get output or logits activations for the mutations mut_predictions = nntrainer.get_activations(sess, mutations, layer=layer) #take the WT and put it into a dict for deepomics WT = {'inputs': X, 'targets': np.ones((X.shape[0], 1))} #Get output or logits activations for the WT sequence predictions = nntrainer.get_activations(sess, WT, layer=layer) #shape the predictions of the mutations into the shape of a heatmap heat_mut = mut_predictions.reshape(X.shape[1], 4).T #normalize the heat map rearrangement by minusing it by the true prediction score of that test sequence norm_heat_mut = heat_mut - predictions[0] norm_heat_mut = utils.normalize_pwm(norm_heat_mut, factor=4) visualize.plot_seq_pos_saliency(np.squeeze(X).T, norm_heat_mut, alphabet=alphabet, nt_width=400)
def fom_convsal(X, layer, alphabet, convidx, nntrainer, sess, title='notitle', figsize=(15, 2), fig=None, pos=None, idx=None): eps = 1e-7 #choose neuron coordinates within convolution output i2, i3, i4 = convidx #first mutate the sequence X_mut = mutate(X, X.shape[1], X.shape[3]) #take all the mutations and assign them into a dict for deepomics mutations = {'inputs': X_mut, 'targets': np.ones((X_mut.shape[0], 1))} #Get the neurons score for the mutations mut_scores = nntrainer.get_activations(sess, mutations, layer=layer)[:, i2, i3, i4] #take the WT and put it into a dict for deepomics WT = {'inputs': X, 'targets': np.ones((X.shape[0], 1))} #Get activations for the WT sequence WT_score = nntrainer.get_activations(sess, WT, layer=layer)[:, i2, i3, i4] #shape the predictions of the mutations into the shape of a heatmap heat_mut = mut_scores.reshape(X.shape[1], 4).T #normalize the heat map rearrangement by minusing it by the true prediction score of that test sequence norm_heat_mut = (heat_mut - WT_score) + eps norm_heat_mut = utils.normalize_pwm(norm_heat_mut, factor=4) if fig: row, col = pos ax = fig.add_subplot(row, col, idx) if title != 'notitle': ax.set_title(title) ax = visualize.plot_seq_pos_saliency(np.squeeze(X).T, norm_heat_mut, alphabet=alphabet, nt_width=400) else: plt.figure(figsize=figsize) if title != 'notitle': plt.title(title) visualize.plot_seq_pos_saliency(np.squeeze(X).T, norm_heat_mut, alphabet=alphabet, nt_width=400)