-
-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port exercise point-mutations (#423)
- Loading branch information
1 parent
d3c024e
commit 48a0de0
Showing
5 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Point Mutations | ||
|
||
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. | ||
|
||
**Note: This problem is deprecated, replaced by the one called `hamming`.** | ||
|
||
## Setup | ||
|
||
Go through the setup instructions for ECMAScript to | ||
install the necessary dependencies: | ||
|
||
http://exercism.io/languages/ecmascript | ||
|
||
## Requirements | ||
|
||
Install assignment dependencies: | ||
|
||
```bash | ||
$ npm install | ||
``` | ||
|
||
## Making the test suite pass | ||
|
||
Execute the tests with: | ||
|
||
```bash | ||
$ npm test | ||
``` | ||
|
||
In the test suites all tests but the first have been skipped. | ||
|
||
Once you get a test passing, you can enable the next one by | ||
changing `xtest` to `test`. | ||
|
||
## Source | ||
|
||
The Calculating Point Mutations problem at Rosalind [http://rosalind.info/problems/hamm/](http://rosalind.info/problems/hamm/) | ||
|
||
## Submitting Incomplete Solutions | ||
It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class DNA { | ||
constructor(nucleotides){ | ||
this.nucleotides = nucleotides; | ||
} | ||
|
||
hammingDistance(comparison){ | ||
let distance = 0; | ||
const calculationDistance = Math.min(this.nucleotides.length, comparison.length); | ||
|
||
for (let i = 0; i < calculationDistance; i++) { | ||
let currentNucleotide = this.nucleotides[i]; | ||
let comparisonNucleotide = comparison[i]; | ||
|
||
if (currentNucleotide !== comparisonNucleotide) { distance++; } | ||
} | ||
|
||
return distance; | ||
} | ||
} | ||
|
||
export default DNA; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"name": "xecmascript", | ||
"version": "0.0.0", | ||
"description": "Exercism exercises in ECMAScript 6.", | ||
"author": "Katrina Owen", | ||
"private": true, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/exercism/xecmascript" | ||
}, | ||
"devDependencies": { | ||
"babel-jest": "^21.2.0", | ||
"babel-plugin-transform-builtin-extend": "^1.1.2", | ||
"babel-preset-env": "^1.4.0", | ||
"eslint": "^3.19.0", | ||
"eslint-config-airbnb": "^15.0.1", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-jsx-a11y": "^5.0.1", | ||
"eslint-plugin-react": "^7.0.1", | ||
"jest": "^21.2.1" | ||
}, | ||
"jest": { | ||
"modulePathIgnorePatterns": [ | ||
"package.json" | ||
] | ||
}, | ||
"babel": { | ||
"presets": [["env",{"targets":[{"node": "current"}]}] | ||
], | ||
"plugins": [ | ||
[ | ||
"babel-plugin-transform-builtin-extend", | ||
{ | ||
"globals": [ | ||
"Error" | ||
] | ||
} | ||
], | ||
[ | ||
"transform-regenerator" | ||
] | ||
] | ||
}, | ||
"scripts": { | ||
"test": "jest --no-cache ./*", | ||
"watch": "jest --no-cache --watch ./*", | ||
"lint": "eslint .", | ||
"lint-test": "eslint . && jest --no-cache ./* " | ||
}, | ||
"eslintConfig": { | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module" | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"jest": true | ||
}, | ||
"extends": "airbnb", | ||
"rules": { | ||
"import/no-unresolved": "off", | ||
"import/extensions": "off" | ||
} | ||
}, | ||
"licenses": [ | ||
"MIT" | ||
], | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import DNA from './point-mutations'; | ||
|
||
describe('DNA', () => { | ||
test('no difference between empty strands', () => { | ||
const dna = new DNA(''); | ||
expect(dna.hammingDistance('')).toEqual(0); | ||
}); | ||
|
||
xtest('no difference between identical strands', () => { | ||
const dna = new DNA('GGACTGA'); | ||
expect(dna.hammingDistance('GGACTGA')).toEqual(0); | ||
}); | ||
|
||
xtest('complete hamming distance in small strand', () => { | ||
const dna = new DNA('ACT'); | ||
expect(dna.hammingDistance('GGA')).toEqual(3); | ||
}); | ||
|
||
xtest('hamming distance in off by one strand', () => { | ||
const dna = new DNA('GGACGGATTCTGACCTGGACTAATTTTGGGG'); | ||
expect(dna.hammingDistance('AGGACGGATTCTGACCTGGACTAATTTTGGGG')).toEqual(19); | ||
}); | ||
|
||
xtest('small hamming distance in middle somewhere', () => { | ||
const dna = new DNA('GGACG'); | ||
expect(dna.hammingDistance('GGTCG')).toEqual(1); | ||
}); | ||
|
||
xtest('larger distance', () => { | ||
const dna = new DNA('ACCAGGG'); | ||
expect(dna.hammingDistance('ACTATGG')).toEqual(2); | ||
}); | ||
|
||
xtest('shortens other strand when longer', () => { | ||
const dna = new DNA('AAACTAGGGG'); | ||
expect(dna.hammingDistance('AGGCTAGCGGTAGGAC')).toEqual(3); | ||
}); | ||
|
||
xtest('shortens original strand when longer', () => { | ||
const dna = new DNA('GACTACGGACAGGGTAGGGAAT'); | ||
expect(dna.hammingDistance('GACATCGCACACC')).toEqual(5); | ||
}); | ||
}); |