Initial Commit
This commit is contained in:
43
lisp/point-mutations/README.md
Normal file
43
lisp/point-mutations/README.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# Point Mutations
|
||||
|
||||
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'
|
||||
|
||||
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. Hence you
|
||||
may assume that only sequences of equal length will be passed to your hamming
|
||||
distance function.
|
||||
|
||||
Check out
|
||||
[Exercism Help](http://help.exercism.io/getting-started-with-lisp.html)
|
||||
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.
|
||||
|
||||
## Source
|
||||
|
||||
The Calculating Point Mutations problem at Rosalind [view source](http://rosalind.info/problems/hamm/)
|
8
lisp/point-mutations/dna.lisp
Normal file
8
lisp/point-mutations/dna.lisp
Normal file
@@ -0,0 +1,8 @@
|
||||
(defpackage #:dna
|
||||
(:use #:cl)
|
||||
(:export #:hamming-distance))
|
||||
(in-package #:dna)
|
||||
|
||||
(defun hamming-distance (dna1 dna2)
|
||||
"Determine number of mutations between DNA strands by computing the Hamming Distance."
|
||||
)
|
33
lisp/point-mutations/point-mutations-test.lisp
Normal file
33
lisp/point-mutations/point-mutations-test.lisp
Normal file
@@ -0,0 +1,33 @@
|
||||
(ql:quickload "lisp-unit")
|
||||
|
||||
(defpackage #:point-mutations-test
|
||||
(:use #:common-lisp #:lisp-unit))
|
||||
|
||||
#-xlisp-test (load "dna")
|
||||
|
||||
(in-package #:point-mutations-test)
|
||||
|
||||
(define-test no-difference-between-empty-strands
|
||||
(assert-equal 0 (dna:hamming-distance "" "")))
|
||||
|
||||
(define-test no-difference-between-identical-strands
|
||||
(assert-equal 0 (dna:hamming-distance "GGACTGA" "GGACTGA")))
|
||||
|
||||
(define-test complete-hamming-distance-in-small-strand
|
||||
(assert-equal 3 (dna:hamming-distance "ACT" "GGA")))
|
||||
|
||||
(define-test small-hamming-distance-in-middle-somewhere
|
||||
(assert-equal 1 (dna:hamming-distance "GGACG" "GGTCG")))
|
||||
|
||||
(define-test larger-distance
|
||||
(assert-equal 2 (dna:hamming-distance "ACCAGGG" "ACTATGG")))
|
||||
|
||||
(define-test invalid-to-get-distance-for-different-length-strings
|
||||
(assert-equal nil (dna:hamming-distance "AGACAACAGCCAGCCGCCGGATT" "AGGCAA"))
|
||||
(assert-equal nil (dna:hamming-distance "AGACAACAGCCAGCCGCCGGATT" "AGACATCTTTCAGCCGCCGGATTAGGCAA"))
|
||||
(assert-equal nil (dna:hamming-distance "AGG" "AGACAACAGCCAGCCGCCGGATT")))
|
||||
|
||||
#-xlisp-test
|
||||
(let ((*print-errors* t)
|
||||
(*print-failures* t))
|
||||
(run-tests :all :point-mutations-test))
|
Reference in New Issue
Block a user