Initial Commit
This commit is contained in:
1
plsql/current
Symbolic link
1
plsql/current
Symbolic link
@@ -0,0 +1 @@
|
||||
hamming
|
77
plsql/hamming/GETTING_STARTED.md
Normal file
77
plsql/hamming/GETTING_STARTED.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# Getting Started
|
||||
|
||||
These exercises lean on Test-Driven Development (TDD), but they're not an
|
||||
exact match.
|
||||
|
||||
## Setup
|
||||
|
||||
You'll need access to a mounted Oracle DB. If you don't have one already
|
||||
installed, here are a few options:
|
||||
* download VirtualBox from Oracle and run one of the freely
|
||||
available images; at the time of writing, the easiest to get started with
|
||||
at the time of writing might be _Database App Development VM_. The
|
||||
image is quite large...
|
||||
* download and install the a version of the Oracle DB itself. Developer licenses
|
||||
are free.
|
||||
* get a free workspace at https://apex.oracle.com
|
||||
|
||||
**Note**: if you're using the online version of APEX, compilation errors will
|
||||
not be indicated very clearly when working in _SQL Commands_ - you will simply
|
||||
get "Error at line XX: PL/SQL: Statement ignored"... More insight can be
|
||||
found using the _Object Browser_ and navigating to the object you created
|
||||
(select either _Packages_ or _Procedures_ in the dropdown menu showing _Tables_,
|
||||
depending on what you created for the exercise). Also, when you run statements,
|
||||
"run" each individual `create` statement individually by selecting its text.
|
||||
APEX does not seem to like doing too much work at once...
|
||||
|
||||
To work on individual problems, a nice and free way is to use SQL Developer. If
|
||||
you don't want to use yet another IDE, you can simply copy and paste your code
|
||||
into a terminal / command prompt connected to the database. The files are
|
||||
prepared in a way that will simply overwrite the previously compiled version.
|
||||
|
||||
#Exercise
|
||||
|
||||
## Step 1
|
||||
|
||||
Compile the test suite. You can easily do that by copy / pasting (let's call
|
||||
that _installing_ for simplicity) into your terminal connected to a mounted
|
||||
Oracle database.
|
||||
|
||||
This will fail, complaining that there is no package called `HAMMING#`.
|
||||
|
||||
To fix the error create the package by installing the prepared solution stub.
|
||||
Note that you will have to re-install the package body of `UT_HAMMING#`.
|
||||
|
||||
A few words about naming: the `#` at the end of the name signifies that this
|
||||
is a package. `UT` means _unit test_. _PL/SQL_ has a maximum identifier length
|
||||
of 30 characters, which is why you will find that many words are abbreviated.
|
||||
|
||||
If you've worked with PL/SQL before, you might wonder why the template is a
|
||||
package and not simply a standalone function. That would of course also be a
|
||||
possibility, but in practice standalone procedures or functions are rarely used.
|
||||
|
||||
## Step 2
|
||||
|
||||
Try to run the test. You will notice that you are missing the function's
|
||||
implementation. Create it (see the test package for examples).
|
||||
|
||||
Note that functions have to return a value, so for now just `return null;`.
|
||||
|
||||
## Step 3
|
||||
|
||||
Run the test again. It should now execute, but the test will fail.
|
||||
That's where you get to actually implement the function!
|
||||
|
||||
## Wash, Rinse, Repeat
|
||||
|
||||
Only the first test is enabled at first, the others are commented out. To enable
|
||||
them, simply delete the `--` in front of the procedure call and they'll run
|
||||
when you next install the test package!
|
||||
|
||||
## Submit
|
||||
|
||||
When everything is passing, you can submit your code with the following
|
||||
command:
|
||||
|
||||
$ exercism submit hamming#.plsql
|
||||
|
59
plsql/hamming/README.md
Normal file
59
plsql/hamming/README.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Hamming
|
||||
|
||||
Write a program that can calculate the Hamming difference between two DNA strands.
|
||||
|
||||
A mutation is simply a mistake that occurs during the creation or
|
||||
copying of a nucleic acid, in particular DNA. Because nucleic acids are
|
||||
vital to cellular functions, mutations tend to cause a ripple effect
|
||||
throughout the cell. Although mutations are technically mistakes, a very
|
||||
rare mutation may equip the cell with a beneficial attribute. In fact,
|
||||
the macro effects of evolution are attributable by the accumulated
|
||||
result of beneficial microscopic mutations over many generations.
|
||||
|
||||
The simplest and most common type of nucleic acid mutation is a point
|
||||
mutation, which replaces one base with another at a single nucleotide.
|
||||
|
||||
By counting the number of differences between two homologous DNA strands
|
||||
taken from different genomes with a common ancestor, we get a measure of
|
||||
the minimum number of point mutations that could have occurred on the
|
||||
evolutionary path between the two strands.
|
||||
|
||||
This is called the 'Hamming distance'.
|
||||
|
||||
It is found by comparing two DNA strands and counting how many of the
|
||||
nucleotides are different from their equivalent in the other string.
|
||||
|
||||
GAGCCTACTAACGGGAT
|
||||
CATCGTAATGACGGCCT
|
||||
^ ^ ^ ^ ^ ^^
|
||||
|
||||
The Hamming distance between these two DNA strands is 7.
|
||||
|
||||
# Implementation notes
|
||||
|
||||
The Hamming distance is only defined for sequences of equal length. This means
|
||||
that based on the definition, each language could deal with getting sequences
|
||||
of equal length differently.
|
||||
|
||||
## Setup
|
||||
|
||||
Go through the setup instructions for PL/SQL to get ready to code:
|
||||
|
||||
http://help.exercism.io/getting-started-with-plsql.html
|
||||
|
||||
## Running the Tests
|
||||
|
||||
Execute the tests by calling the `run` method in the respective `ut_<exercise>#` package.
|
||||
The necessary code should be contained at the end of the test package.
|
||||
As an example, the test for the _hamming_ exercise would be run using
|
||||
|
||||
```
|
||||
begin
|
||||
ut_hamming#.run;
|
||||
end;
|
||||
/
|
||||
```
|
||||
|
||||
## Source
|
||||
|
||||
The Calculating Point Mutations problem at Rosalind [view source](http://rosalind.info/problems/hamm/)
|
23
plsql/hamming/hamming#.plsql
Normal file
23
plsql/hamming/hamming#.plsql
Normal file
@@ -0,0 +1,23 @@
|
||||
create or replace package hamming#
|
||||
is
|
||||
--+--------------------------------------------------------------------------+
|
||||
-- Computes the Hamming distance between two starnds.
|
||||
--
|
||||
-- @param i_first sequence to compare
|
||||
-- @param i_second sequence to compare
|
||||
--
|
||||
-- @return Hamming distance between i_first and i_second
|
||||
--+--------------------------------------------------------------------------+
|
||||
function distance (
|
||||
i_first varchar2
|
||||
,i_second varchar2
|
||||
) return pls_integer;
|
||||
|
||||
end hamming#;
|
||||
/
|
||||
|
||||
create or replace package body hamming#
|
||||
is
|
||||
|
||||
end hamming#;
|
||||
/
|
53
plsql/hamming/ut_hamming#.plsql
Normal file
53
plsql/hamming/ut_hamming#.plsql
Normal file
@@ -0,0 +1,53 @@
|
||||
create or replace package ut_hamming#
|
||||
is
|
||||
procedure run;
|
||||
end ut_hamming#;
|
||||
/
|
||||
|
||||
create or replace package body ut_hamming#
|
||||
is
|
||||
|
||||
procedure test (
|
||||
i_descn varchar2
|
||||
,i_exp pls_integer
|
||||
,i_act pls_integer
|
||||
)
|
||||
is
|
||||
begin
|
||||
if i_exp = i_act then
|
||||
dbms_output.put_line('SUCCESS: ' || i_descn);
|
||||
else
|
||||
dbms_output.put_line(
|
||||
'FAILURE: ' || i_descn
|
||||
|| ': expected ' || nvl('' || i_exp, 'null')
|
||||
|| ', but got ' || nvl('' || i_act, 'null')
|
||||
|| '!'
|
||||
);
|
||||
end if;
|
||||
end test;
|
||||
|
||||
procedure run
|
||||
is
|
||||
begin
|
||||
test('test_no_difference_between_identical_strands' , 0, hamming#.distance(i_first => 'A' , i_second => 'A' ));
|
||||
--test('test_complete_hamming_distance_of_for_single_nucleotide_strand', 1, hamming#.distance(i_first => 'A' , i_second => 'G' ));
|
||||
--test('test_complete_hamming_distance_of_for_small_strand' , 2, hamming#.distance(i_first => 'AG' , i_second => 'CT' ));
|
||||
--test('test_small_hamming_distance' , 1, hamming#.distance(i_first => 'AG' , i_second => 'AT' ));
|
||||
--test('test_small_hamming_distance_in_longer_strand' , 1, hamming#.distance(i_first => 'GGACG' , i_second => 'GGTCG' ));
|
||||
--test('test_nonunique_characters_within_first_strand' , 1, hamming#.distance(i_first => 'AGA' , i_second => 'AGG' ));
|
||||
--test('test_nonunique_characters_within_second_strand' , 1, hamming#.distance(i_first => 'AGG' , i_second => 'AGA' ));
|
||||
--test('test_large_hamming_distance' , 4, hamming#.distance(i_first => 'GATACA' , i_second => 'GCATAA' ));
|
||||
--test('test_hamming_distance_in_very_long_strand' , 9, hamming#.distance(i_first => 'GGACGGATTCTG', i_second => 'AGGACGGATTCT'));
|
||||
exception
|
||||
when others then
|
||||
dbms_output.put_line('Test execution failed.');
|
||||
dbms_output.put_line(sqlerrm);
|
||||
end run;
|
||||
|
||||
end ut_hamming#;
|
||||
/
|
||||
|
||||
begin
|
||||
ut_hamming#.run;
|
||||
end;
|
||||
/
|
Reference in New Issue
Block a user