I am a Bioinformatician and recently started picking up python and i am interested in plotting a Graph.I have a set of nodes and edges.
nodes
set(['ACG', 'ATC', 'GAT', 'CGG', 'CGT', 'AAT', 'ATT', 'GGA', 'TTC', 'CCG', 'TCC', 'GAA'])
edges
[('ACG', 'CGG'), ('CGG', 'GGA'), ('GGA', 'GAA'), ('GAA', 'AAT'), ('AAT', 'ATC'), ('GAT', 'ATT'), ('ATT', 'TTC'), ('TTC', 'TCC'), ('TCC', 'CCG'), ('CCG', 'CGT')]
When i construct the normal graph using above information i get 12 nodes and 10 edges i.e. two disconnected graphs using below function.
def visualize_de_bruijn():
""" Visualize a directed multigraph using graphviz """
nodes = set(['ACG', 'ATC', 'GAT', 'CGG', 'CGT', 'AAT', 'ATT', 'GGA', 'TTC', 'CCG', 'TCC', 'GAA'])
edges = [('ACG', 'CGG'), ('CGG', 'GGA'), ('GGA', 'GAA'), ('GAA', 'AAT'), ('AAT', 'ATC'), ('GAT', 'ATT'), ('ATT', 'TTC'), ('TTC', 'TCC'), ('TCC', 'CCG'), ('CCG', 'CGT')]
dot_str = 'digraph "DeBruijn graph" {\n'
for node in nodes:
dot_str += ' %s [label="%s"] ;\n' % (node, node)
for src, dst in edges:
dot_str += ' %s -> %s ;\n' % (src, dst)
return dot_str + '}\n'
In Biology we have this concept of complementary base pairing where A=T ,T=A ,G=C, and C=G. So complimentary of 'ACG' is 'TGC' and reverse complimentary of 'ACG' = 'CGT' i.e we reverse the complement.
In the nodes list we see 12 nodes in which 6 nodes are reverse complement of each other i.e.
ReverseComplement('ACG') = CGT
ReverseComplement('CGG') = CCG
ReverseComplement('GGA') = TCC
ReverseComplement('GAA') = TTC
ReverseComplement('AAT') = ATT
ReverseComplement('ATC') = GAT
Now i would like to construct a graph where there are six nodes, a node should have its own value and its reverse complement value and total 10 edges i.e. graph should not be disconnected. How to visualize this graph using graphviz in python.? If there is anything else other than graphviz which can help me visualize this type of graph please let me know .?