Exemple #1
0
 def test_list_with_filter(self, kg_client):
     people = Person.list(kg_client, api="nexus", family_name="da Vinci", size=10)
     assert isinstance(people, Person)
     people = Person.list(kg_client, api="nexus", given_name="Katherine", size=10)
     assert isinstance(people, Person)
     people = Person.list(kg_client, api="nexus", given_name="Horatio", size=10)
     assert len(people) == 0
 def _get_person_from_Persons_table(self, pattern):
     logger.debug("getting person %s", pattern)
     pattern = pattern.strip()
     try:
         p = Persons.objects.get(pattern=pattern)
         person = Person(family_name=str(p.last_name),
                         given_name=str(p.first_name),
                         email=str(p.email),
                         affiliation='')
         logger.debug('person : %s', person)
     except:
         if pattern != None:
             #raise Exception(pattern)
             print('person ', pattern,
                   ' has not been found. please enter it by hand')
             family_name = raw_input('  give the family_name : ')
             given_name = raw_input('  give the first_name : ')
             email = raw_input('  give the email adress : ')
             person = Person(family_name=str(family_name),
                             given_name=str(given_name),
                             email=str(email),
                             affiliation='')
         else:
             person = None
     return person
Exemple #3
0
    def test_uuid(self, kg_client):
        obj = Person("Johnson", "Katherine", "*****@*****.**",
                     id="https://nexus.humanbrainproject.org/v0/data/neuralactivity/core/person/v0.1.0/02be7e84-af91-4481-a7c1-1ec204eaeab8")

        assert obj.uuid == "02be7e84-af91-4481-a7c1-1ec204eaeab8"

        assert obj.uri_from_uuid(obj.uuid, kg_client) == obj.id
Exemple #4
0
 def test_get_context(self, kg_client):
     p1 = Person("Hamilton",
                 "Margaret",
                 "*****@*****.**",
                 KGProxy(Organization, "http://fake_uuid_855fead8"),
                 id="http://fake_uuid_8ab3dc739b")
     context = p1.get_context(kg_client)
     assert context == Person.context
Exemple #5
0
 def test_round_trip(self, kg_client):
     p1 = Person("Hamilton", "Margaret", "*****@*****.**",
                 KGProxy(Organization, "http://fake_uuid_855fead8"))
     instance = Instance(Person.path, p1._build_data(kg_client), Instance.path)
     instance.data["@id"] = "http://fake_uuid_8ab3dc739b"
     instance.data["@type"] = Person.type
     p2 = Person.from_kg_instance(instance, kg_client)
     for field in ("family_name", "given_name", "email", "affiliation", "full_name"):
         assert getattr(p1, field) == getattr(p2, field)
 def _save_person_in_KG(self, first_name, last_name, email):
     person = Person(family_name=last_name,
                     given_name=first_name,
                     email=email,
                     affiliation='')
     if not person.exists(NAR_client):
         person.save(NAR_client)
         logger.debug('saved in KG: %s', person)
     else:
         logger.debug('already exists in KG: %s', person)
Exemple #7
0
 def test_exists(self, kg_client):
     p1 = Person("Hamilton", "Margaret", "*****@*****.**",
                 KGProxy(Organization, "http://fake_uuid_855fead8"),
                 id="http://fake_uuid_8ab3dc739b")
     assert p1.exists(kg_client, api="nexus")
     p2 = Person("James", "Bond", "*****@*****.**")
     p2_exists = p2.exists(kg_client, api="nexus")
     assert not p2_exists
     p3_noid = Person("Johnson", "Katherine", "*****@*****.**")
     p3_exists = p3_noid.exists(kg_client, api="nexus")
     assert p3_exists
Exemple #8
0
 def test_existence_query(self):
     obj = Person("Johnson", "Katherine")
     expected = {
         "op":
         "and",
         "value": [{
             "path": "schema:familyName",
             "op": "eq",
             "value": "Johnson"
         }, {
             "path": "schema:givenName",
             "op": "eq",
             "value": "Katherine"
         }]
     }
     generated = obj._build_existence_query(api="nexus")
     assert expected == generated
 def test_existence_query(self, kg_client):
     obj = ModelProject(name="foo",
                        owners=Person("Holmes", "Sherlock"),
                        authors=Person("Holmes", "Sherlock"),
                        description="",
                        private=True,
                        date_created=datetime(2000, 1, 1))
     expected = {
         "op":
         "and",
         "value": [{
             "path": "schema:name",
             "op": "eq",
             "value": "foo"
         }, {
             "path": "schema:dateCreated",
             "op": "eq",
             "value": "2000-01-01T00:00:00"
         }]
     }
     generated = obj._build_existence_query(api="nexus")
     assert expected == generated
    def save(self, allow_update=True):
        if self.obj is None:  # create
            for key in ("author", "owner"):
                if isinstance(self.data[key], dict):
                    self.data[key] = [self.data[key]]
            self.obj = ModelProject(
                self.data["name"],
                [
                    Person(p["family_name"], p["given_name"],
                           p.get("email", None))
                    for p in as_list(self.data["owner"])
                ],
                [
                    Person(p["family_name"], p["given_name"],
                           p.get("email", None))
                    for p in as_list(self.data["author"])
                ],  # need to update person representation in clients,
                self.data.get("description"),
                datetime.now(),
                self.data.get("private", True),
                self.context["collab_id"],
                self.data.get("alias"),
                Organization(self.data["organization"]) if self.data.get(
                    "organization", False) else None,
                pla_components=None,
                brain_region=self._get_ontology_obj(BrainRegion,
                                                    "brain_region"),
                species=self._get_ontology_obj(Species, "species"),
                celltype=self._get_ontology_obj(CellType, "cell_type"),
                abstraction_level=self._get_ontology_obj(
                    AbstractionLevel, "abstraction_level"),
                model_of=self._get_ontology_obj(ModelScope, "model_scope"),
                old_uuid=self.data.get("old_uuid"),
                images=self.data.get("images"))
        else:  # update
            if "name" in self.data:
                self.obj.name = self.data["name"]
            if "alias" in self.data:
                self.obj.alias = self.data["alias"]
            if "author" in self.data:
                self.obj.authors = [
                    Person(p["family_name"], p["given_name"],
                           p.get("email", None))
                    for p in as_list(self.data["author"])
                ]  # need to update person representation in clients
            if "owner" in self.data:
                self.obj.owners = [
                    Person(p["family_name"], p["given_name"],
                           p.get("email", None))
                    for p in as_list(self.data["owner"])
                ]  # need to update person representation in clients
            if "app" in self.data:
                self.obj.collab_id = self.data["app"]["collab_id"]
            if "organization" in self.data and self.data[
                    "organization"] is not None:
                self.obj.organization = Organization(self.data["organization"])
            if "private" in self.data:
                self.obj.private = self.data["private"]
            if "cell_type" in self.data:
                self.obj.celltype = self._get_ontology_obj(
                    CellType, "cell_type")
            if "model_scope" in self.data:
                self.obj.model_of = self._get_ontology_obj(
                    ModelScope, "model_scope")
            if "abstraction_level" in self.data:
                self.obj.abstraction_level = self._get_ontology_obj(
                    AbstractionLevel, "abstraction_level")
            if "brain_region" in self.data:
                self.obj.brain_region = self._get_ontology_obj(
                    BrainRegion, "brain_region")
            if "species" in self.data:
                self.obj.species = self._get_ontology_obj(Species, "species")
            if "description" in self.data:
                self.obj.description = self.data["description"]
            if "old_uuid" in self.data:
                self.obj.old_uuid = self.data["old_uuid"]
            if "images" in self.data:
                self.obj.images = self.data["images"]

        # now save people, organization, model. No easy way to make this atomic, I don't think.
        for person in chain(as_list(self.obj.authors),
                            as_list(self.obj.owners)):
            if not isinstance(person, KGProxy):
                # no need to save if we have a proxy object, as
                # that means the person hasn't been updated
                person.save(self.client)
        if self.obj.organization and not isinstance(self.obj.organization,
                                                    KGProxy):
            self.obj.organization.save(self.client)
        self.obj.save(self.client)
        return self.obj
    def save(self):
        if self.obj is None:  # create
            reference_data = [
                AnalysisResult(
                    name="Reference data #{} for validation test '{}'".format(
                        i, self.data["name"]),
                    result_file=Distribution(url))
                for i, url in enumerate(as_list(self.data["data_location"]))
            ]
            for item in reference_data:
                try:
                    item.save(self.client)
                except Exception as err:
                    logger.error(
                        "error saving reference data. name = {}, urls={}".
                        format(self.data["name"], self.data["data_location"]))
                    raise
            authors = self.data["author"]
            # if not isinstance(authors, list):
            #     authors = [authors]
            self.obj = ValidationTestDefinition(
                name=self.data["name"],
                alias=self.data.get("alias"),
                status=self.data.get("status", "proposal"),
                species=self._get_ontology_obj(Species, "species"),
                brain_region=self._get_ontology_obj(BrainRegion,
                                                    "brain_region"),
                celltype=self._get_ontology_obj(CellType, "cell_type"),
                reference_data=reference_data,
                data_type=self.data.get("data_type"),
                recording_modality=self.data.get("data_modality"),
                test_type=self.data.get("test_type"),
                score_type=self.data.get("score_type"),
                description=self.data.get("protocol"),
                authors=[
                    Person(p["family_name"], p["given_name"],
                           p.get("email", None)) for p in as_list(authors)
                ],
                date_created=datetime.now())
            for author in self.obj.authors:
                author.save(self.client)
        else:  # update
            logger.debug("Updating test {} with data {}".format(
                self.obj.id, self.data))
            if "name" in self.data:
                self.obj.name = self.data["name"]
            if "alias" in self.data:
                self.obj.alias = self.data["alias"]

            if "status" in self.data:
                self.obj.status = self.data["status"]
            if "species" in self.data:
                self.obj.species = self._get_ontology_obj(Species, "species")
            if "brain_region" in self.data:
                self.obj.brain_region = self._get_ontology_obj(
                    BrainRegion, "brain_region")
            if "cell_type" in self.data:
                self.obj.celltype = self._get_ontology_obj(
                    CellType, "cell_type")
            if "data_type" in self.data:
                self.obj.data_type = self.data["data_type"]
            if "data_modality" in self.data:
                self.obj.recording_modality = self.data["data_modality"]
            if "test_type" in self.data:
                self.obj.test_type = self.data["test_type"]
            if "score_type" in self.data:
                self.obj.score_type = self.data["score_type"]
            if "protocol" in self.data:
                self.obj.description = self.data["protocol"]
            if "data_location" in self.data:
                self.obj.reference_data = [
                    AnalysisResult(
                        name="Reference data #{} for validation test '{}'".
                        format(i, self.data["name"]),
                        result_file=Distribution(url)) for i, url in enumerate(
                            as_list(self.data["data_location"]))
                ]
            if "author" in self.data:
                self.obj.authors = [
                    Person(p["family_name"], p["given_name"],
                           p.get("email", None))
                    for p in as_list(self.data["author"])
                ]

            # now save people, ref data, test. No easy way to make this atomic, I don't think.
            for person in as_list(self.obj.authors):
                if not isinstance(person, KGProxy):
                    # no need to save if we have a proxy object, as
                    # that means the person hasn't been updated
                    # although in fact the authors are saved when the test is saved
                    # need to make this consistent
                    person.save(self.client)
            for ref_data in as_list(self.obj.reference_data):
                if not isinstance(person, KGProxy):
                    ref_data.save(self.client)

        self.obj.save(self.client)
        return self.obj
Exemple #12
0
    def test__build_data(self):

        input_data = dict(
            name="PyNN v0.9.4",
            version="0.9.4",
            summary=
            "A Python package for simulator-independent specification of neuronal network models",
            description=
            "PyNN (pronounced 'pine') is a simulator-independent language for building neuronal network models.",
            #identifier=Identifier("RRID:SCR_002715"),
            citation=
            ("Davison AP, Brüderle D, Eppler JM, Kremkow J, Muller E, Pecevski DA, Perrinet L and Yger P (2009) "
             "PyNN: a common interface for neuronal network simulators. "
             "Front. Neuroinform. 2:11 doi:10.3389/neuro.11.011.2008"),
            license=License("CeCILL v2"),
            release_date=date(2019, 3, 22),
            previous_version=None,
            contributors=[
                Person("Davison", "Andrew", "*****@*****.**")
            ],
            project=None,
            image="https://neuralensemble.org/static/photos/pynn_logo.png",
            download_url=
            "https://files.pythonhosted.org/packages/a2/1c/78b5d476900254c2c638a29a343ea12985ea16b12c7aed8cec252215c848/PyNN-0.9.4.tar.gz",
            access_url="https://pypi.org/project/PyNN/0.9.4/",
            categories=None,
            subcategories=None,
            operating_system=[
                OperatingSystem("Linux"),
                OperatingSystem("MacOS"),
                OperatingSystem("Windows")
            ],
            release_notes=
            "http://neuralensemble.org/docs/PyNN/releases/0.9.4.html",
            requirements="neo, lazyarray",
            copyright=Organization("The PyNN community"),
            components=None,
            part_of=None,
            funding=[
                Organization("CNRS"),
                Organization("Human Brain Project")
            ],
            languages=ProgrammingLanguage("Python"),
            features=None,
            #keywords="simulation, neuroscience",
            is_free=True,
            homepage="https://neuralensemble.org/PyNN/",
            documentation="http://neuralensemble.org/docs/PyNN/",
            help="https://groups.google.com/forum/#!forum/neuralensemble")
        software_release = Software(**input_data)
        kg_data = software_release._build_data(client=None)
        assert kg_data == {
            'name':
            input_data["name"],
            'version':
            input_data["version"],
            'headline':
            input_data["summary"],
            'description':
            input_data["description"],
            'citation':
            input_data["citation"],
            'license': {
                '@id': input_data["license"].iri,
                'label': input_data["license"].label
            },
            'dateCreated':
            '2019-03-22',
            #'copyrightYear': input_data["release_date"].year,
            'author': {
                '@id': None,
                '@type': ['nsg:Person', 'prov:Agent']
            },
            #'image': {'@id': input_data["image"]},
            #'distribution': {
            #    'downloadURL': {"@id": input_data["download_url"]},
            #    'accessURL': {"@id": input_data["access_url"]}
            #},
            'operatingSystem': [{
                '@id': os.iri,
                'label': os.label
            } for os in input_data["operating_system"]],
            'releaseNotes': {
                '@id': input_data["release_notes"]
            },
            'softwareRequirements':
            input_data["requirements"],
            'copyrightHolder': {
                '@id': None,
                '@type': ['nsg:Organization']
            },
            'funder': [{
                '@id': None,
                '@type': ['nsg:Organization']
            }, {
                '@id': None,
                '@type': ['nsg:Organization']
            }],
            #'programmingLanguage': [{'@id': input_data["languages"].iri, 'label': input_data["languages"].label}],
            #'keywords': input_data["keywords"],
            'isAccessibleForFree':
            input_data["is_free"],
            'url': {
                '@id': input_data["homepage"]
            },
            'documentation': {
                '@id': input_data["documentation"]
            },
            'softwareHelp': {
                '@id': input_data["help"]
            }
        }
Mirror people from neuroshapes core to uniminds
"""

import os
import hashlib
from fairgraph.client import KGClient
from fairgraph.core import Person as CorePerson
from fairgraph.uniminds import Person as uPerson

token = os.environ["HBP_token"]
#int_client = KGClient(token, nexus_endpoint="https://nexus-int.humanbrainproject.org/v0")
prod_client = KGClient(token,
                       nexus_endpoint="https://nexus.humanbrainproject.org/v0")

CorePerson.namespace = "modelvalidation"
people = CorePerson.list(prod_client, size=10000)

for person in people:
    if person.email is None or "example.com" in person.email:
        email = None
    else:
        email = person.email
    full_name = "{}, {}".format(person.family_name, person.given_name)
    identifier = hashlib.md5(full_name.encode('utf-8')).hexdigest()
    uperson = uPerson(familyName=person.family_name,
                      givenName=person.given_name,
                      email=email,
                      name=full_name,
                      identifier=identifier)
    if uperson.exists(prod_client):
        print("{} exists".format(uperson))
Exemple #14
0
 def test_save_new(self, kg_client, monkeypatch):
     new_p = Person("Ride", "Sally", "*****@*****.**")
     monkeypatch.setattr(Person,
                         "exists",
                         lambda self, kg_client, api='any': False)
     new_p.save(kg_client)
Exemple #15
0
 def test_from_uuid_invalid_uuid(self, kg_client):
     with pytest.raises(ValueError):
         Person.from_uuid("02be7e84-af91-4481-a7c1-1ec204eaeab",
                          kg_client,
                          api="nexus")
Exemple #16
0
 def test_from_uuid_empty_uuid(self, kg_client):
     with pytest.raises(ValueError):
         Person.from_uuid("", kg_client)