Пример #1
0
    def _get_statements(self):
        import pybel
        import requests
        from indra.sources.bel import process_pybel_graph
        logger.info('Processing CONIB from web')
        url = 'https://github.com/pharmacome/conib/raw/master/conib' \
            '/_cache.bel.nodelink.json'
        res_json = requests.get(url).json()
        graph = pybel.from_nodelink(res_json)
        # Get INDRA statements
        pbp = process_pybel_graph(graph)

        # Fix and issue with PMID spaces
        for stmt in pbp.statements:
            for ev in stmt.evidence:
                if ev.pmid:
                    ev.pmid = ev.pmid.strip()
                if ev.text_refs.get('PMID'):
                    ev.text_refs['PMID'] = ev.text_refs['PMID'].strip()

        logger.info('Expanding evidences and deduplicating')
        filtered_stmts = [s for s in _expanded(pbp.statements)]
        unique_stmts, _ = extract_duplicates(filtered_stmts,
                                             KeyFunc.mk_and_one_ev_src)
        return unique_stmts
Пример #2
0
def upload_json(connection: str,
                user_id: int,
                payload: Dict,
                public: bool = False):
    """Receive and process a JSON serialized BEL graph.

    :param connection: A connection to build the manager
    :param user_id: the ID of the user to associate with the graph
    :param payload: JSON dictionary for :func:`pybel.from_json`
    :param public: Should the network be made public?
    """
    manager = WebManager(connection=connection)
    user = manager.get_user_by_id(user_id)

    try:
        graph = from_nodelink(payload)
    except Exception:
        celery_logger.exception('unable to parse JSON')
        return -1

    public = current_app.config.get('DISALLOW_PRIVATE') or public

    try:
        insert_graph(manager=manager, graph=graph, user=user, public=public)
    except Exception:
        celery_logger.exception('unable to insert graph')
        manager.session.rollback()
        return -2

    return 0
Пример #3
0
 def test_slushy_json(self):
     graph_json = to_nodelink(self.slushy_graph)
     graph = from_nodelink(graph_json)
     self.bel_slushy_reconstituted(graph, check_warnings=False)
Пример #4
0
 def test_thorough_json(self):
     graph_json_dict = to_nodelink(self.thorough_graph)
     graph = from_nodelink(graph_json_dict)
     self.bel_thorough_reconstituted(graph)
Пример #5
0
 def test_thorough_json(self):
     """Test the round-trip through node-link JSON."""
     graph_json_dict = to_nodelink(sialic_acid_graph)
     graph = from_nodelink(graph_json_dict)
     self._help_test_equal(graph)
Пример #6
0
 def test_slushy_json(self):
     graph_json = to_nodelink(self.slushy_graph)
     graph = from_nodelink(graph_json)
     self.bel_slushy_reconstituted(graph)