-2
$\begingroup$
(* Build all possible sequence axes *)

g =.; a =.; c =.; u =.;
s1 = Permutations [{g, a, c, u}];

(* manually pair mirrors 
{g,a,c,u}{u,c,a,g}
{g,a,u,c}{c,u,a,g}
{g,c,a,u}{u,a,c,g}
{g,c,u,a}{a,u,c,g}
{g,u,a,c}{c,a,u,g}
{g,u,c,a}{g,u,c,a}
{a,g,c,u}{u,c,g,a}
{a,g,u,c}{c,u,g,a}
{a,c,g,u}{u,g,c,a}
{a,u,g,c}{c,g,u,a}
{c,g,a,u}{u,a,g,c}
{c,a,g,u}{u,g,a,c}

manually eliminate mirrors:

{g,a,c,u},
{g,a,u,c},
{g,c,a,u},
{g,c,u,a},
{g,u,a,c},
{g,u,c,a},
{a,g,c,u},
{a,g,u,c},
{a,c,g,u},
{a,u,g,c},
{c,g,a,u},
{c,a,g,u}

*)


t =.;
c1 = Tuples[{g, a, c, u}, 3];
a1 = Table[0, {ii, 64}];
For[ii = 1, ii <= 64, ii++, 
 If[c1[[ii]] == {g, g, g}, a1[[ii]] = g];
 If[c1[[ii]] == {g, g, a}, a1[[ii]] = g];
 If[c1[[ii]] == {g, g, c}, a1[[ii]] = g];
 If[c1[[ii]] == {g, g, u}, a1[[ii]] = g];
 
 If[c1[[ii]] == {g, a, g}, a1[[ii]] = e];
 If[c1[[ii]] == {g, a, a}, a1[[ii]] = e];
 If[c1[[ii]] == {g, a, c}, a1[[ii]] = d];
 If[c1[[ii]] == {g, a, u}, a1[[ii]] = d];
 
 If[c1[[ii]] == {g, c, g}, a1[[ii]] = a];
 If[c1[[ii]] == {g, c, a}, a1[[ii]] = a];
 If[c1[[ii]] == {g, c, c}, a1[[ii]] = a];
 If[c1[[ii]] == {g, c, u}, a1[[ii]] = a];
 
 If[c1[[ii]] == {g, u, g}, a1[[ii]] = v];
 If[c1[[ii]] == {g, u, a}, a1[[ii]] = v];
 If[c1[[ii]] == {g, u, c}, a1[[ii]] = v];
 If[c1[[ii]] == {g, u, u}, a1[[ii]] = v];
 
 
 If[c1[[ii]] == {a, g, g}, a1[[ii]] = r];
 If[c1[[ii]] == {a, g, a}, a1[[ii]] = r];
 If[c1[[ii]] == {a, g, c}, a1[[ii]] = s];
 If[c1[[ii]] == {a, g, u}, a1[[ii]] = s];
 
 If[c1[[ii]] == {a, a, g}, a1[[ii]] = k];
 If[c1[[ii]] == {a, a, a}, a1[[ii]] = k];
 If[c1[[ii]] == {a, a, c}, a1[[ii]] = n];
 If[c1[[ii]] == {a, a, u}, a1[[ii]] = n];
 
 If[c1[[ii]] == {a, c, g}, a1[[ii]] = t];
 If[c1[[ii]] == {a, c, a}, a1[[ii]] = t];
 If[c1[[ii]] == {a, c, c}, a1[[ii]] = t];
 If[c1[[ii]] == {a, c, u}, a1[[ii]] = t];
 
 If[c1[[ii]] == {a, u, g}, a1[[ii]] = m];
 If[c1[[ii]] == {a, u, a}, a1[[ii]] = i];
 If[c1[[ii]] == {a, u, c}, a1[[ii]] = i];
 If[c1[[ii]] == {a, u, u}, a1[[ii]] = i];
 
 
 
 
 If[c1[[ii]] == {c, g, g}, a1[[ii]] = r];
 If[c1[[ii]] == {c, g, a}, a1[[ii]] = r];
 If[c1[[ii]] == {c, g, c}, a1[[ii]] = r];
 If[c1[[ii]] == {c, g, u}, a1[[ii]] = r];
 
 If[c1[[ii]] == {c, a, g}, a1[[ii]] = q];
 If[c1[[ii]] == {c, a, a}, a1[[ii]] = q];
 If[c1[[ii]] == {c, a, c}, a1[[ii]] = h];
 If[c1[[ii]] == {c, a, u}, a1[[ii]] = h];
 
 If[c1[[ii]] == {c, c, g}, a1[[ii]] = p];
 If[c1[[ii]] == {c, c, a}, a1[[ii]] = p];
 If[c1[[ii]] == {c, c, c}, a1[[ii]] = p];
 If[c1[[ii]] == {c, c, u}, a1[[ii]] = p];
 
 If[c1[[ii]] == {c, u, g}, a1[[ii]] = l];
 If[c1[[ii]] == {c, u, a}, a1[[ii]] = l];
 If[c1[[ii]] == {c, u, c}, a1[[ii]] = l];
 If[c1[[ii]] == {c, u, u}, a1[[ii]] = l];
 
 
 
 
 If[c1[[ii]] == {u, g, g}, a1[[ii]] = w];
 If[c1[[ii]] == {u, g, a}, a1[[ii]] = x];
 If[c1[[ii]] == {u, g, c}, a1[[ii]] = c];
 If[c1[[ii]] == {u, g, u}, a1[[ii]] = c];
 
 If[c1[[ii]] == {u, a, g}, a1[[ii]] = x];
 If[c1[[ii]] == {u, a, a}, a1[[ii]] = x];
 If[c1[[ii]] == {u, a, c}, a1[[ii]] = y];
 If[c1[[ii]] == {u, a, u}, a1[[ii]] = y];
 
 If[c1[[ii]] == {u, c, g}, a1[[ii]] = s];
 If[c1[[ii]] == {u, c, a}, a1[[ii]] = s];
 If[c1[[ii]] == {u, c, c}, a1[[ii]] = s];
 If[c1[[ii]] == {u, c, u}, a1[[ii]] = s];
 
 If[c1[[ii]] == {u, u, g}, a1[[ii]] = l];
 If[c1[[ii]] == {u, u, a}, a1[[ii]] = l];
 If[c1[[ii]] == {u, u, c}, a1[[ii]] = f];
 If[c1[[ii]] == {u, u, u}, a1[[ii]] = f]
 ]

a1
c2 = Partition[c1, 4];
a2 = Partition[a1, 4];

(* Construct an adjacency matrix from the amino acids that are now \
partitioned according to the order of the set in the Tuples call \
above. This example is the gacu sequence. 


{{g,g,g,g},
{e,e,d,d},
{a,a,a,a},
{v,v,v,v},

{r,r,s,s},
{k,k,n,n},
{t,t,t,t},
{m,i,i,i},

{r,r,r,r},
{q,q,h,h},
{p,p,p,p},
{l,l,l,l},

{w,x,c,c},
{x,x,y,y},
{s,s,s,s},
{l,l,f,f}}

The mapping is from 3D to 21D (where the most compact topology is found) and then back to 3D where the elegance can be observed for particular orderings of nucleotides along the axis of the cube in 12 isotropic configurations all having mirrors.

There are 12 horizontal 12 vertical connectors per "paragraph". The paragraphs are stacked. With the g-to-v paragraph stacked on top, the order is gacu moving down into the stack. We put in the gacu cube as the first test, and this final reading of this matrix is by order g,a,c,u.

(We need to get the 3D cube into Mathematica Manipulate where sliders along each of the three axes could be used to change the 64 lattice points displaying the 20 aa's and stops. 12^3 = 1728 different cubes.)

3rd position - 3 connections left to right each line x 16 = 48 connectors

In a Flattened string, Positions: 1<->2, 2<->3<->4, skip, 5 <-> 6, 6 <-> 7, 7[TwoWayRule]8,skip,9[TwoWayRule]10,
etc.

2nd position - 3 connections top to bottom each row x 16 = 48
connectors

1[TwoWayRule]5,5[TwoWayRule]9,9[TwoWayRule]13, (break, reindex +4)
,2[TwoWayRule]6,6[TwoWayRule]10,10[TwoWayRule]14, etc.

1st position - 3 connections per line running into page with top
paragraph stacked on top.

1[TwoWayRule]17, 17[TwoWayRule]33,33<->49,skip,etc.,
16[TwoWayRule]32,32[TwoWayRule]48, 48[TwoWayRule]64 .

Now reading in the order positions: 1, 2, 3.

THIS IS THE FIRST OF 12 CUBES: "GACU Cube".

We hypothesize from the XXXW decryption key, not used here, this is
the most compact, i.e., most self-loops.

aa1 =
 {a1[[1]] <-> a1[[17]], a1[[17]] <-> a1[[33]], a1[[33]] <-> a1[[49]],
  a1[[2]] <-> a1[[18]], a1[[18]] <-> a1[[34]], a1[[34]] <-> a1[[50]],
  a1[[3]] <-> a1[[19]], a1[[19]] <-> a1[[35]], a1[[35]] <-> a1[[51]],
  a1[[4]] <-> a1[[20]], a1[[20]] <-> a1[[36]], a1[[36]] <-> a1[[52]],
  
  a1[[5]] <-> a1[[21]], a1[[21]] <-> a1[[37]], a1[[37]] <-> a1[[53]],
  a1[[6]] <-> a1[[22]], a1[[22]] <-> a1[[38]], a1[[38]] <-> a1[[54]],
  a1[[7]] <-> a1[[23]], a1[[23]] <-> a1[[39]], a1[[39]] <-> a1[[55]],
  a1[[8]] <-> a1[[24]], a1[[24]] <-> a1[[40]], a1[[40]] <-> a1[[56]],
  
  a1[[9]] <-> a1[[25]], a1[[25]] <-> a1[[41]], a1[[41]] <-> a1[[57]],
  a1[[10]] <-> a1[[26]], a1[[26]] <-> a1[[42]], a1[[42]] <-> a1[[58]],
  a1[[11]] <-> a1[[27]], a1[[27]] <-> a1[[43]], a1[[43]] <-> a1[[59]],
  a1[[12]] <-> a1[[28]], a1[[28]] <-> a1[[44]], a1[[44]] <-> a1[[60]],
  
  a1[[13]] <-> a1[[29]], a1[[29]] <-> a1[[45]], a1[[45]] <-> a1[[61]],
  a1[[14]] <-> a1[[30]], a1[[30]] <-> a1[[46]], a1[[46]] <-> a1[[62]],
  a1[[15]] <-> a1[[31]], a1[[31]] <-> a1[[47]], a1[[47]] <-> a1[[63]],
  a1[[16]] <-> a1[[32]], a1[[32]] <-> a1[[48]], a1[[48]] <-> a1[[64]],
  
  a1[[1]] <-> a1[[5]], a1[[5]] <-> a1[[9]], a1[[9]] <-> a1[[13]],
  a1[[2]] <-> a1[[6]], a1[[6]] <-> a1[[10]], a1[[10]] <-> a1[[14]],
  a1[[3]] <-> a1[[7]], a1[[7]] <-> a1[[11]], a1[[11]] <-> a1[[15]],
  a1[[4]] <-> a1[[8]], a1[[8]] <-> a1[[12]], a1[[12]] <-> a1[[16]],
  
  a1[[17]] <-> a1[[21]], a1[[21]] <-> a1[[25]], a1[[25]] <-> a1[[29]],
  a1[[18]] <-> a1[[22]], a1[[22]] <-> a1[[26]], a1[[26]] <-> a1[[30]],
  a1[[19]] <-> a1[[23]], a1[[23]] <-> a1[[27]], a1[[27]] <-> a1[[31]],
  a1[[20]] <-> a1[[24]], a1[[24]] <-> a1[[28]], a1[[28]] <-> a1[[32]],
  
  a1[[33]] <-> a1[[37]], a1[[37]] <-> a1[[41]], a1[[41]] <-> a1[[45]],
  a1[[34]] <-> a1[[38]], a1[[38]] <-> a1[[42]], a1[[42]] <-> a1[[46]],
  a1[[35]] <-> a1[[39]], a1[[39]] <-> a1[[43]], a1[[43]] <-> a1[[47]],
  a1[[36]] <-> a1[[40]], a1[[40]] <-> a1[[44]], a1[[44]] <-> a1[[48]],
  
  a1[[49]] <-> a1[[53]], a1[[53]] <-> a1[[57]], a1[[57]] <-> a1[[61]],
  a1[[50]] <-> a1[[54]], a1[[54]] <-> a1[[58]], a1[[58]] <-> a1[[62]],
  a1[[51]] <-> a1[[55]], a1[[55]] <-> a1[[59]], a1[[59]] <-> a1[[63]],
  a1[[52]] <-> a1[[56]], a1[[56]] <-> a1[[60]], a1[[60]] <-> a1[[64]],
  
  
  
  a1[[1]] <-> a1[[2]], a1[[2]] <-> a1[[3]], a1[[3]] <-> a1[[4]],
  a1[[5]] <-> a1[[6]], a1[[6]] <-> a1[[7]], a1[[7]] <-> a1[[8]],
  a1[[9]] <-> a1[[10]], a1[[10]] <-> a1[[11]], a1[[11]] <-> a1[[12]],
  a1[[13]] <-> a1[[14]], a1[[14]] <-> a1[[15]], a1[[15]] <-> a1[[16]],
  
  a1[[17]] <-> a1[[18]], a1[[18]] <-> a1[[19]], a1[[19]] <-> a1[[20]],
  a1[[21]] <-> a1[[22]], a1[[22]] <-> a1[[23]], a1[[23]] <-> a1[[24]],
  a1[[25]] <-> a1[[26]], a1[[26]] <-> a1[[27]], a1[[27]] <-> a1[[28]],
  a1[[29]] <-> a1[[30]], a1[[30]] <-> a1[[31]], a1[[31]] <-> a1[[32]],
  
  a1[[33]] <-> a1[[34]], a1[[34]] <-> a1[[35]], a1[[35]] <-> a1[[36]],
  a1[[37]] <-> a1[[38]], a1[[38]] <-> a1[[39]], a1[[39]] <-> a1[[40]],
  a1[[41]] <-> a1[[42]], a1[[42]] <-> a1[[43]], a1[[43]] <-> a1[[44]],
  a1[[45]] <-> a1[[46]], a1[[46]] <-> a1[[47]], a1[[47]] <-> a1[[48]],
  
  a1[[49]] <-> a1[[50]], a1[[50]] <-> a1[[51]], a1[[51]] <-> a1[[52]],
  a1[[53]] <-> a1[[54]], a1[[54]] <-> a1[[55]], a1[[55]] <-> a1[[56]],
  a1[[57]] <-> a1[[58]], a1[[58]] <-> a1[[59]], a1[[59]] <-> a1[[60]],
  a1[[61]] <-> a1[[62]], a1[[62]] <-> a1[[63]], a1[[63]] <-> a1[[64]]
  
  }

Graph[aa1, VertexShapeFunction -> "Name"]

Graph of genetic code in GACU configuration

3D cube in GACU conformation

$\endgroup$
8
  • $\begingroup$ Sorry, what did I do wrong? I don't see the two figures. $\endgroup$
    – Youvan
    Jun 10, 2022 at 17:36
  • 4
    $\begingroup$ Youvan, this is completely incomprehensible. Reduce this down to a small example and explain what you need to accomplish, potentially with appropriate inputs and outputs. It will be hard to attract attention of potential helpers with just a wall of code. $\endgroup$
    – MarcoB
    Jun 10, 2022 at 17:44
  • 1
    $\begingroup$ Are you asking whether the For loop could be replaced with a function that uses pattern matching? $\endgroup$
    – lericr
    Jun 10, 2022 at 18:09
  • 2
    $\begingroup$ I presume you've looked at BioSequence[] and related functions like BioSequenceTranslate[]? $\endgroup$ Jun 10, 2022 at 19:08
  • 1
    $\begingroup$ What is the actual question here? The title seems to be completely unrelated to the body of the post. The post starts with a large unmotivated code block. This is a very bad idea. Then the first sentence starts with "The mapping is from 3D to 21D". Which mapping? You really have to invest a some more effort into formulating the question if you want to get help. And to think from the perspective of your readers. You have to provide all of the relevant information, but nothing more. $\endgroup$ Jun 11, 2022 at 6:35

1 Answer 1

1
$\begingroup$

Reading between the lines, I tend to believe OP's actual question is how to work with this large abount of data. Here are a couple of suggestions.

I'd generally suggest to use strings and not symbols to encode bases and aminoacids. This is way more robust.

You can use DeleteDuplicates to strip the duplicates among the permutations that result from simple reversal:

perm = DeleteDuplicates[
   Permutations[{"g", "a", "c", "u"}],
   Reverse[#1] == #2 &
   ];

About everything graph-related: You can make your life a bit easier by using Associations in conjunction with ReplaceAll (/.). At least, that gets you rid of the super long For-loop (which is also super inefficient; Association uses a binary search tree to do the lookups).

Triples = Tuples[{"g", "a", "c", "u"}, 3];

TripleToAminoAcid = Association[
   {"g", "g", "g"} -> "g", {"g", "g", "a"} -> "g",
   {"g", "g", "c"} -> "g", {"g", "g", "u"} -> "g",
   {"g", "a", "g"} -> "e", {"g", "a", "a"} -> "e",
   {"g", "a", "c"} -> "d", {"g", "a", "u"} -> "d",
   {"g", "c", "g"} -> "a", {"g", "c", "a"} -> "a",
   {"g", "c", "c"} -> "a", {"g", "c", "u"} -> "a",
   {"g", "u", "g"} -> "v", {"g", "u", "a"} -> "v",
   {"g", "u", "c"} -> "v", {"g", "u", "u"} -> "v",
   {"a", "g", "g"} -> "r", {"a", "g", "a"} -> "r",
   {"a", "g", "c"} -> "s", {"a", "g", "u"} -> "s",
   {"a", "a", "g"} -> "k", {"a", "a", "a"} -> "k",
   {"a", "a", "c"} -> "n", {"a", "a", "u"} -> "n",
   {"a", "c", "g"} -> "t", {"a", "c", "a"} -> "t",
   {"a", "c", "c"} -> "t", {"a", "c", "u"} -> "t",
   {"a", "u", "g"} -> "m", {"a", "u", "a"} -> "i",
   {"a", "u", "c"} -> "i", {"a", "u", "u"} -> "i",
   {"c", "g", "g"} -> "r", {"c", "g", "a"} -> "r",
   {"c", "g", "c"} -> "r", {"c", "g", "u"} -> "r",
   {"c", "a", "g"} -> "q", {"c", "a", "a"} -> "q",
   {"c", "a", "c"} -> "h", {"c", "a", "u"} -> "h",
   {"c", "c", "g"} -> "p", {"c", "c", "a"} -> "p",
   {"c", "c", "c"} -> "p", {"c", "c", "u"} -> "p",
   {"c", "u", "g"} -> "l", {"c", "u", "a"} -> "l",
   {"c", "u", "c"} -> "l", {"c", "u", "u"} -> "l",
   {"u", "g", "g"} -> "w", {"u", "g", "a"} -> "x",
   {"u", "g", "c"} -> "c", {"u", "g", "u"} -> "c",
   {"u", "a", "g"} -> "x", {"u", "a", "a"} -> "x",
   {"u", "a", "c"} -> "y", {"u", "a", "u"} -> "y",
   {"u", "c", "g"} -> "s", {"u", "c", "a"} -> "s",
   {"u", "c", "c"} -> "s", {"u", "c", "u"} -> "s",
   {"u", "u", "g"} -> "l", {"u", "u", "a"} -> "l",
   {"u", "u", "c"} -> "f", {"u", "u", "u"} -> "f"
   ];

AminoAcids = Triples /. TripleToAminoAcid;

edges = {{1, 17}, {17, 33}, {33, 49}, {2, 18}, {18, 34}, {34, 50},
   {3, 19}, {19, 35}, {35, 51}, {4, 20}, {20, 36}, {36, 52},
   {5, 21}, {21, 37}, {37, 53}, {6, 22}, {22, 38}, {38, 54},
   {7, 23}, {23, 39}, {39, 55}, {8, 24}, {24, 40}, {40, 56},
   {9, 25}, {25, 41}, {41, 57}, {10, 26}, {26, 42}, {42, 58},
   {11, 27}, {27, 43}, {43, 59}, {12, 28}, {28, 44}, {44, 60},
   {13, 29}, {29, 45}, {45, 61}, {14, 30}, {30, 46}, {46, 62},
   {15, 31}, {31, 47}, {47, 63}, {16, 32}, {32, 48}, {48, 64},
   {1, 5}, {5, 9}, {9, 13}, {2, 6}, {6, 10}, {10, 14},
   {3, 7}, {7, 11}, {11, 15}, {4, 8}, {8, 12}, {12, 16},
   {17, 21}, {21, 25}, {25, 29}, {18, 22}, {22, 26}, {26, 30},
   {19, 23}, {23, 27}, {27, 31}, {20, 24}, {24, 28}, {28, 32},
   {33, 37}, {37, 41}, {41, 45}, {34, 38}, {38, 42}, {42, 46},
   {35, 39}, {39, 43}, {43, 47}, {36, 40}, {40, 44}, {44, 48},
   {49, 53}, {53, 57}, {57, 61}, {50, 54}, {54, 58}, {58, 62},
   {51, 55}, {55, 59}, {59, 63}, {52, 56}, {56, 60}, {60, 64},
   {1, 2}, {2, 3}, {3, 4}, {5, 6}, {6, 7}, {7, 8},
   {9, 10}, {10, 11}, {11, 12}, {13, 14}, {14, 15}, {15, 16},
   {17, 18}, {18, 19}, {19, 20}, {21, 22}, {22, 23}, {23, 24},
   {25, 26}, {26, 27}, {27, 28}, {29, 30}, {30, 31}, {31, 32},
   {33, 34}, {34, 35}, {35, 36}, {37, 38}, {38, 39}, {39, 40},
   {41, 42}, {42, 43}, {43, 44}, {45, 46}, {46, 47}, {47, 48},
   {49, 50}, {50, 51}, {51, 52}, {53, 54}, {54, 55}, {55, 56},
   {57, 58}, {58, 59}, {59, 60}, {61, 62}, {62, 63}, {63, 64}
   };

IndexToAminoAcid = AssociationThread[Range[Length[Triples]], Values[TripleToAminoAcid]];
G = Graph[UndirectedEdge @@@ (edges /. IndexToAminoAcid), VertexShapeFunction -> "Name"]
$\endgroup$
5
  • $\begingroup$ Thank you Henrik! Yes, that would have been a better way to ask. Your solution also makes this process more understandable - perhaps to someone in group theory. $\endgroup$
    – Youvan
    Jun 11, 2022 at 11:41
  • $\begingroup$ If someone wants to use this, place: IndexToAminoAcid = AssociationThread[Range[Length[AminoAcids]], AminoAcids]right above the final command to Graph $\endgroup$
    – Youvan
    Jun 11, 2022 at 15:59
  • 1
    $\begingroup$ I realize now that IndexToAminoAcid was missing. It's now added. $\endgroup$ Jun 11, 2022 at 17:22
  • 2
    $\begingroup$ Since I mentioned BioSequence[] in the comments: TripleToAminoAcid = Association[Table[With[{cc = BioSequence["RNA", StringJoin[codon]]}, Characters[ToLowerCase[cc["SequenceString"]]] -> StringReplace[ToLowerCase[BioSequenceTranslate[cc] @ "SequenceString"], "." -> "x"]], {codon, Tuples[{"G", "A", "C", "U"}, 3]}]] (cc @Youvan) $\endgroup$ Jun 11, 2022 at 17:30
  • 2
    $\begingroup$ (or if you're not afraid of entities: KeyMap[ToLowerCase, Map[StringReplace[ToLowerCase[#], "*" -> "x"] &, EntityValue[Entity["GeneticTranslationTable", "Standard"], "CodonTranslations"]]]) $\endgroup$ Jun 11, 2022 at 17:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.