summaryrefslogtreecommitdiffstats
path: root/rosalind/dna.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rosalind/dna.rs')
-rw-r--r--rosalind/dna.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/rosalind/dna.rs b/rosalind/dna.rs
new file mode 100644
index 0000000..a2ee73d
--- /dev/null
+++ b/rosalind/dna.rs
@@ -0,0 +1,30 @@
+use str = core::str;
+
+pure fn gc_content(dna: ~str) -> float {
+ let mut content = 0;
+ for str::each_char(dna) |ch| {
+ match ch {
+ 'C' | 'G' => content += 1,
+ _ => (),
+ }
+ }
+ (content as float) / (str::len(dna) as float)
+}
+
+pure fn complement(base: char) -> char {
+ match base {
+ 'A' => 'T',
+ 'C' => 'G',
+ 'G' => 'C',
+ 'T' => 'A',
+ _ => fail ~"Unknown character found",
+ }
+}
+
+pure fn transcribe(base: char) -> char {
+ match base {
+ 'T' => 'U',
+ 'A' | 'C' | 'G' => base,
+ _ => fail ~"Unknown character found",
+ }
+}