Esempio n. 1
0
def parse_dot(args, files):
    if len(files) == 0:
        return None

    content = files[0].read()
    g = pydotplus.parse_dot_data(content)

    nodes = [_to_node(n) for n in g.get_nodes()]
    edges = [_to_edge(e) for e in g.get_edges()]

    return dict(name=_resolve_name(args, files[0]), nodes=nodes, edges=edges)
Esempio n. 2
0
def parse_dot(args, files):
  if len(files) == 0:
    return None

  content = files[0].read()
  g = pydotplus.parse_dot_data(content)

  nodes = [_to_node(n) for n in g.get_nodes()]
  edges = [_to_edge(e) for e in g.get_edges()]

  return dict(name=_resolve_name(args, files[0]), nodes=nodes, edges=edges)
Esempio n. 3
0
def import_file(file):
  importer.delete_all()
  # fix dot file: don't like =\n -> replace by =""\n
  with open(file, 'r') as f:
    content = f.read()
    g = pydotplus.parse_dot_data(content)

  for n in g.get_nodes():
    id = clean(n.get_name())
    attrs = n.get_attributes()
    targetclass = clean(attrs['targetclass'])
    geneids = clean(attrs['geneids'])
    color = clean(attrs['color'])
    label = clean(attrs['label'])
    labels = ['_Network_Node']
    if len(targetclass) > 0:
      labels.append(targetclass.replace(' ', '_'))
    importer.add_node(labels, id, dict(color=color, name=label, geneids=geneids))

  importer.done_nodes()

  for link in g.get_edges():
    source = clean(link.get_source())
    target = clean(link.get_destination())
    attrs = n.get_attributes()
    distance = float(attrs.get('distance', 0))
    weight = float(attrs.get('weight', 0))
    importer.add_edge('LinkTo', source, target, dict(_isNetworkEdge=True, distance=distance, weight=weight))
    # add reverse edge
    if args.undirected:
      importer.add_edge('LinkTo', target, source, dict(_isNetworkEdge=True, distance=distance, weight=weight))

  if args.sets:
    # create set relationship by targetclass
    for k, g in itertools.groupby(sorted(g.get_nodes(), key=lambda x: x.get_label('targetclass')),
                                  lambda x: x.get_label('targetclass')):
      importer.add_node(['_Set_Node'], k, {'name': k})
      groups = list(g)
      for node in groups:
        id = clean(node.get_name())
        importer.add_edge('ConsistsOf', k, id, dict(), '_Set_Node')
        # for node2 in groups:
        #  id2 = node2.get_name()
        #  if id != id2:
        #    importer.add_edge('Edge', id, id2, dict(_isSetEdge=True,targetclass=k))

  importer.finish()
Esempio n. 4
0
def import_file(file):
  importer.delete_all()
  #fix dot file: don't like =\n -> replace by =""\n
  with open(file,'r') as f:
    content = f.read()
    g = pydotplus.parse_dot_data(content)

  for n in g.get_nodes():
    id = clean(n.get_name())
    attrs = n.get_attributes()
    targetclass = clean(attrs['targetclass'])
    geneids = clean(attrs['geneids'])
    color = clean(attrs['color'])
    label = clean(attrs['label'])
    labels = ['_Network_Node']
    if len(targetclass) > 0:
      labels.append(targetclass.replace(' ','_'))
    importer.add_node(labels, id, dict(color=color,name=label,geneids=geneids))

  importer.done_nodes()

  for link in g.get_edges():
    source = clean(link.get_source())
    target = clean(link.get_destination())
    attrs = n.get_attributes()
    distance = float(attrs.get('distance',0))
    weight = float(attrs.get('weight',0))
    importer.add_edge('LinkTo', source, target, dict(_isNetworkEdge=True,distance=distance,weight=weight))
    #add reverse edge
    if args.undirected:
      importer.add_edge('LinkTo', target, source, dict(_isNetworkEdge=True,distance=distance,weight=weight))

  if args.sets:
    #create set relationship by targetclass
    for k, g in itertools.groupby(sorted(g.get_nodes(),key=lambda x : x.get_label('targetclass')), lambda x : x.get_label('targetclass')):
      importer.add_node(['_Set_Node'], k, {'name': k})
      groups = list(g)
      for node in groups:
        id = clean(node.get_name())
        importer.add_edge('ConsistsOf', k, id, dict(),'_Set_Node')
        #for node2 in groups:
        #  id2 = node2.get_name()
        #  if id != id2:
        #    importer.add_edge('Edge', id, id2, dict(_isSetEdge=True,targetclass=k))

  importer.finish()