# How to deal with wildcards (N) in sequence logos

This is an open question that came to my mind recently, though it might be that it is not a common use case. The purpose is to find common patterns in a collection of sequences by representing the patterns as PSSMs. However, some of the bases have sequencing errors and are thus missing. Is there a way of integrating these missing bases in the PSSM calculation?

For a collection of sequences, deriving a sequence logo is relatively straightforward. For the case:

ACTAGCGT
ACGTACTC
ACGATCTC
ACGTCAGT


Taking the frequencies of each letter at each position would yield the following (pseudocount-corrected) Position Frequency Matrix:

      A       G     T       C
0  0.85  0.0375  0.05  0.0625
1  0.05  0.0375  0.05  0.8625
2  0.05  0.6375  0.25  0.0625
3  0.45  0.0375  0.45  0.0625
4  0.25  0.2375  0.25  0.2625
5  0.25  0.0375  0.05  0.6625
6  0.05  0.4375  0.45  0.0625
7  0.05  0.0375  0.45  0.4625


And by including background frequencies, we can derive the total Infomation Content for each position, and sum them up to compute the total Infomation Content of the matrix.

But what would happen if the analyzed sequences had experimented errors in the sequencing and some of the letters were missing?

ACNNGCGT
ACGTACTC
ACGATNTC
ACNTCAGT

• Would you consider N a new letter of the alphabet and follow the same procedure? (counting ocurrences per position, calculating background frequencies, include it in the sequence logo...)
• Would you ignore them and normalize each column's frequencies to the number of non-N bases?
• Would you penalize positions/sequences bearing N's when calculating the IC?
• Other?

I wanted to start with the case of N since it's the most generic wildcard, and therefore could be easier to address; but if you have ideas on incorporating other more specific wildcards, feel free to add it :)

Since the Position Frequency Matrix is an estimate for the probability to find a particular letter at each position, I think the best way to deal with sequencing errors that result in N is to ignore that base for that position and normalize based on the number of non-N bases.
If there is a position with a lot of Ns, though, you might get a biased estimate of the IC for that position - since using observed frequencies to estimate entropy/information is strongly biased when the number of observations is small.