def get_bioc_relations(self, docid, relations):

        # <relation id="5618#7534">
        #     <infon key="Gene1">5618</infon>
        #     <infon key="Gene2">7534</infon>
        #     <infon key="relation">PPIm</infon>
        # </relation>

        biocDoc=BioCDocument()
        biocDoc.id = docid
        biocDoc.relations=[]

        for rel in relations:
            bioc_rel = BioCRelation()
            rel_list = list(rel)
            infon = {}
            infon["relation"] = "PPIm"
            infon["Gene1"] = rel_list[0]

            infon["Gene2"] = rel_list[0]
            if len(rel_list) == 2:
                infon["Gene2"] = rel_list[1]

            bioc_rel.id="{}#{}".format(infon["Gene1"], infon["Gene2"])
            bioc_rel.infons=infon
            biocDoc.relations.append(bioc_rel)

        return biocDoc
Esempio n. 2
0
def brat2bioc_event(bratevent: BratEvent) -> BioCRelation:
    rel = BioCRelation()
    rel.id = bratevent.id
    rel.infons['type'] = bratevent.type
    rel.infons['trigger_id'] = bratevent.trigger_id
    rel.add_node(BioCNode(bratevent.trigger_id, bratevent.type))
    for role, refid in bratevent.arguments.items():
        rel.add_node(BioCNode(refid, role))
    return rel
Esempio n. 3
0
 def __read_relation(self, start_elem):
     rel = BioCRelation()
     rel.id = start_elem.get('id')
     while self.__has_next():
         event, elem = self.__next_event()
         if event == 'start':
             pass
         elif event == 'end':
             if elem.tag == 'infon':
                 rel.infons[elem.get('key')] = elem.text
             elif elem.tag == 'node':
                 rel.add_node(BioCNode(elem.get('refid'), elem.get('role')))
             if elem.tag == 'relation':
                 return rel
     raise RuntimeError("should not reach here")  # pragma: no cover
Esempio n. 4
0
    def test_is_valid(self, relations_infons, gene1, gene2, expected):
        # arrange
        sut = BiocRelation()
        doc = BioCDocument()

        for dict in relations_infons:
            dict["relation"] = "PPIm"
            relation = BioCRelation()
            relation.infons = dict
            doc.add_relation(relation)

        # Act
        actual = sut.is_valid(doc, gene1, gene2)

        # Assert
        self.assertEqual(expected, actual)
Esempio n. 5
0
def brat2bioc_equiv(brat_equiv: BratEquivRelation) -> BioCRelation:
    rel = BioCRelation()
    rel.id = brat_equiv.id
    rel.infons['type'] = brat_equiv.type
    for argid in brat_equiv.argids:
        rel.add_node(BioCNode(argid, 'Arg'))
    return rel
Esempio n. 6
0
def brat2bioc_relation(bratrelation: BratRelation) -> BioCRelation:
    rel = BioCRelation()
    rel.id = bratrelation.id
    rel.infons['type'] = bratrelation.type
    for role, refid in bratrelation.arguments.items():
        rel.add_node(BioCNode(refid, role))
    return rel
Esempio n. 7
0
 def __parse_relation(self, tree):
     relation = BioCRelation()
     if 'id' in tree.attrib:
         relation.id = tree.attrib['id']
     relation.infons = self.__parse_infons(tree)
     for child in tree.findall('node'):
         relation.add_node(BioCNode(child.attrib['refid'], child.attrib['role']))
     return relation
    def to_bioc(self):
        relation_bioc = BioCRelation()
        relation_bioc.id = str(self.id)
        relation_bioc.add_node(BioCNode(str(self.entity1.id), 'annotation 1'))
        relation_bioc.add_node(BioCNode(str(self.entity2.id), 'annotation 2'))
        relation_bioc.infons['type'] = self.type

        return relation_bioc