Skip to content
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

Add rna-transcription exercise #84

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@
"prerequisites": [],
"difficulty": 3
},
{
"slug": "rna-transcription",
"name": "RNA Transcription",
"uuid": "ddfea5dc-0838-4a35-9936-1fb72cd7b1c4",
"practices": [],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "square-root",
"name": "Square Root",
Expand Down
20 changes: 20 additions & 0 deletions exercises/practice/rna-transcription/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Instructions

Your task is determine the RNA complement of a given DNA sequence.

Both DNA and RNA strands are a sequence of nucleotides.

The four nucleotides found in DNA are adenine (**A**), cytosine (**C**), guanine (**G**) and thymine (**T**).

The four nucleotides found in RNA are adenine (**A**), cytosine (**C**), guanine (**G**) and uracil (**U**).

Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:

- `G` -> `C`
- `C` -> `G`
- `T` -> `A`
- `A` -> `U`

~~~~exercism/note
If you want to look at how the inputs and outputs are structured, take a look at the examples in the test suite.
~~~~
16 changes: 16 additions & 0 deletions exercises/practice/rna-transcription/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Introduction

You work for a bioengineering company that specializes in developing therapeutic solutions.

Your team has just been given a new project to develop a targeted therapy for a rare type of cancer.

~~~~exercism/note
It's all very complicated, but the basic idea is that sometimes people's bodies produce too much of a given protein.
That can cause all sorts of havoc.

But if you can create a very specific molecule (called a micro-RNA), it can prevent the protein from being produced.

This technique is called [RNA Interference][rnai].

[rnai]: https://admin.acceleratingscience.com/ask-a-scientist/what-is-rnai/
~~~~
19 changes: 19 additions & 0 deletions exercises/practice/rna-transcription/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"keiravillekode"
],
"files": {
"solution": [
"rna_transcription.s"
],
"test": [
"rna_transcription_test.c"
],
"example": [
".meta/example.s"
]
},
"blurb": "Given a DNA strand, return its RNA Complement Transcription.",
"source": "Hyperphysics",
"source_url": "https://web.archive.org/web/20220408112140/http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html"
}
21 changes: 21 additions & 0 deletions exercises/practice/rna-transcription/.meta/example.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.text
.globl to_rna

.macro MAP from, to
mov w4, \to
cmp w2, \from
csel w3, w4, w3, eq /* conditionally update output byte */
.endm

/* extern void to_rna(char *buffer, const char *dna); */
to_rna:
ldrb w2, [x1], #1 /* load byte, with post-increment */
mov w3, w2
MAP #'G', #'C'
MAP #'C', #'G'
MAP #'T', #'A'
MAP #'A', #'U'
strb w3, [x0], #1 /* store byte, post-increment */
cbnz w3, to_rna

ret
28 changes: 28 additions & 0 deletions exercises/practice/rna-transcription/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[b4631f82-c98c-4a2f-90b3-c5c2b6c6f661]
description = "Empty RNA sequence"

[a9558a3c-318c-4240-9256-5d5ed47005a6]
description = "RNA complement of cytosine is guanine"

[6eedbb5c-12cb-4c8b-9f51-f8320b4dc2e7]
description = "RNA complement of guanine is cytosine"

[870bd3ec-8487-471d-8d9a-a25046488d3e]
description = "RNA complement of thymine is adenine"

[aade8964-02e1-4073-872f-42d3ffd74c5f]
description = "RNA complement of adenine is uracil"

[79ed2757-f018-4f47-a1d7-34a559392dbf]
description = "RNA complement"
36 changes: 36 additions & 0 deletions exercises/practice/rna-transcription/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
AS = aarch64-linux-gnu-as
CC = aarch64-linux-gnu-gcc

CFLAGS = -g -Wall -Wextra -pedantic -Werror
LDFLAGS =

ALL_LDFLAGS = -pie -Wl,--fatal-warnings

ALL_CFLAGS = -std=c99 -fPIE $(CFLAGS)
ALL_LDFLAGS += $(LDFLAGS)

C_OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
AS_OBJS = $(patsubst %.s,%.o,$(wildcard *.s))
ALL_OBJS = $(filter-out example.o,$(C_OBJS) $(AS_OBJS) vendor/unity.o)

CC_CMD = $(CC) $(ALL_CFLAGS) -c -o $@ $<

all: tests
qemu-aarch64 -L /usr/aarch64-linux-gnu ./$<

tests: $(ALL_OBJS)
@$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $(ALL_OBJS)

%.o: %.s
@$(AS) -o $@ $<

%.o: %.c
@$(CC_CMD)

vendor/unity.o: vendor/unity.c vendor/unity.h vendor/unity_internals.h
@$(CC_CMD)

clean:
@rm -f *.o vendor/*.o tests

.PHONY: all clean
5 changes: 5 additions & 0 deletions exercises/practice/rna-transcription/rna_transcription.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.text
.globl to_rna

to_rna:
ret
69 changes: 69 additions & 0 deletions exercises/practice/rna-transcription/rna_transcription_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "vendor/unity.h"

#define BUFFER_SIZE 80

extern void to_rna(char *buffer, const char *dna);

void setUp(void) {
}

void tearDown(void) {
}

void test_empty_rna_sequence(void) {
char buffer[BUFFER_SIZE];

to_rna(buffer, "");
TEST_ASSERT_EQUAL_STRING("", buffer);
}

void test_rna_complement_of_cytosine_is_guanine(void) {
TEST_IGNORE();
char buffer[BUFFER_SIZE];

to_rna(buffer, "C");
TEST_ASSERT_EQUAL_STRING("G", buffer);
}

void test_rna_complement_of_guanine_is_cytosine(void) {
TEST_IGNORE();
char buffer[BUFFER_SIZE];

to_rna(buffer, "G");
TEST_ASSERT_EQUAL_STRING("C", buffer);
}

void test_rna_complement_of_thymine_is_adenine(void) {
TEST_IGNORE();
char buffer[BUFFER_SIZE];

to_rna(buffer, "T");
TEST_ASSERT_EQUAL_STRING("A", buffer);
}

void test_rna_complement_of_adenine_is_uracil(void) {
TEST_IGNORE();
char buffer[BUFFER_SIZE];

to_rna(buffer, "A");
TEST_ASSERT_EQUAL_STRING("U", buffer);
}

void test_rna_complement(void) {
TEST_IGNORE();
char buffer[BUFFER_SIZE];

to_rna(buffer, "ACGTGGTCTTAA");
TEST_ASSERT_EQUAL_STRING("UGCACCAGAAUU", buffer);
}

int main(void) {
UNITY_BEGIN();
RUN_TEST(test_empty_rna_sequence);
RUN_TEST(test_rna_complement_of_cytosine_is_guanine);
RUN_TEST(test_rna_complement_of_guanine_is_cytosine);
RUN_TEST(test_rna_complement_of_thymine_is_adenine);
RUN_TEST(test_rna_complement_of_adenine_is_uracil);
RUN_TEST(test_rna_complement);
return UNITY_END();
}
Loading