Skip to content
Advertisement

Iterate over and index a list?

I am trying to iterate over a string that has many repeated characters in order to reorganize it into a list with each character replaced with a 3 letter code and its index+1.

So I want to reorganize:

JavaScript

Into:

JavaScript

This is just an example string, and the final one will be ~300 characters long. Thanks for any advice!

Edit: Here is the code I have written which iterates through the string to replace the single letters with 3 letter codes.

JavaScript

Advertisement

Answer

Basically these are the steps.

  • You write a dictionary with keys as 1 letter aa code and value as 3 letter code.
  • Then you make a list of the peptide/protein
  • Declare an empty list to which you append later
  • Then enumerate and iterate over it
  • For every single letter code, you get the 3 letter code and index. Add this to the list defined above
  • Print or return the final list

Here is the code.

JavaScript

When you call it for your peptide, following is the answer

JavaScript
JavaScript

You can potentially convert any big peptide or protein. For insulin follwing is the answer

JavaScript
JavaScript

You should ask this question at Bioinformatics stack-exchange for more elegant solution.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement