示例#1
0
    def to_printable_graph(self, enrichment, graph):
        viz_graph = DiGraph()
        viz_graph.attrs["defaultnodesize"] = "labelsize"
        viz_graph.attrs["label"] = str(enrichment)

        entry_labels = {}

        for entry in enrichment.entries:
            if entry.p_value < self.min_p:
                self.min_p = entry.p_value
            if entry.p_value > self.max_p:
                self.max_p = entry.p_value

        for entry in enrichment.entries:
            new_label = self.entry_to_label(entry)
            viz_graph.add_node(new_label, self.to_printable_data(entry))
            entry_labels[entry.id] = new_label

        for label, node in graph.nodes.items():
            if label not in entry_labels:
                new_label = self.term_to_label(node.data)
                viz_graph.add_node(new_label,
                                   self.term_to_printable(node.data))
                entry_labels[label] = new_label

        for label, u in graph.nodes.items():
            for edge in u.succ:
                viz_graph.add_edge(entry_labels[label],
                                   entry_labels[edge.to_node.label])

        return viz_graph
示例#2
0
 def to_printable_graph(self, enrichment, graph):
     viz_graph = DiGraph()
     viz_graph.attrs["defaultnodesize"] = "labelsize"
     viz_graph.attrs["label"] = str(enrichment)
     
     entry_labels = {}
     
     for entry in enrichment.entries:
         if entry.p_value < self.min_p:
             self.min_p = entry.p_value
         if entry.p_value > self.max_p:
             self.max_p = entry.p_value
     
     for entry in enrichment.entries:
         new_label = self.entry_to_label(entry)
         viz_graph.add_node(new_label, self.to_printable_data(entry))
         entry_labels[entry.id] = new_label
     
     for label, node in graph.nodes.items():
         if label not in entry_labels:
             new_label = self.term_to_label(node.data)
             viz_graph.add_node(new_label, self.term_to_printable(node.data))
             entry_labels[label] = new_label
     
     for label, u in graph.nodes.items():
         for edge in u.succ:
             viz_graph.add_edge(entry_labels[label], entry_labels[edge.to_node.label])
     
     return viz_graph
    def test_write(self):
        correct_output_a = """graph [
  directed 1
  node [
    id 0
    label "1"
    a 1
  ]
  node [
    id 1
    label "2"
  ]
  edge [
    source 0
    target 1
    x "x"
  ]
  edge [
    source 1
    target 0
    label "zzzz"
  ]
]"""
        correct_output_b = """graph [
  directed 1
  node [
    id 0
    label "2"
  ]
  node [
    id 1
    label "1"
    a 1
  ]
  edge [
    source 1
    target 0
    x "x"
  ]
  edge [
    source 0
    target 1
    label "zzzz"
  ]
]"""
        out = StringIO()
        writer = GmlWriter(out)
        graph = DiGraph()
        graph.add_node(1, {'a': 1})
        graph.add_edge(1, 2, {'x': 'x'})
        graph.add_edge(2, 1, "zzzz")
        writer.write(graph)
        self.assertIn(out.getvalue(), set([correct_output_a,
                                           correct_output_b]))
    def test_write(self):
        correct_output_a = """graph [
  directed 1
  node [
    id 0
    label "1"
    a 1
  ]
  node [
    id 1
    label "2"
  ]
  edge [
    source 0
    target 1
    x "x"
  ]
  edge [
    source 1
    target 0
    label "zzzz"
  ]
]"""
        correct_output_b =  """graph [
  directed 1
  node [
    id 0
    label "2"
  ]
  node [
    id 1
    label "1"
    a 1
  ]
  edge [
    source 1
    target 0
    x "x"
  ]
  edge [
    source 0
    target 1
    label "zzzz"
  ]
]"""
        out = StringIO()
        writer = GmlWriter(out)
        graph = DiGraph()
        graph.add_node(1, {'a' : 1 })
        graph.add_edge(1, 2, {'x' : 'x'})
        graph.add_edge(2, 1, "zzzz")
        writer.write(graph)
        self.assertIn(out.getvalue(), set([correct_output_a, correct_output_b]))
示例#5
0
 def test__get_reachable(self):
     
     g = DiGraph([(1,2), (2,3), (3,4), (3,5), (5,2), (5,6), (6,8), (6,7), (2,9), (9,2)])
     reachable_from_2 = g._get_reachable(g.get_node(2))
     expected = ([], set([2, 3, 4, 5, 6, 7, 8, 9]))
     self.assertEqual(expected, reachable_from_2)
     reachable_from_6 = g._get_reachable(g.get_node(6))
     expected = ([], set([8, 7]))
     self.assertEqual(expected, reachable_from_6)
     # Found cycles
     expected =  [[2, 9], [2, 5, 3]]
     self.assertEqual(expected, g.cycles)
示例#6
0
文件: Data.py 项目: juliahi/biopython
 def __init__(self):
     DiGraph.__init__(self)
     self.typedefs = {}
     self.synonyms = {}
示例#7
0
文件: Data.py 项目: umath92/biopython
 def __init__(self):
     DiGraph.__init__(self)
     self.typedefs = {}
     self.synonyms = {}
    def test_write(self):
        correct_output = """graph [
  directed 1
  node [
    id 0
    label "1"
    a 1
    abb "[1, 2]"
    bb 2
  ]
  node [
    id 1
    label "2"
  ]
  node [
    id 2
    label "3"
  ]
  node [
    id 3
    label "4"
  ]
  node [
    id 4
    label "5"
  ]
  edge [
    source 0
    target 1
  ]
  edge [
    source 0
    target 3
    x "x"
  ]
  edge [
    source 1
    target 2
  ]
  edge [
    source 2
    target 3
  ]
  edge [
    source 2
    target 4
  ]
  edge [
    source 4
    target 1
    label "zzzz"
  ]
]"""
        out = StringIO()
        writer = GmlWriter(out)
        graph = DiGraph([(1,2), (2,3), (3,4), (3,5)])
        graph.update_node(1, {'a' : 1, 'bb' : 2, 'abb' : [1, 2] })
        graph.add_edge(1, 4, {'x' : 'x'})
        graph.add_edge(5, 2, "zzzz")
        writer.write(graph)
        self.assertEqual(correct_output, out.getvalue())