# Calculating conditional probability from a query protein sequence

We know there are 20 Amino Acids('A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y').

Now my query sequence is like: KAQTAHIVLEDGTKMKGYSFGHPSSVA of length 27 and "K" is in the center of the sequence. That means 13 amino acids are at the left of K and the other 13 are at the right of K.

It can be represented as: P(K)=R-13R-12R-11R-10R-9R-8R-7R-6R-5R-4R-3R-2R-1KR+1R+2R+3R+4R+5R+6R+7R+8R+9R+10R+11R+12R+13.

Where "-" notation is for left and "+" notation is for right.

Now what is the conditional probability of R-13 given that its closest neighbor is R-12? I mean P-13(R-13|R-12)=?

And what is the non conditional probability of R-1? or P-1(R-1)=?

I am confused at this point as I can not understand how to calculate the probability in this case. And it would be very helpful if anyone provided me python code for calculating conditional probability mentioned above.

I have done the same thing before, you should be able to find the approach from bioinformatics books. But here I will give some simple solution, which might not the approach you should take but it's just a hint of where you should look into.

The non-conditional probability of certain amino acid, you would think it should be 1/20, which is not the case. Since the distribution of the 20 amino acids in a certain family or just certain protein are not equally distributed, so you can use the frequency approach if you know the sequence(s). This is because the secondary structures are very specific for certain amino acids, for example, Proline should have a low frequency, therefore has a low probability in general.

So the formula for non-condition is $$P=\frac{count}{total\ count}$$

Similarly, for the conditional probability of $$R_{-13}$$ given that its closest neighbor is $$R_{-12}$$, you should also do the calculation. basically find the count of all the pairs that have X-$$R_{-12}$$ (total count), then count of $$R_{-13}$$-$$R_{-12}$$:

$$P_{R_{-13}|R_{-12}} = \frac{count\ (R_{-13}R_{-12})}{count\ (XR_{-12})}$$

Yes, you will have a huge table for a certain family, and if you look into Bioinformatics And Functional Genomics (https://www.amazon.com/Bioinformatics-Functional-Genomics-3Ed-2017/dp/8126567686/ref=sr_1_5?keywords=bioinformatics&qid=1573145480&sr=8-5), you will see the approach is very similar, they might have the probability table ready for you, but I cannot recall.

Hope this help.