def align_conv_filters(model, input_seqs, m, train_ind):
    'Aligns the convolutional filters of a given scover model back\n    to the given input sequences at the given indices. \n    '
    import numpy as np
    import torch
    from tqdm import trange
    activation_seqs = input_seqs[train_ind]
    with torch.no_grad():
        model.eval()
        activations = model.conv_1(activation_seqs).cpu().detach().numpy().squeeze()
    n_seq = activation_seqs.shape[0]
    activation_seqs = activation_seqs.squeeze()
    seq_len = activation_seqs.shape[1]
    d = activations.shape[1]
    motifs_pfm_dict = dict()
    motifs_ppm_dict = dict()
    for filter_num in trange(d):
        curr_activation = activations[:, filter_num, :]
        seq_has_pos_vals = np.argwhere((np.amax(curr_activation, axis=1) > 0))[:, 0]
        if (seq_has_pos_vals.shape[0] > 10):
            per_seq_where_max_pos = np.argmax(curr_activation[seq_has_pos_vals], axis=1)
            curr_activation_seqs = activation_seqs[seq_has_pos_vals]
            curr_str_list = []
            for i in range(seq_has_pos_vals.shape[0]):
                curr_max = per_seq_where_max_pos[i]
                curr_str_list.append(curr_activation_seqs[i][curr_max:(curr_max + m)])
            sequence_array = np.stack(curr_str_list)
            sequence_array_summed = np.sum(sequence_array, axis=0)
            motifs_pfm_dict[str(filter_num)] = sequence_array_summed
            row_sums = np.sum(sequence_array_summed, axis=1)
            sequence_array_summed = np.nan_to_num((sequence_array_summed / row_sums[:, np.newaxis]))
            motifs_ppm_dict[str(filter_num)] = sequence_array_summed
    return (motifs_pfm_dict, motifs_ppm_dict)
Aligns the convolutional filters of a given scover model back
to the given input sequences at the given indices.
def align_conv_filters(model, input_seqs, m, train_ind):
    'Aligns the convolutional filters of a given scover model back\n    to the given input sequences at the given indices. \n    '
    import numpy as np
    import torch
    from tqdm import trange
    activation_seqs = input_seqs[train_ind]
    with torch.no_grad():
        model.eval()
        activations = model.conv_1(activation_seqs).cpu().detach().numpy().squeeze()
    n_seq = activation_seqs.shape[0]
    activation_seqs = activation_seqs.squeeze()
    seq_len = activation_seqs.shape[1]
    d = activations.shape[1]
    motifs_pfm_dict = dict()
    motifs_ppm_dict = dict()
    for filter_num in trange(d):
        curr_activation = activations[:, filter_num, :]
        seq_has_pos_vals = np.argwhere((np.amax(curr_activation, axis=1) > 0))[:, 0]
        if (seq_has_pos_vals.shape[0] > 10):
            per_seq_where_max_pos = np.argmax(curr_activation[seq_has_pos_vals], axis=1)
            curr_activation_seqs = activation_seqs[seq_has_pos_vals]
            curr_str_list = []
            for i in range(seq_has_pos_vals.shape[0]):
                curr_max = per_seq_where_max_pos[i]
                curr_str_list.append(curr_activation_seqs[i][curr_max:(curr_max + m)])
            sequence_array = np.stack(curr_str_list)
            sequence_array_summed = np.sum(sequence_array, axis=0)
            motifs_pfm_dict[str(filter_num)] = sequence_array_summed
            row_sums = np.sum(sequence_array_summed, axis=1)
            sequence_array_summed = np.nan_to_num((sequence_array_summed / row_sums[:, np.newaxis]))
            motifs_ppm_dict[str(filter_num)] = sequence_array_summed
    return (motifs_pfm_dict, motifs_ppm_dict)