Beispiel #1
0
 def process_document(self, document):
     ev = self.get_evidence(document)
     stmts = []
     for interaction in self.find_interactions(document['elements']):
         groups = defaultdict(list)
         for entry in interaction['entries']:
             groups[entry['group']].append(
                 self.agent_from_element(
                     self.find_element(document['elements'], entry['id'])
                 )
             )
         groups = dict(groups)
         if interaction['type'] in mod_types:
             stmt_type = interaction_types[interaction['type']]
             enz = groups[None][0] if None in groups else None
             sub = None
             act_inh_stmt = None
             for polarity in {'positive', 'unsigned', 'negative'}:
                 if polarity in groups:
                     if polarity == 'positive':
                         act_inh_stmt = Activation
                     elif polarity == 'negative':
                         act_inh_stmt = Inhibition
                     sub = groups[polarity][0]
                     break
             if sub and enz:
                 stmt = stmt_type(deepcopy(enz),
                                  deepcopy(sub),
                                  evidence=deepcopy(ev))
                 stmts.append(stmt)
                 if act_inh_stmt:
                     stmt = act_inh_stmt(deepcopy(enz),
                                         deepcopy(sub),
                                         evidence=deepcopy(ev))
                     stmts.append(stmt)
         elif interaction['type'] == 'transcription-translation':
             subj = groups[None][0] if None in groups else None
             obj = None
             for polarity in {'positive', 'unsigned', 'negative'}:
                 if polarity in groups:
                     obj = groups[polarity][0]
                     break
             else:
                 polarity = None
             if polarity == 'positive':
                 stmt_type = IncreaseAmount
             elif polarity == 'negative':
                 stmt_type = DecreaseAmount
             if subj and obj and polarity:
                 stmt = stmt_type(deepcopy(subj),
                                  deepcopy(obj),
                                  evidence=deepcopy(ev))
                 stmts.append(stmt)
         elif interaction['type'] == 'binding':
             members = flatten(list(groups.values()))
             stmt = Complex(deepcopy(members),
                            evidence=deepcopy(ev))
             stmts.append(stmt)
     return stmts
Beispiel #2
0
 def _get_citations(bpe: bp.PhysicalEntity):
     refs = []
     xrefs = bpe.xref + flatten([ev.xref for ev in bpe.evidence])
     for xr in xrefs:
         db_name = xr.db
         if db_name is not None and db_name.upper() == 'PUBMED':
             refs.append(xr.id)
     # TODO: handle non-pubmed evidence
     return refs
Beispiel #3
0
 def find_matching_entities(left_simple, right_simple):
     """Find matching entities between two lists of simple entities."""
     matches = []
     for inp, outp in itertools.product(left_simple, right_simple):
         inp_type = infer_pe_type(inp)
         outp_type = infer_pe_type(outp)
         if inp_type != outp_type:
             continue
         elif inp_type == 'family':
             input_ers = {
                 mpe.entity_reference.uid
                 for mpe in expand_family(inp)
                 if isinstance(mpe, bp.SimplePhysicalEntity)
             }
             output_ers = {
                 mpe.entity_reference.uid
                 for mpe in expand_family(outp)
                 if isinstance(mpe, bp.SimplePhysicalEntity)
             }
             if input_ers == output_ers:
                 matches.append((inp, outp))
         # Sometimes we get a "raw" PhysicalEntity here that doesn't
         # actually have an entity reference which is required here so
         # we skip those.
         elif not isinstance(inp, (bp.SimplePhysicalEntity, bp.Complex)) or \
                 not isinstance(outp, (bp.SimplePhysicalEntity, bp.Complex)):
             continue
         elif inp_type == 'complex_named':
             if inp.uid == outp.uid:
                 matches.append((inp, outp))
         elif inp_type == 'complex_family':
             inp_members = flatten(
                 [expand_complex(m) for m in expand_family(inp)])
             outp_members = flatten(
                 [expand_complex(m) for m in expand_family(outp)])
             matches += BiopaxProcessor.find_matching_entities(
                 inp_members, outp_members)
         elif inp.entity_reference.uid == outp.entity_reference.uid:
             matches.append((inp, outp))
     return matches
Beispiel #4
0
 def report_paths_graph(self, paths_list):
     from indra.assemblers.graph import GraphAssembler
     from indra.util import flatten
     path_stmts = [stmts_from_json(l) for l in paths_list]
     all_stmts = flatten(path_stmts)
     ga = GraphAssembler(all_stmts)
     ga.make_model()
     resource = get_img_path('qca_paths.png')
     ga.save_pdf(resource)
     content = KQMLList('display-image')
     content.set('type', 'simulation')
     content.sets('path', resource)
     self.tell(content)
Beispiel #5
0
 def report_paths_graph(self, paths_list):
     from indra.assemblers.graph import GraphAssembler
     from indra.util import flatten
     path_stmts = [stmts_from_json(l) for l in paths_list]
     all_stmts = flatten(path_stmts)
     ga = GraphAssembler(all_stmts)
     ga.make_model()
     resource = get_img_path('qca_paths.png')
     ga.save_pdf(resource)
     content = KQMLList('display-image')
     content.set('type', 'simulation')
     content.sets('path', resource)
     self.tell(content)
Beispiel #6
0
def get_piis(query_str):
    """Search ScienceDirect through the API for articles and return PIIs.

    Note that ScienceDirect has a limitation in which a maximum of 6,000
    PIIs can be retrieved for a given search and therefore this call is
    internally broken up into multiple queries by a range of years and the
    results are combined.

    Parameters
    ----------
    query_str : str
        The query string to search with

    Returns
    -------
    piis : list[str]
        The list of PIIs identifying the papers returned by the search
    """
    dates = range(1960, datetime.datetime.now().year)
    all_piis = flatten([get_piis_for_date(query_str, date) for date in dates])
    return all_piis