Answers.Body: <p>Firstly, the problem with your data is that it ain't aligned. Without that your motif positions are not relative from one protein to another. Basically you need to align it and there's no wriggle room.</p>
  <p>Secondly, its easy you simply parse the motifs you want and their location within the string - after it is aligned. In Python you would use <code>finditer</code> within a comprehension. This will go into a dataframe and subject to a heatmap package, I'm not a 'heatmap' person but it would be easy to graph where the x axis is the position where each motif is found and a qualitative score given for each type of motif (1-3 here). I don't know the equivalent in <code>R</code>.</p>
  <p>There is an issue whether an indel will remove a motif and you would need to check for that by running the same command against an unaligned protein and seeing if the frequency matches.</p>
  <p>My advice is to ask a new question with some code. I dunno whether someone has coded this already, - its easy to do. Personally, I don't think there's sufficient requirement, but I could be wrong.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-14T19:37:07.270Z
Answers.LastActivityDate: 2022-06-14T20:49:15.193Z
Answers.LastEditDate: 2022-06-14T20:49:15.193Z
Answers.UserDisplayName: M__
Body: <p>I have a file containing multiple protein amino acid sequences. I am interested in visually presenting the location of amino acid motifs PQG, QQG and AQG in the sequence in the form of a heatmap in R. Every location of the motifs should be represented as a differently coloured barcode. Example sequence follows,</p>
  <pre><code>&gt;cat archae.fasta
  &gt;A0A075FKY9
  MRRITLPKGIEISGKSPFGTSSGVYEVVISISENKPSDASIASNSFNSLWKDNFHLRVSG
  DHFSQVLGSGSNPIPDNVFDLGSVWIVIQDQFSPVHTSFQFNISPSNQPASKPEEKPRRV
  ETSTVKRTITKPGRLGPPGGKGPRGPSGYPGIKGDKGGRGPTGDKGDKGDKGIPGPQGEK
  GKTGQAGDKGDKGITGPPGEKGPRGSTGPPGDKGDKGVQGKIGDKGLTGTTGPVGDKGTQ
  GPQGPPGGKGLTGIPGPQGDKGTKGPLGPVGERGPTGKPGESGLQGPQGIQGAQGERGHS
  GPPGPQGEKGLIGDKGEIGERGTRGPPGPPGEKGSQGGMSDEGKRLIKELLELLASKNII
  STEEQIKLTSYLY
  &gt;A0A075FMB0
  MPGDKGTSGIRGVPGD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LTSYLY
  
  </code></pre>
  <p>As an example, please see a two-colour heatmap. I need something similar but with three colours corresponding to each of the three motifs.
  <a href="https://i.sstatic.net/B3AVX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/B3AVX.png" alt="enter image description here" /></a></p>
  <p>I looked at the heatmaply package but the biggest problem is that my matrix is not numeric. Is there way to make heatmap using text strings in R?</p>
  <p>Motif is defined as any three character string that matches the general pattern either PQG, QQG and AQG in the uploaded sequence. y-axis is the fasta code appended after &gt; (A0A075FKY9 for example). x-axis would depend on how the data is converted into a matrix.</p>
  
Tags: <r><heatmap><motifs>
Title: Heatmap of motifs present in protein sequences
ThreadText: # Heatmap of motifs present in protein sequences
  
  (Asked by: username_0 on 2022-06-14)
  
  I have a file containing multiple protein amino acid sequences. I am interested in visually presenting the location of amino acid motifs PQG, QQG and AQG in the sequence in the form of a heatmap in R. Every location of the motifs should be represented as a differently coloured barcode. Example sequence follows,
  
  ```
  >cat archae.fasta
  >A0A075FKY9
  MRRITLPKGIEISGKSPFGTSSGVYEVVISISENKPSDASIASNSFNSLWKDNFHLRVSG
  DHFSQVLGSGSNPIPDNVFDLGSVWIVIQDQFSPVHTSFQFNISPSNQPASKPEEKPRRV
  ETSTVKRTITKPGRLGPPGGKGPRGPSGYPGIKGDKGGRGPTGDKGDKGDKGIPGPQGEK
  GKTGQAGDKGDKGITGPPGEKGPRGSTGPPGDKGDKGVQGKIGDKGLTGTTGPVGDKGTQ
  GPQGPPGGKGLTGIPGPQGDKGTKGPLGPVGERGPTGKPGESGLQGPQGIQGAQGERGHS
  GPPGPQGEKGLIGDKGEIGERGTRGPPGPPGEKGSQGGMSDEGKRLIKELLELLASKNII
  STEEQIKLTSYLY
  >A0A075FMB0
  MPGDKGTSGIRGVPGDKGDKGPQGPPGDKGLTGPVGVPGEKGPTGTSGVQGEKGIQGTPG
  PLGEKGVTGPAGDKGPIGPPGPAGSKGITGPAGPLGDKGTIGPPGPLGDKGSKGPEGPTG
  DKGPQGPQGPAGAKGLTGVPGPQGEKGEKGPLGPIGEKGTTGATGPPGDKGPQGPQGTQG
  ERGTTGPSGEKGPQGPQGIQGPQGERGPTGPIGSIGETGPIGGQGPVGPAGPRGPPGPPG
  EKGPSGGMSSEQKAIFKELLEILTTKEIISTEEQIKLMSYLY
  >A0A075G2F8
  MPKGIEISGKSPFGTSSGVYEVKISVSQSKPSNDSITNNSFNSLWKDNFHLRVSEGYFSE
  ILGSDSNPIPDNVFDLGSVWIVIQDQFSPVHTSFEFKISQDSKSIPTPKEKPRRVDTSSV
  KKVRTIPTRQGPTGSKGIPGERGYPGTKGEKGGKGPTGDKGDKGDKGVPGPQGEKGKTGS
  TGDKGDKGITGSPGEKGPRGPTGPPGDKGDKGVQGKIGDKGLTGTTGPIGDKGPQGPQGP
  PGDKGLTGIPGPQGDKGGRGTIGPSGERGPTGRPGESGLQGPQGIQGPQGERGHSGPPGP
  QGEKGIIGDKGEIGERGPRGPPGPPGEKGSQGGMSDDGKILFKELLQLLASKNIISTEEQ
  IKLTSYLY
  >A0A075GLR7
  MPKGIEISGKSPFGTSSGVYEVRISISQDKPSDDGITNNSFNSLWKDNFHLRVSEGHFSE
  ILGTDSNPIPADVFGLGSIWIIIQDQFSPVHTSFELHISQDNKLLSVPQGKPKPVNATKV
  QKVRAQPGRPGPQGEKGGKGPAGYPGTRGEKGGRGITGDKGDKGDKGIPGPQGEKGIKGP
  AGDKGDKGITGPVGPSGPKGSTGPPGDKGDKGVQGKSGDKGLTGVTGPLGDKGTQGPQGP
  PGPKGLTGVPGPQGDKGMRGSIGPAGERGPTGKPGDPGLPGPQGIQGPQGERGHTGPQGP
  PGEKGLVGDKGEIGDRGPRGPPGPPGEKGSQGGMSEESKRLVKELLELLASKNIISTEEQ
  IKLTSYLY
  
  ```
  
  As an example, please see a two-colour heatmap. I need something similar but with three colours corresponding to each of the three motifs.
  [![enter image description here](https://i.sstatic.net/B3AVX.png)](https://i.sstatic.net/B3AVX.png)
  
  I looked at the heatmaply package but the biggest problem is that my matrix is not numeric. Is there way to make heatmap using text strings in R?
  
  Motif is defined as any three character string that matches the general pattern either PQG, QQG and AQG in the uploaded sequence. y-axis is the fasta code appended after > (A0A075FKY9 for example). x-axis would depend on how the data is converted into a matrix.
  
  **Tags:** r, heatmap, motifs
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-06-14. Score: 0
  
  Firstly, the problem with your data is that it ain't aligned. Without that your motif positions are not relative from one protein to another. Basically you need to align it and there's no wriggle room.
  
  Secondly, its easy you simply parse the motifs you want and their location within the string - after it is aligned. In Python you would use `finditer` within a comprehension. This will go into a dataframe and subject to a heatmap package, I'm not a 'heatmap' person but it would be easy to graph where the x axis is the position where each motif is found and a qualitative score given for each type of motif (1-3 here). I don't know the equivalent in `R`.
  
  There is an issue whether an indel will remove a motif and you would need to check for that by running the same command against an unaligned protein and seeing if the frequency matches.
  
  My advice is to ask a new question with some code. I dunno whether someone has coded this already, - its easy to do. Personally, I don't think there's sufficient requirement, but I could be wrong.
  
  
  ---
  
  