Skip to content

Commit

Permalink
Port exercise point-mutations (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmorgan committed Jul 19, 2018
1 parent d3c024e commit 48a0de0
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
"blurb": "ECMAScript is the standard that defines JavaScript, a language widely used in web development. It is updated regularly, requiring transpilation for code to be compatible with most browsers.",
"test_pattern": ".*[.]spec[.]js$",
"exercises": [
{
"slug": "point-mutations",
"uuid": "6d43709b-3809-4a6a-ab41-2a5ab841b5fb",
"core": false,
"unlocked_by": null,
"difficulty": 0,
"topics": null,
"deprecated": true
},
{
"slug": "forth",
"uuid": "e4035939-4375-4720-87ae-e613f925f013",
Expand Down
70 changes: 70 additions & 0 deletions exercises/point-mutations/README.md
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.
21 changes: 21 additions & 0 deletions exercises/point-mutations/example.js
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;
70 changes: 70 additions & 0 deletions exercises/point-mutations/package.json
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": {}
}
43 changes: 43 additions & 0 deletions exercises/point-mutations/point-mutations.spec.js
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);
});
});

0 comments on commit 48a0de0

Please sign in to comment.