Hi everyone
I'm trying to generate a planar graph of amino acids, based on their
properties, something like this:
http://www.russelllab.org/aas/other_images/lb3.gif
I want them to be something like this (I know there is a solution already,
but this is just an example at the moment, if I can't solve this problem, I
can't move forward).
Some amino acids should be close to each other, because they are in the
same group. The problem is, that they can belong to multiple groups, so
just grouping doesn't work. I've seen the fruchterman_reingold_layout and
it's two parameters:
*a* : float (optional, default:)
Attracting force between adjacent vertices.
*r* : float (optional, default: 1.0)
Repulsive force between vertices.
The problem is, that I think I would need the opposite. Repulsive force
between the connected vertices, and attractive force between the vertices
in general. The question is, can I do that somehow? Or is there another way?
This is something I've done to play with until now, attached
Thank you
Csongor
from graph_tool.all import *
class AminoAcid:
def __init__(self, name, polar, hydrophobic, charged, positive, negative, aliphatic, aromatic, size, special):
self.Name = name
self.Polar = polar
self.Hydrophobic = hydrophobic
self.Charged = charged
self.Positive = positive
self.Negative = negative
self.Aliphatic = aliphatic
self.Aromatic = aromatic
self.Size = size
self.Special = special
AA = ['ALA', 'CYS', 'ASP', 'GLU', 'PHE', 'GLY', 'HIS', 'ILE', 'LYS', 'LEU', 'MET',
'ASN', 'PRO', 'GLN', 'ARG', 'SER', 'THR', 'SEC', 'VAL', 'TRP', 'TYR']
Aa = ['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'Y']
Polar = [True, False, True, True, False, False, True, False, True, False, False, #Note Cis is taken as the form where it forms SS bond,
True, False, True, True, True, True, True, False, True, True] #and Sec is taken as Cis where there is no SS bond, just SH, or SeH
Hydrophobic = [True, True, False, False, True, True, True, True, True, True, True,
False, False, False, False, False, True, True, True, True, True]
Charged = [False, False, True, True, False, False, True, False, True, False, False,
False, False, False, True, False, False, False, False, False, False]
Aliphatic = [False, False, False, False, False, False, False, True, False, True,
False, False, False, False, False, False, False, False, True, False, False]
Aromatic = [False, False, False, False, True, False, True, False, False, False, False,
False, False, False, False, False, False, False, False, True, True]
Positive = [False, False, False, False, False, False, True, False, True, False, False,
False, False, False, True, False, False, False, False, False, False]
Negative = [False, False, True, True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False]
Size = [0, 1, 2, 2, 2, 0, 2, 2, 2, 2, 2, 1, 1, 2, 2, 0, 1, 0, 2, 2, 2]
Special = [False, False, False, False, False, False, False, False, False, False, False,
False, True, False, False, False, False, True, False, False, False]
AAList = []
for a in range(len(AA)):
aminoacid = AminoAcid(Aa[a], Polar[a], Hydrophobic[a], Charged[a], Positive[a], Negative[a],
Aliphatic[a], Aromatic[a], Size[a], Special[a])
AAList.append(aminoacid)
G = Graph(directed=False)
VList = G.add_vertex(len(AA))
VProp_Name = G.new_vertex_property("string")
for p, a in enumerate(AAList):
VProp_Name[G.vertex(p)] = a.Name
Adjacency_matrix = []
Adjacency_matrix_inverse = []
for i in range(len(AAList)):
line = []
for j in range(len(AAList)):
line.append(0)
Adjacency_matrix.append(line)
for i in range(len(AAList)):
line = []
for j in range(len(AAList)):
line.append(0)
Adjacency_matrix_inverse.append(line)
for p1, a1 in enumerate(AAList):
for p2, a2 in enumerate(AAList):
if p1 > p2:
if a1.Size == a2.Size:
Adjacency_matrix[p1][p2] += 1
#'''
for p1, a1 in enumerate(AAList):
for p2, a2 in enumerate(AAList):
if p1 > p2:
if a1.Polar and a2.Polar:
Adjacency_matrix[p1][p2] += 1
elif not a1.Polar and not a2.Polar:
Adjacency_matrix_inverse[p1][p2] += 1
#'''
for p1, a1 in enumerate(AAList):
for p2, a2 in enumerate(AAList):
if p1 > p2:
if a1.Hydrophobic and a2.Hydrophobic:
Adjacency_matrix[p1][p2] += 1
elif not a1.Hydrophobic and not a2.Hydrophobic:
Adjacency_matrix_inverse[p1][p2] += 1
'''
for p1, a1 in enumerate(AAList):
for p2, a2 in enumerate(AAList):
if p1 > p2:
if a1.Charged and a2.Charged:
Adjacency_matrix[p1][p2] += 1
elif not a1.Charged and not a2.Charged:
Adjacency_matrix_inverse[p1][p2] += 1
for p1, a1 in enumerate(AAList):
for p2, a2 in enumerate(AAList):
if p1 > p2:
if a1.Positive and a2.Positive:
Adjacency_matrix[p1][p2] += 1
elif not a1.Positive and not a2.Positive:
Adjacency_matrix_inverse[p1][p2] += 1
for p1, a1 in enumerate(AAList):
for p2, a2 in enumerate(AAList):
if p1 > p2:
if a1.Negative and a2.Negative:
Adjacency_matrix[p1][p2] += 1
elif not a1.Negative and not a2.Negative:
Adjacency_matrix_inverse[p1][p2] += 1
for p1, a1 in enumerate(AAList):
for p2, a2 in enumerate(AAList):
if p1 > p2:
if a1.Aliphatic and a2.Aliphatic:
Adjacency_matrix[p1][p2] += 1
elif not a1.Aliphatic and not a2.Aliphatic:
Adjacency_matrix_inverse[p1][p2] += 1
for p1, a1 in enumerate(AAList):
for p2, a2 in enumerate(AAList):
if p1 > p2:
if a1.Aromatic and a2.Aromatic:
Adjacency_matrix[p1][p2] += 1
elif not a1.Aromatic and not a2.Aromatic:
Adjacency_matrix_inverse[p1][p2] += 1
for p1, a1 in enumerate(AAList):
for p2, a2 in enumerate(AAList):
if p1 > p2:
if a1.Special and a2.Special:
Adjacency_matrix[p1][p2] += 1
elif not a1.Special and not a2.Special:
Adjacency_matrix_inverse[p1][p2] += 1
#'''
VProp_Group = G.new_vertex_property("int32_t")
for p, aa in enumerate(AAList):
VProp_Group[G.vertex(p)] = aa.Size
EProp_Weight = G.new_edge_property("float")
for i in range(len(AAList)):
for j in range(len(AAList)):
if Adjacency_matrix[i][j] > 0:
e = G.add_edge(i, j)
EProp_Weight[G.edge(i, j)] = 1.0 / float(Adjacency_matrix[i][j]) * 10
#if Adjacency_matrix_inverse[i][j] > 0:
# e = G.add_edge(i, j)
pos = graph_tool.draw.arf_layout(G, max_iter=0)
#pos = graph_tool.draw.sfdp_layout(G, groups = VProp_Group)
pos = graph_tool.draw.fruchterman_reingold_layout(G, pos = pos, weight = EProp_Weight, n_iter=1000)
Drawing = graph_tool.draw.graph_draw(G, pos = pos, vertex_text=VProp_Name, vertex_font_size=10)
_______________________________________________
graph-tool mailing list
[email protected]
https://lists.skewed.de/mailman/listinfo/graph-tool