Skip to content

Instantly share code, notes, and snippets.

@julia-
Forked from ga-wolf/readme.md
Last active August 29, 2015 14:16
Show Gist options
  • Save julia-/c384ff8b6689a7c2993a to your computer and use it in GitHub Desktop.
Save julia-/c384ff8b6689a7c2993a to your computer and use it in GitHub Desktop.

Revisions

  1. @threequal threequal renamed this gist Feb 24, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @threequal threequal created this gist Feb 24, 2015.
    61 changes: 61 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    # Nucleotide Count

    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 DNA.

    Write a class `DNA` that takes a DNA string. It should have two ways of telling us how many times each nucleotide occurs in the string: `#count(nucleotide)` and `#nucleotide_count`.

    ```ruby
    dna = DNA.new("ATGCTTCAGAAAGGTCTTACG")

    dna.count('A')
    # => 6

    dna.count('T')
    # => 6

    dna.count('G')
    # => 5

    dna.count('C')
    # => 4

    dna.count('U') # Uracil is a nucleotide that is used in RNA
    # => 0

    dna.nucleotide_counts
    # => {'A' => 6, 'T' => 6, 'G' => 5, 'C' => 4}
    ```

    The code should raise an argument error if you try to count something that isn't a nucleotide.

    ```ruby
    dna.count('S')
    # dna.rb:23:in 'count': That's not a nucleotide, silly! (ArgumentError)
    ```

    ## Sample Dataset

    ```ruby
    s = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"
    dna = DNA.new(s)
    dna.nucleotide_counts
    # => {'A' => 20, 'T' => 21, 'G' => 17, 'C' => 12}
    ```

    ## Source
    The _Calculating DNA Nucleotides_ problem at [Rosalind](http://rosalind.info/problems/dna/)