Friday, 29 October 2021

Translating RNA into Protein (Rosalind | English)

        

rosalind


Hi everyone, how are you? On this occasion, I want to discuss about one of the problems from rosalind.info's web. That title is "Translating RNA into Protein". For the reference, you can first check out the problem what will be discussed (here). 

 

DNA to RNA, then RNA to protein.


Overview

In this problem we will given a RNA string based on FASTA format for input. Our job is to translate that RNA string into protein string. For translating a RNA string into protein string we need to use a  special dictionary called RNA codon table

The Code 

This is the code for solving this problem (with java language): 

static void solve() {
HashMap<String, String> vocab = new HashMap<>();
vocab.put("AUU", "I"); 
vocab.put("AUC", "I"); 
vocab.put("AUA", "I"); 
vocab.put("AUG", "M"); 
vocab.put("ACU", "T"); 
vocab.put("ACC", "T"); 
vocab.put("ACA", "T"); 
vocab.put("ACG", "T"); 
vocab.put("AAU", "N"); 
vocab.put("AAC", "N"); 
vocab.put("AAA", "K"); 
vocab.put("AAG", "K"); 
vocab.put("AGU", "S"); 
vocab.put("AGC", "S"); 
vocab.put("AGA", "R"); 
vocab.put("AGG", "R"); 
vocab.put("UUU", "F");    
vocab.put("UUC", "F");    
vocab.put("UUA", "L");    
vocab.put("UUG", "L");    
vocab.put("UCU", "S");    
vocab.put("UCC", "S");    
vocab.put("UCA", "S");    
vocab.put("UCG", "S");    
vocab.put("UAU", "Y");    
vocab.put("UAC", "Y");    
vocab.put("UAA", "Stop"); 
vocab.put("UAG", "Stop");
vocab.put("UGU", "C");    
vocab.put("UGC", "C");    
vocab.put("UGA", "Stop");
vocab.put("UGG", "W");    
vocab.put("CUU", "L"); 
vocab.put("CUC", "L"); 
vocab.put("CUA", "L"); 
vocab.put("CUG", "L"); 
vocab.put("CCU", "P"); 
vocab.put("CCC", "P"); 
vocab.put("CCA", "P"); 
vocab.put("CCG", "P"); 
vocab.put("CAU", "H"); 
vocab.put("CAC", "H"); 
vocab.put("CAA", "Q"); 
vocab.put("CAG", "Q"); 
vocab.put("CGU", "R"); 
vocab.put("CGC", "R"); 
vocab.put("CGA", "R"); 
vocab.put("CGG", "R"); 
vocab.put("GUU", "V");
vocab.put("GUC", "V");
vocab.put("GUA", "V");
vocab.put("GUG", "V");
vocab.put("GCU", "A");
vocab.put("GCC", "A");
vocab.put("GCA", "A");
vocab.put("GCG", "A");
vocab.put("GAU", "D");
vocab.put("GAC", "D");
vocab.put("GAA", "E");
vocab.put("GAG", "E");
vocab.put("GGU", "G");
vocab.put("GGC", "G");
vocab.put("GGA", "G");
vocab.put("GGG", "G");
String s = ns();
for (int i = 0; i < s.length(); i += 3) {
String nowProt = vocab.get(s.substring(i, i + 3));
if (nowProt == "Stop") return;
out.print(nowProt);
}
}    

As you've seen, the code is quite simple. First of all, we just have to make a map from RNA table codon. Then, we start to translate that string three by three. 

Input and Output

In the code above, I used ns() function for entering the string-form data. That function is a extend from one of the system inputs which are available in java, called BufferedReader. 

And for the output I used function out.print(). That function is a modification from function System.out.print() which is very familiar in java. You can see the additional code for that modification (input and output) in my complete code at github

That's it. If you want to ask something, you can write it in the comment section below. I hope this article is useful and see you in the next article! 


Reference :
Source of image 1 :https://www.facebook.com/ProjectRosalind/
Source of image 2 :https://www.abbexa.com/mRNA-cancer-treatment

No comments:

Post a Comment