def test_json_load():
    t = ObographJsonTransformer()
    t.parse(os.path.join(resource_dir, 'goslim_generic.json'))
    assert t.graph.number_of_nodes() == 176
    assert t.graph.number_of_edges() == 206

    n1 = t.graph.nodes(data=True)['GO:0003677']
    assert n1['id'] == 'GO:0003677'
    assert n1['name'] == 'DNA binding'
    assert n1[
        'description'] == 'Any molecular function by which a gene product interacts selectively and non-covalently with DNA (deoxyribonucleic acid).'
    assert n1['category'] == ['biolink:MolecularActivity']
    assert 'structure-specific DNA binding' in n1['synonym']
    assert 'structure specific DNA binding' in n1['synonym']
    assert 'microtubule/chromatin interaction' in n1['synonym']
    assert 'plasmid binding' in n1['synonym']

    n2 = t.graph.nodes(data=True)['GO:0005575']
    assert n2['id'] == 'GO:0005575'
    assert n2['name'] == 'cellular_component'
    assert n2[
        'description'] == 'A location, relative to cellular compartments and structures, occupied by a macromolecular machine when it carries out a molecular function. There are two ways in which the gene ontology describes locations of gene products: (1) relative to cellular structures (e.g., cytoplasmic side of plasma membrane) or compartments (e.g., mitochondrion), and (2) the stable macromolecular complexes of which they are parts (e.g., the ribosome).'
    assert n2['category'] == ['biolink:CellularComponent']
    assert n2['xrefs'] == ['NIF_Subcellular:sao1337158144']
    assert 'goslim_chembl' in n2['subsets']
    assert 'goslim_generic' in n2['subsets']
def test_load_edge():
    edge = {
        "sub": "http://purl.obolibrary.org/obo/GO_0003677",
        "pred": "is_a",
        "obj": "http://purl.obolibrary.org/obo/GO_0003674"
    }
    t = ObographJsonTransformer()
    t.load_edge(edge)

    e = next(iter(t.graph.edges(data=True)))
    assert e[2]['subject'] == 'GO:0003677'
    assert e[2]['edge_label'] == 'biolink:subclass_of'
    assert e[2]['relation'] == 'rdfs:subClassOf'
    assert e[2]['object'] == 'GO:0003674'
Esempio n. 3
0
 def parse(self, name: str, data_file: str, source: str) -> None:
     """Processes the data_file.
     Args:
         name: Name of the ontology
         data_file: data file to parse
         source: Source name
     Returns:
          None.
     """
     print(f"Parsing {data_file}")
     transformer = ObographJsonTransformer()
     transformer.parse(data_file, provided_by=source)
     output_transformer = PandasTransformer(transformer.graph)
     output_transformer.save(filename=os.path.join(self.output_dir, f'{name}'), output_format='tsv', mode=None)
Esempio n. 4
0
    def parse(self, name: str, data_file: str) -> None:
        """Processes the data_file.

        Args:
            name: Name of the ontology
            data_file: data file to parse

        Returns:
             None.

        """
        logging.info(f"Parsing {data_file}")
        transformer = ObographJsonTransformer()
        transformer.parse(data_file)
        output_transformer = PandasTransformer(transformer.graph)
        output_transformer.save(filename=os.path.join(self.output_dir,
                                                      f'{name}'),
                                extension='tsv',
                                mode=None)
def test_load_node():
    node = {
        "id": "http://purl.obolibrary.org/obo/GO_0005615",
        "meta": {
            "basicPropertyValues": [{
                "pred":
                "http://www.geneontology.org/formats/oboInOwl#hasOBONamespace",
                "val": "cellular_component"
            }]
        },
        "type": "CLASS",
        "lbl": "extracellular space"
    }
    t = ObographJsonTransformer()
    t.load_node(node)

    n = next(iter(t.graph.nodes(data=True)))
    assert n[1]['id'] == 'GO:0005615'
    assert n[1]['name'] == 'extracellular space'
    assert n[1]['category'] == ['biolink:CellularComponent']
Esempio n. 6
0
    def parse(self, name: str, data_file: str, source: str) -> None:
        """Processes the data_file.
        
        :param name: Name of the ontology
        :param data_file: data file to parse
        :param source: Source name
        :return: None.
        """

        print(f"Parsing {data_file}")
        transformer = ObographJsonTransformer()
        compression: Optional[str]
        if data_file.endswith('.gz'):
            compression = 'gz'
        else:
            compression = None
        transformer.parse(data_file,
                          compression=compression,
                          provided_by=source)
        output_transformer = PandasTransformer(transformer.graph)
        output_transformer.save(filename=os.path.join(self.output_dir,
                                                      f'{name}'),
                                output_format='tsv',
                                mode=None)
def test_get_category(query):
    node = query[0]
    t = ObographJsonTransformer()
    c = t.get_category(node['id'], node)
    assert c == query[1]