-
-
Notifications
You must be signed in to change notification settings - Fork 661
Please review: Implemented exercise nucleotide-count #349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,62 @@ | ||
| # Nucleotide Count | ||
|
|
||
| Given a DNA string, compute how many times each nucleotide occurs in the string. | ||
|
|
||
| DNA is represented by an alphabet of the following symbols: 'A', 'C', | ||
| 'G', and 'T'. | ||
|
|
||
| Each symbol represents a nucleotide, which is a fancy name for the | ||
| particular molecules that happen to make up a large part of DNA. | ||
|
|
||
| Shortest intro to biochemistry EVAR: | ||
|
|
||
| - twigs are to birds nests as | ||
| - nucleotides are to DNA and RNA as | ||
| - amino acids are to proteins as | ||
| - sugar is to starch as | ||
| - oh crap lipids | ||
|
|
||
| I'm not going to talk about lipids because they're crazy complex. | ||
|
|
||
| So back to nucleotides. | ||
|
|
||
| DNA contains four types of them: adenine (`A`), cytosine (`C`), guanine | ||
| (`G`), and thymine (`T`). | ||
|
|
||
| RNA contains a slightly different set of nucleotides, but we don't care | ||
| about that for now. | ||
|
|
||
| ## 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 DNA Nucleotides_problem at Rosalind [http://rosalind.info/problems/dna/](http://rosalind.info/problems/dna/) | ||
|
|
||
| ## Submitting Incomplete Solutions | ||
| It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
This file contains hidden or 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,24 @@ | ||
| const countIn = (strand, nucleotide) => [...strand] | ||
| .filter(x => x.includes(nucleotide)) | ||
| .length; | ||
|
|
||
| class Dna { | ||
| constructor(strand) { | ||
| this.dna = strand || ''; | ||
| if (!/^[ACGT]*$/.test(this.dna)) { | ||
| throw new Error(`Input strand must not contain anything but A, C, G or T: ${this.dna}`); | ||
| } | ||
| this.nucleotidesCount = new Map([ | ||
| ['A', countIn(this.dna, 'A')], | ||
| ['C', countIn(this.dna, 'C')], | ||
| ['G', countIn(this.dna, 'G')], | ||
| ['T', countIn(this.dna, 'T')], | ||
| ]); | ||
| } | ||
| count(nucleotide) { | ||
| const count = this.nucleotidesCount.get(nucleotide); | ||
| return count || 0; | ||
| } | ||
| } | ||
|
|
||
| module.exports = Dna; |
This file contains hidden or 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,78 @@ | ||
| import Dna from './nucleotide-count'; | ||
|
|
||
| describe('DNA', () => { | ||
| it('counts an undefined DNA strand as 0', () => { | ||
| const dna = new Dna(); | ||
| expect(dna.count('A')).toEqual(0); | ||
| expect(dna.count('C')).toEqual(0); | ||
| expect(dna.count('G')).toEqual(0); | ||
| expect(dna.count('T')).toEqual(0); | ||
| }); | ||
|
|
||
| xit('counts a single repetitive nucleotide correctly.', () => { | ||
| const strand = 'CCCCC'; | ||
| expect(new Dna(strand).count(strand[0])).toEqual(strand.length); | ||
| }); | ||
|
|
||
| xit('returns the same count values steadily.', () => { | ||
| const strand = 'AACCGGTTAACCGGTT'; | ||
| const countOfFirstChar = 4; | ||
| const acid = new Dna(strand); | ||
|
|
||
| expect(acid.count(strand[0])).toEqual(countOfFirstChar); | ||
| expect(acid.count(strand[0])).toEqual(countOfFirstChar); | ||
| expect(acid.count(strand[0])).toEqual(countOfFirstChar); | ||
| }); | ||
|
|
||
| xit('counts 0 for unknown or invalid nucleotides.', () => { | ||
| const strand = 'ACGTACGT'; | ||
|
|
||
| // U-nucleotide as part of the RNA | ||
| expect(new Dna(strand).count('U')).toEqual(0); | ||
| // no-real-nucleotide | ||
| expect(new Dna(strand).count('Z')).toEqual(0); | ||
| // special-character-nucleotides | ||
| expect(new Dna(strand).count('Ä')).toEqual(0); | ||
| expect(new Dna(strand).count('×')).toEqual(0); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inserting a Unicode character by design. |
||
| // 'poocleotide' (aka a Unicode character nucleotide) | ||
| expect(new Dna(strand).count('💩')).toEqual(0); | ||
| }); | ||
|
|
||
| xit('counts 0 for nucleotide sequences, even if they match.', () => { | ||
| const strand = 'ACACACGTCACGTC'; | ||
|
|
||
| // matching AC | ||
| let includedSubStrand = strand.substr(0, 2); | ||
| expect(new Dna(strand).count(includedSubStrand)).toEqual(0); | ||
|
|
||
| // matching GTC | ||
| includedSubStrand = strand.substr(6, 3); | ||
| expect(new Dna(strand).count(includedSubStrand)).toEqual(0); | ||
|
|
||
| // non-matching GC | ||
| expect(new Dna(strand).count('GC')).toEqual(0); | ||
| }); | ||
|
|
||
| xit('counts all nucleotides correctly', () => { | ||
| const strand = 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'; | ||
| const dna = new Dna(strand); | ||
| const expected = { | ||
| A: 20, | ||
| T: 21, | ||
| C: 12, | ||
| G: 17, | ||
| }; | ||
| const testVals = { | ||
| A: dna.count('A'), | ||
| T: dna.count('T'), | ||
| C: dna.count('C'), | ||
| G: dna.count('G'), | ||
| }; | ||
|
|
||
| expect(testVals).toEqual(expected); | ||
| }); | ||
|
|
||
| xit('validates DNA for correct nucleotides', () => { | ||
| expect(() => new Dna('JOHNNYAPPLESEED')).toThrow(); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put it here, because it is related to the rna-transcriptor. That's why I let it unlock with that exercise.
The uuid I generated with https://www.uuidgenerator.net