Created
April 23, 2018 22:54
-
-
Save krlsdu/ce7d55d751d41a07d98e74889f58fc6c to your computer and use it in GitHub Desktop.
rosalinda_computing_GC_content
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
defmodule Gc do | |
def gc_content(dataset) do | |
map = | |
String.replace(dataset, "\n", "") | |
|> String.split(">", trim: true) | |
|> Enum.map(fn x -> String.split_at(x, 13) end) | |
element = Enum.into(map, %{}) | |
element_lenght = Enum.map(element, fn {k, v} -> {k, v, String.length(v)} end) | |
string_splited = | |
Enum.map(element_lenght, fn {k, v, l} -> {k, String.split(v, "", trim: true), l} end) | |
sum_g_c = | |
Enum.map(string_splited, fn {k, v, l} -> | |
{k, v, l, Enum.count(v, fn v -> v == "G" end) + Enum.count(v, fn v -> v == "C" end)} | |
end) | |
percentage = | |
Enum.map(sum_g_c, fn {k, v, l, quantity_gc} -> {k, v, l, quantity_gc * 100 / l} end) | |
default_error = | |
Enum.map(percentage, fn {k, _, _, percent} -> {k, Float.round(percent, 7)} end) | |
keywords = Enum.into(default_error, %{}) | |
tuple = Enum.max_by(keywords, fn {_, v} -> v end) | |
listed = Tuple.to_list(tuple) | |
Enum.map(listed, fn x -> "\n#{x}" end) | |
|> to_string | |
|> String.trim() | |
|> IO.puts() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment