-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ruby/protein-translation: 1st iteration
- Loading branch information
Showing
9 changed files
with
731 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,5 @@ | ||
{ | ||
"result": { | ||
"line": 100.0 | ||
} | ||
} |
This file contains 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,75 @@ | ||
{ | ||
"test:exercism": { | ||
"coverage": { | ||
"/home/vpayno/git_vpayno/exercism-workspace/ruby/protein-translation/protein_translation.rb": { | ||
"lines": [ | ||
null, | ||
null, | ||
null, | ||
null, | ||
1, | ||
1, | ||
null, | ||
1, | ||
null, | ||
32, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
32, | ||
null, | ||
30, | ||
null, | ||
null, | ||
1, | ||
30, | ||
null, | ||
29, | ||
29, | ||
29, | ||
42, | ||
null, | ||
42, | ||
9, | ||
9, | ||
null, | ||
null, | ||
33, | ||
null, | ||
null, | ||
29, | ||
null, | ||
60, | ||
null, | ||
null, | ||
null, | ||
null, | ||
1, | ||
1, | ||
null, | ||
1, | ||
3, | ||
3, | ||
null, | ||
null | ||
] | ||
} | ||
}, | ||
"timestamp": 1698299820 | ||
} | ||
} |
Empty file.
This file contains 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,42 @@ | ||
<?xml version='1.0'?> | ||
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd"> | ||
<!-- Generated by simplecov-cobertura version 2.1.0 (https://github.com/dashingrocket/simplecov-cobertura) --> | ||
<coverage line-rate="1.0" lines-covered="23" lines-valid="23" complexity="0" version="0" timestamp="1698299820"> | ||
<sources> | ||
<source>/home/vpayno/git_vpayno/exercism-workspace/ruby/protein-translation</source> | ||
</sources> | ||
<packages> | ||
<package name="protein-translation" line-rate="1.0" complexity="0"> | ||
<classes> | ||
<class name="protein_translation" filename="protein_translation.rb" line-rate="1.0" complexity="0"> | ||
<methods/> | ||
<lines> | ||
<line number="5" hits="1"/> | ||
<line number="6" hits="1"/> | ||
<line number="8" hits="1"/> | ||
<line number="10" hits="32"/> | ||
<line number="29" hits="32"/> | ||
<line number="31" hits="30"/> | ||
<line number="34" hits="1"/> | ||
<line number="35" hits="30"/> | ||
<line number="37" hits="29"/> | ||
<line number="38" hits="29"/> | ||
<line number="39" hits="29"/> | ||
<line number="40" hits="42"/> | ||
<line number="42" hits="42"/> | ||
<line number="43" hits="9"/> | ||
<line number="44" hits="9"/> | ||
<line number="47" hits="33"/> | ||
<line number="50" hits="29"/> | ||
<line number="52" hits="60"/> | ||
<line number="57" hits="1"/> | ||
<line number="58" hits="1"/> | ||
<line number="60" hits="1"/> | ||
<line number="61" hits="3"/> | ||
<line number="62" hits="3"/> | ||
</lines> | ||
</class> | ||
</classes> | ||
</package> | ||
</packages> | ||
</coverage> |
This file contains 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 |
---|---|---|
@@ -1,7 +1,64 @@ | ||
=begin | ||
Write your code for the 'Protein Translation' exercise in this file. Make the tests in | ||
`protein_translation_test.rb` pass. | ||
# frozen_string_literal: false | ||
|
||
To get started with TDD, see the `README.md` file in your | ||
`ruby/protein-translation` directory. | ||
=end | ||
# https://exercism.org/tracks/ruby/exercises/protein-translation | ||
# Protein Translation exercise | ||
module Translation | ||
CODON_LENGTH = 3 | ||
|
||
def self.to_protein(codon) | ||
codon2protein = { | ||
'AUG' => 'Methionine', | ||
'UUU' => 'Phenylalanine', | ||
'UUC' => 'Phenylalanine', | ||
'UUA' => 'Leucine', | ||
'UUG' => 'Leucine', | ||
'UCU' => 'Serine', | ||
'UCC' => 'Serine', | ||
'UCA' => 'Serine', | ||
'UCG' => 'Serine', | ||
'UAU' => 'Tyrosine', | ||
'UAC' => 'Tyrosine', | ||
'UGU' => 'Cysteine', | ||
'UGC' => 'Cysteine', | ||
'UGG' => 'Tryptophan', | ||
'UAA' => 'STOP', | ||
'UAG' => 'STOP', | ||
'UGA' => 'STOP' | ||
} | ||
|
||
raise InvalidCodonError, 'invalid codon' unless codon2protein.key?(codon) | ||
|
||
codon2protein[codon] | ||
end | ||
|
||
def self.of_rna(rna_sequence) | ||
return [] if rna_sequence.empty? | ||
|
||
has_stop = false | ||
codons = [] | ||
rna_sequence.scan(/([A-Z]{3})/) do |match| | ||
codon = match[0] | ||
|
||
if %w[UAA UAG UGA].include?(codon) | ||
has_stop = true | ||
break | ||
end | ||
|
||
codons.push(codon) | ||
end | ||
|
||
raise InvalidCodonError, 'invalid codon' if !has_stop && rna_sequence.length.modulo(CODON_LENGTH).positive? | ||
|
||
codons.map { |codon| to_protein(codon) } | ||
end | ||
end | ||
|
||
# InvalidCodonError exception | ||
class InvalidCodonError < StandardError | ||
attr_reader :data | ||
|
||
def initialize(data) | ||
super | ||
@data = data | ||
end | ||
end |
Oops, something went wrong.