Sha256: f8a3916f5ef986ad7e312b85cd23acb84ff2ea5b57d964c06d6de96b32dbe8bf

Contents?: true

Size: 704 Bytes

Versions: 326

Compression:

Stored size: 704 Bytes

Contents

defmodule NucleotideCount do
  @nucleotides [?A, ?C, ?G, ?T]

  @doc """
  Counts individual nucleotides in a NucleotideCount strand.

  ## Examples

  iex> NucleotideCount.count('AATAA', ?A)
  4

  iex> NucleotideCount.count('AATAA', ?T)
  1
  """

  def count(strand, nucleotide) when nucleotide in(@nucleotides) do
    Enum.count strand, &(&1 == nucleotide)
  end
  def count(_strand, _nucleotide), do: raise ArgumentError

  @doc """
  Returns a summary of counts by nucleotide.

  ## Examples

  iex> NucleotideCount.nucleotide_counts('AATAA')
  %{?A => 4, ?T => 1, ?C => 0, ?G => 0}
  """

  def histogram(strand) do
    Enum.map(@nucleotides, &{&1, count(strand, &1)}) |> Enum.into(%{})
  end
end

Version data entries

326 entries across 326 versions & 1 rubygems

Version Path
trackler-2.2.1.109 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.108 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.107 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.106 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.105 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.104 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.103 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.102 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.101 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.100 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.99 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.98 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.97 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.96 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.95 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.94 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.93 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.92 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.91 tracks/elixir/exercises/nucleotide-count/example.exs
trackler-2.2.1.90 tracks/elixir/exercises/nucleotide-count/example.exs