예제 #1
0
 def term_to_term(self, node_a, node_b, limit=10000):
     """Given two terms, find articles in chemotext that connect them, and return as a KEdge.
     If nothing is found, return None"""
     meshes_a = self.get_mesh_labels(node_a)
     meshes_b = self.get_mesh_labels(node_b)
     articles = []
     from datetime import datetime
     start = datetime.now()
     for label_a in meshes_a:
         for label_b in meshes_b:
             response = self.ctext.query(
                 query=
                 "MATCH (d:Term)-[r1]-(a:Art)-[r2]-(t:Term) WHERE d.name='%s' AND t.name='%s' RETURN a LIMIT %d"
                 % (label_a, label_b, limit))
             for result in response['results']:
                 for data in result['data']:
                     articles += data['row']
     end = datetime.now()
     logging.getLogger('application').debug(
         'chemotext: {} to {}: {} ({})'.format(meshes_a, meshes_b,
                                               len(articles), end - start))
     if len(articles) > 0:
         ke = KEdge('chemotext',
                    'term_to_term', {'publications': articles},
                    is_support=True)
         ke.source_node = node_a
         ke.target_node = node_b
         return ke
     return None
 def term_to_term(self,node_a,node_b,limit = 10000):
     """Given two terms, find articles in chemotext that connect them, and return as a KEdge.
     If nothing is found, return None"""
     logging.getLogger('application').debug('identifiers: {} to {}'.format(node_a.id, node_b.id))
     meshes_a = self.get_mesh_labels(node_a)
     meshes_b = self.get_mesh_labels(node_b)
     articles=[]
     from datetime import datetime
     start = datetime.now()
     for label_a in meshes_a:
         for label_b in meshes_b:
             response = self.ctext.query( query="MATCH (d:Term)-[r1]-(a:Art)-[r2]-(t:Term) WHERE d.name='%s' AND t.name='%s' RETURN a LIMIT %d" % (label_a, label_b, limit))
             for result in response['results']:
                 for data in result['data']:
                     articles += data['row']
     end = datetime.now()
     logging.getLogger('application').debug('chemotext: {} to {}: {} ({})'.format(meshes_a, meshes_b, len(articles), end-start))
     if len(articles) > 0:
         #ke= KEdge( 'chemotext', 'term_to_term', { 'publications': articles }, is_support = True )
         pmids = [f'PMID:{x["pmid"]}' for x in articles]
         raise RuntimeError('The following KEdge constructor syntax looks very suspect.')
         ke = KEdge('chemotext.term_to_term', dt.now(), 'chemotext:1', 'literature_co-occurence',
                    f'{node_a.id},{node_b.id}','chemotext:1','literature_co-occurence',publications=pmids,
                    is_support=True)
         ke.source_node = node_a
         ke.target_node = node_b
         return ke
     return None
예제 #3
0
 def term_to_term(self, node_a, node_b, limit=10000):
     """Given two terms, find articles in chemotext that connect them, and return as a KEdge.
     If nothing is found, return None"""
     logging.getLogger('application').debug(
         'chemotext2: "{}" to "{}"'.format(node_a.label, node_b.label))
     phrases_a = self.generate_phrases(node_a.label)
     phrases_b = self.generate_phrases(node_b.label)
     maxr = -1
     besta = ''
     bestb = ''
     for p_a in phrases_a:
         for p_b in phrases_b:
             if p_a == p_b:
                 continue
             r = self.chemotext2.get_semantic_similarity(p_a, p_b)
             if r > maxr:
                 maxr = r
                 besta = p_a
                 bestb = p_b
             logging.getLogger('application').debug(
                 '  "{}"-"{}": {} ({})'.format(p_a, p_b, r, maxr))
     logging.getLogger('application').debug(' "{}"-"{}": {}'.format(
         besta, bestb, maxr))
     if maxr > -1:
         ke = KEdge('chemotext2',
                    'term_to_term', {
                        'similarity': maxr,
                        'terms': [besta, bestb]
                    },
                    is_support=True)
         ke.source_node = node_a
         ke.target_node = node_b
         return ke
     return None
예제 #4
0
 def execute(self):
     """Execute the query that defines the graph"""
     self.logger.debug('Executing Query')
     #GreenT wants a cypherquery to find transitions, and a starting point
     cyphers  = self.userquery.generate_cypher()
     starts   = self.userquery.get_start_node()
     reverses = self.userquery.get_reversed()
     lookups  = self.userquery.get_lookups()
     for cypher, start, reverse,lookup in zip(cyphers,starts,reverses,lookups):
         input_name = Text.un_curie(lookup.identifier)
         self.logger.debug(start)
         self.logger.debug('CYPHER')
         self.logger.debug(cypher)
         identifier, ntype = start
         start_node = KNode( identifier, ntype, label=input_name )
         kedge = KEdge( 'lookup', 'lookup' )
         kedge.source_node = lookup
         kedge.target_node = start_node
         self.add_nonsynonymous_edge( kedge )
         #Fire this to rosetta, collect the result
         result_graph = self.rosetta.graph([(None, start_node)],query=cypher)
         #result_graph contains duplicate edges.  Remove them, while preserving order:
         result_graph = list(OrderedDict.fromkeys( result_graph ) )
         self.add_edges( result_graph , reverse )
     self.logger.debug('Query Complete')
예제 #5
0
 def make_edge(self,cooc_list, node_a, node_b):
     k,c = cooc_list[0]
     #TODO: fix this up with details
     c[ 'icd9' ] = list(k) 
     ke= KEdge( 'cdw', 'term_to_term', c,  is_support = True )
     ke.source_node = node_a
     ke.target_node = node_b
     return ke
예제 #6
0
 def make_edge(self, cooc_list, node_a, node_b):
     k, c = cooc_list[0]
     #TODO: fix this up with details
     c['icd9'] = list(k)
     raise RuntimeError(
         'The following KEdge constructor looks somewhat suspect.')
     ke = KEdge('cdw', 'term_to_term', c, is_support=True)
     ke.source_node = node_a
     ke.target_node = node_b
     return ke
 def new_edge(self,
              source,
              function,
              properties,
              source_node=None,
              target_node=None):
     raise RuntimeError(
         'The following KEdge constructor looks very suspect.')
     edge = KEdge(source, function, properties)
     edge.source_node = source_node
     edge.target_node = target_node
     return edge
예제 #8
0
 def term_to_term(self,node_a,node_b):
     articles = self.omnicorp.get_shared_pmids(node_a, node_b)
     #logger.debug(f'OmniCorp {node_a.identifier} {node_b.identifier}')
     if len(articles) > 0:
         #logger.debug(f'    -> {len(articles)}')
         pmids = [f'PMID:{x.split("/")[-1]}' for x in articles]
         ke = KEdge('omnicorp.term_to_term', dt.now(), 'omnicorp:1', 'literature_co-occurence',
                    f'{node_a.identifier},{node_b.identifier}','omnicorp:1','literature_co-occurence',publications=pmids,
                    is_support=True)
         ke.source_node = node_a
         ke.target_node = node_b
         return ke
     return None