Just a commit
This commit is contained in:
90
lisp/hamming/README.md
Normal file
90
lisp/hamming/README.md
Normal file
@@ -0,0 +1,90 @@
|
||||
# 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
|
||||
|
||||
Check out [Exercism Help](http://exercism.io/languages/lisp) for instructions to
|
||||
get started writing Common Lisp. That page will explain how to install and setup
|
||||
a Lisp implementation and how to run the tests.
|
||||
|
||||
## Formatting
|
||||
|
||||
While Common Lisp doesn't care about indentation and layout of code,
|
||||
nor whether you use spaces or tabs, this is an important consideration
|
||||
for submissions to exercism.io. Excercism.io's code widget cannot
|
||||
handle mixing of tab and space characters well so using only spaces is recommended to make
|
||||
the code more readable to the human reviewers. Please review your
|
||||
editors settings on how to accomplish this. Below are instructions for
|
||||
popular editors for Common Lisp.
|
||||
|
||||
### VIM
|
||||
|
||||
Use the following commands to ensure VIM uses only spaces for
|
||||
indentation:
|
||||
|
||||
```vimscript
|
||||
:set tabstop=2
|
||||
:set shiftwidth=2
|
||||
:set expandtab
|
||||
```
|
||||
|
||||
(or as a oneliner `:set tabstop=2 shiftwidth=2 expandtab`). This can
|
||||
be added to your `~/.vimrc` file to use it all the time.
|
||||
|
||||
### Emacs
|
||||
|
||||
Emacs is very well suited for editing Common Lisp and has many
|
||||
powerful add-on packages available. The only thing that one needs to
|
||||
do with a stock emacs to make it work well with exercism.io is to
|
||||
evaluate the following code:
|
||||
|
||||
`(setq indent-tab-mode nil)`
|
||||
|
||||
This can be placed in your `~/.emacs` (or `~/.emacs.d/init.el`) in
|
||||
order to have it set whenever Emacs is launched.
|
||||
|
||||
One suggested add-on for Emacs and Common Lisp is
|
||||
[SLIME](https://github.com/slime/slime) which offers tight integration
|
||||
with the REPL; making iterative coding and testing very easy.
|
||||
|
||||
## Source
|
||||
|
||||
The Calculating Point Mutations problem at Rosalind [http://rosalind.info/problems/hamm/](http://rosalind.info/problems/hamm/)
|
||||
|
||||
## Submitting Incomplete Problems
|
||||
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||
|
33
lisp/hamming/hamming-test.lisp
Normal file
33
lisp/hamming/hamming-test.lisp
Normal file
@@ -0,0 +1,33 @@
|
||||
(ql:quickload "lisp-unit")
|
||||
|
||||
#-xlisp-test (load "hamming")
|
||||
|
||||
(defpackage #:hamming-test
|
||||
(:use #:common-lisp #:lisp-unit))
|
||||
|
||||
(in-package #:hamming-test)
|
||||
|
||||
(define-test no-difference-between-empty-strands
|
||||
(assert-equal 0 (hamming:distance "" "")))
|
||||
|
||||
(define-test no-difference-between-identical-strands
|
||||
(assert-equal 0 (hamming:distance "GGACTGA" "GGACTGA")))
|
||||
|
||||
(define-test complete-hamming-distance-in-small-strand
|
||||
(assert-equal 3 (hamming:distance "ACT" "GGA")))
|
||||
|
||||
(define-test small-hamming-distance-in-middle-somewhere
|
||||
(assert-equal 1 (hamming:distance "GGACG" "GGTCG")))
|
||||
|
||||
(define-test larger-distance
|
||||
(assert-equal 2 (hamming:distance "ACCAGGG" "ACTATGG")))
|
||||
|
||||
(define-test invalid-to-get-distance-for-different-length-strings
|
||||
(assert-equal nil (hamming:distance "AGACAACAGCCAGCCGCCGGATT" "AGGCAA"))
|
||||
(assert-equal nil (hamming:distance "AGACAACAGCCAGCCGCCGGATT" "AGACATCTTTCAGCCGCCGGATTAGGCAA"))
|
||||
(assert-equal nil (hamming:distance "AGG" "AGACAACAGCCAGCCGCCGGATT")))
|
||||
|
||||
#-xlisp-test
|
||||
(let ((*print-errors* t)
|
||||
(*print-failures* t))
|
||||
(run-tests :all :hamming-test))
|
9
lisp/hamming/hamming.lisp
Normal file
9
lisp/hamming/hamming.lisp
Normal file
@@ -0,0 +1,9 @@
|
||||
(defpackage #:hamming
|
||||
(:use #:cl)
|
||||
(:export #:distance))
|
||||
|
||||
(in-package #:hamming)
|
||||
|
||||
(defun distance (dna1 dna2)
|
||||
"Number of positional differences in two equal length dna strands."
|
||||
)
|
Reference in New Issue
Block a user