Answers.Body: <p><strong>UPDATE2</strong></p>
  <p>@chubs wants to compare different clades. This is possible within recent releases of ConSurf:</p>
  <p><a href="https://i.sstatic.net/xyu0W.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xyu0W.png" alt="consurf table 1" /></a></p>
  <p>It is additionally quite possible to use ConSurf's <a href="https://consurf.tau.ac.il/overview.php#_Toc311131301" rel="nofollow noreferrer">default outputs</a> to get per-position conservation scores that can be used for post-processing in any fashion, as well as prefab scripts that can be used with PyMol to make custom visualization:</p>
  <blockquote>
  <p>For all cases, ConSurf creates the following outputs:</p>
  <ol>
  <li><p>The sequence and MSA colored by ConSurf conservation scores.</p>
  </li>
  <li><p>A text file that summarizes for each position the normalized score calculated, the assigned grade (1-through-9), the reliability estimation (for the Bayesian method) and the amino acids/nucleotides observed in the respective MSA column.</p>
  </li>
  <li><p>The sequences selected for the MSA and the MSA constructed (unless those files were uploaded by the user).</p>
  </li>
  <li><p>A file with the frequency of each amino acid/nucleotide observed in each column of the MSA.</p>
  </li>
  <li><p>The evolutionary tree, which was calculated by the server or uploaded by the user, together with the MSA are shown using the WASABI platform (Veidenberg et al., 2015).  Moreover, using WASABI, a user can select a subtree containing a fraction of the homologous sequences and conduct a follow-up ConSurf analysis with these selected sequences. To refine a ConSurf analysis to a selected subtree, a user can choose any internal node on the phylogenetic tree and open a WASABI menu by using a right mouse click. Selecting the option 'run ConSurf on subtree' will issue a new window with the new ConSurf run for the selected subtree sequences (see example in Figure 3).</p>
  </li>
  </ol>
  </blockquote>
  <p><strong>UPDATE</strong></p>
  <p>It seems that what @chubs really wants to do is map protein conservation onto a structure. There are various tools for doing this (<a href="https://academic.oup.com/bioinformatics/article/35/2/332/5040318" rel="nofollow noreferrer">here</a>, <a href="https://academic.oup.com/nar/article/44/W1/W344/2499373" rel="nofollow noreferrer">here</a>). ConSurf is the older and more established tool, using evolutionary conservation to rule out trivial apparent associations due to phylogenetic non-independence.</p>
  <p>here is the  somewhat related 3DPatch workflow, which uses profile HMM information as a measure of conservation:</p>
  <p><a href="https://i.sstatic.net/fDWGY.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fDWGY.png" alt="3Dpatch workflow" /></a></p>
  <p>Here is the output that they get:</p>
  <p><a href="https://i.sstatic.net/eAUSL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eAUSL.png" alt="3dpatch figure" /></a></p>
  <p>Likewise ConSurf gets similar looking outputs:</p>
  <p><a href="https://i.sstatic.net/EyfY6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EyfY6.png" alt="consurf figure" /></a></p>
  <p><strong>ORIGINAL ANSWER</strong></p>
  <p>I think that more information is needed here to answer this question properly (what is your data? what is your ultimate goal? what are the things you've already tried?), but we can say a few things right away.</p>
  <p>I would strongly suggest looking into <a href="https://en.wikipedia.org/wiki/Substitution_model#The_mathematics_of_substitution_models" rel="nofollow noreferrer">substitution models</a>, which are literally substitution probability matrices. Note that these are probabilities <em>per unit time</em>, which is to say that they are calibrated to e.g. evolutionary rates along a specific phylogenetic tree. I would therefore strongly suggest incorporating a phylogenetic model of some kind.</p>
  <p>If you have e.g. a multiple sequence alignment, you can estimate a phylogenetic tree by one of the many tree estimation methods, which will give you a substitution probability matrix &quot;for free&quot; as this estimation is taken care of in the process of tree estimation. These will again be substitution probabilities per unit time; you will honestly not be able to get rid of the time-dependence here, as that's how evolution works.</p>
  <p>I am a little behind the times, but some tools you might look into for tree estimation are <a href="http://www.atgc-montpellier.fr/phyml/" rel="nofollow noreferrer">PhyML</a> and <a href="https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0009490" rel="nofollow noreferrer">FastTree</a>. If you only have sequences and haven't aligned them yet, you can use a tool like MUSCLE, ClustalO, or MAFFT.</p>
  <p>BLOSUM and related models are derived from specific slices of protein sequence identity (evolutionary history) calibrated to certain scopes, it's unlikely that they are appropriate to your case, unless your data fits inside those rather narrow slices.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T21:13:51.993Z
Answers.Text: I have a set of aligned sequences for which I want to generate a probability distribution of amino acids at each position. For example, at position 1, if all amino acids in the alignment are alanines, that position would hold a probability distribution for just alanine, which would be high for itself (alanine) and lower for other amino acids (just like the blosum62 row for alanine). If a position has different kinds of amino acids, its probability distribution would a mix, accordingly.
Answers.UserDisplayName: chubs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T21:18:43.690Z
Answers.Text: My ultimate goal is to have two seperate sets of sequences that can each be distilled to a probability distribution at every sequence position. I can then compare the two distributions (one from each set) to determine how similar that position is between the two groups.
  
  Sorry if this is confusing, but it's the best way I can think of for comparing two sets of alignments (e.g. mammalian sequences versus their arthropod counterparts).
Answers.UserDisplayName: chubs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T21:29:05.150Z
Answers.Text: @chubs is there a reason that you do not just use the sample distribution for each column of the alignment (for each taxonomic slice of alignment rows, if needed)? This is the normal methodology for e.g. generating logo plots, which I would recommend looking into: https://en.wikipedia.org/wiki/Sequence_logo If you are feeling very Bayesian you could pseudocount or try to incorporate a prior distribution based on the background frequency of amino acids in all positions of all the sequences, though that is getting a little over-elaborate IMO.
Answers.UserDisplayName: Maximilian Press
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T21:35:45.303Z
Answers.Text: @chubs I'll note that methods such as PAML have specifically implemented phylogenetic modeling approaches for detecting amino acid patterns of the type that you seem to be interested in between clades, with the branch model allowing $\omega$ variation among branches: http://abacus.gene.ucl.ac.uk/software/paml.html
Answers.UserDisplayName: Maximilian Press
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T22:06:37.483Z
Answers.Text: The reason I'm going about it this way is because I want to map the similarity of a given amino acid between two groups onto a three-dimensional atomic model of the protein. I've tried using sequence identity, but the results aren't quite what I want. In other words, one group with all glutamates at position 1 versus another group with all aspartates at the same position will give a 0% similarity when in fact this conservative substitution should give a higher score. I thought that by using probability distributions, I could calculate a more accurate similarity score to map onto the structure.
Answers.UserDisplayName: chubs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T22:17:19.347Z
Answers.Text: see edit to my answer.
Answers.UserDisplayName: Maximilian Press
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T22:26:02.747Z
Answers.Text: Consurf is great but doesn't compare two groups to each other, right? It just calculates the conservation of a set of sequences. I actually want to compare two groups to each other (e.g. multiple mammalian sequences in group 1 to multiple arthropod sequences in group 2). That's why I'm trying to calculate the probability distribution at each position: to then calculate a score based on how similar they are between the two groups.
Answers.UserDisplayName: chubs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T23:02:00.667Z
Answers.Text: @chubs then why not use consurf on each clade independently, and compare? Alternately, it seems like it should be possible to use any of various tools to export values for each position in each clade of interest, assuming that they are roughly structurally similar. Then you can do whatever you want with the conservation estimates, including mapping them onto a structural model. PAML would also work for this of course, with the advantage that it is explicitly modeling divergence between your two taxa. But you could also fit profile HMMs for each clade and compare, for the conservation task.
Answers.UserDisplayName: Maximilian Press
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T23:04:21.700Z
Answers.Text: @chubs see incoming update- you **can** run consurf on subtrees.
Answers.UserDisplayName: Maximilian Press
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T23:22:22.447Z
Answers.Text: If I use consurf on each clade (or on a subtree) what I will get is how conserved an amino acid is within each clade (e.g. position 1 of clade 1 is 10% conserved and position 1 of clade 2 is 30% conserved). This isn't what I'm looking for. I want to know how similar the amino acids are between the two clades (e.g. position 1 is 60% similar between clades 1 and 2). The two clades don't always have the same number of sequences, so I thought I would calculate the probability distribution at each position to compare instead of running Consurf on the combined sequences. Sorry if it's unclear.
Answers.UserDisplayName: chubs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-23T00:14:40.730Z
Answers.Text: @chubs I see. I continue to think that this is a weird way to do it, and you should use a phylogenetically informed approach such as PAML, which will give you a more exact estimate of what is going on at each position in each clade. It seems like that isn't what you want, though. It's quite heuristic, but if you like, you should be able to do a  summation across the amino acid frequency distribution at each site with BLOSUM (or whatever) as a transformation. Do it as a matrix multiplication of frequency vector 1 * BLOSUM * frequency vector 2. That is a per-site similarity measure, sorta.
Answers.UserDisplayName: Maximilian Press
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-23T00:23:59.910Z
Answers.Text: @MaximilianPress But I guess he has to align first...If I understand what he says it's not always ordered If that's the case that will be the hardest part.
Answers.UserDisplayName: juanjo75es
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-23T00:26:04.667Z
Answers.Text: But I agree that the phylogenetic tree way would be the ideal way (despite that also requires a previous alignment)
Answers.UserDisplayName: juanjo75es
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-24T20:48:32.190Z
Answers.Text: @juanjo75es based on what they says ("I have a set of aligned sequences for which I want to generate a probability distribution of amino acids at each position.", first comment on this answer), I think they already have the alignments? Maybe I am misunderstanding something though.
Answers.UserDisplayName: Maximilian Press
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-24T23:28:38.803Z
Answers.Text: @MaximilianPress "The two clades don't always have the same number of sequences" "one group with all glutamates at position 1 versus another group with all aspartates at the same position will give a 0% similarity" That doesn't seem to mean that it's already aligned.Or at least not well-aligned. No idea. If he says it is then let's accept that.
Answers.UserDisplayName: juanjo75es
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T20:01:27.773Z
Answers.LastActivityDate: 2021-01-22T23:06:46.453Z
Answers.LastEditDate: 2021-01-22T23:06:46.453Z
Answers.UserDisplayName: Maximilian Press
Body: <p>I am trying to calculate the substitution probabilities for amino acids (i.e. the probability of one amino acid given another). In theory, you should be able to derive them from a log-likelihood matrix (also called log-odds), such as Blosum62.</p>
  <p>Does anyone know how to calculate probabilities from log-likelihoods or have a good modern source for a substitution probability matrix?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-22T23:55:18.950Z
Comments.Text: If I understand what you want I think you just need to align the sequences and then make some probability calculation (which will likely make no sense biologically but will work for you). If the sequences have rearrangements as I understand you said somewhere then it's more complicated than just a multiple-alignment and you need a tool that finds local alignments. Am I following you?
Comments.UserDisplayName: juanjo75es
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-23T00:02:47.257Z
Comments.Text: I mean, if I understand well that's not going to be possible with any probabilistic method. You need to align first somehow. I guess something similar to what QUAST does. No idea if there is a tool for that. I said...
Comments.UserDisplayName: juanjo75es
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-23T21:22:46.293Z
Comments.Text: Yes, the sequences are aligned first before comparing the amino acid probability of each position between the two groups. I was just wondering how to convert a Blosum62 log-likelihood score of "2" (for example) to a probability, because I can then use the set of probabilities to calculate a combined probability at every position for a set of sequences.
Comments.UserDisplayName: chubs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-24T13:15:08.073Z
Comments.Text: Note that you are using imprecise language. You don't specify probability of what.  Anyway, I don't think I can help with that part.
Comments.UserDisplayName: juanjo75es
Tags: <phylogenetics>
Title: How does one convert a log-likelihood substitution matrix into a probability matrix?
ThreadText: # How does one convert a log-likelihood substitution matrix into a probability matrix?
  
  (Asked by: username_0 on 2021-01-22)
  
  I am trying to calculate the substitution probabilities for amino acids (i.e. the probability of one amino acid given another). In theory, you should be able to derive them from a log-likelihood matrix (also called log-odds), such as Blosum62.
  
  Does anyone know how to calculate probabilities from log-likelihoods or have a good modern source for a substitution probability matrix?
  
  **Tags:** phylogenetics
  
  > **Comments:**
  > **username_1**: If I understand what you want I think you just need to align the sequences and then make some probability calculation (which will likely make no sense biologically but will work for you). If the sequences have rearrangements as I understand you said somewhere then it's more complicated than just a multiple-alignment and you need a tool that finds local alignments. Am I following you?  
  > **username_1**: I mean, if I understand well that's not going to be possible with any probabilistic method. You need to align first somehow. I guess something similar to what QUAST does. No idea if there is a tool for that. I said...  
  > **username_0**: Yes, the sequences are aligned first before comparing the amino acid probability of each position between the two groups. I was just wondering how to convert a Blosum62 log-likelihood score of "2" (for example) to a probability, because I can then use the set of probabilities to calculate a combined probability at every position for a set of sequences.  
  > **username_1**: Note that you are using imprecise language. You don't specify probability of what.  Anyway, I don't think I can help with that part.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-01-22. Score: 1
  
  **UPDATE2**
  
  @username_0 wants to compare different clades. This is possible within recent releases of ConSurf:
  
  [![consurf table 1](https://i.sstatic.net/xyu0W.png)](https://i.sstatic.net/xyu0W.png)
  
  It is additionally quite possible to use ConSurf's [default outputs](https://consurf.tau.ac.il/overview.php#_Toc311131301) to get per-position conservation scores that can be used for post-processing in any fashion, as well as prefab scripts that can be used with PyMol to make custom visualization:
  
  > For all cases, ConSurf creates the following outputs:
  >
  > 1. The sequence and MSA colored by ConSurf conservation scores.
  > 2. A text file that summarizes for each position the normalized score calculated, the assigned grade (1-through-9), the reliability estimation (for the Bayesian method) and the amino acids/nucleotides observed in the respective MSA column.
  > 3. The sequences selected for the MSA and the MSA constructed (unless those files were uploaded by the user).
  > 4. A file with the frequency of each amino acid/nucleotide observed in each column of the MSA.
  > 5. The evolutionary tree, which was calculated by the server or uploaded by the user, together with the MSA are shown using the WASABI platform (Veidenberg et al., 2015). Moreover, using WASABI, a user can select a subtree containing a fraction of the homologous sequences and conduct a follow-up ConSurf analysis with these selected sequences. To refine a ConSurf analysis to a selected subtree, a user can choose any internal node on the phylogenetic tree and open a WASABI menu by using a right mouse click. Selecting the option 'run ConSurf on subtree' will issue a new window with the new ConSurf run for the selected subtree sequences (see example in Figure 3).
  
  **UPDATE**
  
  It seems that what @username_0 really wants to do is map protein conservation onto a structure. There are various tools for doing this ([here](https://academic.oup.com/bioinformatics/article/35/2/332/5040318), [here](https://academic.oup.com/nar/article/44/W1/W344/2499373)). ConSurf is the older and more established tool, using evolutionary conservation to rule out trivial apparent associations due to phylogenetic non-independence.
  
  here is the somewhat related 3DPatch workflow, which uses profile HMM information as a measure of conservation:
  
  [![3Dpatch workflow](https://i.sstatic.net/fDWGY.png)](https://i.sstatic.net/fDWGY.png)
  
  Here is the output that they get:
  
  [![3dpatch figure](https://i.sstatic.net/eAUSL.png)](https://i.sstatic.net/eAUSL.png)
  
  Likewise ConSurf gets similar looking outputs:
  
  [![consurf figure](https://i.sstatic.net/EyfY6.png)](https://i.sstatic.net/EyfY6.png)
  
  **ORIGINAL ANSWER**
  
  I think that more information is needed here to answer this question properly (what is your data? what is your ultimate goal? what are the things you've already tried?), but we can say a few things right away.
  
  I would strongly suggest looking into [substitution models](https://en.wikipedia.org/wiki/Substitution_model#The_mathematics_of_substitution_models), which are literally substitution probability matrices. Note that these are probabilities *per unit time*, which is to say that they are calibrated to e.g. evolutionary rates along a specific phylogenetic tree. I would therefore strongly suggest incorporating a phylogenetic model of some kind.
  
  If you have e.g. a multiple sequence alignment, you can estimate a phylogenetic tree by one of the many tree estimation methods, which will give you a substitution probability matrix "for free" as this estimation is taken care of in the process of tree estimation. These will again be substitution probabilities per unit time; you will honestly not be able to get rid of the time-dependence here, as that's how evolution works.
  
  I am a little behind the times, but some tools you might look into for tree estimation are [PhyML](http://www.atgc-montpellier.fr/phyml/) and [FastTree](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0009490). If you only have sequences and haven't aligned them yet, you can use a tool like MUSCLE, ClustalO, or MAFFT.
  
  BLOSUM and related models are derived from specific slices of protein sequence identity (evolutionary history) calibrated to certain scopes, it's unlikely that they are appropriate to your case, unless your data fits inside those rather narrow slices.
  
  > **Comments:**
  > **username_0**: I have a set of aligned sequences for which I want to generate a probability distribution of amino acids at each position. For example, at position 1, if all amino acids in the alignment are alanines, that position would hold a probability distribution for just alanine, which would be high for itself (alanine) and lower for other amino acids (just like the blosum62 row for alanine). If a position has different kinds of amino acids, its probability distribution would a mix, accordingly.  
  > **username_0**: My ultimate goal is to have two seperate sets of sequences that can each be distilled to a probability distribution at every sequence position. I can then compare the two distributions (one from each set) to determine how similar that position is between the two groups.  Sorry if this is confusing, but it's the best way I can think of for comparing two sets of alignments (e.g. mammalian sequences versus their arthropod counterparts).  
  > **username_2**: @username_0 is there a reason that you do not just use the sample distribution for each column of the alignment (for each taxonomic slice of alignment rows, if needed)? This is the normal methodology for e.g. generating logo plots, which I would recommend looking into: https://en.wikipedia.org/wiki/Sequence_logo If you are feeling very Bayesian you could pseudocount or try to incorporate a prior distribution based on the background frequency of amino acids in all positions of all the sequences, though that is getting a little over-elaborate IMO.  
  > **username_2**: @username_0 I'll note that methods such as PAML have specifically implemented phylogenetic modeling approaches for detecting amino acid patterns of the type that you seem to be interested in between clades, with the branch model allowing $\omega$ variation among branches: http://abacus.gene.ucl.ac.uk/software/paml.html  
  > **username_0**: The reason I'm going about it this way is because I want to map the similarity of a given amino acid between two groups onto a three-dimensional atomic model of the protein. I've tried using sequence identity, but the results aren't quite what I want. In other words, one group with all glutamates at position 1 versus another group with all aspartates at the same position will give a 0% similarity when in fact this conservative substitution should give a higher score. I thought that by using probability distributions, I could calculate a more accurate similarity score to map onto the structure.  
  > **username_2**: see edit to my answer.  
  > **username_0**: Consurf is great but doesn't compare two groups to each other, right? It just calculates the conservation of a set of sequences. I actually want to compare two groups to each other (e.g. multiple mammalian sequences in group 1 to multiple arthropod sequences in group 2). That's why I'm trying to calculate the probability distribution at each position: to then calculate a score based on how similar they are between the two groups.  
  > **username_2**: @username_0 then why not use consurf on each clade independently, and compare? Alternately, it seems like it should be possible to use any of various tools to export values for each position in each clade of interest, assuming that they are roughly structurally similar. Then you can do whatever you want with the conservation estimates, including mapping them onto a structural model. PAML would also work for this of course, with the advantage that it is explicitly modeling divergence between your two taxa. But you could also fit profile HMMs for each clade and compare, for the conservation task.  
  > **username_2**: @username_0 see incoming update- you **can** run consurf on subtrees.  
  > **username_0**: If I use consurf on each clade (or on a subtree) what I will get is how conserved an amino acid is within each clade (e.g. position 1 of clade 1 is 10% conserved and position 1 of clade 2 is 30% conserved). This isn't what I'm looking for. I want to know how similar the amino acids are between the two clades (e.g. position 1 is 60% similar between clades 1 and 2). The two clades don't always have the same number of sequences, so I thought I would calculate the probability distribution at each position to compare instead of running Consurf on the combined sequences. Sorry if it's unclear.  
  > **username_2**: @username_0 I see. I continue to think that this is a weird way to do it, and you should use a phylogenetically informed approach such as PAML, which will give you a more exact estimate of what is going on at each position in each clade. It seems like that isn't what you want, though. It's quite heuristic, but if you like, you should be able to do a  summation across the amino acid frequency distribution at each site with BLOSUM (or whatever) as a transformation. Do it as a matrix multiplication of frequency vector 1 * BLOSUM * frequency vector 2. That is a per-site similarity measure, sorta.  
  > **username_1**: @username_2 But I guess he has to align first...If I understand what he says it's not always ordered If that's the case that will be the hardest part.  
  > **username_1**: But I agree that the phylogenetic tree way would be the ideal way (despite that also requires a previous alignment)  
  > **username_2**: @username_1 based on what they says ("I have a set of aligned sequences for which I want to generate a probability distribution of amino acids at each position.", first comment on this answer), I think they already have the alignments? Maybe I am misunderstanding something though.  
  > **username_1**: @username_2 "The two clades don't always have the same number of sequences" "one group with all glutamates at position 1 versus another group with all aspartates at the same position will give a 0% similarity" That doesn't seem to mean that it's already aligned.Or at least not well-aligned. No idea. If he says it is then let's accept that.  
  
  ---
  
  