Exemplo n.º 1
0
 def test_repr(self):
     try:
         unicode
     except NameError:
         cell = PatchedCell("example001",
                            brain_location=BrainRegion("primary auditory cortex"),
                            collection=None,
                            cell_type=CellType("pyramidal cell"),
                            experiments=None,
                            pipette_id=31,
                            seal_resistance=QuantitativeValue(1.2, "GΩ"),
                            pipette_resistance=QuantitativeValue(1.5, "MΩ"),
                            liquid_junction_potential=None,
                            labeling_compound="0.1% biocytin ",
                            reversal_potential_cl=None)
         expected_repr = ("PatchedCell(name='example001', "
                          "brain_location=BrainRegion('primary auditory cortex', 'http://purl.obolibrary.org/obo/UBERON_0034751'), "
                          "cell_type=CellType('pyramidal cell', 'http://purl.obolibrary.org/obo/CL_0000598'), "
                          "pipette_id=31, seal_resistance=QuantitativeValue(1.2 'GΩ'), "
                          "pipette_resistance=QuantitativeValue(1.5 'MΩ'), "
                          "labeling_compound='0.1% biocytin ', id=None)")
         assert repr(cell) == expected_repr
     else:
         pytest.skip(
             "The remaining lifespan of Python 2 is too short to fix unicode representation errors")
Exemplo n.º 2
0
def generate_random_object(cls, all_fields=True):
    attrs = {}
    for field in cls.fields:
        if all_fields or field.required:
            obj_type = field.types[
                0]  # todo: pick randomly if len(field.types) > 1
            if not field.intrinsic:
                value = None
            elif obj_type == basestring:
                value = _random_text()
            elif obj_type == int:
                value = random.randint(1, 10)
            elif obj_type == float:
                value = random.uniform(0, 1000)
            elif issubclass(obj_type, KGObject):
                if obj_type == KGObject:
                    # specific type is not determined
                    # arbitrarily, let's choose minds.Dataset
                    value = MockKGObject(id=random_uuid(),
                                         type=["minds:Dataset"])
                else:
                    value = MockKGObject(id=random_uuid(),
                                         type=getattr(obj_type, "type", None))
            elif obj_type == QuantitativeValue:
                # todo: subclass QV so we can specify the required dimensionality in `fields`
                value = QuantitativeValue(
                    random.uniform(-10, 10),
                    random.choice(list(QuantitativeValue.unit_codes)))
            elif obj_type == QuantitativeValueRange:
                # todo: subclass QVR so we can specify the required dimensionality in `fields`
                min = random.uniform(-10, 10)
                value = QuantitativeValueRange(
                    min, min + random.uniform(1, 10),
                    random.choice(list(QuantitativeValue.unit_codes)))
            elif issubclass(obj_type, OntologyTerm):
                value = obj_type(random.choice(list(obj_type.iri_map)))
            elif obj_type == datetime:
                value = datetime.now()
            elif obj_type == date:
                value = date.today()
            elif obj_type == bool:
                value = random.choice([True, False])
            elif obj_type == Distribution:
                value = Distribution("http://example.com/myfile.txt")
            elif obj_type == Age:
                value = Age(QuantitativeValue(random.randint(7, 150), "days"),
                            "Post-natal")
            elif obj_type == IRI:
                value = "http://example.com/åêïøù"
            elif obj_type == Address:
                value = Address("Paris", "France")
            elif obj_type == dict:
                value = {"a": 1, "b": 2}
            else:
                raise NotImplementedError(str(obj_type))
            attrs[field.name] = value
    return cls(**attrs)
Exemplo n.º 3
0
 def test_round_trip(self, kg_client):
     trace1 = Trace("example001",
                    data_location=Distribution(
                        "http://example.com/example.csv",
                        content_type="text/tab-separated-values"),
                    generated_by=MockKGObject(
                        id="http://fake_uuid_abc123",
                        type=PatchClampExperiment.type),
                    generation_metadata=MockKGObject(
                        id="http://fake_uuid_def456",
                        type=QualifiedTraceGeneration.type),
                    channel=42,
                    data_unit="mV",
                    time_step=QuantitativeValue(0.1, "ms"),
                    part_of=MockKGObject(id="http://fake_uuid_ghi789",
                                         type=Dataset.type))
     instance = Instance(Trace.path, trace1._build_data(kg_client),
                         Instance.path)
     instance.data["@id"] = "http://fake_uuid_6a5d6ecf87"
     instance.data["@type"] = Trace.type
     trace2 = Trace.from_kg_instance(instance, kg_client)
     for field in ("name", "data_location", "channel", "data_unit",
                   "time_step"):
         assert getattr(trace1, field) == getattr(trace2, field)
     for field in ("generated_by", "generation_metadata", "part_of"):
         obj1 = getattr(trace1, field)
         obj2 = getattr(trace2, field)
         assert isinstance(obj2, KGProxy)
         assert obj1.id == obj2.id
         assert obj1.type == obj2.type
Exemplo n.º 4
0
 def test_from_jsonld_alt(self):
     data = {
         "http://schema.org/value": 0.05,
         "http://schema.org/unitText": "ms"
     }
     obj = QuantitativeValue.from_jsonld(data)
     assert obj.value == 0.05
     assert obj.unit_text == "ms"
Exemplo n.º 5
0
 def test_round_trip(self, kg_client):
     obj1 = Subject(name="Mickey", species=Species("Mus musculus"),
                    strain=Strain("129/Sv"), sex=Sex("male"),
                    age=Age(QuantitativeValue(20, "days"), "Post-natal"),
                    death_date=datetime(1960, 1, 1))
     instance = Instance(Subject.path, obj1._build_data(kg_client), Instance.path)
     instance.data["@id"] = "http://fake_uuid_9ab2227fe1"
     instance.data["@type"] = Subject.type
     obj2 = Subject.from_kg_instance(instance, kg_client)
     for field in ("name", "species", "strain", "sex", "age", "death_date"):
         assert getattr(obj1, field) == getattr(obj2, field)
Exemplo n.º 6
0
 def test_round_trip(self, kg_client):
     cell1 = PatchedCell("example001",
                         brain_location=BrainRegion("primary auditory cortex"),
                         collection=None,
                         cell_type=CellType("pyramidal cell"),
                         experiments=None,
                         pipette_id=31,
                         seal_resistance=QuantitativeValue(1.2, "GΩ"),
                         pipette_resistance=QuantitativeValue(1.5, "MΩ"),
                         liquid_junction_potential=QuantitativeValue(5.0, "mV"),
                         labeling_compound="0.1% biocytin ",
                         reversal_potential_cl=QuantitativeValue(-65, "mV"))
     instance = Instance(PatchedCell.path, cell1._build_data(kg_client), Instance.path)
     instance.data["@id"] = "http://fake_uuid_93f9cd9a9b"
     instance.data["@type"] = PatchedCell.type
     cell2 = PatchedCell.from_kg_instance(instance, kg_client)
     for field in ("name", "brain_location", "cell_type",
                   "pipette_id", "seal_resistance", "pipette_resistance",
                   "liquid_junction_potential", "labeling_compound",
                   "reversal_potential_cl"):
         assert getattr(cell1, field) == getattr(cell2, field)
Exemplo n.º 7
0
 def test_repr(self):
     cell = PatchedCell(
         "example001",
         brain_location=BrainRegion("primary auditory cortex"),
         collection=None,
         cell_type=CellType("pyramidal cell"),
         experiments=None,
         pipette_id=31,
         seal_resistance=QuantitativeValue(1.2, "GΩ"),
         pipette_resistance=QuantitativeValue(1.5, "MΩ"),
         liquid_junction_potential=None,
         labeling_compound="0.1% biocytin ",
         reversal_potential_cl=None)
     expected_repr = (
         "PatchedCell(name='example001', "
         "brain_location=BrainRegion('primary auditory cortex', 'http://uri.interlex.org/ilx_0443027'), "
         "cell_type=CellType('pyramidal cell', 'http://uri.interlex.org/ilx_0107385'), "
         "pipette_id=31, seal_resistance=QuantitativeValue(1.2 'GΩ'), "
         "pipette_resistance=QuantitativeValue(1.5 'MΩ'), "
         "labeling_compound='0.1% biocytin ', id=None)")
     assert repr(cell) == expected_repr
Exemplo n.º 8
0
 def test_list_nexus(self, kg_client):
     cells = PatchedCell.list(kg_client, api="nexus", size=50)
     assert len(cells) == 30
     assert cells[0].brain_location == BrainRegion("hippocampus CA1")
     assert isinstance(cells[0].collection, KGQuery)
     assert cells[0].cell_type == CellType("hippocampus CA1 pyramidal cell")
     assert isinstance(cells[0].experiments, KGQuery)
     assert cells[0].pipette_id is None
     assert cells[0].seal_resistance is None
     assert cells[0].pipette_resistance is None
     assert cells[0].liquid_junction_potential is None
     assert cells[0].labeling_compound is None
     assert cells[0].reversal_potential_cl == QuantitativeValue(-16.0, unit_text="mV")