def compute_score_seq(seq,
                      score_matrix,
                      pval_mat,
                      min_score,
                      scale,
                      width,
                      offset):
    """
        Score a sequence using a processed motif scoring matrix
        ----
        Parameters:
            seq (str) : sequence to score
            score_matrix (np.ndarray) : scoring matrix
            pval_mat (np.ndarray) : matrix used to compute P-values
                                    using a DP-algorithm (Staden, 1994)
            min_score (int) : lowest score in the scoring matrix
            scale (int) : scale used during motif processing
            width (int) : motif width
            offset (int) : offset used during motif processing
        ----
        Returns:
            score (np.double) : sequence score
            pvalue (np.double) : sequence score P-value
    """

    score = 0

    seq_len = len(seq)
    assert seq_len == width

    # score the current sequence
    for i in range(width):
        nuc = seq[i]

        if nuc == 'N':
            score = min_score
            break  # we don't go further

        elif nuc == 'A' or nuc == 'a':
            score += score_matrix[0, i]
        elif nuc == 'C' or nuc == 'c':
            score += score_matrix[1, i]
        elif nuc == 'G' or nuc == 'g':
            score += score_matrix[2, i]
        elif nuc == 'T' or nuc == 't':
            score += score_matrix[3, i]
        # end if
    # end for

    assert score >= min_score

    # get the p-value for the obtained score
    tot = pval_mat.sum()
    pvalue = (pval_mat[score:].sum()) / tot

    # retrieve the log-likelihood score
    logodds = (score / scale) + (width * offset)
    score = logodds

    assert pvalue > 0
    assert pvalue <= 1

    return score, pvalue