-
Notifications
You must be signed in to change notification settings - Fork 8
Translating RNA into Protein #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danielle-pinto
wants to merge
13
commits into
main
Choose a base branch
from
2026-01-31-prot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+153
−9
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0ba1396
initial commit
danielle-pinto 7e03286
rough draft of first solution
danielle-pinto 9bbaaf5
initial commit
danielle-pinto 485bb3a
adding thought process to solve problem
danielle-pinto f0b421b
remove other tutorials
danielle-pinto 3b086db
add BioSequences translate solution
danielle-pinto a80c198
add hand-written solution
danielle-pinto 3ebe9c3
return X if aa not in codon_table
danielle-pinto 2d54bc9
fix bugs in warnings
danielle-pinto 96f1be8
fix typos
danielle-pinto 79236d3
fix indentation in translate_mrna func
danielle-pinto 50c1d06
Resolve conflict in src/rosalind/06-hamm.md
danielle-pinto 48435ad
make small updates according to Kevin's comments
danielle-pinto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| # Translating RNA into Protein | ||
|
|
||
| 🤔 [Problem link](https://rosalind.info/problems/prot/) | ||
|
|
||
| !!! warning "The Problem" | ||
|
|
||
| The 20 commonly occurring amino acids are abbreviated by using 20 letters from the English alphabet. | ||
| (all letters except for B, J, O, U, X, and Z). | ||
| Protein strings are constructed from these 20 symbols. | ||
| Henceforth, the term genetic string will incorporate protein strings along with DNA strings and RNA strings. | ||
|
|
||
| The RNA codon table dictates the details regarding the encoding of specific codons into the amino acid alphabet. | ||
|
|
||
| Given: An RNA string s corresponding to a strand of mRNA. | ||
| (of length at most 10 kbp). | ||
|
|
||
| Return: The protein string encoded by s. | ||
|
|
||
| Sample Dataset | ||
| ``` | ||
| AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA | ||
| ``` | ||
|
|
||
| Sample Output | ||
| ``` | ||
| MAMAPRTEINSTRING | ||
| ``` | ||
|
|
||
| ### DIY solution | ||
| Let's tackle this problem by writing our own solution, | ||
| and then seeing how we can solve it with functions already available in BioJulia. | ||
|
|
||
| First, we will check that this is a coding region by verifying that the string starts with a start codon (`AUG`). | ||
| If not, we can still convert the string to protein, | ||
| but we'll throw a warning to alert the user. | ||
| There may be a frame shift, | ||
| in which case the returned translation will be incorrect. | ||
|
|
||
| We'll also do a check that the string is divisible by three. | ||
| If it is not, this will likely mean that there was a mutation in the string | ||
| (addition or deletion). | ||
| Again, we can still convert as much of the string as possible. | ||
| However, we should alert the user that the result may be incorrect! | ||
|
|
||
| Next, we'll need to convert this string of mRNA to a string of proteins using the RNA codon table. | ||
| We can convert the RNA codon table into a dictionary, | ||
| which can map over our codons. | ||
| Alternatively, we could also import this from the BioSequences package, | ||
| as this is already defined [there](https://github.com/BioJulia/BioSequences.jl/blob/b626dbcaad76217b248449e6aa2cc1650e95660c/src/geneticcode.jl#L132). | ||
|
|
||
| Then, we'll break the string into codons by slicing it every three characters. | ||
| These codons can be matched against the RNA codon table to get the corresponding amino acid. | ||
| We'll join all these amino acids together to form the final string. | ||
|
|
||
| Lastly, we'll need to deal with any three-character strings that don't match a codon. | ||
| This likely means that there was a mutation in the input mRNA string! | ||
| If we get a codon that doesn't match, | ||
| we can return "X" for that amino acid, | ||
| and continue translating the rest of the string. | ||
| If we get a string of X's, | ||
| that should signal to the user that there was some kind of frame shift. | ||
|
|
||
|
|
||
| Now that we have established an approach, | ||
| let's turn this into code! | ||
|
|
||
| ```julia | ||
| using Test | ||
|
|
||
| rna = "AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA" | ||
|
|
||
| # note: this can be created by hand | ||
| # or it can be accessed from the BioSequences package (see link above) | ||
| codon_table = Dict( | ||
| "AAA" => 'K', "AAC" => 'N', "AAG" => 'K', "AAU" => 'N', | ||
| "ACA" => 'T', "ACC" => 'T', "ACG" => 'T', "ACU" => 'T', | ||
| "AGA" => 'R', "AGC" => 'S', "AGG" => 'R', "AGU" => 'S', | ||
| "AUA" => 'I', "AUC" => 'I', "AUG" => 'M', "AUU" => 'I', | ||
| "CAA" => 'Q', "CAC" => 'H', "CAG" => 'Q', "CAU" => 'H', | ||
| "CCA" => 'P', "CCC" => 'P', "CCG" => 'P', "CCU" => 'P', | ||
| "CGA" => 'R', "CGC" => 'R', "CGG" => 'R', "CGU" => 'R', | ||
| "CUA" => 'L', "CUC" => 'L', "CUG" => 'L', "CUU" => 'L', | ||
| "GAA" => 'E', "GAC" => 'D', "GAG" => 'E', "GAU" => 'D', | ||
| "GCA" => 'A', "GCC" => 'A', "GCG" => 'A', "GCU" => 'A', | ||
| "GGA" => 'G', "GGC" => 'G', "GGG" => 'G', "GGU" => 'G', | ||
| "GUA" => 'V', "GUC" => 'V', "GUG" => 'V', "GUU" => 'V', | ||
| "UAA" => '*', "UAC" => 'Y', "UAG" => '*', "UAU" => 'Y', | ||
| "UCA" => 'S', "UCC" => 'S', "UCG" => 'S', "UCU" => 'S', | ||
| "UGA" => '*', "UGC" => 'C', "UGG" => 'W', "UGU" => 'C', | ||
| "UUA" => 'L', "UUC" => 'F', "UUG" => 'L', "UUU" => 'F', | ||
| ) | ||
|
|
||
| function translate_mrna(seq, codon_table) | ||
|
|
||
| # check if starts with start codon | ||
| if ! startswith(seq, "AUG") | ||
| @warn "this sequence does not start with AUG" | ||
| end | ||
| # check if string is divisible by three | ||
| if rem(length(seq), 3) != 0 | ||
| @warn "this sequence is not divisible by 3" | ||
| end | ||
| # separate string into codons | ||
| # this makes a generator, which allocates less memory than a vector | ||
| codons = (join(chunk) for chunk in Iterators.partition(seq, 3)) | ||
|
|
||
| # map over codons with codon table, return X if not in codon_table | ||
| aa_string = join(get(codon_table, c, "X") for c in codons) | ||
|
|
||
| # return amino acid string | ||
| return aa_string | ||
|
|
||
| end | ||
|
|
||
| translate_mrna(rna, codon_table) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could potentially add some test examples for strings that strings that aren't divisible ny 3, or that don't start with a start-codon |
||
| ``` | ||
|
|
||
|
|
||
| ### BioSequences Solution | ||
|
|
||
| An alternative way to approach this problem would be to leverage an already written, | ||
| established function from the BioSequences package in BioJulia. | ||
|
|
||
| ```julia | ||
| using BioSequences | ||
|
|
||
| rna = "AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA" | ||
|
|
||
| translate(rna"AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA") | ||
|
|
||
| ``` | ||
|
|
||
| This function is straightforward to use, | ||
| especially in the case where the input mRNA has no ambiguous codons | ||
| and is divisible by 3. | ||
| However, there are also additional parameters available for handling other types of strings. | ||
|
|
||
| For instance, the function defaults to using the standard genetic code. | ||
| However, if a user wishes to use another codon chart | ||
| (for example, yeast or invertebrate), | ||
| there are others available on [BioSequences.jl](https://github.com/BioJulia/BioSequences.jl/blob/b626dbcaad76217b248449e6aa2cc1650e95660c/src/geneticcode.jl#L130) to choose from. | ||
|
|
||
| By default, `allow_ambiguous_codons` is `true`. | ||
| If a user gives the function a mRNA string with ambiguous codons that may not be found in the standard genetic code, | ||
| these codons will be translated to the narrowest amino acid which covers all | ||
| non-ambiguous codons encompassed by the ambiguous codon. | ||
| If this option is turned off, | ||
| ambiguous codons will cause an error. | ||
|
|
||
| Additionally, `alternative_start` is `false` by default. | ||
| If set to true, the starting amino acid will be Methionine regardless of what the first codon is. | ||
|
|
||
| Similar to our function, the BioSequences function also throws an error if the input mRNA string is not divisible by 3. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.