Пример #1
0
def get_drug_scores(
    graph: BELGraph,
    dtis: Mapping[str, List[Gene]],
    preprocess_graph: bool = True,
) -> Iterable[Tuple[str, str, float]]:
    """Get drug scores for the given graph."""
    if preprocess_graph:
        logger.info('preprocessing %s', graph)
        graph = neurommsig_graph_preprocessor(graph)

    logger.info('stratifying %s', graph)
    subgraphs = get_subgraphs_by_annotation(graph,
                                            annotation='Subgraph',
                                            sentinel='UNDEFINED')

    logger.info('running subgraphs x drugs for %s', graph)
    it = itt.product(sorted(subgraphs), sorted(dtis))
    it = tqdm(it, total=len(subgraphs) * len(dtis), desc='Calculating scores')

    def get_score(s: str, d: str) -> Optional[float]:
        """Get the score for the given subgraph and drug."""
        return get_neurommsig_score(subgraphs[s], dtis[d])

    for subgraph_name, drug in it:
        score = get_score(subgraph_name, drug)

        if score is None or score == 0.0:
            continue

        yield drug, subgraph_name, score
Пример #2
0
    def test_get_subgraphs_by_annotation_with_sentinel(self):
        sentinel = n()
        subgraphs = get_subgraphs_by_annotation(self.graph, annotation='subgraph', sentinel=sentinel)

        self.assertEqual(3, len(subgraphs))
        self.assertIn(Entity(namespace='subgraph', identifier='1'), subgraphs)
        self.assertIn(Entity(namespace='subgraph', identifier='2'), subgraphs)
        self.assertIn(sentinel, subgraphs)
Пример #3
0
    def test_get_subgraphs_by_annotation_with_sentinel(self):
        sentinel = n()
        subgraphs = get_subgraphs_by_annotation(self.graph,
                                                annotation='subgraph',
                                                sentinel=sentinel)

        self.assertEqual(3, len(subgraphs))
        self.assertIn('1', subgraphs)
        self.assertIn('2', subgraphs)
        self.assertIn(sentinel, subgraphs)
Пример #4
0
    def test_get_subgraphs_by_annotation(self):

        subgraphs = get_subgraphs_by_annotation(self.graph,
                                                annotation='subgraph')

        self.assertEqual(2, len(subgraphs))
        self.assertIn('1', subgraphs)
        self.assertIn('2', subgraphs)

        subgraph_1 = subgraphs['1']
        self.assertIsInstance(subgraph_1, BELGraph)

        self.assertIn('test', subgraph_1.namespace_url)
        self.assertIn('subgraph', subgraph_1.annotation_url)

        self.assertIn(a, subgraph_1)
        self.assertIn(FUNCTION, subgraph_1.node[a.as_tuple()])
        self.assertEqual(PROTEIN, subgraph_1.node[a.as_tuple()][FUNCTION])
        self.assertIn(b, subgraph_1)
        self.assertIn(c, subgraph_1)
        self.assertIn(d, subgraph_1)

        self.assertIn(b.as_tuple(), subgraph_1[a.as_tuple()])
        self.assertIn(c.as_tuple(), subgraph_1[a.as_tuple()])
        self.assertIn(d.as_tuple(), subgraph_1[b.as_tuple()])
        self.assertNotIn(d.as_tuple(), subgraph_1[a.as_tuple()])
        self.assertNotIn(d.as_tuple(), subgraph_1[c.as_tuple()])

        subgraph_2 = subgraphs['2']
        self.assertIsInstance(subgraph_2, BELGraph)

        self.assertIn('test', subgraph_2.namespace_url)
        self.assertIn('subgraph', subgraph_2.annotation_url)

        self.assertIn(a, subgraph_2)
        self.assertIn(b, subgraph_2)
        self.assertNotIn(c, subgraph_2)
        self.assertIn(d, subgraph_2)

        self.assertIn(b.as_tuple(), subgraph_2[a.as_tuple()])
        self.assertNotIn(c.as_tuple(), subgraph_2[a.as_tuple()])
        self.assertIn(d.as_tuple(), subgraph_2[b.as_tuple()])
        self.assertIn(d.as_tuple(), subgraph_2[a.as_tuple()])
Пример #5
0
    def test_get_subgraphs_by_annotation(self):
        subgraphs = get_subgraphs_by_annotation(self.graph,
                                                annotation='subgraph')

        self.assertEqual(2, len(subgraphs))
        self.assertIn('1', subgraphs)
        self.assertIn('2', subgraphs)

        subgraph_1 = subgraphs['1']
        self.assertIsInstance(subgraph_1, BELGraph)

        self.assertIn('test', subgraph_1.namespace_url)
        self.assertIn('subgraph', subgraph_1.annotation_url)

        self.assertIn(a, subgraph_1)
        self.assertIn(b, subgraph_1)
        self.assertIn(c, subgraph_1)
        self.assertIn(d, subgraph_1)

        self.assertIn(b, subgraph_1[a])
        self.assertIn(c, subgraph_1[a])
        self.assertIn(d, subgraph_1[b])
        self.assertNotIn(d, subgraph_1[a])
        self.assertNotIn(d, subgraph_1[c])

        subgraph_2 = subgraphs['2']
        self.assertIsInstance(subgraph_2, BELGraph)

        self.assertIn('test', subgraph_2.namespace_url)
        self.assertIn('subgraph', subgraph_2.annotation_url)

        self.assertIn(a, subgraph_2)
        self.assertIn(b, subgraph_2)
        self.assertNotIn(c, subgraph_2)
        self.assertIn(d, subgraph_2)

        self.assertIn(b, subgraph_2[a])
        self.assertNotIn(c, subgraph_2[a])
        self.assertIn(d, subgraph_2[b])
        self.assertIn(d, subgraph_2[a])