Skip to content

Commit

Permalink
add byte to codon converter
Browse files Browse the repository at this point in the history
  • Loading branch information
0xF6 committed Jul 29, 2019
1 parent 11ead1d commit 748b88f
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/byte2dnk/Host.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace byte2dnk
{
using System;
using System.Drawing;
using System.Linq;
using System.Text;
using Algorithm;
using Pastel;
using static Log;
internal static class Host
{
public static void Main(string[] args)
{
//if(!args.Any())
// Error($"No file specified.", 1);
StringToCodons();
}


public static void StringToCodons()
{
var str = "Влад Гей";

Console.OutputEncoding = Encoding.Unicode;

Info($"String: '{str.Pastel(Color.Gray)}', Length: {str.Length}");
var asw = HexCodon.Encode(Encoding.UTF8.GetBytes(str)).Select(x =>
$"{x.Acid.Symbol.ToString().Pastel(getColorByAminoAcidsState(x.Acid.State))}");
Info($"acid map: {string.Join(" ", asw)}");
Info($"");
Info($"Detail table:");

foreach (var codon in HexCodon.Encode(Encoding.UTF8.GetBytes(str)))
Info($"\t{codon.Value.Pastel(getColorByAminoAcidsState(codon.Acid.State))} {codon.Acid.FullName}/{codon.Acid.Symbol}");
Console.WriteLine();
}
}
}
38 changes: 38 additions & 0 deletions src/byte2dnk/Log.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace byte2dnk
{
using System;
using System.Drawing;
using System.Molecular.Acid;
using Pastel;
using static System.Console;

internal static class Log
{
public static void Error(string msg, int? exitCode)
{
WriteLine($"[{"b2d".Pastel(Color.Coral)}][{"ERR".Pastel(Color.Red)}]: {msg}");
if(exitCode is null)
return;
Environment.Exit(exitCode.Value);
}
public static void Warn(string msg)
{
WriteLine($"[{"b2d".Pastel(Color.Coral)}][{"WRN".Pastel(Color.Orange)}]: {msg}");
}
public static void Info(string msg)
{
WriteLine($"[{"b2d".Pastel(Color.Coral)}]: {msg}");
}

public static Color getColorByAminoAcidsState(AAS state) =>
state switch
{
AAS.Acidic => Color.MediumPurple,
AAS.Basic => Color.CornflowerBlue,
AAS.NonPolar => Color.Yellow,
AAS.Polar => Color.MediumSeaGreen,
AAS.Terminator => Color.DarkRed,
_ => Color.White,
};
}
}
16 changes: 16 additions & 0 deletions src/byte2dnk/byte2dnk.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pastel" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\System.Molecular\System.Molecular.csproj" />
</ItemGroup>

</Project>

0 comments on commit 748b88f

Please sign in to comment.