示例#1
0
    def test_namespace_entry(self):
        model = NamespaceEntry(name='entry',
                               namespace=Namespace(keyword='test'))

        expected = {NAMESPACE: 'test', NAME: 'entry'}

        self.assertEqual(model.to_json(), expected)

        expected['id'] = model.id = 1

        self.assertEqual(model.to_json(include_id=True), expected)

        expected[IDENTIFIER] = model.identifier = 'test:00001'

        self.assertEqual(model.to_json(include_id=True), expected)
示例#2
0
    def test_drop_namespace(self):
        keyword, url = n(), n()

        namespace = Namespace(keyword=keyword, url=url)
        self.manager.session.add(namespace)

        n_entries = 5

        for _ in range(n_entries):
            entry = NamespaceEntry(name=n(), namespace=namespace)
            self.manager.session.add(entry)

        self.manager.session.commit()

        self.assertEqual(1,
                         self.manager.count_namespaces(),
                         msg='Should have one namespace')
        self.assertEqual(n_entries,
                         self.manager.count_namespace_entries(),
                         msg='Should have {} entries'.format(n_entries))

        self.manager.drop_namespace_by_url(url)

        self.assertEqual(0,
                         self.manager.count_namespaces(),
                         msg='Should have no namespaces')
        self.assertEqual(0,
                         self.manager.count_namespace_entries(),
                         msg='Entries should have been dropped')
示例#3
0
 def _create_namespace_entry_from_model(
         self, model: Pathway, namespace: Namespace) -> NamespaceEntry:
     """Create a namespace entry from the model."""
     return NamespaceEntry(encoding='B',
                           name=model.name,
                           identifier=model.wikipathways_id,
                           namespace=namespace)
示例#4
0
 def _create_namespace_entry_from_model(self, model: FlyGene, namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(
         encoding='GRP',
         name=model.symbol,
         identifier=model.flybase_id,
         namespace=namespace,
     )
示例#5
0
 def _create_namespace_entry_from_model(self, model: Drug, namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(
         encoding='A',
         name=model.name,
         identifier=model.drugbank_id,
         namespace=namespace,
     )
示例#6
0
文件: manager.py 项目: bio2bel/entrez
 def _create_namespace_entry_from_model(self, gene: Gene, namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(
         encoding=gene.bel_encoding,
         name=gene.name,
         identifier=gene.entrez_id,
         namespace=namespace,
     )
示例#7
0
 def _create_namespace_entry_from_model(
         self, model: Antibody, namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(
         namespace=namespace,
         identifier=model.antibodyregistry_id,
         name=model.name,
         encoding='A',
     )
示例#8
0
 def _create_namespace_entry_from_model(
         self, term: Term, namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(
         name=term.name,
         identifier=term.go_id,
         encoding=term.bel_encoding,
         namespace=namespace,
     )
示例#9
0
 def _create_namespace_entry_from_model(
         self, model: Homologene, namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(
         namespace=namespace,
         name=model.homologene_id,
         identifier=model.homologene_id,
         encoding=model.bel_encoding,
     )
示例#10
0
 def _create_namespace_entry_from_model(
         self, sequence: Sequence, namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(
         name=sequence.name,
         identifier=sequence.mirbase_id,
         encoding='GM',
         namespace=namespace,
     )
示例#11
0
 def _create_namespace_entry_from_model(
         self, model: Enzyme, namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(
         namespace=namespace,
         name=model.expasy_id,
         identifier=model.expasy_id,
         encoding='GRP',
     )
示例#12
0
 def _create_namespace_entry_from_model(
         self, model: CompathPathwayMixin,
         namespace: Namespace) -> NamespaceEntry:
     """Create a namespace entry from the model."""
     return NamespaceEntry(encoding='B',
                           name=model.name,
                           identifier=model.identifier,
                           namespace=namespace)
示例#13
0
 def _create_namespace_entry_from_model(
         self, descriptor: Descriptor,
         namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(
         namespace=namespace,
         name=descriptor.name,
         identifier=descriptor.descriptor_ui,
         encoding=descriptor.bel_encoding,
     )
 def _create_namespace_entry_from_model(self,
                                        model: Model,
                                        namespace=None):
     """Create a namespace entry."""
     return NamespaceEntry(
         name=model.name,
         identifier=model.test_id,
         namespace=namespace,
     )
示例#15
0
文件: manager.py 项目: bio2bel/mgi
 def _create_namespace_entry_from_model(
         self, mouse_gene: MouseGene,
         namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(
         encoding=mouse_gene.bel_encoding,
         name=mouse_gene.symbol,
         identifier=mouse_gene.mgi_id,
         namespace=namespace,
     )
示例#16
0
 def _create_namespace_entry_from_model(
         self, chemical: Chemical, namespace: Namespace) -> NamespaceEntry:
     """Create a namespace entry from a chemical model."""
     if chemical.name:
         return NamespaceEntry(
             encoding=chemical.bel_encoding,
             name=chemical.name,
             identifier=chemical.chebi_id,
             namespace=namespace,
         )
示例#17
0
文件: utils.py 项目: bgyori/pybel
def make_dummy_namespaces(manager, graph, namespaces):
    """
    :param pybel.manager.Manager manager:
    :param pybel.BELGraph graph:
    :param dict[str,iter[str]] namespaces:
    """
    for keyword, names in namespaces.items():
        url = n()
        graph.namespace_url[keyword] = url

        namespace = Namespace(keyword=keyword, url=url)
        manager.session.add(namespace)
        manager.namespace_model[url] = namespace

        for name in names:
            entry = manager.namespace_object_cache[url][
                entry.name] = NamespaceEntry(name=name, namespace=namespace)
            manager.session.add(entry)

        manager.session.commit()
示例#18
0
 def _create_namespace_entry_from_model(
         self, gene: RatGene, namespace: Namespace) -> NamespaceEntry:
     return NamespaceEntry(encoding=gene.bel_encoding,
                           name=gene.symbol,
                           identifier=gene.rgd_id,
                           namespace=namespace)